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
Method: boolean exists(String appKey, String name)
Checks if a configuration entry exists
Info
Specify an empty appKey
to return the unpackaged entries.
Method: boolean exists(String name)
Same method but using the appKey
attached to the current script or route making the call.
Method: Object get(String appKey, String name)
Returns the configuration value
A P6Exception
exception will be thrown if there is no configuration entry found
If you want to access to a non bundled configuration value you can use an empty appKey
Note
The value returned is cast according to the type of the configuration entry.
Method: Object get(String name)
Same method but using the appKey
attached to the current script or route making the call.
Method: Map<String,Object> list(String appKey)
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.
To access non bundle configuration values you can use an empty appKey
Method: Map<String,Object> list()
Same method but using the appKey
attached to the current script or route making the call.
Method: void override(String appKey, String name, Object value)
Override the configuration entry with the new value. The value will be encoded based on the type.
Warning
The appKey
cannot be empty and must refer to an installed application.
Method: void override(String name, Object value)
Same method but using the appKey
attached to the current script or route making the call.
Examples¶
Example 1
Read configuration
# Read configuration from the bundled context def description = p6.appconfig.get("description") # Read configuration from the application p6_demo boolean initialized = p6.appconfig.get("p6_demo", "initialized") # Read configuration from an unon bundled ressource dev value = p6.appconfig.get("", "key")
Example 2
Override configuration
if(p6.appconfig.exists("p6_demo", "installed")) { println p6.appconfig.override("p6_demo", "installed", true) }
Example 3
List configuration
println "------ Unpackaged ------" for(entry in p6.appconfig.list("")) { println "$entry.key = $entry.value" } println "------ Unpackaged ------" for(entry in p6.appconfig.list("p6_demo")) { println "$entry.key = $entry.value" }