[英]Mule ESB (Groovy Script): How would I check a value and add a new key value mapping to a java.util.LinkedList
I am calling a service that returns data from a DB in the form of a LinkedList. 我正在调用以LinkedList形式从数据库返回数据的服务。 I need to update the LinkedList with a new field called "status" which is determined off of endDate. 我需要使用一个新的字段“ status”来更新LinkedList,该字段由endDate决定。
Mule Payload Class: java.util.LinkedList Mule有效载荷类: java.util.LinkedList
Mule Payload: [{serialNumber=, maintenanceId=12345, customerID=09890, startDate=2017-10-10 23:34:17, endDate=2018-10-10 23:34:17},{serialNumber=, maintenanceId=09091, customerID=74743, startDate=2014-8-16 23:34:17, endDate=2019-8-16 23:34:17}] ule子有效载荷: [{serialNumber =,maintenanceId = 12345,customerID = 09890,startDate = 2017-10-10 23:34:17,endDate = 2018-10-10 23:34:17},{serialNumber =,maintenanceId = 09091 ,customerID = 74743,startDate = 2014-8-16 23:34:17,endDate = 2019-8-16 23:34:17}]]
The issue I am having in mule is that I am unable to navigate into the linked list to retrieve the value as well as add a new value to the list. 我遇到的问题是,我无法导航到链接列表以检索值以及向列表添加新值。 Hoping someone could give me some advice on the best way to move forward. 希望有人能给我一些最好的前进方法的建议。 I am trying to use a groovy transformer to update the payload, but it's not going so well, so I don't have any code to show. 我正在尝试使用常规转换器来更新有效负载,但是效果不是很好,因此没有任何代码可显示。
Thanks taking the time! 感谢您抽出宝贵的时间!
I had a similar requirement (the payload was a JSON but it should work as well) and this is what I did using Dataweave (I added your data so it can be easier to understand). 我有一个类似的要求(有效负载是JSON,但它也应该工作),这就是我使用Dataweave所做的(我添加了数据,以便于理解)。
%dw 1.0
%output application/java
---
flowVars.input2 map {
serialNumber : $.serialNumber,
maintenanceId: $.maintenanceId,
customerID: $.customerID,
startDate: $.startDate,
endDate: $.endDate,
status: "deactivated" when $.endDate as :date {format:"yyyy-M-dd HH:mm:ss"} > (now as :date {format:"yyyy-M-dd HH:mm:ss"}) otherwise "activated"
}
With this transformation you iterate the list and add the status value based on your requirement. 通过此转换,您可以迭代列表并根据需要添加状态值。
Input example: 输入示例:
[{"serialNumber":"test1", "maintenanceId":"12345", "customerID":"09890", "startDate":"2017-10-10 23:34:17", "endDate":"2018-10-10 23:34:17"},{"serialNumber":"test2", "maintenanceId":"09091", "customerID":"74743", "startDate":"2014-8-15 23:34:17", "endDate":"2018-8-15 23:34:17"}]
Output example 输出示例
[{"serialNumber":"test1","maintenanceId":"12345","customerID":"09890","startDate":"2017-10-10 23:34:17","endDate":"2018-10-10 23:34:17","status":"deactivated"},{"serialNumber":"test2","maintenanceId":"09091","customerID":"74743","startDate":"2014-8-15 23:34:17","endDate":"2018-8-15 23:34:17","status":"activated"}]
Hope this helps you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.