Sat, 09 May 2020 14:58:20 +0200
adds module priorities
1.1 --- a/setup/postgres/psql_create_tables.sql Sat May 09 14:37:15 2020 +0200 1.2 +++ b/setup/postgres/psql_create_tables.sql Sat May 09 14:58:20 2020 +0200 1.3 @@ -4,7 +4,8 @@ 1.4 create table lpitcore_module ( 1.5 modid serial primary key, 1.6 classname varchar(100) not null unique, 1.7 - visible boolean not null default(true) 1.8 + visible boolean not null default(true), 1.9 + priority integer not null default(1000) 1.10 ); 1.11 1.12 create table lpitcore_user (
2.1 --- a/src/main/java/de/uapcore/lightpit/LightPITModule.java Sat May 09 14:37:15 2020 +0200 2.2 +++ b/src/main/java/de/uapcore/lightpit/LightPITModule.java Sat May 09 14:58:20 2020 +0200 2.3 @@ -28,12 +28,8 @@ 2.4 */ 2.5 package de.uapcore.lightpit; 2.6 2.7 -import java.lang.annotation.Documented; 2.8 -import java.lang.annotation.ElementType; 2.9 -import java.lang.annotation.Retention; 2.10 -import java.lang.annotation.RetentionPolicy; 2.11 -import java.lang.annotation.Target; 2.12 import javax.servlet.annotation.WebServlet; 2.13 +import java.lang.annotation.*; 2.14 2.15 2.16 /** 2.17 @@ -102,26 +98,34 @@ 2.18 * @return the properties key 2.19 */ 2.20 String titleKey() default "menuLabel"; 2.21 - 2.22 + 2.23 /** 2.24 * If set to <code>true</code>, this module is always loaded, but never 2.25 * visible in the menu or the Web UI module manager. 2.26 - * 2.27 + * 2.28 * @return true, if this is a system module 2.29 */ 2.30 boolean systemModule() default false; 2.31 - 2.32 + 2.33 + /** 2.34 + * Optionally specifies a default priority for this module. 2.35 + * The priority is used to order the menu entries. 2.36 + * 2.37 + * @return an integer priority 2.38 + */ 2.39 + int defaultPriority() default 1000; 2.40 + 2.41 /** 2.42 * Class representing the annotation. 2.43 * This is necessary, because the EL resolver cannot deal with 2.44 * annotation objects. 2.45 - * 2.46 + * <p> 2.47 * Note, that only the properties which are interesting for the JSP pages 2.48 * are proxied by this object. 2.49 */ 2.50 - public static class ELProxy { 2.51 + class ELProxy { 2.52 private final String bundleBaseName, modulePath, menuKey, titleKey, nameKey, descKey; 2.53 - 2.54 + 2.55 public static ELProxy convert(LightPITModule annotation) { 2.56 return new ELProxy( 2.57 annotation.bundleBaseName(),
3.1 --- a/src/main/java/de/uapcore/lightpit/ModuleManager.java Sat May 09 14:37:15 2020 +0200 3.2 +++ b/src/main/java/de/uapcore/lightpit/ModuleManager.java Sat May 09 14:58:20 2020 +0200 3.3 @@ -192,20 +192,18 @@ 3.4 try (Connection conn = db.getDataSource().get().getConnection()) { 3.5 final ModuleDao dao = CoreDAOFactory.getModuleDao(db.getSQLDialect()); 3.6 final List<Module> modules = dao.listAll(conn); 3.7 - 3.8 - final List<Menu> menu = modules 3.9 - .stream() 3.10 - .filter((mod) -> mod.isVisible()) 3.11 - .collect(Collectors.mapping( 3.12 - (mod) -> new Menu( 3.13 - mod.getClassname(), 3.14 - new ResourceKey( 3.15 - registeredModules.get(mod.getClassname()).bundleBaseName(), 3.16 - registeredModules.get(mod.getClassname()).menuKey()), 3.17 - registeredModules.get(mod.getClassname()).modulePath()), 3.18 - Collectors.toList()) 3.19 - ); 3.20 - return menu; 3.21 + 3.22 + return modules 3.23 + .stream() 3.24 + .filter(Module::isVisible) 3.25 + .sorted(new Module.PriorityComparator()) 3.26 + .map(mod -> new Menu( 3.27 + mod.getClassname(), 3.28 + new ResourceKey( 3.29 + registeredModules.get(mod.getClassname()).bundleBaseName(), 3.30 + registeredModules.get(mod.getClassname()).menuKey()), 3.31 + registeredModules.get(mod.getClassname()).modulePath())) 3.32 + .collect(Collectors.toList()); 3.33 } catch (SQLException ex) { 3.34 LOG.error("Unexpected SQLException when loading the main menu", ex); 3.35 return Collections.emptyList();
4.1 --- a/src/main/java/de/uapcore/lightpit/dao/ModuleDao.java Sat May 09 14:37:15 2020 +0200 4.2 +++ b/src/main/java/de/uapcore/lightpit/dao/ModuleDao.java Sat May 09 14:58:20 2020 +0200 4.3 @@ -50,6 +50,7 @@ 4.4 mod.setModID(result.getInt("modid")); 4.5 mod.setClassname(result.getString("classname")); 4.6 mod.setVisible(result.getBoolean("visible")); 4.7 + mod.setPriority(result.getInt("priority")); 4.8 } 4.9 4.10 4.11 @@ -68,21 +69,22 @@ 4.12 protected PreparedStatement moduleCheckStatement(Connection conn) throws SQLException { 4.13 return conn.prepareStatement("SELECT visible FROM lpitcore_module WHERE classname = ?"); 4.14 } 4.15 - 4.16 + 4.17 /** 4.18 * Must return a prepared statement for insertion with the specified properties. 4.19 - * 4.20 + * 4.21 * <ul> 4.22 * <li>Parameter 1: classname</li> 4.23 * <li>Parameter 2: visible</li> 4.24 + * <li>Parameter 3: priority</li> 4.25 * </ul> 4.26 - * 4.27 + * 4.28 * @param conn the connection to use 4.29 * @return the prepared statement 4.30 - * @throws SQLException 4.31 + * @throws SQLException 4.32 */ 4.33 protected PreparedStatement moduleInsertStatement(Connection conn) throws SQLException { 4.34 - return conn.prepareStatement("INSERT INTO lpitcore_module (classname, visible) VALUES (?, ?)"); 4.35 + return conn.prepareStatement("INSERT INTO lpitcore_module (classname, visible, priority) VALUES (?, ?, ?)"); 4.36 } 4.37 4.38 /** 4.39 @@ -110,6 +112,7 @@ 4.40 try (ResultSet r = check.executeQuery()) { 4.41 if (!r.next()) { 4.42 insert.setString(1, modEntry.getKey()); 4.43 + insert.setInt(3, modEntry.getValue().defaultPriority()); 4.44 insert.executeUpdate(); 4.45 } 4.46 }
5.1 --- a/src/main/java/de/uapcore/lightpit/entities/Module.java Sat May 09 14:37:15 2020 +0200 5.2 +++ b/src/main/java/de/uapcore/lightpit/entities/Module.java Sat May 09 14:58:20 2020 +0200 5.3 @@ -24,17 +24,20 @@ 5.4 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5.5 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 5.6 * POSSIBILITY OF SUCH DAMAGE. 5.7 - * 5.8 + * 5.9 */ 5.10 package de.uapcore.lightpit.entities; 5.11 5.12 import de.uapcore.lightpit.LightPITModule; 5.13 5.14 +import java.util.Comparator; 5.15 + 5.16 public final class Module { 5.17 private int modID; 5.18 private String classname; 5.19 private boolean visible; 5.20 - 5.21 + private int priority; 5.22 + 5.23 private LightPITModule.ELProxy annotatedInfos; 5.24 5.25 public int getModID() { 5.26 @@ -61,6 +64,14 @@ 5.27 this.visible = visible; 5.28 } 5.29 5.30 + public int getPriority() { 5.31 + return priority; 5.32 + } 5.33 + 5.34 + public void setPriority(int priority) { 5.35 + this.priority = priority; 5.36 + } 5.37 + 5.38 public LightPITModule.ELProxy getAnnotatedInfos() { 5.39 return annotatedInfos; 5.40 } 5.41 @@ -86,5 +97,18 @@ 5.42 } else { 5.43 return this.modID == ((Module) obj).modID; 5.44 } 5.45 - } 5.46 + } 5.47 + 5.48 + public static final class PriorityComparator implements Comparator<Module> { 5.49 + 5.50 + @Override 5.51 + public int compare(Module left, Module right) { 5.52 + return Integer.compare(left.priority, right.priority); 5.53 + } 5.54 + 5.55 + @Override 5.56 + public boolean equals(Object o) { 5.57 + return o instanceof PriorityComparator; 5.58 + } 5.59 + } 5.60 }
6.1 --- a/src/main/java/de/uapcore/lightpit/modules/HomeModule.java Sat May 09 14:37:15 2020 +0200 6.2 +++ b/src/main/java/de/uapcore/lightpit/modules/HomeModule.java Sat May 09 14:58:20 2020 +0200 6.3 @@ -28,11 +28,8 @@ 6.4 */ 6.5 package de.uapcore.lightpit.modules; 6.6 6.7 -import de.uapcore.lightpit.LightPITModule; 6.8 -import de.uapcore.lightpit.AbstractLightPITServlet; 6.9 -import de.uapcore.lightpit.HttpMethod; 6.10 -import de.uapcore.lightpit.RequestMapping; 6.11 -import de.uapcore.lightpit.ResponseType; 6.12 +import de.uapcore.lightpit.*; 6.13 + 6.14 import javax.servlet.annotation.WebServlet; 6.15 import javax.servlet.http.HttpServletRequest; 6.16 import javax.servlet.http.HttpServletResponse; 6.17 @@ -42,7 +39,8 @@ 6.18 */ 6.19 @LightPITModule( 6.20 bundleBaseName = "localization.home", 6.21 - modulePath = "home" 6.22 + modulePath = "home", 6.23 + defaultPriority = -10000 6.24 ) 6.25 @WebServlet( 6.26 name = "HomeModule",
7.1 --- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Sat May 09 14:37:15 2020 +0200 7.2 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Sat May 09 14:58:20 2020 +0200 7.3 @@ -28,29 +28,21 @@ 7.4 */ 7.5 package de.uapcore.lightpit.modules; 7.6 7.7 -import de.uapcore.lightpit.LightPITModule; 7.8 -import de.uapcore.lightpit.AbstractLightPITServlet; 7.9 -import de.uapcore.lightpit.Constants; 7.10 -import de.uapcore.lightpit.Functions; 7.11 -import de.uapcore.lightpit.HttpMethod; 7.12 +import de.uapcore.lightpit.*; 7.13 +import org.slf4j.Logger; 7.14 +import org.slf4j.LoggerFactory; 7.15 + 7.16 +import javax.servlet.ServletException; 7.17 import javax.servlet.annotation.WebServlet; 7.18 import javax.servlet.http.HttpServletRequest; 7.19 import javax.servlet.http.HttpServletResponse; 7.20 -import de.uapcore.lightpit.RequestMapping; 7.21 -import de.uapcore.lightpit.ResponseType; 7.22 -import java.util.ArrayList; 7.23 -import java.util.IllformedLocaleException; 7.24 -import java.util.List; 7.25 -import java.util.Locale; 7.26 -import java.util.Optional; 7.27 -import javax.servlet.ServletException; 7.28 -import org.slf4j.Logger; 7.29 -import org.slf4j.LoggerFactory; 7.30 +import java.util.*; 7.31 7.32 7.33 @LightPITModule( 7.34 bundleBaseName = "localization.language", 7.35 - modulePath = "language" 7.36 + modulePath = "language", 7.37 + defaultPriority = 20000 7.38 ) 7.39 @WebServlet( 7.40 name = "LanguageModule",
8.1 --- a/src/main/java/de/uapcore/lightpit/modules/ModuleManagerModule.java Sat May 09 14:37:15 2020 +0200 8.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ModuleManagerModule.java Sat May 09 14:58:20 2020 +0200 8.3 @@ -51,7 +51,8 @@ 8.4 */ 8.5 @LightPITModule( 8.6 bundleBaseName = "localization.modmgmt", 8.7 - modulePath = "modmgmt" 8.8 + modulePath = "modmgmt", 8.9 + defaultPriority = 21000 8.10 ) 8.11 @WebServlet( 8.12 name = "ModuleManagerModule",