Skip to content
Permalink
Browse files

Minor

  • Loading branch information
richturner committed Dec 20, 2019
1 parent 551a68e commit bf18099b54ba03700f8642d3238feb995e413635
@@ -132,6 +132,11 @@ public String getAssignToUserName() {
*/
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.
*/
@@ -22,8 +22,6 @@
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.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 @@
);

/**
* 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 @@
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<>();

@@ -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 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>> {

@@ -29,7 +29,6 @@
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;
@@ -292,6 +292,12 @@ public boolean deleteAsset(String assetId) {
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);
@@ -55,7 +55,7 @@
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 void start(Container container) throws Exception {

getFirstRunMillis(timerService.getNow()),
Duration.ofDays(1).toMillis());

}
}

@@ -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 @@

@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();
}
}
@@ -44,6 +44,11 @@ public AttributeDescriptorImpl(String attributeName, AttributeValueDescriptor va
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,
@@ -146,6 +146,8 @@

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 @@

ASSET_STATUS("heart-pulse", ValueType.STRING),

BEARING("compass", ValueType.NUMBER),

CALENDAR_EVENT("calendar", ValueType.OBJECT);

@@ -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 @@
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;
@@ -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 @@
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;
@@ -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,
@@ -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

0 comments on commit bf18099

Please sign in to comment.
You can’t perform that action at this time.