Skip to content

Martini Groovy Functions

The Groovy class in Martini offers functions for managing package properties and retrieving instance properties in the context of the current Martini package.

Functions

getApplicationProperty

Retrieves an application property from the configured Martini application properties.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the application property to retrieve.
defaultValue 1 java.lang.String Default value if the property is not found.

Return Value

Name Type Description
output java.lang.String The application property value or defaultValue.

Usage Example

1
2
def port = Groovy.getApplicationProperty('server.http.port')
def format = Groovy.getApplicationProperty('api.rest.default-content-type', 'json')

getPackageProperty

Fetches a package property from the Martini package in the current thread context.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property to retrieve.
defaultValue 1 java.lang.String Default value if the property is not found.

Return Value

Name Type Description
output java.lang.String The package property value or defaultValue.

Usage Example

1
2
def email = Groovy.getPackageProperty('email')
def email = Groovy.getPackageProperty('email', 'default@email.com')

getPackagePropertyArray

Retrieves the array value of a package property in the current Martini package context.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property to retrieve.
defaultValue 1 java.lang.String[] Default array value if the property is not found.

Return Value

Name Type Description
output java.lang.String[] The array value of the package property or defaultValue.

Usage Example

1
2
def emailAddresses = Groovy.getPackagePropertyArray('email.addresses')
def formats = Groovy.getPackagePropertyArray('formats', ['json', 'xml'])

getPackagePropertyComment

Gets the comment of a package property in the Martini package of the current thread context.

Parameters

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

Return Value

Name Type Description
output java.lang.String The comment of the package property.

Usage Example

1
def propertyComment = Groovy.getPackagePropertyComment('property_name')

removePackageProperty

Removes a package property from the current thread context's Martini package.

Parameters

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

Return Value

Name Type Description
output java.lang.String The property's value before removal.

Usage Example

1
def removedValue = Groovy.removePackageProperty('property_name')

savePackageProperty

Adds or edits a package property in 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/edit.
value 1 java.lang.String The new value of the package property.

Return Value

Name Type Description
output java.lang.String The new value of the added/edited property.

Usage Example

1
def newValue = Groovy.savePackageProperty('property_name', 'new_value')

savePackagePropertyComment

Adds or edits a comment on a package property in the current Martini package context.

Parameters

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

Usage Example

1
Groovy.savePackagePropertyComment('property_name', 'New Comment')