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
Updated Setup tasks
Rich Turnerba06c156c9a4
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.javaindex 021e9b7f7..44d77fc18 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java@@ -48,7 +48,6 @@ import static org.openremote.container.util.MapAccess.getBoolean;* <li>{@link #SETUP_IMPORT_DEMO_ASSETS} depends on {@link #SETUP_IMPORT_DEMO_USERS}</li>* <li>{@link #SETUP_IMPORT_DEMO_SCENES} depends on {@link #SETUP_IMPORT_DEMO_ASSETS}</li>* <li>{@link #SETUP_IMPORT_DEMO_RULES} depends on {@link #SETUP_IMPORT_DEMO_SCENES}</li>- * <li>{@link #SETUP_IMPORT_KNX_DEMO_ASSETS} depends on {@link #SETUP_IMPORT_DEMO_ASSETS}</li>* </ul>*/public class BuiltinSetupTasks extends AbstractSetupTasks {@@ -58,60 +57,72 @@ public class BuiltinSetupTasks extends AbstractSetupTasks {public static final String SETUP_IMPORT_DEMO_ASSETS = "SETUP_IMPORT_DEMO_ASSETS";public static final String SETUP_IMPORT_DEMO_SCENES = "SETUP_IMPORT_DEMO_SCENES";public static final String SETUP_IMPORT_DEMO_RULES = "SETUP_IMPORT_DEMO_RULES";- public static final String SETUP_IMPORT_KNX_DEMO_ASSETS = "SETUP_IMPORT_KNX_DEMO_ASSETS";+ public static final String SETUP_IMPORT_DEMO_AGENT = "SETUP_IMPORT_DEMO_AGENT";- @Override- public List<Setup> createTasks(Container container) {+ protected boolean isCleanDatabase(Container container) {+ return getBoolean(container.getConfig(), SETUP_INIT_CLEAN_DATABASE, container.isDevMode());+ }- boolean cleanDatabase = getBoolean(container.getConfig(), SETUP_INIT_CLEAN_DATABASE, container.isDevMode());+ // Demo agent to demo protocols.+ protected boolean isImportDemoAgent(Container container) {+ return getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_AGENT, false);+ }- // KNX demo assets to test real physical KNX bus. A KNX IP gateway and knx bus is needed- boolean importKNXDemoAssets = getBoolean(container.getConfig(), SETUP_IMPORT_KNX_DEMO_ASSETS, false);-- // Too many rules are difficult to debug, so they are optional- boolean importDemoRules = getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_RULES, container.isDevMode());+ // Too many rules are difficult to debug, so they are optional+ protected boolean isImportDemoRules(Container container) {+ return getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_RULES, container.isDevMode());+ }- // If importing demo rules we have to import demo scenes- boolean importDemoScenes = importDemoRules || getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_SCENES, container.isDevMode());+ // If importing demo rules we have to import demo scenes+ protected boolean isImportDemoScenes(Container container) {+ return isImportDemoRules(container) || getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_SCENES, container.isDevMode());+ }- // If importing demo rules we have to import demo assets- boolean importDemoAssets = importDemoRules || importKNXDemoAssets || getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_ASSETS, container.isDevMode());+ // If importing demo rules we have to import demo assets+ protected boolean isImportDemoAssets(Container container) {+ return isImportDemoRules(container) || getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_ASSETS, container.isDevMode());+ }++ // If importing demo assets we have to import demo users+ protected boolean isImportDemoUsers(Container container) {+ return isImportDemoAssets(container) || getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_USERS, container.isDevMode());+ }- // If importing demo assets we have to import demo users- boolean importDemoUsers = importDemoAssets || getBoolean(container.getConfig(), SETUP_IMPORT_DEMO_USERS, container.isDevMode());+ @Override+ public List<Setup> createTasks(Container container) {// Basic vs Keycloak identity providerif (container.getService(ManagerIdentityService.class).isKeycloakEnabled()) {- if (cleanDatabase) {+ if (isCleanDatabase(container)) {addTask(new ManagerCleanSetup(container));addTask(new KeycloakCleanSetup(container));addTask(new KeycloakInitSetup(container));addTask(new ManagerInitSetup(container));}- if (importDemoUsers) {+ if (isImportDemoUsers(container)) {addTask(new KeycloakDemoSetup(container));}- if (importDemoAssets) {- addTask(new ManagerDemoSetup(container, importDemoScenes));+ if (isImportDemoAssets(container)) {+ addTask(new ManagerDemoSetup(container, isImportDemoScenes(container)));}- if (importDemoRules) {+ if (isImportDemoRules(container)) {addTask(new RulesDemoSetup(container));}- if (importKNXDemoAssets) {- addTask(new ManagerDemoKNXSetup(container));+ if (isImportDemoAgent(container)) {+ addTask(new ManagerDemoAgentSetup(container));}} else {- if (cleanDatabase) {+ if (isCleanDatabase(container)) {addTask(new ManagerCleanSetup(container));addTask(new ManagerInitSetup(container));addTask(new BasicIdentityInitSetup(container));}- if (importDemoUsers) {+ if (isImportDemoUsers(container)) {addTask(new BasicIdentityDemoSetup(container));}}diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoAgentSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoAgentSetup.javanew file mode 100644index 000000000..dc2484cff--- /dev/null+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoAgentSetup.java@@ -0,0 +1,77 @@+/*+ * Copyright 2016, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.manager.server.setup.builtin;++import org.openremote.agent.protocol.knx.KNXProtocol;+import org.openremote.agent.protocol.velbus.VelbusSerialProtocol;+import org.openremote.container.Container;+import org.openremote.manager.server.asset.ServerAsset;+import org.openremote.manager.server.setup.AbstractManagerSetup;+import org.openremote.manager.shared.security.Tenant;+import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.attribute.MetaItem;+import org.openremote.model.value.Values;++import static org.openremote.model.asset.AssetType.AGENT;+import static org.openremote.model.asset.AssetType.THING;+import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;++public class ManagerDemoAgentSetup extends AbstractManagerSetup {++ public String masterRealmId;++ public ManagerDemoAgentSetup(Container container) {+ super(container);+ }++ @Override+ public void execute() throws Exception {++ KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);+ Tenant masterTenant = keycloakDemoSetup.masterTenant;+ masterRealmId = masterTenant.getId();++ // ########### Assets in 'master' realm ####################+ ServerAsset agent = new ServerAsset("Agent", AGENT);+ agent.setRealmId(masterRealmId);+ agent.setAttributes(+ initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME)+ .addMeta(+ new MetaItem(KNXProtocol.META_KNX_GATEWAY_IP, Values.create("192.168.0.64")),+ new MetaItem(KNXProtocol.META_KNX_LOCAL_IP, Values.create("192.168.0.65"))+ ),+ initProtocolConfiguration(new AssetAttribute("velbusConfig"), VelbusSerialProtocol.PROTOCOL_NAME)+ .addMeta(+ new MetaItem(VelbusSerialProtocol.META_VELBUS_SERIAL_PORT, Values.create("COM3"))+ )+ );+ agent = assetStorageService.merge(agent);++ ServerAsset velbusDevices = new ServerAsset("VELBUS Devices", THING, agent);+ velbusDevices.setRealmId(masterRealmId);+ velbusDevices = assetStorageService.merge(velbusDevices);++ ServerAsset knxDevices = new ServerAsset("KNX Devices", THING, agent);+ knxDevices.setRealmId(masterRealmId);+ knxDevices = assetStorageService.merge(knxDevices);+++ }+}\ No newline at end of filediff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoKNXSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoKNXSetup.javadeleted file mode 100644index 7e8ac678c..000000000--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoKNXSetup.java+++ /dev/null@@ -1,134 +0,0 @@-/*- * Copyright 2016, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.manager.server.setup.builtin;--import static org.openremote.model.asset.AssetMeta.DESCRIPTION;-import static org.openremote.model.asset.AssetMeta.LABEL;-import static org.openremote.model.asset.AssetMeta.READ_ONLY;-import static org.openremote.model.asset.AssetType.AGENT;-import static org.openremote.model.asset.AssetType.BUILDING;-import static org.openremote.model.asset.AssetType.ROOM;-import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;--import org.openremote.agent.protocol.knx.KNXProtocol;-import org.openremote.container.Container;-import org.openremote.manager.server.asset.ServerAsset;-import org.openremote.manager.server.setup.AbstractManagerSetup;-import org.openremote.manager.shared.security.Tenant;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.attribute.AttributeType;-import org.openremote.model.attribute.MetaItem;-import org.openremote.model.value.Values;--public class ManagerDemoKNXSetup extends AbstractManagerSetup {-- public String masterRealmId;-- public ManagerDemoKNXSetup(Container container) {- super(container);- }-- @Override- public void execute() throws Exception {-- KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);- Tenant masterTenant = keycloakDemoSetup.masterTenant;- masterRealmId = masterTenant.getId();-- // ########### KNX assets in 'master' realm ####################- ServerAsset knxOffice = new ServerAsset("KNX Building", BUILDING);- knxOffice.setRealmId(masterTenant.getId());- //knxOffice.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));- knxOffice = assetStorageService.merge(knxOffice);-- ServerAsset knxAgent = new ServerAsset("KNX Agent", AGENT, knxOffice);- knxAgent.setAttributes(- initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(KNXProtocol.META_KNX_GATEWAY_IP, Values.create("192.168.100.10"))- )- );- knxAgent.setRealmId(masterTenant.getId());- knxAgent = assetStorageService.merge(knxAgent);-- ServerAsset knxThing = new ServerAsset("Office", ROOM, knxOffice);- knxThing.setAttributes(- new AssetAttribute("Light1_Switch", AttributeType.BOOLEAN)- .setMeta(- new MetaItem(LABEL, Values.create("Light 1 (Switch)")),- new MetaItem(DESCRIPTION, Values.create("Light 1 connected to a KNX switch actuator")),- new MetaItem(KNXProtocol.META_KNX_ACTION_GA, Values.create("1/0/17")),- new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("0/4/14")),- new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("1.001")),- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())- ),- new AssetAttribute("Light2_Switch", AttributeType.BOOLEAN)- .setMeta(- new MetaItem(LABEL, Values.create("Light 2 (Switch)")),- new MetaItem(DESCRIPTION, Values.create("Light 2 connected to a KNX dimming actuator")),- new MetaItem(KNXProtocol.META_KNX_ACTION_GA, Values.create("1/0/11")),- new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("0/4/10")),- new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("1.001")),- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())- ),- new AssetAttribute("Light2_Dimming", AttributeType.PERCENTAGE)- .setMeta(- new MetaItem(LABEL, Values.create("Light 2 (Dimming)")),- new MetaItem(DESCRIPTION, Values.create("Light 2 connected to a KNX dimming actuator")),- new MetaItem(KNXProtocol.META_KNX_ACTION_GA, Values.create("1/0/13")),- new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("0/4/11")),- new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("5.001")),- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())- ),- new AssetAttribute("Temperature", AttributeType.TEMPERATURE_CELCIUS)- .setMeta(- new MetaItem(LABEL, Values.create("Temperature")),- new MetaItem(DESCRIPTION, Values.create("Temperature given by a KNX sensor")),- new MetaItem(READ_ONLY, Values.create(true)),- new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("4/1/10")),- new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("9.001")),- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())- ),- new AssetAttribute("Presence", AttributeType.BOOLEAN)- .setMeta(- new MetaItem(LABEL, Values.create("Presence")),- new MetaItem(DESCRIPTION, Values.create("KNX presence detector")),- new MetaItem(READ_ONLY, Values.create(true)),- new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("4/0/2")),- new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("1.001")),- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())- ),- new AssetAttribute("WindowStatus", AttributeType.BOOLEAN)- .setMeta(- new MetaItem(LABEL, Values.create("Window status")),- new MetaItem(DESCRIPTION, Values.create("KNX binary input")),- new MetaItem(READ_ONLY, Values.create(true)),- new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("4/0/16")),- new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("1.001")),- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())- )- );--- knxThing = assetStorageService.merge(knxThing);- }-}\ No newline at end of file