1

In my case, I have two payloads: domDRC and domPayload (2nd payload).

I have to iterate over the layer (child node) and update the DTOStep value of DTOCoverage and DTORateArea in domPayload based on values in layer of domDRC payload with InclFlag equal to "Y".

Logic:

nodes = domDRC.getRootElement().selectNodes("/Envelope/Body/rateResponse/RateResult/Layers/Layer","LayerNum");
for (Node node : nodes) {
    if (node.valueOf("InclFlag") == 'Y') {
        if ( (int) node.valueOf("LayerPremNonAuto") > 0) {      
                // NonAuto Layer
                //add the DTOStep in CEL DTOCoverage of 2 nd payload
                //add the DTOStep in DTORateArea of 2 nd payload and DTORateArea attributes values(AreaName, Description, FullTermAmt, FinalPremiumAmt, WrittenPremiumAmt)
                
        }
        if ( (int) node.valueOf("LayerPremAuto") > 0) {
                // Auto Layer
                //add the DTOStep in CEL DTOCoverage of 2 nd payload
                //add the DTOStep in DTORateArea of 2 nd payload and DTORateArea attributes values(AreaName, Description, FullTermAmt, FinalPremiumAmt, WrittenPremiumAmt)
        
        }
    }
}

Entire XPR code : https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/auto_split_update_DtoSteps.xpr

DomDRC Payload (input): https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/domDRC_payload.xml

Dom payload (2nd payload) (input): https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/dom_payload(2nd).xml

Expected output : https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/Expected_updated_dtosteps.xml

Logic of xpr : https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/logic_of_auto_split_xpr.txt

I tried dataweave : https://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/transform_DOM_payload.dwl

experts please go through the links.

In mule 3, I've used expression to transform the dom payload. while doing migration, due to unavailability of expression component in mule 4. I wanna go with dataweave 2.0. I've attached the dataweave tried but i couldn't solve the iteration over the domDRC and get the values from Layer node in domDRC payload, then update to it dom payload DTOSTEPS.

please help me on this and thanks in advance.

Any ideas on how to convert the auto_split xpr to dataweave 2.0?

codey_08
  • 249
  • 1
  • 11
  • 1
    What have you tried so far? You are not looking an answer for a problem, you're just asking someone else to do the work. – Adrian Kamycki Apr 21 '22 at 09:17
  • yeah i have tried dataweave, let me update it my question – codey_08 Apr 21 '22 at 10:56
  • I've updated my question with tried DWL. Thanks. – codey_08 Apr 21 '22 at 11:17
  • 1
    You will need to indicate the error with your DataWeave script. I believe you should focus your question in a simplified use case to resolve the logic, with a simpler input, output, or alternatively break down the issue into simpler steps. Stackoverflow is not a place to request for developments. It is a question and answer site. Also please avoid using abbreviations like XPR and DWL. They are not obvious and cause confusions. – aled Apr 21 '22 at 14:56
  • @aled, could you please help on this to solve the logic, this question helps someone how do migration from xpr to dataweave. – codey_08 Apr 21 '22 at 15:18
  • The logic of the Mule 3 script is not clear at all. What problem the DataWeave script has is also not clear. Help us to help you by providing a more focused and clear question. – aled Apr 21 '22 at 15:52
  • I've clearly explained and provided sufficient links. What doubt do you have about this question, if so please let me know aled? – codey_08 Apr 22 '22 at 09:14

1 Answers1

2

My two cents: don't expect a straightforward migration from XPR (whatever that is) to DataWeave. I'd strongly recommend you to do it from scratch without those Java functions you're using right now (I don't think they are necessary at all). Looking to other similar questions you did before, that @aled has kindly help you with, it seems that what you really need is to understand how DataWeave 2 works and the features it has to solve the requirements you have.

So, I'd recommend you to take a look at the following content:

The official documentation has quite useful information to help you with this.

Nonetheless, looking at the snippet logic you're sharing in here (no the ones in GitHub, since with the examples and scripts it's not clear at all), you can start by doing something like:

%dw 2.0
output application/xml 
var layers = payload.Envelope.Body.rateResponse.RateResult.Layers.*Layer
fun processLayers(layers) = do {
    var layersWithInclFlagY = layers filter ((item, index) -> item.InclFlag == 'Y')
    // var layersWithInclFlagY = layers[?$.InclFlag == 'Y'] //The same as above but with inline filter
    --- 
    layersWithInclFlagY map ((layer, index) -> processLayer(layer))
}

fun processLayer(layer) = processAutoLayer(processNonAutoLayer(layer))

fun processAutoLayer(layer) = 
if (layer.LayerPremAuto > 0)
    layer //DO SOMETHING
else layer

fun processNonAutoLayer(layer) = 
if (layer.LayerPremNonAuto > 0)
    layer //DO SOMETHING
else layer
---
Layers: {
    (Layer: processLayers(layers)) if (!isEmpty(layers))   
}

I also recommend you to try to abstract the problems and be specific (specific questions/problems, since this is a Q&A site, don't expect someone else to develop something from a code you share), reduce the examples for the input/expected data so the community in here can help you.