[英]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.