Skip to content

armgit / core

Public Imported from GitHub
0

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

Resolves Store outdated attribute events in the asset_datapoint table (#1643)

Rich Turnerbc5b4dba0588
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 8159569ed..0b8fcf384 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -2,6 +2,7 @@ package org.openremote.manager.datapoint;
import org.openremote.agent.protocol.ProtocolDatapointService;
import org.openremote.container.timer.TimerService;
+import org.openremote.manager.asset.OutdatedAttributeEvent;
import org.openremote.model.datapoint.DatapointQueryTooLargeException;
import org.openremote.model.util.UniqueIdentifierGenerator;
import org.openremote.manager.asset.AssetProcessingException;
@@ -111,6 +112,7 @@ public class AssetDatapointService extends AbstractDatapointService<AssetDatapoi
ClientEventService clientEventService = container.getService(ClientEventService.class);
clientEventService.addSubscription(AttributeEvent.class, null, this::onAttributeEvent);
+ clientEventService.addSubscription(OutdatedAttributeEvent.class, null, this::onOutdatedAttributeEvent);
}
public static boolean attributeIsStoreDatapoint(MetaHolder attributeInfo) {
@@ -127,6 +129,11 @@ public class AssetDatapointService extends AbstractDatapointService<AssetDatapoi
}
}
+ public void onOutdatedAttributeEvent(OutdatedAttributeEvent outdatedAttributeEvent) {
+ // Store the outdated event for historical analysis
+ onAttributeEvent(outdatedAttributeEvent.getEvent());
+ }
+
@Override
protected Class<AssetDatapoint> getDatapointClass() {
return AssetDatapoint.class;
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy
index 917e0e4df..69ea0ec89 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy
@@ -260,6 +260,26 @@ class AssetDatapointTest extends Specification implements ManagerContainerTrait
assert aggregatedDatapoints[60].value == 0
}
+ // ------------------------------------
+ // Test logging of outdated data points
+ // ------------------------------------
+
+ when: "a simulated sensor receives a new outdated value"
+ simulatorProtocol.updateSensor(new AttributeRef(managerTestSetup.thingId, thingLightToggleAttributeName), true, getClockTimeOf(container)-5000)
+
+ then: "the datapoint should be stored"
+ conditions.eventually {
+ def datapoints = assetDatapointService.getDatapoints(new AttributeRef(managerTestSetup.thingId, thingLightToggleAttributeName))
+ assert datapoints.any {it.timestamp == getClockTimeOf(container)-5000 && (it.value as Boolean)}
+ }
+
+ and: "the attribute should not be updated"
+ conditions.eventually {
+ def thing = assetStorageService.find(managerTestSetup.thingId, true)
+ assert !thing.getAttribute(thingLightToggleAttributeName).flatMap { it.getValue(Boolean.class) }.orElse(true)
+ assert thing.getAttribute(thingLightToggleAttributeName).flatMap {it.getTimestamp()}.orElse(0) == getClockTimeOf(container)
+ }
+
// ------------------------------------
// Test purging of data points
// ------------------------------------