aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 10:59:09 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 11:10:50 +0200
commitc276e33e5ebdebc1c727dbd93ea1f876588a0dec (patch)
tree421ad087eefdea0848848012f4dce5efd7c93dce /id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao
parent8ec83e5be6888c9e5aeb8d21a35eb4d7ec040f67 (diff)
downloadmoa-id-spss-c276e33e5ebdebc1c727dbd93ea1f876588a0dec.tar.gz
moa-id-spss-c276e33e5ebdebc1c727dbd93ea1f876588a0dec.tar.bz2
moa-id-spss-c276e33e5ebdebc1c727dbd93ea1f876588a0dec.zip
refactor MOA-ID AuthConfiguration
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDao.java58
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDaoImpl.java169
2 files changed, 126 insertions, 101 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDao.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDao.java
deleted file mode 100644
index db35ba1df..000000000
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDao.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package at.gv.egovernment.moa.id.commons.db.dao.config;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * DAO interface providing means for accessing MOAID configuration properties.
- *
- */
-public interface ConfigPropertyDao {
-
- /**
- * Gets all keys in the database.
- * @return a List containing all keys in the database.
- */
- List<String> getAllKeys();
-
- /**
- * Returns the {@link ConfigProperty} associated with {@code key} or {@code null} if the entry does not exist.
- *
- * @param key The configuration key.
- * @return The configuration property value or {@code null}.
- */
- ConfigProperty getProperty(String key);
-
- /**
- * Persists a given {@link ConfigProperty}.
- * @param property The property to be persisted.
- */
- void saveProperty(ConfigProperty property);
-
- /**
- * Returns a {@link List} containing all stored {@linkplain ConfigProperty ConfigProperties}.
- * @return The list with the properties.
- */
- List<ConfigProperty> getProperties();
-
- /**
- * Returns the value for the configuration property associated with {@code key} or {@code null} if the entry does not exist or its value is {@code null}.
- *
- * @param key The configuration key.
- * @return The configuration property value or {@code null}.
- */
- String getPropertyValue(String key);
-
- /**
- * Persists a {@link List} of {@linkplain ConfigProperty ConfigProperties}.
- * @param properties The list containing all the properties to be persisted.
- */
- void saveProperties(Set<ConfigProperty> properties);
-
- /**
- * Deletes the object associated with the given key.
- * @param key the key
- */
- void delete(String key);
-
-}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDaoImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDaoImpl.java
index 6a76c1d17..24195b0cf 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDaoImpl.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyDaoImpl.java
@@ -1,10 +1,8 @@
package at.gv.egovernment.moa.id.commons.db.dao.config;
import java.util.List;
-import java.util.Set;
import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
@@ -12,20 +10,25 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
+import at.gv.egiz.components.configuration.api.AbstractConfigurationImpl;
+import at.gv.egiz.components.configuration.api.ConfigurationException;
+import at.gv.egovernment.moa.util.MiscUtil;
+
/**
* Database backed implementation of the DAO interface
*
*/
@Transactional("transactionManager")
-public class ConfigPropertyDaoImpl implements ConfigPropertyDao {
+public class ConfigPropertyDaoImpl extends AbstractConfigurationImpl {
private Logger log = LoggerFactory.getLogger(getClass());
@PersistenceContext(unitName = "moaidconf")
private EntityManager em;
+
@Override
- public List<String> getAllKeys() {
+ protected List<String> getAllKeys() {
if (null == em) {
log.error("No EntityManager set!");
return null;
@@ -35,70 +38,150 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao {
return result;
}
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#getValue(java.lang.String)
+ */
+ @Override
+ protected String getValue(String key) throws ConfigurationException {
+ ConfigProperty property = getProperty(key);
+ if (property == null)
+ return null;
+
+ else {
+ if (MiscUtil.isEmpty(property.getValue()))
+ return new String();
+ else
+ return property.getValue();
+
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#containsKey(java.lang.String)
+ */
+ @Override
+ protected boolean containsKey(String key) throws ConfigurationException {
+ ConfigProperty property = getProperty(key);
+ if (property == null)
+ return false;
+ else
+ return true;
+
+ }
+
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#storeKey(java.lang.String, java.lang.String)
+ */
@Override
- public void saveProperty(ConfigProperty property) {
+ protected void storeKey(String key, String value) throws ConfigurationException {
if (null == em) {
log.error("No EntityManager set!");
return;
+
}
-
+ ConfigProperty property = new ConfigProperty();
+ property.setKey(key);
+ property.setValue(value);
log.debug("Storing '{}'.", property.toString());
em.persist(property);
+
}
- @Override
- public ConfigProperty getProperty(String key) {
- log.debug("Looking for configuration property for key '{}'.", key);
- ConfigProperty result = em.find(ConfigProperty.class, key);
- if (result != null) {
- log.debug("Found configuration property {}.", result);
- } else {
- log.debug("Unable to find configuration property for key '{}'.", key);
- }
- return result;
+ protected void deleteKey(String key) {
+ log.debug("Deleting entry with key '{}'.", key);
+ em.remove(em.find(ConfigProperty.class, key));
}
-
+
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#findConfigurationId(java.lang.String)
+ */
@Override
- public String getPropertyValue(String key) {
- ConfigProperty property = getProperty(key);
- if (property == null) {
+ public String[] findConfigurationId(String searchString)
+ throws ConfigurationException {
+ if (null == em) {
+ log.error("No EntityManager set!");
return null;
}
- return property.getValue();
+
+ TypedQuery<String> query = em.createQuery("select * from ConfigProperty dbconfig where dbconfig.key like :key", String.class);
+ query.setParameter("key", searchString.replace("*", "%"));
+ List<String> result = query.getResultList();
+ return result.toArray(new String[result.size()]);
}
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#findByValue(java.lang.String)
+ */
@Override
- public List<ConfigProperty> getProperties() {
-
+ public String[] findByValue(String searchString)
+ throws ConfigurationException {
if (null == em) {
log.error("No EntityManager set!");
return null;
}
-
- log.debug("Retrieving all properties from database.");
- TypedQuery<ConfigProperty> query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class);
- try {
- List<ConfigProperty> propertiesList = query.getResultList();
- return propertiesList;
- } catch (NoResultException e) {
- log.debug("No property found in database.");
- return null;
- }
+
+ TypedQuery<String> query = em.createQuery("select * from ConfigProperty dbconfig where dbconfig.value like :value", String.class);
+ query.setParameter("value", searchString.replace("*", "%"));
+ List<String> result = query.getResultList();
+ return result.toArray(new String[result.size()]);
}
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#synchronize()
+ */
@Override
- public void saveProperties(Set<ConfigProperty> properties) {
- log.debug("Storing {} properties to database.", properties.size());
- for (ConfigProperty cp : properties) {
- saveProperty(cp);
- }
- em.flush();
+ public void synchronize() throws ConfigurationException {
+ //INFO: no implementation required
+
}
+ /* (non-Javadoc)
+ * @see at.gv.egiz.components.configuration.api.AbstractConfigurationImpl#getName()
+ */
@Override
- public void delete(String key) {
- log.debug("Deleting entry with key '{}'.", key);
- em.remove(em.find(ConfigProperty.class, key));
+ public String getName() {
+ return "DatabaseConfiguration";
+ }
+
+
+ private ConfigProperty getProperty(String key) {
+ log.debug("Looking for configuration property for key '{}'.", key);
+ ConfigProperty result = em.find(ConfigProperty.class, key);
+ if (result != null) {
+ log.debug("Found configuration property {}.", result);
+ } else {
+ log.debug("Unable to find configuration property for key '{}'.", key);
+ }
+ return result;
}
-}
+
+// @Override
+// public String getPropertyValue(String key) {
+// ConfigProperty property = getProperty(key);
+// if (property == null) {
+// return null;
+// }
+// return property.getValue();
+// }
+//
+// @Override
+// public List<ConfigProperty> getProperties() {
+//
+// if (null == em) {
+// log.error("No EntityManager set!");
+// return null;
+// }
+//
+// log.debug("Retrieving all properties from database.");
+// TypedQuery<ConfigProperty> query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class);
+// try {
+// List<ConfigProperty> propertiesList = query.getResultList();
+// return propertiesList;
+// } catch (NoResultException e) {
+// log.debug("No property found in database.");
+// return null;
+// }
+// }
+
+} \ No newline at end of file