Sat, 09 May 2020 14:58:20 +0200
adds module priorities
6 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
24 | 4 | * Copyright 2018 Mike Becker. All rights reserved. |
6 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | * | |
28 | */ | |
29 | package de.uapcore.lightpit; | |
30 | ||
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
31 | import de.uapcore.lightpit.dao.CoreDAOFactory; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
32 | import de.uapcore.lightpit.dao.ModuleDao; |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
33 | import de.uapcore.lightpit.entities.Module; |
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
34 | import org.slf4j.Logger; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
35 | import org.slf4j.LoggerFactory; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
36 | |
7
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
37 | import javax.servlet.Registration; |
6 | 38 | import javax.servlet.ServletContext; |
39 | import javax.servlet.ServletContextEvent; | |
40 | import javax.servlet.ServletContextListener; | |
41 | import javax.servlet.annotation.WebListener; | |
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
42 | import java.sql.Connection; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
43 | import java.sql.SQLException; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
44 | import java.util.*; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
45 | import java.util.concurrent.atomic.AtomicBoolean; |
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
46 | import java.util.stream.Collectors; |
6 | 47 | |
48 | /** | |
49 | * Scans registered servlets for LightPIT modules. | |
50 | */ | |
51 | @WebListener | |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
52 | public final class ModuleManager implements ServletContextListener { |
6 | 53 | |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
54 | private static final Logger LOG = LoggerFactory.getLogger(ModuleManager.class); |
6 | 55 | |
56 | /** | |
57 | * The attribute name in the servlet context under which an instance of this class can be found. | |
58 | */ | |
59 | public static final String SC_ATTR_NAME = ModuleManager.class.getName(); | |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
60 | private ServletContext sc; |
6 | 61 | |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
62 | /** |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
63 | * Maps class names to module information. |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
64 | */ |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
65 | private final Map<String, LightPITModule> registeredModules = new HashMap<>(); |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
66 | |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
67 | /** |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
68 | * This flag is true, when synchronization is needed. |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
69 | */ |
21
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
70 | private final AtomicBoolean dirty = new AtomicBoolean(true); |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
71 | |
6 | 72 | @Override |
73 | public void contextInitialized(ServletContextEvent sce) { | |
74 | sc = sce.getServletContext(); | |
75 | reloadAll(); | |
76 | sc.setAttribute(SC_ATTR_NAME, this); | |
77 | LOG.info("Module manager injected into ServletContext."); | |
78 | } | |
79 | ||
80 | @Override | |
81 | public void contextDestroyed(ServletContextEvent sce) { | |
82 | unloadAll(); | |
83 | } | |
84 | ||
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
85 | private Optional<LightPITModule> getModuleInfo(Registration reg) { |
6 | 86 | try { |
7
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
87 | final Class scclass = Class.forName(reg.getClassName()); |
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
88 | |
9
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
89 | final boolean lpservlet = AbstractLightPITServlet.class.isAssignableFrom(scclass); |
7
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
90 | final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class); |
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
91 | |
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
92 | if (lpservlet && !lpmodule) { |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
93 | LOG.warn( |
9
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
94 | "{} is a LightPIT Servlet but is missing the module annotation.", |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
95 | reg.getClassName() |
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
96 | ); |
7
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
97 | } else if (!lpservlet && lpmodule) { |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
98 | LOG.warn( |
9
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
99 | "{} is annotated as a LightPIT Module but does not extend {}.", |
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
100 | reg.getClassName(), |
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
101 | AbstractLightPITServlet.class.getSimpleName() |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
102 | ); |
7
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
103 | } |
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
104 | |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
105 | if (lpservlet && lpmodule) { |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
106 | final Class<? extends AbstractLightPITServlet> clazz = scclass; |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
107 | final LightPITModule moduleInfo = clazz.getAnnotation(LightPITModule.class); |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
108 | return Optional.of(moduleInfo); |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
109 | } else { |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
110 | return Optional.empty(); |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
111 | } |
6 | 112 | } catch (ClassNotFoundException ex) { |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
113 | LOG.error( |
9
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
114 | "Servlet registration refers to class {} which cannot be found by the class loader (Reason: {})", |
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
115 | reg.getClassName(), |
20a9b2bc9063
makes LightPITServlet abstract
Mike Becker <universe@uap-core.de>
parents:
8
diff
changeset
|
116 | ex.getMessage() |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
117 | ); |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
118 | return Optional.empty(); |
6 | 119 | } |
120 | } | |
121 | ||
7
598670d5b0b8
core functionality should also use the modules system, changed the code structure accordingly
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
122 | private void handleServletRegistration(String name, Registration reg) { |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
123 | final Optional<LightPITModule> moduleInfo = getModuleInfo(reg); |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
124 | if (moduleInfo.isPresent()) { |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
125 | registeredModules.put(reg.getClassName(), moduleInfo.get()); |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
126 | LOG.info("Module detected: {}", name); |
6 | 127 | } else { |
8
2dfdb79b5344
adds slf4j to project as netbeans library (make sure to have it configured in your environment)
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
128 | LOG.debug("Servlet {} is no module, skipping.", name); |
6 | 129 | } |
130 | } | |
131 | ||
132 | /** | |
133 | * Scans for modules and reloads them all. | |
134 | */ | |
135 | public void reloadAll() { | |
21
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
136 | registeredModules.clear(); |
6 | 137 | sc.getServletRegistrations().forEach(this::handleServletRegistration); |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
138 | |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
139 | // TODO: implement dependency resolver |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
140 | |
21
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
141 | dirty.set(true); |
6 | 142 | LOG.info("Modules loaded."); |
143 | } | |
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
144 | |
6 | 145 | /** |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
146 | * Synchronizes module information with the database. |
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
147 | * <p> |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
148 | * This must be called from the {@link AbstractLightPITServlet}. |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
149 | * Admittedly the call will perform the synchronization once after reload |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
150 | * and be a no-op, afterwards. |
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
151 | * However, since the DatabaseFacade might be loaded after the module |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
152 | * manager, we must defer the synchronization to the first request |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
153 | * handled by the Servlet. |
30
fb30f7b78f9b
moves DAO classes to different package
Mike Becker <universe@uap-core.de>
parents:
29
diff
changeset
|
154 | * |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
155 | * @param db interface to the database |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
156 | */ |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
157 | public void syncWithDatabase(DatabaseFacade db) { |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
158 | if (dirty.compareAndSet(true, false)) { |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
159 | if (db.getDataSource().isPresent()) { |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
160 | try (Connection conn = db.getDataSource().get().getConnection()) { |
21
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
161 | final ModuleDao moduleDao = CoreDAOFactory.getModuleDao(db.getSQLDialect()); |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
162 | moduleDao.syncRegisteredModuleClasses(conn, registeredModules.entrySet()); |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
163 | } catch (SQLException ex) { |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
164 | LOG.error("Unexpected SQL Exception", ex); |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
165 | } |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
166 | } else { |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
167 | LOG.error("No datasource present. Cannot sync module information with database."); |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
168 | } |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
169 | } else { |
22
5a91fb7067af
minor changes to logging output
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
170 | LOG.trace("Module information clean - no synchronization required."); |
20
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
171 | } |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
172 | } |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
173 | |
bd1a76c91d5b
module synchronization with database
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
174 | /** |
6 | 175 | * Unloads all found modules. |
176 | */ | |
177 | public void unloadAll() { | |
21
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
178 | registeredModules.clear(); |
6 | 179 | LOG.info("All modules unloaded."); |
180 | } | |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
181 | |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
182 | /** |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
183 | * Returns the main menu. |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
184 | * |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
185 | * @param db the interface to the database |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
186 | * @return a list of menus belonging to the main menu |
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
187 | */ |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
188 | public List<Menu> getMainMenu(DatabaseFacade db) { |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
189 | // TODO: user specific menu |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
190 | |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
191 | if (db.getDataSource().isPresent()) { |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
192 | try (Connection conn = db.getDataSource().get().getConnection()) { |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
193 | final ModuleDao dao = CoreDAOFactory.getModuleDao(db.getSQLDialect()); |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
194 | final List<Module> modules = dao.listAll(conn); |
31 | 195 | |
196 | return modules | |
197 | .stream() | |
198 | .filter(Module::isVisible) | |
199 | .sorted(new Module.PriorityComparator()) | |
200 | .map(mod -> new Menu( | |
201 | mod.getClassname(), | |
202 | new ResourceKey( | |
203 | registeredModules.get(mod.getClassname()).bundleBaseName(), | |
204 | registeredModules.get(mod.getClassname()).menuKey()), | |
205 | registeredModules.get(mod.getClassname()).modulePath())) | |
206 | .collect(Collectors.toList()); | |
27
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
207 | } catch (SQLException ex) { |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
208 | LOG.error("Unexpected SQLException when loading the main menu", ex); |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
209 | return Collections.emptyList(); |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
210 | } |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
211 | } else { |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
212 | return Collections.emptyList(); |
1f2a96efa69f
removes caching of main menu
Mike Becker <universe@uap-core.de>
parents:
24
diff
changeset
|
213 | } |
10
89e3e6e28b69
implements automatic menu generation from module information
Mike Becker <universe@uap-core.de>
parents:
9
diff
changeset
|
214 | } |
21
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
215 | |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
216 | /** |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
217 | * Returns an unmodifiable map of all registered modules. |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
218 | * |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
219 | * The key is the classname of the module. |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
220 | * |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
221 | * @return the map of registered modules |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
222 | */ |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
223 | public Map<String, LightPITModule> getRegisteredModules() { |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
224 | return Collections.unmodifiableMap(registeredModules); |
b213fef2539e
adds first part of a module manager UI
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
225 | } |
6 | 226 | } |