2017-09-14 11 views
0

캐시에 데이터가 저장되어 있습니다 (예 : objectstore). 캐시에서 데이터를 가져 와서 필터 조건을 적용해야합니다.데이터웨어 뮬의 필터 조건에서 동적 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에 fieldName에와 fieldValue의 설정 또는 flowVars – AnupamBhusari

+0

우리는 고객 ID를 또는 fieldName은 얻을 것이다지도 위에서이 은 fieldName = 고객 ID를 & fieldValue의 = 101,810 – Gopi

+0

같은 요청에서 올 것이다 검색어 매개 변수로를 점점에 사용되는 코드를 게시하시기 바랍니다 CustomerName 또는 CustomerAddress는 데이터를 필터링하고 filedVaule은 해당 필드의 해당 값입니다.[{ \t \t \t "라벨": "530", \t \t \t "내용": { \t \t \t \t "당신은 { \t"행 "등이 – 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

는 괜찮아 네의 @anupambhusari 작동합니다. 우리가 관련 문서를 찾을 수있는 곳. 당신은 나에게 링크를 제공 해주실 수 있습니까 – Gopi

+0

[Datawave Selector] (https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-selectors#alternative-syntax)를 참조하십시오. – AnupamBhusari