aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/moa-id-commons/src/main/java')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java12
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java110
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java10
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java7
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java35
5 files changed, 135 insertions, 39 deletions
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 223f29a0b..4bd459f23 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
@@ -61,4 +61,16 @@ public interface MOAIDConfiguration extends Configuration {
* @throws ConfigurationException in case of an configuration access error
*/
public Map<String, String> getOnlineApplication(String publicURLPrefix) throws ConfigurationException;
+
+
+ /**
+ * Load an OnlineApplication configuration and remove the OA key prefix
+ * This is a backup version if direct UniqueID selection does not work
+ *
+ * @param publicURLPrefix: Unique identifier of online application
+ * @return Properties of the online application or null if no OA is found
+ * @throws ConfigurationException in case of an configuration access error
+ */
+ public Map<String, String> getOnlineApplicationBackupVersion(String publicURLPrefix) throws ConfigurationException;
+
} \ No newline at end of file
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 297c63d7d..b9b5ad611 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
@@ -1,5 +1,7 @@
package at.gv.egovernment.moa.id.commons.config.persistence;
+import java.sql.SQLSyntaxErrorException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -131,13 +133,88 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement
String keyId = MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES
+ ".%."
+ MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER;
-
+
+ List<ConfigProperty> oaSearchResult = null;
TypedQuery<ConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", ConfigProperty.class);
oaSearchQuery.setParameter("key", keyId);
oaSearchQuery.setParameter("uniqueID", publicURLPrefix);
- List<ConfigProperty> oaSearchResult = oaSearchQuery.getResultList();
+ oaSearchResult = oaSearchQuery.getResultList();
+
+ return postProcessLoadOnlineApplication(em, oaSearchResult);
+
+ }
+
+ /* (non-Javadoc)
+ * @see at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration#getOnlineApplicationBackupVersion(java.lang.String)
+ */
+ @Override
+ public Map<String, String> getOnlineApplicationBackupVersion(
+ String publicURLPrefix) throws ConfigurationException {
+ Logger.debug("Use backup implementation to query configuration database");
+
+ EntityManager em = this.getPersistenceContext();
+ if (null == em) {
+ Logger.error("No EntityManager set!");
+ throw new ConfigurationException("No EntityManager set!");
+
+ }
+
+ //search key prefix for online application with this publicURLPrefix
+ String keyId = MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES
+ + ".%."
+ + MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER;
- if (oaSearchResult.size() == 0) {
+ List<ConfigProperty> oaSearchResult = new ArrayList<ConfigProperty>();
+
+ TypedQuery<ConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class);
+ oaSearchQuery.setParameter("key", keyId);
+ List<ConfigProperty> intermResult = oaSearchQuery.getResultList();
+ if (intermResult != null) {
+ for (ConfigProperty el : intermResult) {
+ if (publicURLPrefix.startsWith(el.getValue()))
+ oaSearchResult.add(el);
+
+ }
+ }
+
+ return postProcessLoadOnlineApplication(em, oaSearchResult);
+
+ }
+
+ /**
+ * Small helper method. NOTE: may return empty configuration properties, but never {@code null}.
+ *
+ * @param propPrefix: the prefix of the desired property.
+ * @param input: List of database objects with key/value information.
+ * @param removePrefix: Indicates if the prefix should be removed from the result key
+ * @return the {@link Map} of configuration properties
+ */
+ private Map<String, String> getKeyValueFromDatabaseDAO(Iterator<ConfigProperty> input, final String prefix, boolean removePrefix) {
+ Map<String, String> configProp = new HashMap<String, String>();
+ while (input.hasNext()) {
+ ConfigProperty el = input.next();
+ if (removePrefix) {
+ if (el.getKey().startsWith(prefix)) {
+ String propertyName = KeyValueUtils.removePrefixFromKey(el.getKey(), prefix);
+ configProp.put(propertyName, el.getValue());
+
+ }
+ } else
+ configProp.put(el.getKey(), el.getValue());
+
+ }
+ return configProp;
+ }
+
+ /**
+ * Online-Application load operation post-processing
+ *
+ * @param em EntityManager for Database access
+ * @param oaSearchResult Search result of first OA selection operation
+ * @return Map of post-processed OA configuration key/value pairs
+ */
+ private Map<String, String> postProcessLoadOnlineApplication(EntityManager em, List<ConfigProperty> oaSearchResult) {
+ if (oaSearchResult == null || oaSearchResult.size() == 0) {
Logger.debug("No entries found.");
return null; }
@@ -170,31 +247,6 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement
result.put(MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES, oaType);
return result;
+
}
-
- /**
- * Small helper method. NOTE: may return empty configuration properties, but never {@code null}.
- *
- * @param propPrefix: the prefix of the desired property.
- * @param input: List of database objects with key/value information.
- * @param removePrefix: Indicates if the prefix should be removed from the result key
- * @return the {@link Map} of configuration properties
- */
- private Map<String, String> getKeyValueFromDatabaseDAO(Iterator<ConfigProperty> input, final String prefix, boolean removePrefix) {
- Map<String, String> configProp = new HashMap<String, String>();
- while (input.hasNext()) {
- ConfigProperty el = input.next();
- if (removePrefix) {
- if (el.getKey().startsWith(prefix)) {
- String propertyName = KeyValueUtils.removePrefixFromKey(el.getKey(), prefix);
- configProp.put(propertyName, el.getValue());
-
- }
- } else
- configProp.put(el.getKey(), el.getValue());
-
- }
- return configProp;
- }
-
}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
index 76215528d..49e0634cb 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
@@ -163,8 +163,9 @@ public final class MOASessionDBUtils {
} catch(HibernateException e) {
Logger.warn("Error during MOASession database saveOrUpdate. Rollback.", e);
- tx.rollback();
- throw new MOADatabaseException(e);
+ if (tx != null)
+ tx.rollback();
+ throw new MOADatabaseException(e);
}
}
@@ -183,8 +184,9 @@ public final class MOASessionDBUtils {
} catch(HibernateException e) {
Logger.warn("Error during MOASession database delete. Rollback.", e);
- tx.rollback();
- return false;
+ if (tx != null)
+ tx.rollback();
+ return false;
}
}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java
index 0f157f109..c049eebc4 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java
@@ -41,9 +41,12 @@ public class NewConfigurationDBRead {
}
- public Map<String, String> getOnlineApplicationKeyValueWithId(String id) {
+ public Map<String, String> getOnlineApplicationKeyValueWithId(String id, boolean backupVersion) {
try {
- return conf.getOnlineApplication(id);
+ if (backupVersion)
+ return conf.getOnlineApplicationBackupVersion(id);
+ else
+ return conf.getOnlineApplication(id);
} catch (ConfigurationException e) {
Logger.warn("OnlineApplication with Id: " + id + " not found.", e);
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java
index f59e39ac6..aad830d65 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java
@@ -1,6 +1,10 @@
package at.gv.egovernment.moa.id.commons.db.dao.config;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map.Entry;
+import java.util.regex.Pattern;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@@ -137,10 +141,33 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl {
throw new ConfigurationException("No EntityManager set!");
}
- TypedQuery<String> query = em.createQuery("select key 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()]);
+ TypedQuery<ConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig", ConfigProperty.class);
+ List<ConfigProperty> all = query.getResultList();
+
+ searchString = searchString.replace(".", "\\.");
+ String regex = searchString.replace("*", ".*");
+ regex = regex.replace("%", "\\w*");
+ log.debug("Searching with regex: {}", regex);
+ Pattern pattern = Pattern.compile(regex);
+
+ List<String> keyList = new ArrayList<String>();
+ Iterator<ConfigProperty> keyIt;
+ if (all != null) {
+ keyIt = all.iterator();
+ while(keyIt.hasNext()) {
+ ConfigProperty entry = keyIt.next();
+ String value = entry.getValue();
+ String key = entry.getKey();
+
+ if(pattern.matcher(value).matches()) {
+ keyList.add(key);
+ }
+ }
+ }
+
+ String[] result = new String[keyList.size()];
+ return keyList.toArray(result);
+
}
/* (non-Javadoc)