added support for default values

This commit is contained in:
2018-08-23 17:00:30 +02:00
parent 4b2e4e9055
commit a0cda5f498

View File

@ -81,6 +81,28 @@ public class ConfigService implements Serializable {
}
}
public String getConfigValue(String configKey, String defaultValue) throws ConfigException {
return getConfigValue(configKey, defaultValue, false);
}
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
// get configValue as usual
String configValue = getConfigValue(configKey);
// if config value is not found null has been returned
// in this case the value to return is the defaultValue
if (configValue == null) {
configValue = defaultValue;
}
// check if the default value should be stored in the database
if (storeDefaultValue) {
updateConfigValue(configKey, null, configValue);
}
return defaultValue;
}
public String getConfigValue(String configKey, AccountEntity account) throws ConfigException {
Query query = em.createNamedQuery("ConfigEntity.findByConfigKeyAndAccount");
query.setParameter("configKey", configKey);