简体   繁体   中英

mule 3 XPR to dataweave 2.0 migration

In my case, I'm doing a migration from Mule 3 to Mule 4.

In Mule 4, xpr files are not supported for xml transformation.

So I converted the xpr file to dataweave 2.0.

Most of the logic was solved,but i don't know how to updated the DTOSteps value and DTOCoverage.@FullTermAmt = fullTermAmts.

mule 3 XPR: https://github.com/Manikandan99/XPR_conversion/blob/master/responseCISGExposure.xpr

My Mule 4 Application: https://github.com/Manikandan99/XPR_conversion/tree/master/xpr_validation

Input xml Request: https://github.com/Manikandan99/XPR_conversion/blob/master/xml_request.xml

Expected output xml response: https://github.com/Manikandan99/XPR_conversion/blob/master/responseCISGExposure.xpr

I've defined all the variables in the Mule 4 application.

Stackoverflow not allow me to post many lines of code, so i provided the github links. please go through it.

Please help me to solve it.

I updated the dataweave code in my mule 4 based on xpr file logic.

For auto increment, I've used the AtomicInteger and the inbuilt incrementAndGet() function in dataweave 2.0.

I added a dependency to my pom.xml:

<dependency>
<groupId>org.mule.module</groupId>
<artifactId>mule-java-module</artifactId>
<version>1.2.5</version>
<classifier>mule-plugin</classifier>
</dependency>

My dataweave 2.0 code:

%dw 2.0
import java!java::util::concurrent::atomic::AtomicInteger
var processFlag = 0
var stepOrder = 1
var subStepOrder = 1
var subSubStepOrder = 1
var multiChar = "X"
var coverageCd = "LIAB"
var fullTermAmts = vars.CISGOutput.Premium.FinalLiabPrem.Exposure.LIAB
var startingValue = AtomicInteger::new(0)
var instartingValue = AtomicInteger::new(0)
output application/xml
fun soutincrement() = Java::invoke('java.util.concurrent.atomic.AtomicInteger', 'incrementAndGet()', startingValue, {})
fun sinincrement() = Java::invoke('java.util.concurrent.atomic.AtomicInteger', 'incrementAndGet()', instartingValue, {})
fun transformSteps(x, index)=
    x filterObject ($$ as String != "DTOSteps") ++
    {
                    DTOSteps: transformNewSteps()
                    
    }
fun transformNewSteps()=
    {
        DTOStep @(Order:soutincrement(), Name:"Base Premium", Operation:"=", Factor: vars.CISGOutput.Factors.LIAB.BasePrem, Value: vars.CISGOutput.Factors.LIAB.BasePrem): DTOSteps: transformChildSteps(),
        DTOStep @(Order:soutincrement(), Name:"Large Premium Discount Plan", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.LPDP, Value: vars.CISGOutput.Factors.LIAB.LPDP): null,
        DTOStep @(Order:soutincrement(), Name:"IRPM", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.IRPM, Value: vars.CISGOutput.Factors.LIAB.IRPM): null,
        DTOStep @(Order:soutincrement(), Name:"Term Factor", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.Term, Value: vars.CISGOutput.Factors.LIAB.Term): null
    }
fun transformChildSteps()=
    {
        DTOStep @(Order:sinincrement(), Name:"Exposure", Operation:"=", Factor: vars.CISGOutput.Factors.LIAB.Exposure, Value: vars.CISGOutput.Factors.LIAB.Exposure): null,
        DTOStep @(Order:sinincrement(), Name:"Base Rate", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.BaseRate, Value: vars.CISGOutput.Factors.LIAB.BaseRate): null,
        DTOStep @(Order:sinincrement(), Name:"Territory", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.Terr, Value: vars.CISGOutput.Factors.LIAB.Terr): null,
        DTOStep @(Order:sinincrement(), Name:"ILF", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.Limit, Value: vars.CISGOutput.Factors.LIAB.Limit): null,
        DTOStep @(Order:sinincrement(), Name:"Med Pay", Operation:multiChar, Factor: vars.CISGOutput.Factors.LIAB.MedPay, Value: vars.CISGOutput.Factors.LIAB.BasePrem): null                                   
    }

fun transformCoverage(x, index)=
    x match {
      case is Object -> x mapObject 
        if ($$ as String == "DTOCoverage" and $$.@CoverageCd == "LIAB")
            { 
                DTOCoverage @(( $$.@ - "FullTermAmt" ), FullTermAmt: fullTermAmts): 
                    transformSteps($, index)
            }
        else 
            (($$): transformCoverage($, index+1)) 
      else -> $
    }
---
transformCoverage(payload,1)

Its work's but its not optimized well.

Hope it helpful for some how doing migration on xpr to dataweave.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM