Skip to content
Permalink
Browse files

GWT jackson updates/bug fixes

  • Loading branch information...
richturner committed Aug 13, 2019
1 parent 146b461 commit c5776bbb2c22cd6040213fbe2cc8ab088cd40f29
@@ -54,8 +54,12 @@ private Long getValueTimestampInternal() {
*/
@JsonProperty
@SuppressWarnings("unchecked")
public void setValueTimestamp(long timestamp) {
getObjectValue().put(VALUE_TIMESTAMP_FIELD_NAME, Values.create(timestamp));
public void setValueTimestamp(Long timestamp) {
if (timestamp == null) {
clearTimestamp();
} else {
getObjectValue().put(VALUE_TIMESTAMP_FIELD_NAME, Values.create(timestamp));
}
}

@Override
@@ -19,7 +19,9 @@
*/
package org.openremote.model.asset;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.openremote.model.AbstractValueHolder;
import org.openremote.model.ValidationFailure;
import org.openremote.model.attribute.*;
@@ -120,6 +122,21 @@ public AssetAttribute(String assetId, String name, AttributeValueType type, Valu
setAssetId(assetId);
}

@JsonCreator
private AssetAttribute(@JsonProperty("assetId") String assetId,
@JsonProperty("name") String name,
@JsonProperty("type") AttributeValueDescriptor type,
@JsonProperty("meta") List<MetaItem> metaItems,
@JsonProperty("value") Value value,
@JsonProperty("timestamp") Long timestamp) {
super(name, type, value);
setValueTimestamp(timestamp);
if (assetId != null) {
setAssetId(assetId);
}
setMeta(metaItems);
}

public Optional<String> getAssetId() {
return Optional.ofNullable(assetId);
}
@@ -155,18 +172,26 @@ public AttributeRef getReferenceOrThrow() {
return super.getMetaItemValidationFailures(item, metaItemDescriptor);
}

@JsonIgnore
@Override
public AssetAttribute setMeta(Meta meta) {
super.setMeta(meta);
return this;
}

@JsonIgnore
@Override
public AssetAttribute setMeta(MetaItem... meta) {
super.setMeta(meta);
return this;
}

@JsonProperty("meta")
@Override
public void setMeta(List<MetaItem> metaItems) {
super.setMeta(metaItems);
}

public AssetAttribute addMeta(MetaItem... meta) {
if (meta != null) {
getMeta().addAll(Arrays.asList(meta));
@@ -114,6 +114,11 @@ public void clearName() {
return getObjectValue().getString(TYPE_FIELD_NAME).flatMap(AssetModelUtil::getAttributeValueDescriptor);
}

@JsonProperty("type")
private AttributeValueDescriptor getTypeInternal() {
return getType().orElse(null);
}

/**
* The below is used in a sufficient number of places to provide it here as a utility method
* with a standardised exception message.
@@ -123,6 +128,7 @@ public AttributeValueDescriptor getTypeOrThrow() {
return getType().orElseThrow(() -> new IllegalStateException("Attribute doesn't have a type"));
}

@JsonProperty
public void setType(AttributeValueDescriptor type) {
Objects.requireNonNull(type);
getObjectValue().put(TYPE_FIELD_NAME, Values.create(type.getName()));
@@ -186,6 +192,18 @@ public boolean hasMetaItem(HasUniqueResourceName metaName) {
return getMetaItem(hasUniqueResourceName.getUrn());
}

@JsonIgnore
public Attribute setMeta(Meta meta) {
setMeta((List<MetaItem>) meta);
return this;
}

@JsonIgnore
public Attribute setMeta(MetaItem... meta) {
setMeta(Arrays.asList(meta));
return this;
}

@JsonProperty("meta")
public void setMeta(List<MetaItem> metaItems) {
Meta meta;
@@ -203,16 +221,6 @@ public void setMeta(List<MetaItem> metaItems) {
getObjectValue().put(META_FIELD_NAME, meta.getArrayValue());
}

public Attribute setMeta(Meta meta) {
setMeta((List<MetaItem>) meta);
return this;
}

public Attribute setMeta(MetaItem... meta) {
setMeta(Arrays.asList(meta));
return this;
}

@Override
public List<ValidationFailure> getValidationFailures() {
return getValidationFailures(true);
@@ -227,8 +235,9 @@ public Attribute setMeta(MetaItem... meta) {
if (!getType().isPresent())
failures.add(new ValidationFailure(ATTRIBUTE_TYPE_MISSING));

if (!getValueTimestamp().isPresent())
failures.add(new ValidationFailure(ATTRIBUTE_VALUE_TIMESTAMP_MISSING));
// Timestamp can be null to be set by the server
// if (!getValueTimestamp().isPresent())
// failures.add(new ValidationFailure(ATTRIBUTE_VALUE_TIMESTAMP_MISSING));

// Value can be empty, if it's not it must validate with the type
getValue().flatMap(value ->

0 comments on commit c5776bb

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