wso2esb - Filter data from JSON by checking condition with two properties - WSO2 ESB
问题描述
Below is the JSON file:
{
"_id": "rezbase_v3",
"_rev": "3-096e751caeeda12a8c30e28075a95e97",
"exchangerate_data": [
{
"buyingrate": 0.274725274725275,
"sellingrate": 0.274725274725275,
"buyingrateinverse": 3.64,
"sellingrateinverse": 3.64,
"basecurrency": {
"currencyCode": "USD",
"currencyName": "US dollar"
},
"quotecurrency": {
"currencyCode": "QAR",
"currencyName": "Qatari riyal"
},
"updateddate": 1491182700431,
"basecurrencyname": "US dollar",
"quotecurrencyname": "Qatari riyal"
},
{
"buyingrate": 0.00681384573453257,
"sellingrate": 0.00681384573453257,
"buyingrateinverse": 146.76,
"sellingrateinverse": 146.76,
"basecurrency": {
"currencyCode": "USD",
"currencyName": "US dollar"
},
"quotecurrency": {
"currencyCode": "LKR",
"currencyName": "Sri Lankan rupee"
},
"updateddate": 1491182700431,
"basecurrencyname": "US dollar",
"quotecurrencyname": "Sri Lankan rupee"
}
]
}
And from the file I need to filter buyingrate where basecurrency/currencycode is USD and quotecurrency/currencycode is LKR.
I have tried below expression:
<property description="quote1" expression="//jsonObject/exchangerate_data[basecurrency/currencyCode='USD' and quotecurrency/currencyCode='LKR']/buyingrate/text()" name="quote1" scope="default" type="STRING"/>
And I could be able to get the buyingrate.
But when I make the values as properties and tried to get the buyingrate, It is logging the exact expression insstead of the value.
<property description="basecurrency" name="basecurrency" scope="default" type="STRING" value="USD"/>
<property description="quotecurrency" name="quotecurrency" scope="default" type="STRING" value="LKR"/>
<property name="apos" scope="default" type="STRING" value="'"/>
<property description="exchangeratePath" expression="fn:concat(get-property('exchangeratePath'),'//jsonObject/exchangerate_data[basecurrency/currencyCode=',get-property('apos'),get-property('basecurrency'),get-property('apos'),' and quotecurrency/currencyCode=',get-property('apos'),get-property('quotecurrency'),get-property('apos'),']/buyingrate/text()')" name="exchangeratePath" scope="default" type="STRING"/>
<log level="custom">
<property expression="get-property('exchangeratePath')" name="exchangeratePath"/>
</log>
Logged value:
[2018-04-27 08:50:41,314] INFO - LogMediator exchangeratePath = //jsonObject/exchangerate_data[basecurrency/currencyCode='USD' and quotecurrency/currencyCode='LKR']/buyingrate/text()
I have checked tried the way mentioned in this answer.
解决方案
这是通过以下方式解决的:
<property description="exchangeratePath" expression="fn:concat(get-property('exchangeratePath'),'//jsonObject/exchangerate_data[basecurrency/currencyCode=',get-property('apos'),get-property('basecurrency'),get-property('apos'),' and quotecurrency/currencyCode=',get-property('apos'),get-property('quotecurrency'),get-property('apos'),']/buyingrate/text()')" name="exchangeratePath" scope="default" type="STRING"/>
<property description="exchangeRate" expression="evaluate($ctx:exchangeratePath)" name="exchangeRate" scope="default" type="STRING"/>
推荐阅读
- javascript - 如何在 Javascript 中的 Keycloak 中获取当前登录用户的密码?
- c++ - 必须打印到屏幕才能使程序正常工作
- cors - Blazor 和 Webapi Cors 支持
- python - 发生奇怪的错误 - discord.py 重写 json 操作
- .net-core - 缺少 OData 信封/上下文
- outlook - 如何使用 Rest API 从可共享日历访问其他用户的 Outlook 会议详细信息
- python - 根据匹配/包含另一个数据帧中特定列的值过滤数据帧
- javascript - 如何从另一个用 Javascript 编写的经典 asp 文件中包含用 Javascript 编写的经典 asp?
- clickhouse - Clickhouse 字符串字段磁盘使用情况:null vs empty
- python-3.x - 为什么要使用 str.format?