From 1c8dc14de27abd95b79f4d515e80639ccb1cc366 Mon Sep 17 00:00:00 2001 From: Gerwin Gsenger Date: Thu, 15 Jan 2015 10:20:46 +0100 Subject: small codereview, added corresponding databasequeries as comments --- .../moa/id/commons/db/NewConfigurationDBRead.java | 52 +++++++++++++++------- 1 file changed, 35 insertions(+), 17 deletions(-) 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 8e2ae7e46..e39f598b1 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 @@ -31,19 +31,6 @@ public class NewConfigurationDBRead { } } - /** - * - * @param key - * @param clazz - * @return - */ - private static List getAllObjects(String key, Class clazz) { - - List result = null; - result = conf.getList("getAllUsers", clazz); - return result; - } - /** * * @return @@ -51,7 +38,8 @@ public class NewConfigurationDBRead { public static List getAllUsers() { Logger.trace("Get All Users from database."); - List result = getAllObjects("getAllUsers", UserDatabase.class); + // select userdatabase from UserDatabase userdatabase + List result = conf.getList("getAllUsers", UserDatabase.class); if (result.size() == 0) { Logger.trace("No entries found."); return null; @@ -67,7 +55,8 @@ public class NewConfigurationDBRead { public static List getAllOnlineApplications() { Logger.trace("Get All OnlineApplications from database."); - return getAllObjects("getAllOnlineApplications", OnlineApplication.class); + // select onlineapplication from OnlineApplication onlineapplication + return conf.getList("getAllOnlineApplications", OnlineApplication.class); } /** @@ -77,6 +66,8 @@ public class NewConfigurationDBRead { public static List getAllNewOnlineApplications() { Logger.trace("Get All New OnlineApplications from database."); + // select onlineapplication from OnlineApplication onlineapplication + // where onlineapplication.isActive = '0' and onlineapplication.isAdminRequired = '1' List result = new ArrayList(); List allOAs = getAllOnlineApplications(); @@ -101,10 +92,14 @@ public class NewConfigurationDBRead { public static MOAIDConfiguration getMOAIDConfiguration() { Logger.trace("Load MOAID Configuration from database."); + // select moaidconfiguration from MOAIDConfiguration moaidconfiguration MOAIDConfiguration result = null; - result = conf.get("getMOAIDConfiguration", MOAIDConfiguration.class); + if(result == null){ + Logger.trace("No entries found. Create fresh instance."); + return new MOAIDConfiguration(); + } return result; } @@ -115,6 +110,8 @@ public class NewConfigurationDBRead { public static List getAllActiveOnlineApplications() { Logger.trace("Get All New OnlineApplications from database."); + // select onlineapplication from OnlineApplication onlineapplication + // where onlineapplication.isActive = '1' List result = new ArrayList(); List allOAs = getAllOnlineApplications(); @@ -140,6 +137,9 @@ public class NewConfigurationDBRead { public static OnlineApplication getActiveOnlineApplication(String id) { Logger.trace("Getting Active OnlineApplication with ID " + id + " from database."); + // select onlineapplication from OnlineApplication onlineapplication + // where onlineapplication.publicURLPrefix = + // SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) and onlineapplication.isActive = '1' OnlineApplication result = null; List allActiveOAs = getAllActiveOnlineApplications(); @@ -168,6 +168,7 @@ public class NewConfigurationDBRead { public static OnlineApplication getOnlineApplication(long dbid) { Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); + // select onlineapplication from OnlineApplication onlineapplication where onlineapplication.hjid = :id OnlineApplication result = null; List allOAs = getAllOnlineApplications(); @@ -189,6 +190,8 @@ public class NewConfigurationDBRead { public static OnlineApplication getOnlineApplication(String id) { Logger.trace("Getting OnlineApplication with ID " + id + " from database."); + // select onlineapplication from OnlineApplication onlineapplication + // where onlineapplication.publicURLPrefix = SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) OnlineApplication result = null; List allOAs = getAllOnlineApplications(); @@ -217,6 +220,8 @@ public class NewConfigurationDBRead { public static List searchOnlineApplications(String id) { Logger.trace("Getting OnlineApplication with ID " + id + " from database."); + // select onlineapplication from OnlineApplication onlineapplication + // where onlineapplication.friendlyName like :id List result = new ArrayList(); List allOAs = getAllOnlineApplications(); @@ -241,12 +246,15 @@ public class NewConfigurationDBRead { public static List getAllOpenUsersRequests() { Logger.trace("Get all new Users from Database"); + // select userdatabase from UserDatabase userdatabase + // where userdatabase.userRequestTokken is not null + // and userdatabase.isAdminRequest = '1' and userdatabase.isMailAddressVerified = '0' List result = new ArrayList(); List allUsers = getAllUsers(); for (UserDatabase user : nullGuard(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")) + if ((user.getUserRequestTokken() != null && !user.getUserRequestTokken().isEmpty() && !user.getUserRequestTokken().equals("NULL")) && (user.isIsAdminRequest()) && (!user.isIsMailAddressVerified())) { result.add(user); } @@ -268,6 +276,7 @@ public class NewConfigurationDBRead { public static UserDatabase getNewUserWithTokken(String tokken) { Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); + // select userdatabase from UserDatabase userdatabase where userdatabase.userRequestTokken = :tokken UserDatabase result = null; List allUsers = getAllUsers(); @@ -289,6 +298,8 @@ public class NewConfigurationDBRead { public static UserDatabase getUsersWithOADBID(long id) { Logger.trace("Getting Userinformation with OADBID " + id + " from database."); + // select userdatabase from UserDatabase userdatabase + // inner join userdatabase.onlineApplication oa where oa.hjid = :id UserDatabase result = null; List allUsers = getAllUsers(); @@ -320,11 +331,14 @@ public class NewConfigurationDBRead { public static UserDatabase getUserWithID(long id) { Logger.trace("Getting Userinformation with ID " + id + " from database."); + // select userdatabase from UserDatabase userdatabase where userdatabase.hjid = :id UserDatabase result = null; List allUsers = getAllUsers(); + for (UserDatabase user : nullGuard(allUsers)) { if (user.getHjid() == id) { result = user; + break; } } @@ -339,12 +353,14 @@ public class NewConfigurationDBRead { public static UserDatabase getUserWithUserName(String username) { Logger.trace("Getting Userinformation with ID " + username + " from database."); + // select userdatabase from UserDatabase userdatabase where userdatabase.username = :username UserDatabase result = null; List allUsers = getAllUsers(); for (UserDatabase user : nullGuard(allUsers)) { if (user.getUsername().equals(username)) { result = user; + break; } } @@ -359,12 +375,14 @@ public class NewConfigurationDBRead { public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); + // select userdatabase from UserDatabase userdatabase where userdatabase.bpk = :bpk UserDatabase result = null; List allUsers = getAllUsers(); for (UserDatabase user : nullGuard(allUsers)) { if (user.getBpk().equals(bpkwbpk)) { result = user; + break; } } -- cgit v1.2.3