vincentlowe

Dataweave reservations

Apr 20th, 2021
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. %dw 2.0
  2. output application/json
  3. import * from dw::util::Values
  4.  
  5. import dw::modules::ComplexData
  6.  
  7. var passengerRecords = readUrl("classpath://passengerRecords.csv", "application/csv")
  8.  
  9. var flightsWithDetails = payload
  10.  
  11. var joinedPassengerAndFlights =
  12. dw::core::Arrays::join(
  13. passengerRecords as Array<Object>,
  14. flightsWithDetails..*flight as Array<Object>,
  15. (pass) -> pass."Flight Code",
  16. (flight) -> flight.flightCode
  17. )
  18.  
  19. fun combineJoinResult(joinResult) =
  20. joinResult map (e,i) ->
  21. //e.l ++ e.r
  22. e.l - "Flight Code" ++ {flight @(code: e.r.flightCode):( e.r )}
  23.  
  24. var reservationsXml = ComplexData::buildXmlObject(
  25. combineJoinResult(joinedPassengerAndFlights),
  26. "reservation"
  27. )
  28.  
  29. fun updateAmerican (flight) =
  30. flight mapObject (v,k) ->
  31. k match {
  32. case "airlineName" -> (k): dw::core::Strings::capitalize(v) ++ " Airlines"
  33. case "flightCode" -> (k): v
  34. else -> (k): v
  35. }
  36.  
  37. ---
  38. reservationsXml update {
  39. case lat at .reservations.*reservation.*flight.*destination.latitude ->
  40. lat as Number as String {format: "#,###.00"}
  41. case long at .reservations.*reservation.*flight.*destination.longitude ->
  42. long as Number as String {format: "#,###.00"}
  43. }
  44. update {
  45. case dest at .reservations.*reservation.*flight.*destination ->
  46. dest - "ICAO"
  47. case flight at .reservations.*reservation.*flight ->
  48. if (lower(flight.airlineName) ~= "american") updateAmerican(flight)
  49. else flight
  50. }
  51. //update {
  52. // case ph at .reservations.*reservation ->
  53. // mask field("Passenger Phone Number") with "*****"
  54. //
  55. //}
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment