In my case, I have updating DTOCoverageItem node FullTermAmt attribute value from the incoming request.
I have to restrict the DTOCoverageItem node updation, if does not contains DTOSteps as a child node.
Request:
<?xml version="1.0" encoding="UTF-8"?>
<DTOApplication id="Application-1054516507-2054171867" ApplicationNumber="QT-00009188" >
<DTOLine id="Line-1977956099-1487151749" StatusCd="Active" LineCd="CommercialAuto" FullTermAmt="0.00" RatingService="ManualRate" >
<DTORisk id="Risk-1669201459-335100744" TypeCd="CommercialVehicle" LocationRef="Location-95582176-1640749066" FullTermAmt="0.00" Status="Active" >
<DTOCoverage id="Coverage-8867140-2034354070" Status="Active" CoverageCd="CARGO" FullTermAmt="0.00" Description="Cargo">
<DTOCoverageItem id="CoverageItem-988993575-1827862517" Status="Active" CoverageItemCd="ScheduledItem" FullTermAmt="0.00" >
<DTOSteps id="Steps-CoverageItem-988993575-1827862517">
<DTOStep id="Step-CoverageItem-988993575-1827862517-FinalRate" Name="Final Rate" Factor="0.00" Value="13.60" Status="Cleared">
<DTOSteps id="Steps-Step-CoverageItem-988993575-1827862517-FinalRate">
<DTOStep id="Step-Step-CoverageItem-988993575-1827862517-FinalRate-BaseRate" Name="Base Rate" Operation="=" Factor="10.78" Value="0.00" Status="Cleared"/>
<DTOStep id="Step-Step-CoverageItem-988993575-1827862517-FinalRate-Theft" Name="Theft" Operation="+" Factor="2.10" Value="0.00" Status="Cleared"/>
<DTOStep id="Step-Step-CoverageItem-988993575-1827862517-FinalRate-EarnedFreight" Name="Earned Freight" Operation="+" Factor="0.72" Value="0.00" Status="Cleared"/>
<DTOStep id="Step-Step-CoverageItem-988993575-1827862517-FinalRate-RefrigerationBreakdown" Name="Refrigeration Breakdown" Operation="+" Factor="0.00" Value="13.60" Status="Cleared"/>
</DTOSteps>
</DTOStep>
<DTOStep id="Step-CoverageItem-988993575-1827862517-LimitPer1000" Name="Limit Per 1000" Operation="*" Factor="100.00" Value="0.00" Status="Cleared"/>
<DTOStep id="Step-CoverageItem-988993575-1827862517-Deductible" Name="Deductible" Operation="*" Factor="0.85" Value="0.00" Status="Cleared"/>
<DTOStep id="Step-CoverageItem-988993575-1827862517-ModFactor" Name="Mod Factor" Operation="*" Factor="1.21" Value="1399.00" Status="Cleared"/>
</DTOSteps>
<DTOLimit id="Limit-1790462058-1228558954" LimitCd="ItemLimit1"/>
<DTOCoverageData id="CoverageData-1696958602-512988804" CoverageDataCd="ClassCd" Value="CIced"/>
</DTOCoverageItem>
<DTOLimit id="Limit-1200709238-1764617886" LimitCd="Limit1" Value="100000"/>
<DTODeductible id="Deductible-99803092-61708522" DeductibleCd="Deductible1" Value="1000"/>
<DTOSteps id="Steps-Coverage-8867140-2034354070">
<DTOStep id="Step-Coverage-8867140-2034354070-ScheduledItem#1" Name="Scheduled Item #1" Desc="Iced or Refrigerated Produce" Operation="+" Factor="1399" Value="1399" Status="Cleared"/>
<DTOStep id="Step-Coverage-8867140-2034354070-ScheduledItem#2" Name="Scheduled Item #2" Desc="General Freight" Operation="+" Factor="0" Value="0" Status="Cleared"/>
</DTOSteps>
<DTOCoverageItem id="CoverageItem-1693945123-524500811" Status="Active" CoverageItemCd="ScheduledItem" FullTermAmt="0.00" >
<DTOLimit id="Limit-1312834274-1499345391" LimitCd="ItemLimit1"/>
<DTOCoverageData id="CoverageData-18362738-128450429" CoverageDataCd="ClassCd" Value="Cgene"/>
</DTOCoverageItem>
</DTOCoverage>
</DTORisk>
</DTOLine>
</DTOApplication>
Data weave 2.0 Code which i have:
%dw 2.0
output application/xml
fun CARGOtransformSteps(x, index)=
x match {
case is Object -> x mapObject
if ($$ as String == "DTOSteps")
{
DTOSteps: DTOStep @(Order:"1", Name:"Final Rate", Value: "1" ) : DTOSteps :null
}
else
(($$): $)
else -> $
}
fun CARGOtransformCoverage(x, index)=
x match {
case is Object -> x mapObject
if ($$ as String == "DTOCoverageItem" and $$.@CoverageItemCd == "ScheduledItem" and $$.@Status == "Active")
{
DTOCoverageItem @(( $$.@ - "FullTermAmt" ), FullTermAmt: "100" ): CARGOtransformSteps($, index)
}
else
(($$): CARGOtransformCoverage($, index+1))
else -> $
}
fun DTORisktransform(x, index)=
x match {
case is Object -> x mapObject
if ($$ as String == "DTORisk" and $$.@id == "Risk-1669201459-335100744" )
{
DTORisk @(( $$.@ )):
CARGOtransformCoverage($, index)
}
else
(($$): DTORisktransform($, index+1))
else -> $
}
---
DTORisktransform(payload,1)
The above dataweave code will updating the all DTOCoverageItem nodes, it's not restricting the update if it doesn't contains DTOSteps.
for the above code, the FullTermAmt values is updating as "100" in DTOCoverageItem. but it doesn't has DTOSteps as child.
Expected Response:
<?xml version='1.0' encoding='UTF-8'?>
<DTOApplication id="Application-1054516507-2054171867" ApplicationNumber="QT-00009188">
<DTOLine id="Line-1977956099-1487151749" StatusCd="Active" LineCd="CommercialAuto" FullTermAmt="0.00" RatingService="ManualRate">
<DTORisk id="Risk-1669201459-335100744" TypeCd="CommercialVehicle" LocationRef="Location-95582176-1640749066" FullTermAmt="0.00" Status="Active">
<DTOCoverage id="Coverage-8867140-2034354070" Status="Active" CoverageCd="CARGO" FullTermAmt="0.00" Description="Cargo">
<DTOCoverageItem id="CoverageItem-988993575-1827862517" Status="Active" CoverageItemCd="ScheduledItem" FullTermAmt="100">
<DTOSteps>
<DTOStep Order="1" Name="Final Rate" Value="1">
<DTOSteps/>
</DTOStep>
</DTOSteps>
<DTOLimit id="Limit-1790462058-1228558954" LimitCd="ItemLimit1"/>
<DTOCoverageData id="CoverageData-1696958602-512988804" CoverageDataCd="ClassCd" Value="CIced"/>
</DTOCoverageItem>
<DTOLimit id="Limit-1200709238-1764617886" LimitCd="Limit1" Value="100000"/>
<DTODeductible id="Deductible-99803092-61708522" DeductibleCd="Deductible1" Value="1000"/>
<DTOSteps id="Steps-Coverage-8867140-2034354070">
<DTOStep id="Step-Coverage-8867140-2034354070-ScheduledItem#1" Name="Scheduled Item #1" Desc="Iced or Refrigerated Produce" Operation="+" Factor="1399" Value="1399" Status="Cleared"/>
<DTOStep id="Step-Coverage-8867140-2034354070-ScheduledItem#2" Name="Scheduled Item #2" Desc="General Freight" Operation="+" Factor="0" Value="0" Status="Cleared"/>
</DTOSteps>
<DTOCoverageItem id="CoverageItem-1693945123-524500811" Status="Active" CoverageItemCd="ScheduledItem" FullTermAmt="0.00">
<DTOLimit id="Limit-1312834274-1499345391" LimitCd="ItemLimit1"/>
<DTOCoverageData id="CoverageData-18362738-128450429" CoverageDataCd="ClassCd" Value="Cgene"/>
</DTOCoverageItem>
</DTOCoverage>
</DTORisk>
</DTOLine>
</DTOApplication>