Use Cases
The requirement is to update overall status to PARTIAL if there is any failure record in the payload, i. e. item.status = "Failed"
Input:1 2 3 4 5 6 7 8 9 10 11 12 13 | { "status" : "SUCCESS" , "items" : [ { "accountId" : "10101xyzabc" , "status" : "Success" }, { "accountId" : "10102aaabbb" , "status" : "Failed" } ] } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | { "status" : "PARTIAL" , "items" : [ { "accountId" : "10101xyzabc" , "status" : "Success" }, { "accountId" : "10102aaabbb" , "status" : "Failed" } ] } |
Datawave 2.0
1 2 3 4 5 6 7 | %dw 2.0 output application/json --- { status: if (sizeOf(payload.items map($) filter ($.status == "Failed" )) > 0) "PARTIAL" else "SUCCESS" , items: payload.items } |
Complete Flow
The following is the complete flow. Please note that I have commented out the transformation payload to java. This is a big improvement of Mule 4 over mule 3.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | < flow name = "use-filterFlow" doc:id = "ddae1e7c-0e9c-424c-842a-5ac4ae018b21" > < http:listener doc:name = "Listener" doc:id = "f0a9f441-4585-4e81-969a-a2d10ad480d1" config-ref = "HTTP_Listener_config" path = "/mule4/poc/filter" > < ee:repeatable-file-store-stream > </ ee:repeatable-file-store-stream ></ http:listener > <!-- <ee:transform doc:name="Transform Message" doc:id="f471f35a-3050-43d8-99fe-dfd1fbb07292" > <ee:message > <ee:set-payload resource="dataweave/toJava.dwl" /> </ee:message> </ee:transform> --> < ee:transform doc:name = "Transform Message" doc:id = "c9ef1500-033f-48f6-92f0-a760c75188d3" > < ee:message > < ee:set-payload resource = "dataweave/useFilter.dwl" > </ ee:set-payload ></ ee:message > < ee:variables > </ ee:variables > </ ee:transform > < logger level = "INFO" doc:name = "Logger" doc:id = "9958ba07-b13b-4bea-82ea-a28696437345" message = "#[payload]" > </ logger ></ flow > |
Key Learnings
- sizeOf function
- filter function
- if else, in Dataweave 1.0, this will be when else
Hi Gary, are you still uploading videos? The Mule videos on youtube are fantastic, but they stopped 2 years ago. Are you uploading on a different platform these days?
ReplyDeleteThank you Bob for asking. Yes, this is my plan to upload new series of Video for Mule 4 shortly.
ReplyDeleteThanks for sharing this blog.This article gives lot of information.
ReplyDeleteMuleSoft Online Training
MuleSoft Training in Hyderabad
Very informative post for mulesoft developers.You can also visit goformule.com for mulesoft stuff.
ReplyDeleteIts very informative blog and useful article thank you for sharing with us , keep posting learn more
ReplyDeletemulesoft course | mulesoft course online