Skip to content

armgit / core

Public Imported from GitHub
0

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

Added AppConfig as Entity in order to store config about apps

Michael Rademakerf40999633986
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 d5dab4b4e..43c900c41 100644
--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppResourceImpl.java
@@ -20,6 +20,7 @@
package org.openremote.manager.apps;
import org.openremote.container.web.WebResource;
+import org.openremote.model.apps.AppConfig;
import org.openremote.model.apps.ConsoleAppResource;
import org.openremote.model.http.RequestParams;
@@ -46,4 +47,13 @@ public class ConsoleAppResourceImpl extends WebResource implements ConsoleAppRes
throw new RuntimeException(ex);
}
}
+
+ @Override
+ public AppConfig getAppConfig(RequestParams requestParams) {
+ try {
+ return consoleAppService.getAppConfig(getRequestRealm());
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
}
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 8208737f4..91f16b267 100644
--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
@@ -21,9 +21,12 @@ package org.openremote.manager.apps;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
+import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.timer.TimerService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
+import org.openremote.model.apps.AppConfig;
+import org.openremote.model.datapoint.AssetDatapoint;
import java.nio.file.Files;
import java.util.logging.Logger;
@@ -35,6 +38,7 @@ public class ConsoleAppService implements ContainerService {
protected TimerService timerService;
protected ManagerWebService managerWebService;
protected ManagerIdentityService identityService;
+ protected PersistenceService persistenceService;
@Override
public int getPriority() {
@@ -47,6 +51,7 @@ public class ConsoleAppService implements ContainerService {
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(
new ConsoleAppResourceImpl(this)
@@ -68,6 +73,16 @@ public class ConsoleAppService implements ContainerService {
.toArray(String[]::new);
}
+ public AppConfig getAppConfig(String realm) {
+ return persistenceService.doReturningTransaction(entityManager ->
+ entityManager.createQuery(
+ "select ac from AppConfig ac " +
+ "where ac.realm = :realm",
+ AppConfig.class)
+ .setParameter("realm", realm)
+ .getResultList()).stream().findFirst().orElse(null);
+ }
+
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
diff --git a/manager/src/main/resources/META-INF/persistence.xml b/manager/src/main/resources/META-INF/persistence.xml
index 3a06b9a2a..624b7c058 100644
--- a/manager/src/main/resources/META-INF/persistence.xml
+++ b/manager/src/main/resources/META-INF/persistence.xml
@@ -23,6 +23,7 @@
<class>org.openremote.model.rules.AssetRuleset</class>
<class>org.openremote.model.syslog.SyslogEvent</class>
<class>org.openremote.model.gateway.GatewayConnection</class>
+ <class>org.openremote.model.apps.AppConfig</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
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 7ef8d7d14..721b3e321 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
@@ -141,6 +141,19 @@ create table GATEWAY_CONNECTION (
primary key (LOCAL_REALM)
);
+create table APP_CONFIG (
+ ID int8 not null,
+ REALM 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)
+);
+
/*
############################# FUNCTIONS #############################
*/
diff --git a/model/src/main/java/org/openremote/model/apps/AppConfig.java b/model/src/main/java/org/openremote/model/apps/AppConfig.java
new file mode 100644
index 000000000..48819cec5
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/apps/AppConfig.java
@@ -0,0 +1,54 @@
+package org.openremote.model.apps;
+
+import org.openremote.model.value.ObjectValue;
+
+import javax.persistence.*;
+
+import static org.openremote.model.Constants.PERSISTENCE_JSON_OBJECT_TYPE;
+import static org.openremote.model.Constants.PERSISTENCE_SEQUENCE_ID_GENERATOR;
+
+@Entity
+@Table(name = "APP_CONFIG")
+public class AppConfig {
+
+ public enum MenuPosition {
+ BOTTOM_LEFT,
+ BOTTOM_RIGHT,
+ TOP_LEFT,
+ TOP_RIGHT
+ }
+
+ public AppConfig() {
+ }
+
+ @Id
+ @Column(name = "ID")
+ @GeneratedValue(generator = PERSISTENCE_SEQUENCE_ID_GENERATOR)
+ protected Long id;
+
+ @Column(name = "REALM", nullable = false)
+ protected String realm;
+
+ @Column(name = "URL", nullable = false)
+ protected String url;
+
+ @Column(name = "MENU_ENABLED", nullable = false)
+ protected Boolean menuEnabled;
+
+ @Column(name = "MENU_POSITION", nullable = false)
+ @Enumerated(EnumType.STRING)
+ protected MenuPosition menuPosition;
+
+ @Column(name = "MENU_IMAGE", nullable = false)
+ protected String menuImage;
+
+ @Column(name = "PRIMARY_COLOR", nullable = false)
+ protected String primaryColor;
+
+ @Column(name = "SECONDARY_COLOR", nullable = false)
+ protected String secondaryColor;
+
+ @Column(name = "LINKS", columnDefinition = "jsonb")
+ @org.hibernate.annotations.Type(type = PERSISTENCE_JSON_OBJECT_TYPE)
+ protected ObjectValue links;
+}
diff --git a/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java b/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java
index d36c036de..a12f4091a 100644
--- a/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java
+++ b/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java
@@ -25,10 +25,7 @@ import org.openremote.model.http.RequestParams;
import org.openremote.model.http.SuccessStatusCode;
import javax.annotation.security.RolesAllowed;
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
+import javax.ws.rs.*;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@@ -47,4 +44,9 @@ public interface ConsoleAppResource {
@SuppressWarnings("unusable-by-js")
String[] getInstalledApps(@BeanParam RequestParams requestParams);
+ @GET
+ @Path("config")
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ AppConfig getAppConfig(@BeanParam RequestParams requestParams);
}