Skip to content

Application Configuration

Purpose

A utility to manage application configuration.

An application configuration is a combination of:

  • an appKey
  • a name
  • a value
  • and a type

The following types are supported:

  • String (default)
  • Double
  • Long
  • Integer
  • Float
  • Boolean
  • Byte
  • UUID
  • Date
  • ZonedDateTime
  • Character
  • JsonObject

If the type of the value does not match one of the previous types, the fallback conversion used will be the String.

Note

Since 6.10.12

Platform6 introduces a new obfuscation mechanism for configuration values (cf. documentation).

All the methods returning a configuration value (get, getAsJson, getOrDefault or list) will automatically decrypt the value if it is obfuscated.

Methods

Binding name: p6.appconfig


exists

Checks if a configuration entry exists

Syntax

boolean p6.appconfig.exists(String name)

Info

If no appKey is defined inside the name parameter then the appKey attached to the current script or route making the call will be used.

Examples
Specifying the appKey
if (p6.appconfig.exists('app.installed')) {
    p6.log.debug 'Entry exists'
}
Using context appKey
if (p6.appconfig.exists('installed')) {
    p6.log.debug 'Entry exists'
}

exists (with appKey)

Checks if a configuration entry exists

Syntax

boolean p6.appconfig.exists(String appKey, String name)

Tip

Specify an empty appKey to return the unpackaged entries.

Examples
Unpackaged
if (p6.appconfig.exists("", "installed")) {
    p6.log.debug "Unpackaged entry exists"
}
Packaged
if (p6.appconfig.exists("myApp", "installed")) {
    p6.log.debug "Packaged entry exists"
}

get

Returns the configuration value cast according to the type of the configuration entry

Syntax

Object p6.appconfig.get(String name)

Info

If no appKey is defined inside the name parameter then the appKey attached to the current script or route making the call will be used.

Examples
Specifying the appKey
println p6.appconfig.get('app.installed')
Using context appKey
println p6.appconfig.get('installed')

get (with appKey)

Returns the configuration value cast according to the type of the configuration entry

Syntax

Object p6.appconfig.get(String appKey, String name)

Warning

A P6Exception exception will be thrown if there is no configuration entry found

Tip

If you want to access a non bundled configuration value you can use an empty appKey

Examples
Unpackaged
println p6.appconfig.get('', 'installed')
Packaged
println p6.appconfig.get('myApp', 'installed')

getOrDefault

Returns the configuration value or if not found, the default value, cast according to the type of the configuration entry.

Syntax

Object p6.appconfig.getOrDefault(String name, Object defaultValue)

Info

If no appKey is defined inside the name parameter then the appKey attached to the current script or route making the call will be used.

Examples
Specifying the appKey
println p6.appconfig.getOrDefault('app.started', false)
Using context appKey
println p6.appconfig.getOrDefault('started', false)

getOrDefault (with appKey)

Returns the configuration value or if not found, the default value, cast according to the type of the configuration entry.

Syntax

Object p6.appconfig.getOrDefault(String appKey, String name, Object defaultValue)

Tip

If you want to access a non bundled configuration value you can use an empty appKey

Examples
Unpackaged
println p6.appconfig.getOrDefault(''', 'started', false)
Packaged
println p6.appconfig.getOrDefault('myApp', 'started', false)

getAsJson

Since 6.10.7

Returns the Json Object configuration as a Object. The value and the default value will be merged together unless merge parameter is set to false.

Syntax

Object p6.appconfig.getAsJson(String name)
Object p6.appconfig.getAsJson(String name, boolean merge)

Info

If no appKey is defined inside the name parameter then the appKey attached to the current script or route making the call will be used.

Warning

A P6Exception exception will be thrown if there is no configuration entry found or not with the correct type

Examples
Specifying the appKey
println p6.appconfig.getAsJson('myApp.configuration')
Using context appKey
println p6.appconfig.getAsJson('configuration')
Using context appKey without merging
println p6.appconfig.getAsJson('configuration', false)

getAsJson (with appKey)

Since 6.10.7

Returns the Json Object configuration as a Object. The value and the default value will be merged together unless merge parameter is set to false.

Syntax

Object p6.appconfig.getAsJson(String appKey, String name)
Object p6.appconfig.getAsJson(String appKey, String name, boolean merge)

Tip

If you want to access a non bundled configuration value you can use an empty appKey

Warning

A P6Exception exception will be thrown if there is no configuration entry found or not with the correct type

Examples
Unpackaged
println p6.appconfig.getAsJson('', 'configuration')
Packaged
println p6.appconfig.getAsJson('myApp', 'configuration')
Packaged without merging
println p6.appconfig.getAsJson('myApp', 'configuration', false)

list

Returns a list of all the available configuration entries where the key is the name of the key and the value, the value or the override value.

Syntax

Map<String,Object> p6.appconfig.list(String appKey)

Tip

To access non bundle configuration values you can use an empty appKey

Examples
Unpackaged
for(entry in p6.appconfig.list('')) {
    p6.log.debug entry.key + ' = ' + entry.value
}
Packaged
for(entry in p6.appconfig.list('myApp')) {
    p6.log.debug entry.key + ' = ' + entry.value
}

list (current appKey)

Same method but using the appKey attached to the current script or route making the call.

Syntax

Map<String,Object> p6.appconfig.list()
Example
for(entry in p6.appconfig.list()) {
    p6.log.debug entry.key + ' = ' + entry.value
}

override

Override the configuration entry with the new value. The value will be encoded based on the type.

Syntax

void p6.appconfig.override(String name, Object value)

Info

If no appKey is defined inside the name parameter then the appKey attached to the current script or route making the call will be used.

Examples
Specifying the appKey
p6.appconfig.override('app.installed', true)
Using context appKey
p6.appconfig.override('installed', true)

override (with appKey)

Override the configuration entry with the new value. The value will be encoded based on the type.

Syntax

void p6.appconfig.override(String appKey, String name, Object value)

Warning

The appKey cannot be empty and must refer to an installed application.

Example
p6.appconfig.override('myApp', 'installed', true)