根据过滤器将两个JSON有效负载聚合为一个

时间:2018-09-02 23:14:12

标签: json mule dataweave mule-esb

我正在尝试将两个json负载聚合为一个。 json以下存储在有效负载中,

{
   "clients":[
      {
         "status":"IN",
         "clientSoftDeleteIndicator":"N",
         "roles":[
            {
               "clientRoleCodeDesc":"PRIMARY OWNER",
               "clientRoleCode":"PO",
               "roleEffDate":null,
               "clientRoleStatusCode":"IN",
               "clientRoleStatusCodeDesc":"INACTIVE",
               "roleSoftDeleteIndicator":"N",
               "contractID":"49006649"
            },
            {
               "clientRoleCodeDesc":"PRIMARY INSURED",
               "clientRoleCode":"PI",
               "roleEffDate":"2014-11-05",
               "clientRoleStatusCode":"IN",
               "clientRoleStatusCodeDesc":"INACTIVE",
               "roleSoftDeleteIndicator":"N",
               "contractID":"49006649"
            },
             {
               "clientRoleCodeDesc":"PRIMARY INSURED",
               "clientRoleCode":"PI",
               "roleEffDate":"2014-11-05",
               "clientRoleStatusCode":"IN",
               "clientRoleStatusCodeDesc":"INACTIVE",
               "roleSoftDeleteIndicator":"N",
               "contractID":"49006648"
            }
         ],
         "clientID":72341935,
         "statusDate":"2014-11-05",
         "party":{
            "tin4":"0346",
            "addresses":[
               {
                  "addrSoftDeleteIndicator":"N",
                  "city":"HOLLYWOOD",
                  "addressType":null,
                  "zip":"104620000",
                  "country":"U",
                  "line3":null,
                  "line2":null,
                  "line1":"5 MODEL OFFICE",
                  "county":null,
                  "state":"CA",
                  "validIndicator":null,
                  "preferredIndicator":null
               }
            ],
            "firstName":"SALLONARO",
            "middleName":null,
            "lastName":"PARETO",
            "personSoftDeleteIndicator":"N",
            "birthDate":"1987-11-10",
            "sufName":null,
            "preName":"MR",
            "tin":"103380346",
            "taxIdSoftDeleteIndicator":"N",
            "gender":"M",
            "phones":[

            ],
            "martialStatus":null,
            "emails":[

            ],
            "tinType":"U"
         },
         "statusDesc":"INACTIVE"
      }
   ]
}

及以下json存储在flowVariable contractVariable

{
   "contracts":[
      {
         "policyEffDate":null,
         "productCode":"97",
         "policyStatusDate":"2014-11-05",
         "cntrctSoftDeleteIndicator":"N",
         "contractID":"49006649",
         "adminSysCode":"FCT",
         "dataSourceCode":null,
         "policyStatus":"B3",
         "lobCode":null,
         "contractIssuerCode":null
      },
      {
         "policyEffDate":null,
         "productCode":"98",
         "policyStatusDate":"2015-11-05",
         "cntrctSoftDeleteIndicator":"N",
         "contractID":"49006648",
         "adminSysCode":"FCT",
         "dataSourceCode":null,
         "policyStatus":"B4",
         "lobCode":null,
         "contractIssuerCode":null
      }
   ]
}

我想在contractId匹配时将属性从flowVariable复制到有效负载中。

下面是我的代码段,但我所得到的只是空json

%dw 1.0
%output application/json
---
payload.clients.roles map ((role,index) ->
     {
    contracts: ((flowVars.contractVariable.contracts default []) filter (role.contractID == $.contractID)) 
                                            map ((contract ,indexOf)  -> {
        policyEffDate: contract.policyEffDate,
        productCode: contract.productCode,
        policyStatusDate: contract.policyStatusDate,
        cntrctSoftDeleteIndicator: contract.cntrctSoftDeleteIndicator,
        contractID: contract.contractID,
        adminSysCode: contract.adminSysCode,
        dataSourceCode: contract.dataSourceCode,
        policyStatus: contract.policyStatus,
        lobCode: contract.lobCode,
        contractIssuerCode: contract.contractIssuerCode,
        clientRoleCodeDesc: role.clientRoleCodeDesc,
        clientRoleCode: role.clientRoleCode,
        roleEffDate: role.roleEffDate,
        clientRoleStatusCode: role.clientRoleStatusCode,
        clientRoleStatusCodeDesc: role.clientRoleStatusCodeDesc,
        roleSoftDeleteIndicator: role.roleSoftDeleteIndicator,
        contractID: role.contractID
    })
})  

我得到的输出是

[
  {
    "contracts": [

    ]
  }
]

请有人帮助我解决问题,我尝试了多种方法,但无法正常工作。

我也经历了Aggregate two payloads in Mule ESB,这与我的要求类似,但是效果不佳。

我们非常感谢您的帮助。

0 个答案:

没有答案