100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Changed ConsoleAppResource getAppConfig() deprecated; now uses file servlet from '/consoleappconfig/{realm}.json'
Rich Turner2ad29e114209
diff --git a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.javaindex 6063887a0..258873656 100644--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java@@ -20,13 +20,15 @@package org.openremote.manager.apps;import org.openremote.container.web.WebResource;-import org.openremote.model.apps.ConsoleAppConfig;+import org.openremote.model.Constants;import org.openremote.model.apps.ConsoleAppResource;import org.openremote.model.http.RequestParams;import javax.ws.rs.BeanParam;import javax.ws.rs.WebApplicationException;import javax.ws.rs.core.Response;+import java.net.URI;+import java.nio.file.Paths;public class ConsoleAppResourceImpl extends WebResource implements ConsoleAppResource {@@ -49,7 +51,8 @@ public class ConsoleAppResourceImpl extends WebResource implements ConsoleAppRes}@Override- public ConsoleAppConfig getAppConfig(RequestParams requestParams) {- return consoleAppService.getAppConfig(getRequestRealm());+ public Response getAppConfig(RequestParams requestParams) {+ String realm = getRequestRealm() != null ? getRequestRealm() : Constants.MASTER_REALM;+ return Response.seeOther(URI.create("../" + ConsoleAppService.CONSOLE_APP_CONFIG_PATH + "/" + realm + ".json")).build();}}diff --git a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.javaindex 672d1535e..73b05ee8c 100644--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java@@ -19,7 +19,9 @@*/package org.openremote.manager.apps;-import jline.internal.Log;+import io.undertow.server.HttpHandler;+import io.undertow.server.handlers.PathHandler;+import org.openremote.container.web.WebService;import org.openremote.model.Container;import org.openremote.model.ContainerService;import org.openremote.container.persistence.PersistenceService;@@ -35,48 +37,50 @@ import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;-import java.util.HashMap;-import java.util.List;import java.util.Map;-import java.util.logging.Level;import java.util.logging.Logger;import java.util.stream.Stream;import static org.openremote.container.util.MapAccess.getString;+import static org.openremote.container.web.WebService.pathStartsWithHandler;public class ConsoleAppService implements ContainerService {private static final Logger LOG = Logger.getLogger(ConsoleAppService.class.getName());- public static final String CONSOLE_APP_CONFIG_ROOT = "CONSOLE_APP_CONFIG_ROOT";- public static final String CONSOLE_APP_CONFIG_ROOT_DEFAULT = "manager/src/consoleappconfig";+ public static final String CONSOLE_APP_CONFIG_PATH = "/consoleappconfig";+ public static final String CONSOLE_APP_CONFIG_DOCROOT = "CONSOLE_APP_CONFIG_DOCROOT";+ public static final String CONSOLE_APP_CONFIG_DOCROOT_DEFAULT = "manager/src/consoleappconfig";protected TimerService timerService;protected ManagerWebService managerWebService;protected ManagerIdentityService identityService;protected PersistenceService persistenceService;protected Path consoleAppDocRoot;- protected Map<String, ConsoleAppConfig> consoleAppConfigMap;-- @Override- public int getPriority() {- return ContainerService.DEFAULT_PRIORITY;- }@Overridepublic void init(Container container) throws Exception {+ boolean devMode = container.isDevMode();this.timerService = container.getService(TimerService.class);this.managerWebService = container.getService(ManagerWebService.class);this.identityService = container.getService(ManagerIdentityService.class);this.persistenceService = container.getService(PersistenceService.class);- container.getService(ManagerWebService.class).getApiSingletons().add(+ container.getService(ManagerWebService.class).addApiSingleton(new ConsoleAppResourceImpl(this));- consoleAppDocRoot = Paths.get(getString(container.getConfig(), CONSOLE_APP_CONFIG_ROOT, CONSOLE_APP_CONFIG_ROOT_DEFAULT));- consoleAppConfigMap = new HashMap<>();+ consoleAppDocRoot = Paths.get(getString(container.getConfig(), CONSOLE_APP_CONFIG_DOCROOT, CONSOLE_APP_CONFIG_DOCROOT_DEFAULT));++ // Serve console app config files+ HttpHandler customBaseFileHandler = ManagerWebService.createFileHandler(container, consoleAppDocRoot, null);++ HttpHandler pathHandler = new PathHandler().addPrefixPath(CONSOLE_APP_CONFIG_PATH, customBaseFileHandler);+ managerWebService.getRequestHandlers().add(0, pathStartsWithHandler(+ "Console app config files",+ CONSOLE_APP_CONFIG_PATH,+ pathHandler));}@Override@@ -96,25 +100,6 @@ public class ConsoleAppService implements ContainerService {.toArray(String[]::new);}- public ConsoleAppConfig getAppConfig(String realm) {- return consoleAppConfigMap.computeIfAbsent(realm, key -> {- try {- return Files.list(consoleAppDocRoot)- .filter(dir -> dir.getFileName().toString().startsWith(key))- .map(dir -> {- try {- return ValueUtil.JSON.readValue(dir.toFile(), ConsoleAppConfig.class);- } catch (IOException e) {- throw new WebApplicationException(e);- }- })- .findFirst().orElseThrow(NotFoundException::new);- } catch (IOException e) {- throw new WebApplicationException(e);- }- });- }-@Overridepublic String toString() {return getClass().getSimpleName() + "{" +diff --git a/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java b/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.javaindex 7d952b9dd..a53a8e0a9 100644--- a/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java+++ b/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java@@ -25,6 +25,7 @@ import org.openremote.model.http.RequestParams;import javax.annotation.security.RolesAllowed;import javax.ws.rs.*;+import javax.ws.rs.core.Response;import static javax.ws.rs.core.MediaType.APPLICATION_JSON;@@ -41,8 +42,10 @@ public interface ConsoleAppResource {@RolesAllowed({Constants.READ_ADMIN_ROLE})String[] getInstalledApps(@BeanParam RequestParams requestParams);+ // TODO: Remove this once console updated to use file path+ @Deprecated@GET@Path("config")@Produces(APPLICATION_JSON)- ConsoleAppConfig getAppConfig(@BeanParam RequestParams requestParams);+ Response getAppConfig(@BeanParam RequestParams requestParams);}diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex 8159397f9..b36cbbd29 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -914,8 +914,8 @@ export class Manager implements EventProviderFactory {protected async getConsoleAppConfig(): Promise<boolean> {try {- const consoleAppConfigResponse = await this.rest.api.ConsoleAppResource.getAppConfig();- this._consoleAppConfig = consoleAppConfigResponse.data;+ const response = await fetch(manager.config.managerUrl + "/consoleappconfig/" + manager.displayRealm + ".json");+ this._consoleAppConfig = await response.json() as ConsoleAppConfig;return true;} catch (e) {return true;