Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %dw 2.0
- output application/json
- import * from dw::util::Values
- import dw::modules::ComplexData
- var passengerRecords = readUrl("classpath://passengerRecords.csv", "application/csv")
- var flightsWithDetails = payload
- var joinedPassengerAndFlights =
- dw::core::Arrays::join(
- passengerRecords as Array<Object>,
- flightsWithDetails..*flight as Array<Object>,
- (pass) -> pass."Flight Code",
- (flight) -> flight.flightCode
- )
- fun combineJoinResult(joinResult) =
- joinResult map (e,i) ->
- //e.l ++ e.r
- e.l - "Flight Code" ++ {flight @(code: e.r.flightCode):( e.r )}
- var reservationsXml = ComplexData::buildXmlObject(
- combineJoinResult(joinedPassengerAndFlights),
- "reservation"
- )
- fun updateAmerican (flight) =
- flight mapObject (v,k) ->
- k match {
- case "airlineName" -> (k): dw::core::Strings::capitalize(v) ++ " Airlines"
- case "flightCode" -> (k): v
- else -> (k): v
- }
- ---
- reservationsXml update {
- case lat at .reservations.*reservation.*flight.*destination.latitude ->
- lat as Number as String {format: "#,###.00"}
- case long at .reservations.*reservation.*flight.*destination.longitude ->
- long as Number as String {format: "#,###.00"}
- }
- update {
- case dest at .reservations.*reservation.*flight.*destination ->
- dest - "ICAO"
- case flight at .reservations.*reservation.*flight ->
- if (lower(flight.airlineName) ~= "american") updateAmerican(flight)
- else flight
- }
- //update {
- // case ph at .reservations.*reservation ->
- // mask field("Passenger Phone Number") with "*****"
- //
- //}
Advertisement
Add Comment
Please, Sign In to add comment