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 updates

Rich Turner78f30d5e5c1a
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 58ff9d846..8163b2a1c 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -121,7 +121,7 @@ public abstract class AbstractProtocol implements Protocol {
static {
attributeMetaItemDescriptors = Arrays.asList(
- META_ATTRIBUTE_FILTERS
+ META_VALUE_FILTERS
);
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
index 109f5bcf0..184e00ede 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
@@ -96,7 +96,7 @@ import static org.openremote.model.attribute.MetaItemDescriptorImpl.*;
* receive and send value change messages with values of that type.
* <p>
* Generic protocols should implement support for filtering state messages from devices (or services) before the
- * protocol updates the linked attribute, to implement this protocols should use the {@link #META_ATTRIBUTE_FILTERS}
+ * protocol updates the linked attribute, to implement this protocols should use the {@link #META_VALUE_FILTERS}
* {@link MetaItem}.
* <p>
* <h1>Dynamic value injection</h1>
@@ -152,19 +152,6 @@ public interface Protocol extends ContainerService {
String ACTUATOR_TOPIC_TARGET_PROTOCOL = "Protocol";
String SENSOR_QUEUE_SOURCE_PROTOCOL = "Protocol";
- /**
- * {@link MetaItem} for defining {@link MessageFilter}s to apply to values before they are sent on the
- * {@link #SENSOR_QUEUE} (i.e. before it is used to update a protocol linked attribute); this is particularly
- * useful for generic protocols. The {@link MetaItem} value should be an {@link ArrayValue} of {@link ObjectValue}s
- * where each {@link ObjectValue} represents a serialised {@link MessageFilter}. The message should pass through the
- * filters in array order.
- */
- MetaItemDescriptor META_ATTRIBUTE_FILTERS = metaItemArray(
- PROTOCOL_NAMESPACE + ":filters",
- ACCESS_PRIVATE,
- false,
- null);
-
/**
* Can be used by protocols that support it to indicate that string values should be converted to/from bytes from/to
* HEX string representation (e.g. 34FD87)
@@ -192,19 +179,13 @@ public interface Protocol extends ContainerService {
* Value to be used for attribute writes, protocols that support this should also support dynamic value insertion,
* see interface javadoc for more details
*/
- MetaItemDescriptor META_ATTRIBUTE_WRITE_VALUE = new MetaItemDescriptorImpl(
+ MetaItemDescriptor META_ATTRIBUTE_WRITE_VALUE = metaItemAny(
PROTOCOL_NAMESPACE + ":writeValue",
- ValueType.ANY,
ACCESS_PRIVATE,
false,
- TextUtil.REGEXP_PATTERN_STRING_NON_EMPTY,
- PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false,
null,
- null,
- null);
+ TextUtil.REGEXP_PATTERN_STRING_NON_EMPTY,
+ PatternFailure.STRING_EMPTY.name());
/**
* Polling frequency in milliseconds for {@link Attribute}s whose value should be polled; can be set on the
@@ -217,6 +198,19 @@ public interface Protocol extends ContainerService {
1000,
null);
+ /**
+ * {@link MetaItem} for defining {@link MessageFilter}s to apply to values before they are sent on the
+ * {@link #SENSOR_QUEUE} (i.e. before it is used to update a protocol linked attribute); this is particularly
+ * useful for generic protocols. The {@link MetaItem} value should be an {@link ArrayValue} of {@link ObjectValue}s
+ * where each {@link ObjectValue} represents a serialised {@link MessageFilter}. The message should pass through the
+ * filters in array order.
+ */
+ MetaItemDescriptor META_VALUE_FILTERS = metaItemArray(
+ PROTOCOL_NAMESPACE + ":valueFilters",
+ ACCESS_PRIVATE,
+ false,
+ null);
+
// TODO: Some of these options should be configurable depending on expected load etc.
// Message topic for communicating from asset/thing to protocol layer (asset attribute changed, trigger actuator)
String ACTUATOR_TOPIC = "seda://ActuatorTopic?multipleConsumers=true&concurrentConsumers=1&waitForTaskToComplete=NEVER&purgeWhenStopping=true&discardIfNoConsumers=true&limitConcurrentConsumers=false&size=1000";
@@ -302,7 +296,7 @@ public interface Protocol extends ContainerService {
return Optional.empty();
}
- Optional<ArrayValue> arrayValueOptional = attribute.getMetaItem(META_ATTRIBUTE_FILTERS)
+ Optional<ArrayValue> arrayValueOptional = attribute.getMetaItem(META_VALUE_FILTERS)
.flatMap(AbstractValueHolder::getValueAsArray);
if (!arrayValueOptional.isPresent()) {
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 c65df8a1e..276d0930e 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
@@ -30,7 +30,6 @@ 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.attribute.MetaItemType;
import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.asset.agent.ProtocolConfiguration;
import org.openremote.model.attribute.*;
@@ -60,6 +59,8 @@ 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.attribute.MetaItemDescriptor.Access.ACCESS_PRIVATE;
+import static org.openremote.model.attribute.MetaItemDescriptorImpl.*;
import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;
import static org.openremote.model.util.TextUtil.*;
@@ -85,13 +86,13 @@ import static org.openremote.model.util.TextUtil.*;
* the response received from this endpoint</b>)</li> <li>{@link #META_QUERY_PARAMETERS}</li>
* <li>{@link #META_FAILURE_CODES}</li>
* <li>{@link #META_HEADERS}</li>
- * <li>{@link Protocol#META_ATTRIBUTE_FILTERS}</li>
+ * <li>{@link Protocol#META_VALUE_FILTERS}</li>
* </ul>
* <p>
* <h1>Response filtering</h1>
* <p>
* Any {@link Attribute} whose value is to be set by the HTTP server response (i.e. it has an {@link
- * #META_POLLING_MILLIS} {@link MetaItem}) can use the standard {@link Protocol#META_ATTRIBUTE_FILTERS} in
+ * #META_POLLING_MILLIS} {@link MetaItem}) can use the standard {@link Protocol#META_VALUE_FILTERS} in
* order to filter the received HTTP response.
* <p>
* <h1>Connection Status</h1>
@@ -157,12 +158,12 @@ public class HttpClientProtocol extends AbstractProtocol {
public static class HttpClientRequest {
- protected String path;
public String method;
public MultivaluedMap<String, String> headers;
public MultivaluedMap<String, String> queryParameters;
- protected List<Integer> failureCodes;
public String body;
+ protected String path;
+ protected List<Integer> failureCodes;
protected String contentType;
protected WebTarget client;
protected WebTarget requestTarget;
@@ -191,26 +192,26 @@ public class HttpClientProtocol extends AbstractProtocol {
this.pagingEnabled = pagingEnabled;
this.contentType = contentType;
dynamicQueryParameters = queryParameters != null
- && queryParameters
- .entrySet()
- .stream()
- .anyMatch(paramNameAndValues ->
- paramNameAndValues.getValue() != null
- && paramNameAndValues.getValue()
- .stream()
- .anyMatch(val -> val.contains(DYNAMIC_VALUE_PLACEHOLDER)));
+ && queryParameters
+ .entrySet()
+ .stream()
+ .anyMatch(paramNameAndValues ->
+ paramNameAndValues.getValue() != null
+ && paramNameAndValues.getValue()
+ .stream()
+ .anyMatch(val -> val.contains(DYNAMIC_VALUE_PLACEHOLDER)));
if (bodyValue != null) {
if (contentType == null) {
this.contentType = bodyValue.getType() == ValueType.OBJECT || bodyValue.getType() == ValueType.ARRAY
- ? MediaType.APPLICATION_JSON
- : DEFAULT_CONTENT_TYPE;
+ ? MediaType.APPLICATION_JSON
+ : DEFAULT_CONTENT_TYPE;
}
body = bodyValue.toString();
}
dynamicBody = !TextUtil.isNullOrEmpty(body)
- && body.contains(DYNAMIC_VALUE_PLACEHOLDER);
+ && body.contains(DYNAMIC_VALUE_PLACEHOLDER);
boolean dynamicPath = !TextUtil.isNullOrEmpty(path) && path.contains(DYNAMIC_VALUE_PLACEHOLDER);
if (!dynamicPath) {
@@ -329,67 +330,151 @@ public class HttpClientProtocol extends AbstractProtocol {
}
public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":httpClient";
+ public static final String PROTOCOL_DISPLAY_NAME = "HTTP Client";
+ public static final String PROTOCOL_VERSION = "1.0";
+ public static final int DEFAULT_PING_MILLIS = 60000;
+ public static final String DEFAULT_HTTP_METHOD = HttpMethod.GET;
+ public static final String DEFAULT_CONTENT_TYPE = MediaType.TEXT_PLAIN;
+ protected static final String HEADER_LINK = "Link";
+ private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, HttpClientProtocol.class.getName());
+ private static int MIN_POLLING_MILLIS = 1000;
+ private static int MIN_PING_MILLIS = 10000;
/*--------------- META ITEMS TO BE USED ON PROTOCOL CONFIGURATIONS ---------------*/
/**
* Base URI for all requests to this server
*/
- public static final String META_PROTOCOL_BASE_URI = PROTOCOL_NAME + ":baseUri";
+ public static final MetaItemDescriptor META_PROTOCOL_BASE_URI = metaItemString(
+ PROTOCOL_NAME + ":baseUri",
+ ACCESS_PRIVATE,
+ true,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY);
+
/**
* Basic authentication username (string)
*/
- public static final String META_PROTOCOL_USERNAME = PROTOCOL_NAME + ":username";
+ public static final MetaItemDescriptor META_PROTOCOL_USERNAME = metaItemString(
+ PROTOCOL_NAME + ":username",
+ ACCESS_PRIVATE,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY);
/**
* Basic authentication password (string)
*/
- public static final String META_PROTOCOL_PASSWORD = PROTOCOL_NAME + ":password";
+ public static final MetaItemDescriptor META_PROTOCOL_PASSWORD = metaItemString(
+ PROTOCOL_NAME + ":password",
+ ACCESS_PRIVATE,
+ true,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY);
+
/**
* OAuth grant ({@link OAuthGrant} stored as {@link ObjectValue})
*/
- public static final String META_PROTOCOL_OAUTH_GRANT = PROTOCOL_NAME + ":oAuthGrant";
+ public static final MetaItemDescriptor META_PROTOCOL_OAUTH_GRANT = metaItemObject(
+ PROTOCOL_NAME + ":oAuthGrant",
+ ACCESS_PRIVATE,
+ false,
+ null);
+
/**
* Relative path to endpoint that should be used for connection status ping (string)
*/
- public static final String META_PROTOCOL_PING_PATH = PROTOCOL_NAME + ":pingPath";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_PATH = metaItemString(
+ PROTOCOL_NAME + ":pingPath",
+ ACCESS_PRIVATE,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY);
+
/**
* HTTP method for connection status ping (integer default: {@value #DEFAULT_HTTP_METHOD})
*/
- public static final String META_PROTOCOL_PING_METHOD = PROTOCOL_NAME + ":pingMethod";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_METHOD = metaItemString(
+ PROTOCOL_NAME + ":pingMethod",
+ ACCESS_PRIVATE,
+ false,
+ HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.OPTIONS);
+
/**
* HTTP request body for connection status ping ({@link Value})
*/
- public static final String META_PROTOCOL_PING_BODY = PROTOCOL_NAME + ":pingBody";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_BODY = metaItemAny(
+ PROTOCOL_NAME + ":pingBody",
+ ACCESS_PRIVATE,
+ false,
+ null,
+ null,
+ null);
+
/**
* Used to indicate the type of data sent in the ping body; (see {@link #META_ATTRIBUTE_CONTENT_TYPE} for details)
*/
- public static final String META_PROTOCOL_PING_CONTENT_TYPE = PROTOCOL_NAME + ":pingContentType";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_CONTENT_TYPE = metaItemString(
+ PROTOCOL_NAME + ":pingContentType",
+ ACCESS_PRIVATE,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY);
+
/**
* Headers for connection status ping (see {@link #META_HEADERS} for details)
*/
- public static final String META_PROTOCOL_PING_HEADERS = PROTOCOL_NAME + ":pingHeaders";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_HEADERS = metaItemObject(
+ PROTOCOL_NAME + ":pingHeaders",
+ ACCESS_PRIVATE,
+ false,
+ null);
+
/**
* Query parameters for connection status ping (see {@link #META_QUERY_PARAMETERS} for details)
*/
- public static final String META_PROTOCOL_PING_QUERY_PARAMETERS = PROTOCOL_NAME + ":pingQueryParameters";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_QUERY_PARAMETERS = metaItemObject(
+ PROTOCOL_NAME + ":pingQueryParameters",
+ ACCESS_PRIVATE,
+ false,
+ null);
+
/**
* Ping frequency in seconds (integer default: {@value #DEFAULT_PING_MILLIS})
*/
- public static final String META_PROTOCOL_PING_MILLIS = PROTOCOL_NAME + ":pingMillis";
+ public static final MetaItemDescriptor META_PROTOCOL_PING_MILLIS = metaItemInteger(
+ PROTOCOL_NAME + ":pingMillis",
+ ACCESS_PRIVATE,
+ false,
+ MIN_PING_MILLIS,
+ null);
+
/**
* Flag to indicate whether redirect responses from the HTTP server should be followed (boolean)
*/
- public static final String META_PROTOCOL_FOLLOW_REDIRECTS = PROTOCOL_NAME + ":followRedirects";
+ public static final MetaItemDescriptor META_PROTOCOL_FOLLOW_REDIRECTS = metaItemFixedBoolean(
+ PROTOCOL_NAME + ":followRedirects",
+ ACCESS_PRIVATE,
+ false);
/*--------------- META ITEMS TO BE USED ON LINKED ATTRIBUTES ---------------*/
/**
* Relative path to endpoint on the server; supports dynamic value insertion, see class javadoc for details
* (string)
*/
- public static final String META_ATTRIBUTE_PATH = PROTOCOL_NAME + ":path";
+ public static final MetaItemDescriptor META_ATTRIBUTE_PATH = metaItemString(
+ PROTOCOL_NAME + ":path",
+ ACCESS_PRIVATE,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY);
+
/**
* HTTP method for request (string default: {@value #DEFAULT_HTTP_METHOD})
*/
- public static final String META_ATTRIBUTE_METHOD = PROTOCOL_NAME + ":method";
+ public static final MetaItemDescriptor META_ATTRIBUTE_METHOD = metaItemString(
+ PROTOCOL_NAME + ":method",
+ ACCESS_PRIVATE,
+ false,
+ HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.OPTIONS);
+
/**
* Used to indicate the type of data sent in the body, a default will be used if not supplied; default is determined
* as follows:
@@ -398,7 +483,12 @@ public class HttpClientProtocol extends AbstractProtocol {
* <li>{@link Protocol#META_ATTRIBUTE_WRITE_VALUE} value type = any other value type: {@value #DEFAULT_CONTENT_TYPE}</li>
* </ul>
*/
- public static final String META_ATTRIBUTE_CONTENT_TYPE = PROTOCOL_NAME + ":contentType";
+ public static final MetaItemDescriptor META_ATTRIBUTE_CONTENT_TYPE = metaItemString(
+ PROTOCOL_NAME + ":contentType",
+ ACCESS_PRIVATE,
+ false,
+ REGEXP_PATTERN_STRING_NON_EMPTY,
+ MetaItemDescriptor.PatternFailure.STRING_EMPTY);
/*--------------- META ITEMS TO BE USED ON PROTOCOL CONFIGURATIONS OR LINKED ATTRIBUTES ---------------*/
/**
@@ -409,7 +499,12 @@ public class HttpClientProtocol extends AbstractProtocol {
* on a linked attribute will be combined with values set on the {@link ProtocolConfiguration} for that request
* (integer array).
*/
- public static final String META_FAILURE_CODES = PROTOCOL_NAME + ":failureCodes";
+ public static final MetaItemDescriptor META_FAILURE_CODES = metaItemArray(
+ PROTOCOL_NAME + ":failureCodes",
+ ACCESS_PRIVATE,
+ false,
+ null);
+
/**
* HTTP headers to be added to requests, {@link ObjectValue} where the keys represent the header name and the value
* represents the header value(s) (value can be a single string or an {@link ArrayValue} of strings), a value of
@@ -419,12 +514,19 @@ public class HttpClientProtocol extends AbstractProtocol {
* NOTE: It is possible to remove a header set by the {@link ProtocolConfiguration} for a specific request by using
* a value of null for the header value on the linked attribute.
*/
- public static final String META_HEADERS = PROTOCOL_NAME + ":headers";
+ public static final MetaItemDescriptor META_HEADERS = metaItemObject(
+ PROTOCOL_NAME + ":headers",
+ ACCESS_PRIVATE,
+ false,
+ null);
/**
* Boolean indicating if paging should occur according to the Link Header specification: https://developer.github.com/v3/guides/traversing-with-pagination/
*/
- public static final String META_PAGING_ENABLED = PROTOCOL_NAME + ":pagingEnabled";
+ public static final MetaItemDescriptor META_PAGING_ENABLED = metaItemFixedBoolean(
+ PROTOCOL_NAME + ":pagingEnabled",
+ ACCESS_PRIVATE,
+ false);
/**
* Query parameters for the request; values specified on a {@link ProtocolConfiguration} will be appended to all
@@ -433,238 +535,134 @@ public class HttpClientProtocol extends AbstractProtocol {
* the parameter value(s); supports dynamic value insertion on linked {@link Attribute}s, see class javadoc for more
* details (value can be a single string or an {@link ArrayValue} of strings).
*/
- public static final String META_QUERY_PARAMETERS = PROTOCOL_NAME + ":queryParameters";
+ public static final MetaItemDescriptor META_QUERY_PARAMETERS = metaItemObject(
+ PROTOCOL_NAME + ":queryParameters",
+ ACCESS_PRIVATE,
+ false,
+ null);
+
+ public static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Arrays.asList(
+ META_ATTRIBUTE_PATH,
+ META_ATTRIBUTE_METHOD,
+ META_ATTRIBUTE_WRITE_VALUE,
+ META_ATTRIBUTE_CONTENT_TYPE,
+ META_HEADERS,
+ META_POLLING_MILLIS,
+ META_QUERY_PARAMETERS,
+ META_FAILURE_CODES,
+ META_PAGING_ENABLED);
- protected static final List<MetaItemDescriptorImpl> PROTOCOL_META_ITEM_DESCRIPTORS = Arrays.asList(
- new MetaItemDescriptorImpl(
+ protected static final List<MetaItemDescriptor> PROTOCOL_META_ITEM_DESCRIPTORS = Arrays.asList(
META_PROTOCOL_BASE_URI,
- ValueType.STRING,
- true,
- REGEXP_PATTERN_BASIC_HTTP_URL,
- MetaItemDescriptor.PatternFailure.HTTP_URL.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_USERNAME,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY_NO_WHITESPACE,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY_OR_CONTAINS_WHITESPACE.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_PASSWORD,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY_NO_WHITESPACE,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY_OR_CONTAINS_WHITESPACE.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_OAUTH_GRANT,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_PING_PATH,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_PING_METHOD,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_PING_BODY,
- null,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_PING_CONTENT_TYPE,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
- META_PROTOCOL_PING_MILLIS,
- ValueType.NUMBER,
- false,
- REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO,
- MetaItemDescriptor.PatternFailure.INTEGER_POSITIVE_NON_ZERO.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
+ META_PROTOCOL_PING_MILLIS,
META_PROTOCOL_PING_QUERY_PARAMETERS,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_PING_HEADERS,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_PROTOCOL_FOLLOW_REDIRECTS,
- ValueType.BOOLEAN,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_QUERY_PARAMETERS,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_HEADERS,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
- META_FAILURE_CODES,
- ValueType.ARRAY,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
- META_PAGING_ENABLED,
- ValueType.BOOLEAN,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null)
- );
-
-
- public static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Arrays.asList(
- new MetaItemDescriptorImpl(
- META_ATTRIBUTE_PATH,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
- META_ATTRIBUTE_METHOD,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false, null, null, null),
- META_ATTRIBUTE_WRITE_VALUE,
- new MetaItemDescriptorImpl(
- META_ATTRIBUTE_CONTENT_TYPE,
- ValueType.STRING,
- false,
- REGEXP_PATTERN_STRING_NON_EMPTY,
- MetaItemDescriptor.PatternFailure.STRING_EMPTY.name(),
- 1,
- null,
- false, null, null, null),
- META_POLLING_MILLIS,
- new MetaItemDescriptorImpl(
- META_QUERY_PARAMETERS,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
- META_QUERY_PARAMETERS,
- ValueType.OBJECT,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
META_FAILURE_CODES,
- ValueType.ARRAY,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null),
- new MetaItemDescriptorImpl(
- META_PAGING_ENABLED,
- ValueType.BOOLEAN,
- false,
- null,
- null,
- 1,
- null,
- false, null, null, null)
- );
-
+ META_PAGING_ENABLED);
- private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, HttpClientProtocol.class.getName());
- public static final String PROTOCOL_DISPLAY_NAME = "HTTP Client";
- public static final String PROTOCOL_VERSION = "1.0";
- protected static final String HEADER_LINK = "Link";
- public static final int DEFAULT_PING_MILLIS = 60000;
- private static int MIN_POLLING_MILLIS = 1000;
- private static int MIN_PING_MILLIS = 10000;
- public static final String DEFAULT_HTTP_METHOD = HttpMethod.GET;
- public static final String DEFAULT_CONTENT_TYPE = MediaType.TEXT_PLAIN;
protected final Map<AttributeRef, Pair<ResteasyWebTarget, List<Integer>>> clientMap = new HashMap<>();
protected final Map<AttributeRef, HttpClientRequest> requestMap = new HashMap<>();
protected final Map<AttributeRef, ScheduledFuture> pollingMap = new HashMap<>();
+ public static Optional<OAuthGrant> getOAuthGrant(AssetAttribute attribute) throws IllegalArgumentException {
+ return !attribute.hasMetaItem(META_PROTOCOL_OAUTH_GRANT)
+ ? Optional.empty()
+ : Optional.of(attribute.getMetaItem(META_PROTOCOL_OAUTH_GRANT)
+ .flatMap(AbstractValueHolder::getValueAsObject)
+ .map(objValue -> {
+ String json = objValue.toJson();
+ try {
+ return Container.JSON.readValue(json, OAuthGrant.class);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("OAuth Grant meta item is not valid", e);
+ }
+ })
+ .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,
+ false,
+ true);
+
+ Optional<StringValue> password = Values.getMetaItemValueOrThrow(
+ attribute,
+ META_PROTOCOL_PASSWORD,
+ 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 getPingMillis(AssetAttribute attribute) throws IllegalArgumentException {
+ return Values.getMetaItemValueOrThrow(
+ attribute,
+ META_PROTOCOL_PING_MILLIS,
+ false,
+ true)
+ .map(polling ->
+ Values.getIntegerCoerced(polling)
+ .map(seconds -> seconds < MIN_PING_MILLIS ? null : seconds)
+ .orElseThrow(() ->
+ new IllegalArgumentException("Ping polling seconds meta item must be an integer >= " + MIN_PING_MILLIS)
+ ))
+ .orElse(DEFAULT_PING_MILLIS);
+ }
+
+ public static Optional<MultivaluedMap<String, String>> getMultivaluedMap(ObjectValue objectValue, boolean throwOnError) throws ClassCastException, IllegalArgumentException {
+ if (objectValue == null) {
+ return Optional.empty();
+ }
+
+ MultivaluedMap<String, String> multivaluedMap = new MultivaluedHashMap<>();
+ objectValue.stream()
+ .forEach((keyAndValue) -> {
+ if (keyAndValue.value != null) {
+ switch (keyAndValue.value.getType()) {
+
+ case OBJECT:
+ if (throwOnError) {
+ throw new IllegalArgumentException("Key '" + keyAndValue.key + "' is of unsupported type: ObjectValue");
+ }
+ break;
+ case ARRAY:
+ Values.getArrayElements(((ArrayValue) keyAndValue.value),
+ StringValue.class,
+ throwOnError,
+ false,
+ StringValue::getString)
+ .ifPresent(strs -> multivaluedMap.addAll(keyAndValue.key, strs));
+ break;
+ case STRING:
+ case NUMBER:
+ case BOOLEAN:
+ multivaluedMap.add(keyAndValue.key, keyAndValue.value.toString());
+ break;
+ }
+ } else {
+ multivaluedMap.add(keyAndValue.key, null);
+ }
+ });
+
+ return multivaluedMap.isEmpty() ? Optional.empty() : Optional.of(multivaluedMap);
+ }
+
@Override
public void init(Container container) throws Exception {
super.init(container);
@@ -690,8 +688,8 @@ public class HttpClientProtocol extends AbstractProtocol {
}
String baseUri = protocolConfiguration.getMetaItem(META_PROTOCOL_BASE_URI)
- .flatMap(AbstractValueHolder::getValueAsString).orElseThrow(() ->
- new IllegalArgumentException("Missing or invalid require meta item: " + META_PROTOCOL_BASE_URI));
+ .flatMap(AbstractValueHolder::getValueAsString).orElseThrow(() ->
+ new IllegalArgumentException("Missing or invalid require meta item: " + META_PROTOCOL_BASE_URI));
/* We're going to fail hard and fast if optional meta items are incorrectly configured */
@@ -699,48 +697,45 @@ public class HttpClientProtocol extends AbstractProtocol {
Optional<Pair<StringValue, StringValue>> usernameAndPassword = getUsernameAndPassword(protocolConfiguration);
boolean followRedirects = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_FOLLOW_REDIRECTS,
- BooleanValue.class,
- false,
- true).map(BooleanValue::getBoolean).orElse(false);
+ protocolConfiguration,
+ META_PROTOCOL_FOLLOW_REDIRECTS,
+ false,
+ true).flatMap(Values::getBoolean).orElse(false);
List<Integer> failureCodes = protocolConfiguration.getMetaItem(META_FAILURE_CODES)
- .flatMap(AbstractValueHolder::getValueAsArray)
- .flatMap(arrayValue ->
- Values.getArrayElements(
- arrayValue,
- NumberValue.class,
- true,
- false,
- number -> Values.getIntegerCoerced(number).orElse(null)))
- .orElse(null);
+ .flatMap(AbstractValueHolder::getValueAsArray)
+ .flatMap(arrayValue ->
+ Values.getArrayElements(
+ arrayValue,
+ NumberValue.class,
+ true,
+ false,
+ number -> Values.getIntegerCoerced(number).orElse(null)))
+ .orElse(null);
Optional<MultivaluedMap<String, String>> headers = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_HEADERS,
- ObjectValue.class,
- false,
- true)
- .flatMap(objectValue -> getMultivaluedMap(objectValue, true));
+ protocolConfiguration,
+ META_HEADERS,
+ false,
+ true)
+ .flatMap(Values::getObject)
+ .flatMap(objectValue -> getMultivaluedMap(objectValue, true));
Optional<MultivaluedMap<String, String>> queryParams = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_QUERY_PARAMETERS,
- ObjectValue.class,
- false,
- true)
- .flatMap(objectValue -> getMultivaluedMap(objectValue, false));
+ protocolConfiguration,
+ META_QUERY_PARAMETERS,
+ false,
+ true)
+ .flatMap(Values::getObject)
+ .flatMap(objectValue -> getMultivaluedMap(objectValue, false));
String pingPath = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PING_PATH,
- StringValue.class,
- false,
- true)
- .map(StringValue::getString)
- .orElse(null);
-
+ protocolConfiguration,
+ META_PROTOCOL_PING_PATH,
+ false,
+ true)
+ .flatMap(Values::getString)
+ .orElse(null);
WebTargetBuilder webTargetBuilder = new WebTargetBuilder(baseUri);
if (oAuthGrant.isPresent()) {
@@ -750,9 +745,10 @@ public class HttpClientProtocol extends AbstractProtocol {
usernameAndPassword.ifPresent(userPass -> {
LOG.info("Adding Basic Authentication");
webTargetBuilder.setBasicAuthentication(userPass.key.getString(),
- userPass.value.getString());
+ userPass.value.getString());
});
}
+
headers.ifPresent(webTargetBuilder::setInjectHeaders);
queryParams.ifPresent(webTargetBuilder::setInjectQueryParameters);
webTargetBuilder.followRedirects(followRedirects);
@@ -768,68 +764,66 @@ public class HttpClientProtocol extends AbstractProtocol {
}
String pingMethod = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PING_METHOD,
- StringValue.class,
- false,
- true)
- .map(StringValue::getString)
- .orElse(DEFAULT_HTTP_METHOD);
+ protocolConfiguration,
+ META_PROTOCOL_PING_METHOD,
+ false,
+ true)
+ .flatMap(Values::getString)
+ .orElse(DEFAULT_HTTP_METHOD);
Value pingBody = protocolConfiguration
- .getMetaItem(META_PROTOCOL_PING_BODY)
- .flatMap(AbstractValueHolder::getValue)
- .orElse(null);
+ .getMetaItem(META_PROTOCOL_PING_BODY)
+ .flatMap(AbstractValueHolder::getValue)
+ .orElse(null);
MultivaluedMap<String, String> pingHeaders = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PING_HEADERS,
- ObjectValue.class,
- false,
- true)
- .flatMap(objectValue -> getMultivaluedMap(objectValue, true))
- .orElse(null);
+ protocolConfiguration,
+ META_PROTOCOL_PING_HEADERS,
+ false,
+ true)
+ .flatMap(Values::getObject)
+ .flatMap(objectValue -> getMultivaluedMap(objectValue, true))
+ .orElse(null);
MultivaluedMap<String, String> pingQueryParams = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PING_QUERY_PARAMETERS,
- ObjectValue.class,
- false,
- true)
- .flatMap(objectValue -> getMultivaluedMap(objectValue, false))
- .orElse(null);
+ protocolConfiguration,
+ META_PROTOCOL_PING_QUERY_PARAMETERS,
+ false,
+ true)
+ .flatMap(Values::getObject)
+ .flatMap(objectValue -> getMultivaluedMap(objectValue, false))
+ .orElse(null);
Integer pingPollingMillis = getPingMillis(protocolConfiguration);
String contentType = Values.getMetaItemValueOrThrow(
- protocolConfiguration,
- META_PROTOCOL_PING_CONTENT_TYPE,
- StringValue.class,
- false,
- true)
- .map(StringValue::getString)
- .orElse(null);
+ protocolConfiguration,
+ META_PROTOCOL_PING_CONTENT_TYPE,
+ false,
+ true)
+ .flatMap(Values::getString)
+ .orElse(null);
HttpClientRequest pingRequest = buildClientRequest(
- client,
- pingPath,
- pingMethod,
- pingHeaders,
- pingQueryParams,
- null,
- true,
- false,
- pingBody,
- contentType);
+ client,
+ pingPath,
+ pingMethod,
+ pingHeaders,
+ pingQueryParams,
+ null,
+ true,
+ false,
+ pingBody,
+ contentType);
LOG.info("Creating ping polling request '" + pingRequest + "'");
requestMap.put(protocolRef, pingRequest);
pollingMap.put(protocolRef, schedulePollingRequest(
- null,
- protocolRef,
- pingRequest,
- pingPollingMillis));
+ null,
+ protocolRef,
+ pingRequest,
+ pingPollingMillis));
}
@Override
@@ -843,100 +837,96 @@ public class HttpClientProtocol extends AbstractProtocol {
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
String method = Values.getMetaItemValueOrThrow(
- attribute,
- META_ATTRIBUTE_METHOD,
- StringValue.class,
- false,
- true)
- .map(StringValue::getString)
- .orElse(DEFAULT_HTTP_METHOD);
+ attribute,
+ META_ATTRIBUTE_METHOD,
+ false,
+ true)
+ .flatMap(Values::getString)
+ .orElse(DEFAULT_HTTP_METHOD);
String path = Values.getMetaItemValueOrThrow(
- attribute,
- META_ATTRIBUTE_PATH,
- StringValue.class,
- false,
- true)
- .map(StringValue::getString)
- .orElse(null);
+ attribute,
+ META_ATTRIBUTE_PATH,
+ false,
+ true)
+ .flatMap(Values::getString)
+ .orElse(null);
String contentType = Values.getMetaItemValueOrThrow(
- attribute,
- META_ATTRIBUTE_CONTENT_TYPE,
- StringValue.class,
- false,
- true)
- .map(StringValue::getString)
- .orElse(null);
+ attribute,
+ META_ATTRIBUTE_CONTENT_TYPE,
+ false,
+ true)
+ .flatMap(Values::getString)
+ .orElse(null);
Value body = attribute
- .getMetaItem(META_ATTRIBUTE_WRITE_VALUE)
- .flatMap(AbstractValueHolder::getValue)
- .orElse(null);
+ .getMetaItem(META_ATTRIBUTE_WRITE_VALUE)
+ .flatMap(AbstractValueHolder::getValue)
+ .orElse(null);
List<Integer> failureCodes = attribute.getMetaItem(META_FAILURE_CODES)
- .flatMap(AbstractValueHolder::getValueAsArray)
- .flatMap(arrayValue ->
- Values.getArrayElements(
- arrayValue,
- NumberValue.class,
- true,
- false,
- number -> Values.getIntegerCoerced(number).orElse(null))
- ).orElse(null);
+ .flatMap(AbstractValueHolder::getValueAsArray)
+ .flatMap(arrayValue ->
+ Values.getArrayElements(
+ arrayValue,
+ NumberValue.class,
+ true,
+ false,
+ number -> Values.getIntegerCoerced(number).orElse(null))
+ ).orElse(null);
MultivaluedMap<String, String> headers = Values.getMetaItemValueOrThrow(
- attribute,
- META_HEADERS,
- ObjectValue.class,
- false,
- true)
- .flatMap(objectValue -> getMultivaluedMap(objectValue, true))
- .orElse(null);
+ attribute,
+ META_HEADERS,
+ false,
+ true)
+ .flatMap(Values::getObject)
+ .flatMap(objectValue -> getMultivaluedMap(objectValue, true))
+ .orElse(null);
MultivaluedMap<String, String> queryParams = Values.getMetaItemValueOrThrow(
- attribute,
- META_QUERY_PARAMETERS,
- ObjectValue.class,
- false,
- true)
- .flatMap(objectValue -> getMultivaluedMap(objectValue, false))
- .orElse(null);
+ attribute,
+ META_QUERY_PARAMETERS,
+ false,
+ true)
+ .flatMap(Values::getObject)
+ .flatMap(objectValue -> getMultivaluedMap(objectValue, false))
+ .orElse(null);
Optional<Integer> pollingMillis = Values.getMetaItemValueOrThrow(
- attribute,
+ attribute,
META_POLLING_MILLIS,
- false,
- true)
- .map(polling ->
- Values.getIntegerCoerced(polling)
- .map(millis -> millis < MIN_POLLING_MILLIS ? null : millis)
- .orElseThrow(() ->
- new IllegalArgumentException("Polling millis meta item must be an integer >= " + MIN_POLLING_MILLIS)
- ));
+ false,
+ true)
+ .map(polling ->
+ Values.getIntegerCoerced(polling)
+ .map(millis -> millis < MIN_POLLING_MILLIS ? null : millis)
+ .orElseThrow(() ->
+ new IllegalArgumentException("Polling millis meta item must be an integer >= " + MIN_POLLING_MILLIS)
+ ));
Boolean pagingEnabled = Values.getMetaItemValueOrThrow(
- attribute,
- META_PAGING_ENABLED,
- BooleanValue.class,
- false,
- true)
- .map(BooleanValue::getBoolean)
- .orElse(false);
+ attribute,
+ META_PAGING_ENABLED,
+ false,
+ true)
+ .flatMap(Values::getBoolean)
+ .orElse(false);
final AttributeRef attributeRef = attribute.getReferenceOrThrow();
addHttpClientRequest(protocolConfiguration,
- attributeRef,
- path,
- method,
- headers,
- queryParams,
- failureCodes,
- pagingEnabled,
- body,
- contentType,
- pollingMillis.orElse(null));
+ attributeRef,
+ path,
+ method,
+ headers,
+ queryParams,
+ failureCodes,
+ pagingEnabled,
+ body,
+ contentType,
+ pollingMillis.orElse(null));
}
protected void addHttpClientRequest(AssetAttribute protocolConfiguration,
@@ -962,41 +952,41 @@ public class HttpClientProtocol extends AbstractProtocol {
}
failureCodes = Optional.ofNullable(failureCodes)
- .map(codes -> {
- if (clientAndFailureCodes.value != null) {
- codes.addAll(clientAndFailureCodes.value);
- }
- return codes;
- }).orElseGet(() -> {
- if (clientAndFailureCodes.value != null) {
- return clientAndFailureCodes.value;
- }
- return null;
- });
+ .map(codes -> {
+ if (clientAndFailureCodes.value != null) {
+ codes.addAll(clientAndFailureCodes.value);
+ }
+ return codes;
+ }).orElseGet(() -> {
+ if (clientAndFailureCodes.value != null) {
+ return clientAndFailureCodes.value;
+ }
+ return null;
+ });
boolean updateConnectionStatus = !pollingMap.containsKey(protocolConfigurationRef);
HttpClientRequest clientRequest = buildClientRequest(
- client,
- path,
- method,
- headers,
- queryParams,
- failureCodes,
- updateConnectionStatus,
- pagingEnabled,
- body,
- contentType);
+ client,
+ path,
+ method,
+ headers,
+ queryParams,
+ failureCodes,
+ updateConnectionStatus,
+ pagingEnabled,
+ body,
+ contentType);
LOG.fine("Creating HTTP request for attributeRef '" + clientRequest + "': " + attributeRef);
requestMap.put(attributeRef, clientRequest);
Optional.ofNullable(pollingSeconds).ifPresent(seconds -> pollingMap.put(attributeRef, schedulePollingRequest(
- attributeRef,
- protocolConfigurationRef,
- clientRequest,
- seconds)));
+ attributeRef,
+ protocolConfigurationRef,
+ clientRequest,
+ seconds)));
}
@Override
@@ -1017,13 +1007,13 @@ public class HttpClientProtocol extends AbstractProtocol {
if (request != null && clientAndFailureCodes != null) {
executeAttributeWriteRequest(request,
- event.getValue().orElse(null),
- response ->
- onAttributeWriteResponse(
- request,
- response,
- protocolRef
- ));
+ event.getValue().orElse(null),
+ response ->
+ onAttributeWriteResponse(
+ request,
+ response,
+ protocolRef
+ ));
} else {
LOG.finest("Ignoring attribute write request as either attribute or protocol configuration is not linked: " + event);
}
@@ -1059,9 +1049,9 @@ public class HttpClientProtocol extends AbstractProtocol {
@Override
public AssetAttribute getProtocolConfigurationTemplate() {
return super.getProtocolConfigurationTemplate()
- .addMeta(
- new MetaItem(META_PROTOCOL_BASE_URI, null)
- );
+ .addMeta(
+ new MetaItem(META_PROTOCOL_BASE_URI, null)
+ );
}
@Override
@@ -1074,118 +1064,25 @@ public class HttpClientProtocol extends AbstractProtocol {
getPingMillis(protocolConfiguration);
} catch (IllegalArgumentException e) {
result.addAttributeFailure(
- new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, PROTOCOL_NAME)
+ 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()
- : Optional.of(attribute.getMetaItem(META_PROTOCOL_OAUTH_GRANT)
- .flatMap(AbstractValueHolder::getValueAsObject)
- .map(objValue -> {
- String json = objValue.toJson();
- try {
- return Container.JSON.readValue(json, OAuthGrant.class);
- } catch (IOException e) {
- throw new IllegalArgumentException("OAuth Grant meta item is not valid", e);
- }
- })
- .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 getPingMillis(AssetAttribute attribute) throws IllegalArgumentException {
- return Values.getMetaItemValueOrThrow(
- attribute,
- META_PROTOCOL_PING_MILLIS,
- NumberValue.class,
- false,
- true)
- .map(polling ->
- Values.getIntegerCoerced(polling)
- .map(seconds -> seconds < MIN_PING_MILLIS ? null : seconds)
- .orElseThrow(() ->
- new IllegalArgumentException("Ping polling seconds meta item must be an integer >= " + MIN_PING_MILLIS)
- ))
- .orElse(DEFAULT_PING_MILLIS);
- }
-
-
- public static Optional<MultivaluedMap<String, String>> getMultivaluedMap(ObjectValue objectValue, boolean throwOnError) throws ClassCastException, IllegalArgumentException {
- if (objectValue == null) {
- return Optional.empty();
- }
-
- MultivaluedMap<String, String> multivaluedMap = new MultivaluedHashMap<>();
- objectValue.stream()
- .forEach((keyAndValue) -> {
- if (keyAndValue.value != null) {
- switch (keyAndValue.value.getType()) {
-
- case OBJECT:
- if (throwOnError) {
- throw new IllegalArgumentException("Key '" + keyAndValue.key + "' is of unsupported type: ObjectValue");
- }
- break;
- case ARRAY:
- Values.getArrayElements(((ArrayValue) keyAndValue.value),
- StringValue.class,
- throwOnError,
- false,
- StringValue::getString)
- .ifPresent(strs -> multivaluedMap.addAll(keyAndValue.key, strs));
- break;
- case STRING:
- case NUMBER:
- case BOOLEAN:
- multivaluedMap.add(keyAndValue.key, keyAndValue.value.toString());
- break;
- }
- } else {
- multivaluedMap.add(keyAndValue.key, null);
- }
- });
-
- return multivaluedMap.isEmpty() ? Optional.empty() : Optional.of(multivaluedMap);
- }
-
protected HttpClientRequest buildClientRequest(WebTarget client, String path, String method, MultivaluedMap<String, String> headers, MultivaluedMap<String, String> queryParams, List<Integer> failureCodes, boolean updateConnectionStatus, boolean pagingEnabled, Value body, String contentType) {
return new HttpClientRequest(
- client,
- path,
- method,
- headers,
- queryParams,
- failureCodes,
- updateConnectionStatus,
- pagingEnabled,
- body,
- contentType);
+ client,
+ path,
+ method,
+ headers,
+ queryParams,
+ failureCodes,
+ updateConnectionStatus,
+ pagingEnabled,
+ body,
+ contentType);
}
protected ScheduledFuture schedulePollingRequest(AttributeRef attributeRef,
@@ -1196,17 +1093,17 @@ public class HttpClientProtocol extends AbstractProtocol {
LOG.fine("Scheduling polling request '" + clientRequest + "' to execute every " + pollingMillis + " ms for attribute: " + attributeRef);
return executorService.scheduleWithFixedDelay(() ->
- executePollingRequest(clientRequest, response ->
- onPollingResponse(
- clientRequest,
- response,
- attributeRef,
- protocolConfigurationRef)
- ), 0, pollingMillis, TimeUnit.MILLISECONDS);
+ executePollingRequest(clientRequest, response ->
+ onPollingResponse(
+ clientRequest,
+ response,
+ attributeRef,
+ protocolConfigurationRef)
+ ), 0, pollingMillis, TimeUnit.MILLISECONDS);
}
protected void executePollingRequest(HttpClientRequest clientRequest, Consumer<Response> responseConsumer) {
- Response originalResponse = null, lastResponse = null;
+ Response originalResponse = null, lastResponse;
List<String> entities = new ArrayList<>();
try {
@@ -1317,15 +1214,9 @@ public class HttpClientProtocol extends AbstractProtocol {
connectionStatus = ConnectionStatus.UNKNOWN;
} else {
switch (status.getFamily()) {
- case INFORMATIONAL:
- connectionStatus = ConnectionStatus.ERROR;
- break;
case SUCCESSFUL:
connectionStatus = ConnectionStatus.CONNECTED;
break;
- case REDIRECTION:
- connectionStatus = ConnectionStatus.ERROR;
- break;
case CLIENT_ERROR:
if (responseCode == 401 || responseCode == 402 || responseCode == 403) {
connectionStatus = ConnectionStatus.ERROR_AUTHENTICATION;
@@ -1334,6 +1225,8 @@ public class HttpClientProtocol extends AbstractProtocol {
}
break;
case SERVER_ERROR:
+ case REDIRECTION:
+ case INFORMATIONAL:
connectionStatus = ConnectionStatus.ERROR;
break;
case OTHER:
@@ -1342,7 +1235,7 @@ public class HttpClientProtocol extends AbstractProtocol {
}
LOG.fine("Updating connection status based on polling response code: URI=" + request +
- ", ResponseCode=" + responseCode + ", Status=" + connectionStatus);
+ ", ResponseCode=" + responseCode + ", Status=" + connectionStatus);
updateStatus(protocolConfigurationRef, connectionStatus);
}
@@ -1361,8 +1254,8 @@ public class HttpClientProtocol extends AbstractProtocol {
LOG.fine("Updating protocol configuration enabled status to false");
updateLinkedProtocolConfiguration(
- protocolInfo.getProtocolConfiguration(),
- protocolConfig -> protocolConfig.setDisabled(true)
+ protocolInfo.getProtocolConfiguration(),
+ protocolConfig -> protocolConfig.setDisabled(true)
);
}
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 c42d1dc3a..04d2e1a00 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
@@ -61,7 +61,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
* IP address of the KNX gateway to connect to in TUNNEL mode. Optional if {@link #META_KNX_IP_CONNECTION_TYPE} is ROUTING.<br>
* In ROUTING mode, the IP address specifies the multicast group to join.
*/
- public static final String META_KNX_GATEWAY_IP = PROTOCOL_NAME + ":gatewayIp";
+ public static final String META_KNX_GATEWAY_HOST = PROTOCOL_NAME + ":gatewayHost";
/**
* The KNX gateway port to connect to in TUNNEL mode. Not used in ROUTING mode.<br>
@@ -92,7 +92,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
* Local IP address or hostname to establish connection from.<br>
* Default: hostname
*/
- public static final String META_KNX_LOCAL_IP = PROTOCOL_NAME + ":localIP";
+ public static final String META_KNX_LOCAL_HOST = PROTOCOL_NAME + ":localhost";
//Attribute specific configuration meta items
@@ -110,12 +110,12 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
public static final String PATTERN_FAILURE_GROUP_ADDRESS = "KNX Group Address (e.g. 1/1/1)";
protected static final List<MetaItemDescriptor> PROTOCOL_CONFIG_META_ITEM_DESCRIPTORS = Arrays.asList(
- new MetaItemDescriptorImpl(META_KNX_GATEWAY_IP, ValueType.STRING, false, null, null, 1, null, false, null, null, null),
+ new MetaItemDescriptorImpl(META_KNX_GATEWAY_HOST, ValueType.STRING, false, null, null, 1, null, false, null, null, null),
new MetaItemDescriptorImpl(META_KNX_GATEWAY_PORT, ValueType.NUMBER, false, REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO, MetaItemDescriptor.PatternFailure.INTEGER_POSITIVE_NON_ZERO.name(), 1, null, false, null, null, null),
new MetaItemDescriptorImpl(META_KNX_GATEWAY_USENAT, ValueType.BOOLEAN, false, null, null, 1, Values.create(false), false, null, null, null),
new MetaItemDescriptorImpl(META_KNX_IP_CONNECTION_TYPE, ValueType.STRING, false, "^(TUNNELLING|ROUTING)$", PATTERN_FAILURE_CONNECTION_TYPE, 1, Values.create("TUNNELLING"), false, null, null, null),
new MetaItemDescriptorImpl(META_KNX_LOCAL_BUS_ADDRESS, ValueType.STRING, false, REGEXP_BUS_ADDRESS, "0.0.0", 1, null, false, null, null, null),
- new MetaItemDescriptorImpl(META_KNX_LOCAL_IP, ValueType.STRING, false, null, null, 1, null, false, null, null, null)
+ new MetaItemDescriptorImpl(META_KNX_LOCAL_HOST, ValueType.STRING, false, null, null, 1, null, false, null, null, null)
);
protected static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Arrays.asList(
@@ -149,7 +149,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
return super.getProtocolConfigurationTemplate()
.addMeta(
new MetaItem(META_KNX_IP_CONNECTION_TYPE, Values.create("TUNNELLING")),
- new MetaItem(META_KNX_GATEWAY_IP, null)
+ new MetaItem(META_KNX_GATEWAY_HOST, null)
);
}
@@ -171,7 +171,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
}
ipFound = "ROUTING".equals(connectionType);
- } else if (isMetaNameEqualTo(actionMetaItem, META_KNX_GATEWAY_IP)) {
+ } else if (isMetaNameEqualTo(actionMetaItem, META_KNX_GATEWAY_HOST)) {
ipFound = true;
if (isNullOrEmpty(actionMetaItem.getValueAsString().orElse(null))) {
result.addMetaFailure(
@@ -184,7 +184,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
if (!ipFound) {
result.addMetaFailure(
- new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, META_KNX_GATEWAY_IP)
+ new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, META_KNX_GATEWAY_HOST)
);
}
}
@@ -213,7 +213,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
return;
}
- Optional<String> gatewayIpParam = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_IP).flatMap(AbstractValueHolder::getValueAsString);
+ Optional<String> gatewayIpParam = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_HOST).flatMap(AbstractValueHolder::getValueAsString);
// RT: KNXConnection constructor implies gateway IP is always required so removed TUNNELLING only check here
if (!gatewayIpParam.isPresent()) {
LOG.severe("No KNX gateway IP address provided for protocol configuration: " + protocolConfiguration);
@@ -226,7 +226,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
return;
}
- String localIp = protocolConfiguration.getMetaItem(META_KNX_LOCAL_IP).flatMap(AbstractValueHolder::getValueAsString).orElse(null);
+ String localIp = protocolConfiguration.getMetaItem(META_KNX_LOCAL_HOST).flatMap(AbstractValueHolder::getValueAsString).orElse(null);
Integer remotePort = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_PORT).flatMap(AbstractValueHolder::getValueAsInteger).orElse(3671);
String localKNXAddress = protocolConfiguration.getMetaItem(META_KNX_LOCAL_BUS_ADDRESS).flatMap(AbstractValueHolder::getValueAsString).orElse("0.0.0");
Boolean useNat = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_USENAT).flatMap(AbstractValueHolder::getValueAsBoolean).orElse(Boolean.FALSE);
@@ -257,7 +257,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
statusConsumer = statusConsumerMap.get(protocolConfiguration.getReferenceOrThrow());
}
- String gatewayIp = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_IP).flatMap(AbstractValueHolder::getValueAsString).orElse("");
+ String gatewayIp = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_HOST).flatMap(AbstractValueHolder::getValueAsString).orElse("");
synchronized (knxConnections) {
KNXConnection knxConnection = knxConnections.get(gatewayIp);
if (knxConnection != null) {
@@ -272,7 +272,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
- String gatewayIp = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_IP).flatMap(AbstractValueHolder::getValueAsString).orElse("");
+ String gatewayIp = protocolConfiguration.getMetaItem(META_KNX_GATEWAY_HOST).flatMap(AbstractValueHolder::getValueAsString).orElse("");
final AttributeRef attributeRef = attribute.getReferenceOrThrow();
// Check there is a META_KNX_DPT
diff --git a/agent/src/main/java/org/openremote/agent/protocol/udp/UdpClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/udp/UdpClientProtocol.java
index d15dec508..fd80c8ed2 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/udp/UdpClientProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/udp/UdpClientProtocol.java
@@ -71,7 +71,7 @@ import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;
* the following meta items:
* <ul>
* <li>{@link #META_ATTRIBUTE_WRITE_VALUE} (if specified also supports dynamic value injection as described in {@link Protocol})</li>
- * <li>{@link #META_ATTRIBUTE_FILTERS}</li>
+ * <li>{@link #META_VALUE_FILTERS}</li>
* <li>{@link #META_POLLING_MILLIS}</li>
* </ul>
*
@@ -81,8 +81,15 @@ public class UdpClientProtocol extends AbstractProtocol {
private static class AttributeInfo {
Consumer<Value> sendConsumer;
ScheduledFuture pollingTask;
-
-
+ int retries;
+ boolean expectResponse;
+
+ public AttributeInfo(Consumer<Value> sendConsumer, ScheduledFuture pollingTask, int retries, boolean expectResponse) {
+ this.sendConsumer = sendConsumer;
+ this.pollingTask = pollingTask;
+ this.retries = retries;
+ this.expectResponse = expectResponse;
+ }
}
@@ -93,9 +100,9 @@ public class UdpClientProtocol extends AbstractProtocol {
private static int DEFAULT_RESPONSE_TIMEOUT_MILLIS = 3000;
private static int DEFAULT_SEND_RETRIES = 1;
private static boolean DEFAULT_SERVER_ALWAYS_RESPONDS = false;
+ private static int MIN_POLLING_MILLIS = 1000;
protected final Map<AttributeRef, IoClient<String>> clientMap = new HashMap<>();
- protected final Map<AttributeRef, Consumer<Value>> attributeWriteMap = new HashMap<>();
- protected final Map<AttributeRef, ScheduledFuture> attributePollingMap = new HashMap<>();
+ protected final Map<AttributeRef, AttributeInfo> attributeInfoMap = new HashMap<>();
/**
* The UDP server host name/IP address
@@ -170,6 +177,12 @@ public class UdpClientProtocol extends AbstractProtocol {
@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
+
+ if (!protocolConfiguration.isEnabled()) {
+ LOG.info("Protocol configuration is disabled so ignoring: " + protocolConfiguration.getReferenceOrThrow());
+ return;
+ }
+
final AttributeRef protocolRef = protocolConfiguration.getReferenceOrThrow();
String host = Values.getMetaItemValueOrThrow(
@@ -237,6 +250,11 @@ public class UdpClientProtocol extends AbstractProtocol {
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
+ if (!protocolConfiguration.isEnabled()) {
+ LOG.info("Protocol configuration is disabled so ignoring: " + protocolConfiguration.getReferenceOrThrow());
+ return;
+ }
+
IoClient<String> client = clientMap.get(protocolConfiguration.getReferenceOrThrow());
if (client == null) {
@@ -250,29 +268,42 @@ public class UdpClientProtocol extends AbstractProtocol {
.flatMap(Values::getIntegerCoerced)
.orElse(null);
- final Integer responseTimeoutMillis = Values.getMetaItemValueOrThrow(attribute, META_RESPONSE_TIMEOUT_MILLIS, false, true)
+ final int responseTimeoutMillis = Values.getMetaItemValueOrThrow(attribute, META_RESPONSE_TIMEOUT_MILLIS, false, true)
.flatMap(Values::getIntegerCoerced)
.orElseGet(() ->
Values.getMetaItemValueOrThrow(protocolConfiguration, META_RESPONSE_TIMEOUT_MILLIS, false, true)
.flatMap(Values::getIntegerCoerced)
- .orElse(null)
+ .orElse(DEFAULT_RESPONSE_TIMEOUT_MILLIS)
);
- final Integer sendRetries = Values.getMetaItemValueOrThrow(attribute, META_SEND_RETRIES, false, true)
+ final int sendRetries = Values.getMetaItemValueOrThrow(attribute, META_SEND_RETRIES, false, true)
.flatMap(Values::getIntegerCoerced)
.orElseGet(() ->
Values.getMetaItemValueOrThrow(protocolConfiguration, META_SEND_RETRIES, false, true)
.flatMap(Values::getIntegerCoerced)
- .orElse(null)
+ .orElse(DEFAULT_SEND_RETRIES)
);
+ final boolean serverAlwaysResponds = Values.getMetaItemValueOrThrow(
+ attribute,
+ META_SERVER_ALWAYS_RESPONDS,
+ false,
+ false
+ ).flatMap(Values::getBoolean).orElseGet(() ->
+ Values.getMetaItemValueOrThrow(protocolConfiguration, META_SERVER_ALWAYS_RESPONDS, false, false)
+ .flatMap(Values::getBoolean)
+ .orElse(DEFAULT_SERVER_ALWAYS_RESPONDS)
+ );
+
+ Consumer<Value> sendConsumer = null;
+ ScheduledFuture pollingTask = null;
+
if (!attribute.isReadOnly()) {
- Consumer<Value> valueWriter = createWriteConsumer(client, attribute.getReferenceOrThrow(), writeValue, null);
- attributeWriteMap.put(attribute.getReferenceOrThrow(), valueWriter);
+ sendConsumer = createWriteConsumer(client, attribute.getReferenceOrThrow(), writeValue, null);
}
- if (pollingMillis < 1000) {
- LOG.warning("Polling ms must be >= 1000");
+ if (pollingMillis != null && pollingMillis < MIN_POLLING_MILLIS) {
+ LOG.warning("Polling ms must be >= " + MIN_POLLING_MILLIS);
return;
}
@@ -289,45 +320,45 @@ public class UdpClientProtocol extends AbstractProtocol {
str != null ? Values.create(str) : null));
Consumer<Value> pollingWriter = createWriteConsumer(client, attribute.getReferenceOrThrow(), writeValue, responseConsumer);
- Runnable pollingTask = () -> pollingWriter.accept(null);
- ScheduledFuture pollingFuture = schedulePollingRequest(client, attribute.getReferenceOrThrow(), pollingTask, pollingMillis);
- attributePollingMap.put(attribute.getReferenceOrThrow(), pollingFuture);
+ Runnable pollingRunnable = () -> pollingWriter.accept(null);
+ pollingTask = schedulePollingRequest(client, attribute.getReferenceOrThrow(), pollingRunnable, pollingMillis);
}
- }
-
- protected Consumer<Value> createWriteConsumer(IoClient<String> client, AttributeRef attributeRef, String writeValue, Consumer<String> responseConsumer) {
- return value -> {
-
- String str = value != null ? value.toString() : "";
- if (!TextUtil.isNullOrEmpty(writeValue) && writeValue.contains(DYNAMIC_VALUE_PLACEHOLDER)) {
- str = writeValue.replaceAll(DYNAMIC_VALUE_PLACEHOLDER_REGEXP, str);
- }
-
- onClientWriteRequest(client, attributeRef, str, responseConsumer);
- };
+ attributeInfoMap.put(attribute.getReferenceOrThrow(), new AttributeInfo(sendConsumer, pollingTask, sendRetries, serverAlwaysResponds));
}
@Override
protected void doUnlinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
- attributeWriteMap.remove(attribute.getReferenceOrThrow());
- ScheduledFuture pollingTask = attributePollingMap.remove(attribute.getReferenceOrThrow());
+ AttributeInfo info = attributeInfoMap.remove(attribute.getReferenceOrThrow());
- if (pollingTask != null) {
- pollingTask.cancel(false);
+ if (info != null && info.pollingTask != null) {
+ info.pollingTask.cancel(false);
}
}
@Override
protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute protocolConfiguration) {
- Consumer<Value> writer = attributeWriteMap.get(event.getAttributeRef());
+ AttributeInfo info = attributeInfoMap.get(event.getAttributeRef());
- if (writer == null) {
- LOG.info("Request to write unlinked attribute so ignoring: " + event);
+ if (info == null || info.sendConsumer == null) {
+ LOG.info("Request to write unlinked attribute or attribute that doesn't support writes so ignoring: " + event);
return;
}
- writer.accept(event.getValue().orElse(null));
+ info.sendConsumer.accept(event.getValue().orElse(null));
+ }
+
+ protected Consumer<Value> createWriteConsumer(IoClient<String> client, AttributeRef attributeRef, String writeValue, Consumer<String> responseConsumer) {
+ return value -> {
+
+ String str = value != null ? value.toString() : "";
+
+ if (!TextUtil.isNullOrEmpty(writeValue) && writeValue.contains(DYNAMIC_VALUE_PLACEHOLDER)) {
+ str = writeValue.replaceAll(DYNAMIC_VALUE_PLACEHOLDER_REGEXP, str);
+ }
+
+ onClientWriteRequest(client, attributeRef, str, responseConsumer);
+ };
}
protected void onConnectionStatusChanged(AttributeRef protocolRef, ConnectionStatus connectionStatus) {
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 cd8884ace..cc3542ced 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
@@ -127,6 +127,11 @@ public abstract class AbstractVelbusProtocol extends AbstractProtocol implements
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
final AttributeRef protocolRef = protocolConfiguration.getReferenceOrThrow();
+ if (!protocolConfiguration.isEnabled()) {
+ LOG.info("Protocol configuration is disabled so ignoring: " + protocolConfiguration.getReferenceOrThrow());
+ return;
+ }
+
// Look for existing network
String networkIdentifier = getUniqueNetworkIdentifier(protocolConfiguration);
VelbusNetwork velbusNetwork = null;
@@ -182,6 +187,12 @@ public abstract class AbstractVelbusProtocol extends AbstractProtocol implements
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
+
+ if (!protocolConfiguration.isEnabled()) {
+ LOG.info("Protocol configuration is disabled so ignoring: " + protocolConfiguration.getReferenceOrThrow());
+ return;
+ }
+
Pair<VelbusNetwork, Consumer<ConnectionStatus>> velbusNetworkConsumerPair = networkConfigurationMap.get(protocolConfiguration.getReferenceOrThrow());
if (velbusNetworkConsumerPair == null) {
diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusConfiguration.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusConfiguration.java
index 7f916b2bb..eb741881e 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusConfiguration.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusConfiguration.java
@@ -75,7 +75,7 @@ public final class VelbusConfiguration {
if (attribute.getMeta() != null && !attribute.getMeta().isEmpty()) {
for (int i = 0; i < attribute.getMeta().size(); i++) {
MetaItem metaItem = attribute.getMeta().get(i);
- if (isMetaNameEqualTo(metaItem, VelbusTcpProtocol.META_VELBUS_SOCKET_HOST)) {
+ if (isMetaNameEqualTo(metaItem, VelbusTcpProtocol.META_VELBUS_HOST)) {
hostFound = true;
if (isNullOrEmpty(metaItem.getValueAsString().orElse(null))) {
failure = true;
@@ -85,7 +85,7 @@ public final class VelbusConfiguration {
result.addMetaFailure(i,
new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_VALUE_IS_REQUIRED, ValueType.STRING.name()));
}
- } else if (isMetaNameEqualTo(metaItem, VelbusTcpProtocol.META_VELBUS_SOCKET_PORT)) {
+ } else if (isMetaNameEqualTo(metaItem, VelbusTcpProtocol.META_VELBUS_PORT)) {
portFound = true;
int port = metaItem.getValueAsInteger().orElse(0);
if (port <= 0 || port > 65536) {
@@ -106,7 +106,7 @@ public final class VelbusConfiguration {
result.addMetaFailure(
new ValidationFailure(
MetaItem.MetaItemFailureReason.META_ITEM_MISSING,
- VelbusTcpProtocol.META_VELBUS_SOCKET_HOST));
+ VelbusTcpProtocol.META_VELBUS_HOST));
}
}
if (!portFound) {
@@ -115,7 +115,7 @@ public final class VelbusConfiguration {
result.addMetaFailure(
new ValidationFailure(
MetaItem.MetaItemFailureReason.META_ITEM_MISSING,
- VelbusTcpProtocol.META_VELBUS_SOCKET_PORT));
+ VelbusTcpProtocol.META_VELBUS_PORT));
}
}
@@ -170,7 +170,7 @@ public final class VelbusConfiguration {
failure = true;
if (result != null) {
result.addMetaFailure(
- new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, VelbusTcpProtocol.META_VELBUS_SOCKET_PORT)
+ new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, VelbusTcpProtocol.META_VELBUS_PORT)
);
}
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusTcpProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusTcpProtocol.java
index 7e1147c58..539ee7fb9 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusTcpProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/VelbusTcpProtocol.java
@@ -39,11 +39,11 @@ public class VelbusTcpProtocol extends AbstractVelbusProtocol {
public static final String PROTOCOL_NAME = PROTOCOL_BASE_NAME + "Socket";
public static final String PROTOCOL_DISPLAY_NAME = "VELBUS Socket";
- public static final String META_VELBUS_SOCKET_HOST = PROTOCOL_NAME + ":host";
- public static final String META_VELBUS_SOCKET_PORT = PROTOCOL_NAME + ":port";
+ public static final String META_VELBUS_HOST = PROTOCOL_NAME + ":host";
+ public static final String META_VELBUS_PORT = PROTOCOL_NAME + ":port";
public static final List<MetaItemDescriptorImpl> META_ITEM_DESCRIPTORS = Arrays.asList(
new MetaItemDescriptorImpl(
- META_VELBUS_SOCKET_HOST,
+ META_VELBUS_HOST,
ValueType.STRING,
true,
null,
@@ -53,7 +53,7 @@ public class VelbusTcpProtocol extends AbstractVelbusProtocol {
false,
null, null, null),
new MetaItemDescriptorImpl(
- META_VELBUS_SOCKET_PORT,
+ META_VELBUS_PORT,
ValueType.NUMBER,
true,
REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO,
@@ -94,8 +94,8 @@ public class VelbusTcpProtocol extends AbstractVelbusProtocol {
public AssetAttribute getProtocolConfigurationTemplate() {
return super.getProtocolConfigurationTemplate()
.addMeta(
- new MetaItem(META_VELBUS_SOCKET_HOST, null),
- new MetaItem(META_VELBUS_SOCKET_PORT, null)
+ new MetaItem(META_VELBUS_HOST, null),
+ new MetaItem(META_VELBUS_PORT, null)
);
}
@@ -103,8 +103,8 @@ public class VelbusTcpProtocol extends AbstractVelbusProtocol {
protected IoClient<VelbusPacket> createClient(AssetAttribute protocolConfiguration) throws RuntimeException {
// Extract IP and Host
- String host = protocolConfiguration.getMetaItem(META_VELBUS_SOCKET_HOST).flatMap(AbstractValueHolder::getValueAsString).orElse(null);
- Integer port = protocolConfiguration.getMetaItem(META_VELBUS_SOCKET_PORT).flatMap(AbstractValueHolder::getValueAsInteger).orElse(null);
+ String host = protocolConfiguration.getMetaItem(META_VELBUS_HOST).flatMap(AbstractValueHolder::getValueAsString).orElse(null);
+ Integer port = protocolConfiguration.getMetaItem(META_VELBUS_PORT).flatMap(AbstractValueHolder::getValueAsInteger).orElse(null);
TextUtil.requireNonNullAndNonEmpty(host, "Host cannot be null or empty");
Objects.requireNonNull(port, "Port cannot be null");
@@ -114,10 +114,10 @@ public class VelbusTcpProtocol extends AbstractVelbusProtocol {
@Override
protected String getUniqueNetworkIdentifier(AssetAttribute protocolConfiguration) {
- String host = protocolConfiguration.getMetaItem(META_VELBUS_SOCKET_HOST)
+ String host = protocolConfiguration.getMetaItem(META_VELBUS_HOST)
.flatMap(AbstractValueHolder::getValueAsString)
.orElse("");
- String port = protocolConfiguration.getMetaItem(META_VELBUS_SOCKET_PORT)
+ String port = protocolConfiguration.getMetaItem(META_VELBUS_PORT)
.flatMap(AbstractValueHolder::getValueAsInteger)
.map(Object::toString)
.orElse("");
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 faf41c5f8..e590f5150 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
@@ -598,11 +598,11 @@ public class MetaEditor extends AbstractAttributeViewExtension {
}
- public static String getMetaItemDisplayName(Environment environment, String name) {
- String displayName = environment.getMessages().metaItemDisplayName(name);
+ public static String getMetaItemDisplayName(Environment environment, String urn) {
+ String displayName = environment.getMessages().metaItemDisplayName(urn.replace(":", ""));
if (isNullOrEmpty(displayName)) {
- displayName = name;
+ displayName = urn;
}
return displayName;
}
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 75ec39d63..04bb13dc6 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
@@ -213,7 +213,7 @@ public class AttributeLinkEditor extends FlowPanel {
// Check item with this name doesn't already exist
boolean canAdd = !converterAttribute.hasMetaItem(item.getName().orElse(null));
if (!canAdd) {
- String metaItemName = getMetaItemDisplayName(environment, MetaItemType.ATTRIBUTE_LINK.name());
+ String metaItemName = getMetaItemDisplayName(environment, MetaItemType.ATTRIBUTE_LINK.getUrn());
showValidationError(attribute.getName().orElse(""), metaItemName, new ValidationFailure(FailureReason.CONVERTER_KEY_DUPLICATION, item.getName().orElse("")));
return false;
}
@@ -266,7 +266,7 @@ public class AttributeLinkEditor extends FlowPanel {
@SuppressWarnings("ParameterCanBeLocal")
protected void showConverterEditorValidationError(String attributeName, String metaItemName, ValidationFailure validationFailure) {
// Replace metaItemName with AttributeLink
- metaItemName = environment.getMessages().metaItemDisplayName(MetaItemType.ATTRIBUTE_LINK.name());
+ metaItemName = environment.getMessages().metaItemDisplayName(MetaItemType.ATTRIBUTE_LINK.getUrn().replace(":", ""));
// Replace meta item validation failures
if (validationFailure != null) {
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 70e61fb78..ead12fa93 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
@@ -190,32 +190,44 @@ commandRequestSent=Sent command request: {0}
attributeValueType=Unknown attribute type
attributeValueType[STRING]=Text
attributeValueType[NUMBER]=Number
-attributeValueType[BOOLEAN]=On/Off toggle
+attributeValueType[INTEGER]=Integer
+attributeValueType[BOOLEAN]=Boolean
+attributeValueType[SWITCH_TOGGLE]=On/Off toggle switch
+attributeValueType[SWITCH_MOMENTARY]=On/Off momentary switch
attributeValueType[OBJECT]=JSON object
attributeValueType[ARRAY]=JSON array
attributeValueType[PERCENTAGE]=Percentage
attributeValueType[LEVEL_UINT8]=Level 0-255
attributeValueType[TIMESTAMP_MILLIS]=Timestamp milliseconds since epoch
attributeValueType[TIMESTAMP_SECONDS]=Timestamp seconds since epoch
+attributeValueType[TIME_SECONDS]=Time seconds
+attributeValueType[TIME_MINUTES]=Time minutes
attributeValueType[DATETIME]=Timestamp in ISO 8601
attributeValueType[COLOR_RGB]=Color RGB
attributeValueType[COLOR_ARGB]=Color ARGB
attributeValueType[COLOR_HEX]=Color HEX
+attributeValueType[SOUND_DB]=Sound (dB)
attributeValueType[TEMPERATURE_CELCIUS]=Temperature in Celcius
attributeValueType[TEMPERATURE_KELVIN]=Temperature in Kelvin
attributeValueType[TEMPERATURE_FAHRENHEIT]=Temperature in Fahrenheit
+attributeValueType[RAINFALL]=Rainfall millimetres per hour
+attributeValueType[BRIGHTNESS_LUX]=Lux brightness
attributeValueType[DISTANCE_M]=Distance in metres
attributeValueType[DISTANCE_CM]=Distance in centimetres
attributeValueType[DISTANCE_MM]=Distance in millimetres
attributeValueType[DISTANCE_IN]=Distance in inch
attributeValueType[DISTANCE_FT]=Distance in feet
attributeValueType[DISTANCE_YARD]=Distance in yard
+attributeValueType[SPEED_MS]=Metres per second
+attributeValueType[SPEED_KPH]=Kilometres per hour
+attributeValueType[SPEED_MPH]=Miles per hour
attributeValueType[CO2_PPM]=CO2 Level in PPM
attributeValueType[HUMIDITY_PERCENTAGE]=Humidity percentage
attributeValueType[HUMIDITY_GPCM]=Humidity in grams per cubic metres
attributeValueType[POWER_WATT]=Power in watt
attributeValueType[POWER_KILOWATT]=Power in kilowatt
attributeValueType[POWER_MEGAWATT]=Power in megawatt
+attributeValueType[POWER_PERCENTAGE]=Power Percentage
attributeValueType[CHARGE_PERCENTAGE]=Charge percentage
attributeValueType[CHARGE_KWH]=Charge in kilowatt-hours
attributeValueType[ENERGY_KWH]=Energy in kilowatt-hours
@@ -223,20 +235,13 @@ attributeValueType[ENERGY_JOULE]=Energy in joule
attributeValueType[ENERGY_MEGAJOULE]=Energy in megajoule
attributeValueType[FLOW_LPM]=Flow in litre per minute
attributeValueType[FLOW_CMPS]=Flow in cubic metres per second
-attributeValueType[FLOW_SCCM]=Flow in cubic centimetres per minute
+attributeValueType[FLOW_CCMPS]=Flow in cubic centimetres per second
attributeValueType[FLOW_CFPS]=Flow in cubic feet per second
attributeValueType[FLOW_GPM]=Flow in gallons per minute
-attributeValueType[RULES_TEMPLATE_FILTER]=Rules template filter
-attributeValueType[SPEED_MS]=Metres per second
-attributeValueType[SPEED_KPH]=Kilometres per hour
-attributeValueType[SPEED_MPH]=Miles per hour
-attributeValueType[TIME_SECONDS]=Time seconds
-attributeValueType[TIME_MINUTES]=Time minutes
-attributeValueType[RAINFALL]=Rainfall millimetres per hour
-attributeValueType[BRIGHTNESS_LUX]=Lux brightness
attributeValueType[DIRECTION_DECIMAL_DEGREES]=Direction in decimal degrees
attributeValueType[GEO_JSON_POINT]=Coordinates
-attributeValueType[POWER_PERCENTAGE]=Power Percentage
+attributeValueType[EMAIL]=Email
+attributeValueType[RULES_TEMPLATE_FILTER]=Rules template filter
validationFailureOnAttribute=Attribute error on ''{0}''
validationFailureOnMetaItem=Meta item error on ''{0}'' meta item ''{1}''
validationFailure=Unknown validation failure.
@@ -319,81 +324,87 @@ valueTypeDisplayName[NUMBER]=Number
valueTypeDisplayName[BOOLEAN]=On/Off toggle
valueTypeDisplayName[STRING]=Text
metaItemDisplayName=
-metaItemDisplayName[PROTOCOL_CONFIGURATION]=Protocol configuration
-metaItemDisplayName[AGENT_LINK]=Agent protocol link
-metaItemDisplayName[ATTRIBUTE_LINK]=Attribute link
-metaItemDisplayName[LABEL]=Label
-metaItemDisplayName[SHOW_ON_DASHBOARD]=Show on dashboard
-metaItemDisplayName[FORMAT]=Format
-metaItemDisplayName[DESCRIPTION]=Description
-metaItemDisplayName[ABOUT]=About
-metaItemDisplayName[READ_ONLY]=Read only
-metaItemDisplayName[ACCESS_RESTRICTED_READ]=Restricted read access
-metaItemDisplayName[ACCESS_RESTRICTED_WRITE]=Restricted write access
-metaItemDisplayName[ACCESS_PUBLIC_READ]=Public read access
-metaItemDisplayName[ACCESS_PUBLIC_WRITE]=Public write access
-metaItemDisplayName[RANGE_MIN]=Min value
-metaItemDisplayName[RANGE_MAX]=Max value
-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_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_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
-metaItemDisplayName[PROTOCOL_DEVICE_NAME]=Controller Device name
-metaItemDisplayName[PROTOCOL_SENSOR_NAME]=Controller Sensor name
-metaItemDisplayName[PROTOCOL_COMMAND_DEVICE_NAME]=Controller Device name for command
-metaItemDisplayName[PROTOCOL_COMMAND_NAME]=Controller Command name
-metaItemDisplayName[PROTOCOL_COMMANDS_MAP]=Controller Commands map
-metaItemDisplayName[PROTOCOL_CONTROLLER_BASE_URI]=Controller Base URI
-metaItemDisplayName[DATA_POINTS_MAX_AGE_DAYS]=Data points max age (days)
+metaItemDisplayName[urnopenremoteassetmetaprotocolConfiguration]=Protocol configuration
+metaItemDisplayName[urnopenremoteassetmetaagentLink]=Agent protocol link
+metaItemDisplayName[urnopenremoteassetmetaattributeLink]=Attribute link
+metaItemDisplayName[urnopenremoteassetmetalabel]=Label
+metaItemDisplayName[urnopenremoteassetmetashowOnDashboard]=Show on dashboard
+metaItemDisplayName[urnopenremoteassetmetaformat]=Format
+metaItemDisplayName[urnopenremoteassetmetadescription]=Description
+metaItemDisplayName[urnopenremoteassetmetaabout]=About
+metaItemDisplayName[urnopenremoteassetmetareadOnly]=Read only
+metaItemDisplayName[urnopenremoteassetmetaaccessRestrictedRead]=Restricted read access
+metaItemDisplayName[urnopenremoteassetmetaaccessRestrictedWrite]=Restricted write access
+metaItemDisplayName[urnopenremoteassetmetaaccessPublicRead]=Public read access
+metaItemDisplayName[urnopenremoteassetmetaaccessPublicWrite]=Public write access
+metaItemDisplayName[urnopenremoteassetmetarangeMin]=Min value
+metaItemDisplayName[urnopenremoteassetmetarangeMax]=Max value
+metaItemDisplayName[urnopenremoteassetmetastep]=Step
+metaItemDisplayName[urnopenremoteassetmetapattern]=Pattern
+metaItemDisplayName[urnopenremoteassetmetastoreDataPoints]=Store data points
+metaItemDisplayName[urnopenremoteassetmetaruleState]=Rule state
+metaItemDisplayName[urnopenremoteassetmetaruleEvent]=Rule event
+metaItemDisplayName[urnopenremoteassetmetaruleEventExpires]=Rule event expires
+metaItemDisplayName[urnopenremoteassetmetadisabled]=Disabled
+metaItemDisplayName[urnopenremoteassetmetaexecutable]=Executable
+metaItemDisplayName[urnopenremoteassetmetaallowedValues]=Allowed values
+metaItemDisplayName[urnopenremoteassetmetadataPointsMaxAgeDays]=Data points max age (days)
+metaItemDisplayName[urnopenremoteprotocolvalueFilters]=Value filters
+metaItemDisplayName[urnopenremoteprotocolpollingMillis]=Polling interval (ms)
+metaItemDisplayName[urnopenremoteprotocolwriteValue]=Write value
+metaItemDisplayName[urnopenremoteprotocolcharset]=Charset
+metaItemDisplayName[urnopenremoteprotocolconvertBinary]=Convert to/from binary string
+metaItemDisplayName[urnopenremoteprotocolconvertHex]=Convert to/from HEX string
+metaItemDisplayName[urnopenremoteprotocolmacroaction]=Macro action
+metaItemDisplayName[urnopenremoteprotocolmacroactionIndex]=Macro action index
+metaItemDisplayName[urnopenremoteprotocolvelbustimeInjectionInterval]=VELBUS time injection (s)
+metaItemDisplayName[urnopenremoteprotocolvelbusSockethost]=VELBUS host
+metaItemDisplayName[urnopenremoteprotocolvelbusSocketPort]=VELBUS port
+metaItemDisplayName[urnopenremoteprotocolvelbusSerialPort]=VELBUS port
+metaItemDisplayName[urnopenremoteprotocolvelbusSerialbaudRate]=VELBUS baudrate
+metaItemDisplayName[urnopenremoteprotocolvelbusdeviceAddress]=VELBUS device address
+metaItemDisplayName[urnopenremoteprotocolvelbusdeviceValueLink]=VELBUS device link
+metaItemDisplayName[urnopenremoteprotocolknxgatewayHost]=KNX gateway host
+metaItemDisplayName[urnopenremoteprotocolknxgatewayPort]=KNX gateway port
+metaItemDisplayName[urnopenremoteprotocolknxuseNAT]=KNX use NAT
+metaItemDisplayName[urnopenremoteprotocolknxconnectionType]=KNX connection type
+metaItemDisplayName[urnopenremoteprotocolknxlocalBusAddress]=KNX local bus address
+metaItemDisplayName[urnopenremoteprotocolknxlocalhost]=KNX local host
+metaItemDisplayName[urnopenremoteprotocolknxactionGA]=KNX actuator group address
+metaItemDisplayName[urnopenremoteprotocolknxstatusGA]=KNX status group address
+metaItemDisplayName[urnopenremoteprotocolknxdpt]=KNX DPT
+metaItemDisplayName[urnopenremoteprotocoltimeraction]=Timer action
+metaItemDisplayName[urnopenremoteprotocoltimercronExpression]=Timer CRON expression
+metaItemDisplayName[urnopenremoteprotocoltimerlink]=Timer value link
+metaItemDisplayName[urnopenremoteprotocolsimulatormode]=Simulator mode
+metaItemDisplayName[urnopenremoteprotocolsimulator]=Simulator write delay (ms)
+metaItemDisplayName[urnopenremoteprotocolsimulatorelement]=Simulator element type
+metaItemDisplayName[urnopenremoteprotocolhttpClientbaseUri]=HTTP base URI
+metaItemDisplayName[urnopenremoteprotocolhttpClientusername]=HTTP basic auth username
+metaItemDisplayName[urnopenremoteprotocolhttpClientpassword]=HTTP basic auth password
+metaItemDisplayName[urnopenremoteprotocolhttpClientoAuthGrant]=HTTP OAuth
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingPath]=HTTP ping path
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingMethod]=HTTP ping method
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingBody]=HTTP ping body
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingHeaders]=HTTP ping headers
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingContentType]=HTTP ping content type
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingMillis]=HTTP ping interval (ms)
+metaItemDisplayName[urnopenremoteprotocolhttpClientpingQueryParameters]=HTTP ping query parameters
+metaItemDisplayName[urnopenremoteprotocolhttpClientpath]=HTTP path
+metaItemDisplayName[urnopenremoteprotocolhttpClientmethod]=HTTP method
+metaItemDisplayName[urnopenremoteprotocolhttpClientbody]=HTTP body
+metaItemDisplayName[urnopenremoteprotocolhttpClientcontentType]=HTTP content type
+metaItemDisplayName[urnopenremoteprotocolhttpClientfollowRedirects]=HTTP follow redirects
+metaItemDisplayName[urnopenremoteprotocolhttpClientqueryParameters]=HTTP query parameters
+metaItemDisplayName[urnopenremoteprotocolhttpClientfailureCodes]=HTTP response failure codes
+metaItemDisplayName[urnopenremoteprotocolhttpClientheaders]=HTTP headers
+metaItemDisplayName[urnopenremoteprotocolhttpClientpagingEnabled]=HTTP paging enabled
+metaItemDisplayName[urnopenremoteprotocolcontrollerClientdeviceName]=Controller device name
+metaItemDisplayName[urnopenremoteprotocolcontrollerClientsensorName]=Controller sensor name
+metaItemDisplayName[urnopenremoteprotocolcontrollerClientcommandDeviceName]=Controller device name for command
+metaItemDisplayName[urnopenremoteprotocolcontrollerClientcommandName]=Controller command name
+metaItemDisplayName[urnopenremoteprotocolcontrollerClientcommandsMap]=Controller commands map
+metaItemDisplayName[urnopenremoteprotocolcontrollerClientbaseUri]=Controller base URI
attributeLinkConverterValues=Converter values
attributeLinkNewConverterValue=New converter value
enterConverterValue=Enter converter value
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java
index 4467a7c4c..052180167 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java
@@ -84,8 +84,8 @@ public class ManagerDemoAgentSetup extends AbstractManagerSetup {
agent.addAttributes(
initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME)
.addMeta(
- new MetaItem(KNXProtocol.META_KNX_GATEWAY_IP, Values.create(knxGatewayIp)),
- new MetaItem(KNXProtocol.META_KNX_LOCAL_IP, Values.create(knxLocalIp))
+ new MetaItem(KNXProtocol.META_KNX_GATEWAY_HOST, Values.create(knxGatewayIp)),
+ new MetaItem(KNXProtocol.META_KNX_LOCAL_HOST, Values.create(knxLocalIp))
)
);
Asset knxDevices = new Asset("KNX Devices", THING, agent, masterRealm);
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
index e6dc9a3b1..09a3343fb 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -58,9 +58,6 @@ public enum AttributeValueType implements AttributeValueDescriptor {
ARRAY("bars", ValueType.ARRAY),
- // TODO Implement "Saved Filter/Searches" properly, see AssetResourceImpl
- RULES_TEMPLATE_FILTER("filter", ValueType.ARRAY),
-
PERCENTAGE("percentage", ValueType.NUMBER,
value -> Values.getNumber(value)
.filter(number -> number < 0 || number > 100)
@@ -202,7 +199,11 @@ public enum AttributeValueType implements AttributeValueDescriptor {
EMAIL("at", ValueType.STRING, value -> Values.getString(value)
.filter(s -> !s.matches("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"))
.map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_EMAIL_FORMAT))
- );
+ ),
+
+ // TODO Implement "Saved Filter/Searches" properly, see AssetResourceImpl
+ RULES_TEMPLATE_FILTER("filter", ValueType.ARRAY);
+
public enum AttributeValueTypeFailureReason implements ValidationFailure.Reason {
ATTRIBUTE_TYPE_VALUE_DOES_NOT_MATCH
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
index ab5e382bd..e96bed0a6 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
@@ -192,6 +192,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
'}';
}
+ @JsIgnore
public static MetaItemDescriptor metaItemFixedBoolean(String urn, Access access, boolean required) {
return new MetaItemDescriptorImpl(
urn,
@@ -208,6 +209,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
null);
}
+ @JsIgnore
public static MetaItemDescriptor metaItemString(String urn, Access access, boolean required, String...allowedValues) {
Value[] values = allowedValues != null && allowedValues.length > 0 ? Arrays.stream(allowedValues).map(Values::create).toArray(Value[]::new) : null;
@@ -226,10 +228,12 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
allowedValues != null ? Arrays.stream(allowedValues).map(Values::create).toArray(Value[]::new) : null);
}
+ @JsIgnore
public static MetaItemDescriptor metaItemString(String urn, Access access, boolean required, String patternRegex, PatternFailure failureMessage) {
return metaItemString(urn, access, required, patternRegex, failureMessage.name());
}
+ @JsIgnore
public static MetaItemDescriptor metaItemString(String urn, Access access, boolean required, String patternRegex, String patternFailureMessage) {
return new MetaItemDescriptorImpl(
urn,
@@ -246,6 +250,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
null);
}
+ @JsIgnore
public static MetaItemDescriptor metaItemInteger(String urn, Access access, boolean required, Integer minValue, Integer maxValue) {
return new MetaItemDescriptorImpl(
urn,
@@ -262,6 +267,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
null);
}
+ @JsIgnore
public static MetaItemDescriptor metaItemInteger(String urn, Access access, boolean required, Integer...allowedValues) {
Value[] values = allowedValues != null && allowedValues.length > 0 ? Arrays.stream(allowedValues).map(Values::create).toArray(Value[]::new) : null;
@@ -280,6 +286,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
values);
}
+ @JsIgnore
public static MetaItemDescriptor metaItemObject(String urn, Access access, boolean required, ObjectValue initialValue) {
return new MetaItemDescriptorImpl(
urn,
@@ -296,6 +303,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
null);
}
+ @JsIgnore
public static MetaItemDescriptor metaItemArray(String urn, Access access, boolean required, ArrayValue initialValue) {
return new MetaItemDescriptorImpl(
urn,
@@ -311,4 +319,27 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
null,
null);
}
+
+ @JsIgnore
+ public static MetaItemDescriptor metaItemAny(
+ String urn,
+ Access access,
+ boolean required,
+ Value initialValue,
+ String patternRegex,
+ String patternFailureMessage) {
+ return new MetaItemDescriptorImpl(
+ urn,
+ ValueType.ANY,
+ access,
+ required,
+ patternRegex,
+ patternFailureMessage,
+ 1,
+ initialValue,
+ false,
+ null,
+ null,
+ null);
+ }
}
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 ccc853f25..3e56b6767 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
@@ -310,7 +310,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
),
new MetaItem(
- Protocol.META_ATTRIBUTE_FILTERS,
+ Protocol.META_VALUE_FILTERS,
Values.createArray().add(new RegexFilter("\\w(\\d+)", 1, 2).toValue().get())
)
),
@@ -322,7 +322,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
),
new MetaItem(
- Protocol.META_ATTRIBUTE_FILTERS,
+ Protocol.META_VALUE_FILTERS,
Values.createArray().add(new SubStringFilter(10, 12).toValue().get())
)
),
@@ -334,7 +334,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
),
new MetaItem(
- Protocol.META_ATTRIBUTE_FILTERS,
+ Protocol.META_VALUE_FILTERS,
Values.createArray()
.add(new SubStringFilter(23).toValue().get())
.add(new RegexFilter("[a-z|\\s]+(\\d+)%\"}", 1, 0).toValue().get())
diff --git a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
index 99afb2e58..71632bbbd 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
@@ -94,8 +94,8 @@ class KNXProtocolTest extends Specification implements ManagerContainerTrait {
knxAgent.setAttributes(
ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME)
.addMeta(
- new MetaItem(KNXProtocol.META_KNX_GATEWAY_IP, Values.create("localhost")),
- new MetaItem(KNXProtocol.META_KNX_LOCAL_IP, Values.create("localhost"))
+ new MetaItem(KNXProtocol.META_KNX_GATEWAY_HOST, Values.create("localhost")),
+ new MetaItem(KNXProtocol.META_KNX_LOCAL_HOST, Values.create("localhost"))
),
ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("knxConfigError1"), KNXProtocol.PROTOCOL_NAME),
ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("knxConfigError2"), KNXProtocol.PROTOCOL_NAME)
diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
index dee4a44b0..04a416577 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
@@ -50,7 +50,6 @@ import javax.ws.rs.HttpMethod
import javax.ws.rs.client.ClientRequestContext
import javax.ws.rs.client.ClientRequestFilter
import javax.ws.rs.core.*
-import java.util.concurrent.TimeUnit
import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration
@@ -494,7 +493,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_poll_slow")),
new MetaItem(HttpClientProtocol.META_POLLING_MILLIS, Values.create(50)), // This is ms in testing
new MetaItem(
- Protocol.META_ATTRIBUTE_FILTERS,
+ Protocol.META_VALUE_FILTERS,
Values.createArray().add(new RegexFilter("\\d+", 0, 0).toValue().get())
)
),
@@ -505,7 +504,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_poll_fast")),
new MetaItem(HttpClientProtocol.META_POLLING_MILLIS, Values.create(40)), // This is ms in testing
new MetaItem(
- Protocol.META_ATTRIBUTE_FILTERS,
+ Protocol.META_VALUE_FILTERS,
Values.createArray().add(new RegexFilter("\\d+", 0, 1).toValue().get())
)
)