Фильтрация данных из JSON путем проверки условия с двумя свойствами - WSO2 ESB - PullRequest
0 голосов
/ 26 апреля 2018

Ниже приведен файл JSON:

    {
      "_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"
        }
      ]
    }

И из файла мне нужно отфильтровать курс покупки, где базовая валюта / код валюты равна доллару США, а котировочная / валютный код равен LKR.

Я пробовал ниже выражение:

<property description="quote1" expression="//jsonObject/exchangerate_data[basecurrency/currencyCode='USD' and quotecurrency/currencyCode='LKR']/buyingrate/text()" name="quote1" scope="default" type="STRING"/>

И я смогу получить цену покупки.

Но когда я делаю значения как свойства и пытаюсь получить цену покупки, она записывает точное выражение вместо значения.

<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>

Зарегистрированное значение:

[2018-04-27 08:50:41,314]  INFO - LogMediator exchangeratePath = //jsonObject/exchangerate_data[basecurrency/currencyCode='USD' and quotecurrency/currencyCode='LKR']/buyingrate/text()

Я проверил, попробовал способ, упомянутый в этот ответ .

1 Ответ

0 голосов
/ 29 апреля 2018

Это решается с помощью:

<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"/>
...