MULESOFT TRAINING -:- SESSION 02 -:- MULESOFT DATAWEAVE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so today i will do uh first small recap what we did and then we will move to a new topic okay so first we understood like first yesterday we discussed about database like what is data wave and what all version we have then like how to use data with playground we went through that then we like i explained what all person we will use like where you will pass input where you can write database databases sorry database script and then where you will get output okay so this part actually we discussed like we have inline and file one so that we did some modification i will do correction in this ppt and then uh we discuss about the structure of data we have two part one is header and another one is body so in header what all you can define we discuss about everything like we can define database version then input type then output type we can define namespace we can define variable we can define function all those things we discuss in detail and then like we have gone through few example then we have discussed about input directory what all input directory data we support like application json application xml then application java application csv application dw text plane we discussed multiple formats yesterday we mostly we focused on json and xml since these two are very commonly used but today we will discuss about few other input type or output type that will be our application cs application csv one application database text plane all these we will see same we have in output type also similar to input type we have output type also okay and then like we have gone through few example okay so today we will start from this data rule okay so whenever we are discussing about data we variable function whatever new things we are defining there okay so we must need to follow some rule or some pattern it's not like that you can define any name or anything in variable or function there are certain rule we must need to follow okay so first rule is that name or function name or variable name must be start with alphabet okay it can be in lowercase it can be uppercase that will not create problem but it must be alphabet okay whenever you are defining any variable or any constant or any function you must need to follow this rule second in special character you can take only underscore you can take numbers and you can take later so letter should be a to z capital and small number one to ten anything and then underscore okay if you will take anything else like a part of this like other special character like dollar hash symbol then it will give you error okay and third thing is there you should not use user keyword in case of like whenever you are defining function or variable you you should not use reward reserved keyword and where you will get list of result keyword you will get in this link so i will share this ppt then you will able to open and you will able to see all the result keywords so you should not take digital keyword for your variable name for your function name okay so we'll see one small example here let me go to database so here i am trying to define one variable okay and here so this is working fine this is working perfectly since i followed that rule and i defined this now what i am trying to do i am trying to use some special current in variable name so you can see invalid input dollar expected alpha numeric okay it should be alpha numeric it should not be special character same way if i take any other special character again we are getting same error but in special character you can take underscore and after underscore you must need to put any alpha numeric it can be anything unable to your reference for abc okay sorry this one okay so name must contain alphanumeric and underscore only okay if you want to use number at the starting then again you will get problem okay so your main name variable name should not contain number at the starting it must be start with alphabet either it's a lowercase or uppercase it should contain a combination of alphabet plus numeric number plus underscore only okay it should not contain any special character and it should not be any keyword what reserve keyword we have in database we should not use that one so what all reserve keyword we have for example we have map function for map function we have reserved keyword map okay it's taking this map but it's a good practice don't use that special keyword yes sorry reserved keyword okay reserved keyword you can use but it's recommended you should not use real keyword since map is a function okay and we use that like a name for deserve keyword means we have that reserved keyword we should not use that one okay like this we have another result keyword some result keyword give will give you error also so better to avoid any kind of user keyword and you will get list in that particular link okay what is here what i will share with this ppt okay so here we have some example like abc underscore one two three a one two three a one two underscore q w jet these all are valid example of our variable name or function name we can use any of this so here we are going to do a small quiz so we have one two three four everyone need to tell in chat so which all is valid keyword and which all are not sorry which all are valid variable name and which all are not a valid variable name so put your answer like one two three four yes no yes no like okay let me go to chat let me see how many people got this idea what what should be valid and what should okay yeah i i think everyone seen my screen what what okay uh i think you need to reconnect other people are seeing so most probably there is some network issue from your side have sick and money you can monitor so i hope we are getting okay so i am moving to chat screen now let me see also like what answer is coming on or maybe i can split my screen into two part if i will split one and four is valid one and four three and four are not recommended one two yes i'm showing my screen again so you let me put in chat or otherwise oh sorry yes yes okay so i think uh now like we will go for answer so you can check how many of you have given correct answer so only for yeah so only valid answer is yes first one and other are not valid since here you can see number is on first place so it should not be a valid okay then here dollar so this this is like as i told you this is special character so special character should not be and then last one is type type is a keyword okay so we should not use this keyword also in place of variable name so only correct answer will be first yes and other will be no is it clear to everyone if anyone has any doubt you can ask quickly okay fine i think this is very easy part so hope everyone got it okay okay so here now so we will see how to like how to comment in database okay so here you can see we have one database script we have we can do multicom multiline comment and we can do single line comment to do multi-line comment it should be start with for what's less star then it should be end with back star backwards less similar to other programming language here also we can do multi-line comment if you want to do single line comment it should be two time four what's less okay so this this particular like way you can comment out particular part of your database script okay if you want to see it practically then here you can see so so for now you can see only this payload value so what we have inside payload you can see only payload value since this particular payload is not commented a part of this a part of this this one is commented and let's see this one is also commented now what i will do i will comment this thing and i will remove comment from here so you can see now we are getting payload.message in output previously we were getting entire payload since payload was not commented and payload dot message what was commented again i will comment this i will remove this then you will able to see entire payload okay you can see entire payload so we have flexibility here we can do single line comment and we can do multi-line comment so what i will do now i will remove this multi-line comment now you can see this particular script here okay so in database we have flexibility we can do single line comment and we can do multi-line comment okay same way in like whenever you will go to mule soft code there also you can do single line comment you can do multi-line comment so like there you will get some shortcut also to do this in data view like in this playground i am not sure they have given any shortcut or not i think they haven't but uh in any point studio you have some shortcut you can use that shortcut and you can do single or multiline comment okay hope everyone clear with this okay now in data view like whenever we are dealing with data so many place you will see special character okay so in data view how to deal with special character this is very much important so many time like whenever you are getting string or whenever you are like doing some operation you need to use that some special character okay so in that case like how you will deal with special character so here we are going to work on this so here you can see we have dollar sign so here we have one simple string that is a something so you can see here a something is coming that's fine string is there so string is coming as per expectation second you can see here dollar sign hmm okay so here we have one spec like we are we were discussing about special character so here you can see when i am taking this dollar sign slash like this backwards less and then dollar symbol then only dollar is coming here and if you will put direct dollar then it may give you some error let me quickly check okay so if i will use direct dollar see it's giving error so you can't use the dollar symbol dollar special character directly if you want this particular symbol in your string then you must need to use backwards loss before this same way with this single inverted comma in case of double inverted so comma you will see if you will put double inward comma with backwards less both will come okay and if i remove this then it will give you error okay so here we have some limitation with this double inverted comma but for other special character it will remove this backwards less and it will take that special character after this here you can use some combination also for example you want to use two time dollar so you need to write backward slash dollar backwards plus dollar i want to add single inverted comma so here okay now for single inverted comma it's taking doubles less okay so this this special backwards less after this we can use combination of special character also okay so here whenever you want to deal with special character you must need to be careful and you must need to use backwards less okay now in in in case of this uh double inverted comma as i mentioned you must need to use backwards less and whenever you will use this it will come with backward slash only but this behavior will change as per your data type what is your mimi type for output okay if it is json then it will behave like this but if you will go to xml okay so here you can see for this double slash it's coming doubleslash only sorry for this double inverted comma it's coming double inverted comma only so this behavior is dependent on your output type okay only for this double inverted comma for other dollar single inverted comma and for other special character behavior will be same but this behavior will change for this okay and only thing you need to like remember here that you must need to use this backwards less other combination you can check when you are working you have to some you you can do some data with poc and you can work on this okay so next this one is very important part of data view okay double backslash so single one you can write directly and double one yes so if you want to use this double backslash so first single one will treat it as normal okay and if you want to put another backslash then you need to write it two time is it clear so this these all things are part of compiler okay data view compiler okay so we don't have any control whatever logic they have created we must need to follow that one okay and in in worst case there may be some work around with the help of java if you want to use some special character and that is not handled by database then you must need to use your java code to handle those special characters and java is very much compatible to handle those special character but still in data wave we have flexibility you can handle multiple uh like a special character but if you are like finding some issue you are unable to handle then you should move with this java or you can write javascript okay as i remember like one time i have faced issue with database when i was dealing with this special character then i used javascript and i dissolved that issue so you need to like you need to be open like you have to search on google like what solution you are looking for if database capable then well and would otherwise go for javascript or java okay now this this particular thing is very much important in data view data with selector okay whenever you will write data v you must need to use some selector we already using some selector but now here we will do detailed discussion of this selected okay so till this point we are using first selector single value okay like payload dot message or something like we we used multiple time but so here you can see okay let me go with anyone so payload dot message okay this one is dot selector single value selector so what it will do it will select single value and it will display you here okay for example here we have message then we have name okay we have message and name it will select only this particular single value message from here okay if i want name then i want so we we use this single value selector very frequently and this single value selector is denoted by dot what we are using here okay next we have multivalued selector okay so what it will do so here you can see after dot we are placing star okay okay let me explain in this another way i think i have created one okay this one is like a good example to explain single value selected and multivalue selected so here you can see payload.users so this users dot user so what this single value selector will do out of this three user it will select first user and it will give you in output so we can see only we are getting weave okay now if i will convert this to single value to multi value so what it will do it will take all the matching key from here and it will display all the matching value so here you can see we bat tf all three having same user user user okay for this particular payload wherever you can see this particular key it will display value of all the key in add a format but single value it will select only it will take only one okay so this is like a difference between single value and multi-valued selector and like if you will say in real time then mostly we deal with this single like we use this multivalued one also but mostly you will use this single value okay there can be some business scenario where you need this multi-valued one okay next descendant so what it will do so dot dot i if you are from this linux or other background then you should know like this dot dot will give you descendant value same way in data web also we have dot dot for descendant value so if you go with one single simple example here so sorry so here payload dot dot so what it will do it will create one array okay and it will take all the descendant value so first descendant value will be user okay okay let me take in xml only or let me put in json so i hope everyone is more familiar with json so let me deal this everything okay okay yes so here you can see what i did here i took payload dot dot so first it will take create one array and it will take our first descendant this is this one starting from name to this then this particular we will yeah after this what it will do it will take another payload let me convert in xml only it was more clear to explain to jet okay fine it's not going back control yet is not working so here you can see now our what is next descendant so this user is not next descendant of this user okay so second one will come this particular user and then inside this we have another descendant is this one user so again it will come this particular descendant okay so this payload dot dot dot we will use very rarely but what it will do it will take all the descendant value one by one and it will display in adding okay but this particular thing you will use very rarely but other two what we are going to cover this two you will use very frequently okay so what i will do i will comment out this and try to understand in this one so here you can see payload dot dot name now it will not take care of like where you have name it will explore entire payload and it will check where all places you have name it will take all the name so first name is here web second name is here that third name is here bdd so it will take all three name let me put one more name here but here you can see that particular developer guide is not coming can anyone tell me reason why it's not coming so as i mentioned this payload dot dot name what it will do it will check all the descendant value and it will find where all we have name so name we it's coming here name bat it's coming here name bdd it's coming here okay but one particular name is not coming this name is not coming except this all name arkan can anyone tell me just now we covered this particular thing maybe 10 minutes back correct so here we did single value selector so what it will do in this particular name we have first name this second name this third name something okay let me take another name okay so it's it should be comma separated so it's taking only first name from each descendant so first descendant inside this user this second descendant is this third descendant is this okay so what it will do it will take first name from each descendant but if you want to select all name from each descendant then you need to use multi-value selector so now it's you can see here it's taking name web name bat and here inside this particular descendant we have three name it's taking all the three name okay hope everyone cleared with this okay next we have dynamics okay so dynamic one again like you will not use very frequently but yeah we have this capability so you should know how dynamic works everyone please go on mute so here we have output application json and then payload payload dot riff okay so here you can see let me format this okay so here first what i am taking here payload.ref what is the value of payload.rep name okay so this value will be name now inside payload i am taking name so payload dot instead of payload.name what i am giving here payload bracket name so what it will do here it will search this payload has in this particular payload where we have name keyword so it will select this and what is value here data v so it will take data view if you want here instead of this dynamic value you can hard code also it will also give you this value data v from this name key but here i want to make it dynamic i don't know what will come name will come or something else will come for example you have one input payload okay let's say you have one input payload okay and we don't know like what in from input which value i will take i will take data view i will take one or i will take abc okay so this thing should be decided at run time based on this ref value if ref value will contain name then i will take name if ref value will contain s then i will take h so how you will make this particular logic so here you need to define payload dot left now if i am passing in input if i am passing ref equals to h then it will take age value if i am passing this as a add it will take address value and if i will pass this as a name then it will take name value so in this way you can define dynamic selector in data view and this one is like very much important okay you should know then you will able to make your database logic very simple next we have key value pair okay so dollar key name object with the matching key okay this one i haven't used let me quickly check upset you have idea uh key value pair dot dollar key name okay this one actually i haven't used so i need to check i will i will explain later okay find next okay object with the matching key okay okay this one i will take or i hope i can i got it so payload then okay so what it will do from your object it will take key value pair both till this point if if you will put ref only then it will give you value of your reference okay but if you want this key also and value also then you will use this okay yeah this this one we use very rarely but yeah still if you should like you should know if okay so here we will get key value here both okay okay okay fine you say it like you are facing some issues and you use javascript to overcome that so what was that regarding like how you can use javascript and database asking okay so you're talking about our code or javascript no uh we have a scripting component if you go in mulesoft yeah so you will get a scripting component you can use that scripting component and you can write your javascript code here okay and if you are talking about scenario where i got so there was one scenario where i was getting like slash n was not working like i want to remove all the special character from my stream okay like slash and new line or whatever was there i want to make it single line stream okay at that time i was facing difficulty with the help of data view so what i did i retained one i explored on internet i got one javascript code which was like making all these which was removing all the special character from your listing you don't need to do anything then i used that scripting component and i returned the javascript and it worked perfectly so that was the scenario where i used okay if you are comfortable with java then using java also you can write java function and you can remove all the special characters yeah and then you can use database to call the java file that we will show in the coming session that is possible like you can call java using the data wave okay uh ravi we have other question like karthik is asking is there a way to use multi-value selector with dynamic selector okay so here we have here is the dynamic sector uh adding chica is saying like uh dynamic value but to achieve this we need to make changes in input she is asking that she or he like here's my dynamic value one oh i think this was [Music] any interview questions this one was the key prelude yeah that any interview questions in the database see if we cannot see you directly over here right now okay but whatever we are showing you you can just see that like this all our interview questions only like you can get questions like this okay okay okay here i will request focus on learning okay interview question is second part you should once you will learn this thoroughly you will able to answer all these interview scenario based question what is coming on data view okay but first focus on this concept okay everything can come from concept only first focus on concept once you will get concerned whatever scenario they will give you you will definitely be able to answer them okay okay okay so obviously what was that question so the question is is there a way to use multi-value selector with dynamic selector okay adding to that uh dynamic value but to achieve this we need to change the input and the third one again regarding this is where exactly we use this dynamic value this all were the questions see again like uh where exactly you will use so as i mentioned there can be some scenario where which key value you want okay value means what value you want from which key you don't know at the development time okay so you need to design your api in such a way you will pass which key you will select at runtime okay and during runtime what it will do it will take that particular key from where you are deciding which particular key i need to select for example i define i i passed name here then what it will do it will select name from all the key and it will take like it will print value so first objective of this dynamic value selector is at the development time you don't know which key value you want okay so you want to take decision at the run time then we should use this dynamic value selector okay now you are saying like it can be multi-valued or not that even i haven't explored so i will take this as a like i i will try to take this in next session i need to explore is it possible or not since uh like this this particular dynamic value selector is not frequently used so i don't have much exposure but yeah i will explore it on this part and i will try to answer this okay hope hope it's uh like i am able to answer and second part what i told i will try to take in next next session i need to explore a bit okay i'll see any any other question uh not much like someone is asking what filter and again about dynamic but filter will cover in another yeah okay fine so key value here is done next index one this index range this you will use very frequently okay this you need to understand and this one is like as i have experienced like we are using very frequently okay so let me take any example i have or not okay one example for this this is also fine so what i can do let me make it add a okay or or so here you can see like we have added and inside array we have repeating or object and each repeating object have message name and age okay now what i will do if i will write here payload dot message so what it will do or let me put only payload so what it will do inside payload we have added so entire array will come in your output okay okay fine so here you can see when i am taking payload so entire payload is coming but i want only but i want only this first element of our first object of our array so what you will do here you can write here payload zero so what you can see here it's taking first object helloworld1 developer guide 1 and age 1 if i will change this 0 to 1 then it will take second payload so you can take it you can see it's taking second payload here if i will change this payload four so four means index four means fifth payload so where we have fifth payload we have this one so it will take fifth payload it will take fifth payload so here you can see period so this particular selector this index selector you need to define index and it will take value from that particular index now what i want i want range of index for for example i want from this second payload to fifth payload so what will be my range second payload means index one then two fifth fifth payload means index will be four so you can see here it's taking second third four five it's taking from here to four now there may be some scenario i don't know what is my last index okay it can be five it can be ten it can be twenty so if if you don't know in that case you can write minus one okay minus one always represent last index or if you want you can put directly here also so if you don't know what is your last element then you can use minus one plus okay and if you want to give range then you can give like anything four to not four three two minus one so it will take from that index to last one three third index means fourth payload to last period okay so this index and range will work like this okay we have some other uh filter here so i will take important only i will not take all so another one is namespace okay yesterday someone asked what is namespace and like how it will deal with namespace how you will deal with namespace so today i have very good example for this okay first try to understand this here we have one payload where we have xml payload okay so this xml payload has two child tag see so this is this one is root tag and this root tag has two charity tag one is table another one is also table as i mentioned in yesterday like we have one society or colony where we have two house both house has like similar everything is similar paint door structure like like you can say whatever whatever decoration they have did from outside everything is 100 same then it will be difficult for someone to identify which like home or house he need to go so how he will identify he will identify through his house number okay so each house will have unique house number okay so here we are avoiding namespace conflict like we are avoiding we are not going to incorrect house same way in xml this two table you can see okay let me make it completely similar then you will get good idea h table f table and then now you can see this two table has everything next is close tag tr trtr td okay okay so here you can see both has completely same structure this table also and this table also this is inside this root tag now if i want to take value from this okay let me change value okay now if i want to take value from this one i want to take value from this table okay then how i will take and from this table how everything so only difference you can see here this name space here we are using h and here we are using f okay if you see data view coding here payload inside a we are taking payload inside paid payload we have root then inside root we have two tab one is h tag another one is f tag so value of h tag what is value of h tag here or let better let me take h only instead of html let me take h and f in here h f so here inside a we are taking value from payload dot root dot h tag table so where we have h tag hashtag value is tr html so where we have tr html this one okay so what it will do it will take this particular table all the structure of this two table are same if i will not put this it will get both places it will take first one okay it will not filter out all the table it will see what is first table and it will take if i will put star here it will take both the table means it will take multi value so here you can see h1 f1 h1 f1 okay but if you want to make call of specific table with some identifier what is the identifier here namespace in html for particular tag or particular root element if you want to put some identifier then you must need to define namespace so it will avoid any conflict between multiple multiple elements having similar structure or name okay so what will be syntax here if i want table from this namespace okay then i have to define h name space okay if i will not define anything then it will take first one if i will put star it will take all and if i want to take for particular one for f tag then we need to define h and for name space we use this half symbol okay this part is a bit complex so i'm giving a two minute of time if anyone has any query you can ask okay so this this particular keyword this particular keyword we use to define namespace okay this is keyword diff defined by dataview okay we don't have any control so this is their way of writing this name space okay so this is keyword to define any namespace this is name of namespace okay and this particular so whenever we define any namespace we used to give some url okay this is standard format to define any namespace okay same way we have defined another namespace fnamespace so keyword should be ns the name of that name space and then some url which denote or which help you to make it unique okay and now to use that namespace syntax will be h namespace name and then hashing wall again this is like way of data view compiler to understand or to write code okay i hope she'll be i'm able to answer your query still if you have any query you can ask yes yes yeah correct so if like your you are calling some external system and that is soap service and they follow some name space without tap name space like you are not getting means many places uh like in in xml actually we have to follow like many strict rule okay if they have defined their soap service like you are calling any external soap service and when they are taking value from their input they are taking they are defining name space also okay i'm not so like if anyone know this particular thing like in web service if you will not you if you want if you don't want to force name space you can use star okay and if you want to force namespace then you need you must need to give namespace name if that external service has used that namespace name and if you will pass something else then it will create problem for them okay they will not able to give you expected detail and if they have used start then whatever name space you will pass or if you will not pass name space that external service will give you response okay it depends on external service if that external service must need particular name space then only it will give you success response in that case only you need to handle this in this way otherwise you are good to go ahead without name space yes domain name domain name is url only correct actually standard actually i don't think like there is another standard standard is always this only you have okay yeah it's also domain name you know this is also domain name only this is also domain name only so you can use any domain but yeah that should be specific to company like for which client you are working and that should be specific to exams that should be some relevant name it should not be like you can put anything okay fine then yeah that that should not work that will give you error then krishna you want to elaborate your question okay or dave is asking any error relevant to xml in database causes schema validation error then that that can be possible if you are passing uh okay you got it uh if you are passing a wrong input which which doesn't satisfy this structure then then that can be a bad request okay we can move forward yeah okay so other other like uh data web selectors are there which we use very rarely but whatever i we discuss first focus on this and this all selectors you will use very frequently and if you have good understanding you will able to write all the data code and everything now uh yesterday we discussed about few uh supported data format like yesterday we were more focused on this application json and application xml today we will see some more data type okay data format like dw csv then text plane which we use frequently only okay i will not cover all but i will i will try to take you through most commonly used data type okay what you should know okay so first let's start with csv one or dw1 okay i have one example here for dw1 so this particular dw okay now this one application dw okay so this dw data type we can use and you can convert particular request format it can be like csb it can be json and dw will convert in standard this is another standard format which will convert in database language format messaging format okay but uh this this particular messaging format also we will not use very frequently but you should know like there is one more messaging format is there that is dw1 and it will convert your input payload into you can see here output is dwm okay and it's converting it's very similar to json kind of thing okay second and like second csv format that you must need to use multiple places okay and you should have good understanding so here you can see in cs like here we have request in json format like first name last name sex employee id email address country date of birth so these all are input in json payload i want to convert into csv format okay so what will be my syntax so here output should be application csb this one i commented so first ignore this one so output will be application csbc money check [Music] okay so here i am taking this payload and output type is application csv so you can see here automatically this particular json converted into csv format and csv format is comma separated one okay you can define your on separator and you can convert in that particular format okay selector you can select and if here you can see this this particular thing juan write mail everything name then last name everything coming without single like double inverted comma if you want to make it if you want to make it like john should be a double inverted comma right should be double inverted comma then you can uncheck this code value so if you will code value true then see everything is coming inside this double inverted comma what what is our expected or like request value it it's coming in same way and if you will make it if you will remove this by default it will take false same way we have separator also but long back i use separator so let me see if i can remember syntax so we can define our own separator also for example slashers less n separator okay let me quickly check if i can get any separator and for separator you can't use direct name you must need to use their special character like how we are defining so yeah these all things are there you can define header skip character you can define then separate okay separator by default it's comma separated but if you want you can define on your own so let me quickly check okay here they have given they haven't given any syntax to use separator but what i can use what i can remember so separate a keyword but also anything else right yeah separator also we will suggest data we will suggest like if you have written anything wrong so it will be as epa rtr sorry sorry s e p e a p a s e e will not be done yeah okay and let me use okay the separator one is not working i will explode and i will explain in next session but here you can define your own separator but by default it will take comma separated one okay no but try it uh before code values right before that and also try it like someone was asking about header let me get the separator so we have multiple separator actually we have pipe delimited we have comma separated okay so it depends on your csv file like what what csv file you want to generate and what separator you want to put so maybe it's not working in this playground remove yeah okay okay working working yeah so here you can see now i am using separator pipe delimited one okay so if you will use pipe delimited separator so you can see here everything is coming in pipe delimited form okay so if in this way you can define your separator also okay instead of comma if i want single invert so see everything is now coming with single inverted comma okay so in this way you can define your on separator and you can generate your csv file so by default like many like by default it will come comma separated one many places you will use comma like 80 cases i will say we are using comma separated but there may be some specific requirement if you are connecting with any ibm system then mostly they follow this pipe delimited one okay if in case of like whenever i am connecting with ibm system i observe this they prefer this pipe delimited i don't know is there any constant from their side or it's easy to handle but i observe this so pipe delimited also you will use very frequently a part of that other i i haven't observed like other special character you will use as lesson like it's after every record for example we have here multi-valued recorder this is in array okay ravi can you do some example with headers like i'm getting a few questions on headers okay i'm going so here you can see now we have to record so this key is coming one time and how many time we will have record those many of records will be created here and this is any csb format i hope everyone got this like how to convert any messaging format in csv format yeah and by default header is true so if you don't define header equal to true in the upper part then also you will get the first first line as the fields water fields are that if you don't want that field then you can do it header is false okay okay yeah header one if you want to define by default it will be true okay so let's header line number uh okay no the upper one this is this is the header is true or false you can do okay so here header is true if you want to make it fall okay what is difference here header is true so you can see here this particular key is coming here first name last name tax employee id email address country this all key is coming here if you will make it false then that key will not come only you will get value okay and here i can see you can define index of your header also so header line number you can define index which line you will consider as a hidden that also you can define okay hope everyone cleared with this uh csv format yeah quite good would you like to try like header false comma separator pipeline okay no put comma okay let me try first like this yeah first i'm trying like this and then so you should give a comma okay okay we can move forward yeah you can check if we have any query now other messaging format we have this uh okay data we already covered text plane okay so it will give you a text plane value let's say we have this json payload okay and i want text plane value so it will give you here you can see we are getting text value okay so you if you want you can convert your data type into particular format same way if you want to convert in java you can convert in java so for java syntax will be application slash java okay so you can see here output type is application java okay so this this particular data wave output type is very much important so based on different different scenario you need to convert in different different format and you should have good understanding of this okay now so till this point we have learnt about different data type the data type and what all like basic thing we should do now i will slowly move to any point studio and i will show you so till this point we did everything inside this platform this uh dw lang dot fun but if you want to do similar kind of practice in your any point studio so how you will do this so let me share with you okay so here i created simple mule application first i will explain this what i created and then i will do everything from scratch okay then you will get complete understanding so here what you can see i have one mule application okay it's taking time to load let it load so till this point we seen we can write this database script okay and we can get expected result okay so here we have preview option and we can see response here here like till this point we seen we can write here code and we will get response here but in data view we have this like feature also you can drag and drop and you can do mapping for example here i have location address and i want to map this location address with or let me take what is this this is detail and in input data attribute relationship author data id type include yeah we have this name inside this attribute we have name and here we have detail inside this we have name agent gender so i want to map name of attribute with name of details so how we can map so we can drag and we can drop it here so you can see here automatically it will generate database script for you okay so this is the another feature we have in datavip we can drag and drop and we can generate our data view code if you remember our first session i i explained that like we have two way of writing data with code so one is graphical map field another one we can write data view script so right now we are discussing this graphical map field how we can make it graphically so you don't need to write code if you are not very good in database you can use this particular way but here you will have like you can do limited thing only like if you want to do some further processing then it will be difficult from here but in other integration technology what i observed they have much more capability you can add function in between but in until this point in mulesoft they haven't added that feature if that feature will be added then yeah you don't need to learn this database script also you can do everything from here but till this point so far we have that limitation so you must need to have data view scripting knowledge but you can take initial help of mapping from here i want to say till this point only name is mapped with name i want to add map with ace to edge now easy also added okay now you will see how you will create this input structure how you will create output structure and how everything will be created and you can see here in preview you will get response also like what what value is mapping here so first i will explain how you will create this input type how we will create output type and how you will do mapping okay let me create one project from scratch i hope everyone got understanding what we are going to do now i am doing from scratch i am creating new mule project okay and i'm taking one http listener then i am taking one transform message i am taking one logger so for listener i am doing some small configuration okay now i want to take so here you can see in input i am not getting any other things i am getting attributes i am getting but in payload i am not getting anything inside variable i am not getting anything for output also i am not getting inside and i am not getting anything in payload ok so we will not able to do mapping we need to do everything from script but if you want to make your task a bit easy and if you know what is your input and what is your output structure then it will be very easy for you to create here mapping okay so first let me help you to create two structure one for input one for output and then we will do mapping okay so first i am creating structure of input so in input my json payload will contain first name okay so always try to use camel case everywhere in mulesoft whatever name whatever you are defining application name file name folder name huge camel case first name developer last name guide plus nine one while number okay then address line one then city mobile number thanks okay so this is our input payload okay so what i will do first i will save this input payload okay this is my okay data sample or sample data sample request data dot json okay save this okay and next go to new tab so here instead of first name and last name i want only name target system or my output should contain only name and this would contain okay there should be space i don't want this last name then country and mobile number it will contain only mobile number and this will contain country code also i don't want this com code separately or let it be country code and mobile number will be separate only and this address i want only one address i want i don't want three address like three line so i want only address address house this city country so this is my output structure okay so this will be sample response data sample response data and save this so now we have input and output payload structure so what i will do i will go to database here i will inside src main resource either you can create inside this or src test resource anywhere you can create let me create here only src main resource new folder sample data i created this folder sample data and inside this folder what i will do i will copy paste those two files just now i created so sample request and sample response copy from here and paste it here now we have sample request data sample response data what i will do here i will go to this database define metadata go here click on add define here request create type request here string and then type i don't want simple type i want json so select json whatever you want you will get all i want json one and you want to define it so you have two way here either you can use schema or you can use example so i created example so let me go with example select that particular folder so that folder is inside src main resources sample data request so this will come here and click on select so you can see here that particular structure is coming here same we will do fine view will do fair output click on add response create type json example src main resource sample data response okay you can see here in response also now i want to do mapping so this first name with name last name with name okay first c here so this first name is going with name okay if you want to see preview okay first let me delete everything only payload so entire payload is coming what payload we have here entire payload is coming here now i will remove everything and i will do mapping from here first name with name oh okay let me just let me give this one so you can see here i mapped this first name with this particular name and we are getting name as a developer and you can see here syntax is generated database script is generated here i want last name also here only so automatically it will create mapping for you payload.firstname empty payload dot last name so you are getting developer guide but i want to add some space also so you need to do it manually so in between i want space and for last name also i want to add default value okay so developer guide we are getting now second what we want we want country code with country code okay and then we want mobile number with mobile number so everything is generating here so let me make it full screen okay next we have this three should be inside address okay so first i will map this address with this address then this city with this address okay and then this country with this entries okay so you can see here everything coming by default so here i want to add one space and same i want to add before this city also okay so this in this way you can generate your data with script graphically okay you don't need to write much code if you will have complete structure of your input if you have complete structure of output you can easily you can easily do this okay and after this if i will run mem if i will run this application you need to pass that particular input payload and based on that it will do required transformation and it will generate output payload okay this part is very simple so i am not going to do it everyone want me to run this application or is it good like we are we will be more focused on data view only hope let we can skip that part deployment part and testing part this will definitely work so you need to pass particular input payload and it will do required mapping and it will generate this particular output payload okay now another thing we discuss if you remember like we can we can take this source code from this file also okay so to do this what we need to do we need to externalize this particular data syntax okay so what i am going to do i will take this particular syntax and inside this sample data only or let me create one more folder folder name will be datab or dwl here do right click new and you will get here file option here file name you can write like uh sample dwm extension must be dwn click on finish and here you can paste your script what script you have okay and then where you want to use this particular so go to your let's see we let let's say we have another transformation okay and here instead of writing my database script here i want to reuse existing database script so what i will do go to edit option change it from inline to file one go to search and here go to src main where exactly we are then resource data view folder okay it's not coming looks like i am doing any mistake here come again i'm doing any mistake here it's not taking this one this twl go back cancel this show me what uh you are you're trying to take it as a file correct yes yes so you just need to put sample dot dw and that's it just put sample dot dw it will automatically take it okay you have okay put dwl sample.twl it will automatically take from your resources so if it will be correct then syntax should come here let me quickly check change the slash make it a backslash no no check the name i think you were doing something wrong sample.dwl this is fine oh empty okay now make the slash again back here forward slash okay it will change again i guess now go to sample now go to sample.xml uh sorry sample.dwn yeah put it again it overwrites generally we do in reverse order so that's why so two issue is there i think that that is something different that is not related to this means uh that can be dummy issue so you can ignore this dummy is you like you need to here you need to put default value okay and unable to call with so this is like dummy so you can ignore this one but still if you want to fix it everywhere you need to put default value then here okay this is so you can ignore okay if you want if if you are getting error at this place if you can see red cross here that means that is genuine problem if you are getting just error here then that is dummy error you can ignore and you can proceed okay that will not create any problem if you want you can let me deploy this application this application will be deployed successfully there will not be any problem ravi here creating two files one is the database slash sample.dwn and another one is the in dwn folder sample dot booting level which one i think we are referring this one yes we are referring this one we can delete this one okay so this application is deployed successfully so there is no problem with this particular mapping okay okay fine then uh so i think we are almost done with today's session so if you have any query then you are open for your query and we will wrap up our session after 10 minutes so for next 10 minutes we are open for your queries okay no one has any query from the playground from this studio ah sorry sorry means how to take the code from playground from list to video from playground to studio you can copy paste i don't think there will be any other option okay there is a question from rama in optimized perspective do we use metadata what size of metadata can use an entire project okay so metadata in request if you are saying then definitely we should take some metadata in header like transaction id we
Info
Channel: Developers Guide
Views: 4,364
Rating: undefined out of 5
Keywords: Mulesoft, Dataweave, Dataweave2, Mule, Developers, Guides, DevelopersGuide, Basics, MulesoftDevelopers, session
Id: _cSWpsWbUKU
Channel Id: undefined
Length: 95min 39sec (5739 seconds)
Published: Sat Feb 26 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.