Basics of DWL and writing basic DWL expressions

Mule 4 Indepth DataWeave2 Transformations
18 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.18
List Price:  €95.97
You save:  €28.79
£55.86
List Price:  £79.80
You save:  £23.94
CA$97.87
List Price:  CA$139.82
You save:  CA$41.95
A$107.62
List Price:  A$153.75
You save:  A$46.13
S$94.24
List Price:  S$134.64
You save:  S$40.39
HK$544.83
List Price:  HK$778.36
You save:  HK$233.53
CHF 62.54
List Price:  CHF 89.34
You save:  CHF 26.80
NOK kr774.97
List Price:  NOK kr1,107.14
You save:  NOK kr332.17
DKK kr501
List Price:  DKK kr715.75
You save:  DKK kr214.74
NZ$119.95
List Price:  NZ$171.37
You save:  NZ$51.41
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,361.58
List Price:  ৳11,945.63
You save:  ৳3,584.04
₹5,909.84
List Price:  ₹8,442.99
You save:  ₹2,533.15
RM312.71
List Price:  RM446.75
You save:  RM134.04
₦118,484.88
List Price:  ₦169,271.38
You save:  ₦50,786.49
₨19,443.22
List Price:  ₨27,777.22
You save:  ₨8,334
฿2,412.28
List Price:  ฿3,446.26
You save:  ฿1,033.98
₺2,418.32
List Price:  ₺3,454.90
You save:  ₺1,036.57
B$406.01
List Price:  B$580.04
You save:  B$174.03
R1,267.89
List Price:  R1,811.35
You save:  R543.45
Лв131.37
List Price:  Лв187.69
You save:  Лв56.31
₩98,301.65
List Price:  ₩140,436.95
You save:  ₩42,135.30
₪259.10
List Price:  ₪370.16
You save:  ₪111.06
₱4,125.14
List Price:  ₱5,893.31
You save:  ₱1,768.17
¥10,832.35
List Price:  ¥15,475.45
You save:  ¥4,643.10
MX$1,429.79
List Price:  MX$2,042.64
You save:  MX$612.85
QR255.18
List Price:  QR364.56
You save:  QR109.38
P956.90
List Price:  P1,367.06
You save:  P410.16
KSh9,061.51
List Price:  KSh12,945.58
You save:  KSh3,884.06
E£3,475.01
List Price:  E£4,964.52
You save:  E£1,489.50
ብር8,566
List Price:  ብር12,237.67
You save:  ብር3,671.66
Kz63,900.87
List Price:  Kz91,290.87
You save:  Kz27,390
CLP$69,057.73
List Price:  CLP$98,658.13
You save:  CLP$29,600.40
CN¥506.93
List Price:  CN¥724.22
You save:  CN¥217.29
RD$4,217.06
List Price:  RD$6,024.63
You save:  RD$1,807.57
DA9,397.90
List Price:  DA13,426.15
You save:  DA4,028.25
FJ$159.29
List Price:  FJ$227.57
You save:  FJ$68.27
Q540.13
List Price:  Q771.64
You save:  Q231.51
GY$14,638.82
List Price:  GY$20,913.50
You save:  GY$6,274.67
ISK kr9,776.20
List Price:  ISK kr13,966.60
You save:  ISK kr4,190.40
DH703.91
List Price:  DH1,005.63
You save:  DH301.72
L1,275.33
List Price:  L1,821.98
You save:  L546.64
ден4,132.76
List Price:  ден5,904.20
You save:  ден1,771.43
MOP$561.01
List Price:  MOP$801.48
You save:  MOP$240.46
N$1,268.91
List Price:  N$1,812.81
You save:  N$543.90
C$2,574.70
List Price:  C$3,678.31
You save:  C$1,103.60
रु9,449.77
List Price:  रु13,500.25
You save:  रु4,050.48
S/265.32
List Price:  S/379.05
You save:  S/113.72
K281.71
List Price:  K402.47
You save:  K120.75
SAR262.77
List Price:  SAR375.40
You save:  SAR112.63
ZK1,934.92
List Price:  ZK2,764.29
You save:  ZK829.37
L334.42
List Price:  L477.77
You save:  L143.34
Kč1,702.59
List Price:  Kč2,432.37
You save:  Kč729.78
Ft27,646.05
List Price:  Ft39,496.05
You save:  Ft11,850
SEK kr772.42
List Price:  SEK kr1,103.50
You save:  SEK kr331.08
ARS$70,259.44
List Price:  ARS$100,374.93
You save:  ARS$30,115.49
Bs483.50
List Price:  Bs690.75
You save:  Bs207.24
COP$307,238.59
List Price:  COP$438,931.09
You save:  COP$131,692.49
₡35,641.51
List Price:  ₡50,918.63
You save:  ₡15,277.11
L1,768.23
List Price:  L2,526.16
You save:  L757.92
₲546,248.87
List Price:  ₲780,388.98
You save:  ₲234,140.10
$U2,983.14
List Price:  $U4,261.82
You save:  $U1,278.67
zł291.40
List Price:  zł416.31
You save:  zł124.90
Already have an account? Log In

Transcript

Welcome back. In this video we are going to understand more about data view transformation language. In earlier modules, we have understood about DDL we have written some basic transformations, but here we are going to dig deeper into it. Actually, before mule version three dot three, there was no data transformation language. There were different Transformers for different purposes. So, in mule three dot three or three or four I don't remember exactly but somewhere before around three or three or three or four.

They introduced the wl Data View transformation language a single solution for all of your transformation requirements. This dw is very simple. It is JSON like language, we see step by step and it is assumed that the performance of data view transformation language is six times better than the earlier approaches performance is so good. So it is recommended to write database expressions for all of your transformations from now. So let us see how to write some simple transformation to complex but in this video, we'll start understanding about transform message component. So what I want to do is in this module, I want to drag and drop or HTTP listener, I'm expecting a POST request to come.

So I'll configure this HTTP listener with a droid one slash get a badass slash transform. Okay, I'm expecting some Jason to come in post born. So actually, in this project, I have a sample file. I'm expecting a POST requests to Jason, here having SRC main resources, I have a sample product codebase. And I'm expecting a post to contain this, this kind of Jason, right, so I want to transform it, transform this Jason to Java, XML or again to another JSON. So what we'll do is simply drag and drop transform message component.

If you see in this transform methods component, there are three parts right now input part where it is showing some input metadata, like words the payload type, it's saying any attributes raw HTTP attributes, and in the output section, the output is undefined. And third section is, is a place where we write our dw expressions. And in this third part, you can see dash dash dash it is a separate line. So, what are we are coming What are we are having about as there's there's nothing but d wl headers were the first one says the DW versions which we're using is rod zero, and the output metadata type should be application slash Jason. Okay. Now I want to see some transformations, it's good to actually set some define some meta data of the payload.

So I know I'm expecting this product dot Jason content. Actually, whenever we are doing any transformation, we should be very clear about what is expected input format, and what is the expected output format. So now I clearly know what is the input format. So I can define the input payload by clicking on define. And here there is nothing I'll click on Add. I'll give name as a product, Jason okay.

And what is the type here I'll select it as Jason and I don't have schema I have an example. So I select example and I select from FFC mainly for this product dot Jason. So I gave the sample it identified all the keys okay selected. Now, you can see that on the left side the input will change, I will maximize this. So the input payload has a metadata right now with all this properties. Now, I will click on this preview window where you can see there is no preview at Shawn running the preview here.

You can update Actually the output metadata is Java. And I wrote curly braces, actually, as I told you, dw is similar to JSON. If you know Jason, curly braces means word map right an object. Here also you can see that when I wrote curly braces, you can see the metadata as like something like link to the hash map. So curly braces, empty curly braces give output as linkwood hash map, which is empty. Now what I'll do is here inside this, I want to have a key set p ID, colon.

Payload is implicit object, payload dot product right. Now, you can see here, the output. You can see the Preview. This is a map. Actually it is a hash map. And here you can see, the key is PD one is a number, and it is a Java dot Lang dot integer.

Now what I'll do is again, I'll do comma, I'll say p name is my one key p name, product name. colon, I want it with failure dot name. Now you can see the preview p name. The value is this one according to the sample data. Actually how to see the sample data you can right click and see any sample data. Yep, what our content of product or JSON is taken as sample.

According to the sample, the name is HP Pavillion laptop, that's what I got. And same p ID is one. Okay. Now I want to convert it back to Jason Yeah, p this left side Jason is converted back to this one. That's fine. Now I'll try to convert it back to XML.

I am getting an error saying two issues found. Why? Because whenever you're working with XML, XML has a root tag. We didn't specify anything about root. Here we're given key value pairs. Normally key becomes the tag name and value becomes the tag value.

Here I didn't mention anything about the router. So what I have to do is whenever I'm having an XML, I have to specify what will route tech. So what I'll do is I'll write simply productor colon empty parenthesis. Now you can see the root tag I have mentioned product and the body is empty. Now what I'll do is paste whatever I have got p ID and P name p, this P ID and P name became the tax inside the body. Now, I also wanted to get the images first image I want the image IMG SLA and I like payload or dot images actually can see images is of type error here in this case, whenever you have an array, you can access the elements of an error by using index images of zero images of one like that, right.

So I got images. So now you understand how to access an array. Okay. Then, I want this P ID to be an attribute to product tag right now p ID is a tag is it. I want it to be an attribute so what I can do is simply to this product I can use f symbol and I will write the brackets and then I'll press C now, p ID has become an attribute now you understood how to write an attribute by using it Okay. Now, we can see that P ad is a attribute grid, you understood how to write a basic XML.

Now, if you see here on the top, there is a drop down here which is saying this expression will be set as output payload. Right. Now, one thing I want to do is here if you see the XML the XML is containing the DW l inside it and it is not readable. It is difficult to read because XML and dw are Next, it will be good if I can externalize the DW. How, what I can do is I can fill up this transform message. And there's a button here edit current target.

Current target is payload and the source code is selected to be inlined. I want to give by file and I'll give a file name as product. xml Okay. Now, you can see that under SRC main resources this product XML dot DWT file created. If I just open it, see, this is the content whatever I wrote. Right.

Now I'll go back I'll just show you an XML view for this. You can see equals set payload resources pointing to the externalize define. So, now, you understood how to externalize the DWI by editing the current doc. Now, if you see the water expression I have written will be set as Taylor, what I want is I want to evaluate one more expression and set it as a flow variable or set as a variable. What I can do is I can click on plus add a new target. What I want to do is I want to add a variable and I want CRO variable name to be, say product name.

So, I want to create a variable with them. Main and I want the output a bit of P name. Okay, now we can see that there is one more output variable product name. Now what our expression I right here will be part of evaluated and its value will be set as a variable product name. So what I'll do is I'll say simply payload dot name, that's all. So, this expression is simple expression will be evaluated.

And its value will be set as product name. So like that, I can create one more variable if I want. I'll click on Create, again, another variable. Let it be in line. I don't want it to be a separate file. is a brand name Okay, so you're gonna say payload dot brand name.

So, the brand name is extracted it is stored inside another variable. But now if I click on Edit target, it was in line, I can even make it to go to file by reading a file name we name and say okay. Now you can see the XML if you see the XML he called set variable is called variable name his product name, what should be the readable file corresponding to it p name. Similarly, brand name v name.dw Select that you understood by using single transform message component, we are evaluating the content of this dw and setting it as payload. We are evaluating these contents of these variables and setting the variables, not only variables, you might have observed here, we can set some attributes also, I can just select here, click on Add a new target, here we can write an attribute. Right.

So here what you can do attributes is it has to be a key value pair, right? You have to make sure that you are right key value pairs. What are key value pairs? You're right here they set us at our just delete them. I don't want that. Okay, so when we payload into variables, now I want to debug and see what will happen Drag and drop a logger and configure it to print hash table.

Okay, now it is debug I want to debug right now as a running it's just so fast to kill that instance. Okay, now I debug and in the meanwhile, keep a breakpoint on this transform component. And now it is asking me to switch to debug perspective. Okay, I'd say yes. No. First man out of makeup post record asked to class so my guess is that check was or less transform so I'll go to postman for slash guys.

I want to Jason so copy the content of this product dot Jason another equation here yeah so now if I send this a see what lepen sending a Pisces to do perspective Yep. So payload you can see that it is a JSON right now before this is evaluated During the holidays in order I posted and there are no variables if I say f6 now it is here there are two variables you can see the name and the product name and the payload is an XML is it whatever I have actually written Exactly. So, now you understood how to use a transform message component to write a basic transformer transformer and also you understood how to set pay or how to set variables. Okay. Great. So, you have a lab right now after this video, you can just open this Transformers document and complete the exercise.

I'll see you next video, where we'll be discussing about some complex transformations.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.