2017-09-14 92 views
0

我在缓存中有数据,即objectstore。我需要从缓存中获取数据并在其上应用过滤条件。如何在dataweave mule的过滤条件中传递动态fieldName

这里需求是,我必须公开api来获取基于filedName和filedValue的数据,这些数据将在请求中动态生成。

样品要求:

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

帮助,我得到以下错误

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. 

可以请你在这个

+0

请发布其用于设置字段名和fieldValue方法在对象存储或flowVars – AnupamBhusari

+0

我们得到他们作为查询参数将来自这样 字段名=客户ID和fieldValue方法= 101810 – Gopi

+0

要求从上面的映射,我们会得到字段名作为客户ID或代码CustomerName或CustomerAddress来过滤数据,而filedVaule是该字段的相应值。[{ \t \t \t “标签”: “530”, \t \t \t “内容”:{ \t \t \t \t“可以请你在这个 – Gopi

回答

1

帮助的问题与用于选择的代码应该像$.content[flowVars.fieldName].content 。完整的代码将是

%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

请参考[Dataweave Selector](https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-selectors#alternative-syntax)。 – AnupamBhusari