use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceImpl method loadDefaultConfig.
@Override
public SettingsRecord loadDefaultConfig() {
SettingsRecord settingsRecord = null;
org.springframework.core.io.Resource defaultSettings = resourceLoader.getResource("classpath:motech-settings.properties");
if (defaultSettings != null) {
settingsRecord = loadSettingsFromStream(defaultSettings);
}
return settingsRecord;
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceImpl method addOrUpdateSettings.
/**
* Adds given settings to the settings service. If they are present, they will be updated.
*
* @param settingsRecord the settings to be add
*/
@Override
@Transactional
public void addOrUpdateSettings(SettingsRecord settingsRecord) {
SettingsRecord record = getSettingsRecord();
if (record == null) {
settingsDataService.create(settingsRecord);
} else {
record.setConfigFileChecksum(settingsRecord.getConfigFileChecksum());
record.setFilePath(settingsRecord.getFilePath());
record.setPlatformInitialized(settingsRecord.isPlatformInitialized());
record.setPlatformSettings(settingsRecord.getPlatformSettings());
settingsDataService.update(record);
}
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceImpl method loadSettingsFromStream.
private SettingsRecord loadSettingsFromStream(org.springframework.core.io.Resource motechSettings) {
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
try (DigestInputStream dis = new DigestInputStream(motechSettings.getInputStream(), digest)) {
// load configFileSettings and calculate MD5 hash
SettingsRecord settingsRecord = new SettingsRecord();
settingsRecord.load(dis);
settingsRecord.setConfigFileChecksum(new String(digest.digest()));
// startup loaded
return settingsRecord;
} catch (IOException e) {
throw new MotechException("Error loading configuration", e);
}
} catch (NoSuchAlgorithmException e) {
throw new MotechException("MD5 algorithm not available", e);
}
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceBundleIT method prepareDbSettingsRecord.
private void prepareDbSettingsRecord() {
SettingsRecord settingsRecord = configurationService.loadDefaultConfig();
Map<String, String> platformSettings = new HashMap<>();
platformSettings.put(ConfigurationConstants.SERVER_URL, SERVER_URL_TEST);
platformSettings.put(ConfigurationConstants.SESSION_TIMEOUT, "80");
platformSettings.put(ConfigurationConstants.EMAIL_REQUIRED, "true");
settingsRecord.setPlatformInitialized(true);
settingsRecord.setPlatformSettings(platformSettings);
configurationService.addOrUpdateSettings(settingsRecord);
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigLoader method loadDefaultConfig.
/**
* Loads default MOTECH settings.
*
* @return the {SettingsRecord} object
*/
public SettingsRecord loadDefaultConfig() {
SettingsRecord settingsRecord = null;
Resource defaultSettings = resourceLoader.getResource("classpath:motech-settings.properties");
if (defaultSettings != null) {
settingsRecord = loadSettingsFromStream(defaultSettings);
}
return settingsRecord;
}
Aggregations