Skip to content

armgit / core

Public Imported from GitHub
0

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

Cleaned up demo/test data, replaced attribute event sender with northbound boolean flag

Christian Bauer1d4a951c12aa
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
index 54fd60f34..a6383ec85 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
@@ -130,7 +130,7 @@ public abstract class AbstractProtocol implements Protocol {
}
protected void onSensorUpdate(AttributeState state, long timestamp) {
- producerTemplate.sendBody(SENSOR_TOPIC, new AttributeEvent(state, this.getClass(), timestamp));
+ producerTemplate.sendBody(SENSOR_TOPIC, new AttributeEvent(state, timestamp));
}
protected void onSensorUpdate(AttributeState state) {
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
index d24fc25aa..bb966e30c 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
@@ -20,7 +20,6 @@
package org.openremote.manager.server.agent;
import org.apache.camel.builder.RouteBuilder;
-import org.openremote.agent3.protocol.AbstractProtocol;
import org.openremote.agent3.protocol.Protocol;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
@@ -63,6 +62,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
final protected Function<AttributeRef, ProtocolConfiguration> agentLinkResolver = agentLink -> {
// Resolve the agent and the protocol configuration
// TODO This is very inefficient and requires Hibernate second-level caching
+ // TODO: Check the realm, the thing must be in the same realm as its agent!
Asset agent = find(agentLink.getEntityId());
if (agent != null && agent.getWellKnownType().equals(AGENT)) {
AgentAttributes agentAttributes = new AgentAttributes(agent);
@@ -120,7 +120,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
LOG.fine("Deploy agent: " + agent);
switch (cause) {
case UPDATE:
- // TODO: Find everything with this agent ID in the asset tree not just children
+ // TODO: Find everything with this agent ID in the asset tree (only within the same tenant/realm!) not just children
List<ServerAsset> things = assetStorageService.findAll(new AssetQuery()
.select(new AssetQuery.Select(true, false))
.type(THING)
@@ -220,13 +220,13 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
@Override
public void accept(AssetUpdate assetUpdate) {
// Check that asset is a THING
- if (assetUpdate.getAssetType() != THING) {
+ if (assetUpdate.getType() != THING) {
LOG.fine("Ignoring asset update as asset is not a THING: " + assetUpdate);
return;
}
// If update was initiated by a protocol ignore it
- if (AbstractProtocol.class.isAssignableFrom(assetUpdate.getSender())) {
+ if (assetUpdate.isNorthbound()) {
LOG.fine("Ignoring asset update as it came from a protocol:" + assetUpdate);
return;
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
index ee7852c62..c8769f5f7 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
@@ -190,13 +190,15 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
ServerAsset asset = assetStorageService.find(attributeEvent.getEntityId(), true);
if (asset == null) {
- LOG.warning("Processing client update failed asset not found: " + attributeEvent);
+ LOG.warning("Processing client update failed, asset not found: " + attributeEvent);
return;
}
// Prevent editing of individual agent attributes
if (asset.getWellKnownType() == AssetType.AGENT) {
- throw new RuntimeException("Agent attributes can not be updated individually, update the whole asset instead");
+ throw new IllegalArgumentException(
+ "Agent attributes can not be updated individually, update the whole asset instead: " + asset
+ );
}
// Pass attribute event through the processing chain
@@ -215,7 +217,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
return;
}
- processUpdate(asset, attribute, attributeEvent);
+ processUpdate(asset, attribute, attributeEvent, false);
}
/**
@@ -250,12 +252,13 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
// Protocols can write to readonly attributes (i.e. sensor attributes)
// So no need to check readonly flag
- processUpdate(thing, thingAttribute, attributeEvent);
+ processUpdate(thing, thingAttribute, attributeEvent, true);
}
protected void processUpdate(ServerAsset asset,
AbstractAssetAttribute attribute,
- AttributeEvent attributeEvent) {
+ AttributeEvent attributeEvent,
+ boolean northbound) {
// Ensure timestamp of event is not in the future as that would essentially block access to
// the attribute until after that time (maybe that is desirable behaviour)
// Allow a leniency of 1s
@@ -283,7 +286,14 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
return;
}
- processUpdate(new AssetUpdate(asset, attribute, lastStateEvent.getValue(), lastStateEvent.getTimestamp(), attributeEvent.getSender()));
+ processUpdate(
+ new AssetUpdate(
+ asset,
+ attribute,
+ lastStateEvent.getValue(),
+ lastStateEvent.getTimestamp(),
+ northbound)
+ );
}
protected void processUpdate(AssetUpdate assetUpdate) {
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java
index 61d568333..96359f3dc 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java
@@ -228,7 +228,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
try {
JsonValue value = Json.instance().parse(rawJson);
assetProcessingService.updateAttributeValue(
- new AttributeEvent(new AttributeRef(assetId, attributeName), value, this.getClass())
+ new AttributeEvent(new AttributeRef(assetId, attributeName), value)
);
} catch (RuntimeException ex) {
throw new IllegalStateException("Error updating attribute: " + attributeName, ex);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
index 3ea6c3d68..17527e2e0 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
@@ -78,7 +78,7 @@ public class AssetStorageService implements ContainerService, Consumer<AssetUpda
@Override
public void accept(AssetUpdate assetUpdate) {
- String assetId = assetUpdate.getAssetId();
+ String assetId = assetUpdate.getId();
String attributeName = assetUpdate.getAttribute().getName();
JsonValue value = assetUpdate.getAttribute().getValue();
// Some sanity checking, of course the timestamp should never be -1 if we store updated attribute state
diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java
index 761c8580e..d0dafb5dd 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java
@@ -382,7 +382,7 @@ public class RulesDeployment<T extends RulesDefinition> {
// If there already is a fact in working memory for this attribute then delete it
AssetUpdate update = facts.keySet()
.stream()
- .filter(au -> au.getAssetId().equals(assetUpdate.getAssetId()) && au.getAttributeName().equals(assetUpdate.getAttributeName()))
+ .filter(au -> au.getId().equals(assetUpdate.getId()) && au.getAttributeName().equals(assetUpdate.getAttributeName()))
.findFirst()
.orElse(null);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java
index fe20dd9e8..30a494e32 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java
@@ -438,7 +438,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
// TODO: implement rules processing error state handling
// Get the chain of rule engines that we need to pass through
- List<RulesDeployment> rulesDeployments = getEnginesInScope(assetUpdate.getAssetRealmId(), assetUpdate.getAssetPath());
+ List<RulesDeployment> rulesDeployments = getEnginesInScope(assetUpdate.getRealmId(), assetUpdate.getPath());
if (rulesDeployments.size() == 0) {
LOG.fine("Ignoring asset update as there are no matching rules deployments: " + assetUpdate);
@@ -464,7 +464,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
protected void retractFact(AssetUpdate assetUpdate) {
// Get the chain of rule engines that we need to pass through
- List<RulesDeployment> rulesDeployments = getEnginesInScope(assetUpdate.getAssetRealmId(), assetUpdate.getAssetPath());
+ List<RulesDeployment> rulesDeployments = getEnginesInScope(assetUpdate.getRealmId(), assetUpdate.getPath());
if (rulesDeployments.size() == 0) {
LOG.fine("Ignoring asset update as there are no matching rules deployments: " + assetUpdate);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
index 2866dba5b..7e8e73ad9 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
@@ -49,8 +49,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
public String smartOfficeId;
public String groundFloorId;
public String lobbyId;
- public String demoAgentId;
- public final String demoAgentProtocolConfigName = "simulator123";
+ public String agentId;
+ public final String agentProtocolConfigName = "simulator123";
public String thingId;
public String smartHomeId;
public String apartment1Id;
@@ -127,7 +127,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
agent.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
agent.setType(AssetType.AGENT);
AgentAttributes agentAttributes = new AgentAttributes();
- ProtocolConfiguration protocolConfigSimulator123 = new ProtocolConfiguration(demoAgentProtocolConfigName, SimulatorProtocol.PROTOCOL_NAME);
+ ProtocolConfiguration protocolConfigSimulator123 = new ProtocolConfiguration(agentProtocolConfigName, SimulatorProtocol.PROTOCOL_NAME);
protocolConfigSimulator123.setMeta(new Meta()
.add(new MetaItem(
SimulatorProtocol.CONFIG_MODE,
@@ -142,7 +142,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
agentAttributes.put(protocolConfigSimulator123);
agent.setAttributes(agentAttributes.getJsonObject());
agent = assetStorageService.merge(agent);
- demoAgentId = agent.getId();
+ agentId = agent.getId();
ServerAsset thing = new ServerAsset(agent);
thing.setName("Demo Thing");
@@ -158,7 +158,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
)
.add(new MetaItem(
AssetMeta.AGENT_LINK,
- new AttributeRef(agent.getId(), demoAgentProtocolConfigName).asJsonValue()
+ new AttributeRef(agent.getId(), agentProtocolConfigName).asJsonValue()
))
.add(new MetaItem(
SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(SwitchSimulatorElement.ELEMENT_NAME)
@@ -180,7 +180,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
)
.add(new MetaItem(
AssetMeta.AGENT_LINK,
- new AttributeRef(agent.getId(), demoAgentProtocolConfigName).asJsonValue()
+ new AttributeRef(agent.getId(), agentProtocolConfigName).asJsonValue()
))
.add(new MetaItem(
SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(IntegerSimulatorElement.ELEMENT_NAME_RANGE)
@@ -201,7 +201,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
)
.add(new MetaItem(
AssetMeta.AGENT_LINK,
- new AttributeRef(agent.getId(), demoAgentProtocolConfigName).asJsonValue()
+ new AttributeRef(agent.getId(), agentProtocolConfigName).asJsonValue()
))
.add(new MetaItem(
SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(ColorSimulatorElement.ELEMENT_NAME)
@@ -227,7 +227,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
)
.add(new MetaItem(
AssetMeta.AGENT_LINK,
- new AttributeRef(agent.getId(), demoAgentProtocolConfigName).asJsonValue()
+ new AttributeRef(agent.getId(), agentProtocolConfigName).asJsonValue()
))
.add(new MetaItem(
SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(DecimalSimulatorElement.ELEMENT_NAME)
@@ -246,14 +246,30 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset smartHome = new ServerAsset();
smartHome.setRealmId(customerATenant.getId());
smartHome.setName("Smart Home");
- smartHome.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ smartHome.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
smartHome.setType(BUILDING);
AssetAttributes smartHomeAttributes = new AssetAttributes();
smartHomeAttributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo")),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
+ new AssetAttribute("geoStreet", STRING, Json.create("Wilhelminaplein 21C"))
+ .setMeta(new Meta()
+ .add(createMetaItem(LABEL, Json.create("Street")))
+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoStreet")))
+ ),
+ new AssetAttribute("geoPostalCode", AttributeType.INTEGER, Json.create(5611))
+ .setMeta(new Meta()
+ .add(createMetaItem(LABEL, Json.create("Postal Code")))
+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoPostalCode")))
+ ),
+ new AssetAttribute("geoCity", STRING, Json.create("Eindhoven"))
+ .setMeta(new Meta()
+ .add(createMetaItem(LABEL, Json.create("City")))
+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCity")))
+ ),
+ new AssetAttribute("geoCountry", STRING, Json.create("Netherlands"))
+ .setMeta(new Meta()
+ .add(createMetaItem(LABEL, Json.create("Country")))
+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCountry")))
+ )
);
smartHome.setAttributes(smartHomeAttributes.getJsonObject());
smartHome = assetStorageService.merge(smartHome);
@@ -261,14 +277,20 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment1 = new ServerAsset(smartHome);
apartment1.setName("Apartment 1");
- apartment1.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ apartment1.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment1.setType(RESIDENCE);
AssetAttributes apartment1Attributes = new AssetAttributes();
apartment1Attributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo")),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
+ new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("All Lights Off Switch"))
+ ).add(
+ new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ )
+ )
);
apartment1.setAttributes(apartment1Attributes.getJsonObject());
apartment1 = assetStorageService.merge(apartment1);
@@ -276,23 +298,40 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment1Livingroom = new ServerAsset(apartment1);
apartment1Livingroom.setName("Livingroom");
- apartment1Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ apartment1Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment1Livingroom.setType(ROOM);
AssetAttributes apartment1LivingroomAttributes = new AssetAttributes();
apartment1LivingroomAttributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true))
- .setMeta(new Meta().add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
- )),
- new AssetAttribute("demoString", STRING, Json.create("demo"))
- .setMeta(new Meta().add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
- )),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
- .setMeta(new Meta().add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
- ))
+ new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ )
+ ),
+ new AssetAttribute("presenceCount15m", AttributeType.INTEGER, Json.create(0))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Presence Count 15m"))
+ ).add(
+ new MetaItem(AssetMeta.READ_ONLY, Json.create(true))
+ )
+ ),
+ new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
+ )
+ ),
+ new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Window Open"))
+ )
+ )
);
apartment1Livingroom.setAttributes(apartment1LivingroomAttributes.getJsonObject());
apartment1Livingroom = assetStorageService.merge(apartment1Livingroom);
@@ -303,24 +342,16 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment1LivingroomThermostat.setType(AssetType.THING);
AssetAttributes apartment1LivingroomThermostatAttributes = new AssetAttributes(apartment1LivingroomThermostat);
apartment1LivingroomThermostatAttributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo")),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d)),
new AssetAttribute("currentTemperature", DECIMAL, Json.createNull())
.setMeta(new Meta()
.add(new MetaItem(
- AssetMeta.AGENT_LINK,
- new AttributeRef(demoAgentId, demoAgentProtocolConfigName).asJsonValue()
- ))
+ AssetMeta.LABEL,
+ Json.create("Current Temperature"))
+ )
.add(new MetaItem(
AssetMeta.RULES_FACT,
Json.create(true)
))
- .add(new MetaItem(
- AssetMeta.LABEL,
- Json.create("Current Temp"))
- )
.add(new MetaItem(
AssetMeta.PROTECTED,
Json.create(true))
@@ -335,25 +366,17 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
.add(new MetaItem(
"urn:thirdparty:bar", Json.create("BAR")
))
- .add(new MetaItem(
- SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(DecimalSimulatorElement.ELEMENT_NAME)
- ))
-
),
- new AssetAttribute("targetTemperature", DECIMAL, Json.createNull())
+ new AssetAttribute("comfortTemperature", DECIMAL, Json.createNull())
.setMeta(new Meta()
.add(new MetaItem(
- AssetMeta.AGENT_LINK,
- new AttributeRef(demoAgentId, demoAgentProtocolConfigName).asJsonValue()
- ))
+ AssetMeta.LABEL,
+ Json.create("Comfort Temperature"))
+ )
.add(new MetaItem(
AssetMeta.RULES_FACT,
Json.create(true)
))
- .add(new MetaItem(
- AssetMeta.LABEL,
- Json.create("Target Temp"))
- )
.add(new MetaItem(
AssetMeta.PROTECTED,
Json.create(true))
@@ -376,14 +399,20 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment2 = new ServerAsset(smartHome);
apartment2.setName("Apartment 2");
- apartment2.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ apartment2.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment2.setType(RESIDENCE);
AssetAttributes apartment2Attributes = new AssetAttributes();
apartment2Attributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo")),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
+ new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("All Lights Off Switch"))
+ ).add(
+ new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ )
+ )
);
apartment2.setAttributes(apartment2Attributes.getJsonObject());
apartment2 = assetStorageService.merge(apartment2);
@@ -391,14 +420,40 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment2Livingroom = new ServerAsset(apartment2);
apartment2Livingroom.setName("Livingroom");
- apartment2Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ apartment2Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment2Livingroom.setType(ROOM);
AssetAttributes apartment2LivingroomAttributes = new AssetAttributes();
apartment2LivingroomAttributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo")),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
+ new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ )
+ ),
+ new AssetAttribute("presenceCount15m", AttributeType.INTEGER, Json.create(0))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Presence Count 15m"))
+ ).add(
+ new MetaItem(AssetMeta.READ_ONLY, Json.create(true))
+ )
+ ),
+ new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
+ )
+ ),
+ new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Window Open"))
+ )
+ )
);
apartment2Livingroom.setAttributes(apartment2LivingroomAttributes.getJsonObject());
apartment2Livingroom = assetStorageService.merge(apartment2Livingroom);
@@ -406,14 +461,20 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment3 = new ServerAsset(smartHome);
apartment3.setName("Apartment 3");
- apartment3.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ apartment3.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment3.setType(RESIDENCE);
AssetAttributes apartment3Attributes = new AssetAttributes();
apartment3Attributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo")),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
+ new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("All Lights Off Switch"))
+ ).add(
+ new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ )
+ )
);
apartment3.setAttributes(apartment3Attributes.getJsonObject());
apartment3 = assetStorageService.merge(apartment3);
@@ -421,17 +482,40 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ServerAsset apartment3Livingroom = new ServerAsset(apartment3);
apartment3Livingroom.setName("Livingroom");
- apartment3Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.469751699216005, 51.44760787406028)));
+ apartment3Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment3Livingroom.setType(ROOM);
AssetAttributes apartment3LivingroomAttributes = new AssetAttributes();
apartment3LivingroomAttributes.put(
- new AssetAttribute("demoBoolean", BOOLEAN, Json.create(true)),
- new AssetAttribute("demoString", STRING, Json.create("demo"))
- .setMeta(new Meta().add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
- )),
- new AssetAttribute("demoInteger", INTEGER, Json.create(0)),
- new AssetAttribute("demoDecimal", DECIMAL, Json.create(0d))
+ new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ )
+ ),
+ new AssetAttribute("presenceCount15m", AttributeType.INTEGER, Json.create(0))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Presence Count 15m"))
+ ).add(
+ new MetaItem(AssetMeta.READ_ONLY, Json.create(true))
+ )
+ ),
+ new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
+ ).add(
+ new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
+ )
+ ),
+ new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Window Open"))
+ )
+ )
);
apartment3Livingroom.setAttributes(apartment3LivingroomAttributes.getJsonObject());
apartment3Livingroom = assetStorageService.merge(apartment3Livingroom);
diff --git a/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy
index 722899b12..55b171be2 100644
--- a/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy
@@ -40,7 +40,7 @@ class AgentDeploymentTest extends Specification implements ManagerContainerTrait
when: "a client wants to change a thing attributes' value, triggering an actuator"
conditions = new PollingConditions(timeout: 3, initialDelay: 2)
def light1DimmerChange = new AttributeEvent(
- managerDemoSetup.thingId, "light1Dimmer", Json.create(66), getClass()
+ managerDemoSetup.thingId, "light1Dimmer", Json.create(66)
)
assetStorageService.updateAttributeValue(light1DimmerChange)
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
index 9b9c446d6..99b60d55f 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
@@ -449,8 +449,8 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
apartment1.realmId == keycloakDemoSetup.customerATenant.id
apartment1.type == AssetType.RESIDENCE.value
apartment1.parentId == managerDemoSetup.smartHomeId
- apartment1.coordinates[0] == 5.469751699216005d
- apartment1.coordinates[1] == 51.44760787406028d
+ apartment1.coordinates[0] == 5.470945d
+ apartment1.coordinates[1] == 51.438d
Asset apartment1Livingroom = assets[1]
apartment1Livingroom.id == managerDemoSetup.apartment1LivingroomId
@@ -467,7 +467,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
protectedAttributes.get("currentTemperature").getValueAsDecimal() == null
Meta protectedMeta = protectedAttributes.get("currentTemperature").getMeta()
protectedMeta.all().length == 3
- protectedMeta.first(AssetMeta.LABEL).getValueAsString() == "Current Temp"
+ protectedMeta.first(AssetMeta.LABEL).getValueAsString() == "Current Temperature"
protectedMeta.first(AssetMeta.READ_ONLY).getValueAsBoolean()
protectedMeta.first(AssetMeta.RULES_FACT).getValueAsBoolean()
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index 6dda28b9f..d81d355fd 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -21,7 +21,7 @@ import java.util.function.Consumer
import java.util.logging.Logger
class AssetProcessingTest extends Specification implements ManagerContainerTrait {
- Logger LOG = Logger.getLogger(AssetStorageService.class.getName());
+ Logger LOG = Logger.getLogger(AssetStorageService.class.getName())
def "Check processing of asset updates"() {
@@ -101,15 +101,15 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
//region and: "a mock agent that uses the mock protocol is created"
and: "a mock agent that uses the mock protocol is created"
- def mockAgent = new ServerAsset();
- mockAgent.setName("Mock Agent");
- mockAgent.setType(AssetType.AGENT);
- AgentAttributes agentAttributes = new AgentAttributes();
- ProtocolConfiguration mockProtocolConfig = new ProtocolConfiguration("mock123", mockProtocolName);
- agentAttributes.put(mockProtocolConfig);
- mockAgent.setAttributes(agentAttributes.getJsonObject());
+ def mockAgent = new ServerAsset()
+ mockAgent.setName("Mock Agent")
+ mockAgent.setType(AssetType.AGENT)
+ AgentAttributes agentAttributes = new AgentAttributes()
+ ProtocolConfiguration mockProtocolConfig = new ProtocolConfiguration("mock123", mockProtocolName)
+ agentAttributes.put(mockProtocolConfig)
+ mockAgent.setAttributes(agentAttributes.getJsonObject())
mockAgent.setRealmId(keycloakDemoSetup.masterTenant.id)
- mockAgent = assetStorageService.merge(mockAgent);
+ mockAgent = assetStorageService.merge(mockAgent)
//endregion
//region and: "a mock thing asset is created with a valid protocol attribute, an invalid protocol attribute and a plain attribute"
@@ -117,7 +117,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
def mockThing = new ServerAsset(mockAgent)
mockThing.setName("Mock Thing Asset")
mockThing.setType(AssetType.THING)
- def mockThingAttributes = new AssetAttributes(mockThing);
+ def mockThingAttributes = new AssetAttributes(mockThing)
mockThingAttributes.put(
new AssetAttribute("light1Toggle", AttributeType.BOOLEAN, Json.create(false))
.setMeta(new Meta()
@@ -141,7 +141,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
.add(new MetaItem(
AssetMeta.AGENT_LINK,
- new AttributeRef("INVALID AGENT ID", managerDemoSetup.demoAgentProtocolConfigName).asJsonValue()
+ new AttributeRef("INVALID AGENT ID", managerDemoSetup.agentProtocolConfigName).asJsonValue()
)
)
),
@@ -153,8 +153,8 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
)
)
)
- mockThing.setAttributes(mockThingAttributes.getJsonObject());
- mockThing = assetStorageService.merge(mockThing);
+ mockThing.setAttributes(mockThingAttributes.getJsonObject())
+ mockThing = assetStorageService.merge(mockThing)
//endregion
expect: "the mock thing to be deployed to the protocol"
@@ -164,7 +164,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
when: "an attribute event occurs for the valid protocol attribute"
def light1toggleOn = new AttributeEvent(
- new AttributeState(new AttributeRef(mockThing.getId(), "light1Toggle"), Json.create(true)), getClass()
+ new AttributeState(new AttributeRef(mockThing.getId(), "light1Toggle"), Json.create(true))
)
assetProcessingService.updateAttributeValue(light1toggleOn)
@@ -188,7 +188,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert updatesPassedStartOfProcessingChain.size() == 2
assert sendToActuatorEvents.size() == 1
assert updatesReachedEndOfProcessingChain.size() == 1
- assert updatesReachedEndOfProcessingChain[0].assetName == "Mock Thing Asset"
+ assert updatesReachedEndOfProcessingChain[0].name == "Mock Thing Asset"
assert updatesReachedEndOfProcessingChain[0].attributeName == "light1Toggle"
assert updatesReachedEndOfProcessingChain[0].oldValue.asBoolean() == false
assert updatesReachedEndOfProcessingChain[0].value.asBoolean() == true
@@ -201,7 +201,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
updatesReachedEndOfProcessingChain.clear()
sendToActuatorEvents.clear()
def light2toggleOn = new AttributeEvent(
- new AttributeState(new AttributeRef(mockThing.getId(), "light2Toggle"), Json.create(true)), getClass()
+ new AttributeState(new AttributeRef(mockThing.getId(), "light2Toggle"), Json.create(true))
)
assetProcessingService.updateAttributeValue(light2toggleOn)
@@ -211,7 +211,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert updatesPassedStartOfProcessingChain.size() == 1
assert updatesReachedEndOfProcessingChain.size() == 0
assert sendToActuatorEvents.size() == 0
- assert updatesPassedStartOfProcessingChain[0].assetId == mockThing.id
+ assert updatesPassedStartOfProcessingChain[0].id == mockThing.id
assert updatesPassedStartOfProcessingChain[0].attributeName == "light2Toggle"
assert updatesPassedStartOfProcessingChain[0].error != null
assert updatesPassedStartOfProcessingChain[0].error instanceof RuntimeException
@@ -223,7 +223,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
updatesReachedEndOfProcessingChain.clear()
sendToActuatorEvents.clear()
def plainAttributeTest = new AttributeEvent(
- new AttributeState(new AttributeRef(mockThing.getId(), "plainAttribute"), Json.create("test")), getClass()
+ new AttributeState(new AttributeRef(mockThing.getId(), "plainAttribute"), Json.create("test"))
)
assetProcessingService.updateAttributeValue(plainAttributeTest)
@@ -232,7 +232,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert updatesPassedStartOfProcessingChain.size() == 1
assert sendToActuatorEvents.size() == 0
assert updatesReachedEndOfProcessingChain.size() == 1
- assert updatesReachedEndOfProcessingChain[0].assetName == "Mock Thing Asset"
+ assert updatesReachedEndOfProcessingChain[0].name == "Mock Thing Asset"
assert updatesReachedEndOfProcessingChain[0].attributeName == "plainAttribute"
assert updatesReachedEndOfProcessingChain[0].oldValue.asString() == "demo"
assert updatesReachedEndOfProcessingChain[0].value.asString() == "test"
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index cf02c8f16..9b96b8a3d 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -251,8 +251,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetAttributes(assets.get(2).attributes).size() == 2
new AssetAttributes(assets.get(2).attributes).get("currentTemperature").valueAsDecimal == null
new AssetAttributes(assets.get(2).attributes).get("currentTemperature").meta.size() == 3
- new AssetAttributes(assets.get(2).attributes).get("targetTemperature").valueAsDecimal == null
- new AssetAttributes(assets.get(2).attributes).get("targetTemperature").meta.size() == 2
+ new AssetAttributes(assets.get(2).attributes).get("comfortTemperature").valueAsDecimal == null
+ new AssetAttributes(assets.get(2).attributes).get("comfortTemperature").meta.size() == 2
assets.get(3).id == managerDemoSetup.apartment2Id
when: "a query is executed"
@@ -278,12 +278,12 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
then: "result should match"
assets.size() == 1
- assets.get(0).id == managerDemoSetup.demoAgentId
+ assets.get(0).id == managerDemoSetup.agentId
when: "a query is executed"
assets = assetStorageService.findAll(new AssetQuery()
.type(THING)
- .parent(new ParentPredicate(managerDemoSetup.demoAgentId))
+ .parent(new ParentPredicate(managerDemoSetup.agentId))
)
then: "result should match"
@@ -327,42 +327,54 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
AssetMeta.AGENT_LINK,
- managerDemoSetup.demoAgentId,
- managerDemoSetup.demoAgentProtocolConfigName
+ managerDemoSetup.agentId,
+ managerDemoSetup.agentProtocolConfigName
)
)
)
then: "result should match"
- assets.size() == 2
+ assets.size() == 1
assets.get(0).id == managerDemoSetup.thingId
- assets.get(1).id == managerDemoSetup.apartment1LivingroomThermostatId
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
AssetMeta.AGENT_LINK,
- managerDemoSetup.demoAgentId,
- managerDemoSetup.demoAgentProtocolConfigName
+ managerDemoSetup.agentId,
+ managerDemoSetup.agentProtocolConfigName
)
- )
+ ).name(new StringPredicate(Match.CONTAINS, false, "thing"))
)
then: "result should match"
- assets.size() == 2
+ assets.size() == 1
assets.get(0).id == managerDemoSetup.thingId
- assets.get(1).id == managerDemoSetup.apartment1LivingroomThermostatId
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
AssetMeta.AGENT_LINK,
- managerDemoSetup.demoAgentId,
- managerDemoSetup.demoAgentProtocolConfigName
+ managerDemoSetup.agentId,
+ managerDemoSetup.agentProtocolConfigName
)
- ).name(new StringPredicate(Match.CONTAINS, false, "thing"))
+ ).name(new StringPredicate(Match.CONTAINS, true, "thing"))
+ )
+
+ then: "result should match"
+ assets.size() == 0
+
+ when: "a query is executed"
+ assets = assetStorageService.findAll(
+ new AssetQuery().attributeMeta(
+ new AttributeRefPredicate(
+ AssetMeta.AGENT_LINK,
+ managerDemoSetup.agentId,
+ managerDemoSetup.agentProtocolConfigName
+ )
+ ).parent(new ParentPredicate(managerDemoSetup.agentId))
)
then: "result should match"
@@ -374,30 +386,28 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
AssetMeta.AGENT_LINK,
- managerDemoSetup.demoAgentId,
- managerDemoSetup.demoAgentProtocolConfigName
+ managerDemoSetup.agentId,
+ managerDemoSetup.agentProtocolConfigName
)
).parent(new ParentPredicate(managerDemoSetup.apartment1LivingroomId))
)
then: "result should match"
- assets.size() == 1
- assets.get(0).id == managerDemoSetup.apartment1LivingroomThermostatId
+ assets.size() == 0
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
- managerDemoSetup.demoAgentId,
- managerDemoSetup.demoAgentProtocolConfigName
+ managerDemoSetup.agentId,
+ managerDemoSetup.agentProtocolConfigName
)
- ).tenant(new TenantPredicate().realm(keycloakDemoSetup.customerATenant.realm))
+ ).tenant(new TenantPredicate().realm(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
assets.size() == 1
- assets.get(0).id == managerDemoSetup.apartment1LivingroomThermostatId
+ assets.get(0).id == managerDemoSetup.thingId
cleanup: "the server should be stopped"
stopContainer(container)
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index 88fd12d46..87905addb 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -118,10 +118,10 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(apartment3Engine, apartment3EngineFiredRules)
and: "an attribute event is pushed into the system for an attribute with RULES_FACT meta set to true"
- def apartment1LivingRoomDemoBooleanChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoBoolean"), Json.create(false)), getClass()
+ def apartment1LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "presenceDetected", Json.create(true)
)
- assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoBooleanChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomPresenceDetectedChange)
then: "the rule engines in scope should fire the 'All' and 'All changed' rules"
conditions.eventually {
@@ -139,37 +139,37 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
when: "an attribute event is pushed into the system for an attribute with RULES_FACT meta set to false"
resetRuleExecutionLoggers()
- def apartment1LivingRoomDemoStringChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoString"), Json.create("demo2")), getClass()
+ def apartment1LivingRoomLightSwitchChange = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "lightSwitch", Json.create(true)
)
- assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoStringChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomLightSwitchChange)
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
when: "an attribute event is pushed into the system for an attribute with no RULES_FACT meta"
resetRuleExecutionLoggers()
- def apartment1LivingRoomDemoIntegerChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoInteger"), Json.create(1)), getClass()
+ def apartment1LivingRoomWindowOpenChange = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "windowOpen", Json.create(true)
)
- assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoIntegerChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomWindowOpenChange)
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
when: "an old (stale) attribute event is pushed into the system"
resetRuleExecutionLoggers()
- assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoBooleanChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomPresenceDetectedChange)
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
when: "an attribute event with the same value as current value is pushed into the system"
resetRuleExecutionLoggers()
- apartment1LivingRoomDemoBooleanChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoBoolean"), Json.create(false)), getClass()
+ apartment1LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "presenceDetected", Json.create(true)
)
- assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoBooleanChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomPresenceDetectedChange)
then: "the rule engines in scope should fire the 'All' rule but not the 'All changed' rule"
conditions.eventually {
@@ -209,10 +209,10 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(smartHomeEngine, smartHomeEngineFiredRules)
and: "an apartment 3 living room attribute event occurs"
- def apartment3LivingRoomDemoStringChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment3LivingroomId, "demoString"), Json.create("demo2")), getClass()
+ def apartment3LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment3LivingroomId, "presenceDetected", Json.create(true)
)
- assetProcessingService.updateAttributeValue(apartment3LivingRoomDemoStringChange)
+ assetProcessingService.updateAttributeValue(apartment3LivingRoomPresenceDetectedChange)
then: "the engines in scope should have fired the matched rules"
conditions.eventually {
@@ -221,7 +221,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.size() == 2
assert customerAEngineFiredRules.containsAll(["All", "All changed"])
assert smartHomeEngineFiredRules.size() == 5
- assert smartHomeEngineFiredRules.containsAll(["Living Room All", "Current Asset Update", "Parent Type Residence", "Asset Type Room", "String Attributes"])
+ assert smartHomeEngineFiredRules.containsAll(["Living Room All", "Current Asset Update", "Parent Type Residence", "Asset Type Room", "Boolean Attributes"])
assert apartment3EngineFiredRules.size() == 2
assert apartment3EngineFiredRules.containsAll(["All", "All changed"])
assert apartment1EngineFiredRules.size() == 0
@@ -229,10 +229,10 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
when: "an apartment 1 living room thermostat attribute event occurs"
resetRuleExecutionLoggers()
- def apartment1LivingRoomTargetTempChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomThermostatId, "targetTemperature"), Json.create(22.5)), getClass()
+ def apartment1LivingRoomComfortTemperatureChange = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomThermostatId, "comfortTemperature", Json.create(22.5)
)
- assetProcessingService.updateAttributeValue(apartment1LivingRoomTargetTempChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomComfortTemperatureChange)
then: "the engines in scope should have fired the matched rules"
conditions.eventually {
@@ -244,7 +244,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert smartHomeEngineFiredRules.containsAll(
[
"Living Room Thermostat",
- "Living Room Target Temp",
+ "Living Room Comfort Temperature",
"Living Room as Parent",
"JSON Number value types",
"Current Asset Update"
@@ -277,10 +277,10 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(globalEngine, globalEngineFiredRules)
and: "an apartment 1 living room thermostat attribute event occurs"
- apartment1LivingRoomTargetTempChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomThermostatId, "targetTemperature"), Json.create(22.5)), getClass()
+ apartment1LivingRoomComfortTemperatureChange = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomThermostatId, "comfortTemperature", Json.create(20.3)
)
- assetProcessingService.updateAttributeValue(apartment1LivingRoomTargetTempChange)
+ assetProcessingService.updateAttributeValue(apartment1LivingRoomComfortTemperatureChange)
then: "after a few seconds only the global engine should have fired the All, All changed and Prevent Livingroom Thermostat Change rules"
conditions.eventually {
@@ -294,10 +294,10 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
when: "an apartment 3 living room attribute event occurs"
resetRuleExecutionLoggers()
- apartment3LivingRoomDemoStringChange = new AttributeEvent(
- new AttributeState(new AttributeRef(managerDemoSetup.apartment3LivingroomId, "demoString"), Json.create("demo3")), getClass()
+ apartment3LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment3LivingroomId, "presenceDetected", Json.create(false)
)
- assetProcessingService.updateAttributeValue(apartment3LivingRoomDemoStringChange)
+ assetProcessingService.updateAttributeValue(apartment3LivingRoomPresenceDetectedChange)
then: "all the engines in scope should have fired the matched rules"
conditions.eventually {
@@ -306,7 +306,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.size() == 2
assert customerAEngineFiredRules.containsAll(["All", "All changed"])
assert smartHomeEngineFiredRules.size() == 5
- assert smartHomeEngineFiredRules.containsAll(["Living Room All", "Current Asset Update", "Parent Type Residence", "Asset Type Room", "String Attributes"])
+ assert smartHomeEngineFiredRules.containsAll(["Living Room All", "Current Asset Update", "Parent Type Residence", "Asset Type Room", "Boolean Attributes"])
assert apartment3EngineFiredRules.size() == 2
assert apartment3EngineFiredRules.containsAll(["All", "All changed"])
assert apartment1EngineFiredRules.size() == 0
diff --git a/manager/test/src/test/resources/org/openremote/test/rules/SmartHomeMatchAllAssetUpdates.drl b/manager/test/src/test/resources/org/openremote/test/rules/SmartHomeMatchAllAssetUpdates.drl
index a129f0915..9c43b277c 100644
--- a/manager/test/src/test/resources/org/openremote/test/rules/SmartHomeMatchAllAssetUpdates.drl
+++ b/manager/test/src/test/resources/org/openremote/test/rules/SmartHomeMatchAllAssetUpdates.drl
@@ -8,46 +8,53 @@ global java.util.logging.Logger LOG;
rule "Living Room All"
when
- $e: AssetUpdate(assetName == "Livingroom")
+ $e: AssetUpdate(name == "Livingroom")
then
return;
end
rule "Kitchen All"
when
- $e: AssetUpdate(assetName == "Kitchen")
+ $e: AssetUpdate(name == "Kitchen")
then
return;
end
rule "Kitchen Integer Attributes"
when
- $e: AssetUpdate(assetName == "Kitchen", attributeType == AttributeType.INTEGER)
+ $e: AssetUpdate(name == "Kitchen", attributeType == AttributeType.INTEGER)
then
return;
end
rule "Living Room Thermostat"
when
- $e: AssetUpdate(assetName == "Livingroom Thermostat")
+ $e: AssetUpdate(name == "Livingroom Thermostat")
then
return;
end
-rule "Living Room Target Temp"
+rule "Living Room Comfort Temperature"
when
- $e: AssetUpdate(assetName == "Livingroom Thermostat", attributeName == "targetTemperature")
+ $e: AssetUpdate(name == "Livingroom Thermostat", attributeName == "comfortTemperature")
then
return;
end
rule "Living Room as Parent"
when
- AssetUpdate(assetParentName == "Livingroom")
+ AssetUpdate(parentName == "Livingroom")
then
return;
end
+rule "Boolean Attributes"
+when
+ AssetUpdate(attributeType == AttributeType.BOOLEAN)
+then
+ return;
+end
+
rule "String Attributes"
when
AssetUpdate(attributeType == AttributeType.STRING)
@@ -71,14 +78,14 @@ end
rule "Parent Type Residence"
when
- AssetUpdate(assetParentType == AssetType.RESIDENCE)
+ AssetUpdate(parentType == AssetType.RESIDENCE)
then
return;
end
rule "Asset Type Room"
when
- AssetUpdate(assetType == AssetType.ROOM)
+ AssetUpdate(type == AssetType.ROOM)
then
return;
end
\ No newline at end of file
diff --git a/manager/test/src/test/resources/org/openremote/test/rules/SmartHomePreventAssetUpdate.drl b/manager/test/src/test/resources/org/openremote/test/rules/SmartHomePreventAssetUpdate.drl
index b53812ae1..d4226be39 100644
--- a/manager/test/src/test/resources/org/openremote/test/rules/SmartHomePreventAssetUpdate.drl
+++ b/manager/test/src/test/resources/org/openremote/test/rules/SmartHomePreventAssetUpdate.drl
@@ -8,7 +8,7 @@ global java.util.logging.Logger LOG;
rule "Prevent Livingroom Thermostat Change"
when
- $e: AssetUpdate(assetName == "Livingroom Thermostat", !completed)
+ $e: AssetUpdate(name == "Livingroom Thermostat", !completed)
then
$e.setStatus(AssetUpdate.Status.HANDLED);
end
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/AttributeEvent.java b/model/src/main/java/org/openremote/model/AttributeEvent.java
index 4c15bd440..ac90b76ae 100644
--- a/model/src/main/java/org/openremote/model/AttributeEvent.java
+++ b/model/src/main/java/org/openremote/model/AttributeEvent.java
@@ -30,25 +30,20 @@ public class AttributeEvent extends Event {
final protected AttributeState attributeState;
- public AttributeEvent(String entityId, String attributeName, JsonValue value, Class<?> sender) {
- this(new AttributeState(new AttributeRef(entityId, attributeName), value), sender);
+ public AttributeEvent(String entityId, String attributeName, JsonValue value) {
+ this(new AttributeState(new AttributeRef(entityId, attributeName), value));
}
- public AttributeEvent(AttributeRef attributeRef, JsonValue value, Class<?> sender) {
- this(new AttributeState(attributeRef, value), sender);
+ public AttributeEvent(AttributeRef attributeRef, JsonValue value) {
+ this(new AttributeState(attributeRef, value));
}
- public AttributeEvent(AttributeState attributeState, Class<?> sender) {
- super(sender);
+ public AttributeEvent(AttributeState attributeState) {
this.attributeState = attributeState;
}
- public AttributeEvent(AttributeRef attributeRef, JsonValue value, Class<?> sender, long timestamp) {
- this(new AttributeState(attributeRef, value), sender, timestamp);
- }
-
- public AttributeEvent(AttributeState attributeState, Class<?> sender, long timestamp) {
- super(timestamp, sender);
+ public AttributeEvent(AttributeState attributeState, long timestamp) {
+ super(timestamp);
this.attributeState = attributeState;
}
diff --git a/model/src/main/java/org/openremote/model/Event.java b/model/src/main/java/org/openremote/model/Event.java
index 898460a27..808e2acf4 100644
--- a/model/src/main/java/org/openremote/model/Event.java
+++ b/model/src/main/java/org/openremote/model/Event.java
@@ -37,25 +37,19 @@ import java.util.Locale;
*/
// TODO Any subclass that is not @JsonIgnoreType will be made serializable (and must be compilable in GWT!)
// TODO This needs more work when we know how to do client/server pub/sub message bus
-// TODO Should sender be compulsory?
/**
- * A timestamped event with optional sender.
+ * A timestamped event.
*/
public abstract class Event {
- protected Class<?> sender;
+
protected long timestamp;
- protected Event(long timestamp, Class<?> sender) {
+ protected Event(long timestamp) {
this.timestamp = timestamp;
- this.sender = sender;
}
protected Event() {
- this(System.currentTimeMillis(), null);
- }
-
- protected Event(Class<?> sender) {
- this(System.currentTimeMillis(), sender);
+ this(System.currentTimeMillis());
}
/**
@@ -114,11 +108,6 @@ public abstract class Event {
return timestamp;
}
- @JsonIgnore
- public Class<?> getSender() {
- return sender;
- }
-
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java
index 90d10a294..5e258ca80 100644
--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java
@@ -103,7 +103,6 @@ public abstract class AbstractAssetAttribute<CHILD extends AbstractAssetAttribut
public AttributeEvent getStateEvent() {
return new AttributeEvent(
getState(),
- null,
getValueTimestamp()
);
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetQuery.java b/model/src/main/java/org/openremote/model/asset/AssetQuery.java
index 231c88ede..fc843743c 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetQuery.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetQuery.java
@@ -29,7 +29,7 @@ import java.util.Locale;
* A query returns a collection of {@link Asset} instances, or when the
* {@link #id} predicate is set, a single instance.
*/
-public class AssetQuery {
+public class AssetQuery<CHILD extends AssetQuery<CHILD>> {
static public class Select {
public boolean loadComplete;
@@ -381,60 +381,72 @@ public class AssetQuery {
public AssetQuery() {
}
- public AssetQuery select(Select select) {
+ public CHILD select(Select select) {
this.select = select;
- return this;
+ return (CHILD) this;
}
/**
* If this value is set, no other restrictions will be applied and only a single result should be returned.
*/
- public AssetQuery id(String id) {
+ public CHILD id(String id) {
this.id = id;
- return this;
+ return (CHILD) this;
}
- public AssetQuery name(StringPredicate name) {
+ public CHILD name(String name) {
+ return name(new StringPredicate(name));
+ }
+
+ public CHILD name(StringPredicate name) {
this.name = name;
- return this;
+ return (CHILD) this;
+ }
+
+ public CHILD parent(String id) {
+ return parent(new ParentPredicate(id));
+ }
+
+ public CHILD parent(AssetType assetType) {
+ return parent(new ParentPredicate().type(assetType));
}
- public AssetQuery parent(ParentPredicate parentPredicate) {
+ public CHILD parent(ParentPredicate parentPredicate) {
this.parentPredicate = parentPredicate;
- return this;
+ return (CHILD) this;
}
- public AssetQuery path(PathPredicate pathPredicate) {
+ public CHILD path(PathPredicate pathPredicate) {
this.pathPredicate = pathPredicate;
- return this;
+ return (CHILD) this;
}
- public AssetQuery tenant(TenantPredicate tenantPredicate) {
+ public CHILD tenant(TenantPredicate tenantPredicate) {
this.tenantPredicate = tenantPredicate;
- return this;
+ return (CHILD) this;
}
- public AssetQuery userId(String userId) {
+ public CHILD userId(String userId) {
this.userId = userId;
- return this;
+ return (CHILD) this;
}
- public AssetQuery type(StringPredicate type) {
+ public CHILD type(StringPredicate type) {
this.type = type;
- return this;
+ return (CHILD) this;
}
- public AssetQuery type(AssetType assetType) {
+ public CHILD type(AssetType assetType) {
return type(new StringPredicate(assetType.getValue()));
}
- public AssetQuery attributeMeta(AttributeMetaPredicate attributeMetaPredicate) {
+ public CHILD attributeMeta(AttributeMetaPredicate attributeMetaPredicate) {
this.attributeMetaPredicate = attributeMetaPredicate;
- return this;
+ return (CHILD) this;
}
- public AssetQuery orderBy(OrderBy orderBy) {
+ public CHILD orderBy(OrderBy orderBy) {
this.orderBy = orderBy;
- return this;
+ return (CHILD) this;
}
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AssetUpdate.java
index 690d4a31f..c48bf9a23 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetUpdate.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetUpdate.java
@@ -63,25 +63,29 @@ public class AssetUpdate {
final protected AbstractAssetAttribute attribute;
- final protected Date assetCreatedOn;
+ final protected Date createdOn;
- final protected String assetId;
+ final protected String id;
- final protected String assetName;
+ final protected String name;
- final protected String assetType;
+ final protected String typeString;
- final protected String[] assetPath;
+ final protected AssetType type;
- final protected String assetParentId;
+ final protected String[] path;
- final protected String assetParentName;
+ final protected String parentId;
- final protected String assetParentType;
+ final protected String parentName;
- final protected String assetRealmId;
+ final protected String parentTypeString;
- final protected String assetTenantRealm;
+ final protected AssetType parentType;
+
+ final protected String realmId;
+
+ final protected String tenantRealm;
final protected double[] coordinates;
@@ -93,79 +97,83 @@ public class AssetUpdate {
protected Throwable error;
- final protected Class<?> sender;
+ // True if the update was initiated by a protocol and is being processed northbound
+ protected boolean northbound;
public AssetUpdate(Asset asset, AbstractAssetAttribute attribute) {
- this(asset, attribute, null, 0, null);
+ this(asset, attribute, null, 0, false);
}
- public AssetUpdate(Asset asset, AbstractAssetAttribute attribute, JsonValue oldValue, long oldValueTimestamp, Class<?> sender) {
+ public AssetUpdate(Asset asset, AbstractAssetAttribute attribute, JsonValue oldValue, long oldValueTimestamp, boolean northbound) {
this.attribute = attribute;
- this.assetId = asset.getId();
- this.assetName = asset.getName();
+ this.id = asset.getId();
+ this.name = asset.getName();
if (asset.getPath() == null) {
throw new IllegalArgumentException("Asset not loaded completely, empty path: " + asset);
}
- this.assetPath = asset.getPath();
- this.assetType = asset.getType();
- this.assetCreatedOn = asset.getCreatedOn();
- this.assetParentId = asset.getParentId();
- this.assetParentName = asset.getParentName();
- this.assetParentType = asset.getParentType();
- this.assetRealmId = asset.getRealmId();
- this.assetTenantRealm = asset.getTenantRealm();
+ this.path = asset.getPath();
+ this.typeString = asset.getType();
+ this.type = asset.getWellKnownType();
+ this.createdOn = asset.getCreatedOn();
+ this.parentId = asset.getParentId();
+ this.parentName = asset.getParentName();
+ this.parentTypeString = asset.getParentType();
+ this.parentType = asset.getParentType() != null ? AssetType.getByValue(asset.getParentType()) : null;
+ this.realmId = asset.getRealmId();
+ this.tenantRealm = asset.getTenantRealm();
this.coordinates = asset.getCoordinates();
this.oldValue = oldValue;
this.oldValueTimestamp = oldValueTimestamp;
- this.sender = sender;
+ this.northbound = northbound;
}
- public Date getAssetCreatedOn() {
- return assetCreatedOn;
+ public Date getCreatedOn() {
+ return createdOn;
}
- public String getAssetId() {
- return assetId;
+ public String getId() {
+ return id;
}
- public String getAssetName() {
- return assetName;
+ public String getName() {
+ return name;
}
- public AssetType getAssetType() {
- return AssetType.getByValue(assetType);
+ public String getTypeString() {
+ return typeString;
}
- public String getAssetTypeString() {
- return assetType;
+ public AssetType getType() {
+ return type;
}
- public String[] getAssetPath() {
- return assetPath;
+
+ public String[] getPath() {
+ return path;
}
- public String getAssetParentId() {
- return assetParentId;
+ public String getParentId() {
+ return parentId;
}
- public String getAssetParentName() {
- return assetParentName;
+ public String getParentName() {
+ return parentName;
}
- public AssetType getAssetParentType() {
- return AssetType.getByValue(assetParentType);
+ public String getParentTypeString() {
+ return parentTypeString;
}
- public String getAssetParentTypeString() {
- return assetParentType;
+ public AssetType getParentType() {
+ return parentType;
}
- public String getAssetRealmId() {
- return assetRealmId;
+ public String getRealmId() {
+ return realmId;
}
- public String getAssetTenantRealm() {
- return assetTenantRealm;
+ public String getTenantRealm() {
+ return tenantRealm;
}
public double[] getCoordinates() {
@@ -188,8 +196,8 @@ public class AssetUpdate {
return error;
}
- public Class<?> getSender() {
- return sender;
+ public boolean isNorthbound() {
+ return northbound;
}
public JsonValue getValue() {
@@ -268,7 +276,7 @@ public class AssetUpdate {
// TODO Don't use jsEquals(), write own comparison by value
- return assetId.equals(that.assetId) &&
+ return id.equals(that.id) &&
getAttributeName().equalsIgnoreCase(that.getAttributeName()) &&
JsonUtil.equals(getValue(), that.getValue()) &&
getValueTimestamp() == that.getValueTimestamp() &&
@@ -278,7 +286,7 @@ public class AssetUpdate {
@Override
public int hashCode() {
- return assetId.hashCode() + getAttributeName().hashCode() + JsonUtil.hashCode(getValue())
+ return id.hashCode() + getAttributeName().hashCode() + JsonUtil.hashCode(getValue())
+ Long.hashCode(getValueTimestamp())
+ (oldValue != null ? JsonUtil.hashCode(oldValue) : 0) + Long.hashCode(oldValueTimestamp);
}
@@ -286,7 +294,7 @@ public class AssetUpdate {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "assetId=" + getAssetName() +
+ "assetId=" + getName() +
", attributeName=" + getAttributeName() +
", value=" + getValue().toJson() +
", valueTimestamp=" + getValueTimestamp() +