Groovy Week 2020: More Free Scripts for hale»studio

Groovy Week 2020: More Free Scripts for hale»studio

Tutorials Groovy hale»studio Tutorial

Two years ago, we published a series of posts around using Groovy scripts to extend the functionality that hale»studio offers. These posts have been a favorite among you, so we've decided to do a reload of the original "Groovy Week" this week!

Let's start with the basics: When you try to do something in hale studio that isn’t possible with the out-of-the-box functionality, hale studio offers several ways of creating that functionality yourself. The most accessible of these is to add your own transformation functions using Groovy scripting. There are several points where Groovy functions can be added:

  • Type Transformation Functions
  • Property Transformation Functions
  • Custom Functions
  • Post-processing scripts (only through the CLI)

Groovy is a superset of Java, i.e. any valid Java program is also a valid Groovy program. What it makes much easier than Java is the creation of data structures – no boilerplate constructors and initialisation and the like. Here are some key resources for learning Groovy:

The following posts should help you with some common challenges. Please note that this article assumes you have working knowledge of hale studio and know the terminology.

The Groovy Logo, by Zorak1103, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=13358930

Monday's Script: Create a persistent ID for your target object (Johanna)

Sometimes, you can't just use a property of a source object to create a unique, persistent ID on the target side. The source object might not have an unique ID, or you might have to merge several source objects. If you just use Generate sequential ID or Generate unique ID, the ID will not be persistent across multiple transformation runs.

If a combination of attributes of the source objects can be found that is unique and stable over time, the values of those attributes can be used to generate an unique ID on the target side that is persistent.

To generate an ID from several source attributes, you can use the function _.crypto.sha256 which is part of the standard Groovy helper functions. The function creates a hash for a string and, as long as the input String is stable, the generated hash value will also be stable.

When using the generated hash as an ID, you should always use a prefix (e.g. the feature type name followed by an underscore) as the hash value might start with a number which is not allowed in a gml:id.

Here is an example for mapping the gml:id attribute of a Road object of in the INSPIRE Transport Network Roads schema:

You can download this script here and import it in hale studio as a Groovy snippet by going to File -> Import -> Groovy Snippet. Please note that some scripts use protected functions, so you might need to "Lift Groovy Restrictions" to execute the script. Make sure you replace the placeholder attribute names with your own attribute names.

Happy transforming!