ConfigurationService

public interface ConfigurationService

Central configuration service that monitors and manages configurations.

Fields

SETTINGS_CACHE_NAME

String SETTINGS_CACHE_NAME

Methods

addOrUpdate

void addOrUpdate(File file)

Saves both property and raw configurations in FILE mode only. Files are classified as either raw config or properties based on the extension of the file.

Parameters:
  • file – File to read configuration from.

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

void deleteByBundle(String bundle)

Deletes the db records corresponding to the bundle with given bundle symbolic name.

deleteByBundleAndFileName

void deleteByBundleAndFileName(String bundle, String filename)

Deletes the db record corresponding to the bundle and filename.

evictMotechSettingsCache

void evictMotechSettingsCache()

Removes all cached MOTECH settings.

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:

  1. Load the configuration from bootstrap.properties from the config directory specified by the environment variable MOTECH_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
    
  2. 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')
    
  3. 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:
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

void processExistingConfigs(List<File> files)

Adds, updates, or deletes configurations in FILE mode only. Files are classified as either raw config or properties based on the extension of the file.s

Parameters:
  • files – Files to read configuration from.

rawConfigExists

boolean rawConfigExists(String bundle, String filename)

Allows to check if raw data has been registered for specified bundle

Parameters:
  • bundle – Bundle symbolic name
  • filename – Resource filename
Returns:

True if raw data exists for given parameters, false otherwise

registersProperties

boolean registersProperties(String bundle, String filename)

Checks if given bundle registers certain property file

Parameters:
  • bundle – Bundle we wish to perform check for
  • filename – Resource filename
Returns:

True if properties exist, false otherwise

removeAllBundleProperties

void removeAllBundleProperties(String bundle)

Removes properties for given bundle.

Parameters:
  • bundle – The bundle we wish to remove properties for

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

List<String> retrieveRegisteredBundleNames()

Depending on the selected ConfigSource mode, this method looks for registered bundle properties and returns a list of files it has found

Returns:List of files with registered properties

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:

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

void setPlatformSetting(String key, String value)

Sets given value for the platform setting with given key.

Parameters:
  • key – the setting name
  • value – the value to be set

updateConfigLocation

void updateConfigLocation(String newConfigLocation)

Adds a new config location and restarts the monitor.

Parameters:
  • newConfigLocation – New config location

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 available

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