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
Bug fix for AgentService link/unlink protocol configuration
Rich Turner84d4d467944e
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.javaindex e7da4a917..0f5c5fe91 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@@ -33,11 +33,13 @@ import org.openremote.manager.server.datapoint.AssetDatapointService;import org.openremote.model.AbstractValueTimestampHolder;import org.openremote.model.AttributeRef;import org.openremote.model.asset.*;+import org.openremote.model.asset.agent.AgentLink;import org.openremote.model.util.JsonUtil;import java.util.*;import java.util.function.Consumer;import java.util.function.Function;+import java.util.function.Predicate;import java.util.logging.Level;import java.util.logging.Logger;import java.util.stream.Collectors;@@ -208,7 +210,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons// Link any AGENT_LINK attributes to the referenced protocolMap<AssetAttribute, List<AssetAttribute>> groupedAgentLinksAttributes =- getGroupedAgentLinkAttributes(asset.getAttributeStream());+ getGroupedAgentLinkAttributes(asset.getAttributeStream(), null);groupedAgentLinksAttributes.forEach(this::linkAttributes);break;@@ -245,7 +247,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons));- getGroupedAgentLinkAttributes(attributesToUnlink)+ getGroupedAgentLinkAttributes(attributesToUnlink, null).forEach(this::unlinkAttributes);// Link thing attributes that are in new but not in old@@ -260,7 +262,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons));- getGroupedAgentLinkAttributes(attributesToLink)+ getGroupedAgentLinkAttributes(attributesToLink, null).forEach(this::linkAttributes);break;@@ -268,7 +270,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons// Unlink any AGENT_LINK attributes from the referenced protocolMap<AssetAttribute, List<AssetAttribute>> groupedAgentLinkAndProtocolAttributes =- getGroupedAgentLinkAttributes(asset.getAttributeStream());+ getGroupedAgentLinkAttributes(asset.getAttributeStream(), null);groupedAgentLinkAndProtocolAttributes.forEach(this::unlinkAttributes@@ -303,7 +305,10 @@ public class AgentService extends RouteBuilder implements ContainerService, Consassets.forEach(asset ->- getGroupedAgentLinkAttributes(asset.getAttributeStream())+ getGroupedAgentLinkAttributes(+ asset.getAttributeStream(),+ assetAttribute -> AgentLink.getAgentLink().apply(assetAttribute).equals(protocolAttributeRef)+ ).forEach(this::linkAttributes));}@@ -326,7 +331,10 @@ public class AgentService extends RouteBuilder implements ContainerService, Consassets.forEach(asset ->- getGroupedAgentLinkAttributes(asset.getAttributeStream())+ getGroupedAgentLinkAttributes(+ asset.getAttributeStream(),+ assetAttribute -> AgentLink.getAgentLink().apply(assetAttribute).equals(protocolAttributeRef)+ ).forEach(this::unlinkAttributes));@@ -432,21 +440,23 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons/*** Gets all agent link attributes and their linked protocol configuration and groups them by Protocol Configuration*/- protected Map<AssetAttribute, List<AssetAttribute>> getGroupedAgentLinkAttributes(Stream<AssetAttribute> attributes) {+ protected Map<AssetAttribute, List<AssetAttribute>> getGroupedAgentLinkAttributes(Stream<AssetAttribute> attributes, Predicate<AssetAttribute> filter) {Map<AssetAttribute, List<AssetAttribute>> map = new HashMap<>();attributes.filter(isValidAgentLink()).forEach(agentLinkAttribute -> {- AttributeRef protocolRef = getAgentLink().apply(agentLinkAttribute);- AssetAttribute protocolConfiguration = protocolConfigurationResolver.apply(protocolRef);-- if (protocolConfiguration == null) {- LOG.warning("Invalid agent link '" + protocolRef + "' on attribute '" + agentLinkAttribute.getReference() + "'");- } else {- map.computeIfAbsent(protocolConfiguration, newProtocolConfiguration -> new ArrayList<>())- .add(agentLinkAttribute);+ if (filter == null || filter.test(agentLinkAttribute)) {+ AttributeRef protocolRef = getAgentLink().apply(agentLinkAttribute);+ AssetAttribute protocolConfiguration = protocolConfigurationResolver.apply(protocolRef);++ if (protocolConfiguration == null) {+ LOG.warning("Invalid agent link '" + protocolRef + "' on attribute '" + agentLinkAttribute.getReference() + "'");+ } else {+ map.computeIfAbsent(protocolConfiguration, newProtocolConfiguration -> new ArrayList<>())+ .add(agentLinkAttribute);+ }}});return map;