Sun, 10 May 2020 10:11:37 +0200
removes features that are not (and probably will not) used anyway
--- a/setup/postgres/psql_create_tables.sql Sun May 10 10:11:10 2020 +0200 +++ b/setup/postgres/psql_create_tables.sql Sun May 10 10:11:37 2020 +0200 @@ -1,28 +1,9 @@ -- This script creates the module management tables -- -create table lpitcore_module ( - modid serial primary key, - classname varchar(100) not null unique, - visible boolean not null default(true), - priority integer not null default(1000) -); - create table lpitcore_user ( userid serial primary key, username varchar(50) not null unique, lastname varchar(50), givenname varchar(50) ); - -create table lpitcore_authorization ( - modid integer not null references lpitcore_modules(modid) on delete cascade, - userid integer not null references lpitcore_user(userid) on delete cascade, - power integer not null check(power >= 0) -); - -create table lpitcore_menu ( - modid integer not null references lpitcore_modules(modid) on delete cascade, - userid integer not null references lpitcore_user(userid) on delete cascade, - seq integer not null -);
--- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sun May 10 10:11:37 2020 +0200 @@ -52,14 +52,9 @@ private static final String HTML_FULL_DISPATCHER = Functions.jspPath("html_full"); /** - * Store a reference to the annotation for quicker access. - */ - private LightPITModule moduleInfo = null; - - /** * The EL proxy is necessary, because the EL resolver cannot handle annotation properties. */ - private LightPITModule.ELProxy moduleInfoELProxy = null; + private LightPITModule.ELProxy moduleInfo = null; @FunctionalInterface @@ -88,15 +83,6 @@ } /** - * Returns the annotated module information. - * - * @return the module annotation - */ - public final LightPITModule getModuleInfo() { - return moduleInfo; - } - - /** * Gives implementing modules access to the {@link DatabaseFacade}. * * @return the database facade @@ -118,8 +104,8 @@ @Override public void init() throws ServletException { - moduleInfo = this.getClass().getAnnotation(LightPITModule.class); - moduleInfoELProxy = moduleInfo == null ? null : LightPITModule.ELProxy.convert(moduleInfo); + moduleInfo = Optional.ofNullable(this.getClass().getAnnotation(LightPITModule.class)) + .map(LightPITModule.ELProxy::new).orElse(null); if (moduleInfo != null) { scanForRequestMappings(); @@ -228,7 +214,7 @@ private void forwardToFullView(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - req.setAttribute(Constants.REQ_ATTR_MENU, getModuleManager().getMainMenu(getDatabaseFacade())); + req.setAttribute(Constants.REQ_ATTR_MENU, getModuleManager().getMainMenu()); req.getRequestDispatcher(HTML_FULL_DISPATCHER).forward(req, resp); } @@ -255,9 +241,6 @@ private void doProcess(HttpMethod method, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - // Synchronize module information with database - getModuleManager().syncWithDatabase(getDatabaseFacade()); - // choose the requested language as session language (if available) or fall back to english, otherwise HttpSession session = req.getSession(); if (session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) == null) { @@ -275,7 +258,7 @@ // set some internal request attributes req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req)); req.setAttribute(Constants.REQ_ATTR_MODULE_CLASSNAME, this.getClass().getName()); - Optional.ofNullable(moduleInfoELProxy).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); + Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); // call the handler, if available, or send an HTTP 404 error
--- a/src/main/java/de/uapcore/lightpit/LightPITModule.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/LightPITModule.java Sun May 10 10:11:37 2020 +0200 @@ -128,24 +128,13 @@ class ELProxy { private final String bundleBaseName, modulePath, menuKey, titleKey, nameKey, descKey; - public static ELProxy convert(LightPITModule annotation) { - return new ELProxy( - annotation.bundleBaseName(), - annotation.modulePath(), - annotation.menuKey(), - annotation.titleKey(), - annotation.nameKey(), - annotation.descKey() - ); - } - - private ELProxy(String bundleBaseName, String modulePath, String menuKey, String titleKey, String nameKey, String descKey) { - this.bundleBaseName = bundleBaseName; - this.modulePath = modulePath; - this.menuKey = menuKey; - this.titleKey = titleKey; - this.nameKey = nameKey; - this.descKey = descKey; + public ELProxy(LightPITModule annotation) { + bundleBaseName = annotation.bundleBaseName(); + modulePath = annotation.modulePath(); + menuKey = annotation.menuKey(); + titleKey = annotation.titleKey(); + nameKey = annotation.nameKey(); + descKey = annotation.descKey(); } public String getBundleBaseName() {
--- a/src/main/java/de/uapcore/lightpit/Menu.java Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ -package de.uapcore.lightpit; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Maps a resource key for the menu label to the path name for the underlying - * site. - * <p> - * Objects of this class are internally instantiated by the - * {@link ModuleManager}. - */ -public class Menu extends MenuEntry { - - private final List<MenuEntry> entries = new ArrayList<>(); - private final List<MenuEntry> immutableEntries = Collections.unmodifiableList(entries); - - /** - * Class name of the module for which this menu is built. - */ - private String moduleClassName; - - - public Menu() { - super(); - } - - public Menu(String moduleClassName, ResourceKey resourceKey, String pathName) { - super(resourceKey, pathName); - this.moduleClassName = moduleClassName; - } - - public void setModuleClassName(String moduleClassName) { - this.moduleClassName = moduleClassName; - } - - public String getModuleClassName() { - return moduleClassName; - } - - /** - * Sets a new list of menu entries for this menu. - * - * @param entries the list of new menu entries - */ - public void setEntries(List<MenuEntry> entries) { - // in case the given list is immutable, we copy the contents - this.entries.clear(); - this.entries.addAll(entries); - } - - /** - * Retrieves an immutable list of menu entries for this menu. - * - * @return the list of menu entries - */ - public List<MenuEntry> getEntries() { - return immutableEntries; - } - - /** - * Adds a new menu entry to this menu. - * - * @param entry the menu entry to add - */ - public void addMenuEntry(MenuEntry entry) { - entries.add(entry); - } -}
--- a/src/main/java/de/uapcore/lightpit/MenuEntry.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/MenuEntry.java Sun May 10 10:11:37 2020 +0200 @@ -28,6 +28,8 @@ */ package de.uapcore.lightpit; +import java.util.Objects; + /** * Maps a resource key for the menu label to the path name for the underlying * site. @@ -35,40 +37,67 @@ * Objects of this class are internally instantiated by the * {@link ModuleManager}. */ -public class MenuEntry { +public class MenuEntry implements Comparable<MenuEntry> { + + /** + * Class name of the module for which this menu is built. + */ + private final String moduleClassName; /** * Resource key for the menu label. */ - private ResourceKey resourceKey; + private final ResourceKey resourceKey; /** * Path name of the module, linked by this menu entry. */ - private String pathName; + private final String pathName; - public MenuEntry() { + /** + * Sequence number to determine the ordering of the menu. + */ + private final int sequence; + + public MenuEntry(String moduleClassName, ResourceKey resourceKey, String pathName, int sequence) { + this.moduleClassName = moduleClassName; + this.resourceKey = resourceKey; + this.pathName = pathName; + this.sequence = sequence; } - public MenuEntry(ResourceKey resourceKey, String pathName) { - this.resourceKey = resourceKey; - this.pathName = pathName; - } - - public void setResourceKey(ResourceKey resourceKey) { - this.resourceKey = resourceKey; + public String getModuleClassName() { + return moduleClassName; } public ResourceKey getResourceKey() { return resourceKey; } - public void setPathName(String pathName) { - this.pathName = pathName; - } - public String getPathName() { return pathName; } + public int getSequence() { + return sequence; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MenuEntry menuEntry = (MenuEntry) o; + return resourceKey.equals(menuEntry.resourceKey) && + pathName.equals(menuEntry.pathName); + } + + @Override + public int hashCode() { + return Objects.hash(resourceKey, pathName); + } + + @Override + public int compareTo(MenuEntry menuEntry) { + return Integer.compare(this.sequence, menuEntry.sequence); + } }
--- a/src/main/java/de/uapcore/lightpit/ModuleManager.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/ModuleManager.java Sun May 10 10:11:37 2020 +0200 @@ -28,7 +28,6 @@ */ package de.uapcore.lightpit; -import de.uapcore.lightpit.entities.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,11 +36,7 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; -import java.sql.Connection; -import java.sql.SQLException; import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; /** * Scans registered servlets for LightPIT modules. @@ -63,9 +58,9 @@ private final Map<String, LightPITModule> registeredModules = new HashMap<>(); /** - * This flag is true, when synchronization is needed. + * Contains the menu entries for the loaded modules. */ - private final AtomicBoolean dirty = new AtomicBoolean(true); + private final List<MenuEntry> mainMenu = new ArrayList<>(); @Override public void contextInitialized(ServletContextEvent sce) { @@ -132,41 +127,9 @@ public void reloadAll() { registeredModules.clear(); sc.getServletRegistrations().forEach(this::handleServletRegistration); - - // TODO: implement dependency resolver - - dirty.set(true); - LOG.info("Modules loaded."); - } + createMainMenu(); - /** - * Synchronizes module information with the database. - * <p> - * This must be called from the {@link AbstractLightPITServlet}. - * Admittedly the call will perform the synchronization once after reload - * and be a no-op, afterwards. - * However, since the DatabaseFacade might be loaded after the module - * manager, we must defer the synchronization to the first request - * handled by the Servlet. - * - * @param db interface to the database - */ - public void syncWithDatabase(DatabaseFacade db) { - if (dirty.compareAndSet(true, false)) { - if (db.getDataSource().isPresent()) { - try (Connection conn = db.getDataSource().get().getConnection()) { - db.getDataAccessObjects() - .getModuleDao() - .syncRegisteredModuleClasses(conn, registeredModules.entrySet()); - } catch (SQLException ex) { - LOG.error("Unexpected SQL Exception", ex); - } - } else { - LOG.error("No datasource present. Cannot sync module information with database."); - } - } else { - LOG.trace("Module information clean - no synchronization required."); - } + LOG.info("Modules loaded."); } /** @@ -178,46 +141,30 @@ } /** - * Returns the main menu. - * - * @param db the interface to the database - * @return a list of menus belonging to the main menu + * Populates the main menu based on the registered modules. */ - public List<Menu> getMainMenu(DatabaseFacade db) { - // TODO: user specific menu - - if (db.getDataSource().isPresent()) { - try (Connection conn = db.getDataSource().get().getConnection()) { - final List<Module> modules = db.getDataAccessObjects().getModuleDao().list(conn); - - return modules - .stream() - .filter(Module::isVisible) - .sorted(new Module.PriorityComparator()) - .map(mod -> new Menu( - mod.getClassname(), - new ResourceKey( - registeredModules.get(mod.getClassname()).bundleBaseName(), - registeredModules.get(mod.getClassname()).menuKey()), - registeredModules.get(mod.getClassname()).modulePath())) - .collect(Collectors.toList()); - } catch (SQLException ex) { - LOG.error("Unexpected SQLException when loading the main menu", ex); - return Collections.emptyList(); - } - } else { - return Collections.emptyList(); - } + private void createMainMenu() { + mainMenu.clear(); + registeredModules.entrySet() + .stream() + .filter(mod -> !mod.getValue().systemModule()) + .map(mod -> new MenuEntry( + mod.getKey(), + new ResourceKey( + mod.getValue().bundleBaseName(), + mod.getValue().menuKey()), + mod.getValue().modulePath(), + mod.getValue().defaultPriority())) + .sorted() + .forEachOrdered(mainMenu::add); } /** - * Returns an unmodifiable map of all registered modules. - * <p> - * The key is the classname of the module. + * Returns the main menu. * - * @return the map of registered modules + * @return a list of menu items */ - public Map<String, LightPITModule> getRegisteredModules() { - return Collections.unmodifiableMap(registeredModules); + public List<MenuEntry> getMainMenu() { + return Collections.unmodifiableList(mainMenu); } }
--- a/src/main/java/de/uapcore/lightpit/dao/DataAccessObjects.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/dao/DataAccessObjects.java Sun May 10 10:11:37 2020 +0200 @@ -29,8 +29,5 @@ package de.uapcore.lightpit.dao; public interface DataAccessObjects { - - ModuleDao getModuleDao(); - UserDao getUserDao(); }
--- a/src/main/java/de/uapcore/lightpit/dao/ModuleDao.java Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ -package de.uapcore.lightpit.dao; - -import de.uapcore.lightpit.LightPITModule; -import de.uapcore.lightpit.entities.Module; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Map; -import java.util.Set; - -public interface ModuleDao extends GenericDao<Module> { - - /** - * Synchronizes a set of registered module classes with the database. - * <p> - * 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 - * @throws SQLException on any kind of SQL errors - */ - void syncRegisteredModuleClasses(Connection conn, Set<Map.Entry<String, LightPITModule>> moduleSet) throws SQLException; -}
--- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGDataAccessObjects.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/dao/postgres/PGDataAccessObjects.java Sun May 10 10:11:37 2020 +0200 @@ -29,20 +29,13 @@ package de.uapcore.lightpit.dao.postgres; import de.uapcore.lightpit.dao.DataAccessObjects; -import de.uapcore.lightpit.dao.ModuleDao; import de.uapcore.lightpit.dao.UserDao; public class PGDataAccessObjects implements DataAccessObjects { - private final ModuleDao moduleDao = new PGModuleDao(); private final UserDao userDao = new PGUserDao(); @Override - public ModuleDao getModuleDao() { - return moduleDao; - } - - @Override public UserDao getUserDao() { return userDao; }
--- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGModuleDao.java Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ -package de.uapcore.lightpit.dao.postgres; - -import de.uapcore.lightpit.LightPITModule; -import de.uapcore.lightpit.dao.AbstractDao; -import de.uapcore.lightpit.dao.ModuleDao; -import de.uapcore.lightpit.entities.Module; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map; -import java.util.Set; - -public final class PGModuleDao extends AbstractDao<Module> implements ModuleDao { - - @Override - protected PreparedStatement listQuery(Connection connection) throws SQLException { - return connection.prepareStatement("select * from lpitcore_module"); - } - - @Override - protected Module mapColumns(ResultSet result) throws SQLException { - final var mod = new Module(); - mod.setModID(result.getInt("modid")); - mod.setClassname(result.getString("classname")); - mod.setVisible(result.getBoolean("visible")); - mod.setPriority(result.getInt("priority")); - return mod; - } - - @Override - public void syncRegisteredModuleClasses(Connection conn, Set<Map.Entry<String, LightPITModule>> moduleSet) throws SQLException { - - var check = conn.prepareStatement("select visible from lpitcore_module where classname = ?"); - var insert = conn.prepareStatement("insert into lpitcore_module (classname, visible, priority) values (?, ?, ?)"); - insert.setBoolean(2, true); - // update/delete not required, we do this in the module management UI - - for (Map.Entry<String, LightPITModule> modEntry : moduleSet) { - if (modEntry.getValue().systemModule()) continue; - - check.setString(1, modEntry.getKey()); - try (ResultSet r = check.executeQuery()) { - if (!r.next()) { - insert.setString(1, modEntry.getKey()); - insert.setInt(3, modEntry.getValue().defaultPriority()); - insert.executeUpdate(); - } - } - } - } -}
--- a/src/main/java/de/uapcore/lightpit/entities/Module.java Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ -package de.uapcore.lightpit.entities; - -import de.uapcore.lightpit.LightPITModule; - -import java.util.Comparator; - -public final class Module { - private int modID; - private String classname; - private boolean visible; - private int priority; - - private LightPITModule.ELProxy annotatedInfos; - - public int getModID() { - return modID; - } - - public void setModID(int modID) { - this.modID = modID; - } - - public String getClassname() { - return classname; - } - - public void setClassname(String classname) { - this.classname = classname; - } - - public boolean isVisible() { - return visible; - } - - public void setVisible(boolean visible) { - this.visible = visible; - } - - public int getPriority() { - return priority; - } - - public void setPriority(int priority) { - this.priority = priority; - } - - public LightPITModule.ELProxy getAnnotatedInfos() { - return annotatedInfos; - } - - public void setAnnotatedInfos(LightPITModule.ELProxy annotatedInfos) { - this.annotatedInfos = annotatedInfos; - } - - @Override - public int hashCode() { - int hash = 3; - hash = 41 * hash + this.modID; - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } else { - return this.modID == ((Module) obj).modID; - } - } - - public static final class PriorityComparator implements Comparator<Module> { - - @Override - public int compare(Module left, Module right) { - return Integer.compare(left.priority, right.priority); - } - - @Override - public boolean equals(Object o) { - return o instanceof PriorityComparator; - } - } -}
--- a/src/main/java/de/uapcore/lightpit/modules/ModuleManagerModule.java Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ -package de.uapcore.lightpit.modules; - -import de.uapcore.lightpit.*; -import de.uapcore.lightpit.LightPITModule.ELProxy; -import de.uapcore.lightpit.entities.Module; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.sql.DataSource; -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Entry point for the application. - */ -@LightPITModule( - bundleBaseName = "localization.modmgmt", - modulePath = "modmgmt", - defaultPriority = 21000 -) -@WebServlet( - name = "ModuleManagerModule", - urlPatterns = "/modmgmt/*" -) -public final class ModuleManagerModule extends AbstractLightPITServlet { - - private static final Logger LOG = LoggerFactory.getLogger(ModuleManagerModule.class); - - private static final String REQ_ATTR_MODULES = "modules"; - - - @RequestMapping(method = HttpMethod.GET) - public ResponseType handle(HttpServletRequest req, HttpServletResponse resp) throws IOException { - - DatabaseFacade db = getDatabaseFacade(); - Optional<DataSource> ds = db.getDataSource(); - if (ds.isPresent()) { - try (Connection conn = ds.get().getConnection()) { - final List<Module> modules = db.getDataAccessObjects().getModuleDao().list(conn); - - final Map<String, LightPITModule> registeredModules = getModuleManager().getRegisteredModules(); - modules.forEach((mod) -> mod.setAnnotatedInfos(ELProxy.convert(registeredModules.get(mod.getClassname())))); - - req.setAttribute(REQ_ATTR_MODULES, modules); - setDynamicFragment(req, "modules"); - return ResponseType.HTML_FULL; - } catch (SQLException ex) { - LOG.error("Unexpected SQL Exception", ex); - resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return ResponseType.NONE; - } - } else { - resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return ResponseType.NONE; - } - } -}
--- a/src/main/java/de/uapcore/lightpit/modules/VersionsModule.java Sun May 10 10:11:10 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/VersionsModule.java Sun May 10 10:11:37 2020 +0200 @@ -37,7 +37,8 @@ @LightPITModule( bundleBaseName = "localization.versions", - modulePath = "versions" + modulePath = "versions", + defaultPriority = 50 ) @WebServlet( name = "VersionsModule",
--- a/src/main/resources/localization/modmgmt.properties Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -# Copyright 2018 Mike Becker. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -name = Module Management -description = Configure the visible LightPIT modules and the required access powers. -menuLabel = Modules - -section.modlist.title = List of Modules - -caption.module = Module -caption.path = Path -caption.desc = Description -caption.active = Active -caption.class = Class -caption.bundle = Resource Bundle -
--- a/src/main/resources/localization/modmgmt_de.properties Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -# Copyright 2018 Mike Becker. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -name = Modulverwaltung -description = Konfiguration der sichtbaren LightPIT Module und deren Zugriffsrechte. -menuLabel = Module - -section.modlist.title = Liste der Module - -caption.module = Modul -caption.path = Pfad -caption.desc = Beschreibung -caption.active = Aktiv -caption.class = Klasse -caption.bundle = Ressourcen-Datei
--- a/src/main/webapp/WEB-INF/dynamic_fragments/modules.jsp Sun May 10 10:11:10 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -<%-- -DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - -Copyright 2018 Mike Becker. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---%> -<%@page pageEncoding="UTF-8" session="true" %> -<%@page import="de.uapcore.lightpit.Constants" %> -<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> - -<h2><fmt:message key="section.modlist.title"/></h2> -<table class="datatable"> - <tr> - <th class="hcenter"><fmt:message key="caption.active" /></th> - <th><fmt:message key="caption.module" /></th> - <th><fmt:message key="caption.path" /></th> - <th><fmt:message key="caption.desc" /></th> - <th><fmt:message key="caption.class" /></th> - <th><fmt:message key="caption.bundle" /></th> - </tr> - <c:forEach items="${modules}" var="module"> - <tr> - <td class="hcenter">${module.visible}</td> - <fmt:bundle basename="${module.annotatedInfos.bundleBaseName}"> - <td class="nowrap"><fmt:message key="${module.annotatedInfos.nameKey}" /></td> - <td>/${module.annotatedInfos.modulePath}</td> - <td><fmt:message key="${module.annotatedInfos.descKey}" /></td> - <td class="smalltext">${module.classname}</td> - <td class="smalltext">${module.annotatedInfos.bundleBaseName}</td> - </fmt:bundle> - </tr> - </c:forEach> -</table> \ No newline at end of file