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
Minor: removed obsolete Agent class
Rich Turner4fb3ef84e807
diff --git a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.javaindex ba907b2d2..56ad6b048 100644--- a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java+++ b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java@@ -164,8 +164,7 @@ public interface ProtocolAssetService extends ContainerService {Value applyValueFilters(Value value, ValueFilter<?>... filters);/**- * Subscribe to changes of {@link Asset}s that are descendants of the specified- * {@link org.openremote.model.asset.agent.Agent}.+ * Subscribe to changes of {@link Asset}s that are descendants of the specified agent.* <p>* When an agent is unlinked from a protocol then all subscriptions will be automatically removed also; it is safe* to call this method multiple times for the same agentId and assetChangeConsumer and only a single subscriptiondiff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.javaindex b0fa48e98..bc84f46e6 100644--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java@@ -859,7 +859,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Assereturn Optional.empty();}- return !Agent.hasUrl(agent) ? Optional.of(localAgentConnector) : Optional.empty();+ return Optional.of(localAgentConnector);}protected boolean addReplaceAgent(Asset agent) {diff --git a/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java b/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.javaindex 12391ca3e..87aba95c3 100644--- a/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java+++ b/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java@@ -36,6 +36,7 @@ import java.util.*;import java.util.logging.Logger;import java.util.stream.Collectors;+@Deprecatedpublic class LocalAgentConnector implements AgentConnector {private static final Logger LOG = Logger.getLogger(LocalAgentConnector.class.getName());@@ -51,7 +52,8 @@ public class LocalAgentConnector implements AgentConnector {.filter(entry -> entry.getKey().equals(agent.getId())).map(Map.Entry::getValue).findFirst();- return foundAgent.map(asset -> Agent.getProtocolConfigurations(asset).stream()+ return foundAgent.map(asset -> asset.getAttributesStream()+ .filter(ProtocolConfiguration::isProtocolConfiguration).map(AssetAttribute::getReferenceOrThrow).map(protocolConfigurationRef -> new Pair<>(protocolConfigurationRef, agentService.getProtocolConnectionStatus(protocolConfigurationRef))).map(pair -> new AgentStatusEvent(@@ -60,7 +62,7 @@ public class LocalAgentConnector implements AgentConnector {pair.key,pair.value))- .collect(Collectors.toList())).orElseGet(ArrayList::new);+ .collect(Collectors.toList())).orElse(Collections.emptyList());}@Overridediff --git a/model/src/main/java/org/openremote/model/Constants.java b/model/src/main/java/org/openremote/model/Constants.javaindex d876208f4..219fe9459 100644--- a/model/src/main/java/org/openremote/model/Constants.java+++ b/model/src/main/java/org/openremote/model/Constants.java@@ -49,6 +49,7 @@ public interface Constants {String NAMESPACE = "urn:openremote";String PROTOCOL_NAMESPACE = NAMESPACE + ":protocol";String ASSET_NAMESPACE = NAMESPACE + ":asset";+ String AGENT_ASSET_NAMESPACE = ASSET_NAMESPACE + ":agent";String ASSET_META_NAMESPACE = ASSET_NAMESPACE + ":meta";String DEFAULT_DATETIME_FORMAT ="dd. MMM yyyy HH:mm:ss zzz";String DEFAULT_DATETIME_FORMAT_MILLIS ="dd. MMM yyyy HH:mm:ss:SSS zzz";diff --git a/model/src/main/java/org/openremote/model/asset/agent/Agent.java b/model/src/main/java/org/openremote/model/asset/agent/Agent.javadeleted file mode 100644index daa756b4c..000000000--- a/model/src/main/java/org/openremote/model/asset/agent/Agent.java+++ /dev/null@@ -1,124 +0,0 @@-/*- * 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.asset.agent;--import org.openremote.model.AbstractValueHolder;-import org.openremote.model.asset.Asset;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetType;-import org.openremote.model.attribute.AttributeValueType;-import org.openremote.model.security.UserPasswordCredentials;-import org.openremote.model.value.Values;--import java.util.Collections;-import java.util.List;-import java.util.Objects;-import java.util.Optional;-import java.util.stream.Collectors;--import static org.openremote.model.util.TextUtil.isNullOrEmpty;--/**- * An agent is a special type of {@link Asset} with an AssetType of {@link AssetType#AGENT}.- * <p>- * If the agent doesn't have an attribute with the name {@link #URL_ATTRIBUTE_NAME} then it is assumed that the agent is- * running in the current VM (i.e. a local agent).- * <p>- * Currently only local agents are supported.- */-public final class Agent {-- protected static final String URL_ATTRIBUTE_NAME = "url";- protected static final String CREDENTIALS_ATTRIBUTE_NAME = "credentials";- protected Asset asset;-- private Agent() {- }-- public static void initAgent(Asset asset) {- asset.setType(AssetType.AGENT);- }-- public static boolean hasUrl(Asset asset) {- return asset != null && asset- .getAttribute(URL_ATTRIBUTE_NAME)- .flatMap(AbstractValueHolder::getValueAsString)- .isPresent();- }-- public static Optional<String> getUrl(Asset asset) {- return asset == null ? Optional.empty() : asset- .getAttribute(URL_ATTRIBUTE_NAME)- .flatMap(AbstractValueHolder::getValueAsString);- }-- public static void setUrl(Asset asset, String url) {- if (asset != null) {- if (isNullOrEmpty(url)) {- asset.removeAttribute(URL_ATTRIBUTE_NAME);- } else {- asset.replaceAttribute(new AssetAttribute(URL_ATTRIBUTE_NAME, AttributeValueType.STRING, Values.create(url)));- }- }- }-- public static boolean hasCredentials(Asset asset) {- return asset != null && asset- .getAttribute(CREDENTIALS_ATTRIBUTE_NAME)- .filter(UserPasswordCredentials::isUserPasswordCredentials)- .isPresent();- }-- public static Optional<UserPasswordCredentials> getCredentials(Asset asset) {- return asset == null ? Optional.empty() : asset- .getAttribute(CREDENTIALS_ATTRIBUTE_NAME)- .flatMap(AbstractValueHolder::getValueAsObject)- .flatMap(UserPasswordCredentials::fromValue);- }-- public static void setCredentials(Asset asset, UserPasswordCredentials credentials) {- if (asset != null) {- if (Objects.isNull(credentials)) {- asset.removeAttribute(CREDENTIALS_ATTRIBUTE_NAME);- } else {- asset.replaceAttribute(new AssetAttribute(CREDENTIALS_ATTRIBUTE_NAME, AttributeValueType.OBJECT, credentials.toObjectValue()));- }- }- }-- public static Optional<AssetAttribute> getProtocolConfiguration(Asset asset, String protocolConfigurationName) {- if (asset == null || isNullOrEmpty(protocolConfigurationName)) {- return Optional.empty();- }-- return asset.getAttribute(protocolConfigurationName)- .filter(ProtocolConfiguration::isProtocolConfiguration);- }-- public static List<AssetAttribute> getProtocolConfigurations(Asset asset) {- if (asset == null) {- return Collections.emptyList();- }-- return asset.getAttributesStream()- .filter(ProtocolConfiguration::isProtocolConfiguration)- .collect(Collectors.toList());- }-}diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java b/model/src/main/java/org/openremote/model/asset/agent/AgentResource.javaindex 1f534efd2..c387c244f 100644--- a/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java@@ -120,7 +120,7 @@ public interface AgentResource {);/**- * Get discovered linked attributes for the specified {@link org.openremote.model.asset.agent.Agent}+ * Get discovered linked attributes for the specified Agent* and {@link org.openremote.model.asset.agent.ProtocolConfiguration}.* <p>* Currently this request will automatically add the found {@link Asset}s to the DB as well as returning@@ -142,7 +142,7 @@ public interface AgentResource {);/**- * Get discovered linked attributes for the specified {@link org.openremote.model.asset.agent.Agent}+ * Get discovered linked attributes for the specified Agent* and {@link org.openremote.model.asset.agent.ProtocolConfiguration} using the supplied {@link FileInfo}.* <p>* Currently this request will automatically add the found {@link Asset}s to the DB as well as returning