100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Rollback forced AttributeType now Optional
Rich Turner82b8f19f6f11
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.javaindex 94445ba86..c0987b077 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java@@ -235,9 +235,9 @@ public abstract class AttributesBrowser// "Blink" the editor so users know there might be a new valueeditor.asWidget().addStyleName(environment.getWidgetStyle().HighlightBackground());- Browser.getWindow().setTimeout(() -> {- editor.asWidget().removeStyleName(environment.getWidgetStyle().HighlightBackground());- }, 250);+ Browser.getWindow().setTimeout(() -> editor+ .asWidget()+ .removeStyleName(environment.getWidgetStyle().HighlightBackground()), 250);// Refresh charts, jump to current time so the new value is visibleFormGroup attributeFormGroup = attributeGroups.get(attribute);@@ -254,7 +254,8 @@ public abstract class AttributesBrowserprotected DatapointBrowser createDatapointBrowser(AssetAttribute attribute) {if (!attribute.isStoreDatapoints())return null;- if (!(attribute.getType() == AttributeType.DECIMAL || attribute.getType() == AttributeType.INTEGER))+ if (!attribute.getType().isPresent()+ || !(attribute.getType().get() == AttributeType.DECIMAL || attribute.getType().get() == AttributeType.INTEGER))return null;return new DatapointBrowser(environment.getMessages(), 650, 220) {@Overridediff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.javaindex 0a2964fed..30cc95865 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java@@ -207,7 +207,7 @@ public abstract class AttributesView<S style = container.getStyle();AttributeEditor attributeEditor;- AttributeType attributeType = attribute.getType();+ AttributeType attributeType = attribute.getType().orElse(AttributeType.STRING);if (attributeType == AttributeType.STRING) {attributeEditor = createStringEditor(attribute, defaultValueItem, style, formGroup);} else if (attributeType == AttributeType.INTEGER) {@@ -226,7 +226,7 @@ public abstract class AttributesView<FormField unsupportedField = new FormField();unsupportedField.add(new FormOutputText(environment.getMessages().unsupportedAttributeType(- attribute.getType().getValue()+ attribute.getType().map(AttributeType::getValue).orElse(null))));return () -> unsupportedField;diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovyindex 9c11983b8..ffe7c7926 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy@@ -586,7 +586,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraidef protectedAttributes = apartment1LivingroomThermostat.getAttributeList()protectedAttributes.size() == 2def currentTemperature = apartment1LivingroomThermostat.getAttribute("currentTemperature")- currentTemperature.get().getType() == AttributeType.DECIMAL+ currentTemperature.get().getType().get() == AttributeType.DECIMALcurrentTemperature.get().getValueAsDecimal() == nullMeta protectedMeta = currentTemperature.get().getMeta()protectedMeta.getAll().size() == 3diff --git a/model/src/main/java/org/openremote/model/Attribute.java b/model/src/main/java/org/openremote/model/Attribute.javaindex b4dc2f4e8..9a18e952d 100644--- a/model/src/main/java/org/openremote/model/Attribute.java+++ b/model/src/main/java/org/openremote/model/Attribute.java@@ -182,12 +182,14 @@ public abstract class Attribute extends AbstractValueTimestampHolder {}protected Attribute(Attribute attribute) {- this(attribute.getName(), attribute.getType(), attribute.getJsonObject());+ this(attribute.getName(), attribute.getType().orElse(null), attribute.getJsonObject());}@Overrideprotected boolean isValidValue(JsonValue value) {- return getType().isValid(value);+ return getType().isPresent()+ ? getType().get().isValid(value)+ : super.isValidValue(value);}public void setName(String name) {@@ -202,17 +204,17 @@ public abstract class Attribute extends AbstractValueTimestampHolder {return jsonObject;}- public AttributeType getType() {+ public Optional<AttributeType> getType() {String typeName = jsonObject.hasKey(TYPE_FIELD_NAME) ? jsonObject.get(TYPE_FIELD_NAME).asString() : null;- return typeName != null ? AttributeType.fromValue(typeName) : AttributeType.NULL;+ return Optional.ofNullable(typeName != null ? AttributeType.fromValue(typeName) : null);}public void setType(AttributeType type) {if (type == null) {- type = AttributeType.NULL;+ return;}- if (getType() == type) {+ if (getType().isPresent() && getType().get() == type) {return;}@@ -399,6 +401,7 @@ public abstract class Attribute extends AbstractValueTimestampHolder {@Overridepublic boolean isValid() {- return super.isValid() && ATTRIBUTE_NAME_VALIDATOR.test(name) && getValue() != null && (getValue().getType() == JsonType.NULL || getValue().getType() == getType().getJsonType());+ // TODO: Should value validity be part of the isValid check?+ return super.isValid() && ATTRIBUTE_NAME_VALIDATOR.test(name) && getType().isPresent();}}diff --git a/model/src/main/java/org/openremote/model/AttributeType.java b/model/src/main/java/org/openremote/model/AttributeType.javaindex 4fb3ca34b..18939b4c0 100644--- a/model/src/main/java/org/openremote/model/AttributeType.java+++ b/model/src/main/java/org/openremote/model/AttributeType.java@@ -32,7 +32,7 @@ import elemental.json.JsonValue;*/public enum AttributeType {- NULL("Null", JsonType.NULL),+ //NULL("Null", JsonType.NULL), // TODO: Decide if 'Null' is a valid AttributeTypeSTRING("String", JsonType.STRING),OBJECT("Object", JsonType.OBJECT),INTEGER("Integer", JsonType.NUMBER),diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.javaindex 23d4f4236..bd06fae35 100644--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java@@ -27,7 +27,6 @@ import org.openremote.model.AttributeType;import org.openremote.model.util.JsonUtil;import java.util.Date;-import java.util.Optional;/*** An asset attribute value update, capturing that asset state at a point in time.@@ -227,7 +226,7 @@ public abstract class AbstractAssetUpdate {}public AttributeType getAttributeType() {- return attribute.getType();+ return attribute.getType().orElse(null);}public AttributeEvent getStateEvent() {diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex 03e159020..2cdf64858 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -539,8 +539,7 @@ public class Asset implements IdentifiableEntity {}public boolean hasAttribute(String name, AttributeType type) {- Optional<AssetAttribute> attribute = getAttribute(name);- return attribute.isPresent() && attribute.get().getType() == type;+ return getFromJson(id, name, type).apply(getAttributes()).isPresent();}public boolean hasAttribute(String name, JsonValue value) {diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AssetAttribute.javaindex 5b7324247..5337b44f4 100644--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java@@ -144,7 +144,8 @@ public class AssetAttribute extends Attribute {return Optional.empty();}AssetAttribute attribute = new AssetAttribute(assetId, attributeName, jsonObject.getObject(attributeName));- return attribute.getType() == type ? Optional.of((attribute)) : Optional.empty();+ Optional<AttributeType> attributeType = attribute.getType();+ return attributeType.isPresent() && attributeType.get() == type ? Optional.of((attribute)) : Optional.empty();};}@@ -184,7 +185,7 @@ public class AssetAttribute extends Attribute {final protected Optional<String> assetId;public static AssetAttribute createEmpty() {- return new AssetAttribute(null, AttributeType.NULL, Json.createNull());+ return new AssetAttribute(null, Json.createObject());}public AssetAttribute(String name) {