diff options
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java')
-rw-r--r-- | id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java | 679 |
1 files changed, 345 insertions, 334 deletions
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 6efdd6223..5c14df671 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 @@ -22,6 +22,15 @@ *******************************************************************************/ package at.gv.egovernment.moa.id.commons.db; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; + +import org.apache.commons.lang3.StringEscapeUtils; + import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; @@ -29,15 +38,14 @@ import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; //import org.apache.commons.lang.StringEscapeUtils; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; - -import org.apache.commons.lang3.StringEscapeUtils; +import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +/** + * + * @author tlenz + * + * @deprecated + */ @SuppressWarnings("rawtypes") public class ConfigurationDBRead { @@ -63,330 +71,333 @@ public class ConfigurationDBRead { QUERIES.put("searchOnlineApplicationsWithID", "select onlineapplication from OnlineApplication onlineapplication where onlineapplication.friendlyName like :id"); } - public static OnlineApplication getActiveOnlineApplication(String id) { - MiscUtil.assertNotNull(id, "OnlineApplictionID"); - Logger.trace("Getting OnlineApplication with ID " + id + " from database."); - - List result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getActiveOnlineApplicationWithID")); - //query.setParameter("id", id+"%"); - query.setParameter("id", StringEscapeUtils.escapeHtml4(id)); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.debug("No entries found."); - return null; - } - - if (result.size() > 1) { - Logger.warn("OAIdentifier match to more then one DB-entry!"); - return null; - } - - return (OnlineApplication) result.get(0); - } - - public static OnlineApplication getOnlineApplication(String id) { - MiscUtil.assertNotNull(id, "OnlineApplictionID"); - Logger.trace("Getting OnlineApplication with ID " + id + " from database."); - - List result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithID")); - //query.setParameter("id", id+"%"); - query.setParameter("id", id); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - - if (result.size() > 1) { - Logger.warn("OAIdentifier match to more then one DB-entry!"); - return null; - } - - return (OnlineApplication) result.get(0); - } - - public static OnlineApplication getOnlineApplication(long dbid) { - MiscUtil.assertNotNull(dbid, "OnlineApplictionID"); - Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); - - List result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithDBID")); - //query.setParameter("id", id+"%"); - query.setParameter("id", dbid); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - - return (OnlineApplication) result.get(0); - } - - public static MOAIDConfiguration getMOAIDConfiguration() { - Logger.trace("Load MOAID Configuration from database."); - - List<MOAIDConfiguration> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getMOAIDConfiguration")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found. Create fresh instance."); - return null; - } - - return (MOAIDConfiguration) result.get(0); - } - - public static List<OnlineApplication> getAllOnlineApplications() { - Logger.trace("Get All OnlineApplications from database."); - - List<OnlineApplication> result = null; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOnlineApplications")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return result; - } - - public static List<OnlineApplication> getAllNewOnlineApplications() { - Logger.trace("Get All OnlineApplications from database."); - - List<OnlineApplication> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getAllNewOnlineApplications")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return result; - } - - public static List<UserDatabase> getAllUsers() { - Logger.trace("Get All OnlineApplications from database."); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getAllUsers")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return result; - } - - public static List<OnlineApplication> getAllActiveOnlineApplications() { - Logger.trace("Get All active OnlineApplications from database."); - - List<OnlineApplication> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getAllActiveOnlineApplications")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - result = new ArrayList<OnlineApplication>(); - - } - return result; - } - - @SuppressWarnings("rawtypes") - public static List<OnlineApplication> searchOnlineApplications(String id) { - MiscUtil.assertNotNull(id, "OnlineApplictionID"); - Logger.trace("Getting OnlineApplication with ID " + id + " from database."); - - List<OnlineApplication> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("searchOnlineApplicationsWithID")); - query.setParameter("id", "%" + id + "%"); - - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - - return result; - } - - public static UserDatabase getUserWithID(long id) { - MiscUtil.assertNotNull(id, "UserID"); - Logger.trace("Getting Userinformation with ID " + id + " from database."); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserID")); - query.setParameter("id", id); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return (UserDatabase) result.get(0); - } - - public static UserDatabase getUsersWithOADBID(long id) { - MiscUtil.assertNotNull(id, "OADBID"); - Logger.trace("Getting Userinformation with OADBID " + id + " from database."); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getUsersWithOADBID")); - query.setParameter("id", id); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return (UserDatabase) result.get(0); - } - - public static UserDatabase getUserWithUserName(String username) { - MiscUtil.assertNotNull(username, "UserName"); - Logger.trace("Getting Userinformation with ID " + username + " from database."); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserUsername")); - query.setParameter("username", username); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return (UserDatabase) result.get(0); - } - - public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { - MiscUtil.assertNotNull(bpkwbpk, "bpk/wbpk"); - Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserBPKWBPK")); - query.setParameter("bpk", bpkwbpk); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return (UserDatabase) result.get(0); - } - - public static UserDatabase getNewUserWithTokken(String tokken) { - MiscUtil.assertNotNull(tokken, "bpk/wbpk"); - Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getNewUserWithUserTokken")); - query.setParameter("tokken", tokken); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return (UserDatabase) result.get(0); - } - - public static List<UserDatabase> getAllNewUsers() { - Logger.trace("Get all new Users from Database"); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getAllNewUsers")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return result; - } - - public static List<UserDatabase> getAllOpenUsersRequests() { - Logger.trace("Get all new Users from Database"); - - List<UserDatabase> result; - EntityManager session = ConfigurationDBUtils.getCurrentSession(); - - javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOpenUsersRequests")); - result = query.getResultList(); - - Logger.trace("Found entries: " + result.size()); - - if (result.size() == 0) { - Logger.trace("No entries found."); - return null; - } - return result; - } +// public static OnlineApplication getActiveOnlineApplication(String id) { +// MiscUtil.assertNotNull(id, "OnlineApplictionID"); +// Logger.trace("Getting OnlineApplication with ID " + id + " from database."); +// +// List result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getActiveOnlineApplicationWithID")); +// //query.setParameter("id", id+"%"); +// query.setParameter("id", StringEscapeUtils.escapeHtml4(id)); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.debug("No entries found."); +// return null; +// } +// +// if (result.size() > 1) { +// Logger.warn("OAIdentifier match to more then one DB-entry!"); +// return null; +// } +// +// return (OnlineApplication) result.get(0); +// } +// +// public static OnlineApplication getOnlineApplication(String id) { +// MiscUtil.assertNotNull(id, "OnlineApplictionID"); +// Logger.trace("Getting OnlineApplication with ID " + id + " from database."); +// +// List result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithID")); +// //query.setParameter("id", id+"%"); +// query.setParameter("id", id); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// +// if (result.size() > 1) { +// Logger.warn("OAIdentifier match to more then one DB-entry!"); +// return null; +// } +// +// return (OnlineApplication) result.get(0); +// } +// +// public static OnlineApplication getOnlineApplication(long dbid) { +// MiscUtil.assertNotNull(dbid, "OnlineApplictionID"); +// Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); +// +// List result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getOnlineApplicationWithDBID")); +// //query.setParameter("id", id+"%"); +// query.setParameter("id", dbid); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// +// return (OnlineApplication) result.get(0); +// } +// +// @JsonProperty("getMOAIDConfiguration") +// public static MOAIDConfiguration getMOAIDConfiguration() { +// Logger.trace("Load MOAID Configuration from database."); +// +// List<MOAIDConfiguration> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getMOAIDConfiguration")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found. Create fresh instance."); +// return null; +// } +// +// return (MOAIDConfiguration) result.get(0); +// } +// +// @JsonProperty("getAllOnlineApplications") +// public static List<OnlineApplication> getAllOnlineApplications() { +// Logger.trace("Get All OnlineApplications from database."); +// +// List<OnlineApplication> result = null; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOnlineApplications")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return result; +// } +// +// public static List<OnlineApplication> getAllNewOnlineApplications() { +// Logger.trace("Get All OnlineApplications from database."); +// +// List<OnlineApplication> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getAllNewOnlineApplications")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return result; +// } +// +// @JsonProperty("getAllUsers") +// public static List<UserDatabase> getAllUsers() { +// Logger.trace("Get All OnlineApplications from database."); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getAllUsers")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return result; +// } +// +// public static List<OnlineApplication> getAllActiveOnlineApplications() { +// Logger.trace("Get All active OnlineApplications from database."); +// +// List<OnlineApplication> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getAllActiveOnlineApplications")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// result = new ArrayList<OnlineApplication>(); +// +// } +// return result; +// } +// +// @SuppressWarnings("rawtypes") +// public static List<OnlineApplication> searchOnlineApplications(String id) { +// MiscUtil.assertNotNull(id, "OnlineApplictionID"); +// Logger.trace("Getting OnlineApplication with ID " + id + " from database."); +// +// List<OnlineApplication> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("searchOnlineApplicationsWithID")); +// query.setParameter("id", "%" + id + "%"); +// +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// +// return result; +// } +// +// public static UserDatabase getUserWithID(long id) { +// MiscUtil.assertNotNull(id, "UserID"); +// Logger.trace("Getting Userinformation with ID " + id + " from database."); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserID")); +// query.setParameter("id", id); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return (UserDatabase) result.get(0); +// } +// +// public static UserDatabase getUsersWithOADBID(long id) { +// MiscUtil.assertNotNull(id, "OADBID"); +// Logger.trace("Getting Userinformation with OADBID " + id + " from database."); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getUsersWithOADBID")); +// query.setParameter("id", id); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return (UserDatabase) result.get(0); +// } +// +// public static UserDatabase getUserWithUserName(String username) { +// MiscUtil.assertNotNull(username, "UserName"); +// Logger.trace("Getting Userinformation with ID " + username + " from database."); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserUsername")); +// query.setParameter("username", username); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return (UserDatabase) result.get(0); +// } +// +// public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { +// MiscUtil.assertNotNull(bpkwbpk, "bpk/wbpk"); +// Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserBPKWBPK")); +// query.setParameter("bpk", bpkwbpk); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return (UserDatabase) result.get(0); +// } +// +// public static UserDatabase getNewUserWithTokken(String tokken) { +// MiscUtil.assertNotNull(tokken, "bpk/wbpk"); +// Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getNewUserWithUserTokken")); +// query.setParameter("tokken", tokken); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return (UserDatabase) result.get(0); +// } +// +// public static List<UserDatabase> getAllNewUsers() { +// Logger.trace("Get all new Users from Database"); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getAllNewUsers")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return result; +// } +// +// public static List<UserDatabase> getAllOpenUsersRequests() { +// Logger.trace("Get all new Users from Database"); +// +// List<UserDatabase> result; +// EntityManager session = ConfigurationDBUtils.getCurrentSession(); +// +// javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOpenUsersRequests")); +// result = query.getResultList(); +// +// Logger.trace("Found entries: " + result.size()); +// +// if (result.size() == 0) { +// Logger.trace("No entries found."); +// return null; +// } +// return result; +// } } |