SlideShare a Scribd company logo
1 of 28
Alexandra Martinez
Reviewing a Complex DataWeave
Transformation Use-case
2
● Functions (fun)
○ Parameters using types
○ Calling functions with 2 parameters
● Variables (var)
● do statement to create scopes (local variables)
● Object manipulation using object destructor {( )}
● If/else
● Selectors:
○ Index (array[0])
○ Range (1 to 10)
● Setting default values
● Core functions/operators
○ isEmpty, reduce, map, groupBy, flatten
○ Remove (-), Sum (+), Concatenation (++), Prepend (>>)
Solution will make use of the following:
Requirement
4
Input JSON structure to Output JSON structure
Requirement
5
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
Requirement
5
6
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
Requirement
6
7
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
Requirement
7
8
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
4. If there are EndOfConnection fields
that are true and this is not the last
object inside the Connections array,
create a new output object
containing all the false Connection
objects before this, and using this
last object’s TaxCode.
Requirement
8
9
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
4. If there are EndOfConnection fields
that are true and this is not the last
object inside the Connections array,
create a new output object
containing all the false Connection
objects before this, and using this
last object’s TaxCode.
5. Each AppliedConnections object in
the output must have:
1. A hardcoded Type value
“Connection”.
Requirement
9
Building the Solution
11
● DW Playground: https://dwl.mule.club/
● Input payload:
{"FlightOptions":[{"Connections":[{"ReferenceID":111,"TaxCode":"ABC","EndOfConnection":false},{"ReferenceID":222,"TaxCode":"DEF","EndOfConnection":true}]},{"
Connections":[{"ReferenceID":333,"TaxCode":"GHI","EndOfConnection":true},{"ReferenceID":444,"TaxCode":"JKL","EndOfConnection":true}]},{"Connections":[{"Ref
erenceID":555,"TaxCode":"MNO","EndOfConnection":false},{"ReferenceID":666,"TaxCode":"PQR","EndOfConnection":false},{"ReferenceID":777,"TaxCode":"STU","
EndOfConnection":false}]},{"Connections":[{"ReferenceID":888,"TaxCode":"VWX","EndOfConnection":false}]},{"Connections":[{"ReferenceID":999,"TaxCode":"MNO"
,"EndOfConnection":false},{"ReferenceID":101,"TaxCode":"PQR","EndOfConnection":true},{"ReferenceID":102,"TaxCode":"STU","EndOfConnection":false}]}]}
● Expected output:
[{"AppliedTaxCode":"DEF","AppliedConnections":[{"Type":"Connection","IndexValue":1},{"Type":"Connection","IndexValue":2}]},{"AppliedTaxCode":"GHI","AppliedCo
nnections":[{"Type":"Connection","IndexValue":3}]},{"AppliedTaxCode":"JKL","AppliedConnections":[{"Type":"Connection","IndexValue":4}]},{"AppliedTaxCode":"STU
","AppliedConnections":[{"Type":"Connection","IndexValue":5},{"Type":"Connection","IndexValue":6},{"Type":"Connection","IndexValue":7}]},{"AppliedTaxCode":"VW
X","AppliedConnections":[{"Type":"Connection","IndexValue":8}]},{"AppliedTaxCode":"PQR","AppliedConnections":[{"Type":"Connection","IndexValue":9},{"Type":"C
onnection","IndexValue":10}]},{"AppliedTaxCode":"STU","AppliedConnections":[{"Type":"Connection","IndexValue":11}]}]
● Format JSONs:
https://jsonformatter.curiousconcept.com/
Building the Solution
12
1) Extract the Connections arrays.
Building the Solution
13
2) Change all the EndOfConnection to true for the last Connection object from the Connections
array.
Building the Solution
14
3) flatten the array of arrays to be just one array.
Building the Solution
15
4) Add a new field to keep track of the object’s index, basing on the EndOfConnection field.
(For each EndOfConnection=true, stop incrementing the index.)
Building the Solution
Index 1
Index 2
Index 1
Index 1
Index 1
Index 3
Index 2
16
5) Add a new field to keep track of the final AppliedConnections object’s (first) index where the
object in question will be added.
Note: This is calculated using the object’s index + 1 (to start at 1) and then minus the previously
added indexBasedOnEOC field.
Building the Solution
Index 0
Index 2
Index 3
Index 4
17
6) Separate the objects based on the EndOfConnection value (true or false).
Building the Solution
18
7) Take only the objects that are inside the “true” list.
Building the Solution
19
8) Create the final output.
Building the Solution
Playing with the indexes
21
Playing with the indexes
1
2
1
1
1
2
3
1
1
1
2
Index based on
EndOfConnection
22
Playing with the indexes
Index based on
EndOfConnection index + 1
1
3
4
5
2 6
7
8
9
10
11
1
2
1
1
1
2
3
1
1
1
2
23
Playing with the indexes
Index based on
EndOfConnection
1-1=0
3-1=2
4-1=3
5-1=4
2-2=0 6-2=4
7-3=4
8-1=7
9-1=8
10-2=8
11-1=10
1
2
1
1
1
2
3
1
1
1
2
AppliedConnections
Index
(index+1) - indexBasedOnEOC
24
Playing with the indexes
Index based on
EndOfConnection
0
2
3
4
0 4
4
7
8
8
10
1
2
1
1
1
2
3
1
1
1
2
1+0=1
2+0=2
1+2=3
1+3=4
1+4=5
2+4=6
3+4=7
1+7=8
1+8=9
2+8=10
1+10=11
AppliedConnections
Index
(index+1) - indexBasedOnEOC
IndexValue
indexBasedOnEOC (or actualIndex or
actualNum) +
indexAppliedConnections
Try it yourself!
Code
● GitHub repository: https://github.com/alexandramartinez/reviewing-a-complex-dw-
transformation-use-case/
References
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-functions
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-variables
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-flow-control
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-selectors
● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-defaults
● https://docs.mulesoft.com/mule-runtime/3.9/dataweave-operators
● https://docs.mulesoft.com/mule-runtime/4.3/dw-operators
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-isempty
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-reduce
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-map
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-groupby
● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-flatten
Questions?

More Related Content

What's hot

04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructorHaresh Jaiswal
 
Flying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnightFlying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnightWiem Zine Elabidine
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaWiem Zine Elabidine
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cppgourav kottawar
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and eventsPrem Kumar Badri
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsMohammad Shaker
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Ontico
 
Scientific calcultor-Java
Scientific calcultor-JavaScientific calcultor-Java
Scientific calcultor-JavaShaibal Ahmed
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application javagthe
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQKnoldus Inc.
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a BossBob Tiernay
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 

What's hot (20)

ZIO Queue
ZIO QueueZIO Queue
ZIO Queue
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Berlin meetup
Berlin meetupBerlin meetup
Berlin meetup
 
Fiber supervision in ZIO
Fiber supervision in ZIOFiber supervision in ZIO
Fiber supervision in ZIO
 
Zio from Home
Zio from Home Zio from Home
Zio from Home
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
Flying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnightFlying Futures at the same sky can make the sun rise at midnight
Flying Futures at the same sky can make the sun rise at midnight
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in Scala
 
Intake 38 5
Intake 38 5Intake 38 5
Intake 38 5
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and events
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension Methods
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
 
Scientific calcultor-Java
Scientific calcultor-JavaScientific calcultor-Java
Scientific calcultor-Java
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQ
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 

Similar to Complex DataWeave Transformation

ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersBartosz Kosarzycki
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2ytoshima
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon) Doyun Hwang
 
Writing Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWriting Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWithTheBest
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...ikram_ahamed
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime
 
Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Fwdays
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189Mahmoud Samir Fayed
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Vagif Abilov
 
Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Frost
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptLaurence Svekis ✔
 
Qtprealtimescripts 110103234828-phpapp02
Qtprealtimescripts 110103234828-phpapp02Qtprealtimescripts 110103234828-phpapp02
Qtprealtimescripts 110103234828-phpapp02Pavan Kokkiripati
 
Qtp realtime scripts
Qtp realtime scriptsQtp realtime scripts
Qtp realtime scriptsRamu Palanki
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 
What\'s New in C# 4.0
What\'s New in C# 4.0What\'s New in C# 4.0
What\'s New in C# 4.0Eyal Vardi
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 

Similar to Complex DataWeave Transformation (20)

ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon)
 
Day 1
Day 1Day 1
Day 1
 
Writing Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWriting Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel Schulhof
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
 
Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#
 
Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
Qtprealtimescripts 110103234828-phpapp02
Qtprealtimescripts 110103234828-phpapp02Qtprealtimescripts 110103234828-phpapp02
Qtprealtimescripts 110103234828-phpapp02
 
Qtp realtime scripts
Qtp realtime scriptsQtp realtime scripts
Qtp realtime scripts
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
What\'s New in C# 4.0
What\'s New in C# 4.0What\'s New in C# 4.0
What\'s New in C# 4.0
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Dlr
DlrDlr
Dlr
 

More from Alexandra N. Martinez

Mejora tu productividad creando aplicaciones de Slack
Mejora tu productividad creando aplicaciones de SlackMejora tu productividad creando aplicaciones de Slack
Mejora tu productividad creando aplicaciones de SlackAlexandra N. Martinez
 
Women Who Mule - Workshop series #2: Ghost
Women Who Mule - Workshop series #2: GhostWomen Who Mule - Workshop series #2: Ghost
Women Who Mule - Workshop series #2: GhostAlexandra N. Martinez
 
Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...Alexandra N. Martinez
 
Toronto Virtual Meetup #12 - Testing Strategies and MUnit Test Recorder
Toronto Virtual Meetup #12 - Testing Strategies and MUnit Test RecorderToronto Virtual Meetup #12 - Testing Strategies and MUnit Test Recorder
Toronto Virtual Meetup #12 - Testing Strategies and MUnit Test RecorderAlexandra N. Martinez
 
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseToronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseAlexandra N. Martinez
 
Cómo generar e implementar monitoreo para aplicaciones de Mule
Cómo generar e implementar monitoreo para aplicaciones de MuleCómo generar e implementar monitoreo para aplicaciones de Mule
Cómo generar e implementar monitoreo para aplicaciones de MuleAlexandra N. Martinez
 
reCONNECT 2021 May Meetup - Women Who Mule #4
reCONNECT 2021 May Meetup - Women Who Mule #4reCONNECT 2021 May Meetup - Women Who Mule #4
reCONNECT 2021 May Meetup - Women Who Mule #4Alexandra N. Martinez
 
Women Who Mule - April Meetup (Diane Kesler's Journey)
Women Who Mule - April Meetup (Diane Kesler's Journey)Women Who Mule - April Meetup (Diane Kesler's Journey)
Women Who Mule - April Meetup (Diane Kesler's Journey)Alexandra N. Martinez
 
Toronto Virtual Meetup #9 - KPIs and metrics accelerator
Toronto Virtual Meetup #9 - KPIs and metrics acceleratorToronto Virtual Meetup #9 - KPIs and metrics accelerator
Toronto Virtual Meetup #9 - KPIs and metrics acceleratorAlexandra N. Martinez
 
What is munit and how to create your first unit test
What is munit and how to create your first unit testWhat is munit and how to create your first unit test
What is munit and how to create your first unit testAlexandra N. Martinez
 
Toronto Virtual Meetup #8 - Tips for Reusability
Toronto Virtual Meetup #8 - Tips for ReusabilityToronto Virtual Meetup #8 - Tips for Reusability
Toronto Virtual Meetup #8 - Tips for ReusabilityAlexandra N. Martinez
 
Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)
Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)
Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)Alexandra N. Martinez
 
Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...
Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...
Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...Alexandra N. Martinez
 
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB ArchitectureToronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB ArchitectureAlexandra N. Martinez
 
How to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in MuleHow to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in MuleAlexandra N. Martinez
 
Meetup en español #4 - MuleSoft para profesionales de Java
 Meetup en español #4 - MuleSoft para profesionales de Java Meetup en español #4 - MuleSoft para profesionales de Java
Meetup en español #4 - MuleSoft para profesionales de JavaAlexandra N. Martinez
 
Toronto Virtual Meetup #5 - API Security and Threats
Toronto Virtual Meetup #5 - API Security and ThreatsToronto Virtual Meetup #5 - API Security and Threats
Toronto Virtual Meetup #5 - API Security and ThreatsAlexandra N. Martinez
 

More from Alexandra N. Martinez (20)

Mejora tu productividad creando aplicaciones de Slack
Mejora tu productividad creando aplicaciones de SlackMejora tu productividad creando aplicaciones de Slack
Mejora tu productividad creando aplicaciones de Slack
 
Women Who Mule - Workshop series #2: Ghost
Women Who Mule - Workshop series #2: GhostWomen Who Mule - Workshop series #2: Ghost
Women Who Mule - Workshop series #2: Ghost
 
Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...Women Who Mule - Workshop series: Create your own blog from scratch without a...
Women Who Mule - Workshop series: Create your own blog from scratch without a...
 
Toronto Virtual Meetup #12 - Testing Strategies and MUnit Test Recorder
Toronto Virtual Meetup #12 - Testing Strategies and MUnit Test RecorderToronto Virtual Meetup #12 - Testing Strategies and MUnit Test Recorder
Toronto Virtual Meetup #12 - Testing Strategies and MUnit Test Recorder
 
Women Who Mule - June Meetup (EMEA)
Women Who Mule - June Meetup (EMEA)Women Who Mule - June Meetup (EMEA)
Women Who Mule - June Meetup (EMEA)
 
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseToronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
 
Cómo generar e implementar monitoreo para aplicaciones de Mule
Cómo generar e implementar monitoreo para aplicaciones de MuleCómo generar e implementar monitoreo para aplicaciones de Mule
Cómo generar e implementar monitoreo para aplicaciones de Mule
 
reCONNECT 2021 May Meetup - Women Who Mule #4
reCONNECT 2021 May Meetup - Women Who Mule #4reCONNECT 2021 May Meetup - Women Who Mule #4
reCONNECT 2021 May Meetup - Women Who Mule #4
 
Women Who Mule - April Meetup (Diane Kesler's Journey)
Women Who Mule - April Meetup (Diane Kesler's Journey)Women Who Mule - April Meetup (Diane Kesler's Journey)
Women Who Mule - April Meetup (Diane Kesler's Journey)
 
Toronto Virtual Meetup #9 - KPIs and metrics accelerator
Toronto Virtual Meetup #9 - KPIs and metrics acceleratorToronto Virtual Meetup #9 - KPIs and metrics accelerator
Toronto Virtual Meetup #9 - KPIs and metrics accelerator
 
Introduction to MuleSoft
Introduction to MuleSoftIntroduction to MuleSoft
Introduction to MuleSoft
 
What is munit and how to create your first unit test
What is munit and how to create your first unit testWhat is munit and how to create your first unit test
What is munit and how to create your first unit test
 
Truly Human part 1
Truly Human part 1Truly Human part 1
Truly Human part 1
 
Toronto Virtual Meetup #8 - Tips for Reusability
Toronto Virtual Meetup #8 - Tips for ReusabilityToronto Virtual Meetup #8 - Tips for Reusability
Toronto Virtual Meetup #8 - Tips for Reusability
 
Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)
Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)
Meetup en español #6 - MuleSoft para profesionales de Java (segunda edición)
 
Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...
Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...
Meetup en español #5 - Continuous Integration and Continuous Delivery (CI/CD)...
 
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB ArchitectureToronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
 
How to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in MuleHow to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in Mule
 
Meetup en español #4 - MuleSoft para profesionales de Java
 Meetup en español #4 - MuleSoft para profesionales de Java Meetup en español #4 - MuleSoft para profesionales de Java
Meetup en español #4 - MuleSoft para profesionales de Java
 
Toronto Virtual Meetup #5 - API Security and Threats
Toronto Virtual Meetup #5 - API Security and ThreatsToronto Virtual Meetup #5 - API Security and Threats
Toronto Virtual Meetup #5 - API Security and Threats
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Complex DataWeave Transformation

  • 1. Alexandra Martinez Reviewing a Complex DataWeave Transformation Use-case
  • 2. 2 ● Functions (fun) ○ Parameters using types ○ Calling functions with 2 parameters ● Variables (var) ● do statement to create scopes (local variables) ● Object manipulation using object destructor {( )} ● If/else ● Selectors: ○ Index (array[0]) ○ Range (1 to 10) ● Setting default values ● Core functions/operators ○ isEmpty, reduce, map, groupBy, flatten ○ Remove (-), Sum (+), Concatenation (++), Prepend (>>) Solution will make use of the following:
  • 4. 4 Input JSON structure to Output JSON structure Requirement
  • 5. 5 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. Requirement 5
  • 6. 6 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. Requirement 6
  • 7. 7 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. 3. If the EndOfConnection field is true, create a separate output object. Requirement 7
  • 8. 8 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. 3. If the EndOfConnection field is true, create a separate output object. 4. If there are EndOfConnection fields that are true and this is not the last object inside the Connections array, create a new output object containing all the false Connection objects before this, and using this last object’s TaxCode. Requirement 8
  • 9. 9 ● Logic: 1. For each object from the FlightOptions array, create one output object inside the output array. 2. The AppliedTaxCode will contain the value from the last Connection object. 3. If the EndOfConnection field is true, create a separate output object. 4. If there are EndOfConnection fields that are true and this is not the last object inside the Connections array, create a new output object containing all the false Connection objects before this, and using this last object’s TaxCode. 5. Each AppliedConnections object in the output must have: 1. A hardcoded Type value “Connection”. Requirement 9
  • 11. 11 ● DW Playground: https://dwl.mule.club/ ● Input payload: {"FlightOptions":[{"Connections":[{"ReferenceID":111,"TaxCode":"ABC","EndOfConnection":false},{"ReferenceID":222,"TaxCode":"DEF","EndOfConnection":true}]},{" Connections":[{"ReferenceID":333,"TaxCode":"GHI","EndOfConnection":true},{"ReferenceID":444,"TaxCode":"JKL","EndOfConnection":true}]},{"Connections":[{"Ref erenceID":555,"TaxCode":"MNO","EndOfConnection":false},{"ReferenceID":666,"TaxCode":"PQR","EndOfConnection":false},{"ReferenceID":777,"TaxCode":"STU"," EndOfConnection":false}]},{"Connections":[{"ReferenceID":888,"TaxCode":"VWX","EndOfConnection":false}]},{"Connections":[{"ReferenceID":999,"TaxCode":"MNO" ,"EndOfConnection":false},{"ReferenceID":101,"TaxCode":"PQR","EndOfConnection":true},{"ReferenceID":102,"TaxCode":"STU","EndOfConnection":false}]}]} ● Expected output: [{"AppliedTaxCode":"DEF","AppliedConnections":[{"Type":"Connection","IndexValue":1},{"Type":"Connection","IndexValue":2}]},{"AppliedTaxCode":"GHI","AppliedCo nnections":[{"Type":"Connection","IndexValue":3}]},{"AppliedTaxCode":"JKL","AppliedConnections":[{"Type":"Connection","IndexValue":4}]},{"AppliedTaxCode":"STU ","AppliedConnections":[{"Type":"Connection","IndexValue":5},{"Type":"Connection","IndexValue":6},{"Type":"Connection","IndexValue":7}]},{"AppliedTaxCode":"VW X","AppliedConnections":[{"Type":"Connection","IndexValue":8}]},{"AppliedTaxCode":"PQR","AppliedConnections":[{"Type":"Connection","IndexValue":9},{"Type":"C onnection","IndexValue":10}]},{"AppliedTaxCode":"STU","AppliedConnections":[{"Type":"Connection","IndexValue":11}]}] ● Format JSONs: https://jsonformatter.curiousconcept.com/ Building the Solution
  • 12. 12 1) Extract the Connections arrays. Building the Solution
  • 13. 13 2) Change all the EndOfConnection to true for the last Connection object from the Connections array. Building the Solution
  • 14. 14 3) flatten the array of arrays to be just one array. Building the Solution
  • 15. 15 4) Add a new field to keep track of the object’s index, basing on the EndOfConnection field. (For each EndOfConnection=true, stop incrementing the index.) Building the Solution Index 1 Index 2 Index 1 Index 1 Index 1 Index 3 Index 2
  • 16. 16 5) Add a new field to keep track of the final AppliedConnections object’s (first) index where the object in question will be added. Note: This is calculated using the object’s index + 1 (to start at 1) and then minus the previously added indexBasedOnEOC field. Building the Solution Index 0 Index 2 Index 3 Index 4
  • 17. 17 6) Separate the objects based on the EndOfConnection value (true or false). Building the Solution
  • 18. 18 7) Take only the objects that are inside the “true” list. Building the Solution
  • 19. 19 8) Create the final output. Building the Solution
  • 20. Playing with the indexes
  • 21. 21 Playing with the indexes 1 2 1 1 1 2 3 1 1 1 2 Index based on EndOfConnection
  • 22. 22 Playing with the indexes Index based on EndOfConnection index + 1 1 3 4 5 2 6 7 8 9 10 11 1 2 1 1 1 2 3 1 1 1 2
  • 23. 23 Playing with the indexes Index based on EndOfConnection 1-1=0 3-1=2 4-1=3 5-1=4 2-2=0 6-2=4 7-3=4 8-1=7 9-1=8 10-2=8 11-1=10 1 2 1 1 1 2 3 1 1 1 2 AppliedConnections Index (index+1) - indexBasedOnEOC
  • 24. 24 Playing with the indexes Index based on EndOfConnection 0 2 3 4 0 4 4 7 8 8 10 1 2 1 1 1 2 3 1 1 1 2 1+0=1 2+0=2 1+2=3 1+3=4 1+4=5 2+4=6 3+4=7 1+7=8 1+8=9 2+8=10 1+10=11 AppliedConnections Index (index+1) - indexBasedOnEOC IndexValue indexBasedOnEOC (or actualIndex or actualNum) + indexAppliedConnections
  • 26. Code ● GitHub repository: https://github.com/alexandramartinez/reviewing-a-complex-dw- transformation-use-case/
  • 27. References ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-functions ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-variables ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-flow-control ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-selectors ● https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-defaults ● https://docs.mulesoft.com/mule-runtime/3.9/dataweave-operators ● https://docs.mulesoft.com/mule-runtime/4.3/dw-operators ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-isempty ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-reduce ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-map ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-groupby ● https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-flatten