[英]for loops in Mule 3.8.4 | Dataweave 1.0
I need to do a string comparison on the incoming payload string with the existing list of product names from cache, as there will not be a exact match, first I need to remove last 3 chars from the incoming payload string and do a comparison with all the existing strings/product Names.我需要对传入的有效负载字符串与缓存中的现有产品名称列表进行字符串比较,因为不会有完全匹配,首先我需要从传入的有效负载字符串中删除最后 3 个字符并与所有字符进行比较现有的字符串/产品名称。 If I find a match then do other transformation.如果我找到匹配项,则进行其他转换。 else remove one more char from incoming payload string and compare again.否则从传入的有效负载字符串中再删除一个字符并再次比较。 I need to repeat this till the string size of incoming payload is =3 (no need to compare if the string size is less than 3)我需要重复此操作,直到传入有效负载的字符串大小为 =3(如果字符串大小小于 3,则无需比较)
Summary: i need to remove chars from right to left and do a string comparison总结:我需要从右到左删除字符并进行字符串比较
Imput Payload is as below:输入有效载荷如下:
{
"productPartNo": "MPN-400110",
"supplier": "70058",
"productCode": "02",
}
Need to compare the string "productPartNo" against the "partNumber" field from the below existing product list需要将字符串“productPartNo”与下面现有产品列表中的“partNumber”字段进行比较
{
"Product": [
{
"productNumber": "420475",
"created": "2012-10-28",
"partNumber": "C1F2PNEX71K9",
"codeNo": "7712",
"manufacturer": ""
},
{
"productNumber": "478376",
"created": "2017-12-12",
"partNumber": "N77-C77-RMK=",
"codeNo": "1589",
"manufacturer": "50884"
},
{
"productNumber": "478381",
"created": "2017-12-12",
"partNumber": "CON-U-C1F2PXNE",
"codeNo": "1586",
"manufacturer": "50884"
},
{
"productNumber": "478384",
"created": "2017-12-12",
"partNumber": "PMPN4070",
"codeNo": "1585",
"manufacturer": "50884"
}
]
}
In this case, my input string "productPartNo": "MPN-400110" should be compared with all the PartNumber.在这种情况下,我的输入字符串 "productPartNo": "MPN-400110" 应该与所有 PartNumber 进行比较。 After removing chars from last, the string 'MPN' will have the match/contain with the "partNumber": "PMPN4070" hence I should get the "codeNo": "1585" associated with partNumber-PMPN4070 as my output field.从最后删除字符后,字符串 'MPN' 将与“partNumber”匹配/包含:“PMPN4070”,因此我应该得到与 partNumber-PMPN4070 关联的“codeNo”:“1585”作为我的输出字段。
How can I implement this logic in %dw 1.0我如何在 %dw 1.0 中实现这个逻辑
This needed a little thinking and its late, not much brain power left, in the morning I may revise but its a good start given your sample data.这需要一点思考,而且它很晚,没有多少脑力了,早上我可能会修改,但鉴于您的样本数据,这是一个好的开始。 Just let me know if you have any further clarifications.如果您有任何进一步的说明,请告诉我。
Just copy and paste inside a Transform Message
processor and turn on the preview.只需复制并粘贴到Transform Message
处理器中,然后打开预览即可。
%dw 1.0
%output application/dw
%var products = {
"Product": [
{
"productNumber": "420475",
"created": "2012-10-28",
"partNumber": "C1F2PNEX71K9",
"codeNo": "7712",
"manufacturer": ""
},
{
"productNumber": "478376",
"created": "2017-12-12",
"partNumber": "N77-C77-RMK=",
"codeNo": "1589",
"manufacturer": "50884"
},
{
"productNumber": "478381",
"created": "2017-12-12",
"partNumber": "CON-U-C1F2PXNE",
"codeNo": "1586",
"manufacturer": "50884"
},
{
"productNumber": "478384",
"created": "2017-12-12",
"partNumber": "PMPN4070",
"codeNo": "1585",
"manufacturer": "50884"
}
]
}
%var inputPayload = {
"productPartNo": "MPN-400110",
"supplier": "70058",
"productCode": "02"
}
---
// Get a list with all the substrings to search with--this give you the following array
// ["MPN-400","MPN-40","MPN-4","MPN-","MPN"]
(4 to (sizeOf inputPayload.productPartNo ) - 2 map inputPayload.productPartNo[0 to -$]
map (
// Filter the list of products on the substring,
// this should either give you a matches or the empty list
// Finally, take the first match. I am not sure if this what you want.
(products.Product filter (e) -> (e.partNumber contains $))[0]
)
filter ($ != null))[0].codeNo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.