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
€65.39
List Price:  €93.41
You save:  €28.02
£55.92
List Price:  £79.90
You save:  £23.97
CA$96.01
List Price:  CA$137.16
You save:  CA$41.15
A$107.15
List Price:  A$153.08
You save:  A$45.93
S$95.13
List Price:  S$135.90
You save:  S$40.77
HK$547.14
List Price:  HK$781.66
You save:  HK$234.52
CHF 63.86
List Price:  CHF 91.23
You save:  CHF 27.37
NOK kr775.40
List Price:  NOK kr1,107.76
You save:  NOK kr332.36
DKK kr487.78
List Price:  DKK kr696.86
You save:  DKK kr209.07
NZ$118.01
List Price:  NZ$168.60
You save:  NZ$50.58
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,680.49
List Price:  ৳10,972.60
You save:  ৳3,292.11
₹5,842.03
List Price:  ₹8,346.11
You save:  ₹2,504.08
RM332.86
List Price:  RM475.54
You save:  RM142.67
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,491.96
List Price:  ₨27,846.85
You save:  ₨8,354.89
฿2,586.09
List Price:  ฿3,694.58
You save:  ฿1,108.48
₺2,265.39
List Price:  ₺3,236.41
You save:  ₺971.02
B$363.53
List Price:  B$519.35
You save:  B$155.82
R1,302.64
List Price:  R1,861
You save:  R558.35
Лв127.90
List Price:  Лв182.73
You save:  Лв54.82
₩96,270.48
List Price:  ₩137,535.16
You save:  ₩41,264.67
₪262.29
List Price:  ₪374.71
You save:  ₪112.42
₱4,033.94
List Price:  ₱5,763.02
You save:  ₱1,729.07
¥10,867.12
List Price:  ¥15,525.12
You save:  ¥4,658
MX$1,187.12
List Price:  MX$1,695.96
You save:  MX$508.84
QR254.93
List Price:  QR364.20
You save:  QR109.27
P994.08
List Price:  P1,420.18
You save:  P426.09
KSh9,360.69
List Price:  KSh13,372.99
You save:  KSh4,012.30
E£3,358.63
List Price:  E£4,798.26
You save:  E£1,439.62
ብር4,003.77
List Price:  ብር5,719.92
You save:  ብር1,716.15
Kz58,546.63
List Price:  Kz83,641.63
You save:  Kz25,095
CLP$67,216.99
List Price:  CLP$96,028.39
You save:  CLP$28,811.40
CN¥506.70
List Price:  CN¥723.89
You save:  CN¥217.19
RD$4,073.53
List Price:  RD$5,819.58
You save:  RD$1,746.04
DA9,418.34
List Price:  DA13,455.35
You save:  DA4,037.01
FJ$158.31
List Price:  FJ$226.17
You save:  FJ$67.86
Q543.96
List Price:  Q777.12
You save:  Q233.16
GY$14,650.29
List Price:  GY$20,929.88
You save:  GY$6,279.59
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.71
List Price:  DH1,011.06
You save:  DH303.35
L1,237.78
List Price:  L1,768.33
You save:  L530.55
ден4,025.24
List Price:  ден5,750.59
You save:  ден1,725.35
MOP$563.96
List Price:  MOP$805.69
You save:  MOP$241.73
N$1,304.33
List Price:  N$1,863.42
You save:  N$559.08
C$2,570.38
List Price:  C$3,672.13
You save:  C$1,101.75
रु9,397.27
List Price:  रु13,425.24
You save:  रु4,027.97
S/263.43
List Price:  S/376.35
You save:  S/112.91
K270.11
List Price:  K385.89
You save:  K115.77
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,873.89
List Price:  ZK2,677.10
You save:  ZK803.21
L325.37
List Price:  L464.84
You save:  L139.46
Kč1,643.47
List Price:  Kč2,347.91
You save:  Kč704.44
Ft25,458.03
List Price:  Ft36,370.18
You save:  Ft10,912.14
SEK kr764.90
List Price:  SEK kr1,092.76
You save:  SEK kr327.86
ARS$61,327.27
List Price:  ARS$87,614.14
You save:  ARS$26,286.87
Bs483.57
List Price:  Bs690.85
You save:  Bs207.27
COP$273,218.78
List Price:  COP$390,329.27
You save:  COP$117,110.49
₡35,710.66
List Price:  ₡51,017.42
You save:  ₡15,306.75
L1,733.65
List Price:  L2,476.75
You save:  L743.09
₲524,442.73
List Price:  ₲749,236.02
You save:  ₲224,793.28
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł283.24
List Price:  zł404.64
You save:  zł121.40
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.