如何使用DataWeave 2.0基于XPR中的逻辑更新DToSteps节点值

发布于 2025-01-23 01:24:12 字数 2902 浏览 2 评论 0 原文

就我而言,我有两个有效载荷:DOMDRC和DOMPAYLOAD(第二有效载荷)。

我必须迭代层(子节点),并根据DOMDRC有效载荷中的值和含有等于“ y”的dompayload中的dtocoverage和dtoratearea的dtoStep值。

逻辑:

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)
        
        }
    }
}

整个XPR代码:

domdrc pareload(input): https://github.com/manikandan99/java-code-datawaweave-2/lob/main/main/mmain/mmain/domdrc_payload.xml

dom有效载荷(第二有效载荷)(输入): https://github.com/manikandan99/java-code-te-dataweave-2/blob/main/main/main/main/dom_payload(2nd).xml

预期输出:

xpr的逻辑:

https://github.com/manikandan99/java-code-to-dataweave-2/blob/main/main/logic_auto_auto_split_xpr.txt ://github.com/Manikandan99/java-code-to-dataweave-2/blob/main/transform_DOM_payload.dwl" rel="nofollow noreferrer">https://github.com/Manikandan99/java-code-to- dataweave-2/blob/main/transform_dom_payload.dwl

专家请浏览链接。

在m子3中,我使用表达式转换DOM有效载荷。在进行迁移时,由于m子4中表达组件的不可用。我想选择DataWeave 2.0。我已经连接了尝试的数据拖曳,但是我无法通过DOMDRC解决迭代,并从DOMDRC有效载荷中的Layer Node获取值,然后更新到IT DOM有效载荷DTOSTEPS。

请帮助我,并提前感谢。

关于如何将auto_split xpr转换为dataweave 2.0的任何想法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽蝶幻影 2025-01-30 01:24:12

我的两分钱:不要指望从XPR(无论是什么)直接迁移到数据驱动。我强烈建议您在不使用的那些Java功能的情况下从头开始进行此操作(我认为它们根本不需要)。
寻找您以前做过的其他类似问题,@ALED也对您有所帮助,似乎您真正需要的是了解DataWeave 2如何工作以及它必须解决您所拥有的要求的功能。

因此,我建议您查看以下内容:

官方文档可帮助您帮助您有用的信息与此。

但是,查看您在这里共享的摘要逻辑(Github中没有一个,因为有了示例和脚本,这根本不清楚),您可以从做类似的事情开始:

%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))   
}

我也建议您尝试抽象一下问题和特定(特定问题/问题,因为这是一个Q&一个网站,不要期望别人从您共享的代码中开发某些内容),请减少输入/预期数据的示例,以便此处的社区可以帮助您。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文