From 22474d762e26931489593403774c1755601878be Mon Sep 17 00:00:00 2001 From: Christian Wagner Date: Wed, 14 Jan 2015 15:16:43 +0100 Subject: add a class that has the same method signatures as 'ConfiguratiohnDBRead' and is capable of reading from the new key-value DB --- .../moa/id/commons/db/NewConfigurationDBRead.java | 355 +++++++++++++++++++++ .../src/main/resources/configuration.beans.xml | 2 + 2 files changed, 357 insertions(+) create mode 100644 id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java 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 new file mode 100644 index 000000000..470d4d293 --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java @@ -0,0 +1,355 @@ +package at.gv.egovernment.moa.id.commons.db; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; + +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; +import at.gv.egovernment.moa.logging.Logger; + +import com.datentechnik.moa.id.conf.persistence.Configuration; + +/** + * + * + */ +public class NewConfigurationDBRead { + + @Autowired + private static Configuration conf; + + /** + * + * @param key + * @param clazz + * @return + */ + private static List getAllObjects(String key, Class clazz) { + List result = null; + + result = conf.getList("getAllUsers", clazz); + + return result; + } + + /** + * + * @return + */ + public static List getAllUsers() { + + Logger.trace("Get All Users from database."); + + return getAllObjects("getAllUsers", UserDatabase.class); + } + + /** + * + * @return + */ + public static List getAllOnlineApplications() { + + Logger.trace("Get All OnlineApplications from database."); + + return getAllObjects("getAllOnlineApplications", OnlineApplication.class); + } + + /** + * + * @return + */ + public static List getAllNewOnlineApplications() { + + Logger.trace("Get All New OnlineApplications from database."); + + List result = new ArrayList(); + List allOAs = getAllOnlineApplications(); + + for (OnlineApplication oa : allOAs) { + if (!oa.isIsActive() && oa.isIsAdminRequired()) { + result.add(oa); + } + } + + return result; + } + + /** + * + * @return + */ + public static MOAIDConfiguration getMOAIDConfiguration() { + + Logger.trace("Load MOAID Configuration from database."); + + MOAIDConfiguration result = null; + + result = conf.get("getMOAIDConfiguration", MOAIDConfiguration.class); + + return result; + } + + /** + * + * @return + */ + public static List getAllActiveOnlineApplications() { + + Logger.trace("Get All New OnlineApplications from database."); + + List result = new ArrayList(); + List allOAs = getAllOnlineApplications(); + + for (OnlineApplication oa : allOAs) { + if (oa.isIsActive()) { + result.add(oa); + } + } + + return result; + } + + /** + * + * @param id + * @return + */ + public static OnlineApplication getActiveOnlineApplication(String id) { + + Logger.trace("Getting Active OnlineApplication with ID " + id + " from database."); + + OnlineApplication result = null; + List allActiveOAs = getAllActiveOnlineApplications(); + + for (OnlineApplication oa : allActiveOAs) { + String publicUrlPrefix = oa.getPublicURLPrefix(); + if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { + if ((id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix))) { + if (result != null) { + Logger.warn("OAIdentifier match to more then one DB-entry!"); + return null; + } else { + result = oa; + } + } + } + } + + return result; + } + + /** + * + * @param dbid + * @return + */ + public static OnlineApplication getOnlineApplication(long dbid) { + Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); + + OnlineApplication result = null; + List allOAs = getAllOnlineApplications(); + + for (OnlineApplication oa : allOAs) { + if (oa.getHjid() == dbid) { + result = oa; + break; + } + } + + return result; + } + + /** + * + * @param id + * @return + */ + public static OnlineApplication getOnlineApplication(String id) { + + Logger.trace("Getting OnlineApplication with ID " + id + " from database."); + + OnlineApplication result = null; + List allOAs = getAllOnlineApplications(); + + for (OnlineApplication oa : allOAs) { + String publicUrlPrefix = oa.getPublicURLPrefix(); + if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { + if (id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix)) { + if (result != null) { + Logger.warn("OAIdentifier match to more then one DB-entry!"); + return null; + } else { + result = oa; + } + } + } + } + + return result; + } + + /** + * + * @param id + * @return + */ + public static List searchOnlineApplications(String id) { + Logger.trace("Getting OnlineApplication with ID " + id + " from database."); + + List result = new ArrayList(); + + List allOAs = getAllOnlineApplications(); + + for (OnlineApplication oa : allOAs) { + if (id.equals(oa.getFriendlyName())) { + result.add(oa); + } + } + + if (result.size() == 0) { + Logger.trace("No entries found."); + return null; + } else { + Logger.trace("Found entries: " + result.size()); + return result; + } + } + + /** + * + * @return + */ + public static List getAllOpenUsersRequests() { + Logger.trace("Get all new Users from Database"); + + List result = new ArrayList(); + List allUsers = getAllUsers(); + + for (UserDatabase user : allUsers) { + // TODO check result of query "... userdatabase.userRequestTokken is not null" if Tokken is null -> (null, "NULL", "", ... ?) + if ((user.getUserRequestTokken() != null || !user.getUserRequestTokken().equals("") || !user.getUserRequestTokken().equals("NULL")) + && (user.isIsAdminRequest()) && (!user.isIsMailAddressVerified())) { + result.add(user); + } + } + return result; + } + + /** + * + * @param tokken + * @return + */ + public static UserDatabase getNewUserWithTokken(String tokken) { + + Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); + + UserDatabase result = null; + List allUsers = getAllUsers(); + + for (UserDatabase user : allUsers) { + if (user.getUserRequestTokken().equals(tokken)) { + result = user; + break; + } + } + + return result; + } + + /** + * + * @param id + * @return + */ + public static UserDatabase getUsersWithOADBID(long id) { + + UserDatabase result = null; + List allUsers = getAllUsers(); + + boolean quit = false; + for (UserDatabase user : allUsers) { + + for (OnlineApplication oa : user.getOnlineApplication()) { + + if (oa.getHjid() == id) { + result = user; + quit = true; + break; + } + } + + if (quit) { + break; + } + } + + return result; + } + + /** + * + * @param id + * @return + */ + public static UserDatabase getUserWithID(long id) { + + Logger.trace("Getting Userinformation with ID " + id + " from database."); + + UserDatabase result = null; + List allUsers = getAllUsers(); + for (UserDatabase user : allUsers) { + if (user.getHjid() == id) { + result = user; + } + } + + return result; + } + + /** + * + * @param username + * @return + */ + public static UserDatabase getUserWithUserName(String username) { + + Logger.trace("Getting Userinformation with ID " + username + " from database."); + + UserDatabase result = null; + List allUsers = getAllUsers(); + + for (UserDatabase user : allUsers) { + if (user.getUsername().equals(username)) { + result = user; + } + } + + return result; + } + + /** + * + * @param bpkwbpk + * @return + */ + public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { + + Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); + + UserDatabase result = null; + List allUsers = getAllUsers(); + + for (UserDatabase user : allUsers) { + if (user.getBpk().equals(bpkwbpk)) { + result = user; + } + } + + return result; + } + +} diff --git a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml index a2e678a5f..1a2e1fedd 100644 --- a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml +++ b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml @@ -22,6 +22,8 @@ + + -- cgit v1.2.3