use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceImpl method savePlatformSettings.
@Override
@Transactional
public void savePlatformSettings(Properties settings) {
SettingsRecord dbSettings = getSettings();
dbSettings.setPlatformInitialized(true);
dbSettings.setLastRun(DateTime.now());
dbSettings.updateFromProperties(settings);
dbSettings.removeDefaults(defaultConfig);
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
dbSettings.setConfigFileChecksum(new String(digest.digest(MapUtils.toProperties(dbSettings.asProperties()).toString().getBytes())));
} catch (NoSuchAlgorithmException e) {
throw new MotechException("MD5 algorithm not available", e);
}
addOrUpdateSettings(dbSettings);
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceImpl method getPlatformSettings.
@Override
@Transactional
@Caching(cacheable = { @Cacheable(value = SETTINGS_CACHE_NAME, key = "#root.methodName") })
public MotechSettings getPlatformSettings() {
if (settingsDataService == null) {
return null;
}
SettingsRecord settings = getSettings();
SettingsRecord merged = new SettingsRecord();
merged.setPlatformInitialized(settings.isPlatformInitialized());
merged.setLastRun(settings.getLastRun());
merged.setFilePath(settings.getFilePath());
merged.setConfigFileChecksum(settings.getConfigFileChecksum());
merged.setPlatformSettings(settings.getPlatformSettings());
merged.mergeWithDefaults(defaultConfig);
return merged;
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceTest method shouldUpdateMotechSettings.
@Test
public void shouldUpdateMotechSettings() {
when(configLoader.loadMotechSettings()).thenReturn(new SettingsRecord());
final SettingsRecord settingsRecord = new SettingsRecord();
when(settingsDataService.retrieveAll()).thenReturn(singletonList(settingsRecord));
configurationService.addOrUpdate(FileHelper.getResourceFile("config/motech-settings.properties"));
verify(settingsDataService).update(settingsRecord);
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceTest method shouldUpdatePlatformCoreConfigWhileProcessingExistingConfigs.
@Test
public void shouldUpdatePlatformCoreConfigWhileProcessingExistingConfigs() {
List<SettingsRecord> dbRecords = new ArrayList<>();
dbRecords.add(new SettingsRecord());
when(configLoader.loadMotechSettings()).thenReturn(new SettingsRecord());
when(settingsDataService.retrieve("id", 1)).thenReturn(null);
File file = FileHelper.getResourceFile("config/motech-settings.properties");
configurationService.processExistingConfigs(Arrays.asList(file));
verify(settingsDataService).create((SettingsRecord) any());
verify(bundlePropertiesDataService, never()).create((ModulePropertiesRecord) any());
verify(bundlePropertiesDataService, never()).update((ModulePropertiesRecord) any());
verify(bundlePropertiesDataService, never()).delete((ModulePropertiesRecord) any());
}
use of org.motechproject.config.domain.SettingsRecord in project motech by motech.
the class ConfigurationServiceImpl method setPlatformSetting.
@Override
@Transactional
public void setPlatformSetting(final String key, final String value) {
SettingsRecord dbSettings = getSettings();
dbSettings.savePlatformSetting(key, value);
dbSettings.removeDefaults(defaultConfig);
addOrUpdateSettings(dbSettings);
}
Aggregations