diff options
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java')
-rw-r--r-- | id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java | 137 |
1 files changed, 84 insertions, 53 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java index 10ed19f83..442ff6247 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java @@ -2,6 +2,7 @@ package at.gv.egovernment.moa.id.commons.config.persistence; import java.util.Arrays; import java.util.List; +import java.util.Properties; import javax.persistence.EntityExistsException; @@ -11,13 +12,14 @@ import org.springframework.beans.factory.annotation.Required; import org.springframework.stereotype.Component; import at.gv.egiz.components.configuration.api.Configuration; +import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigPropertyDaoImpl; /** * The implementation of a key-value configuration implementing the {@link Configuration} interface. * It employs the {@link ConfigPropertyDao} to persist configuration data. */ @Component -public class MOAIDConfigurationImpl implements MOAIDConfiguration { +public class MOAIDConfigurationImpl extends ConfigPropertyDaoImpl implements MOAIDConfiguration { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -33,64 +35,93 @@ public class MOAIDConfigurationImpl implements MOAIDConfiguration { this.configPropertyDao = configPropertyDao; } + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration#getPropertySubset(java.lang.String) + */ @Override - public List<String> getAllKeys(){ - try { - return Arrays.asList(this.configPropertyDao.getConfigurationIds()); - } catch (Exception e) { - log.debug("Error while retrieving a list of all keys in the database."); - return null; - } + public Properties getPropertySubset(String preFix) { + // TODO Auto-generated method stub + return null; } + + + /** + * Small helper method. NOTE: may return empty properties, but never {@code null}. + * @param propPrefix the prefix of the desired property. + * @return the {@link Properties} + */ + private Properties getGeneralProperiesConfig(Properties input, final String propPrefix) { - @Override - public String get(String key) { - // return null if key does not exist - try { - return configPropertyDao.getStringValue(key); - - } catch (Exception e) { - log.debug("Error while searching value of key '{}' to object.", key); - return null; - } - } - - @Override - public <T> T get(String key, Class<T> clazz) { - // return null if key does not exist - try { - T property = configPropertyDao.getObjectValue(key, clazz); - return property; - - } catch (IllegalArgumentException e) { - log.debug("Error while searching for key '{}' in the database.", key); - return null; - } catch (Exception e) { - log.debug("Error while deserializing value of key '{}' to object of type {}.", key, clazz.getClass()); - return null; - } - } - - @Override - public boolean set(String key, String value) { - - try { - //TODO: add delete - if (value == null) { - //configPropertyDao.delete(key); - return true; - } else { - configPropertyDao.setStringValue(key, value); - return true; + Properties configProp = new Properties(); + for (Object key : input.keySet()) { + if (key.toString().startsWith(propPrefix)) { + String propertyName = key.toString().substring(propPrefix.length()); + configProp.put(propertyName, input.get(key.toString())); } - } catch (EntityExistsException e) { - log.debug("Property '{}' already exists!", key); - return false; - } catch (Exception e) { - log.debug("Error while setting value for key '{}' in the database.", key); - return false; } + return configProp; } + + +// @Override +// public List<String> getAllKeys(){ +// try { +// return Arrays.asList(this.configPropertyDao.getConfigurationIds()); +// } catch (Exception e) { +// log.debug("Error while retrieving a list of all keys in the database."); +// return null; +// } +// } +// +// @Override +// public String get(String key) { +// // return null if key does not exist +// try { +// return configPropertyDao.getStringValue(key); +// +// } catch (Exception e) { +// log.debug("Error while searching value of key '{}' to object.", key); +// return null; +// } +// } +// +// @Override +// public <T> T get(String key, Class<T> clazz) { +// // return null if key does not exist +// try { +// T property = configPropertyDao.getObjectValue(key, clazz); +// return property; +// +// } catch (IllegalArgumentException e) { +// log.debug("Error while searching for key '{}' in the database.", key); +// return null; +// } catch (Exception e) { +// log.debug("Error while deserializing value of key '{}' to object of type {}.", key, clazz.getClass()); +// return null; +// } +// } +// +// @Override +// public boolean set(String key, String value) { +// +// try { +// //TODO: add delete +// if (value == null) { +// //configPropertyDao.delete(key); +// return true; +// } else { +// configPropertyDao.setStringValue(key, value); +// return true; +// } +// } catch (EntityExistsException e) { +// log.debug("Property '{}' already exists!", key); +// return false; +// } catch (Exception e) { +// log.debug("Error while setting value for key '{}' in the database.", key); +// return false; +// } +// } // @Override // public <T> T get(String key, Class<T> clazz, Object defaultValue) { |