2. Agenda
•Introduction Of Organizers and Speakers
•Community Details!
•Integration with Local SFTP Server(RebexTinySftpServerBin-1.0.6)
•Dataweave Concepts
•Q & A
•Trivia Quiz
2
4. Speaker for the day!
4
PADMA BANDI
Cognizant
Sr. Integration Developer
5. Community Details
•Register for Meetups : https://meetups.mulesoft.com
•Register for Official Training platform : https://training.mulesoft.com
•MuleSoft forum : https://help.mulesoft.com
•For all blogs : https://blogs.mulesoft.com/
•Anypoint platform : https://anypoint.mulesoft.com
5
7. 2
Agenda
• SFTP – Local Setup
• Demonstration of using RebexTinySftpServerBin
• Dataweave Concepts
a. String Interpolation
b. ndjson
b. Recursive functions with match case
d. firstWith
8. 2
SFTP Local Setup
Usual Problems to connect to SFTP :
● Appropriate permissions.
● Waiting time for installation of test SFTP server.
● Difficulty to unit test code.
● Back and forth code changes to test with alternative
connectors.
Solution :
● Setup the local SFTP server.
● No change required to alter the code with alternative
connectors
● One such server is Rebex tiny SFTP Server .
9. 2
SFTP Local Setup
Rebex Tiny SFTP Server:
● Small minimalist, single-user
SFTP server for testing
purposes.
● Runs as a windows application.
● Just unzip and run ,
no installation needed.
https://www.rebex.net/tiny-sftp-server/
10. 2
SFTP Local Setup
Steps for connecting to Rebex Tiny SFTP from Mulesoft:
● Download and unpack the zip package.
https://www.rebex.net/tiny-sftp-server/#download
● Edit the config file with your username, password and root
directory details.
11. 2
SFTP Local Setup
● Add your flow in the Anypoint studio with SFTP connector
configuration.
12. 2
SFTP Local Setup
● Start your Rebex tiny SFTP server application and then test
your SFTP connector configuration.
13. 13
Dataweave
● Dataweave is a simple powerful tool used to query and
transform data inside Mule.
● It is a powerful engine that allows to transform data to and
from any kind if formats like JSON, XML, CSV, Pojos etc..
● This is a functional programming language designed for
transforming data.
14. 14
Dataweave : String Interpolation
● String interpolation is the process of evaluating a string literal
containing one or more placeholders, yielding a result in
which the placeholders are replaced by the corresponding
values.
● In simple words, it’s an alternative to concatenation in a
simpler way without using quoting and unquoting.
15. 15
Dataweave : ndjson
● ndjson : Newline Delimited JSON format.
● Usage : Most log formats like elastic search queries uses the
ndjson formats.
● Dataweave helps in the transformations with ndjson
● ndjson reader ignores all lines of ndjson data that are invalid
if skipInvalid=true
● MIME TYPE : application/x-ndjson
● Each line of ndjson is mapped to one object in the array
Example ndjson:
{"name": “David","lastName": “Ross"}
{"name": "Mariano","lastName": “Dekker"}
16. 16
Dataweave : ndjson
● Sample scenario of using ndjson:
To bulk update the records in an elastic index we use the ndjson format with the below
query:
Sample input JSON:
[{"id": "12345","empName": "David", "department" : "finance", "role": "TL"},
{"id": "123456","empName": "Kiran", "department": "payroll", "role": “TL"}
]
POST my_elastic_index/_bulk
{"update": {"_id": " 12345 "}}
{"doc": {"empName": " David","department": "finance","role": "TL"},"doc_as_upsert":
true}
{"update": {"_id": "00010783625"}}
{"doc": {"empName": "Kiran","department": "payroll","role": “TL"},"doc_as_upsert":
17. 17
Dataweave : Match case
● Instead of using multiple if and else condition we can use a
match case to determine the respective output.
● It behaves just as the switch statement in another languages.
Syntax:
inputExpression match {
case <condition> -> <routing expression>
case <condition> -> <routing expression>
else -> <default routing expression>
}
19. 19
Dataweave : Recursion with Match case
● A recursive function solves a particular problem by calling a copy
of itself.
● It’s a technique of making a function call itself.
● Scenarios :
a. We want to check for null values and recursively replace with “”
b. Wherever the number exists in the input payload change to 5
digit number recursively
c. Make all the first letters of the entire payload values to capital
Letters using recursion
d. Map to Key recursively
20. 20
Dataweave : Creating reusable functions
● A reusable code is the best standards of any programming
language.
● If a function can be reused at multiple places, defining it as
common function and calling at various flows makes the life
easier.
● For example , let’s see the conversion of string to decimals
and try to make it as a reusable function.
“1234.567” as Number as String {format: “0.00”} -> “1234.56”
If in another mapper we want the same function but with 3
decimal digits and in another with 4 digits and so on…
21. 21
Dataweave : firstWith
● firstWith returns the first element that satisfies the condition.
● This is similar to filter condition, but it stops at the first element that
satisfies the condition.
● Performance of firstWith may vary with filter.
22. 22
Dataweave : cumulative Additions using Reduce
● Let us see how to add cumulatively the number of quantities using
the reduce function.
25. Enter Your Full Valid Name (no nick Names are allowed)
Only those who have registered and joined the session will be
allowed!
1. Go to Browser
Enter :
quizizz.com/join
2. Wait for code
3. Enter your name