Skip to content

Gloop Map Icon

Map

The Gloop Map Step is used to set variable values and to declare new variables. There are two ways to set a variable in a Map Step:

  • A Map Line
  • A Set Expression

When a Map Step is chosen in the Gloop Service Editor, the Mapper view in Coder will show all of the available Input and Output variables. This is where you declare and map variable values and add Set Expressions.

Map Lines

To map a variable, or in other words, assign the value of a variable to the value of another, simply drag and drop a variable to another as shown below:

Mapping a variable

The line in the GIF above is the same as the following code:

1
outputModel.anotherMessage = message2

To delete a line, first click on the line to highlight it, then press Delete or right click on the line and select the Delete menu item.

Removing variable mapping

Set Expressions

If the value of a variable is to be hardcoded, or requires some more advanced logic in order to set its value (such as performing lookups, or some sort of transformation, etc.), you can use a Set Expression instead of a Map Line. When adding a Set Expression, you have the option whether to have Gloop evaluate it or not. When Gloop doesn't evaluate the Set Expression, then the expression itself is used as the value of the variable. When evaluate is on, then Gloop assumes the Set Expression is a Groovy snippet, which gets compiled and executed at runtime. The output of the Groovy snippet is used as the value of the variable.

Set Step Guidelines

Since evaluated Set Expressions are written in Groovy, you can (in theory) write dozens of lines of code in a Set Expression; however it's bad practice to do so. Instead, you should use a Gloovy step or write a reuseable Groovy class.

To add a Set Expression to a variable, right click on a variable in the output half of the Mapper and double click on it, or press Alt. The Set Expression dialog has the available Gloop properties in a tree on the right hand side. If you double click on a variable in the tree while editing your expression, the Groovy code for accessing the variable is inserted into the Set Expression at the location of the cursor. Focus is kept on the script editor even when double clicking so the code can continue to be edited without having to manually put focus back on the editor.

Mapping to a Set Expression

In Coder Studio, you can also either right click or press Alt on a Map Step, and choose the variable you would like to set:

Mapping to a Set Expression

The Set Expression in the GIFs above is the same as the following code:

1
outputModel.anotherMessage = "Hello ${message2.toUpperCase()}"

To delete a Set Expression, simply right click on the variable and choose Delete Set Expression, or highlight the variable, and press Delete.

Deleting a Set Expression

Map Line and Set Expression Priority

You may have noticed in the screenshots above that the Set Expression dialog has a Priority field. This field is used to determine the order in which the Map Lines and Set Expressions are executed. This allows you to map the same fields more than once in the same step. Take the following Map Step for example:

An example where the _Priority_ field will matter

If all the lines in this example had the same priority, then there will be no guarantee on the order in which the lines were executed. Thankfully with the priority feature you can safely determine the order.

Map Steps execute Map Lines and Set Expressions which have the lowest priority number first. This means that if the lines were configured like so:

Input Output Priority
a b 0
b c 1
c d 2
d a 3

Then it would be the same as the following Java code:

1
2
3
4
b = a;
c = b:
d = c;
a = d;

Priorities for Map Lines can be configured by clicking on the line itself (in the Mapper area in the middle) until it is highlighted, then changing the value of the Priority field in the Properties view.

Coder Studio Map Line *Priority* change

Errors in Set Expressions

If your Set Expression throws an exception (regardless whether it was from a syntax error or not), Gloop will produce a standard Gloop stacktrace, but with an extra suffix telling you the line number where the error occurred in your Set Expression, and which Set Expression it was. For example, given the error below, the Set Expression at outputModel.innerModel.outputString threw an exception at line 6:

1
2
3
io.toro.gloop.exception.GloopException: groovy.lang.MissingPropertyException: No such property: oops for class: Script1
    at NaughtyExpression.Set(NaughtyExpression.gloop:3)[outputModel.innerModel.outputString:6]
    at NaughtyCodeInvoker.InvokeGloop(NaughtyCodeInvoker.gloop:1)

Note the second line in the stacktrace, below, which also has some extra notes on the line underneath:

1
2
3
at NaughtyExpression.Set(NaughtyExpression.gloop:3)[outputModel.innerModel.outputString:6]
-------------------------------------------------------------------------------------------------------------------
                        |      Gloop Service      |      Set step output variable      | Set Expression Line Number 

Here is a screenshot showing the Set Step:

The Set Step with error

Errors in Set Expressions

Exceptions are thrown at runtime if your Set Step has a syntax error. Like any other exception, they will be caught by any parent Block Steps with a catch.

Declaring Variables

Gloop lets you declare variables in a Map Step. Similar to Java, variables have a concept of scope, meaning that if you declare a variable in a nested Block Step, then its parents will not see the declared variable. In Coder Studio, there are four ways in which you can declare a variable:

  • By right-clicking in the output side of the Mapper and choosing Declare then choosing the type of variable to declare
  • By using the hotkeys (e.g. Alt will declare a new String)
  • By pressing the full-stop key, which will bring up Coder Studio Content Assist
  • By dragging and dropping a model from the Coder Navigator to the Mapper

The GIF below shows all four methods, in order:

Four ways of declaring variables in Gloop

Unloading Variables

Gloop also lets you remove declared variables once you're finished with them. This feature is useful in helping keep the Mapper in Coder nice and clean, and also makes Gloop code easier to read. When a variable is unloaded, it will not show in the Mapper for any steps after the step that has unloaded it. To unload a declared variable, right click on it, then select Unload Property, or press Alt.

Unloading a variable

Rules for declaring and unloading variables

Gloop lets you declare and unload variables in Map and Invoke Steps only.