Skip to content

armgit / core

Public Imported from GitHub
0

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

Minor

Rich Turnerbf18099b54ba
diff --git a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java
index d4be2c5d1..00d9fb95f 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java
@@ -132,6 +132,11 @@ public interface ProtocolAssetService extends ContainerService {
*/
boolean deleteAsset(String assetId);
+ /**
+ * Get asset from the store by ID.
+ */
+ Asset findAsset(String assetId);
+
/**
* Protocols can send arbitrary attribute change events for regular processing.
*/
diff --git a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIoClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIoClientProtocol.java
index 74e412075..49fc84ed4 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIoClientProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIoClientProtocol.java
@@ -22,8 +22,6 @@ package org.openremote.agent.protocol.io;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelInboundHandler;
-import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.FixedLengthFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
@@ -39,11 +37,9 @@ import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.attribute.MetaItemDescriptor;
import org.openremote.model.syslog.SyslogCategory;
-import org.openremote.model.util.Pair;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
-import java.net.SocketAddress;
import java.nio.charset.Charset;
import java.util.*;
import java.util.function.BiConsumer;
@@ -72,7 +68,7 @@ public abstract class AbstractIoClientProtocol<T, U extends IoClient<T>> extends
);
/**
- * Supplies decoders that convert from ByteBuf to
+ * Supplies a set of encoders/decoders that convert from/to {@link String} to/from {@link ByteBuf} based on the generic protocol {@link MetaItem}s
*/
public static Supplier<ChannelHandler[]> getGenericStringEncodersAndDecoders(AbstractNettyIoClient<String, ?> client, AssetAttribute protocolConfiguration) {
@@ -173,17 +169,6 @@ public abstract class AbstractIoClientProtocol<T, U extends IoClient<T>> extends
return encoderDecoderProvider;
}
- public static <T, U extends SocketAddress> Pair<ChannelOutboundHandler[], ChannelInboundHandler[]> createBasicEncoderAndDecoder(Class<T> typeClazz, AbstractNettyIoClient<T, U> client, BiConsumer<T, ByteBuf> encoder, BiConsumer<ByteBuf, List<T>> decoder) {
- return new Pair<>(
- new ChannelOutboundHandler[] {
- new AbstractNettyIoClient.MessageToByteEncoder<>(typeClazz, client, encoder)
- },
- new ChannelInboundHandler[] {
- new AbstractNettyIoClient.ByteToMessageDecoder<>(client, decoder)
- }
- );
- }
-
public static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, AbstractIoClientProtocol.class);
protected final Map<AttributeRef, ProtocolIoClient<T, U>> protocolIoClientMap = new HashMap<>();
diff --git a/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java
index 65fdeb582..659dc6c49 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java
@@ -20,7 +20,6 @@
package org.openremote.agent.protocol.udp;
import org.openremote.agent.protocol.io.AbstractIoClientProtocol;
-import org.openremote.agent.protocol.io.IoClient;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.attribute.MetaItemDescriptor;
import org.openremote.model.syslog.SyslogCategory;
@@ -33,13 +32,12 @@ import java.util.logging.Logger;
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.metaItemFixedBoolean;
import static org.openremote.model.attribute.MetaItemDescriptorImpl.metaItemInteger;
import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;
/**
- * This is an abstract UDP client protocol for communicating with UDP servers; concrete implementations must provide
- * an {@link IoClient<T> for handling over the wire communication}.
+ * This is an abstract UDP client protocol for communicating with UDP servers; concrete implementations must implement
+ * {@link #getEncoderDecoderProvider} to provide encoders/decoders for messages of type &lt;T&gt;.
*/
public abstract class AbstractUdpClientProtocol<T> extends AbstractIoClientProtocol<T, UdpIoClient<T>> {
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 24c617dad..090908d08 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
@@ -29,7 +29,6 @@ import org.openremote.model.syslog.SyslogCategory;
import org.openremote.model.util.Pair;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueFilter;
-import org.openremote.model.value.Values;
import java.util.*;
import java.util.function.Consumer;
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index f46cf5411..0524060b0 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -292,6 +292,12 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
return assetStorageService.delete(Collections.singletonList(assetId));
}
+ @Override
+ public Asset findAsset(String assetId) {
+ LOG.fine("Getting protocol-provided: " + assetId);
+ return assetStorageService.find(assetId);
+ }
+
@Override
public void sendAttributeEvent(AttributeEvent attributeEvent) {
assetProcessingService.sendAttributeEvent(attributeEvent);
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
index 127e5e9f7..b96bbb22a 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -55,7 +55,7 @@ import static java.util.stream.Collectors.toList;
public class AssetDatapointService implements ContainerService, AssetUpdateProcessor {
public static final String DATA_POINTS_MAX_AGE_DAYS = "DATA_POINTS_MAX_AGE_DAYS";
- public static final String DATA_POINTS_MAX_AGE_DAYS_DEFAULT = "30";
+ public static final String DATA_POINTS_MAX_AGE_DAYS_DEFAULT = "31";
private static final Logger LOG = Logger.getLogger(AssetDatapointService.class.getName());
protected PersistenceService persistenceService;
protected AssetStorageService assetStorageService;
@@ -102,7 +102,6 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
getFirstRunMillis(timerService.getNow()),
Duration.ofDays(1).toMillis());
-
}
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
index 4521f8a47..701aa8844 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
@@ -20,10 +20,14 @@
package org.openremote.model.asset;
import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.attribute.AttributeDescriptor;
+import java.util.Arrays;
+import java.util.Optional;
+
/**
* Describes an {@link Asset} that can be added to the manager; the {@link #getType()} is the unique identifier.
* <p>
@@ -36,14 +40,30 @@ public interface AssetDescriptor {
@JsonProperty
String getName();
+
@JsonProperty
String getType();
+
@JsonProperty
String getIcon();
+
@JsonProperty
String getColor();
+
@JsonProperty
boolean getAccessPublicRead();
+
@JsonProperty
AttributeDescriptor[] getAttributeDescriptors();
+
+ @JsonIgnore
+ static Optional<AttributeDescriptor> getAttributeDescriptor(AssetDescriptor descriptor, String attributeName) {
+ if (descriptor == null || descriptor.getAttributeDescriptors() == null) {
+ return Optional.empty();
+ }
+
+ return Arrays.stream(descriptor.getAttributeDescriptors())
+ .filter(ad -> ad.getAttributeName().equals(attributeName))
+ .findFirst();
+ }
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java
index fcc9d370f..285b6f618 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java
@@ -44,6 +44,11 @@ public class AttributeDescriptorImpl implements AttributeDescriptor {
this(attributeName, valueDescriptor, initialValue, (MetaItemDescriptor[]) null);
}
+ @JsIgnore
+ public AttributeDescriptorImpl(AttributeDescriptor ad, MetaItemDescriptor... metaItemDescriptors) {
+ this(ad.getAttributeName(), ad.getValueDescriptor(), ad.getInitialValue(), metaItemDescriptors);
+ }
+
@JsonCreator
@JsConstructor
public AttributeDescriptorImpl(@JsonProperty("attributeName") String attributeName,
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 0fe2e6350..cb42e5715 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -146,6 +146,8 @@ public enum AttributeValueType implements AttributeValueDescriptor {
SPEED_MPH("circle", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f mi/h"))),
+ SPEED_KNOTS("circle", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f knots"))),
+
CO2_PPM("leaf", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%4d ppm"))),
HUMIDITY_PERCENTAGE("water", ValueType.NUMBER, value -> Values.getNumber(value)
@@ -206,6 +208,7 @@ public enum AttributeValueType implements AttributeValueDescriptor {
ASSET_STATUS("heart-pulse", ValueType.STRING),
+ BEARING("compass", ValueType.NUMBER),
CALENDAR_EVENT("calendar", ValueType.OBJECT);
diff --git a/model/src/main/java/org/openremote/model/calendar/CalendarEvent.java b/model/src/main/java/org/openremote/model/calendar/CalendarEvent.java
index a88f43429..d6fb0dede 100644
--- a/model/src/main/java/org/openremote/model/calendar/CalendarEvent.java
+++ b/model/src/main/java/org/openremote/model/calendar/CalendarEvent.java
@@ -20,6 +20,7 @@
package org.openremote.model.calendar;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
import org.openremote.model.asset.Asset;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
@@ -82,7 +83,7 @@ public class CalendarEvent {
protected RecurrenceRule recurrence;
@JsonCreator
- public CalendarEvent(Date start, Date end, RecurrenceRule recurrence) {
+ public CalendarEvent(@JsonProperty("start") Date start, @JsonProperty("end") Date end, @JsonProperty("recurrence") RecurrenceRule recurrence) {
this.start = start;
this.end = end;
this.recurrence = recurrence;
diff --git a/model/src/main/java/org/openremote/model/calendar/RecurrenceRule.java b/model/src/main/java/org/openremote/model/calendar/RecurrenceRule.java
index e6ba39f4c..efc6fb115 100644
--- a/model/src/main/java/org/openremote/model/calendar/RecurrenceRule.java
+++ b/model/src/main/java/org/openremote/model/calendar/RecurrenceRule.java
@@ -19,6 +19,8 @@
*/
package org.openremote.model.calendar;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
import org.openremote.model.util.EnumUtil;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
@@ -42,7 +44,8 @@ public class RecurrenceRule {
protected Integer count;
protected Date until;
- public RecurrenceRule(Frequency frequency, Integer interval, Integer count, Date until) {
+ @JsonCreator
+ public RecurrenceRule(@JsonProperty("frequency") Frequency frequency, @JsonProperty("interval") Integer interval, @JsonProperty("count") Integer count, @JsonProperty("until") Date until) {
this.frequency = frequency;
this.interval = interval;
this.count = count;
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 1e424f2a9..d659f9049 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
@@ -406,7 +406,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
),
new MetaItem(
HttpClientProtocol.META_PROTOCOL_PING_MILLIS,
- Values.create(100) // Note for testing time unit is set to milliseconds
+ Values.create(100)
),
new MetaItem(
HttpClientProtocol.META_PROTOCOL_PING_METHOD,
diff --git a/test/src/test/groovy/org/openremote/test/protocol/udp/UdpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/udp/UdpClientProtocolTest.groovy
index 56a5697fb..75f9e5abb 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/udp/UdpClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/udp/UdpClientProtocolTest.groovy
@@ -131,7 +131,7 @@ class UdpClientProtocolTest extends Specification implements ManagerContainerTra
and: "the agent is added to the asset service"
agent = assetStorageService.merge(agent)
- then: "the protocol should authenticate and start pinging the server and the connection status should become CONNECTED"
+ then: "the protocol should become CONNECTED"
conditions.eventually {
def status = agentService.getProtocolConnectionStatus(new AttributeRef(agent.id, "protocolConfig"))
assert status == ConnectionStatus.CONNECTED