Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

ConsoleAppConfig is not persisted anymore

Michael Rademaker1e7a46b2310d
diff --git a/manager/src/consoleappconfig/master.json b/manager/src/consoleappconfig/master.json
new file mode 100644
index 000000000..ab1bf582d
--- /dev/null
+++ b/manager/src/consoleappconfig/master.json
@@ -0,0 +1,11 @@
+{
+ "realm": "master",
+ "initialUrl": "/console_loader/?realm=master&consoleProviders=geofence push storage",
+ "url": "/manager/?realm=master&consoleProviders=geofence push storage",
+ "menuEnabled": false,
+ "menuPosition": "BOTTOM_RIGHT",
+ "menuImage": null,
+ "primaryColor": "#4D9D2A",
+ "secondaryColor": "#CFCFCF",
+ "links": null
+}
\ No newline at end of file
diff --git a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java
index b2b8d8bf2..6063887a0 100644
--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java
@@ -50,10 +50,6 @@ public class ConsoleAppResourceImpl extends WebResource implements ConsoleAppRes
@Override
public ConsoleAppConfig getAppConfig(RequestParams requestParams) {
- try {
- return consoleAppService.getAppConfig(getRequestRealm());
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
+ return consoleAppService.getAppConfig(getRequestRealm());
}
}
diff --git a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
index d77a37943..672d1535e 100644
--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
@@ -19,6 +19,7 @@
*/
package org.openremote.manager.apps;
+import jline.internal.Log;
import org.openremote.model.Container;
import org.openremote.model.ContainerService;
import org.openremote.container.persistence.PersistenceService;
@@ -26,20 +27,36 @@ import org.openremote.container.timer.TimerService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.apps.ConsoleAppConfig;
+import org.openremote.model.util.ValueUtil;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.WebApplicationException;
+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;
+
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";
+
protected TimerService timerService;
protected ManagerWebService managerWebService;
protected ManagerIdentityService identityService;
protected PersistenceService persistenceService;
+ protected Path consoleAppDocRoot;
+ protected Map<String, ConsoleAppConfig> consoleAppConfigMap;
@Override
public int getPriority() {
@@ -57,6 +74,9 @@ public class ConsoleAppService implements ContainerService {
container.getService(ManagerWebService.class).getApiSingletons().add(
new ConsoleAppResourceImpl(this)
);
+
+ consoleAppDocRoot = Paths.get(getString(container.getConfig(), CONSOLE_APP_CONFIG_ROOT, CONSOLE_APP_CONFIG_ROOT_DEFAULT));
+ consoleAppConfigMap = new HashMap<>();
}
@Override
@@ -77,18 +97,28 @@ public class ConsoleAppService implements ContainerService {
}
public ConsoleAppConfig getAppConfig(String realm) {
- return persistenceService.doReturningTransaction(entityManager ->
- entityManager.createQuery(
- "select ac from ConsoleAppConfig ac " +
- "where ac.realm = :realm",
- ConsoleAppConfig.class)
- .setParameter("realm", realm)
- .getResultList()).stream().findFirst().orElse(null);
+ 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);
+ }
+ });
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
+ "consoleAppDocRoot=" + consoleAppDocRoot +
'}';
}
}
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql
index d668cc703..0c1048113 100644
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql
+++ b/manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql
@@ -135,20 +135,6 @@ create table GATEWAY_CONNECTION (
primary key (LOCAL_REALM)
);
-create table CONSOLE_APP_CONFIG (
- ID int8 not null,
- REALM varchar(255) not null,
- INITIAL_URL varchar(255) not null,
- URL varchar(255) not null,
- MENU_ENABLED varchar(255) not null default false,
- MENU_POSITION varchar(255) not null default 'BOTTOM_LEFT',
- MENU_IMAGE varchar(255) null,
- PRIMARY_COLOR varchar(255) not null default '#43A047',
- SECONDARY_COLOR varchar(255) not null default '#C1D72E',
- LINKS jsonb null,
- primary key (ID)
-);
-
create table PROVISIONING_CONFIG (
ID int8 not null,
CREATED_ON timestamp with time zone not null,
diff --git a/model/src/main/java/org/openremote/model/apps/ConsoleAppConfig.java b/model/src/main/java/org/openremote/model/apps/ConsoleAppConfig.java
index e4c356e8a..ba38bd2d4 100644
--- a/model/src/main/java/org/openremote/model/apps/ConsoleAppConfig.java
+++ b/model/src/main/java/org/openremote/model/apps/ConsoleAppConfig.java
@@ -1,13 +1,9 @@
package org.openremote.model.apps;
-import javax.persistence.*;
-import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonProperty;
-import static org.openremote.model.Constants.PERSISTENCE_JSON_VALUE_TYPE;
-import static org.openremote.model.Constants.PERSISTENCE_SEQUENCE_ID_GENERATOR;
+import java.io.Serializable;
-@Entity
-@Table(name = "CONSOLE_APP_CONFIG")
public class ConsoleAppConfig {
public static class AppLink implements Serializable {
@@ -40,50 +36,42 @@ public class ConsoleAppConfig {
public ConsoleAppConfig() {
}
- public ConsoleAppConfig(String realm, String initialUrl, String url, Boolean menuEnabled, MenuPosition menuPosition, String menuImage, String primaryColor, String secondaryColor, AppLink[] links) {
+ public ConsoleAppConfig(String realm, String initialUrl, String url, Boolean menuEnabled, MenuPosition menuPosition, String primaryColor, String secondaryColor, AppLink[] links) {
this.realm = realm;
this.initialUrl = initialUrl;
this.url = url;
this.menuEnabled = menuEnabled;
this.menuPosition = menuPosition;
- this.menuImage = menuImage;
this.primaryColor = primaryColor;
this.secondaryColor = secondaryColor;
this.links = links;
}
- @Id
- @Column(name = "ID")
- @GeneratedValue(generator = PERSISTENCE_SEQUENCE_ID_GENERATOR)
+ @JsonProperty
protected Long id;
- @Column(name = "REALM", nullable = false)
+ @JsonProperty
protected String realm;
- @Column(name = "INITIAL_URL", nullable = false)
+ @JsonProperty
protected String initialUrl;
- @Column(name = "URL", nullable = false)
+ @JsonProperty
protected String url;
- @Column(name = "MENU_ENABLED", nullable = false)
+ @JsonProperty
protected Boolean menuEnabled;
- @Column(name = "MENU_POSITION", nullable = false)
- @Enumerated(EnumType.STRING)
+ @JsonProperty
protected MenuPosition menuPosition;
- @Column(name = "MENU_IMAGE", nullable = false)
- protected String menuImage;
-
- @Column(name = "PRIMARY_COLOR", nullable = false)
+ @JsonProperty
protected String primaryColor;
- @Column(name = "SECONDARY_COLOR", nullable = false)
+ @JsonProperty
protected String secondaryColor;
- @Column(name = "LINKS", columnDefinition = "jsonb")
- @org.hibernate.annotations.Type(type = PERSISTENCE_JSON_VALUE_TYPE)
+ @JsonProperty
protected AppLink[] links;
public String getRealm() {
diff --git a/project.gradle b/project.gradle
index 5142a7421..a1fb9fadf 100644
--- a/project.gradle
+++ b/project.gradle
@@ -76,7 +76,8 @@ if (project == rootProject) {
envs = [
MAP_SETTINGS_PATH: "../deployment/map/mapsettings.json",
MAP_TILES_PATH: "../deployment/map/mapdata.mbtiles",
- CUSTOM_APP_DOCROOT: "../deployment/manager/app"
+ CUSTOM_APP_DOCROOT: "../deployment/manager/app",
+ CONSOLE_APP_CONFIG_ROOT: "../deployment/manager/consoleappconfig"
]
}
}