diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 13:34:42 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 13:34:42 +0200 |
commit | e0c190004d654a2fa4f91f33133f6d55444e3798 (patch) | |
tree | f550ebfb176cf923a7749894e4b45c18159cc648 /id/server/moa-id-commons/src/main/java/at/gv/egovernment | |
parent | 0ac1586549bf1bb391c48a4151a5f32a0863a5f4 (diff) | |
download | moa-id-spss-e0c190004d654a2fa4f91f33133f6d55444e3798.tar.gz moa-id-spss-e0c190004d654a2fa4f91f33133f6d55444e3798.tar.bz2 moa-id-spss-e0c190004d654a2fa4f91f33133f6d55444e3798.zip |
refactoring for properties based configuration
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment')
4 files changed, 146 insertions, 95 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java index 6217c6c68..71c95c1e6 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java @@ -175,10 +175,10 @@ public final class MOAIDConfigurationConstants { public static final String GENERAL_AUTH_SSO_TARGET = GENERAL_AUTH + "." + SSO + ".target"; public static final String GENERAL_AUTH_SSO_AUTHBLOCK_TEXT = GENERAL_AUTH + "." + SSO + ".authblock.text"; - private static final String GENERAL_PROTOCOLS = PROTOCOLS; - private static final String GENERAL_PROTOCOLS_SAML1 = GENERAL_PROTOCOLS + "." + SAML1; - private static final String GENERAL_PROTOCOLS_PVP2X = GENERAL_PROTOCOLS + "." + PVP2X; - private static final String GENERAL_PROTOCOLS_OPENID = GENERAL_PROTOCOLS + "." + OPENID; + public static final String GENERAL_PROTOCOLS = PROTOCOLS; + public static final String GENERAL_PROTOCOLS_SAML1 = GENERAL_PROTOCOLS + "." + SAML1; + public static final String GENERAL_PROTOCOLS_PVP2X = GENERAL_PROTOCOLS + "." + PVP2X; + public static final String GENERAL_PROTOCOLS_OPENID = GENERAL_PROTOCOLS + "." + OPENID; public static final String GENERAL_PROTOCOLS_SAML1_ENABLED = GENERAL_PROTOCOLS_SAML1 + ".enabled"; public static final String GENERAL_PROTOCOLS_SAML1_LEGACY = GENERAL_PROTOCOLS_SAML1 + ".legacy"; public static final String GENERAL_PROTOCOLS_SAML1_SOURCEID = GENERAL_PROTOCOLS_SAML1 + ".sourceID"; @@ -187,17 +187,20 @@ public final class MOAIDConfigurationConstants { public static final String GENERAL_PROTOCOLS_PVP2X_ENABLED = GENERAL_PROTOCOLS_PVP2X + ".enabled"; public static final String GENERAL_PROTOCOLS_PVP2X_LEGACY = GENERAL_PROTOCOLS_PVP2X + ".legacy"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_SERVICENAMME = GENERAL_PROTOCOLS_PVP2X + ".metadata.servicename"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_SHORTNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.org.name.short"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_FULLNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.org.name.full"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_URL = GENERAL_PROTOCOLS_PVP2X + ".metadata.org.url"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA = GENERAL_PROTOCOLS_PVP2X + ".metadata"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_SERVICENAMME = GENERAL_PROTOCOLS_PVP2X_METADATA + ".servicename"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG = GENERAL_PROTOCOLS_PVP2X_METADATA + ".org"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_SHORTNAME = GENERAL_PROTOCOLS_PVP2X_METADATA + ".name.short"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_FULLNAME = GENERAL_PROTOCOLS_PVP2X_METADATA + ".name.full"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_URL = GENERAL_PROTOCOLS_PVP2X_METADATA + ".url"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_FAMLIYNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.familyname"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_GIVENNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.givenname"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_MAIL = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.mail"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_PHONE = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.phone"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_COMPANY = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.company"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_TYPE = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.type"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT = GENERAL_PROTOCOLS_PVP2X_METADATA + ".contact"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_FAMLIYNAME = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".familyname"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_GIVENNAME = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".givenname"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_MAIL = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".mail"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_PHONE = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".phone"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_COMPANY = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".company"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_TYPE = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".type"; public static final String GENERAL_AUTH_AUTHBLOCK_TRANSFORMATION_NAME = GENERAL_AUTH + ".authblock.transformation.name"; public static final String GENERAL_AUTH_AUTHBLOCK_TRANSFORMATION_BASE64 = GENERAL_AUTH + ".authblock.transformation.base64"; diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java index 45f37ef97..026a907d7 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java @@ -1,44 +1,54 @@ package at.gv.egovernment.moa.id.commons.config.persistence; -import java.util.List; +import java.util.Properties; import at.gv.egiz.components.configuration.api.Configuration; /** * An interface for a key-value configuration. */ -public interface MOAIDConfiguration { +public interface MOAIDConfiguration extends Configuration { /** - * Gets all keys in the database. NOTE: may return an empty list or {@code null}. - * @return a List containing all keys in the database or {@code null}. - */ - List<String> getAllKeys(); - - /** - * Get the value associated with the given key as {@link Object}. - * @param key the key - * @return the String associated with the given key or {@code null} if the key does not exist or does not have a value. - */ - String get(String key); - - /** - * Get the object of type {@code T} associated with the given key. + * Get all key/value pairs with a prefix * - * @param key the key - * @param clazz the type of the requested object - * @return the object associated with the given key or {@code null} if the key does not exist or does not have a value. - */ - <T> T get(String key, Class<T> clazz); - - /** - * Store an object associated with a key. If the given object is set to {@code null} then the entry associated with the key is deleted. + * @param preFix A key prefix + * @return All key/value pairs with this prefix. The prefix is removed from the key. * - * @param key the key under which the value is stored, respectively key determining the entry to be deleted. - * @param value the String to store. if value is set to {@code null} then the entry associated with key {@code key} is deleted. - * @return {@code true} if the operation was carried out successfully, {@code false} otherwise. */ - boolean set(String key, String value); + Properties getPropertySubset(final String preFix); + + +// /** +// * Gets all keys in the database. NOTE: may return an empty list or {@code null}. +// * @return a List containing all keys in the database or {@code null}. +// */ +// List<String> getAllKeys(); +// +// /** +// * Get the value associated with the given key as {@link Object}. +// * @param key the key +// * @return the String associated with the given key or {@code null} if the key does not exist or does not have a value. +// */ +// String get(String key); +// +// /** +// * Get the object of type {@code T} associated with the given key. +// * +// * @param key the key +// * @param clazz the type of the requested object +// * @return the object associated with the given key or {@code null} if the key does not exist or does not have a value. +// */ +// <T> T get(String key, Class<T> clazz); +// +// /** +// * Store an object associated with a key. If the given object is set to {@code null} then the entry associated with the key is deleted. +// * +// * @param key the key under which the value is stored, respectively key determining the entry to be deleted. +// * @param value the String to store. if value is set to {@code null} then the entry associated with key {@code key} is deleted. +// * @return {@code true} if the operation was carried out successfully, {@code false} otherwise. +// */ +// boolean set(String key, String value); // // /** // * Get the object of type {@code T} associated with the given key from the database. If the key does not exist or does not have a value, the given default 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) { diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java index f5421a47d..22a7bf76b 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java @@ -40,6 +40,13 @@ import at.gv.egovernment.moa.util.MiscUtil; import com.fasterxml.jackson.annotation.JsonProperty; +/** + * + * @author tlenz + * + * @deprecated + */ + @SuppressWarnings("rawtypes") public class ConfigurationDBRead { |