11_DataWeave Flashcards

1
Q

By default, where is the dataweave code?

A

inline in the Mule configuration file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where is sample data used for live preview stored?

A

src/test/resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where are the dwl files stored?

A

src/main/resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dwl stand for?

A

data weave language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Where in the Transform Message component can you reference to use an external DWL file?

A

resource attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where in an element that has an expression property (e.g. choice router), can you use reference to an external DWL file?

A

using syntax ${file::filename}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you create modules (libraries) of reusable Dataweave functions?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you create multiple transformations with one Transform Message Component?

A
  1. Add new target button (lines and a plus sign), 2. Set where to store result (Variables or Attributes or…) 3. Switch between multiple transformation (click on the dropdown.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The data model of the produced output of the dataweave expression could consist of what 3 data types?

A

Object. Array. Simple literals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an object?

A

Key : value pairs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Array?

A

A sequence of comma separated values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is a dataweave expression separated into header and body?

A

Delimiter to separate header and body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the header of a dwl file contain?

A

directives that apply to the body expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the body of a dwl file contain?

A

DataWeave expression that generates the output structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give some example mime type (formats) that the script will output

A

application/json, application/java, application/xml, text/plain, application/dw, application/csv, application/xlsx, …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the 2 types of DataWeave errors?

A

Scripting errors (syntax problems) and Formatting errors (a problem with how the transformation takes one format to another, there could be an issue if you are outputting an XML but the structure does no have a single root node))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

If you get an error what can you do to check what type of error it is?

A

transform the input to application/dw, then if the transformation is successful it’s likely to be a formatting error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Dataweave syntax for a applcation/json output, fname: payload.firstname and {fname: payload.firstname} produce what outputs (if the firstname in the payload is “RayJones”?

A

{fname: “RayJones”} and {fname: “RayJones”}

same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does an XML file need?

A

A root level (and only one).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Will this dwl code with an application/xml output write? — fname: payload.first, lname: payload.last

A

No, as it doesn’t have a one top-level value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you specify an attribute for an XML output? (you can have multiple attributes within the brackets).

A

@(attName: attValue)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Are attributes written to XML output as default?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

XML input has an attribute ? Output application/json. What is the dataweave syntax to access the attribute?

A

payload.name.@initials
(which would give you
“ww”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

When using the map function what can the input array be?

A

JSON or Java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does a map function do to an array?
IT takes each element in the array and applies the transformation function (or lambda function)
26
What does the map function return?
An array. (just think, if you are inputting an array and taking every value and transforming each value, it puts it back in the array).
27
Where is the transformation function used?
In the map function.
28
Within the transformation function what does the $ refer to?
value
29
Within the transformation function what does the $$ refer to?
Index
30
In dwl where can you find the syntax $.firstname
Within the transformation function (therefore, in the map function)
31
What does the $$ in the transformation function start from?
0 (index starts at 0, think it's handling arrays - so makes sense)
32
What is payload map (object, index) -> { num: index, fname:object.fname} the same syntax as?
payload map (num: $$, fname: $.firstname)
33
What does wrapping Java/JSON array elements with {()} do?
If the output is application/xml, then it will convert the array to an XML object
34
How do you change a Java/JSON array to application/xml?
You have to wrap the map operation in the {()}. If you do not do so, the array will error 'Cannot coerce an array object').
35
You can wrap the elements either around the map function or around the map operation, true or false?
true
36
What do you use the .* selector for?
To reference repeated elements.
37
How do you reference repeated elements?
Use the .* selector.
38
If you are converting XML to JSON and dwl has the payload.lname whilst there are repeated tags of the lname, what is the JSON output?
lname (and only the first value. If you want to have all the repeated references you need to include the .*
39
XML -> JSON: What is the output if the input is ( Mule Jennet ). DWL code: payload.users.*user map (obj,index) -> { fname: obj.@firstname, lname: obj.lastname }
[ {"fname": "Max", "lname": "Mule" }, {"fname": "Molly", "lname": "Jennet" } ]
40
Where can global variables can be referenced?
anywhere in the body
41
Where should you use the var directive in the dwl code?
In the header.
42
What does the dwl code (var name) = "the" do?
states the global variable name to the, which can be used throughout the body of the code (acts as functional programming language).
43
What does the code (var name = () -> "wow") ?
When you call the variable name, with the name() it will replace it with "wow".
44
``` What does the dwl code produce, if the input is {"lname": "plants"} and the dwl has (output application/xml var mname = "the" var mname2 = () -> "other" var lname = (aString) -> upper(aString) --- name: { first: payload.firstname, middle1: mname, middle2: mname2(), last: lname(payload.lastname) })? ```
plants the other PLANTS
45
What are the 2 different types of syntax for accessing lambda expressions within dataweave?
I think it's referring to the var and fun. ??? check
46
What is the 2 alternative syntaxs to access lambda expressions?
``` var functionName = (aString) -> function(aString) OR fun functionName(aString) = function(aString) ```
47
Where can you use the keyword using?
in the body of the dwl code
48
Where can local variables be referenced?
In the scope of the expression where they are initialized
49
json -> json What does this dwl code output? using (fname = payload.firstname, lname = payload.lastname) { person: using (user = fname, color = "gray") { name1: user, color: color }, name2: lname, color: color }
Unable to resolve reference of color.
50
Explain using ( = )
It is a local variable that can only be referenced within the scope that it is initialized. e.g. using (fname = "I'm" ++ payload.firstname) { You can use it here } You can't use it here.
51
How do you format data?
{format: ""} (and in between the quotation marks you add in the format you'd like to output)
52
If you want to change the data type, what operation do you use?
as (e.g. as Number, as String)
53
How do you define a custom data type?
using the type header directive (name has to be all lower case, no special chars, or numbers)
54
What is this dwl code doing? (type = ourdateformat = DateTime {format: "yyyyMMddHHmm"})
This is setting a custom data type named 'ourdateformat', which is a DateTime with the format 'yyyyMMddHHmm'.
55
You've created a custom data type called sweetpotato, you want to use it in the body of the dwl code, how do you use it?
payload.normalPotato as sweetpotato
56
What does POJO stand for?
Plain old java object
57
2 ways to transform an oject to a POJO?
1. specify inline | 2. define a custom data type and use that instead
58
Define a custom data type to transform an object to a POJO
type custompojo = Object {class: ""} - -- customer: payload.blah as custompojo (the type is defining the custom data type, the custompojo is the name of the custom data type, Object is datatype with the class stating what java class it should be) ----(the last statement is changing the field blah from the payload to a pojo)
59
Define how to transorm an object to a POJO by specifying inline.
customer: payload.blah as Object {class: ""} think POJO - java - class, as it will need a class... think think think
60
What are dw functions packaged into?
modules
61
What functions are automatically imported into dataweave scipts?
core modules
62
Functions that have 2 params, have 2 alternative syntax, what are they?
#[contains (payload, max)] OR #[payload contains "max"] | the function here being the contains e.g. #[function(param1, param2)] OR #[param1 function "param2"]
63
When using a series of functions, how are they executed?
From the right to the left (the last function in the chain is executed first)
64
How do you get something that is an expression using the map function to be evaluated first if it's at the beginning of a series of functions
You can use the 'using' to define it as a local variable.
65
How do you import a function in a module?
import functionName from dw::core::module
66
How do you import a module
import dw::core:module | basically import module name
67
What does the dasherize(String) function do?
replaces spaces, underscores and camel-casing in a string with dashes (hyphens).
68
How do you call a flow in dwl?
Use the lookup function | lookup("flowName", payload)
69
Can you call sub flows in dwl using the lookup?
No.
70
What does the lookup function return?
Whatever the payload the flow returns is what the expression returns
71
What is a lambda?
An anonymous function not bound to an identifier.
72
What is at the top of the precendence order before binary functions?
using() function
73
What header is used to import functions?
import
74
What does the as Object {class: ""} syntax denote?
transforming objects to POJOs