Skip to content

Home

Introduction

Development

IDEs

Services

Service manager

API Explorer

GloopMethods

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

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

Not for Groovy

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

getSystemTime

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

Return Value

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

Usage

Sample Gloop service showing how to use the `getSystemTime` one-liner of `GloopMethods`

getSystemProperty

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

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 method will return a String property if the property exists; otherwise, null.

Usage

Sample Gloop service showing how to use the `getSystemProperty` one-liner of `GloopMethods`

setSystemProperty

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

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 method will return the configured value for the property.

Usage

Sample Gloop service showing how to use the `setSystemProperty` one-liner of `GloopMethods`

runScriptlet

Use the GloopMethods.runScriptlet(String, GloopExecutionContext) method 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 method will return the output of the scriptlet as a java.lang.Object.

Usage

Sample Gloop service showing how to use the `runScriptlet` one-liner of `GloopMethods`

contextToJsonString

This method 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 method returns a JSON string representing the Gloop context.

Usage

Sample Gloop service showing how to use the `contextToJsonString` one-liner of `GloopMethods`

cursorHasNext

Use the GloopMethods.cursorHasNext(GloopCursor) method 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 Gloop service showing how to use the `cursorHasNext` one-liner of `GloopMethods`

cursorNextRecord

Use this method 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 Gloop service showing how to use the `cursorNextRecord` one-liner of `GloopMethods`

cursorGetValue

Use the GloopMethods.cursorGetValue(GloopCursor) method 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 method returns the current record the Gloop cursor is pointing to as a java.lang.Object.

Usage

Sample Gloop service showing how to use the `cursorGetValue` one-liner of `GloopMethods`

cursorAppend

Use this method 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 Gloop service showing how to use the `cursorAppend` one-liner of `GloopMethods`

cursorSize

Use the GloopMethods.cursorSize(GloopCursor) method 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 Gloop service showing how to use the `cursorSize` one-liner of `GloopMethods`

cursorSkip

Use the GloopMethods.cursorSkip(GloopCursor, int) method 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 Gloop service showing how to use the `cursorSkip` one-liner of `GloopMethods`

cursorLast

Use the GloopMethods.cursorLast(GloopCursor) method 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 Gloop service showing how to use the `cursorLast` one-liner of `GloopMethods`

cursorClose

Use the GloopMethods.cursorClose(GloopCursor) method to close a given cursor.

Parameters

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

Usage

Sample Gloop service showing how to use the `cursorClose` one-liner of `GloopMethods`

cursorToArray

Use the GloopMethods.cursorToArray(GloopCursor) method 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 method returns a io.toro.gloop.object.property.GloopModel containing all cursor data.

Usage

Sample Gloop service showing how to use the `cursorToArray` one-liner of `GloopMethods`

throwException(String)

Use the GloopMethods.throwException(String) method to throw an exception with the configured message.

Parameters

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

Usage

Sample Gloop service showing how to use the `throwException` one-liner of `GloopMethods`

throwException(String, Throwable)

Use the GloopMethods.throwException(String, Throwable) method 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 Gloop service showing how to use the `throwException` one-liner of `GloopMethods` with throwable

dynamicModelToMapModelArray

Use this method 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) method

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

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

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

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

Parameters

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

Return Value

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

Usage

Sample Gloop service showing how to use the `dynamicModelToMapModelArray` one-liner of `GloopMethods`

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 method, 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 method is the reverse counterpart of dynamicModelToMapModelArray(GloopModel).

Example transformation using the mapModelArrayToDynamicModel(GloopModel) method

Given the source array of models:

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

... the output of this method would be:

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

Parameters

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

Return Value

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

Usage

Sample Gloop service showing how to use the `mapModelArrayToDynamicModel` one-liner of `GloopMethods`