Skip to content

armgit / core

Public Imported from GitHub
0

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

Various protocol bug fixes and improvements (mainly for HTTP Client protocol)

Rich Turner3f356f8ecd50
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
index e5fe3d81c..0201499a8 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -113,12 +113,28 @@ public abstract class AbstractProtocol implements Protocol {
protected final Map<AttributeRef, LinkedProtocolInfo> linkedProtocolConfigurations = new HashMap<>();
protected final Map<AttributeRef, List<MessageFilter>> linkedAttributeFilters = new HashMap<>();
protected final List<AttributeRef> locationLinkedAttributes = new ArrayList<>();
+ protected static final List<MetaItemDescriptor> attributeMetaItemDescriptors;
protected MessageBrokerContext messageBrokerContext;
protected ProducerTemplate producerTemplate;
protected TimerService timerService;
protected ProtocolExecutorService executorService;
protected ProtocolAssetService assetService;
+ static {
+ attributeMetaItemDescriptors = Arrays.asList(
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_FILTERS",
+ META_PROTOCOL_FILTERS,
+ ValueType.ARRAY,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false)
+ );
+ }
+
@Override
public void init(Container container) throws Exception {
LOG.info("Initializing protocol: " + getProtocolName());
@@ -326,12 +342,28 @@ public abstract class AbstractProtocol implements Protocol {
LOG.fine("Applying message filters to sensor value...");
for (MessageFilter filter : filters) {
- if (filter.getMessageType() != value.getType().getModelType()) {
- LOG.fine("Message filter type '" + filter.getMessageType().getName()
- + "' is not compatible with actual message type '" + value.getType().getModelType().getName()
- + "': " + filter.getClass().getName());
- value = null;
- } else {
+ boolean filterOk = filter.getMessageType() == value.getType().getModelType();
+
+ if (!filterOk) {
+ // Try and convert the value
+ ValueType filterValueType = ValueType.fromModelType(filter.getMessageType());
+ if (filterValueType == null) {
+ LOG.fine("Message filter type unknown: " + filter.getMessageType().getName());
+ value = null;
+ } else {
+ Optional<Value> val = Values.convert(value, filterValueType);
+ if (!val.isPresent()) {
+ LOG.fine("Message filter type '" + filter.getMessageType().getName()
+ + "' is not compatible with actual message type '" + value.getType().getModelType().getName()
+ + "': " + filter.getClass().getName());
+ } else {
+ filterOk = true;
+ }
+ value = val.orElse(null);
+ }
+ }
+
+ if (filterOk) {
try {
LOG.finest("Applying message filter: " + filter.getClass().getName());
value = filter.process(value);
@@ -506,12 +538,20 @@ public abstract class AbstractProtocol implements Protocol {
'}';
}
+ /**
+ * Get list of {@link MetaItemDescriptor}s that describe the {@link MetaItem}s a {@link ProtocolConfiguration} for this
+ * protocol supports
+ */
protected List<MetaItemDescriptor> getProtocolConfigurationMetaItemDescriptors() {
return Collections.emptyList();
}
+ /**
+ * Get list of {@link MetaItemDescriptor}s that describe the {@link MetaItem}s an {@link Attribute} linked to this
+ * protocol supports
+ */
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
- return Collections.emptyList();
+ return attributeMetaItemDescriptors;
}
/**
diff --git a/agent/src/main/java/org/openremote/agent/protocol/filter/JsonFilter.java b/agent/src/main/java/org/openremote/agent/protocol/filter/JsonFilter.java
new file mode 100644
index 000000000..1bb793474
--- /dev/null
+++ b/agent/src/main/java/org/openremote/agent/protocol/filter/JsonFilter.java
@@ -0,0 +1,88 @@
+/*
+ * 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.agent.protocol.filter;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.openremote.model.util.TextUtil;
+import org.openremote.model.value.*;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import static org.openremote.agent.protocol.filter.RegexFilter.NAME;
+
+@JsonTypeName(NAME)
+public class JsonFilter extends MessageFilter<ObjectValue> {
+
+ public static final String NAME = "json";
+
+ @JsonProperty
+ protected List<String> path;
+
+ @JsonCreator
+ public JsonFilter(@JsonProperty("path") List<String> path) {
+ this.path = path;
+ }
+
+ public JsonFilter(String... path) {
+ this(Arrays.asList(path));
+ }
+
+ @Override
+ public Class<ObjectValue> getMessageType() {
+ return ObjectValue.class;
+ }
+
+ @Override
+ public Value process(ObjectValue value) {
+ if (value == null || path == null || path.isEmpty()) {
+ return null;
+ }
+
+ Value currentValue = value;
+ for (int i = 0; i < path.size(); i++) {
+ String pathSegment = path.get(i);
+ if (currentValue == null || TextUtil.isNullOrEmpty(pathSegment)) {
+ return null;
+ }
+
+ if (TextUtil.INTEGER_POSITIVE_VALIDATOR.test(pathSegment)) {
+ // Check value is an array
+ if (currentValue.getType() != ValueType.ARRAY) {
+ // Integer key requires an array value
+ return null;
+ }
+ currentValue = ((ArrayValue)currentValue).get(Integer.parseInt(pathSegment)).orElse(null);
+ } else {
+ if (currentValue.getType() != ValueType.OBJECT) {
+ return null;
+ }
+ currentValue = ((ObjectValue)currentValue).get(pathSegment).orElse(null);
+ }
+ }
+
+ return currentValue;
+ }
+}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/filter/MessageFilter.java b/agent/src/main/java/org/openremote/agent/protocol/filter/MessageFilter.java
index ab96c4718..4f5eab2a4 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/filter/MessageFilter.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/filter/MessageFilter.java
@@ -43,7 +43,8 @@ import java.util.Optional;
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(name = RegexFilter.NAME, value = RegexFilter.class),
- @JsonSubTypes.Type(name = SubStringFilter.NAME, value = SubStringFilter.class)
+ @JsonSubTypes.Type(name = SubStringFilter.NAME, value = SubStringFilter.class),
+ @JsonSubTypes.Type(name = JsonFilter.NAME, value = JsonFilter.class)
})
public abstract class MessageFilter<T extends Value> {
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java
index e8c80fc11..290f3b005 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java
@@ -24,6 +24,8 @@ import org.openremote.agent.protocol.AbstractProtocol;
import org.openremote.agent.protocol.Protocol;
import org.openremote.container.Container;
import org.openremote.model.AbstractValueHolder;
+import org.openremote.model.ValidationFailure;
+import org.openremote.model.ValueHolder;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
import org.openremote.model.asset.agent.ConnectionStatus;
@@ -42,10 +44,7 @@ import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -55,6 +54,7 @@ import java.util.logging.Logger;
import static org.openremote.container.concurrent.GlobalLock.withLock;
import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
+import static org.openremote.model.util.TextUtil.*;
/**
* This is a HTTP client protocol for communicating with HTTP servers; it uses the {@link WebTargetBuilder} factory to
@@ -380,6 +380,234 @@ public class HttpClientProtocol extends AbstractProtocol {
*/
public static final String META_QUERY_PARAMETERS = PROTOCOL_NAME + ":queryParameters";
+ protected static final List<MetaItemDescriptorImpl> PROTOCOL_META_ITEM_DESCRIPTORS = Arrays.asList(
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_BASE_URI",
+ META_PROTOCOL_BASE_URI,
+ ValueType.STRING,
+ true,
+ REGEXP_PATTERN_BASIC_HTTP_URL,
+ MetaItemDescriptor.PatternFailure.HTTP_URL.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_USERNAME",
+ META_PROTOCOL_USERNAME,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY_NO_WHITESPACE,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY_OR_CONTAINS_WHITESPACE.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PASSWORD",
+ META_PROTOCOL_PASSWORD,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY_NO_WHITESPACE,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY_OR_CONTAINS_WHITESPACE.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_OAUTH",
+ META_PROTOCOL_OAUTH_GRANT,
+ ValueType.OBJECT,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PING_PATH",
+ META_PROTOCOL_PING_PATH,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PING_METHOD",
+ META_PROTOCOL_PING_METHOD,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PING_BODY",
+ META_PROTOCOL_PING_BODY,
+ null,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PING_CONTENT_TYPE",
+ META_PROTOCOL_PING_CONTENT_TYPE,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PING_SECONDS",
+ META_PROTOCOL_PING_SECONDS,
+ ValueType.NUMBER,
+ false,
+ REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO,
+ MetaItemDescriptor.PatternFailure.INTEGER_POSITIVE_NON_ZERO.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PING_QUERY_PARAMETERS",
+ META_PROTOCOL_PING_QUERY_PARAMETERS,
+ ValueType.OBJECT,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_FOLLOW_REDIRECTS",
+ META_PROTOCOL_FOLLOW_REDIRECTS,
+ ValueType.BOOLEAN,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_QUERY_PARAMETERS",
+ META_QUERY_PARAMETERS,
+ ValueType.OBJECT,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_HEADERS",
+ META_QUERY_PARAMETERS,
+ ValueType.OBJECT,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_FAILURE_CODES",
+ META_FAILURE_CODES,
+ ValueType.ARRAY,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false)
+ );
+
+
+ public static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Arrays.asList(
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_PATH",
+ META_ATTRIBUTE_PATH,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_METHOD",
+ META_ATTRIBUTE_METHOD,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_BODY",
+ META_ATTRIBUTE_BODY,
+ null,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_CONTENT_TYPE",
+ META_ATTRIBUTE_CONTENT_TYPE,
+ ValueType.STRING,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_POLLING_SECONDS",
+ META_ATTRIBUTE_POLLING_SECONDS,
+ ValueType.NUMBER,
+ false,
+ REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO,
+ MetaItemDescriptor.PatternFailure.INTEGER_POSITIVE_NON_ZERO.name(),
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_QUERY_PARAMETERS",
+ META_QUERY_PARAMETERS,
+ ValueType.OBJECT,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_HEADERS",
+ META_QUERY_PARAMETERS,
+ ValueType.OBJECT,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false),
+ new MetaItemDescriptorImpl(
+ "PROTOCOL_HTTP_CLIENT_FAILURE_CODES",
+ META_FAILURE_CODES,
+ ValueType.ARRAY,
+ false,
+ null,
+ null,
+ 1,
+ null,
+ false)
+ );
+
+
private static final Logger LOG = Logger.getLogger(HttpClientProtocol.class.getName());
public static final String PROTOCOL_DISPLAY_NAME = "Http Client";
public static final String PROTOCOL_VERSION = "1.0";
@@ -424,20 +652,7 @@ public class HttpClientProtocol extends AbstractProtocol {
/* We're going to fail hard and fast if optional meta items are incorrectly configured */
Optional<OAuthGrant> oAuthGrant = getOAuthGrant(protocolConfiguration);
-
- Optional<StringValue> username = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_USERNAME,
- StringValue.class,
- false,
- true);
-
- Optional<StringValue> password = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PASSWORD,
- StringValue.class,
- false,
- true);
+ Optional<Pair<StringValue, StringValue>> usernameAndPassword = getUsernameAndPassword(protocolConfiguration);
boolean followRedirects = Values.getMetaItemValueOrThrow(
protocolConfiguration,
@@ -482,20 +697,17 @@ public class HttpClientProtocol extends AbstractProtocol {
.map(StringValue::getString)
.orElse(null);
- if ((username.isPresent() && !password.isPresent()) || (!username.isPresent() && password.isPresent())) {
- throw new IllegalArgumentException("Both username and password must be set for basic authentication");
- }
+
WebTargetBuilder webTargetBuilder = new WebTargetBuilder(baseUri);
if (oAuthGrant.isPresent()) {
LOG.info("Adding OAuth");
webTargetBuilder.setOAuthAuthentication(oAuthGrant.get());
} else {
- //noinspection ConstantConditions
- username.ifPresent(stringValue -> {
+ usernameAndPassword.ifPresent(userPass -> {
LOG.info("Adding Basic Authentication");
- webTargetBuilder.setBasicAuthentication(stringValue.getString(),
- password.get().getString());
+ webTargetBuilder.setBasicAuthentication(userPass.key.getString(),
+ userPass.value.getString());
});
}
headers.ifPresent(webTargetBuilder::setInjectHeaders);
@@ -535,19 +747,7 @@ public class HttpClientProtocol extends AbstractProtocol {
.flatMap(objectValue -> getMultivaluedMap(objectValue, false))
.orElse(null);
- Integer pingPollingSeconds = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PING_SECONDS,
- NumberValue.class,
- false,
- true)
- .map(polling ->
- Values.getIntegerCoerced(polling)
- .map(seconds -> seconds < 1 ? null : seconds)
- .orElseThrow(() ->
- new IllegalArgumentException("Ping polling seconds meta item must be an integer >= 1")
- ))
- .orElse(DEFAULT_PING_SECONDS);
+ Integer pingPollingSeconds = getPingSeconds(protocolConfiguration);
String contentType = Values.getMetaItemValueOrThrow(
protocolConfiguration,
@@ -758,6 +958,43 @@ public class HttpClientProtocol extends AbstractProtocol {
return PROTOCOL_VERSION;
}
+ @Override
+ protected List<MetaItemDescriptor> getProtocolConfigurationMetaItemDescriptors() {
+ return new ArrayList<>(PROTOCOL_META_ITEM_DESCRIPTORS);
+ }
+
+ @Override
+ protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
+ List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
+ descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
+ return descriptors;
+ }
+
+ @Override
+ public AssetAttribute getProtocolConfigurationTemplate() {
+ return super.getProtocolConfigurationTemplate()
+ .addMeta(
+ new MetaItem(META_PROTOCOL_BASE_URI, null)
+ );
+ }
+
+ @Override
+ public AttributeValidationResult validateProtocolConfiguration(AssetAttribute protocolConfiguration) {
+ AttributeValidationResult result = super.validateProtocolConfiguration(protocolConfiguration);
+ if (result.isValid()) {
+ try {
+ getOAuthGrant(protocolConfiguration);
+ getUsernameAndPassword(protocolConfiguration);
+ getPingSeconds(protocolConfiguration);
+ } catch (IllegalArgumentException e) {
+ result.addAttributeFailure(
+ new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, PROTOCOL_NAME)
+ );
+ }
+ }
+ return result;
+ }
+
public static Optional<OAuthGrant> getOAuthGrant(AssetAttribute attribute) throws IllegalArgumentException {
return !attribute.hasMetaItem(META_PROTOCOL_OAUTH_GRANT)
? Optional.empty()
@@ -774,6 +1011,46 @@ public class HttpClientProtocol extends AbstractProtocol {
.orElseThrow(() -> new IllegalArgumentException("OAuth grant meta item must be an ObjectValue")));
}
+ public static Optional<Pair<StringValue, StringValue>> getUsernameAndPassword(AssetAttribute attribute) throws IllegalArgumentException {
+ Optional<StringValue> username = Values.getMetaItemValueOrThrow(
+ attribute,
+ META_PROTOCOL_USERNAME,
+ StringValue.class,
+ false,
+ true);
+
+ Optional<StringValue> password = Values.getMetaItemValueOrThrow(
+ attribute,
+ META_PROTOCOL_PASSWORD,
+ StringValue.class,
+ false,
+ true);
+
+ if ((username.isPresent() && !password.isPresent()) || (!username.isPresent() && password.isPresent())) {
+ throw new IllegalArgumentException("Both username and password must be set for basic authentication");
+ }
+
+ return username.map(stringValue -> new Pair<>(stringValue, password.get()));
+ }
+
+ public static Integer getPingSeconds(AssetAttribute attribute) throws IllegalArgumentException {
+ return Values.getMetaItemValueOrThrow(
+ attribute,
+ META_PROTOCOL_PING_SECONDS,
+ NumberValue.class,
+ false,
+ true)
+ .map(polling ->
+ Values.getIntegerCoerced(polling)
+ .map(seconds -> seconds < 1 ? null : seconds)
+ .orElseThrow(() ->
+ new IllegalArgumentException("Ping polling seconds meta item must be an integer >= 1")
+ ))
+ .orElse(DEFAULT_PING_SECONDS);
+ }
+
+
+
public static Optional<MultivaluedMap<String, String>> getMultivaluedMap(ObjectValue objectValue, boolean throwOnError) throws ClassCastException, IllegalArgumentException {
if (objectValue == null) {
return Optional.empty();
diff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java
index 8d19172a7..8d85f0b54 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java
@@ -199,7 +199,9 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
- return ATTRIBUTE_META_ITEM_DESCRIPTORS;
+ List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
+ descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
+ return descriptors;
}
@Override
diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
index 12b7e0a3a..f86bb1d32 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
@@ -173,7 +173,9 @@ public class MacroProtocol extends AbstractProtocol {
@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
- return ATTRIBUTE_META_ITEM_DESCRIPTORS;
+ List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
+ descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
+ return descriptors;
}
@Override
diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
index 04050ed88..0f7357c5d 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
@@ -192,7 +192,9 @@ public class SimulatorProtocol extends AbstractProtocol {
@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
- return ATTRIBUTE_META_ITEM_DESCRIPTORS;
+ List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
+ descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
+ return descriptors;
}
@Override
diff --git a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
index c100e9b84..ba6c63ff9 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
@@ -143,7 +143,9 @@ public class TimerProtocol extends AbstractProtocol {
@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
- return ATTRIBUTE_META_ITEM_DESCRIPTORS;
+ List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
+ descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
+ return descriptors;
}
@Override
diff --git a/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.java
index 5d4d642fd..d3ccb8671 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.java
@@ -18,12 +18,10 @@ import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.attribute.MetaItem;
+import org.openremote.model.attribute.MetaItemDescriptor;
import org.openremote.model.value.Values;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
import java.util.logging.Logger;
import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
@@ -84,6 +82,16 @@ public class UpnpProtocol extends AbstractProtocol {
return VERSION;
}
+ @Override
+ protected List<MetaItemDescriptor> getProtocolConfigurationMetaItemDescriptors() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
+ return super.getLinkedAttributeMetaItemDescriptors();
+ }
+
@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
boolean isEnabled = protocolConfiguration.isEnabled();
diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
index 586af0471..74c130439 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
@@ -120,7 +120,9 @@ public abstract class AbstractVelbusProtocol extends AbstractProtocol implements
@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
- return ATTRIBUTE_META_ITEM_DESCRIPTORS;
+ List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
+ descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
+ return descriptors;
}
@Override
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java b/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
index 1bc767d5c..f192e228a 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
@@ -50,6 +50,7 @@ public class MetaEditor extends AbstractAttributeViewExtension {
protected MetaEditor parentEditor;
protected MetaItem item;
protected FormField field;
+ protected FormLabel nameLabel;
protected FormListBox nameList;
protected FormListBox typeList;
protected FormInputText nameInput;
@@ -72,27 +73,18 @@ public class MetaEditor extends AbstractAttributeViewExtension {
}
nameList = new FormListBox();
+ nameLabel = new FormLabel("TEST");
field.add(nameList);
+ field.add(nameLabel);
- final int[] currentIndex = {0};
- final int[] selectedIndex = {0};
- final MetaItemDescriptor[] currentMetaItemDescriptor = {null};
-
- nameList.addItem(environment.getMessages().customItem(), "");
-
- Arrays.stream(metaItemDescriptors)
- .forEach(metaItemDescriptor -> {
- String name = getMetaItemDisplayName(environment, metaItemDescriptor.name());
- nameList.addItem(name, metaItemDescriptor.getUrn());
-
- if (item.getName().map(n -> n.equals(metaItemDescriptor.getUrn())).orElse(false)) {
- currentMetaItemDescriptor[0] = metaItemDescriptor;
- selectedIndex[0] = currentIndex[0] + 1;
- }
- currentIndex[0]++;
- });
+ if (newItem) {
+ nameLabel.setVisible(false);
+ } else {
+ nameList.setVisible(false);
+ }
- nameList.setSelectedIndex(selectedIndex[0]);
+ updateNameList();
+ nameList.selectItem(item.getName().orElse(""));
nameList.addChangeHandler(event -> onNameChanged(true));
nameInput = new FormInputText();
@@ -145,6 +137,18 @@ public class MetaEditor extends AbstractAttributeViewExtension {
onNameChanged(false);
}
+ protected void updateNameList() {
+ nameList.clear();
+
+ nameList.addItem(environment.getMessages().customItem(), "");
+
+ Arrays.stream(metaItemDescriptors)
+ .forEach(metaItemDescriptor -> {
+ String name = getMetaItemDisplayName(environment, metaItemDescriptor.name());
+ nameList.addItem(name, metaItemDescriptor.getUrn());
+ });
+ }
+
public FormListBox getNameList() {
return nameList;
}
@@ -200,6 +204,7 @@ public class MetaEditor extends AbstractAttributeViewExtension {
}
}
+ nameLabel.setText(currentMetaItemDescriptor.map(metaItemDescriptor -> getMetaItemDisplayName(environment, metaItemDescriptor.name())).orElse(urn));
nameInput.setVisible(!currentMetaItemDescriptor.isPresent());
typeList.setVisible(!currentMetaItemDescriptor.isPresent());
typeList.selectItem(typeListValue);
@@ -263,13 +268,25 @@ public class MetaEditor extends AbstractAttributeViewExtension {
protected MetaItemDescriptor[] metaItemDescriptors;
protected boolean isProtocolConfiguration;
protected AttributeValidationResult lastValidationResult;
+ protected Supplier<List<ProtocolDescriptor>> protocolDescriptorSupplier;
public MetaEditor(Environment environment, AttributeView.Style style, String existingItemsHeader, String newItemsHeader, AttributeView parentView, AssetAttribute attribute, Supplier<List<ProtocolDescriptor>> protocolDescriptorSupplier) {
super(environment, style, parentView, attribute, existingItemsHeader);
setLabelVisible(false);
this.attribute = attribute;
this.style = style;
+ this.protocolDescriptorSupplier = protocolDescriptorSupplier;
isProtocolConfiguration = attribute.hasMetaItem(AssetMeta.PROTOCOL_CONFIGURATION);
+
+ refreshMetaItemDescriptors();
+
+ itemEditorSectionLabel = new FormSectionLabel(newItemsHeader);
+ add(itemListPanel);
+ add(itemEditorSectionLabel);
+ add(itemEditorPanel);
+ }
+
+ protected void refreshMetaItemDescriptors() {
List<MetaItemDescriptor> metaItemDescriptors = new ArrayList<>();
if (isProtocolConfiguration) {
@@ -303,18 +320,24 @@ public class MetaEditor extends AbstractAttributeViewExtension {
this.metaItemDescriptors = metaItemDescriptors.stream()
.filter(metaItemDescriptor -> {
- // Always add protocol configuration using protocol from attribute drop down
+ // Always auto add protocol configuration using protocol from attribute drop down (don't allow manual add)
+ // Agent link shouldn't be allowed on protocol configurations
return metaItemDescriptor != AssetMeta.PROTOCOL_CONFIGURATION &&
- // Agent link shouldn't be allowed on protocol configurations
(!isProtocolConfiguration || metaItemDescriptor != AssetMeta.AGENT_LINK);
})
- .sorted(Comparator.comparing(MetaItemDescriptor::name))
+ .sorted(Comparator.comparing(metaItemDescriptor -> getMetaItemDisplayName(environment, metaItemDescriptor.name())))
.toArray(MetaItemDescriptor[]::new);
- itemEditorSectionLabel = new FormSectionLabel(newItemsHeader);
- add(itemListPanel);
- add(itemEditorSectionLabel);
- add(itemEditorPanel);
+ // Refresh the new item meta item editor
+ itemEditorPanel.forEach(w -> {
+ if (w instanceof MetaItemEditor) {
+ MetaItemEditor editor = (MetaItemEditor)w;
+ if (editor.isNewItem()) {
+ // Agent link status could have changed so update the name list
+ editor.updateNameList();
+ }
+ }
+ });
}
@Override
@@ -380,8 +403,9 @@ public class MetaEditor extends AbstractAttributeViewExtension {
// TODO Should use meta item descriptors from server
Value initialValue = Arrays.stream(AssetMeta.values())
.filter(assetMeta -> assetMeta.getUrn().equals(itemEditor.nameList.getSelectedValue()))
+ .findFirst()
.map(MetaItemDescriptor::getInitialValue)
- .findFirst().orElse(null);
+ .orElse(null);
ValueType valueType = EnumUtil.enumFromString(ValueType.class, itemEditor.typeList.getSelectedValue()).orElse(null);
if (valueType == ValueType.BOOLEAN && initialValue == null) {
@@ -442,6 +466,8 @@ public class MetaEditor extends AbstractAttributeViewExtension {
attribute.getMeta().add(item);
+ refreshMetaItemDescriptors();
+
// Notify the presenter that the attribute has changed
notifyAttributeModified();
}
@@ -452,6 +478,8 @@ public class MetaEditor extends AbstractAttributeViewExtension {
setLabelVisible(itemListPanel.getWidgetCount() > 0);
+ // Update meta item descriptors if agent link status has changed
+
// Check if we have a validation failure for this editor
if (lastValidationResult != null && lastValidationResult.getMetaFailures() != null) {
List<ValidationFailure> failures = lastValidationResult.getMetaFailures().get(index);
@@ -474,6 +502,8 @@ public class MetaEditor extends AbstractAttributeViewExtension {
attribute.getMeta().remove(index);
+ refreshMetaItemDescriptors();
+
// Notify the presenter that the attribute has changed
notifyAttributeModified();
}
diff --git a/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java b/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
index 95b9fd6c8..518f4b6f6 100644
--- a/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
+++ b/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
@@ -162,7 +162,9 @@ public class AttributeLinkEditor extends FlowPanel {
@Override
protected MetaItemEditor createMetaItemEditor(MetaItem item, boolean isNewItem) {
MetaItemEditor itemEditor = super.createMetaItemEditor(item, isNewItem);
- itemEditor.getNameList().setVisible(false);
+ if (itemEditor.getNameList() != null) {
+ itemEditor.getNameList().setVisible(false);
+ }
return itemEditor;
}
diff --git a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
index b93e08fa9..1e6e666c7 100644
--- a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
+++ b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
@@ -321,36 +321,57 @@ metaItemDisplayName[STEP]=Step
metaItemDisplayName[PATTERN]=Pattern
metaItemDisplayName[STORE_DATA_POINTS]=Store data points
metaItemDisplayName[RULE_STATE]=Rule state
+metaItemDisplayName[LOCATION_LINK]=Location link
metaItemDisplayName[RULE_EVENT]=Rule event
metaItemDisplayName[RULE_EVENT_EXPIRES]=Rule event expires
metaItemDisplayName[DISABLED]=Disabled
metaItemDisplayName[EXECUTABLE]=Executable
-metaItemDisplayName[PROTOCOL_MACRO_ACTION]=Macro Action
-metaItemDisplayName[PROTOCOL_MACRO_ACTION_INDEX]=Macro Action Index
-metaItemDisplayName[PROTOCOL_VELBUS_TIME_INJECTION_INTERVAL_SECONDS]=VELBUS Time Injection (s)
-metaItemDisplayName[PROTOCOL_VELBUS_SOCKET_HOST]=VELBUS Host
-metaItemDisplayName[PROTOCOL_VELBUS_SOCKET_PORT]=VELBUS Port
-metaItemDisplayName[PROTOCOL_VELBUS_SERIAL_PORT]=VELBUS Port
-metaItemDisplayName[PROTOCOL_VELBUS_SERIAL_BAUDRATE]=VELBUS Baudrate
-metaItemDisplayName[PROTOCOL_VELBUS_DEVICE_ADDRESS]=VELBUS Device Address
-metaItemDisplayName[PROTOCOL_VELBUS_DEVICE_LINK]=VELBUS Device Link
-metaItemDisplayName[PROTOCOL_KNX_IP]=KNX Gateway Host
-metaItemDisplayName[PROTOCOL_KNX_PORT]=KNX Gateway Port
-metaItemDisplayName[PROTOCOL_KNX_USENAT]=KNX Use NAT
-metaItemDisplayName[PROTOCOL_KNX_CONNECTION_TYPE]=KNX Connection Type
-metaItemDisplayName[PROTOCOL_KNX_LOCAL_BUS_ADDRESS]=KNX Local BUS Address
-metaItemDisplayName[PROTOCOL_KNX_LOCAL_IP]=KNX Local Host
-metaItemDisplayName[PROTOCOL_KNX_ACTION_GA]=KNX Actuator Group Address
-metaItemDisplayName[PROTOCOL_KNX_STATUS_GA]=KNX Status Group Address
+metaItemDisplayName[PROTOCOL_MACRO_ACTION]=Macro action
+metaItemDisplayName[PROTOCOL_MACRO_ACTION_INDEX]=Macro action index
+metaItemDisplayName[PROTOCOL_VELBUS_TIME_INJECTION_INTERVAL_SECONDS]=VELBUS time injection (s)
+metaItemDisplayName[PROTOCOL_VELBUS_SOCKET_HOST]=VELBUS host
+metaItemDisplayName[PROTOCOL_VELBUS_SOCKET_PORT]=VELBUS port
+metaItemDisplayName[PROTOCOL_VELBUS_SERIAL_PORT]=VELBUS port
+metaItemDisplayName[PROTOCOL_VELBUS_SERIAL_BAUDRATE]=VELBUS baudrate
+metaItemDisplayName[PROTOCOL_VELBUS_DEVICE_ADDRESS]=VELBUS device address
+metaItemDisplayName[PROTOCOL_VELBUS_DEVICE_LINK]=VELBUS device link
+metaItemDisplayName[PROTOCOL_KNX_IP]=KNX gateway host
+metaItemDisplayName[PROTOCOL_KNX_PORT]=KNX gateway port
+metaItemDisplayName[PROTOCOL_KNX_USENAT]=KNX use NAT
+metaItemDisplayName[PROTOCOL_KNX_CONNECTION_TYPE]=KNX connection type
+metaItemDisplayName[PROTOCOL_KNX_LOCAL_BUS_ADDRESS]=KNX local bus address
+metaItemDisplayName[PROTOCOL_KNX_LOCAL_IP]=KNX local host
+metaItemDisplayName[PROTOCOL_KNX_ACTION_GA]=KNX actuator group address
+metaItemDisplayName[PROTOCOL_KNX_STATUS_GA]=KNX status group address
metaItemDisplayName[PROTOCOL_KNX_DPT]=KNX DPT
-metaItemDisplayName[PROTOCOL_TIMER_ACTION]=Timer Action
-metaItemDisplayName[PROTOCOL_TIMER_CRON]=Timer CRON Expression
-metaItemDisplayName[PROTOCOL_TIMER_LINK]=Timer Value Link
-metaItemDisplayName[PROTOCOL_SIMULATOR_MODE]=Simulator Mode
-metaItemDisplayName[PROTOCOL_SIMULATOR_WRITE_DELAY]=Simulator Write Delay (ms)
-metaItemDisplayName[PROTOCOL_SIMULATOR_ELEMENT]=Simulator Element Type
+metaItemDisplayName[PROTOCOL_TIMER_ACTION]=Timer action
+metaItemDisplayName[PROTOCOL_TIMER_CRON]=Timer CRON expression
+metaItemDisplayName[PROTOCOL_TIMER_LINK]=Timer value link
+metaItemDisplayName[PROTOCOL_SIMULATOR_MODE]=Simulator mode
+metaItemDisplayName[PROTOCOL_SIMULATOR_WRITE_DELAY]=Simulator write delay (ms)
+metaItemDisplayName[PROTOCOL_SIMULATOR_ELEMENT]=Simulator element type
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_BASE_URI]=HTTP base URI
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_USERNAME]=HTTP basic auth username
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PASSWORD]=HTTP basic auth password
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_OAUH]=HTTP OAuth
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PING_PATH]=HTTP ping path
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PING_METHOD]=HTTP ping method
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PING_BODY]=HTTP ping body
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PING_CONTENT_TYPE]=HTTP ping content type
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PING_SECONDS]=HTTP ping interval (s)
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PING_QUERY_PARAMETERS]=HTTP ping query parameters
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_PATH]=HTTP path
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_METHOD]=HTTP method
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_BODY]=HTTP body
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_CONTENT_TYPE]=HTTP content type
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_POLLING_SECONDS]=HTTP polling interval (s)
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_FOLLOW_REDIRECTS]=HTTP Follow redirects
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_QUERY_PARAMETERS]=HTTP query parameters
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_FAILURE_CODES]=HTTP response failure codes
+metaItemDisplayName[PROTOCOL_HTTP_CLIENT_HEADERS]=HTTP headers
+metaItemDisplayName[PROTOCOL_FILTERS]=Protocol response filters
attributeLinkConverterValues=Converter values
-attributeLinkNewConverterValue=New Converter value
+attributeLinkNewConverterValue=New converter value
enterConverterValue=Enter converter value
selectConverter=Select converter
customConverter=Custom
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItem.java b/model/src/main/java/org/openremote/model/attribute/MetaItem.java
index 49616c1d4..d2e7d9e36 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItem.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItem.java
@@ -113,12 +113,12 @@ public class MetaItem extends AbstractValueHolder {
.orElseGet(
() -> {
if (!getValue().isPresent()) {
- failures.add(new ValidationFailure(META_ITEM_VALUE_IS_REQUIRED, descriptor.getValueType().name())
+ failures.add(new ValidationFailure(META_ITEM_VALUE_IS_REQUIRED, descriptor.getValueType() != null ? descriptor.getValueType().name() : null)
);
}
- if (getValue().map(Value::getType).map(type -> descriptor.getValueType() != type).orElse(true)) {
- failures.add(new ValidationFailure(META_ITEM_VALUE_MISMATCH, descriptor.getValueType().name()));
+ if (getValue().map(Value::getType).map(type -> descriptor.getValueType() != null && descriptor.getValueType() != type).orElse(true)) {
+ failures.add(new ValidationFailure(META_ITEM_VALUE_MISMATCH, descriptor.getValueType() != null ? descriptor.getValueType().name() : null));
return true;
}
@@ -126,7 +126,7 @@ public class MetaItem extends AbstractValueHolder {
String valueStr = getValue().get().toString();
if (isNullOrEmpty(valueStr)) {
- failures.add(new ValidationFailure(MetaItemFailureReason.META_ITEM_VALUE_IS_REQUIRED, descriptor.getValueType().name()));
+ failures.add(new ValidationFailure(MetaItemFailureReason.META_ITEM_VALUE_IS_REQUIRED, descriptor.getValueType() != null ? descriptor.getValueType().name() : null));
return true;
}
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
index 629185920..077cab0d0 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
@@ -102,7 +102,10 @@ public interface MetaItemDescriptor extends HasUniqueResourceName {
DOUBLE_POSITIVE_NON_ZERO,
DOUBLE_NEGATIVE_NON_ZERO,
CRON_EXPRESSION,
- DAYS_HOURS_MINS_SECONDS
+ DAYS_HOURS_MINS_SECONDS,
+ STRING_EMPTY,
+ STRING_EMPTY_OR_CONTAINS_WHITESPACE,
+ HTTP_URL
}
String name();
diff --git a/model/src/main/java/org/openremote/model/util/TextUtil.java b/model/src/main/java/org/openremote/model/util/TextUtil.java
index 7610764b5..1e497590b 100644
--- a/model/src/main/java/org/openremote/model/util/TextUtil.java
+++ b/model/src/main/java/org/openremote/model/util/TextUtil.java
@@ -43,6 +43,11 @@ public class TextUtil {
public static final String REGEXP_PATTERN_DOUBLE_NON_ZERO = "^-?(?!0*(\\.0+)?$)([0-9]+\\.[0-9]+|[1-9]\\d*)$";
public static final String REGEXP_PATTERN_DOUBLE_POSITIVE_NON_ZERO = "^(?!0*(\\.0+)?$)([0-9]+\\.[0-9]+|[1-9]\\d*)$";
public static final String REGEXP_PATTERN_DOUBLE_NEGATIVE_NON_ZERO = "^-(?!0*(\\.0+)?$)([0-9]+\\.[0-9]+|[1-9]\\d*)$";
+ public static final String REGEXP_PATTERN_BASIC_HTTP_URL = "^(http|https)://.+$";
+ public static final String REGEXP_PATTERN_STRING_NON_EMPTY = "(.|\\s)*\\S(.|\\s)*";
+ public static final String REGEXP_PATTERN_STRING_NON_EMPTY_NO_WHITESPACE = "^\\S+$";
+ public static final RegExp REGEXP_INTEGER_POSITIVE = RegExp.compile(REGEXP_PATTERN_INTEGER_POSITIVE);
+ public static final Predicate<String> INTEGER_POSITIVE_VALIDATOR = name -> !isNullOrEmpty(name) && REGEXP_INTEGER_POSITIVE.test(name);
// TODO Unused, doesn't work for "0 30 8 ? * FRI *
public static final String REGEXP_PATTERN_CRON_EXPRESSION = "^\\\\s*($|#|\\\\w+\\\\s*=|(\\\\?|\\\\*|(?:[0-5]?\\\\d)(?:(?:-|\\/|\\\\,)(?:[0-5]?\\\\d))?(?:,(?:[0-5]?\\\\d)(?:(?:-|\\/|\\\\,)(?:[0-5]?\\\\d))?)*)\\\\s+(\\\\?|\\\\*|(?:[0-5]?\\\\d)(?:(?:-|\\/|\\\\,)(?:[0-5]?\\\\d))?(?:,(?:[0-5]?\\\\d)(?:(?:-|\\/|\\\\,)(?:[0-5]?\\\\d))?)*)\\\\s+(\\\\?|\\\\*|(?:[01]?\\\\d|2[0-3])(?:(?:-|\\/|\\\\,)(?:[01]?\\\\d|2[0-3]))?(?:,(?:[01]?\\\\d|2[0-3])(?:(?:-|\\/|\\\\,)(?:[01]?\\\\d|2[0-3]))?)*)\\\\s+(\\\\?|\\\\*|(?:0?[1-9]|[12]\\\\d|3[01])(?:(?:-|\\/|\\\\,)(?:0?[1-9]|[12]\\\\d|3[01]))?(?:,(?:0?[1-9]|[12]\\\\d|3[01])(?:(?:-|\\/|\\\\,)(?:0?[1-9]|[12]\\\\d|3[01]))?)*)\\\\s+(\\\\?|\\\\*|(?:[1-9]|1[012])(?:(?:-|\\/|\\\\,)(?:[1-9]|1[012]))?(?:L|W)?(?:,(?:[1-9]|1[012])(?:(?:-|\\/|\\\\,)(?:[1-9]|1[012]))?(?:L|W)?)*|\\\\?|\\\\*|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?(?:,(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)*)\\\\s+(\\\\?|\\\\*|(?:[0-6])(?:(?:-|\\/|\\\\,|#)(?:[0-6]))?(?:L)?(?:,(?:[0-6])(?:(?:-|\\/|\\\\,|#)(?:[0-6]))?(?:L)?)*|\\\\?|\\\\*|(?:MON|TUE|WED|THU|FRI|SAT|SUN)(?:(?:-)(?:MON|TUE|WED|THU|FRI|SAT|SUN))?(?:,(?:MON|TUE|WED|THU|FRI|SAT|SUN)(?:(?:-)(?:MON|TUE|WED|THU|FRI|SAT|SUN))?)*)(|\\\\s)+(\\\\?|\\\\*|(?:|\\\\d{4})(?:(?:-|\\/|\\\\,)(?:|\\\\d{4}))?(?:,(?:|\\\\d{4})(?:(?:-|\\/|\\\\,)(?:|\\\\d{4}))?)*))$";
diff --git a/model/src/main/java/org/openremote/model/value/Values.java b/model/src/main/java/org/openremote/model/value/Values.java
index 50f8d3706..1bcf992fb 100644
--- a/model/src/main/java/org/openremote/model/value/Values.java
+++ b/model/src/main/java/org/openremote/model/value/Values.java
@@ -230,6 +230,13 @@ public class Values {
case BOOLEAN:
outputValue = (T) Values.create(Boolean.parseBoolean(value.toString()));
break;
+ case ARRAY:
+ case OBJECT:
+ try {
+ outputValue = (T) Values.parse(value.toString()).orElse(null);
+ } catch (ValueException e) {
+ return Optional.empty();
+ }
}
break;
case NUMBER:
diff --git a/model/src/main/java/org/openremote/model/value/impl/ValueTokenizer.java b/model/src/main/java/org/openremote/model/value/impl/ValueTokenizer.java
index ae83d4211..f2ee49090 100644
--- a/model/src/main/java/org/openremote/model/value/impl/ValueTokenizer.java
+++ b/model/src/main/java/org/openremote/model/value/impl/ValueTokenizer.java
@@ -237,11 +237,11 @@ class ValueTokenizer {
default:
if (lenient && (Character.isDigit((char) c) || Character.isLetterOrDigit((char) c))) {
StringBuilder keyBuffer = new StringBuilder();
- keyBuffer.append(c);
+ keyBuffer.append((char) c);
while (true) {
c = next();
if (Character.isDigit((char) c) || Character.isLetterOrDigit((char) c)) {
- keyBuffer.append(c);
+ keyBuffer.append((char) c);
} else {
back(c);
break;
diff --git a/test/src/main/groovy/org/openremote/test/protocol/http/TestHttpServerProtocol.java b/test/src/main/groovy/org/openremote/test/protocol/http/TestHttpServerProtocol.java
index 664717c56..49171c7f5 100644
--- a/test/src/main/groovy/org/openremote/test/protocol/http/TestHttpServerProtocol.java
+++ b/test/src/main/groovy/org/openremote/test/protocol/http/TestHttpServerProtocol.java
@@ -22,9 +22,11 @@ package org.openremote.test.protocol.http;
import org.openremote.agent.protocol.http.AbstractHttpServerProtocol;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.attribute.AttributeEvent;
+import org.openremote.model.attribute.MetaItemDescriptor;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
public class TestHttpServerProtocol extends AbstractHttpServerProtocol {
@@ -37,6 +39,16 @@ public class TestHttpServerProtocol extends AbstractHttpServerProtocol {
return new HashSet<>(Collections.singletonList(resource1));
}
+ @Override
+ protected List<MetaItemDescriptor> getProtocolConfigurationMetaItemDescriptors() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
+ return super.getLinkedAttributeMetaItemDescriptors();
+ }
+
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
}
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index e5e2fdd8f..2d9935804 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -39,6 +39,16 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
updateLinkedAttribute(sendToActuatorEvents.last().getAttributeState())
}
+ @Override
+ protected List<MetaItemDescriptor> getProtocolConfigurationMetaItemDescriptors() {
+ return null
+ }
+
+ @Override
+ protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
+ return null
+ }
+
@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
LOG.info("Mock Protocol: linkProtocol")
diff --git a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
index 3c7dca715..cf3e44f93 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
@@ -78,6 +78,16 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
sendAttributeEvent(state)
}
+ @Override
+ protected List<MetaItemDescriptor> getProtocolConfigurationMetaItemDescriptors() {
+ return null
+ }
+
+ @Override
+ protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
+ return null
+ }
+
@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
protocolMethodCalls.add("LINK_PROTOCOL")