Search in sources :

Example 1 with SettingsRecord

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);
}
Also used : MotechException(org.motechproject.commons.api.MotechException) SettingsRecord(org.motechproject.config.domain.SettingsRecord) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SettingsRecord

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;
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) Caching(org.springframework.cache.annotation.Caching) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SettingsRecord

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);
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) Test(org.junit.Test)

Example 4 with 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());
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 5 with SettingsRecord

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);
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SettingsRecord (org.motechproject.config.domain.SettingsRecord)12 Transactional (org.springframework.transaction.annotation.Transactional)4 IOException (java.io.IOException)3 MessageDigest (java.security.MessageDigest)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 MotechException (org.motechproject.commons.api.MotechException)3 Resource (org.springframework.core.io.Resource)3 DigestInputStream (java.security.DigestInputStream)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)1 MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)1 Caching (org.springframework.cache.annotation.Caching)1