ConfigurationService¶
- public interface ConfigurationService¶
Central configuration service that monitors and manages configurations.
Methods¶
addOrUpdate¶
addOrUpdateModuleRecord¶
- void addOrUpdateModuleRecord(ModulePropertiesRecord record)¶
addOrUpdateModuleRecords¶
- void addOrUpdateModuleRecords(List<ModulePropertiesRecord> records)¶
addOrUpdateProperties¶
- void addOrUpdateProperties(String module, String version, String bundle, String filename, Properties newProperties, Properties defaultProperties)¶
Depending on the config source, it will either store properties in the DB or file. Only properties that are different from the default ones are stored. If the properties database record or file doesn’t exist yet for the given module, it will be created.
Parameters: - module – The module we wish to update properties for
- version – Version of updated bundle
- bundle – Symbolic name of updated bundle
- filename – Resource filename
- newProperties – New properties to store
- defaultProperties – Default properties of the module
Throws: - IOException – if module properties cannot be retrieved from file
createZipWithConfigFiles¶
- FileInputStream createZipWithConfigFiles(String propertyFile, String fileName)¶
Uses current configuration and default one to find changed properties and then connects them with annotations. Moreover creates file with non default configurations and packs is into the zip file.
Parameters: - propertyFile – name of exported file
Throws: - IOException –
Returns: FileInputStream that contains zip file
deleteByBundle¶
getAllModuleProperties¶
- Map<String, Properties> getAllModuleProperties(String module, Map<String, Properties> defaultProperties)¶
Retrieves all the module properties and returns them as Map, where key is the filename.
Parameters: - module – The module we wish to retrieve properties for
- defaultProperties – Default properties of the module
Throws: - IOException – if any of the module properties file cannot be read
Returns: Properties mapped by filename
getConfigSource¶
- ConfigSource getConfigSource()¶
This method allows to check whether MOTECH is currently running in the FILE or UI mode
Returns: Current Config Source
getModuleProperties¶
- Properties getModuleProperties(String module, String filename, Properties defaultProperties)¶
Retrieves merged properties, given default set. Depending on the ConfigSource, it will either merge default properties with the properties from DB or get properties from file.
Parameters: - module – The module we wish to retrieve properties for
- filename – Resource filename
- defaultProperties – Default properties of the module
Throws: - IOException – if module properties cannot be read from file
Returns: Merged properties of the certain module
getPlatformSettings¶
- MotechSettings getPlatformSettings()¶
getRawConfig¶
- InputStream getRawConfig(String module, String filename, Resource resource)¶
Allows to retrieve raw JSON data either from the database or file, depending on the specified ConfigSource mode.
Parameters: - module – Module we wish to retrieve raw data for
- filename – Resource filename
- resource – Resource file containing default rawConfig, in case no other has been found
Throws: - IOException –
Returns: Raw JSON data as InputStream
listRawConfigNames¶
- List<String> listRawConfigNames(String module)¶
Depending on the selected ConfigSource mode, this method looks for all registered raw data properties within the specified module.
Parameters: - module – Module we wish to perform look for
Returns: List of filenames that register raw config for specified module
loadBootstrapConfig¶
- BootstrapConfig loadBootstrapConfig()¶
Loads bootstrap config that is used to start up the Motech server.
The bootstrap configuration is loaded in the following order:
Load the configuration from bootstrap.properties from the config directory specified by the environment variable MOTECH_CONFIG_DIR. bootstrap.properties contains the following properties:
couchDb.url (Mandatory) couchDb.username (If required) couchDb.password (If required) sql.url (Mandatory) sql.username (If required) sql.password (If required) tenant.id (Optional. Defaults to 'DEFAULT') config.source (Optional. Defaults to 'UI')
An example bootstrap.properties is given below:
couchDb.url=http://localhost:5984 couchDb.username=motech couchDb.password=motech sql.url=jdbc:mysql://localhost:3306/ sql.username=motech sql.password=motech tenant.id=MotherChildCare config.source=FILE
If MOTECH_CONFIG_DIR environment variable is not set, load the specific configuration values from the following environment variables:
MOTECH_COUCHDB_URL (Mandatory) MOTECH_COUCHDB_USERNAME (If required) MOTECH_COUCHDB_PASSWORD (If required) MOTECH_SQL_URL (Mandatory) MOTECH_SQL_USERNAME (If required) MOTECH_SQL_PASSWORD (If required) MOTECH_TENANT_ID (Optional. Defaults to 'DEFAULT') MOTECH_CONFIG_SOURCE (Optional. Defaults to 'UI')
If MOTECH_DB_URL environment is not set, load the configuration from bootstrap.properties from the default MOTECH config directory specified in the file config-locations.properties.
Throws: - org.motechproject.config.core.MotechConfigurationException – if bootstrap configuration cannot be loaded.
Returns: Bootstrap configuration
loadConfig¶
- SettingsRecord loadConfig()¶
loadDefaultConfig¶
- SettingsRecord loadDefaultConfig()¶
processExistingConfigs¶
rawConfigExists¶
registersProperties¶
removeModuleRecords¶
- void removeModuleRecords(List<ModulePropertiesRecord> records)¶
removeProperties¶
retrieveRegisteredBundleNames¶
save¶
- void save(BootstrapConfig bootstrapConfig)¶
Saves the given BootstrapConfig in the bootstrap.properties file located in default MOTECH config location. The default motech config location is specified in the file config-locations.properties.
Parameters: - bootstrapConfig – Bootstrap configuration.
Throws: - org.motechproject.config.core.MotechConfigurationException – if bootstrap configuration cannot be saved.
savePlatformSettings¶
- void savePlatformSettings(Properties settings)¶
savePlatformSettings¶
- void savePlatformSettings(MotechSettings settings)¶
saveRawConfig¶
- void saveRawConfig(String module, String version, String bundle, String filename, InputStream rawData)¶
Allows persisting of raw json properties either in the database or file, depending on the selected ConfigSource mode.
Parameters: - module – Module we wish to save properties for
- filename – Resource filename
- rawData – Raw JSON data to persist
Throws: - IOException –
updateConfigLocation¶
updatePropertiesAfterReinstallation¶
- void updatePropertiesAfterReinstallation(String module, String version, String bundle, String filename, Properties defaultProperties, Properties newProperties)¶
Works similar to addOrUpdateProperties but instead of just adding / updating properties checks database for any deprecated properties and removes to ensure that only current ones are available
Parameters: - module – The module we wish to update properties for
- version – Version of updated bundle
- bundle – Symbolic name of updated bundle
- filename – Resource filename
- newProperties – New properties to store
- defaultProperties – Default properties of the module
Throws: - IOException – if module properties cannot be retrieved from file