SettingsFacade

public class SettingsFacade

SettingsFacade provides an interface to access application configuration present in files or database.

Methods

afterPropertiesSet

public void afterPropertiesSet()

areConfigurationSettingsRegistered

public boolean areConfigurationSettingsRegistered()

Checks if configuration settings have been registered.

Returns:true if setting have been registered, false otherwise

asProperties

public Properties asProperties()

Converts stored configuration to Properties.

Returns:the configuration as Properties

findFilename

protected String findFilename(String key)

Returns a name of a file containing given property.

Parameters:
  • key – the property name
Returns:

the name of a file

getBundleSymbolicName

public String getBundleSymbolicName()

getBundleVersion

public String getBundleVersion()

getPlatformSettings

public MotechSettings getPlatformSettings()

getProperties

public Properties getProperties(String filename)

Returns properties from a resource with given filename.

Parameters:
  • filename – the resource filename
Returns:

properties stored in the file

getProperty

public String getProperty(String key)

getProperty

public String getProperty(String key, String filename)

Returns a value of a property with given key, stored in a resource with given filename.

Parameters:
  • key – the name of the property
  • filename – the resource filename
Returns:

property value as String

getRawConfig

public InputStream getRawConfig(String filename)

Allows to retrieve raw JSON data either from the database or file.

Parameters:
  • filename – Resource filename
Throws:
Returns:

Raw JSON data as InputStream

getResourceFileName

protected static String getResourceFileName(Resource resource)

Returns a name of resource file

Parameters:
  • resource – the resource file
Returns:

the file name of the resource

registerAllProperties

protected void registerAllProperties()

Registers all the properties to the configuration service.

registerAllRawConfig

protected void registerAllRawConfig()

Registers all raw configurations to the configuration service.

registerProperties

protected void registerProperties(String filename, Properties properties)

Registers properties from file with given name to the configuration service.

Parameters:
  • filename – the name of the file with properties
  • properties – properties to be registered

saveConfigProperties

public void saveConfigProperties(String filename, Properties properties)

Saves given properties and resource filename to the configuration. If configuration properties stored in this object were already registered to the configuration service, the given properties and resource filename will also be added there.

Parameters:
  • filename – the resource filename
  • properties – the properties to be saved
Throws:

savePlatformSettings

public void savePlatformSettings(MotechSettings settings)

Saves given MOTECH settings to the configuration service.

Parameters:
  • settings – the MotechSettings to be saved

saveRawConfig

public void saveRawConfig(String filename, Resource resource)

Allows persisting of raw JSON properties either in the database or file.

Parameters:
  • filename – resource filename
  • resource – resource data to persist
Throws:

saveRawConfig

public void saveRawConfig(String filename, String jsonText)

Allows persisting of raw JSON properties either in the database or file.

Parameters:
  • filename – json filename
  • jsonText – json data to persist
Throws:

setBundleContext

public void setBundleContext(BundleContext bundleContext)

setConfigFiles

public void setConfigFiles(List<Resource> resources)

setProperty

public void setProperty(String key, String value)

setRawConfigFiles

public void setRawConfigFiles(List<Resource> resources)

unregisterProperties

public void unregisterProperties(String symbolicName)

Unregisters properties of the bundle with given symbolic name.

Parameters:
  • symbolicName – the symbolic name of the bundle