100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Optional read all attributes with ReadAttributesEvent
Christian Bauer7361f5bb356a
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.javaindex 782f06d31..4892955f0 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java@@ -154,10 +154,7 @@ public abstract class AttributesBrowserprotected void readAllAttributeValues() {environment.getEventService().dispatch(- new ReadAttributesEvent(- asset.getId(),- attributeGroups.keySet().stream().map(Attribute::getName).collect(Collectors.toList())- )+ new ReadAttributesEvent(asset.getId()));}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.javaindex e98fdb3aa..2ed25551f 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@@ -157,7 +157,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (auth.isSuperUser()) {ServerAsset asset = find(event.getEntityId(), true);if (asset != null)- replyWithAttributeEvents(sessionKey, asset, Arrays.asList(event.getAttributeNames()));+ replyWithAttributeEvents(sessionKey, asset, event.getAttributeNames());return;}@@ -171,8 +171,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServictrue,managerIdentityService.isRestrictedUser(auth.getUserId()) // Restricted users get filtered state);- if (asset != null)- replyWithAttributeEvents(sessionKey, asset, Arrays.asList(event.getAttributeNames()));+ if (asset != null) {+ replyWithAttributeEvents(sessionKey, asset, event.getAttributeNames());+ }});}@@ -677,12 +678,20 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic}}- protected void replyWithAttributeEvents(String sessionKey, ServerAsset asset, List<String> attributeNames) {- LOG.fine("For client session '" + sessionKey + "', reading asset attributes " + attributeNames + " on: " + asset);- List<AttributeEvent> events = new AssetAttributes(asset).get().stream()- .filter(assetAttribute -> attributeNames.contains(assetAttribute.getName()))+ protected void replyWithAttributeEvents(String sessionKey, ServerAsset asset, String[] attributeNames) {+ AssetAttributes attributes = new AssetAttributes(asset);++ // Client may want to read a subset or all attributes of the asset+ List<String> names = attributeNames != null && attributeNames.length > 0+ ? Arrays.asList(attributeNames)+ : attributes.names();++ LOG.fine("For client session '" + sessionKey + "', reading asset attributes " + names + " on: " + asset);+ List<AttributeEvent> events = attributes.get().stream()+ .filter(assetAttribute -> names.contains(assetAttribute.getName())).map(AbstractAssetAttribute::getStateEvent).collect(Collectors.toList());+eventService.sendToSession(sessionKey, events.toArray(new AttributeEvent[events.size()]));}diff --git a/model/src/main/java/org/openremote/model/ReadAttributesEvent.java b/model/src/main/java/org/openremote/model/ReadAttributesEvent.javaindex 3ed35e599..e13d12123 100644--- a/model/src/main/java/org/openremote/model/ReadAttributesEvent.java+++ b/model/src/main/java/org/openremote/model/ReadAttributesEvent.java@@ -22,7 +22,6 @@ package org.openremote.model;import org.openremote.model.event.shared.SharedEvent;import java.util.Arrays;-import java.util.List;/*** A client sends this event to the server to refresh its attribute state, expecting@@ -30,6 +29,9 @@ import java.util.List;* decides that the client doesn't have the right permissions, or if anything* else is not in order (e.g. the entity doesn't exist), the server might not react* at all.+ * <p>+ * If no attribute names and only an entity identifier are provided, all attributes+ * of the entity, accessible by the client, will be read/returned.*/public class ReadAttributesEvent extends SharedEvent {@@ -45,10 +47,6 @@ public class ReadAttributesEvent extends SharedEvent {this.attributeNames = attributeNames;}- public ReadAttributesEvent(String entityId, List<String> attributeNames) {- this(entityId, attributeNames.toArray(new String[attributeNames.size()]));- }-public String getEntityId() {return entityId;}