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
Minor geofence and attribute from AttributeDescriptor changes
Rich Turner03c36a9ed978
diff --git a/manager/src/main/java/org/openremote/manager/rules/AssetLocationPredicateConsumer.java b/manager/src/main/java/org/openremote/manager/rules/AssetLocationPredicateConsumer.javanew file mode 100644index 000000000..8fba2440a--- /dev/null+++ b/manager/src/main/java/org/openremote/manager/rules/AssetLocationPredicateConsumer.java@@ -0,0 +1,32 @@+/*+ * Copyright 2017, 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.rules;++import java.util.List;++@FunctionalInterface+public interface AssetLocationPredicateConsumer {++ /**+ * Called when one or more asset's location predicate rules change; the initialising flag indicates if the+ */+ void accept(RulesEngine t, List<RulesEngine.AssetStateLocationPredicates> u);+}+diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.javaindex 66040c5ce..b6c769ed4 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java@@ -38,7 +38,6 @@ import org.openremote.model.rules.*;import java.util.*;import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;-import java.util.function.BiConsumer;import java.util.logging.Level;import java.util.logging.Logger;@@ -85,7 +84,7 @@ public class RulesEngine<T extends Ruleset> {final protected Assets assetsFacade;final protected Users usersFacade;final protected ConsolesFacade consolesFacade;- final protected BiConsumer<RulesEngine, List<AssetStateLocationPredicates>> assetLocationPredicatesConsumer;+ final protected AssetLocationPredicateConsumer assetLocationPredicatesConsumer;final protected Map<Long, RulesetDeployment> deployments = new LinkedHashMap<>();final protected RulesFacts facts;@@ -109,8 +108,7 @@ public class RulesEngine<T extends Ruleset> {AssetProcessingService assetProcessingService,NotificationService notificationService,RulesEngineId<T> id,- // Change to a class- BiConsumer<RulesEngine, List<AssetStateLocationPredicates>> assetLocationPredicatesConsumer) {+ AssetLocationPredicateConsumer assetLocationPredicatesConsumer) {this.timerService = timerService;this.executorService = executorService;this.assetStorageService = assetStorageService;diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.javaindex ac41f3c21..1980837a3 100644--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java@@ -113,7 +113,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {smartOffice.setName("Smart Office");smartOffice.setType(BUILDING);List<AssetAttribute> smartOfficeAttributes = Arrays.asList(- AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValue),+ new AssetAttribute(AttributeType.LOCATION, locationValue),new AssetAttribute("geoStreet", STRING, Values.create("Torenallee 20")).setMeta(new MetaItem(LABEL, Values.create("Street")),@@ -141,12 +141,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {smartOfficeId = smartOffice.getId();Asset groundFloor = new Asset("Ground Floor", FLOOR, smartOffice)- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValue));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValue));groundFloor = assetStorageService.merge(groundFloor);groundFloorId = groundFloor.getId();Asset lobby = new Asset("Lobby", ROOM, groundFloor)- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValue));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValue));lobby.addAttributes(new AssetAttribute("lobbyLocations", AttributeValueType.ARRAY));@@ -156,7 +156,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Asset agent = new Asset("Demo Agent", AGENT, lobby);agent.addAttributes(- AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValue),+ new AssetAttribute(AttributeType.LOCATION, locationValue),initProtocolConfiguration(new AssetAttribute(agentProtocolConfigName), SimulatorProtocol.PROTOCOL_NAME).addMeta(new MetaItem(@@ -173,7 +173,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {agentId = agent.getId();Asset thing = new Asset("Demo Thing", THING, agent)- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValue)+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValue).setMeta(new MetaItem(RULE_STATE, Values.create(true))));thing.addAttributes(new AssetAttribute(thingLightToggleAttributeName, BOOLEAN, Values.create(true))@@ -375,7 +375,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {smartHome.setName("Smart Home");smartHome.setType(BUILDING);smartHome.addAttributes(- AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA),+ new AssetAttribute(AttributeType.LOCATION, locationValueA),new AssetAttribute("geoStreet", STRING, Values.create("Wilhelminaplein 21C")).setMeta(new MetaItem(LABEL, Values.create("Street")),@@ -402,7 +402,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {// The "Apartment 1" is the demo apartment with complex scenesAsset apartment1 = createDemoApartment(smartHome, "Apartment 1")- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));apartment1 = assetStorageService.merge(apartment1);apartment1Id = apartment1.getId();@@ -421,7 +421,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {/* ############################ ROOMS ############################## */Asset apartment1Livingroom = createDemoApartmentRoom(apartment1, "Living Room")- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));addDemoApartmentRoomMotionSensor(apartment1Livingroom, true, () -> new MetaItem[]{new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()),new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME))@@ -447,7 +447,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment1LivingroomId = apartment1Livingroom.getId();Asset apartment1Kitchen = createDemoApartmentRoom(apartment1, "Kitchen")- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));addDemoApartmentRoomMotionSensor(apartment1Kitchen, true, () -> new MetaItem[]{new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()),new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME))@@ -489,7 +489,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment1KitchenId = apartment1Kitchen.getId();Asset apartment1Hallway = createDemoApartmentRoom(apartment1, "Hallway")- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));addDemoApartmentRoomMotionSensor(apartment1Hallway, true, () -> new MetaItem[]{new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()),new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME))@@ -515,7 +515,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Asset demoApartmentSceneAgent = createDemoApartmentSceneAgent(apartment1, scenes, apartment1Livingroom, apartment1Kitchen, apartment1Hallway- ).addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ ).addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));demoApartmentSceneAgent = assetStorageService.merge(demoApartmentSceneAgent);@@ -525,7 +525,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Asset apartment2 = new Asset("Apartment 2", RESIDENCE, smartHome);apartment2.addAttributes(- AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA),+ new AssetAttribute(AttributeType.LOCATION, locationValueA),new AssetAttribute("allLightsOffSwitch", AttributeValueType.BOOLEAN, Values.create(true)).setMeta(new MetaItem(LABEL, Values.create("All Lights Off Switch")),@@ -539,7 +539,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Asset apartment2Livingroom = new Asset("Living Room", ROOM, apartment2);apartment2Livingroom.addAttributes(- AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA),+ new AssetAttribute(AttributeType.LOCATION, locationValueA),new AssetAttribute("motionSensor", AttributeValueType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Motion Sensor")),@@ -585,7 +585,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Asset apartment2Bathroom = new Asset("Bathroom", ROOM, apartment2);apartment2Bathroom.addAttributes(- AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA),+ new AssetAttribute(AttributeType.LOCATION, locationValueA),new AssetAttribute("motionSensor", AttributeValueType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Motion Sensor")),@@ -621,12 +621,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment2BathroomId = apartment2Bathroom.getId();Asset apartment3 = new Asset("Apartment 3", RESIDENCE, smartHome)- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));apartment3 = assetStorageService.merge(apartment3);apartment3Id = apartment3.getId();Asset apartment3Livingroom = new Asset("Living Room", ROOM, apartment3)- .addAttributes(AssetAttribute.createWithDescriptor(AttributeType.LOCATION, locationValueA));+ .addAttributes(new AssetAttribute(AttributeType.LOCATION, locationValueA));apartment3Livingroom.addAttributes(new AssetAttribute("lightSwitch", AttributeValueType.BOOLEAN));diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AssetAttribute.javaindex 62afbbf1f..a59770b55 100644--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java@@ -62,6 +62,16 @@ public class AssetAttribute extends Attribute {addMeta(attributeDescriptor.getDefaultMetaItems());}+ public AssetAttribute(AttributeDescriptor attributeDescriptor, Value value) {+ super(attributeDescriptor.getName(), attributeDescriptor.getValueType());+ if (value != null) {+ if (value.getType() != attributeDescriptor.getValueType().getValueType()) {+ throw new IllegalArgumentException("Provided value type is not compatible with this attribute type");+ }+ }+ addMeta(attributeDescriptor.getDefaultMetaItems());+ }+public AssetAttribute(String name, AttributeValueType type, Value value, long timestamp) {super(name, type, value, timestamp);}@@ -495,13 +505,4 @@ public class AssetAttribute extends Attribute {}return Optional.of(objectValue);}-- public static AssetAttribute createWithDescriptor(AttributeDescriptor descriptor) {- return createWithDescriptor(descriptor, null);- }-- public static AssetAttribute createWithDescriptor(AttributeDescriptor descriptor, Value value) {- return new AssetAttribute(descriptor.getName(), descriptor.getValueType(), Optional.ofNullable(value).orElse(descriptor.getDefaultValue()))- .setMeta(descriptor.getDefaultMetaItems());- }}diff --git a/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java b/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.javaindex fc5c2ef94..a26004057 100644--- a/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java+++ b/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java@@ -165,7 +165,7 @@ public final class ConsoleConfiguration {public static Asset setConsoleName(Asset asset, String name) {Objects.requireNonNull(asset);TextUtil.requireNonNullAndNonEmpty(name);- asset.replaceAttribute(AssetAttribute.createWithDescriptor(AttributeType.CONSOLE_NAME,+ asset.replaceAttribute(new AssetAttribute(AttributeType.CONSOLE_NAME,Values.create(name)));return asset;}@@ -177,7 +177,7 @@ public final class ConsoleConfiguration {public static Asset setConsoleVersion(Asset asset, String version) {Objects.requireNonNull(asset);TextUtil.requireNonNullAndNonEmpty(version);- asset.replaceAttribute(AssetAttribute.createWithDescriptor(AttributeType.CONSOLE_VERSION,+ asset.replaceAttribute(new AssetAttribute(AttributeType.CONSOLE_VERSION,Values.create(version)));return asset;}@@ -189,7 +189,7 @@ public final class ConsoleConfiguration {public static Asset setConsolePlatform(Asset asset, String platform) {Objects.requireNonNull(asset);TextUtil.requireNonNullAndNonEmpty(platform);- asset.replaceAttribute(AssetAttribute.createWithDescriptor(AttributeType.CONSOLE_PLATFORM,+ asset.replaceAttribute(new AssetAttribute(AttributeType.CONSOLE_PLATFORM,Values.create(platform)));return asset;}@@ -213,7 +213,7 @@ public final class ConsoleConfiguration {return asset;}- asset.replaceAttribute(AssetAttribute.createWithDescriptor(AttributeType.CONSOLE_PROVIDERS,+ asset.replaceAttribute(new AssetAttribute(AttributeType.CONSOLE_PROVIDERS,ConsoleProvider.toValue(consoleProviderMap)));return asset;}@@ -222,7 +222,7 @@ public final class ConsoleConfiguration {Objects.requireNonNull(asset);TextUtil.requireNonNullAndNonEmpty(name);AssetAttribute providerAttribute = asset.getAttribute(AttributeType.CONSOLE_PROVIDERS).orElseGet(() -> {- AssetAttribute attr = AssetAttribute.createWithDescriptor(AttributeType.CONSOLE_PROVIDERS, Values.createObject());+ AssetAttribute attr = new AssetAttribute(AttributeType.CONSOLE_PROVIDERS, Values.createObject());asset.addAttributes(attr);return attr;});diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovyindex 114506aea..61aa35e60 100644--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy@@ -99,7 +99,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.size() == 6assets.get(0).id == managerDemoSetup.apartment1Idassets.get(1).id == managerDemoSetup.apartment1LivingroomId- assets.get(1).getAttributesList().size() == 8+ assets.get(1).getAttributesList().size() == 9assets.get(1).getAttribute("motionSensor").isPresent()!assets.get(1).getAttribute("currentTemperature").get().getValue().isPresent()assets.get(1).getAttribute("currentTemperature").get().meta.size() == 1diff --git a/test/src/test/groovy/org/openremote/test/console/ConsoleAssetTest.groovy b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovysimilarity index 51%rename from test/src/test/groovy/org/openremote/test/console/ConsoleAssetTest.groovyrename to test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovyindex 7123a540d..a3cea61e1 100644--- a/test/src/test/groovy/org/openremote/test/console/ConsoleAssetTest.groovy+++ b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy@@ -1,33 +1,232 @@package org.openremote.test.console+import org.junit.Ignoreimport org.openremote.container.util.UniqueIdentifierGeneratorimport org.openremote.manager.asset.AssetStorageServiceimport org.openremote.manager.asset.console.ConsoleResourceImpl+import org.openremote.manager.rules.RulesEngine+import org.openremote.manager.rules.RulesService+import org.openremote.manager.rules.RulesetStorageServiceimport org.openremote.manager.rules.geofence.ORConsoleGeofenceAssetAdapterimport org.openremote.manager.setup.SetupServiceimport org.openremote.manager.setup.builtin.KeycloakDemoSetupimport org.openremote.manager.setup.builtin.ManagerDemoSetupimport org.openremote.model.asset.Asset+import org.openremote.model.asset.AssetAttribute+import org.openremote.model.asset.AssetMetaimport org.openremote.model.attribute.AttributeType+import org.openremote.model.attribute.MetaItemimport org.openremote.model.console.ConsoleConfigurationimport org.openremote.model.console.ConsoleProviderimport org.openremote.model.console.ConsoleResource+import org.openremote.model.rules.AssetRuleset+import org.openremote.model.rules.GlobalRuleset+import org.openremote.model.rules.Rulesetimport org.openremote.model.util.TextUtilimport org.openremote.model.value.ObjectValueimport org.openremote.model.value.Valuesimport org.openremote.test.ManagerContainerTrait+import org.openremote.test.rules.BasicRulesImportimport spock.lang.Specification+import spock.util.concurrent.PollingConditionsimport javax.ws.rs.WebApplicationException+import static org.openremote.manager.rules.RulesetDeployment.Status.DEPLOYED+import static org.openremote.manager.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_2+import static org.openremote.manager.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_3+import static org.openremote.manager.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_CUSTOMER_A+import static org.openremote.manager.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_GLOBAL+import static org.openremote.manager.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_SMART_OFFICEimport static org.openremote.model.Constants.KEYCLOAK_CLIENT_IDimport static org.openremote.model.Constants.MASTER_REALM+import static org.openremote.model.asset.AssetMeta.RULE_STATEimport static org.openremote.model.asset.AssetType.CONSOLEimport static org.openremote.model.value.Values.parse-class ConsoleAssetTest extends Specification implements ManagerContainerTrait {+class ConsoleTest extends Specification implements ManagerContainerTrait {- def "Console registration"() {+ @Ignore+ def "Check basic geofence provider functionality"() {+ given: "expected conditions"+ def conditions = new PollingConditions(timeout: 10, initialDelay: 0.5, delay: 0.5)++ and: "the container is started"+ def serverPort = findEphemeralPort()+ RulesService.GEOFENCE_INIT_DEBOUNCE_MILLIS = 500+ def container = startContainer(defaultConfig(serverPort), defaultServices())+ def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)+ def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)+ def rulesService = container.getService(RulesService.class)+ def rulesetStorageService = container.getService(RulesetStorageService.class)+ def assetStorageService = container.getService(AssetStorageService.class)+ def geofenceAdapter = (ORConsoleGeofenceAssetAdapter) rulesService.geofenceAssetAdapters.find {it.name == "ORConsole" }++ and: "some test rulesets have been imported"+ def rulesImport = new BasicRulesImport(rulesetStorageService, keycloakDemoSetup, managerDemoSetup)++ expect: "the rules engines to be ready"+ conditions.eventually {+ rulesImport.assertEnginesReady(rulesService, keycloakDemoSetup, managerDemoSetup)+ }++ and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"+ conditions.eventually {+ assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL+ assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL+ assert rulesImport.masterEngine.assetStates.size() == DEMO_RULE_STATES_SMART_OFFICE+ assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2+ assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3+ }++ and: "the geofence adapter should have been initialised with the demo consoles location predicate"+ conditions.eventually {+ def geofences = rulesService.getAssetGeofences(managerDemoSetup.consoleId)+ assert geofences.size() == 1+ assert geofences[0].radius == 100+ assert geofences[0].lat == 50+ assert geofences[0].lng == 100+ assert geofences[0].id == managerDemoSetup.consoleId + "_-174661203"+ assert geofences[0].url == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"+ }++ when: "another console asset is added with its location attribute marked as RULE_STATE and it has a CONSOLE_PROVIDER_GEOFENCE attribute"+ Asset console2 = ConsoleConfiguration.initConsoleConfiguration(+ new Asset("Demo Android Console 2", CONSOLE),+ "Demo Android Console",+ "1.0",+ "Android 7.1.2",+ new HashMap<String, ConsoleProvider>() {++ {+ put("geofence", new ConsoleProvider(+ ORConsoleGeofenceAssetAdapter.NAME,+ true,+ false,+ false,+ null+ ))+ }+ })+ .addAttributes(+ new AssetAttribute(AttributeType.LOCATION.getName(),+ AttributeType.LOCATION.getType())+ .setMeta(new MetaItem(RULE_STATE))+ )+ console2.setParentId(managerDemoSetup.lobbyId)+ console2 = assetStorageService.merge(console2)+ def console2Id = console2.getId()++ then: "the geofence adapter should be notified of the new console asset with the existing location predicate"+ conditions.eventually {+ def geofences = rulesService.getAssetGeofences(console2Id)+ assert geofences.size() == 1+ assert geofences[0].radius == 100+ assert geofences[0].lat == 50+ assert geofences[0].lng == 100+ assert geofences[0].id == console2Id + "_-174661203"+ assert geofences[0].url == "/master/asset/public/${console2Id}/updateLocation"+ }++ when: "a new ruleset is deployed with multiple location predicate rules (including a duplicate and a rectangular predicate) on the lobby asset"+ def lobbyRuleset = new AssetRuleset(+ "Lobby location predicates",+ managerDemoSetup.lobbyId,+ getClass().getResource("/org/openremote/test/rules/BasicLocationPredicate2.groovy").text,+ Ruleset.Lang.GROOVY+ )+ rulesetStorageService.merge(lobbyRuleset)+ RulesEngine lobbyEngine = null++ then: "the new rule engine should be created and be running"+ conditions.eventually {+ lobbyEngine = rulesService.assetEngines.get(managerDemoSetup.lobbyId)+ assert lobbyEngine != null+ assert lobbyEngine.isRunning()+ assert lobbyEngine.deployments.size() == 1+ assert lobbyEngine.deployments.values().any({+ it.name == "Lobby location predicates" && it.status == DEPLOYED+ })+ }++ then: "the geofence adapter should have been notified of the new radial location predicates for the console assets (but shouldn't contain the rectangular or duplicate predicates)"+ conditions.eventually {+ def console1Geofences = rulesService.getAssetGeofences(managerDemoSetup.consoleId)+ def console2Geofences = rulesService.getAssetGeofences(console2Id)+ assert console1Geofences.size() == 1+ assert console2Geofences.size() == 2+ assert console1Geofences[0].radius == 100+ assert console1Geofences[0].lat == 50+ assert console1Geofences[0].lng == 100+ assert console1Geofences[0].id == managerDemoSetup.consoleId + "_-174661203"+ assert console1Geofences[0].url == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"++ def console2Geofence1 = console2Geofences.find {+ it.radius == 100 &&+ it.lat == 50 &&+ it.lng == 100 &&+ it.id == console2Id + "_-174661203" &&+ it.url == "/master/asset/public/${console2Id}/updateLocation"+ }+ assert console2Geofence1 != null++ def console2Geofence2 = console2Geofences.find {+ it.radius == 50 &&+ it.lat == 0 &&+ it.lng == -60 &&+ it.id == console2Id + "_-1397479941" &&+ it.url == "/master/asset/public/${console2Id}/updateLocation"+ }+ assert console2Geofence2 != null+ }++ when: "a location predicate ruleset is removed"+ rulesetStorageService.delete(GlobalRuleset.class, rulesImport.globalRuleset3Id)++ then: "the geofence adapter should be notified and update to reflect the changes"+ conditions.eventually {+ def console1Geofences = rulesService.getAssetGeofences(managerDemoSetup.consoleId)+ def console2Geofences = rulesService.getAssetGeofences(console2Id)+ assert console1Geofences.size() == 0+ assert console2Geofences.size() == 2++ def console2Geofence1 = console2Geofences.find {+ it.radius == 100 &&+ it.lat == 50 &&+ it.lng == 100 &&+ it.id == console2Id + "_-174661203" &&+ it.url == "/master/asset/public/${console2Id}/updateLocation"+ }+ assert console2Geofence1 != null++ def console2Geofence2 = console2Geofences.find {+ it.radius == 50 &&+ it.lat == 0 &&+ it.lng == -60 &&+ it.id == console2Id + "_-1397479941" &&+ it.url == "/master/asset/public/${console2Id}/updateLocation"+ }+ assert console2Geofence2 != null+ }++ when: "the RULE_STATE meta is removed from the second console asset's location attribute"+ console2.getAttribute(AttributeType.LOCATION.getName()).get().getMeta().removeIf({it.name.orElse(null) == AssetMeta.RULE_STATE.urn})+ console2 = assetStorageService.merge(console2)++ then: "the geofence adapter should be notified that the console asset no longer has any rules with location predicates"+ conditions.eventually {+ def console2Geofences = rulesService.getAssetGeofences(console2Id)+ assert console2Geofences.size() == 0+ assert geofenceAdapter.assetLocationPredicatesMap.isEmpty()+ }++ cleanup: "the server should be stopped"+ stopContainer(container)+ }++ @Ignore+ def "Check full console behaviour"() {given: "the server container is started"def serverPort = findEphemeralPort()def container = startContainer(defaultConfig(serverPort), defaultServices())diff --git a/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovydeleted file mode 100644index bfdf6cdc6..000000000--- a/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovy+++ /dev/null@@ -1,212 +0,0 @@-package org.openremote.test.rules.geofence--import org.openremote.manager.asset.AssetStorageService-import org.openremote.manager.rules.RulesEngine-import org.openremote.manager.rules.RulesService-import org.openremote.manager.rules.RulesetStorageService-import org.openremote.manager.rules.geofence.ORConsoleGeofenceAssetAdapter-import org.openremote.manager.setup.SetupService-import org.openremote.manager.setup.builtin.KeycloakDemoSetup-import org.openremote.manager.setup.builtin.ManagerDemoSetup-import org.openremote.model.asset.Asset-import org.openremote.model.asset.AssetAttribute-import org.openremote.model.asset.AssetMeta-import org.openremote.model.attribute.AttributeType-import org.openremote.model.attribute.MetaItem-import org.openremote.model.console.ConsoleConfiguration-import org.openremote.model.console.ConsoleProvider-import org.openremote.model.rules.AssetRuleset-import org.openremote.model.rules.GlobalRuleset-import org.openremote.model.rules.Ruleset-import org.openremote.test.ManagerContainerTrait-import org.openremote.test.rules.BasicRulesImport-import spock.lang.Specification-import spock.util.concurrent.PollingConditions--import static org.openremote.manager.rules.RulesetDeployment.Status.DEPLOYED-import static org.openremote.manager.setup.builtin.ManagerDemoSetup.*-import static org.openremote.model.asset.AssetMeta.RULE_STATE-import static org.openremote.model.asset.AssetType.CONSOLE--class BasicGeofenceProcessingTest extends Specification implements ManagerContainerTrait {-- def "Check tracking of location predicate rules"() {- given: "expected conditions"- def conditions = new PollingConditions(timeout: 10, initialDelay: 0.5, delay: 0.5)-- and: "the container is started"- def serverPort = findEphemeralPort()- RulesService.GEOFENCE_PROCESSING_DEBOUNCE_MILLIS = 50- def container = startContainer(defaultConfig(serverPort), defaultServices())- def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)- def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)- def rulesService = container.getService(RulesService.class)- def rulesetStorageService = container.getService(RulesetStorageService.class)- def assetStorageService = container.getService(AssetStorageService.class)- def geofenceAdapter = (ORConsoleGeofenceAssetAdapter) rulesService.geofenceAssetAdapters.find {it.name == "ORConsole" }-- and: "some test rulesets have been imported"- def rulesImport = new BasicRulesImport(rulesetStorageService, keycloakDemoSetup, managerDemoSetup)-- expect: "the rules engines to be ready"- conditions.eventually {- rulesImport.assertEnginesReady(rulesService, keycloakDemoSetup, managerDemoSetup)- }-- and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"- conditions.eventually {- assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL- assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL- assert rulesImport.masterEngine.assetStates.size() == DEMO_RULE_STATES_SMART_OFFICE- assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A- assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2- assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3- }-- and: "the geofence adapter should have been initialised with the demo consoles location predicate"- conditions.eventually {- def geofences = rulesService.getAssetGeofences(managerDemoSetup.consoleId)- assert geofences.size() == 1- assert geofences[0].radius == 100- assert geofences[0].lat == 50- assert geofences[0].lng == 100- assert geofences[0].id == managerDemoSetup.consoleId + "_-174661203"- assert geofences[0].url == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"- }-- when: "another console asset is added with its location attribute marked as RULE_STATE and it has a CONSOLE_PROVIDER_GEOFENCE attribute"- Asset console2 = ConsoleConfiguration.initConsoleConfiguration(- new Asset("Demo Android Console 2", CONSOLE),- "Demo Android Console",- "1.0",- "Android 7.1.2",- new HashMap<String, ConsoleProvider>() {-- {- put("geofence", new ConsoleProvider(- ORConsoleGeofenceAssetAdapter.NAME,- true,- false,- false,- null- ))- }- })- .addAttributes(- new AssetAttribute(AttributeType.LOCATION.getName(),- AttributeType.LOCATION.getType())- .setMeta(new MetaItem(RULE_STATE))- )- console2.setParentId(managerDemoSetup.lobbyId)- console2 = assetStorageService.merge(console2)- def console2Id = console2.getId()-- then: "the geofence adapter should be notified of the new console asset with the existing location predicate"- conditions.eventually {- def geofences = rulesService.getAssetGeofences(console2Id)- assert geofences.size() == 1- assert geofences[0].radius == 100- assert geofences[0].lat == 50- assert geofences[0].lng == 100- assert geofences[0].id == console2Id + "_-174661203"- assert geofences[0].url == "/master/asset/public/${console2Id}/updateLocation"- }-- when: "a new ruleset is deployed with multiple location predicate rules (including a duplicate and a rectangular predicate) on the lobby asset"- def lobbyRuleset = new AssetRuleset(- "Lobby location predicates",- managerDemoSetup.lobbyId,- getClass().getResource("/org/openremote/test/rules/BasicLocationPredicate2.groovy").text,- Ruleset.Lang.GROOVY- )- rulesetStorageService.merge(lobbyRuleset)- RulesEngine lobbyEngine = null-- then: "the new rule engine should be created and be running"- conditions.eventually {- lobbyEngine = rulesService.assetEngines.get(managerDemoSetup.lobbyId)- assert lobbyEngine != null- assert lobbyEngine.isRunning()- assert lobbyEngine.deployments.size() == 1- assert lobbyEngine.deployments.values().any({- it.name == "Lobby location predicates" && it.status == DEPLOYED- })- }-- then: "the geofence adapter should have been notified of the new radial location predicates for the console assets (but shouldn't contain the rectangular or duplicate predicates)"- conditions.eventually {- def console1Geofences = rulesService.getAssetGeofences(managerDemoSetup.consoleId)- def console2Geofences = rulesService.getAssetGeofences(console2Id)- assert console1Geofences.size() == 1- assert console2Geofences.size() == 2- assert console1Geofences[0].radius == 100- assert console1Geofences[0].lat == 50- assert console1Geofences[0].lng == 100- assert console1Geofences[0].id == managerDemoSetup.consoleId + "_-174661203"- assert console1Geofences[0].url == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"-- def console2Geofence1 = console2Geofences.find {- it.radius == 100 &&- it.lat == 50 &&- it.lng == 100 &&- it.id == console2Id + "_-174661203" &&- it.url == "/master/asset/public/${console2Id}/updateLocation"- }- assert console2Geofence1 != null-- def console2Geofence2 = console2Geofences.find {- it.radius == 50 &&- it.lat == 0 &&- it.lng == -60 &&- it.id == console2Id + "_-1397479941" &&- it.url == "/master/asset/public/${console2Id}/updateLocation"- }- assert console2Geofence2 != null- }-- when: "a location predicate ruleset is removed"- rulesetStorageService.delete(GlobalRuleset.class, rulesImport.globalRuleset3Id)-- then: "the geofence adapter should be notified and update to reflect the changes"- conditions.eventually {- def console1Geofences = rulesService.getAssetGeofences(managerDemoSetup.consoleId)- def console2Geofences = rulesService.getAssetGeofences(console2Id)- assert console1Geofences.size() == 0- assert console2Geofences.size() == 2-- def console2Geofence1 = console2Geofences.find {- it.radius == 100 &&- it.lat == 50 &&- it.lng == 100 &&- it.id == console2Id + "_-174661203" &&- it.url == "/master/asset/public/${console2Id}/updateLocation"- }- assert console2Geofence1 != null-- def console2Geofence2 = console2Geofences.find {- it.radius == 50 &&- it.lat == 0 &&- it.lng == -60 &&- it.id == console2Id + "_-1397479941" &&- it.url == "/master/asset/public/${console2Id}/updateLocation"- }- assert console2Geofence2 != null- }-- when: "the RULE_STATE meta is removed from the second console asset's location attribute"- console2.getAttribute(AttributeType.LOCATION.getName()).get().getMeta().removeIf({it.name.orElse(null) == AssetMeta.RULE_STATE.urn})- console2 = assetStorageService.merge(console2)-- then: "the geofence adapter should be notified that the console asset no longer has any rules with location predicates"- conditions.eventually {- def console2Geofences = rulesService.getAssetGeofences(console2Id)- assert console2Geofences.size() == 0- assert geofenceAdapter.assetLocationPredicatesMap.isEmpty()- }-- // TODO: Verify the RulesResource code path-- cleanup: "the server should be stopped"- stopContainer(container)- }-}