Skip to content

armgit / core

Public Imported from GitHub
0

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

Fixed error with AssetEvent not matching with the filter in subcriptions

Michael Rademakerc09090c49535
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
index 76455172c..9c18feffe 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
@@ -45,6 +45,7 @@ import org.openremote.model.datapoint.AssetDatapointResource;
import org.openremote.model.datapoint.Datapoint;
import org.openremote.model.datapoint.DatapointInterval;
import org.openremote.model.datapoint.NumberDatapoint;
+import org.openremote.model.event.shared.SharedEventWithAssetId;
import org.openremote.model.event.shared.TenantFilter;
import org.openremote.model.interop.Consumer;
import org.openremote.model.map.MapResource;
@@ -186,7 +187,7 @@ public class AssetViewActivity
protected void subscribeLiveUpdates(boolean subscribe) {
if (subscribe) {
environment.getEventService().subscribe(
- AttributeEvent.class,
+ SharedEventWithAssetId.class,
new AssetEvent.AssetIdFilter(asset.getId())
);
} else {
diff --git a/client/src/main/java/org/openremote/app/client/map/MapActivity.java b/client/src/main/java/org/openremote/app/client/map/MapActivity.java
index b42a3fbcd..c90bae5de 100644
--- a/client/src/main/java/org/openremote/app/client/map/MapActivity.java
+++ b/client/src/main/java/org/openremote/app/client/map/MapActivity.java
@@ -40,6 +40,7 @@ import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.AttributeValueType;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
+import org.openremote.model.event.shared.SharedEventWithAssetId;
import org.openremote.model.geo.GeoJSON;
import org.openremote.model.map.MapResource;
import org.openremote.model.value.Values;
@@ -180,7 +181,7 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapV
if (asset.hasGeoFeature() || dashboardAttributes.size() > 0) {
showAssetInfoItems();
environment.getEventService().subscribe(
- AttributeEvent.class,
+ SharedEventWithAssetId.class,
new AssetEvent.AssetIdFilter(asset.getId())
);
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetEvent.java b/model/src/main/java/org/openremote/model/asset/AssetEvent.java
index ee6be575e..8ce3f24a6 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetEvent.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetEvent.java
@@ -19,9 +19,8 @@
*/
package org.openremote.model.asset;
-import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.event.shared.EventFilter;
-import org.openremote.model.event.shared.SharedEvent;
+import org.openremote.model.event.shared.SharedEventWithAssetId;
import java.util.Arrays;
@@ -31,9 +30,9 @@ import java.util.Arrays;
* the {@link org.openremote.model.attribute.AttributeEvent}. When the cause is {@link Cause#READ} then the asset's
* {@link org.openremote.model.attribute.Attribute}s will be included in the asset otherwise they are not.
*/
-public class AssetEvent extends SharedEvent {
+public class AssetEvent extends SharedEventWithAssetId {
- public static class AssetIdFilter extends EventFilter<AttributeEvent> {
+ public static class AssetIdFilter extends EventFilter<SharedEventWithAssetId> {
public static final String FILTER_TYPE = "asset-id";
@@ -56,7 +55,7 @@ public class AssetEvent extends SharedEvent {
}
@Override
- public boolean apply(AttributeEvent event) {
+ public boolean apply(SharedEventWithAssetId event) {
return Arrays.asList(assetIds).contains(event.getEntityId());
}
@@ -86,6 +85,10 @@ public class AssetEvent extends SharedEvent {
this.updatedProperties = updatedProperties;
}
+ public String getEntityId() {
+ return asset.id;
+ }
+
public Cause getCause() {
return cause;
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java b/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java
index a29a4383a..0d999390c 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java
@@ -19,7 +19,7 @@
*/
package org.openremote.model.attribute;
-import org.openremote.model.event.shared.SharedEvent;
+import org.openremote.model.event.shared.SharedEventWithAssetId;
import org.openremote.model.value.Value;
import java.util.Objects;
@@ -28,7 +28,7 @@ import java.util.Optional;
/**
* A timestamped {@link AttributeState}.
*/
-public class AttributeEvent extends SharedEvent {
+public class AttributeEvent extends SharedEventWithAssetId {
public static final String HEADER_SOURCE = AttributeEvent.class.getName() + ".SOURCE";
diff --git a/model/src/main/java/org/openremote/model/event/shared/SharedEventWithAssetId.java b/model/src/main/java/org/openremote/model/event/shared/SharedEventWithAssetId.java
new file mode 100644
index 000000000..3bc0779f8
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/event/shared/SharedEventWithAssetId.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.event.shared;
+
+public abstract class SharedEventWithAssetId extends SharedEvent {
+
+ public SharedEventWithAssetId() {
+ }
+
+ public SharedEventWithAssetId(long timestamp) {
+ super(timestamp);
+ }
+
+ public abstract String getEntityId();
+}