ConfigurationService¶
-
public interface
ConfigurationService
¶ Central configuration service that monitors and manages configurations.
Methods¶
addOrUpdate¶
addOrUpdateBundleRecord¶
-
void
addOrUpdateBundleRecord
(ModulePropertiesRecord record)¶ A convenient method for adding or updating the properties, which determines on its own whether the record should be added or updated
Parameters: - record – a record to store
addOrUpdateBundleRecords¶
-
void
addOrUpdateBundleRecords
(List<ModulePropertiesRecord> records)¶ Bulk add or update method for the Bundle Properties records. Iterates through the passed records and either adds them, if they are not present, or updates otherwise.
Parameters: - records – a list of properties records
addOrUpdateProperties¶
-
void
addOrUpdateProperties
(String bundle, String version, 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 bundle, it will be created.
Parameters: - bundle – Symbolic name of updated bundle
- version – Version of updated bundle
- filename – Resource filename
- newProperties – New properties to store
- defaultProperties – Default properties of the bundle
Throws: - IOException – if bundle properties cannot be retrieved from file
addOrUpdateSettings¶
-
void
addOrUpdateSettings
(SettingsRecord settingsRecord)¶ Adds or updates a MOTECH settings to the settings service.
Parameters: - settingsRecord – a settings record to store
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¶
deleteByBundleAndFileName¶
getAllBundleProperties¶
-
Map<String, Properties>
getAllBundleProperties
(String bundle, Map<String, Properties> defaultProperties)¶ Retrieves all the bundle properties and returns them as Map, where key is the filename.
Parameters: - bundle – The bundle we wish to retrieve properties for
- defaultProperties – Default properties of the bundle
Throws: - IOException – if any of the bundle properties file cannot be read
Returns: Properties mapped by filename
getBundleProperties¶
-
Properties
getBundleProperties
(String bundle, 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: - bundle – The bundle we wish to retrieve properties for
- filename – Resource filename
- defaultProperties – Default properties of the bundle
Throws: - IOException – if bundle properties cannot be read from file
Returns: Merged properties of the certain bundle
getConfigSource¶
-
ConfigSource
getConfigSource
()¶ This method allows to check whether MOTECH is currently running in the FILE or UI mode
Returns: Current Config Source
getPlatformSettings¶
-
MotechSettings
getPlatformSettings
()¶
getRawConfig¶
-
InputStream
getRawConfig
(String bundle, String filename, Resource resource)¶ Allows to retrieve raw JSON data either from the database or file, depending on the specified ConfigSource mode.
Parameters: - bundle – Bundle 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 bundle)¶ Depending on the selected ConfigSource mode, this method looks for all registered raw data properties within the specified bundle.
Parameters: - bundle – Bundle we wish to perform look for
Returns: List of filenames that register raw config for specified bundle
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 variableMOTECH_CONFIG_DIR
.bootstrap.properties
contains the following properties:sql.url (Mandatory) sql.driver (Mandatory) sql.username (If required) sql.password (If required) config.source (Optional. Defaults to 'UI')
An example
bootstrap.properties
is given below:sql.url=jdbc:mysql://localhost:3306/ sql.driver=com.mysql.jdbc.Driver sql.username=motech sql.password=motech config.source=FILE
If
MOTECH_CONFIG_DIR
environment variable is not set, load the specific configuration values from the following environment variables:MOTECH_SQL_URL (Mandatory) MOTECH_SQL_DRIVER (Mandatory) MOTECH_SQL_USERNAME (If required) MOTECH_SQL_PASSWORD (If required) MOTECH_CONFIG_SOURCE (Optional. Defaults to 'UI')
If
MOTECH_DB_URL
environment is not set, load the configuration frombootstrap.properties
from the default MOTECH config directory specified in the fileconfig-locations.properties
.
Throws: - MotechConfigurationException – if bootstrap configuration cannot be loaded.
Returns: Bootstrap configuration
loadConfig¶
-
SettingsRecord
loadConfig
()¶ Loads current MOTECH configuration
Returns: current MOTECH settings
loadDefaultConfig¶
-
SettingsRecord
loadDefaultConfig
()¶ Loads the default config for MOTECH from the resource file.
Returns: default settings
processExistingConfigs¶
rawConfigExists¶
registersProperties¶
removeAllBundleProperties¶
removeBundleRecords¶
-
void
removeBundleRecords
(List<ModulePropertiesRecord> records)¶ Removes given bundle properties records
Parameters: - records – a list of properties records to remove
requiresConfigurationFiles¶
-
boolean
requiresConfigurationFiles
()¶ Checks whether set MOTECH configuration requires the configuraton files to be present
Returns: true if files are required, false otherwise
retrieveRegisteredBundleNames¶
save¶
-
void
save
(BootstrapConfig bootstrapConfig)¶ Saves the given
BootstrapConfig
in thebootstrap.properties
file located in default MOTECH config location. The default motech config location is specified in the fileconfig-locations.properties
.Parameters: - bootstrapConfig – Bootstrap configuration.
Throws: - MotechConfigurationException – if bootstrap configuration cannot be saved.
savePlatformSettings¶
-
void
savePlatformSettings
(Properties settings)¶ Saves given platform settings to the settings service. Available platform settings are language, login mode, provider name, provider URL, server URL, status message timeout, and upload size.
Parameters: - settings – the settings to be saved
savePlatformSettings¶
-
void
savePlatformSettings
(MotechSettings settings)¶ Saves given MOTECH settings to the settings service.
Parameters: - settings – the settings to be saved
saveRawConfig¶
-
void
saveRawConfig
(String bundle, String version, String filename, InputStream rawData)¶ Allows persisting of raw json properties either in the database or file, depending on the selected ConfigSource mode.
Parameters: - bundle – Bundle we wish to save properties for
- filename – Resource filename
- rawData – Raw JSON data to persist
Throws: - IOException –
setPlatformSetting¶
updateConfigLocation¶
updatePropertiesAfterReinstallation¶
-
void
updatePropertiesAfterReinstallation
(String bundle, String version, 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 availableParameters: - bundle – Symbolic name of updated bundle
- version – Version of updated bundle
- filename – Resource filename
- newProperties – New properties to store
- defaultProperties – Default properties of the bundle
Throws: - IOException – if bundle properties cannot be retrieved from file