Skip to content

armgit / core

Public Imported from GitHub
0

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

RULE_STATE and STORE_DATA_POINTS now only implicitly true for attributes with an AGENT_LINK meta item

Rich Turner42a4da411d60
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
index f1405a7b1..875276df6 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
@@ -117,7 +117,8 @@ import static org.openremote.model.value.MetaItemType.AGENT_LINK;
* successful.
* <h2>Asset Datapoint Service processing logic</h2>
* <p>
- * Checks if attribute has {@link MetaItemType#STORE_DATA_POINTS} set to false, and if so the {@link AttributeEvent}
+ * Checks if attribute has {@link MetaItemType#STORE_DATA_POINTS} set to false or if the attribute does not have an
+ * {@link org.openremote.model.asset.agent.AgentLink} meta, and if so the {@link AttributeEvent}
* is not stored in a time series DB of historical data, otherwise the value is stored. Then allows the message to
* continue if the commit was successful.
*/
diff --git a/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
index d71086d3f..5c5bbc907 100644
--- a/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
@@ -122,6 +122,8 @@ public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleRe
public static ConsoleAsset initConsoleAsset(ConsoleRegistration consoleRegistration, boolean allowPublicLocationWrite, boolean allowRestrictedLocationWrite) {
ConsoleAsset consoleAsset = new ConsoleAsset(consoleRegistration.getName());
+ consoleAsset.getAttributes().getOrCreate(Asset.LOCATION).addOrReplaceMeta(new MetaItem<>(RULE_STATE));
+
if (allowPublicLocationWrite) {
consoleAsset.getAttributes().getOrCreate(Asset.LOCATION).addOrReplaceMeta(new MetaItem<>(ACCESS_PUBLIC_WRITE, true));
}
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
index f5742d89e..360c7709d 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -114,14 +114,17 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
}
}
+ protected static boolean attributeIsStoreDatapoint(Attribute<?> attribute) {
+ return attribute.getMetaValue(STORE_DATA_POINTS).orElse(attribute.hasMeta(MetaItemType.AGENT_LINK));
+ }
+
@Override
public boolean processAssetUpdate(EntityManager em,
Asset<?> asset,
Attribute<?> attribute,
Source source) throws AssetProcessingException {
- if (attribute.getMetaValue(STORE_DATA_POINTS).orElse(true)
- && attribute.getValue().isPresent()) { // Don't store datapoints with null value
+ if (attributeIsStoreDatapoint(attribute) && attribute.getValue().isPresent()) { // Don't store datapoints with null value
// Perform upsert on datapoint (datapoint isn't immutable then really and tied to postgresql but prevents entire attribute event from failing)
LOG.finest("Storing datapoint for: " + attribute);
@@ -322,7 +325,7 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
try (ResultSet rs = st.executeQuery()) {
List<ValueDatapoint<?>> result = new ArrayList<>();
while (rs.next()) {
- Object value = rs.getObject(2) != null ? Values.convert(rs.getString(2), Double.class) : null;
+ Object value = rs.getObject(2) != null ? Values.getValueCoerced(rs.getObject(2), Double.class).orElse(null) : null;
result.add(new ValueDatapoint<>(rs.getTimestamp(1).getTime(), value));
}
return result.toArray(new ValueDatapoint<?>[0]);
diff --git a/manager/src/main/java/org/openremote/manager/predicted/AssetPredictedDatapointService.java b/manager/src/main/java/org/openremote/manager/predicted/AssetPredictedDatapointService.java
index 1a404cdbe..d7dc8eae2 100644
--- a/manager/src/main/java/org/openremote/manager/predicted/AssetPredictedDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/predicted/AssetPredictedDatapointService.java
@@ -206,7 +206,7 @@ public class AssetPredictedDatapointService implements ContainerService, Protoco
try (ResultSet rs = st.executeQuery()) {
List<ValueDatapoint<?>> result = new ArrayList<>();
while (rs.next()) {
- Object value = rs.getObject(2) != null ? Values.convert(rs.getString(2), attributeType) : null;
+ Object value = rs.getObject(2) != null ? Values.getValueCoerced(rs.getObject(2), attributeType).orElse(null) : null;
result.add(new ValueDatapoint<>(rs.getTimestamp(1).getTime(), value));
}
return result.toArray(new ValueDatapoint<?>[0]);
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
index 8d46abf46..f30c132d0 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -79,10 +79,11 @@ import static org.openremote.model.value.MetaItemType.RULE_STATE;
/**
* Manages {@link RulesEngine}s for stored {@link Ruleset}s and processes asset attribute updates.
* <p>
- * If an updated attribute doesn't have meta {@link MetaItemType#RULE_STATE} is false, this implementation of {@link
- * AssetUpdateProcessor} converts the update message to an {@link AssetState} fact. This service keeps the facts and
- * thus the state of rule facts are in sync with the asset state changes that occur. If an asset attribute value
- * changes, the {@link AssetState} in the rules engines will be updated to reflect the change.
+ * If an updated attribute doesn't have meta {@link MetaItemType#RULE_STATE} is false and the attribute has an {@link
+ * org.openremote.model.asset.agent.AgentLink} meta, this implementation of {@link AssetUpdateProcessor} converts the
+ * update message to an {@link AssetState} fact. This service keeps the facts and thus the state of rule facts are in
+ * sync with the asset state changes that occur. If an asset attribute value changes, the {@link AssetState} in the
+ * rules engines will be updated to reflect the change.
* <p>
* If an updated attribute's {@link MetaItemType#RULE_EVENT} is true, another temporary {@link AssetState} fact is
* inserted in the rules engines in scope. This fact expires automatically if the lifetime set in {@link
@@ -330,6 +331,10 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
}
}
+ protected static boolean attributeIsRuleState(Attribute<?> attribute) {
+ return attribute.getMetaValue(MetaItemType.RULE_STATE).orElse(attribute.hasMeta(MetaItemType.AGENT_LINK));
+ }
+
@Override
public boolean processAssetUpdate(EntityManager em,
Asset<?> asset,
@@ -338,7 +343,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
// We might process two facts for a single attribute update, if that is what the user wants
// First as asset state
- if (attribute.getMetaValue(MetaItemType.RULE_STATE).orElse(true)) {
+ if (attributeIsRuleState(attribute)) {
updateAssetState(new AssetState<>(asset, attribute, source));
}
@@ -464,7 +469,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
List<Attribute<?>> ruleStateAttributes = asset
.getAttributes()
.stream()
- .filter(attribute -> attribute.getMetaValue(MetaItemType.RULE_STATE).orElse(true)).collect(Collectors.toList());
+ .filter(RulesService::attributeIsRuleState).collect(Collectors.toList());
// Asset<?> used to be loaded for each attribute which is inefficient
Asset<?> loadedAsset = ruleStateAttributes.isEmpty() ? null : assetStorageService.find(asset.getId(),
@@ -496,14 +501,14 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
if (loadedAsset == null)
return;
- List<Attribute<?>> oldStateAttributes = ((AttributeMap)persistenceEvent.getPreviousState("attributes"))
+ List<Attribute<?>> oldStateAttributes = ((AttributeMap) persistenceEvent.getPreviousState("attributes"))
.stream()
- .filter(attr -> attr.getMetaValue(RULE_STATE).orElse(true))
+ .filter(RulesService::attributeIsRuleState)
.collect(toList());
List<Attribute<?>> newStateAttributes = ((AttributeMap) persistenceEvent.getCurrentState("attributes"))
.stream()
- .filter(attr -> attr.getMetaValue(RULE_STATE).orElse(true))
+ .filter(RulesService::attributeIsRuleState)
.collect(Collectors.toList());
// Retract obsolete or modified attributes
@@ -528,7 +533,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
case DELETE:
// Retract any facts that were associated with this asset
asset.getAttributes().stream()
- .filter(attribute -> attribute.getMetaValue(MetaItemType.RULE_STATE).orElse(true))
+ .filter(RulesService::attributeIsRuleState)
.forEach(attribute -> {
AssetState<?> assetState = new AssetState<>(asset, attribute, Source.INTERNAL);
LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + assetState);
@@ -857,14 +862,14 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
return assets.stream()
.map(asset ->
new Pair<>(asset, asset.getAttributes().stream()
- .filter(attribute -> attribute.getMetaValue(MetaItemType.RULE_STATE).orElse(true)))
+ .filter(RulesService::attributeIsRuleState))
);
}
/**
- * Called when an engine's rules change identifying assets with location attributes that also have
- * {@link LocationAttributePredicate} in the rules. The job here is to identify the asset's (via {@link AssetState})
- * that have modified {@link LocationAttributePredicate}s and to notify the {@link GeofenceAssetAdapter}s.
+ * Called when an engine's rules change identifying assets with location attributes that also have {@link
+ * LocationAttributePredicate} in the rules. The job here is to identify the asset's (via {@link AssetState}) that
+ * have modified {@link LocationAttributePredicate}s and to notify the {@link GeofenceAssetAdapter}s.
*/
protected void onEngineLocationRulesChanged(RulesEngine<?> rulesEngine, List<RulesEngine.AssetStateLocationPredicates> newEngineAssetStateLocationPredicates) {
withLock(getClass().getSimpleName() + "::onEngineLocationRulesChanged", () -> {
diff --git a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
index f144690c9..a57b7e3ec 100644
--- a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
@@ -91,25 +91,30 @@ public abstract class AbstractManagerSetup implements Setup {
.addMeta(
new MetaItem<>(LABEL, "Alarm enabled"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(ACCESS_RESTRICTED_WRITE, true)
+ new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("presenceDetected", BOOLEAN)
.addMeta(
new MetaItem<>(LABEL, "Presence detected"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(READ_ONLY, true)
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true),
+ new MetaItem<>(STORE_DATA_POINTS, true)
),
new Attribute<>("vacationUntil", TIMESTAMP)
.addMeta(
new MetaItem<>(LABEL, "Vacation until"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(ACCESS_RESTRICTED_WRITE, true)
+ new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lastExecutedScene", ValueType.TEXT)
.addMeta(
new MetaItem<>(LABEL, "Last executed scene"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(READ_ONLY, true)
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>(Asset.LOCATION, location)
.addMeta(new MetaItem<>(ACCESS_RESTRICTED_READ, true))
@@ -120,11 +125,13 @@ public abstract class AbstractManagerSetup implements Setup {
new MetaItem<>(DESCRIPTION, "Predict presence and automatically adjust scene schedule"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lastDetectedScene", ValueType.STRING)
.addMeta(
new MetaItem<>(LABEL, "Last detected scene by rules"),
new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true)
)
*/
);
@@ -142,22 +149,28 @@ public abstract class AbstractManagerSetup implements Setup {
new Attribute<>("motionSensor", INTEGER)
.addMeta(
new MetaItem<>(LABEL, "Motion sensor"),
- new MetaItem<>(READ_ONLY, true)),
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true),
+ new MetaItem<>(STORE_DATA_POINTS)),
new Attribute<>("presenceDetected", BOOLEAN)
.addMeta(
new MetaItem<>(LABEL, "Presence detected"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(READ_ONLY, true)
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(STORE_DATA_POINTS, true)
),
new Attribute<>("firstPresenceDetected", TIMESTAMP)
.addMeta(
new MetaItem<>(LABEL, "First time movement was detected"),
- new MetaItem<>(READ_ONLY, true)
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lastPresenceDetected", TIMESTAMP)
.addMeta(
new MetaItem<>(LABEL, "Last time movement was detected"),
- new MetaItem<>(READ_ONLY, true)
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true)
)
);
@@ -177,10 +190,12 @@ public abstract class AbstractManagerSetup implements Setup {
.addMeta(
new MetaItem<>(UNITS, Constants.units(UNITS_PART_PER_MILLION)),
new MetaItem<>(LABEL, "CO2 level"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(RULE_EVENT, true),
new MetaItem<>(RULE_EVENT_EXPIRES, "PT45M"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(READ_ONLY, true)
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(STORE_DATA_POINTS)
));
if (shouldBeLinked) {
@@ -195,11 +210,13 @@ public abstract class AbstractManagerSetup implements Setup {
new Attribute<>("humidity", POSITIVE_INTEGER)
.addMeta(
new MetaItem<>(LABEL, "Humidity"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(RULE_EVENT, true),
new MetaItem<>(RULE_EVENT_EXPIRES, "PT45M"),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(READ_ONLY, true),
- new MetaItem<>(UNITS, Constants.units(UNITS_PERCENTAGE))
+ new MetaItem<>(UNITS, Constants.units(UNITS_PERCENTAGE)),
+ new MetaItem<>(STORE_DATA_POINTS)
));
if (shouldBeLinked) {
@@ -216,10 +233,12 @@ public abstract class AbstractManagerSetup implements Setup {
new Attribute<>("currentTemperature", NUMBER)
.addMeta(
new MetaItem<>(LABEL, "Current temperature"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(READ_ONLY, true),
new MetaItem<>(UNITS, Constants.units(UNITS_CELSIUS)),
- new MetaItem<>(FORMAT, ValueFormat.NUMBER_1_DP())
+ new MetaItem<>(FORMAT, ValueFormat.NUMBER_1_DP()),
+ new MetaItem<>(STORE_DATA_POINTS)
));
if (shouldBeLinked) {
@@ -236,10 +255,12 @@ public abstract class AbstractManagerSetup implements Setup {
new Attribute<>("targetTemperature", NUMBER)
.addMeta(
new MetaItem<>(LABEL, "Target temperature"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
new MetaItem<>(UNITS, Constants.units(UNITS_CELSIUS)),
- new MetaItem<>(FORMAT, ValueFormat.NUMBER_1_DP())
+ new MetaItem<>(FORMAT, ValueFormat.NUMBER_1_DP()),
+ new MetaItem<>(STORE_DATA_POINTS)
));
if (shouldBeLinked) {
@@ -267,6 +288,7 @@ public abstract class AbstractManagerSetup implements Setup {
new MetaItem<>(LABEL, "Smart Switch mode " + switchName),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(RULE_EVENT, true),
new MetaItem<>(RULE_EVENT_EXPIRES, "PT48H")),
// Time
@@ -274,28 +296,28 @@ public abstract class AbstractManagerSetup implements Setup {
.addMeta(
new MetaItem<>(LABEL, "Smart Switch begin/end cycle " + switchName),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(ACCESS_RESTRICTED_WRITE, true)
- ),
+ new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(RULE_STATE, true)),
// StartTime
new Attribute<>("smartSwitchStartTime" + switchName, TIMESTAMP)
.addMeta(
new MetaItem<>(LABEL, "Smart Switch actuator earliest start time " + switchName),
new MetaItem<>(READ_ONLY, true),
- new MetaItem<>(UNITS, Constants.units(UNITS_SECOND))
- ),
+ new MetaItem<>(UNITS, Constants.units(UNITS_SECOND)),
+ new MetaItem<>(RULE_STATE, true)),
// StopTime
new Attribute<>("smartSwitchStopTime" + switchName, TIMESTAMP)
.addMeta(
new MetaItem<>(LABEL, "Smart Switch actuator latest stop time " + switchName),
new MetaItem<>(READ_ONLY, true),
- new MetaItem<>(UNITS, Constants.units(UNITS_SECOND))
- ),
+ new MetaItem<>(UNITS, Constants.units(UNITS_SECOND)),
+ new MetaItem<>(RULE_STATE, true)),
// Enabled
new Attribute<>("smartSwitchEnabled" + switchName, NUMBER)
.addMeta(
new MetaItem<>(LABEL, "Smart Switch actuator enabled " + switchName),
- new MetaItem<>(READ_ONLY, true)
- )
+ new MetaItem<>(READ_ONLY, true),
+ new MetaItem<>(RULE_STATE, true))
);
if (shouldBeLinked) {
@@ -324,11 +346,14 @@ public abstract class AbstractManagerSetup implements Setup {
new Attribute<>("ventilationLevel", POSITIVE_INTEGER)
.addMeta(
new MetaItem<>(LABEL, "Ventilation level"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
- new MetaItem<>(ACCESS_RESTRICTED_WRITE, true)),
+ new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(STORE_DATA_POINTS)),
new Attribute<>("ventilationAuto", BOOLEAN)
.addMeta(
new MetaItem<>(LABEL, "Ventilation auto"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(ACCESS_RESTRICTED_WRITE, true)
)
@@ -504,6 +529,7 @@ public abstract class AbstractManagerSetup implements Setup {
new MetaItem<>(LABEL, scene.sceneName + " time " + dayOfWeekLabel),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(ACCESS_RESTRICTED_WRITE, true),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(AGENT_LINK, new TimerAgent.TimerAgentLink(agents.get(i+j).getId()).setTimerValue(TimerValue.TIME))
),
new Attribute<>(scene.attributeName + "Enabled" + dayOfWeek.name(), BOOLEAN)
@@ -549,27 +575,46 @@ public abstract class AbstractManagerSetup implements Setup {
new Attribute<>(Asset.LOCATION, location)
);
peopleCounterAsset.getAttribute("peopleCountIn").ifPresent(assetAttribute -> {
+ assetAttribute.addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
if (agentLinker != null) {
assetAttribute.addMeta(new MetaItem<>(AGENT_LINK, agentLinker.get()));
}
});
peopleCounterAsset.getAttribute("peopleCountOut").ifPresent(assetAttribute -> {
+ assetAttribute.addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
if (agentLinker != null) {
assetAttribute.addMeta(new MetaItem<>(AGENT_LINK, agentLinker.get()));
}
});
peopleCounterAsset.getAttribute("peopleCountInMinute").ifPresent(assetAttribute -> {
+ assetAttribute.addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
if (agentLinker != null) {
assetAttribute.addMeta(new MetaItem<>(AGENT_LINK, agentLinker.get()));
}
});
peopleCounterAsset.getAttribute("peopleCountOutMinute").ifPresent(assetAttribute -> {
+ assetAttribute.addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
if (agentLinker != null) {
assetAttribute.addMeta(new MetaItem<>(AGENT_LINK, agentLinker.get()));
}
});
peopleCounterAsset.getAttribute("peopleCountTotal").ifPresent(assetAttribute -> {
-
+ assetAttribute.addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
if (agentLinker != null) {
assetAttribute.addMeta(new MetaItem<>(AGENT_LINK, agentLinker.get()));
}
@@ -586,7 +631,8 @@ public abstract class AbstractManagerSetup implements Setup {
);
microphoneAsset.getAttribute(MicrophoneAsset.SOUND_LEVEL).ifPresent(assetAttribute -> {
assetAttribute.addMeta(
- new MetaItem<>(READ_ONLY)
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
);
if (agentLinker != null) {
assetAttribute.addMeta(new MetaItem<>(AGENT_LINK, agentLinker.get()));
@@ -622,8 +668,29 @@ public abstract class AbstractManagerSetup implements Setup {
protected LightAsset createDemoLightAsset(String name, Asset<?> area, GeoJSONPoint location) {
LightAsset lightAsset = new LightAsset(name);
lightAsset.setParent(area);
- lightAsset.getAttributes().getOrCreate("groupNumber", POSITIVE_INTEGER);
- lightAsset.getAttributes().getOrCreate("scenario", TEXT);
+ lightAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+ lightAsset.getAttributes().getOrCreate(LightAsset.ON_OFF).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate(LightAsset.BRIGHTNESS).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate(LightAsset.COLOUR_RGB).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate("groupNumber", POSITIVE_INTEGER).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate("scenario", TEXT).addMeta(
+ new MetaItem<>(RULE_STATE)
+ );
+
return lightAsset;
}
@@ -633,7 +700,21 @@ public abstract class AbstractManagerSetup implements Setup {
lightAsset.getAttributes().addOrReplace(
new Attribute<>(Asset.LOCATION, location)
);
- lightAsset.getAttributes().getOrCreate("scenario", TEXT);
+ lightAsset.getAttributes().getOrCreate(LightAsset.ON_OFF).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate(LightAsset.BRIGHTNESS).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate(LightAsset.COLOUR_RGB).addMeta(
+ new MetaItem<>(RULE_STATE),
+ new MetaItem<>(STORE_DATA_POINTS)
+ );
+ lightAsset.getAttributes().getOrCreate("scenario", TEXT).addMeta(
+ new MetaItem<>(RULE_STATE)
+ );
return lightAsset;
}
@@ -641,42 +722,70 @@ public abstract class AbstractManagerSetup implements Setup {
protected ElectricityStorageAsset createDemoElectricityStorageAsset(String name, Asset<?> area, GeoJSONPoint location) {
ElectricityStorageAsset electricityStorageAsset = new ElectricityStorageAsset(name);
electricityStorageAsset.setParent(area);
- return electricityStorageAsset;
+ electricityStorageAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
+ return electricityStorageAsset;
}
protected ElectricityProducerSolarAsset createDemoElectricitySolarProducerAsset(String name, Asset<?> area, GeoJSONPoint location) {
ElectricityProducerSolarAsset electricityProducerAsset = new ElectricityProducerSolarAsset(name);
electricityProducerAsset.setParent(area);
- return electricityProducerAsset;
+ electricityProducerAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
+ return electricityProducerAsset;
}
protected ElectricityConsumerAsset createDemoElectricityConsumerAsset(String name, Asset<?> area, GeoJSONPoint location) {
ElectricityConsumerAsset electricityConsumerAsset = new ElectricityConsumerAsset(name);
electricityConsumerAsset.setParent(area);
- return electricityConsumerAsset;
+ electricityConsumerAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
+ return electricityConsumerAsset;
}
protected ElectricityChargerAsset createDemoElectricityChargerAsset(String name, Asset<?> area, GeoJSONPoint location) {
ElectricityChargerAsset electricityChargerAsset = new ElectricityChargerAsset(name);
electricityChargerAsset.setParent(area);
+ electricityChargerAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
return electricityChargerAsset;
}
protected GroundwaterSensorAsset createDemoGroundwaterAsset(String name, Asset<?> area, GeoJSONPoint location) {
GroundwaterSensorAsset groundwaterAsset = new GroundwaterSensorAsset(name);
groundwaterAsset.setParent(area);
- return groundwaterAsset;
+ groundwaterAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
+ return groundwaterAsset;
}
protected ParkingAsset createDemoParkingAsset(String name, Asset<?> area, GeoJSONPoint location) {
ParkingAsset parkingAsset = new ParkingAsset(name);
parkingAsset.setParent(area);
- return parkingAsset;
+ parkingAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
+ return parkingAsset;
}
protected ShipAsset createDemoShipAsset(String name, Asset<?> area, GeoJSONPoint location) {
ShipAsset shipAsset = new ShipAsset(name);
shipAsset.setParent(area);
+ shipAsset.getAttributes().addOrReplace(
+ new Attribute<>(Asset.LOCATION, location)
+ );
+
return shipAsset;
}
}
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerTestSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerTestSetup.java
index dc158ec8c..010afa6ee 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerTestSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerTestSetup.java
@@ -51,14 +51,14 @@ import static org.openremote.model.value.ValueType.*;
public class ManagerTestSetup extends AbstractManagerSetup {
// Update these numbers whenever you change a RULE_STATE flag in test data
- public static final int DEMO_RULE_STATES_APARTMENT_1 = 69;
- public static final int DEMO_RULE_STATES_APARTMENT_2 = 25;
- public static final int DEMO_RULE_STATES_APARTMENT_3 = 9;
- public static final int DEMO_RULE_STATES_SMART_OFFICE = 21;
- public static final int DEMO_RULE_STATES_SMART_BUILDING = DEMO_RULE_STATES_APARTMENT_1 + DEMO_RULE_STATES_APARTMENT_2 + DEMO_RULE_STATES_APARTMENT_3 + 6;
- public static final int DEMO_RULE_STATES_SMART_CITY = 82;
+ public static final int DEMO_RULE_STATES_APARTMENT_1 = 44;
+ public static final int DEMO_RULE_STATES_APARTMENT_2 = 13;
+ public static final int DEMO_RULE_STATES_APARTMENT_3 = 0;
+ public static final int DEMO_RULE_STATES_SMART_OFFICE = 5;
+ public static final int DEMO_RULE_STATES_SMART_BUILDING = DEMO_RULE_STATES_APARTMENT_1 + DEMO_RULE_STATES_APARTMENT_2 + DEMO_RULE_STATES_APARTMENT_3;
+ public static final int DEMO_RULE_STATES_SMART_CITY = 27;
public static final int DEMO_RULE_STATES_GLOBAL = DEMO_RULE_STATES_SMART_BUILDING + DEMO_RULE_STATES_SMART_OFFICE + DEMO_RULE_STATES_SMART_CITY;
- public static final int DEMO_RULE_STATES_APARTMENT_1_WITH_SCENES = DEMO_RULE_STATES_APARTMENT_1 + 309;
+ public static final int DEMO_RULE_STATES_APARTMENT_1_WITH_SCENES = DEMO_RULE_STATES_APARTMENT_1 + 70;
public static final int DEMO_RULE_STATES_SMART_BUILDING_WITH_SCENES = DEMO_RULE_STATES_APARTMENT_1_WITH_SCENES + DEMO_RULE_STATES_APARTMENT_2 + DEMO_RULE_STATES_APARTMENT_3;
public static GeoJSONPoint SMART_OFFICE_LOCATION = new GeoJSONPoint(5.460315214821094, 51.44541688237109);
public static GeoJSONPoint SMART_BUILDING_LOCATION = new GeoJSONPoint(5.454027, 51.446308);
@@ -160,7 +160,7 @@ public class ManagerTestSetup extends AbstractManagerSetup {
Asset<?> thing = new ThingAsset("Demo Thing");
thing.setParent(agent);
thing.getAttributes().addOrReplace(
- new Attribute<>(Asset.LOCATION, SMART_OFFICE_LOCATION),
+ new Attribute<>(Asset.LOCATION, SMART_OFFICE_LOCATION).addMeta(new MetaItem<>(RULE_STATE, true)),
new Attribute<>(thingLightToggleAttributeName, BOOLEAN, true)
.addOrReplaceMeta(
new MetaItem<>(
@@ -332,6 +332,7 @@ public class ManagerTestSetup extends AbstractManagerSetup {
new Attribute<>(Asset.LOCATION, new GeoJSONPoint(5.454227,51.446753)),
new Attribute<>("lights", BOOLEAN, true)
.addMeta(
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(ACCESS_RESTRICTED_READ, true),
new MetaItem<>(ACCESS_RESTRICTED_WRITE, true)
)
@@ -381,28 +382,34 @@ public class ManagerTestSetup extends AbstractManagerSetup {
new Attribute<>("motionSensor", BOOLEAN, false)
.addMeta(
new MetaItem<>(LABEL, "Motion Sensor"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(RULE_EVENT, true)
),
new Attribute<>("presenceDetected", BOOLEAN, false)
.addMeta(
- new MetaItem<>(LABEL, "Presence Detected")
+ new MetaItem<>(LABEL, "Presence Detected"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("firstPresenceDetected", ValueType.TIMESTAMP)
.addMeta(
- new MetaItem<>(LABEL, "First Presence Timestamp")
+ new MetaItem<>(LABEL, "First Presence Timestamp"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lastPresenceDetected", ValueType.TIMESTAMP)
.addMeta(
- new MetaItem<>(LABEL, "Last Presence Timestamp")
+ new MetaItem<>(LABEL, "Last Presence Timestamp"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("co2Level", POSITIVE_INTEGER, 350)
.addMeta(
new MetaItem<>(LABEL, "CO2 Level"),
- new MetaItem<>(UNITS, Constants.units(UNITS_PART_PER_MILLION))
+ new MetaItem<>(UNITS, Constants.units(UNITS_PART_PER_MILLION)),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lightSwitch", BOOLEAN, true)
.addMeta(
- new MetaItem<>(LABEL, "Light Switch")
+ new MetaItem<>(LABEL, "Light Switch"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("windowOpen", BOOLEAN, false)
.addMeta(
@@ -410,11 +417,13 @@ public class ManagerTestSetup extends AbstractManagerSetup {
),
new Attribute<>("lightSwitchTriggerTimes", TEXT.asArray(), new String[] {"1800", "0830"})
.addMeta(
- new MetaItem<>(LABEL, "Lightswitch Trigger Times")
+ new MetaItem<>(LABEL, "Lightswitch Trigger Times"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("plantsWaterLevels", JSON_OBJECT, objectMap)
.addMeta(
- new MetaItem<>(LABEL, "Water levels of the plants")
+ new MetaItem<>(LABEL, "Water levels of the plants"),
+ new MetaItem<>(RULE_STATE, true)
)
);
apartment2Livingroom = assetStorageService.merge(apartment2Livingroom);
@@ -427,23 +436,28 @@ public class ManagerTestSetup extends AbstractManagerSetup {
new Attribute<>("motionSensor", BOOLEAN, false)
.addMeta(
new MetaItem<>(LABEL, "Motion Sensor"),
+ new MetaItem<>(RULE_STATE, true),
new MetaItem<>(RULE_EVENT, true)
),
new Attribute<>("presenceDetected", BOOLEAN, false)
.addMeta(
- new MetaItem<>(LABEL, "Presence Detected")
+ new MetaItem<>(LABEL, "Presence Detected"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("firstPresenceDetected", ValueType.TIMESTAMP)
.addMeta(
- new MetaItem<>(LABEL, "First Presence Timestamp")
+ new MetaItem<>(LABEL, "First Presence Timestamp"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lastPresenceDetected", ValueType.TIMESTAMP)
.addMeta(
- new MetaItem<>(LABEL, "Last Presence Timestamp")
+ new MetaItem<>(LABEL, "Last Presence Timestamp"),
+ new MetaItem<>(RULE_STATE, true)
),
new Attribute<>("lightSwitch", BOOLEAN, true)
.addMeta(
- new MetaItem<>(LABEL, "Light Switch")
+ new MetaItem<>(LABEL, "Light Switch"),
+ new MetaItem<>(RULE_STATE, true)
)
);
apartment2Bathroom = assetStorageService.merge(apartment2Bathroom);
diff --git a/model/src/main/java/org/openremote/model/asset/impl/ElectricVehicleAsset.java b/model/src/main/java/org/openremote/model/asset/impl/ElectricVehicleAsset.java
index a68f6fe96..97d39d34b 100644
--- a/model/src/main/java/org/openremote/model/asset/impl/ElectricVehicleAsset.java
+++ b/model/src/main/java/org/openremote/model/asset/impl/ElectricVehicleAsset.java
@@ -197,8 +197,14 @@ public class ElectricVehicleAsset extends ElectricityStorageAsset {
}
@Override
- public ElectricVehicleAsset setCarbonTotal(Integer value) {
- super.setCarbonTotal(value);
+ public ElectricVehicleAsset setCarbonImportTotal(Integer value) {
+ super.setCarbonImportTotal(value);
+ return this;
+ }
+
+ @Override
+ public ElectricVehicleAsset setCarbonExportTotal(Integer value) {
+ super.setCarbonExportTotal(value);
return this;
}
diff --git a/model/src/main/java/org/openremote/model/asset/impl/ElectricityAsset.java b/model/src/main/java/org/openremote/model/asset/impl/ElectricityAsset.java
index 8f9495dd6..ee49201b7 100644
--- a/model/src/main/java/org/openremote/model/asset/impl/ElectricityAsset.java
+++ b/model/src/main/java/org/openremote/model/asset/impl/ElectricityAsset.java
@@ -20,7 +20,6 @@
package org.openremote.model.asset.impl;
import org.openremote.model.asset.Asset;
-import org.openremote.model.asset.AssetDescriptor;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.value.*;
@@ -28,7 +27,6 @@ import java.util.Optional;
import static org.openremote.model.Constants.*;
-@SuppressWarnings("unchecked")
public abstract class ElectricityAsset<T extends ElectricityAsset<?>> extends Asset<T> {
public static final AttributeDescriptor<Double> POWER = new AttributeDescriptor<>("power", ValueType.POSITIVE_NUMBER,
@@ -80,7 +78,10 @@ public abstract class ElectricityAsset<T extends ElectricityAsset<?>> extends As
.withUnits(UNITS_KILO, UNITS_GRAM, UNITS_PER, UNITS_KILO, UNITS_WATT, UNITS_HOUR);
public static final AttributeDescriptor<Double> CARBON_EXPORT = new AttributeDescriptor<>("carbonExport", ValueType.POSITIVE_NUMBER)
.withUnits(UNITS_KILO, UNITS_GRAM, UNITS_PER, UNITS_KILO, UNITS_WATT, UNITS_HOUR);
- public static final AttributeDescriptor<Integer> CARBON_TOTAL = new AttributeDescriptor<>("carbonTotal", ValueType.POSITIVE_INTEGER,
+ public static final AttributeDescriptor<Integer> CARBON_IMPORT_TOTAL = new AttributeDescriptor<>("carbonImportTotal", ValueType.POSITIVE_INTEGER,
+ new MetaItem<>(MetaItemType.READ_ONLY, true)
+ ).withUnits(UNITS_KILO, UNITS_GRAM);
+ public static final AttributeDescriptor<Integer> CARBON_EXPORT_TOTAL = new AttributeDescriptor<>("carbonExportTotal", ValueType.POSITIVE_INTEGER,
new MetaItem<>(MetaItemType.READ_ONLY, true)
).withUnits(UNITS_KILO, UNITS_GRAM);
@@ -266,12 +267,21 @@ public abstract class ElectricityAsset<T extends ElectricityAsset<?>> extends As
return (T)this;
}
- public Optional<Integer> getCarbonTotal() {
- return getAttributes().getValue(CARBON_TOTAL);
+ public Optional<Integer> getCarbonImportTotal() {
+ return getAttributes().getValue(CARBON_IMPORT_TOTAL);
+ }
+
+ public T setCarbonImportTotal(Integer value) {
+ getAttributes().getOrCreate(CARBON_IMPORT_TOTAL).setValue(value);
+ return (T)this;
+ }
+
+ public Optional<Integer> getCarbonExportTotal() {
+ return getAttributes().getValue(CARBON_EXPORT_TOTAL);
}
- public T setCarbonTotal(Integer value) {
- getAttributes().getOrCreate(CARBON_TOTAL).setValue(value);
+ public T setCarbonExportTotal(Integer value) {
+ getAttributes().getOrCreate(CARBON_EXPORT_TOTAL).setValue(value);
return (T)this;
}
}
diff --git a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java
index f882662f1..28d050fcc 100644
--- a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java
+++ b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java
@@ -205,8 +205,14 @@ public class ElectricityProducerSolarAsset extends ElectricityProducerAsset {
}
@Override
- public ElectricityProducerSolarAsset setCarbonTotal(Integer value) {
- super.setCarbonTotal(value);
+ public ElectricityProducerSolarAsset setCarbonImportTotal(Integer value) {
+ super.setCarbonImportTotal(value);
+ return this;
+ }
+
+ @Override
+ public ElectricityProducerSolarAsset setCarbonExportTotal(Integer value) {
+ super.setCarbonExportTotal(value);
return this;
}
diff --git a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerWindAsset.java b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerWindAsset.java
index 11e32a968..2506108d9 100644
--- a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerWindAsset.java
+++ b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerWindAsset.java
@@ -156,8 +156,14 @@ public class ElectricityProducerWindAsset extends ElectricityProducerAsset {
}
@Override
- public ElectricityProducerWindAsset setCarbonTotal(Integer value) {
- super.setCarbonTotal(value);
+ public ElectricityProducerWindAsset setCarbonImportTotal(Integer value) {
+ super.setCarbonImportTotal(value);
+ return this;
+ }
+
+ @Override
+ public ElectricityProducerWindAsset setCarbonExportTotal(Integer value) {
+ super.setCarbonExportTotal(value);
return this;
}
diff --git a/model/src/main/java/org/openremote/model/value/MetaItemType.java b/model/src/main/java/org/openremote/model/value/MetaItemType.java
index 8a8c7996b..1d3104ce8 100644
--- a/model/src/main/java/org/openremote/model/value/MetaItemType.java
+++ b/model/src/main/java/org/openremote/model/value/MetaItemType.java
@@ -86,7 +86,8 @@ public final class MetaItemType {
/* DATA POINT META */
/**
- * Can be set to false to prevent attribute values being stored in time series database
+ * Can be set to false to prevent attribute values being stored in time series database; otherwise any attribute
+ * which also has an {@link #AGENT_LINK} meta item or {@link #STORE_DATA_POINTS} is set to true, will be stored.
*/
public static final MetaItemDescriptor<Boolean> STORE_DATA_POINTS = new MetaItemDescriptor<>("storeDataPoints", ValueType.BOOLEAN);
@@ -129,7 +130,8 @@ public final class MetaItemType {
/**
* Can be set to false to exclude an attribute update from being processed by the rules engines as {@link
- * AssetState} facts, with a lifecycle that reflects the state of the asset attribute. Each attribute will have one
+ * AssetState} facts, otherwise any attribute that also has an {@link #AGENT_LINK} meta item or {@link #RULE_STATE}
+ * is true, will be processed with a lifecycle that reflects the state of the asset attribute. Each attribute will have one
* fact at all times in rules memory. These state facts are kept in sync with asset changes: When the attribute is
* updated, the fact will be updated (replaced). If you want evaluate the change history of an attribute, you
* typically need to combine this with {@link #RULE_EVENT}.
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index fefccf615..b06fd14ad 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -82,10 +82,9 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assertRulesFired(rulesImport.tenantBuildingEngine, ["All"])
assertRulesFired(rulesImport.apartment2Engine, 1)
assertRulesFired(rulesImport.apartment2Engine, ["All"])
- assertRulesFired(rulesImport.apartment3Engine, 1)
- assertRulesFired(rulesImport.apartment3Engine, ["All"])
+ assertRulesFired(rulesImport.apartment3Engine, 0)
assertRulesFired(smartHomeEngine, 8)
- assertRulesFired(smartHomeEngine, ["Living Room All", "Kitchen All", "Kitchen Number Attributes", "Parent Type Residence", "Asset Type Room", "Boolean Attributes", "String attributes", "Number value types"])
+ assertRulesFired(smartHomeEngine, ["Living Room All", "Kitchen All", "Kitchen Number Attributes", "Parent Type Residence", "Asset Type Room", "Boolean attributes", "String attributes", "Number value types"])
}
when: "an attribute event occurs"
@@ -136,12 +135,15 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert noRuleEngineFiringScheduled()
}
- when: "a Kitchen room asset is inserted into apartment"
+ when: "a Kitchen room asset is inserted into apartment that contains a RULE_STATE = true meta flag"
def apartment2 = assetStorageService.find(managerTestSetup.apartment2Id)
def asset = new RoomAsset("Kitchen")
.setParent(apartment2)
.addOrReplaceAttributes(
new Attribute<>("testString", ValueType.TEXT, "test")
+ .addOrReplaceMeta(
+ new MetaItem<>(MetaItemType.RULE_STATE, true)
+ )
)
asset = assetStorageService.merge(asset)
@@ -156,11 +158,11 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "after a few seconds the engines in scope should have facts and rules should have fired"
conditions.eventually {
- assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 3
- assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 3
+ assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 1
+ assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 1
assert rulesImport.masterEngine.assetStates.size() == DEMO_RULE_STATES_SMART_OFFICE
- assert rulesImport.tenantBuildingEngine.assetStates.size() == DEMO_RULE_STATES_SMART_BUILDING + 3
- assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 3
+ assert rulesImport.tenantBuildingEngine.assetStates.size() == DEMO_RULE_STATES_SMART_BUILDING + 1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 1
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
assertRulesFired(rulesImport.globalEngine, 1)
assertRulesFired(rulesImport.globalEngine, ["All"])
@@ -170,8 +172,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assertRulesFired(rulesImport.tenantBuildingEngine, ["All"])
assertRulesFired(rulesImport.apartment2Engine, 1)
assertRulesFired(rulesImport.apartment2Engine, ["All"])
- assertRulesFired(rulesImport.apartment3Engine, 1)
- assertRulesFired(rulesImport.apartment3Engine, ["All"])
+ assertRulesFired(rulesImport.apartment3Engine, 0)
}
when: "time advances"
@@ -199,26 +200,29 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert apartment2LivingRoom.getAttribute("windowOpen").flatMap{it.getValueAs(Boolean.class)}.orElse(false)
}
- then: "the rules engines should have fired"
+ then: "the rules engines should not have fired"
conditions.eventually {
- assert rulesImport.globalEngine.lastFireTimestamp > globalLastFireTimestamp
+ assert rulesImport.globalEngine.lastFireTimestamp == globalLastFireTimestamp
assert rulesImport.masterEngine.lastFireTimestamp == masterLastFireTimestamp
- assert rulesImport.tenantBuildingEngine.lastFireTimestamp > tenantALastFireTimestamp
- assert rulesImport.apartment2Engine.lastFireTimestamp > apartment2LastFireTimestamp
+ assert rulesImport.tenantBuildingEngine.lastFireTimestamp == tenantALastFireTimestamp
+ assert rulesImport.apartment2Engine.lastFireTimestamp == apartment2LastFireTimestamp
assert rulesImport.apartment3Engine.lastFireTimestamp == apartment3LastFireTimestamp
}
when: "time advances"
advancePseudoClock(1, TimeUnit.SECONDS, container)
- and: "the Kitchen room asset is modified to add a new attribute"
+ and: "the Kitchen room asset is modified to add a new attribute but RULE_STATE = true meta is not changed"
globalLastFireTimestamp = rulesImport.globalEngine.lastFireTimestamp
masterLastFireTimestamp = rulesImport.masterEngine.lastFireTimestamp
tenantALastFireTimestamp = rulesImport.tenantBuildingEngine.lastFireTimestamp
apartment2LastFireTimestamp = rulesImport.apartment2Engine.lastFireTimestamp
apartment3LastFireTimestamp = rulesImport.apartment3Engine.lastFireTimestamp
asset.addOrReplaceAttributes(
- new Attribute<>("testString", ValueType.TEXT, "test"),
+ new Attribute<>("testString", ValueType.TEXT, "test")
+ .addOrReplaceMeta(
+ new MetaItem<>(MetaItemType.RULE_STATE, true)
+ ),
new Attribute<>("testInteger", ValueType.NUMBER, 0d)
)
asset = assetStorageService.merge(asset)
@@ -234,20 +238,20 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "no rules should have fired"
conditions.eventually {
- assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 4
- assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 4
+ assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 1
+ assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 1
assert rulesImport.masterEngine.assetStates.size() == DEMO_RULE_STATES_SMART_OFFICE
- assert rulesImport.tenantBuildingEngine.assetStates.size() == DEMO_RULE_STATES_SMART_BUILDING + 4
- assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 4
+ assert rulesImport.tenantBuildingEngine.assetStates.size() == DEMO_RULE_STATES_SMART_BUILDING + 1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 1
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
assertRulesFired(rulesImport.globalEngine, 1)
assertRulesFired(rulesImport.masterEngine, 1)
assertRulesFired(rulesImport.tenantBuildingEngine, 1)
assertRulesFired(rulesImport.apartment2Engine, 1)
- assertRulesFired(rulesImport.apartment3Engine, 1)
+ assertRulesFired(rulesImport.apartment3Engine, 0)
}
- when: "the Kitchen room asset is modified to set the RULE_STATE to false on one attribute"
+ when: "the Kitchen room asset is modified to set the RULE_STATE to false"
rulesImport.resetRulesFired()
asset.addOrReplaceAttributes(
new Attribute<>("testString", ValueType.TEXT, "test")
@@ -260,11 +264,11 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "the facts should be removed from the rule engines and rules should have fired"
conditions.eventually {
- assert rulesService.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 3
- assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 3
+ 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.tenantBuildingEngine.assetStates.size() == DEMO_RULE_STATES_SMART_BUILDING + 3
- assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 3
+ assert rulesImport.tenantBuildingEngine.assetStates.size() == DEMO_RULE_STATES_SMART_BUILDING
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
assertRulesFired(rulesImport.globalEngine, 1)
assertRulesFired(rulesImport.globalEngine, ["All"])
@@ -275,16 +279,16 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assertRulesFired(rulesImport.apartment3Engine, 0)
}
- when: "the Kitchen room asset is modified to set all attributes to RULE_STATE = false"
+ when: "the Kitchen room asset is modified to set all attributes to RULE_STATE = true"
rulesImport.resetRulesFired()
asset.addOrReplaceAttributes(
new Attribute<>("testString", ValueType.TEXT, "test")
.addOrReplaceMeta(
- new MetaItem<>(MetaItemType.RULE_STATE, false)
+ new MetaItem<>(MetaItemType.RULE_STATE, true)
),
new Attribute<>("testInteger", ValueType.NUMBER, 0d)
.addOrReplaceMeta(
- new MetaItem<>(MetaItemType.RULE_STATE, false)
+ new MetaItem<>(MetaItemType.RULE_STATE, true)
)
)
asset = assetStorageService.merge(asset)