From 4791f1f77125e1c4c76d189f441924fd62874091 Mon Sep 17 00:00:00 2001 From: Christian Wagner Date: Mon, 19 Jan 2015 15:57:51 +0100 Subject: add writer to store the configuration in key-value database use solely kv database within 'AuthConfigurationProvider' add constants declaring db keys --- .../moa/id/conf/persistence/Configuration.java | 9 ++++++++- .../moa/id/conf/persistence/ConfigurationImpl.java | 16 ++++++++++++++-- .../moa/id/conf/persistence/dal/ConfigPropertyDao.java | 7 +++++++ .../id/conf/persistence/dal/ConfigPropertyDaoImpl.java | 14 ++++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) (limited to 'id/server/moa-id-commons/src/main/java/com/datentechnik') diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java index 6ec43c583..43f7d9454 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java @@ -27,7 +27,7 @@ public interface Configuration { * @param key * @param value */ - void set(String key, Object value); + boolean set(String key, Object value); /** * @@ -45,4 +45,11 @@ public interface Configuration { * @return */ List getList(String key, Class clazz); + + /** + * + * @param key + * @return + */ + void delete(String key); } \ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java index 7a52d0c9d..eebecf509 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java @@ -66,7 +66,7 @@ public class ConfigurationImpl implements Configuration { } @Override - public void set(String key, Object value) { + public boolean set(String key, Object value) { ConfigProperty keyValue = new ConfigProperty(); keyValue.setKey(key); @@ -74,10 +74,11 @@ public class ConfigurationImpl implements Configuration { keyValue.setValue(mapper.serialize(value)); // System.out.println(">> key - value: " + keyValue.getKey() + " - " + keyValue.getValue() + "\n"); configPropertyDao.saveProperty(keyValue); - + return true; } catch (JsonProcessingException e) { // TODO do proper error handling e.printStackTrace(); + return false; } } @@ -98,6 +99,10 @@ public class ConfigurationImpl implements Configuration { public List getList(String key, Class clazz) { CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz); + + if(configPropertyDao.getProperty(key)==null){ + return new ArrayList(); + } String json = configPropertyDao.getProperty(key).getValue(); ObjectMapper mapper = new ObjectMapper(); @@ -120,6 +125,12 @@ public class ConfigurationImpl implements Configuration { return property.getValue(); } + @Override + public void delete(String key) { + configPropertyDao.delete(key); + } + + /** * * @@ -178,4 +189,5 @@ public class ConfigurationImpl implements Configuration { }; + } diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java index a11d23ce8..50dddd745 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java @@ -42,4 +42,11 @@ public interface ConfigPropertyDao { * @param properties The list containing all the properties to be persisted. */ public void saveProperties(Set properties); + + /** + * Deletes the object associated with the given key. + * @param key the key + */ + public void delete(String key); + } diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java index 2b28cb245..752c7dc09 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java @@ -64,12 +64,12 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao { @Override public List getProperties() { - + if (null == em) { log.error("No EntityManager set!"); return null; } - + log.debug("Retrieving all properties from database."); TypedQuery query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class); try { @@ -90,4 +90,14 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao { em.flush(); } + @Override + public void delete(String key) { + log.debug("Deleting entry with key '{}'.", key); + try{ + em.remove(em.find(ConfigProperty.class, key)); + }catch (IllegalArgumentException e){ + log.trace("Error while deleting entry with key '{}':" + e.getMessage(), key); + } + } + } -- cgit v1.2.3