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
If the type
of the value
does not match one of the previous types, the fallback conversion used will be
the String
.
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
if (p6.appconfig.exists("app.installed")) {
println "Entry exists"
}
if (p6.appconfig.exists("installed")) {
println "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
if (p6.appconfig.exists("", "installed")) {
println "Unpackaged entry exists"
}
if (p6.appconfig.exists("myApp", "installed")) {
println "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
println p6.appconfig.get("app.installed")
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
println p6.appconfig.get("", "installed")
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
println p6.appconfig.getOrDefault("app.started", false)
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
println p6.appconfig.getOrDefault("", "started", false)
println p6.appconfig.getOrDefault("myApp", "started", 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
for(entry in p6.appconfig.list("")) {
println "$entry.key = $entry.value"
}
for(entry in p6.appconfig.list("myApp")) {
println "$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()) {
println "$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
p6.appconfig.override("app.installed", true)
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)