Skip to content

Toro Cloud Dev Center


GloopFunctions

The Gloop class contains a series of utility functions that are intended for use in Gloop only. These include:

  • Java system utility functions;
  • functions for running scripts;
  • functions for working with cursors;
  • throwing exceptions; and
  • creating Gloop models.

Not for Groovy

Most of the functions in GloopFunctions deal with Gloop-specific objects; the remaining utility functions are already supported natively by Groovy and thus, this class does not provide much value for Groovy code.

getSystemTime

Use Gloop.getSystemTime() to get the current system time.

Return value

This function will return the system time in milliseconds as a long property.

Usage

Sample service showing how to use the `getSystemTime` function of `Gloop`

getSystemProperty

Use Gloop.getSystemProperty(String, String) to get a Java system property. This function is a wrapper for the java.lang.System.getProperty(String, String) function.

Parameters

Property Type Description
name java.lang.String The name of the property to get.
defaultVal java.lang.String The default return value if the property isn't set yet.

Return value

This function will return a String property if the property exists; otherwise, null.

Usage

Sample service showing how to use the `getSystemProperty` function of `Gloop`

setSystemProperty

Use Gloop.setSystemProperty(String, String) to set a Java system property. This function is a wrapper for the java.lang.System.setProperty(String, String) function.

Parameters

Property Type Description
name java.lang.String The name of the property to set.
value java.lang.String The value to assign to the system property.

Return value

This function will return the configured value for the property.

Usage

Sample service showing how to use the `setSystemProperty` function of `Gloop`

runScriptlet

Use the Gloop.runScriptlet(String, GloopExecutionContext) function to run a piece of Groovy code in the current context.

Parameters

Property Type Description
scriptlet java.lang.String The groovy code snippet to execute agains the current context.
context The Gloop execution context; Gloop maps this automatically.

Return value

The function will return the output of the scriptlet as a java.lang.Object.

Usage

Sample service showing how to use the `runScriptlet` function of `Gloop`

contextToJsonString

This function creates a JSON representation of the current Gloop variable context.

Parameters

Property Type Description
context The Gloop execution context; Gloop maps this automatically.

Return value

This function returns a JSON string representing the Gloop context.

Usage

Sample service showing how to use the `contextToJsonString` function of `Gloop`

cursorHasNext

Use the Gloop.cursorHasNext(GloopCursor) function to check whether or not the given Gloop cursor has another record.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor to be checked.

Return value

A boolean property; true if the cursor has another record; `false otherwise.

Usage

Sample service showing how to use the `cursorHasNext` function of `Gloop`

cursorNextRecord

Use this function to point the cursor to the next record.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor which must point to the next record.

Usage

Sample service showing how to use the `cursorNextRecord` function of `Gloop`

cursorGetValue

Use the Gloop.cursorGetValue(GloopCursor) function to get the value of the given cursor's current record.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor whose record will be read.

Return value

This function returns the current record the Gloop cursor is pointing to as a java.lang.Object.

Usage

Sample service showing how to use the `cursorGetValue` function of `Gloop`

cursorAppend

Use this function to add a new record to the cursor. If the value received is a collection or and array, elements will be iterated and added individually.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor whose records will be modified.
value java.lang.Object The value(s) to add to the cursor.

Usage

Sample service showing how to use the `cursorAppend` function of `Gloop`

cursorSize

Use the Gloop.cursorSize(GloopCursor) function to get the size of a given cursor.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor whose records will be counted.

Return value

A long property whose value is set to the number of records held by the cursor.

Usage

Sample service showing how to use the `cursorSize` function of `Gloop`

cursorSkip

Use the Gloop.cursorSkip(GloopCursor, int) function to skip the next n record(s) of a given cursor.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor with records to skip.
skipCount java.lang.Integer The number of records to skip over.

Return value

The number of records actually skipped.

Usage

Sample service showing how to use the `cursorSkip` function of `Gloop`

cursorLast

Use the Gloop.cursorLast(GloopCursor) function to iterate through the cursor until the last record is reached.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor whose last record must be reached.

Return value

The number of records skipped over.

Usage

Sample service showing how to use the `cursorLast` function of `Gloop`

cursorClose

Use the Gloop.cursorClose(GloopCursor) function to close a given cursor.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor to close.

Usage

Sample service showing how to use the `cursorClose` function of `Gloop`

cursorToArray

Use the Gloop.cursorToArray(GloopCursor) function to iterate through a cursor and create an in-memory array of Gloop models of its records.

Parameters

Property Type Description
cursor io.toro.gloop.object.cursor.GloopCursor The Gloop cursor whose records shall be copied.

Return value

This function returns a io.toro.gloop.object.property.GloopModel containing all cursor data.

Usage

Sample service showing how to use the `cursorToArray` function of `Gloop`

throwException(String)

Use the Gloop.throwException(String) function to throw an exception with the configured message.

Parameters

Property Type Description
message java.lang.String The exception message.

Usage

Sample service showing how to use the `throwException` function of `Gloop`

throwException(String, Throwable)

Use the Gloop.throwException(String, Throwable) function throw an exception with the configured message and cause (of type Throwable).

Parameters

Property Type Description
message java.lang.String The exception message.
cause java.lang.Throwable The cause of the exception or null if the cause is non-existent or unknown.

Usage

Sample service showing how to use the `throwException` function of `Gloop` with throwable

dynamicModelToMapModelArray

Use this function to create a map-like Gloop model out of a given Gloop model. The result is an array of Gloop models; each with name and value properties. Every property in the source Gloop model will have its own entry in the resulting array. In these entries, the property name is mapped to the name property, and the value mapped to the value.

Example transformation using the dynamicModelToMapModelArray(GloopModel) function

For this example, let's assume the source Gloop model is the model below, represented in JSON:

1
2
3
4
{
    "TORO": "Cloud",
    "Martini": "Ninja"
}

When this function is used, the resulting array will be:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[
    {
        "name": "TORO",
        "value": "Cloud"
    },
    {
        "name": "Martini",
        "value": "Ninja"
    }
]

Parameters

Property Type Description
anonymousModel io.toro.gloop.object.property.GloopModel The Gloop model to be converted.

Return value

This function returns an array of io.toro.gloop.object.property.GloopModels; each model representing a property of anonymousModel.

Usage

Sample service showing how to use the `dynamicModelToMapModelArray` function of `Gloop`

mapModelArrayToDynamicModel

mapModelArrayToDynamicModel(GloopModel) is used to create a model out of an array of models. Each model in the source array follows a specific structure; with a name and value property each. Using said function, the resulting Gloop model would have properties named after name properties and their values equal to the corresponding value property of each source model.

This function is the reverse counterpart of dynamicModelToMapModelArray(GloopModel).

Example transformation using the mapModelArrayToDynamicModel(GloopModel) function

Given the source array of models:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[
    {
        "name": "TORO",
        "value": "Cloud"
    },
    {
        "name": "Martini",
        "value": "Ninja"
    }
]

... the output of this function would be:

1
2
3
4
{
    "TORO": "Cloud",
    "Martini": "Ninja"
}

Parameters

Property Type Description
model io.toro.gloop.object.property.GloopModel The Gloop model to be converted.

Return value

This function returns a new io.toro.gloop.object.property.GloopModel, containing properties described by the source array of models.

Usage

Sample service showing how to use the `mapModelArrayToDynamicModel` function of `Gloop`