From c393a871d38abe1638addd106258d8211eaa6a92 Mon Sep 17 00:00:00 2001 From: Gerwin Gsenger Date: Fri, 16 Jan 2015 15:14:34 +0100 Subject: add ability to extract all database data needed to build a 'MOAIDConfiguration' object --- .../commons/db/ConfigurationFromDBExtractor.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java (limited to 'id/server/moa-id-commons/src/main') diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java new file mode 100644 index 000000000..63c3b5bfb --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java @@ -0,0 +1,82 @@ +package at.gv.egovernment.moa.id.commons.db; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; + +import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; +import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; +import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; +import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; +import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; + +public class ConfigurationFromDBExtractor { + + private ConfigurationFromDBExtractor() { + } + + private static T getSingleValue(String queryString, Class clazz) { + T result = null; + EntityManager session = ConfigurationDBUtils.getCurrentSession(); + TypedQuery query = session.createQuery(queryString, clazz); + try { + result = clazz.cast(query.getSingleResult()); + } catch (Exception e) { + return null; + } + return result; + } + + private static List getListOfValues(String queryString, Class clazz) { + List result = new ArrayList(); + EntityManager session = ConfigurationDBUtils.getCurrentSession(); + TypedQuery query = session.createQuery(queryString, clazz); + try { + result = query.getResultList(); + } catch (Exception e) { + return new ArrayList(); + } + return result; + } + + public static AuthComponentGeneral getAuthComponentGeneral() { + return getSingleValue("from AuthComponentGeneral", AuthComponentGeneral.class); + } + + public static ChainingModes getChainingModes() { + return (ChainingModes) getSingleValue("from ChainingModes", ChainingModes.class); + } + + public static List getOnlineApplications() { + return getListOfValues("from OnlineApplication", OnlineApplication.class); + } + + public static List getGenericConfigurations() { + return getListOfValues("from GenericConfiguration", GenericConfiguration.class); + } + + public static String getTrustedCACertificates() { + return getSingleValue("select trustedCACertificates from MOAIDConfiguration", String.class); + } + + public static DefaultBKUs getDefaultBKUs() { + return getSingleValue("select defaultBKUs from MOAIDConfiguration", DefaultBKUs.class); + } + + public static SLRequestTemplates getSLRequestTemplates() { + return getSingleValue("select SLRequestTemplates from MOAIDConfiguration", SLRequestTemplates.class); + } + + public static Date getTimeStampItem() { + return getSingleValue("select timestampItem from MOAIDConfiguration", Date.class); + } + + public static Date getPvp2RefreshItem() { + return getSingleValue("select pvp2RefreshItem from MOAIDConfiguration", Date.class); + } + +} -- cgit v1.2.3