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
Fixed AssetQueryTest
Michael Rademaker46c8abb6b313
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.javaindex 5ab8225b3..57f87ea56 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java@@ -808,9 +808,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (query.location instanceof RadialLocationPredicate) {RadialLocationPredicate location = (RadialLocationPredicate) query.location;sb.append(" and ST_Distance_Sphere(ST_MakePoint(");- sb.append("(A.attributes -> 'location' -> 'value' ->> 'latitude')::numeric");sb.append("(A.attributes -> 'location' -> 'value' ->> 'longitude')::numeric");- sb.append(")), ST_MakePoint(");+ sb.append(", (A.attributes -> 'location' -> 'value' ->> 'latitude')::numeric");+ sb.append("), ST_MakePoint(");sb.append(location.lng);sb.append(",");sb.append(location.lat);@@ -819,11 +819,11 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic} else if (query.location instanceof RectangularLocationPredicate) {RectangularLocationPredicate location = (RectangularLocationPredicate) query.location;sb.append(location.negated ? " and NOT" : " and");- sb.append(" ST_Within(ST_MakePoint(,");- sb.append("(A.attributes -> 'location' -> 'value' ->> 'latitude')::numeric");+ sb.append(" ST_Within(ST_MakePoint(");sb.append("(A.attributes -> 'location' -> 'value' ->> 'longitude')::numeric");+ sb.append(", (A.attributes -> 'location' -> 'value' ->> 'latitude')::numeric");sb.append(")");- sb.append("ST_MakeEnvelope(");+ sb.append(", ST_MakeEnvelope(");sb.append(location.lngMin);sb.append(",");sb.append(location.latMin);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 e8a8f28b4..d6bd9f7c9 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@@ -50,7 +50,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {final protected boolean importDemoScenes;// Update these numbers whenever you change a RULE_STATE flag in test data- public static final int DEMO_RULE_STATES_APARTMENT_1 = 33;+ public static final int DEMO_RULE_STATES_APARTMENT_1 = 37;public static final int DEMO_RULE_STATES_APARTMENT_2 = 11;public static final int DEMO_RULE_STATES_APARTMENT_3 = 0;public static final int DEMO_RULE_STATES_SMART_OFFICE = 1;@@ -136,12 +136,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {smartOfficeId = smartOffice.getId();Asset groundFloor = new Asset("Ground Floor", FLOOR, smartOffice)- .setAttributes(new AssetAttribute("location", LOCATION, locationValue));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValue));groundFloor = assetStorageService.merge(groundFloor);groundFloorId = groundFloor.getId();Asset lobby = new Asset("Lobby", ROOM, groundFloor)- .setAttributes(new AssetAttribute("location", LOCATION, locationValue));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValue));lobby.addAttributes(new AssetAttribute("lobbyLocations", AttributeType.ARRAY));@@ -150,8 +150,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {lobbyId = lobby.getId();Asset agent = new Asset("Demo Agent", AGENT, lobby);- agent.setAttributes(- new AssetAttribute("location", LOCATION, locationValue),+ agent.addAttributes(+ AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValue),initProtocolConfiguration(new AssetAttribute(agentProtocolConfigName), SimulatorProtocol.PROTOCOL_NAME).addMeta(new MetaItem(@@ -168,8 +168,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {agentId = agent.getId();Asset thing = new Asset("Demo Thing", THING, agent)- .setAttributes(new AssetAttribute("location", LOCATION, locationValue));- thing.setAttributes(+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValue));+ thing.addAttributes(new AssetAttribute(thingLightToggleAttributeName, BOOLEAN, Values.create(true)).setMeta(new Meta(new MetaItem(@@ -249,7 +249,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {STORE_DATA_POINTS, Values.create(true)))),- new AssetAttribute("location", ARRAY)+ new AssetAttribute("locations", ARRAY).setMeta(new MetaItem(RULE_STATE)));thing = assetStorageService.merge(thing);@@ -321,8 +321,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {smartHome.setRealmId(customerATenant.getId());smartHome.setName("Smart Home");smartHome.setType(BUILDING);- smartHome.setAttributes(- new AssetAttribute("location", LOCATION, locationValueA),+ smartHome.addAttributes(+ AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA),new AssetAttribute("geoStreet", STRING, Values.create("Wilhelminaplein 21C")).setMeta(new MetaItem(LABEL, Values.create("Street")),@@ -349,12 +349,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {// The "Apartment 1" is the demo apartment with complex scenesAsset apartment1 = createDemoApartment(smartHome, "Apartment 1")- .setAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ .addAttributes(new AssetAttribute("location", LOCATION, locationValueA));apartment1 = assetStorageService.merge(apartment1);apartment1Id = apartment1.getId();Asset apartment1ServiceAgent = new Asset("Service Agent (Simulator)", AGENT, apartment1);- apartment1ServiceAgent.setAttributes(+ apartment1ServiceAgent.addAttributes(initProtocolConfiguration(new AssetAttribute("apartmentSimulator"), SimulatorProtocol.PROTOCOL_NAME).addMeta(new MetaItem(@@ -368,7 +368,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {/* ############################ ROOMS ############################## */Asset apartment1Livingroom = createDemoApartmentRoom(apartment1, "Living Room")- .setAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.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))@@ -394,7 +394,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment1LivingroomId = apartment1Livingroom.getId();Asset apartment1Kitchen = createDemoApartmentRoom(apartment1, "Kitchen")- .setAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.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))@@ -427,7 +427,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment1KitchenId = apartment1Kitchen.getId();Asset apartment1Hallway = createDemoApartmentRoom(apartment1, "Hallway")- .setAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.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))@@ -453,7 +453,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Asset demoApartmentSceneAgent = createDemoApartmentSceneAgent(apartment1, scenes, apartment1Livingroom, apartment1Kitchen, apartment1Hallway- ).addAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ ).addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA));demoApartmentSceneAgent = assetStorageService.merge(demoApartmentSceneAgent);@@ -462,8 +462,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {}Asset apartment2 = new Asset("Apartment 2", RESIDENCE, smartHome);- apartment2.setAttributes(- new AssetAttribute("location", LOCATION, locationValueA),+ apartment2.addAttributes(+ AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA),new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Values.create(true)).setMeta(new MetaItem(LABEL, Values.create("All Lights Off Switch")),@@ -476,8 +476,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment2Id = apartment2.getId();Asset apartment2Livingroom = new Asset("Living Room", ROOM, apartment2);- apartment2Livingroom.setAttributes(- new AssetAttribute("location", LOCATION, locationValueA),+ apartment2Livingroom.addAttributes(+ AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA),new AssetAttribute("motionSensor", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Motion Sensor")),@@ -522,8 +522,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment2LivingroomId = apartment2Livingroom.getId();Asset apartment2Bathroom = new Asset("Bathroom", ROOM, apartment2);- apartment2Bathroom.setAttributes(- new AssetAttribute("location", LOCATION, locationValueA),+ apartment2Bathroom.addAttributes(+ AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA),new AssetAttribute("motionSensor", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Motion Sensor")),@@ -559,12 +559,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment2BathroomId = apartment2Bathroom.getId();Asset apartment3 = new Asset("Apartment 3", RESIDENCE, smartHome)- .setAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA));apartment3 = assetStorageService.merge(apartment3);apartment3Id = apartment3.getId();Asset apartment3Livingroom = new Asset("Living Room", ROOM, apartment3)- .setAttributes(new AssetAttribute("location", LOCATION, locationValueA));+ .addAttributes(AssetAttribute.createWithDescriptor(AttributeDescriptorImpl.LOCATION, locationValueA));apartment3Livingroom.addAttributes(new AssetAttribute("lightSwitch", AttributeType.BOOLEAN));diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovyindex 2d60a81b3..783aa7f69 100644--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy@@ -11,12 +11,15 @@ import 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.AssetAttributeimport org.openremote.model.asset.AssetMetaimport org.openremote.model.asset.AssetQueryimport org.openremote.model.asset.AssetTypeimport org.openremote.model.asset.CalendarEventConfiguration+import org.openremote.model.attribute.AttributeDescriptorImplimport org.openremote.model.calendar.CalendarEventimport org.openremote.model.calendar.RecurrenceRule+import org.openremote.model.value.Valuesimport org.openremote.test.ManagerContainerTraitimport spock.lang.Sharedimport spock.lang.Specification@@ -25,6 +28,7 @@ import spock.util.concurrent.PollingConditionsimport javax.persistence.EntityManagerimport java.util.function.Function+import static org.openremote.model.asset.AssetAttribute.createWithDescriptorimport static org.openremote.model.asset.BaseAssetQuery.*import static org.openremote.model.asset.BaseAssetQuery.Access.PRIVATE_READimport static org.openremote.model.asset.BaseAssetQuery.Access.RESTRICTED_READ@@ -84,7 +88,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets[0].realmId == nullassets[0].tenantRealm == nullassets[0].tenantDisplayName == null- assets[0].coordinates == nullassets[0].path == nullwhen: "a user filtering query is executed that returns only IDs, names and attribute names"@@ -166,7 +169,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets[1].realmId == nullassets[1].tenantRealm == nullassets[1].tenantDisplayName == null- assets[1].coordinates == nullassets[1].path == nullassets[1].getAttributesList().size() == 6assets[1].getAttribute("ventilationAuto").isPresent()@@ -208,7 +210,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.realmId == keycloakDemoSetup.customerATenant.idasset.tenantRealm == nullasset.tenantDisplayName == null- asset.coordinates.length == 2asset.path.length == 2asset.path[0] == managerDemoSetup.apartment1Idasset.path[1] == managerDemoSetup.smartHomeId@@ -232,7 +233,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.realmId == keycloakDemoSetup.masterTenant.idasset.tenantRealm == keycloakDemoSetup.masterTenant.realmasset.tenantDisplayName == keycloakDemoSetup.masterTenant.displayName- asset.coordinates.length == 2asset.path == nullasset.attributesList.size() == 0@@ -255,7 +255,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.realmId == keycloakDemoSetup.masterTenant.idasset.tenantRealm == keycloakDemoSetup.masterTenant.realmasset.tenantDisplayName == keycloakDemoSetup.masterTenant.displayName- asset.coordinates.length == 2asset.path.length == 1asset.path[0] == managerDemoSetup.smartOfficeIdasset.getAttribute("geoStreet").get().getValueAsString().get() == "Torenallee 20"@@ -280,7 +279,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).realmId == keycloakDemoSetup.masterTenant.idassets.get(0).tenantRealm == keycloakDemoSetup.masterTenant.realmassets.get(0).tenantDisplayName == keycloakDemoSetup.masterTenant.displayName- assets.get(0).coordinates.length == 2assets.get(0).path == nullassets.get(0).attributesList.size() == 0@@ -305,7 +303,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).realmId == keycloakDemoSetup.masterTenant.idassets.get(0).tenantRealm == keycloakDemoSetup.masterTenant.realmassets.get(0).tenantDisplayName == keycloakDemoSetup.masterTenant.displayName- assets.get(0).coordinates.length == 2assets.get(0).path.length == 1assets.get(0).path[0] == managerDemoSetup.smartOfficeIdassets.get(0).getAttribute("geoStreet").get().getValueAsString().get() == "Torenallee 20"@@ -328,7 +325,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).realmId == keycloakDemoSetup.customerATenant.idassets.get(0).tenantRealm == keycloakDemoSetup.customerATenant.realmassets.get(0).tenantDisplayName == keycloakDemoSetup.customerATenant.displayName- assets.get(0).coordinates.length == 2assets.get(0).path == nullassets.get(0).attributesList.size() == 0assets.get(1).id == managerDemoSetup.apartment2Id@@ -594,7 +590,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.realmId == keycloakDemoSetup.customerATenant.idasset.tenantRealm == keycloakDemoSetup.customerATenant.realmasset.tenantDisplayName == keycloakDemoSetup.customerATenant.displayName- asset.coordinates.length == 2asset.path != nullasset.getAttributesList().size() == 3asset.getAttribute("co2Level").isPresent()@@ -623,7 +618,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.realmId == keycloakDemoSetup.customerATenant.idasset.tenantRealm == keycloakDemoSetup.customerATenant.realmasset.tenantDisplayName == keycloakDemoSetup.customerATenant.displayName- asset.coordinates.length == 2asset.path != nullasset.getAttributesList().size() == 1asset.getAttribute("co2Level").isPresent()@@ -681,7 +675,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {when: "one of the assets in the region is moved"def lobby = assetStorageService.find(managerDemoSetup.lobbyId, true)- lobby.setLocation(new GeometryFactory().createPoint(new Coordinate(5.46108d, 51.44593d)))+ lobby.replaceAttribute(createWithDescriptor(AttributeDescriptorImpl.LOCATION, Values.createObject().put("latitude", 51.44593d).put("longitude", 5.46108d)))lobby = assetStorageService.merge(lobby)then: "the system should settle down"