Search in sources :

Example 6 with SettingsRecord

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;
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) Resource(org.springframework.core.io.Resource)

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

Example 8 with SettingsRecord

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

Example 9 with SettingsRecord

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

Example 10 with 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;
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) Resource(org.springframework.core.io.Resource)

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