diff options
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv')
-rw-r--r-- | id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java | 79 |
1 files changed, 49 insertions, 30 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 470d4d293..8e2ae7e46 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 @@ -1,6 +1,7 @@ package at.gv.egovernment.moa.id.commons.db; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +22,15 @@ public class NewConfigurationDBRead { @Autowired private static Configuration conf; + @SuppressWarnings("unchecked") + public static <T extends Iterable<?>> T nullGuard(T item) { + if (item == null) { + return (T) Collections.emptyList(); + } else { + return item; + } + } + /** * * @param key @@ -28,10 +38,9 @@ public class NewConfigurationDBRead { * @return */ private static <T> List<T> getAllObjects(String key, Class<T> clazz) { - List<T> result = null; + List<T> result = null; result = conf.getList("getAllUsers", clazz); - return result; } @@ -40,10 +49,15 @@ public class NewConfigurationDBRead { * @return */ public static List<UserDatabase> getAllUsers() { - Logger.trace("Get All Users from database."); - return getAllObjects("getAllUsers", UserDatabase.class); + List<UserDatabase> result = getAllObjects("getAllUsers", UserDatabase.class); + if (result.size() == 0) { + Logger.trace("No entries found."); + return null; + } + + return result; } /** @@ -51,7 +65,6 @@ public class NewConfigurationDBRead { * @return */ public static List<OnlineApplication> getAllOnlineApplications() { - Logger.trace("Get All OnlineApplications from database."); return getAllObjects("getAllOnlineApplications", OnlineApplication.class); @@ -62,18 +75,22 @@ public class NewConfigurationDBRead { * @return */ public static List<OnlineApplication> getAllNewOnlineApplications() { - Logger.trace("Get All New OnlineApplications from database."); List<OnlineApplication> result = new ArrayList<OnlineApplication>(); List<OnlineApplication> allOAs = getAllOnlineApplications(); - for (OnlineApplication oa : allOAs) { + for (OnlineApplication oa : nullGuard(allOAs)) { if (!oa.isIsActive() && oa.isIsAdminRequired()) { result.add(oa); } } + if (result.size() == 0) { + Logger.trace("No entries found."); + return null; + } + return result; } @@ -82,7 +99,6 @@ public class NewConfigurationDBRead { * @return */ public static MOAIDConfiguration getMOAIDConfiguration() { - Logger.trace("Load MOAID Configuration from database."); MOAIDConfiguration result = null; @@ -97,18 +113,22 @@ public class NewConfigurationDBRead { * @return */ public static List<OnlineApplication> getAllActiveOnlineApplications() { - Logger.trace("Get All New OnlineApplications from database."); List<OnlineApplication> result = new ArrayList<OnlineApplication>(); List<OnlineApplication> allOAs = getAllOnlineApplications(); - for (OnlineApplication oa : allOAs) { + for (OnlineApplication oa : nullGuard(allOAs)) { if (oa.isIsActive()) { result.add(oa); } } + if (result.size() == 0) { + Logger.trace("No entries found."); + return null; + } + return result; } @@ -118,13 +138,12 @@ public class NewConfigurationDBRead { * @return */ public static OnlineApplication getActiveOnlineApplication(String id) { - Logger.trace("Getting Active OnlineApplication with ID " + id + " from database."); OnlineApplication result = null; List<OnlineApplication> allActiveOAs = getAllActiveOnlineApplications(); - for (OnlineApplication oa : allActiveOAs) { + for (OnlineApplication oa : nullGuard(allActiveOAs)) { String publicUrlPrefix = oa.getPublicURLPrefix(); if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { if ((id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix))) { @@ -152,7 +171,7 @@ public class NewConfigurationDBRead { OnlineApplication result = null; List<OnlineApplication> allOAs = getAllOnlineApplications(); - for (OnlineApplication oa : allOAs) { + for (OnlineApplication oa : nullGuard(allOAs)) { if (oa.getHjid() == dbid) { result = oa; break; @@ -168,13 +187,12 @@ public class NewConfigurationDBRead { * @return */ public static OnlineApplication getOnlineApplication(String id) { - Logger.trace("Getting OnlineApplication with ID " + id + " from database."); OnlineApplication result = null; List<OnlineApplication> allOAs = getAllOnlineApplications(); - for (OnlineApplication oa : allOAs) { + for (OnlineApplication oa : nullGuard(allOAs)) { String publicUrlPrefix = oa.getPublicURLPrefix(); if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { if (id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix)) { @@ -200,10 +218,9 @@ public class NewConfigurationDBRead { Logger.trace("Getting OnlineApplication with ID " + id + " from database."); List<OnlineApplication> result = new ArrayList<OnlineApplication>(); - List<OnlineApplication> allOAs = getAllOnlineApplications(); - for (OnlineApplication oa : allOAs) { + for (OnlineApplication oa : nullGuard(allOAs)) { if (id.equals(oa.getFriendlyName())) { result.add(oa); } @@ -212,10 +229,9 @@ public class NewConfigurationDBRead { if (result.size() == 0) { Logger.trace("No entries found."); return null; - } else { - Logger.trace("Found entries: " + result.size()); - return result; } + + return result; } /** @@ -228,13 +244,19 @@ public class NewConfigurationDBRead { List<UserDatabase> result = new ArrayList<UserDatabase>(); List<UserDatabase> allUsers = getAllUsers(); - for (UserDatabase user : allUsers) { + 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")) && (user.isIsAdminRequest()) && (!user.isIsMailAddressVerified())) { result.add(user); } } + + if (result.size() == 0) { + Logger.trace("No entries found."); + return null; + } + return result; } @@ -244,13 +266,12 @@ public class NewConfigurationDBRead { * @return */ public static UserDatabase getNewUserWithTokken(String tokken) { - Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); UserDatabase result = null; List<UserDatabase> allUsers = getAllUsers(); - for (UserDatabase user : allUsers) { + for (UserDatabase user : nullGuard(allUsers)) { if (user.getUserRequestTokken().equals(tokken)) { result = user; break; @@ -266,12 +287,13 @@ public class NewConfigurationDBRead { * @return */ public static UserDatabase getUsersWithOADBID(long id) { + Logger.trace("Getting Userinformation with OADBID " + id + " from database."); UserDatabase result = null; List<UserDatabase> allUsers = getAllUsers(); boolean quit = false; - for (UserDatabase user : allUsers) { + for (UserDatabase user : nullGuard(allUsers)) { for (OnlineApplication oa : user.getOnlineApplication()) { @@ -296,12 +318,11 @@ public class NewConfigurationDBRead { * @return */ public static UserDatabase getUserWithID(long id) { - Logger.trace("Getting Userinformation with ID " + id + " from database."); UserDatabase result = null; List<UserDatabase> allUsers = getAllUsers(); - for (UserDatabase user : allUsers) { + for (UserDatabase user : nullGuard(allUsers)) { if (user.getHjid() == id) { result = user; } @@ -316,13 +337,12 @@ public class NewConfigurationDBRead { * @return */ public static UserDatabase getUserWithUserName(String username) { - Logger.trace("Getting Userinformation with ID " + username + " from database."); UserDatabase result = null; List<UserDatabase> allUsers = getAllUsers(); - for (UserDatabase user : allUsers) { + for (UserDatabase user : nullGuard(allUsers)) { if (user.getUsername().equals(username)) { result = user; } @@ -337,13 +357,12 @@ public class NewConfigurationDBRead { * @return */ public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { - Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); UserDatabase result = null; List<UserDatabase> allUsers = getAllUsers(); - for (UserDatabase user : allUsers) { + for (UserDatabase user : nullGuard(allUsers)) { if (user.getBpk().equals(bpkwbpk)) { result = user; } |