[英]dataweave 1.0 to 2.0 migration in mulesoft
我正在尝试将下面的数据编织从 1.0 转换为 2.0,但我尝试过的所有操作都会出现以下错误,例如评估表达式错误、无效输入“减少”和替换。
骡子 3 数据编织 1.0:
%dw 1.0
%output application/xml
%var basicPolicy = payload.DTOApplication.DTOBasicPolicy
%var insuredInfo = payload.DTOApplication.DTOInsured
%var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
%var lineLiability = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "Liability")][0]
%var lineProperty = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "CommercialProperty")][0]
%var lineProductLiability = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "ProductLiability")][0]
%var primaryClassTotalExposure = lineLiability.*DTORisk[?($.@Status == "Active" and $.@TypeCd == "Exposure")].*DTOGLClass[?($.@GLClassCode == primaryExposure)].@Exposure default [] reduce ((val,acc=0) -> acc + (val replace "\$" with "" replace "," with "") as :number)
%var primaryClassPLTotalExposure = lineProductLiability.*DTORisk[?($.@Status == "Active" and $.@TypeCd == "Exposure")].*DTOGLClass[?($.@GLClassCode == primaryExposurePL)].@Exposure default [] reduce ((val,acc=0) -> acc + (val replace "\$" with "" replace "," with "") as :number)
---
{
Policy: {
PolType: basicPolicy.@SubTypeCd default "",
Zip: insuredPrimaryAddr.@PostalCode[0..4] default "",
EffDate: basicPolicy.@EffectiveDt default "",
ExpDate: basicPolicy.@ExpirationDt default "",
EBCov: lineProperty.@EquipmentBreakdown default "No",
PolFeeOR2: payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt default "",
PolFeeOR: (payload.DTOApplication.DTOFeeOverrides.*DTOFeeOverride[?($.@Code == "POLF" and $.@OverrideInd == "Yes")][0].@Amount default "") when payload.DTOApplication.DTOFeeOverrides.*DTOFeeOverride[?($.@Code == "POLF" and $.@OverrideInd == "Yes")][0].@Amount != null
otherwise (payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt default "") when payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt != null
otherwise "",
LiabExp: primaryClassTotalExposure,
ProdExp: primaryClassPLTotalExposure
}
}
输入载荷: https://github.com/Manikandan99/rate-dtostep/blob/master/request.xml
预计 output: https://github.com/Manikandan99/rate-dtostep/blob/master/policy_response.xml
我试过数据编织 2.0:
%dw 2.0
output application/xml
var basicPolicy = payload.DTOApplication.DTOBasicPolicy
var insuredInfo = payload.DTOApplication.DTOInsured
var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
var lineLiability = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "Liability")][0]
var lineProperty = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "CommercialProperty")][0]
var lineProductLiability = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "ProductLiability")][0]
var primaryClassTotalExposure = lineLiability.*DTORisk[?($.@Status == "Active" and $.@TypeCd == "Exposure")].*DTOGLClass[?($.@GLClassCode == primaryExposure)].@Exposure default [] reduce ((val,acc=0) -> acc + (val replace "\$" with "" replace "," with "") as :number)
var primaryClassPLTotalExposure = lineProductLiability.*DTORisk[?($.@Status == "Active" and $.@TypeCd == "Exposure")].*DTOGLClass[?($.@GLClassCode == primaryExposurePL)].@Exposure default [] reduce ((val,acc=0) -> acc + (val replace "\$" with "" replace "," with "") as :number)
---
{
Policy: {
PolType: basicPolicy.@SubTypeCd default "",
Zip: insuredPrimaryAddr.@PostalCode[0 to 4] default "",
EffDate: basicPolicy.@EffectiveDt default "",
ExpDate: basicPolicy.@ExpirationDt default "",
EBCov: lineProperty.@EquipmentBreakdown default "No",
PolFeeOR2: payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt default "",
PolFeeOR: (payload.DTOApplication.DTOFeeOverrides.*DTOFeeOverride[?($.@Code == "POLF" and $.@OverrideInd == "Yes")][0].@Amount default "") when payload.DTOApplication.DTOFeeOverrides.*DTOFeeOverride[?($.@Code == "POLF" and $.@OverrideInd == "Yes")][0].@Amount != null
otherwise (payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt default "") when payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt != null
otherwise "",
LiabExp: primaryClassTotalExposure,
ProdExp: primaryClassPLTotalExposure
}
}
关于如何在 dataweave 2.0 中编写相同内容的任何想法?
在@AnuragSharma 的评论中再添加几点
GLClassCode == primaryExposure
,输入有效负载中不存在primaryExposure因此这将导致 null 值,您不能replace
function 与 null 一起使用default
值。 这里我设置为0。encoding="UTF-8"
为了测试您的代码,我已将GLClasscode 作为 CANDIS传递给您,就像您在有效负载中所拥有的那样。
注意->请同时检查您的括号。
%dw 2.0
output application/xml encoding="UTF-8"
var basicPolicy = payload.DTOApplication.DTOBasicPolicy
var insuredInfo = payload.DTOApplication.DTOInsured
var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
var lineLiability = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "Liability")][0]
var lineProperty = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "CommercialProperty")][0]
var lineProductLiability = payload.DTOApplication.*DTOLine[?($.@StatusCd == "Active" and $.@LineCd == "ProductLiability")][0]
var primaryClassTotalExposure = lineLiability.*DTORisk[?($.@Status == "Active" and $.@TypeCd == "Exposure")].*DTOGLClass[?($.@GLClassCode == "CANDIS")].@Exposure default [] reduce ($$++$) replace "\$" with "" replace "," with "" default 0 as Number
var primaryClassPLTotalExposure = lineProductLiability.*DTORisk[?($.@Status == "Active" and $.@TypeCd == "Exposure")].*DTOGLClass[?($.@GLClassCode == "CANDIS")].@Exposure default [] reduce ($$++$) replace "\$" with "" replace "," with "" default 0 as Number
---
{
Policy: {
PolType: basicPolicy.@SubTypeCd default "",
Zip: insuredPrimaryAddr.@PostalCode[0 to 4] default "",
EffDate: basicPolicy.@EffectiveDt default "",
ExpDate: basicPolicy.@ExpirationDt default "",
EBCov: lineProperty.@EquipmentBreakdown default "No",
PolFeeOR2: payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt default "",
PolFeeOR: if (payload.DTOApplication.DTOFeeOverrides.*DTOFeeOverride[?($.@Code == "POLF" and $.@OverrideInd == "Yes")][0].@Amount != null)
(payload.DTOApplication.DTOFeeOverrides.*DTOFeeOverride[?($.@Code == "POLF" and $.@OverrideInd == "Yes")][0].@Amount default "")
else if (payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt != null)
(payload.DTOApplication.*DTOFee[?($.@Status == "Active" and $.@RateDRCFeeInd == "No")][0].@FullTermAmt default "")
else "",
LiabExp: primaryClassTotalExposure,
ProdExp: primaryClassPLTotalExposure
}
}
Output
<?xml version='1.0' encoding='UTF-8'?>
<Policy>
<PolType>CNPK</PolType>
<Zip>80003</Zip>
<EffDate>20211117</EffDate>
<ExpDate>20221117</ExpDate>
<EBCov>Yes</EBCov>
<PolFeeOR2/>
<PolFeeOR/>
<LiabExp>2000000</LiabExp>
<ProdExp>0</ProdExp>
</Policy>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.