Mule ESB(Groovy 脚本):我将如何检查值并将新的键值映射添加到 java.util.LinkedList
Mule ESB (Groovy Script): How would I check a value and add a new key value mapping to a java.util.LinkedList
我正在调用一项服务,该服务 returns 数据来自 LinkedList 形式的数据库。我需要用一个名为 "status" 的新字段更新 LinkedList,该字段由 endDate 确定。
- endDate > 当前日期 => status=deactivated
- 结束日期 <= 当前日期 => 状态=有效
骡子有效载荷Class: java.util.LinkedList
Mule 载荷: [{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}]
我在 mule 中遇到的问题是我无法导航到链接列表以检索值以及向列表添加新值。希望有人能给我一些关于前进的最佳方式的建议。我正在尝试使用 groovy 变换器来更新有效负载,但效果不是很好,所以我没有任何代码可以展示。
感谢抽空!
我有类似的要求(有效负载是 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"
}
通过此转换,您可以迭代列表并根据您的要求添加状态值。
输入示例:
[{"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"}]
输出示例
[{"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"}]
希望对您有所帮助
我正在调用一项服务,该服务 returns 数据来自 LinkedList 形式的数据库。我需要用一个名为 "status" 的新字段更新 LinkedList,该字段由 endDate 确定。
- endDate > 当前日期 => status=deactivated
- 结束日期 <= 当前日期 => 状态=有效
骡子有效载荷Class: java.util.LinkedList
Mule 载荷: [{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}]
我在 mule 中遇到的问题是我无法导航到链接列表以检索值以及向列表添加新值。希望有人能给我一些关于前进的最佳方式的建议。我正在尝试使用 groovy 变换器来更新有效负载,但效果不是很好,所以我没有任何代码可以展示。
感谢抽空!
我有类似的要求(有效负载是 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"
}
通过此转换,您可以迭代列表并根据您的要求添加状态值。
输入示例:
[{"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"}]
输出示例
[{"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"}]
希望对您有所帮助