2017-09-14 4 views
0

私はキャッシュ内にオブジェクトストアを持っています。私はキャッシュからデータを取得し、その上にフィルタ条件を適用する必要があります。データウェアラブのフィルタ条件で動的fieldNameを渡す方法

ここでの要件は、リクエストで動的に表示されるfiledNameとfiledValueに基づいてデータを取得するためにapiを公開する必要があります。

サンプル要求:

https://localhost:8082/api/customer/filter?fieldName=customerId&fieldValue=101810 

私はdataweave内のデータをフィルタリングするためのリターンコードを持っていますが、それは動作しません。あなたはこの

%dw 1.0 
%output application/json 
--- 
payload.rows filter (("$.content." ++ flowVars.fieldName ++ ".content") as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> { 
    customerId: row.content.customerId.content as :string when row.content.customerId.content != null otherwise null, 
    customerName: row.content.customerName.content as :string when row.content.customerName.content != null otherwise null, 
    customerAddress:row.content.customerAddress.content as :string when row.content.customerAddress.content != null otherwise null 
}) 

に助けてくださいすることができますし、私はあなたが問題がセレクタに使用されるコードで、それは$.content[flowVars.fieldName].contentようにする必要があります。この

+0

はObjectStoreの中にフィールド名とfieldValueの設定やflowVars – AnupamBhusari

+0

我々ははcustomerIdかのようにフィールド名を取得するマッピングを上からこの フィールド名=はcustomerId&fieldValueの= 101810 – Gopi

+0

などの要求から来るクエリのparamsとしてそれらを取得しているために使用されるコードを投稿してくださいCustomerNameまたはCustomerAddressはデータをフィルタリングし、filedVauleはそのフィールドの対応する値です。[{ \t \t \t "ラベル": "530"、 \t \t \t "コンテンツ":{ \t \t \t \t「あなたは{ \t "行" と入力(JSON)を見つけてください。この – Gopi

答えて

1

に助けてくださいすることができ、エラー

Exception while executing: 
payload.rows filter (("$.content." ++ flowVars.fieldName ++ ".content") as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> { 
        ^
Type mismatch for '++' operator 
    found :object, :string 
    required :string, :string. 

の下に取得しています。完全なコードは

%dw 1.0 
%output application/json 
--- 
payload.rows filter (($.content[flowVars.fieldName].content) as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> { 
    customerId: row.content.customerId.content as :string when row.content.customerId.content != null otherwise null, 
    customerName: row.content.customerName.content as :string when row.content.customerName.content != null otherwise null, 
    customerAddress:row.content.customerAddress.content as :string when row.content.customerAddress.content != null otherwise null 
}) 

です。これは、あなたが入力したもので問題なく動作します。

このヘルプが必要です。

+0

それはfine.Thanks @anupambhusari作品。これに関連する文書をどこに見つけることができます。私にリンクを提供してください。 – Gopi

+0

[Datawave Selector](https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-selectors#alternative-syntax)を参照してください。 – AnupamBhusari

関連する問題