aboutsummaryrefslogtreecommitdiff
path: root/id
diff options
context:
space:
mode:
authorChristian Wagner <c.wagner@datentechnik-innovation.com>2015-01-14 15:16:43 +0100
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 11:07:49 +0200
commit22474d762e26931489593403774c1755601878be (patch)
tree8eb8ef4283fb6da6092284b33c7cca4dcbb48809 /id
parent0b78a86a1cb499873c7ba86c5568d3c8f4bda357 (diff)
downloadmoa-id-spss-22474d762e26931489593403774c1755601878be.tar.gz
moa-id-spss-22474d762e26931489593403774c1755601878be.tar.bz2
moa-id-spss-22474d762e26931489593403774c1755601878be.zip
add a class that has the same method signatures as 'ConfiguratiohnDBRead' and is capable of reading from the new key-value DB
Diffstat (limited to 'id')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java355
-rw-r--r--id/server/moa-id-commons/src/main/resources/configuration.beans.xml2
2 files changed, 357 insertions, 0 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
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 <T> List<T> getAllObjects(String key, Class<T> clazz) {
+ List<T> result = null;
+
+ result = conf.getList("getAllUsers", clazz);
+
+ return result;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static List<UserDatabase> getAllUsers() {
+
+ Logger.trace("Get All Users from database.");
+
+ return getAllObjects("getAllUsers", UserDatabase.class);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static List<OnlineApplication> getAllOnlineApplications() {
+
+ Logger.trace("Get All OnlineApplications from database.");
+
+ return getAllObjects("getAllOnlineApplications", OnlineApplication.class);
+ }
+
+ /**
+ *
+ * @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) {
+ 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<OnlineApplication> getAllActiveOnlineApplications() {
+
+ Logger.trace("Get All New OnlineApplications from database.");
+
+ List<OnlineApplication> result = new ArrayList<OnlineApplication>();
+ List<OnlineApplication> 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<OnlineApplication> 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<OnlineApplication> 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<OnlineApplication> 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<OnlineApplication> searchOnlineApplications(String id) {
+ Logger.trace("Getting OnlineApplication with ID " + id + " from database.");
+
+ List<OnlineApplication> result = new ArrayList<OnlineApplication>();
+
+ List<OnlineApplication> 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<UserDatabase> getAllOpenUsersRequests() {
+ Logger.trace("Get all new Users from Database");
+
+ List<UserDatabase> result = new ArrayList<UserDatabase>();
+ List<UserDatabase> 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<UserDatabase> 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<UserDatabase> 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<UserDatabase> 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<UserDatabase> 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<UserDatabase> 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 @@
</bean>
<bean id="auth" class="at.gv.egovernment.moa.id.config.auth.NewAuthConfigurationProvider"/>
+
+ <bean id="auth" class="at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true" destroy-method="close">
<aop:scoped-proxy/>