diff options
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/db/ConfigurationFromDBExtractor.java | 82 |
1 files changed, 82 insertions, 0 deletions
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> T getSingleValue(String queryString, Class<T> clazz) { + T result = null; + EntityManager session = ConfigurationDBUtils.getCurrentSession(); + TypedQuery<T> query = session.createQuery(queryString, clazz); + try { + result = clazz.cast(query.getSingleResult()); + } catch (Exception e) { + return null; + } + return result; + } + + private static <T> List<T> getListOfValues(String queryString, Class<T> clazz) { + List<T> result = new ArrayList<T>(); + EntityManager session = ConfigurationDBUtils.getCurrentSession(); + TypedQuery<T> query = session.createQuery(queryString, clazz); + try { + result = query.getResultList(); + } catch (Exception e) { + return new ArrayList<T>(); + } + 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<OnlineApplication> getOnlineApplications() { + return getListOfValues("from OnlineApplication", OnlineApplication.class); + } + + public static List<GenericConfiguration> 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); + } + +} |