Skip to content

Toro Cloud Dev Center


GroovyFunctions

The Groovy class contains a bunch of functions for:

Below are the functions that make up the GroovyFunctions class.

getApplicationProperty

Use any of these two functions to get an application property from the list of configured Martini application properties:

  • Groovy.getApplicationProperty(String)
  • Groovy.getApplicationProperty(String, String)

Parameters

Name Index Type Description
key 0 java.lang.String The name of the application property to get
defaultValue 1 java.lang.String The return value if the application property does not exist

Return value

Name Type Description
output java.lang.String The value of the application property; defaultValue if not found

Usage

Sample `getApplicationProperty` usage

1
2
3
4
5
6
// Gets value of the 'server.http.port' property of the Martini instance
def port = 'server.http.port'.getApplicationProperty()

// Gets the value of the 'api.rest.default-content-type' property of the Martini instance
// If the 'api.rest.default-content-type' property could not be found, return the value 'json' instead
def format = 'api.rest.default-content-type'.getApplicationProperty('json')

getPackageProperty

Use any of these two functions to get the value of a package property belonging to the Martini package in the current thread context:

  • Groovy.getPackageProperty(String)
  • Groovy.getPackageProperty(String, String)

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property to get
defaultValue 1 java.lang.String The return value if the package property does not exist

Return value

Name Type Description
output java.lang.String The value of the package property; defaultValue if not found

Usage

Sample `getPackageProperty` usage

1
2
3
4
5
6
// Gets the value of the 'email' package property
def email = 'email'.getPackageProperty()

// Gets the value of the 'email' package property
// If the 'email' property could not be found, return the value 'default@email.com' instead
def email = 'email'.getPackageProperty('default@email.com')

getPackagePropertyArray

Use any of these two functions to get the array value of a package property belonging to the Martini package in the current thread context:

  • Groovy.getPackagePropertyArray(String)
  • Groovy.getPackagePropertyArray(String, String)

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property to get
defaultValue 1 java.lang.String[] The return value if the package property does not exist

Return value

Name Type Description
output java.lang.String[] The array value of the package property; defaultValue if not found

Usage

Sample `getPackagePropertyArray` usage

1
2
3
4
5
6
// Gets the value of the 'email.addresses' property as an array
def email = 'email.addresses'.getPackagePropertyArray()

// Gets the value of the 'formats' property as an array
// If 'formats' could not be found, return the array ['json', 'xml'] instead.
def formats = 'formats'.getPackagePropertyArray('json,xml')

getPackagePropertyComment

Use the function Groovy.getPackagePropertyComment(String) to get the comment of an existing package property. The property must belong to the Martini package in the current thread context.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property whose comment must be fetched

Return value

Name Type Description
output java.lang.String The package property's comment

Usage

Sample `getPackagePropertyComment` usage

1
2
// Gets the 'name' package property's comment
def name = 'name'.getPackagePropertyComment()

removePackageProperty

Use this function to remove a package property from the list of configured package properties owned by the current thread context's Martini package.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property which will be removed

Return value

Name Type Description
output java.lang.String The package property's value before it got removed

Usage

Sample `removePackageProperty` usage

1
2
3
// Remove the 'name' property from the list of package properties
// And return its last cofigured value
def name = 'name'.removePackageProperty()

savePackageProperty

Use this function to add a new package property or edit the value of an existing package property. The affected Martini package will be the Martini package of the current thread context.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the property to add or edit
value 1 java.lang.String The new value of the package property

Return value

Name Type Description
output java.lang.String The added or edited package property's new value

Usage

Sample `savePackageProperty` usage

1
2
3
// Set the 'name' package property's value to 'Bob'
// And return its newly configured value
def name = 'name'.savePackageProperty('Bob')

savePackagePropertyComment

Adds a comment to an existing package property or edits its previously configured comment. Only the Martini package of the current thread context will be affected.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property where comment will be added to
comment 1 java.lang.String The comment to be added

Usage

Sample `savePackagePropertyComment` usage

1
2
// Sets the 'name' package property's comment to 'The name of the recipient'
'name'.savePackagePropertyComment('The name of the recipient')

  1. Or in simpler terms, the Martini package the script running the code belongs to.