vincentlowe

APDev Dataweave multi-record example

Feb 10th, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. %dw 2.0
  2. output application/json
  3. type Currency = String {format: "###.00"}
  4. type Flight = Object {class: "com.mulesoft.training.Flight"}
  5.  
  6. //var numSeats = 400
  7. //var numSeats = (x=400) -> x
  8. /*var numSeats = (planeType: String) ->
  9. if (planeType contains('737'))
  10. 150
  11. else
  12. 300
  13. */
  14. fun getNumSeats(planeType: String) =
  15. if (planeType contains('737'))
  16. 150
  17. else
  18. 300
  19.  
  20. fun normalizeModelName (planeType: String) =
  21. planeType replace /Boing/ with "Boeing"
  22. ---
  23. using (flights =
  24. payload..*return map (object, index) -> {
  25. destination: object.destination,
  26. price: object.price as Number as Currency,
  27. totalSeats: getNumSeats(object.planeType as String),
  28. availableSeats: object.emptySeats,
  29. planeType: upper(normalizeModelName(object.planeType)),
  30. departureDate: object.departureDate
  31. as Date {format: "yyyy/MM/dd"}
  32. as String {format: "MMM dd, yyyy"}
  33. } as Flight
  34. )
  35.  
  36. flights orderBy $.departureDate orderBy $.price
  37. distinctBy $ filter ($.availableSeats != "0")
Advertisement
Add Comment
Please, Sign In to add comment