use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigLoader method loadMotechSettings.
/**
* Loads MOTECH settings containing core platform settings.
*
* @return the {SettingsRecord} object
*/
public SettingsRecord loadMotechSettings() {
SettingsRecord settingsRecord;
ConfigLocation configLocation = coreConfigurationService.getConfigLocation();
Resource configLocationResource = configLocation.toResource();
try {
Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME);
settingsRecord = loadSettingsFromStream(motechSettings);
settingsRecord.setFilePath(configLocationResource.getURL().getPath());
checkSettingsRecord(settingsRecord);
} catch (IOException e) {
throw new MotechConfigurationException(String.format("Could not read settings from file at location %s", configLocation), e);
}
return settingsRecord;
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigLoader method loadSettingsFromStream.
private SettingsRecord loadSettingsFromStream(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);
}
}
Aggregations