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.

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

delete

void delete(String module)

Deletes the db record corresponding to the module.

deleteByBundle

void deleteByBundle(String module)

Deletes the db record corresponding to the module with given bundle symbolic name.

evictMotechSettingsCache

void evictMotechSettingsCache()

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:

  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:

    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
    
  2. 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')
    
  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()

loadDefaultConfig

SettingsRecord loadDefaultConfig()

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 module, String filename)

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

Parameters:
  • module – Module symbolic name
  • filename – Resource filename
Returns:

True if raw data exists for given parameters, false otherwise

registersProperties

boolean registersProperties(String module, String filename)

Checks if given module registers certain property file

Parameters:
  • module – Module we wish to perform check for
  • filename – Resource filename
Returns:

True if properties exist, false otherwise

removeModuleRecords

void removeModuleRecords(List<ModulePropertiesRecord> records)

removeProperties

void removeProperties(String module, String filename)

Removes properties for given module from database or file.

Parameters:
  • module – The module we wish to remove properties for
  • filename – Resource filename

requiresConfigurationFiles

boolean requiresConfigurationFiles()

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)

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

setPlatformSetting

void setPlatformSetting(String key, String value)

updateConfigLocation

void updateConfigLocation(String newConfigLocation)

Adds a new config location and restarts the monitor.

Parameters:
  • newConfigLocation – New config location

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