src/java/de/uapcore/lightpit/entities/ModuleDao.java

changeset 27
1f2a96efa69f
parent 26
65d5a0ca49ae
--- a/src/java/de/uapcore/lightpit/entities/ModuleDao.java	Sun Apr 08 15:34:11 2018 +0200
+++ b/src/java/de/uapcore/lightpit/entities/ModuleDao.java	Sun Apr 08 16:41:02 2018 +0200
@@ -34,7 +34,6 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -88,18 +87,16 @@
     }
     
     /**
-     * Synchronizes a set of registered module classes with the database and gives a list of visible modules in return.
+     * Synchronizes a set of registered module classes with the database.
      * 
      * Inserts module classes which are not known to the database and sets them to be visible by default.
      * Module classes known to the database, which are not in the given set, are ignored.
      * 
      * @param conn the connection to use
      * @param moduleSet the module set to synchronize
-     * @return a list of elements from the given set, which should be visible in the menu
      * @throws SQLException
      */
-    public final List<Map.Entry<String, LightPITModule>>
-            syncRegisteredModuleClasses(Connection conn, Set<Map.Entry<String, LightPITModule>> moduleSet) throws SQLException {
+    public final void syncRegisteredModuleClasses(Connection conn, Set<Map.Entry<String, LightPITModule>> moduleSet) throws SQLException {
                 
         PreparedStatement
                 check = moduleCheckStatement(conn),
@@ -107,30 +104,17 @@
         insert.setBoolean(2, true);
         // update/delete not required, we do this in the module management UI
 
-        final List<Map.Entry<String, LightPITModule>> visibleModules = new ArrayList<>();
+        for (Map.Entry<String, LightPITModule> modEntry : moduleSet) {
+            if (modEntry.getValue().systemModule()) continue;
 
-        for (Map.Entry<String, LightPITModule> mod : moduleSet) {
-            if (mod.getValue().systemModule()) continue;
-
-            check.setString(1, mod.getKey());
+            check.setString(1, modEntry.getKey());
             try (ResultSet r = check.executeQuery()) {
-                final boolean visible;
-                if (r.next()) {
-                    visible = r.getBoolean(1);
-                } else {
-                    insert.setString(1, mod.getKey());
+                if (!r.next()) {
+                    insert.setString(1, modEntry.getKey());
                     insert.executeUpdate();
-                    visible = !mod.getValue().menuKey().isEmpty();
-                }
-                if (visible) {
-                    visibleModules.add(new AbstractMap.SimpleEntry<>(
-                            mod.getKey(),
-                            mod.getValue()
-                    ));
                 }
             }
         }
-        return visibleModules;
     }
 
     /**
@@ -144,8 +128,7 @@
      */
     public List<Module> listAll(Connection conn) throws SQLException {
         List<Module> list = new ArrayList<>();
-        try (
-                Statement stmt = conn.createStatement();
+        try (Statement stmt = conn.createStatement();
                 ResultSet result = stmt.executeQuery("SELECT * FROM lpitcore_module")) {
             while (result.next()) {
                 final Module mod = new Module();

mercurial