Skip to content

armgit / core

Public Imported from GitHub
0

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

Improved asset attributes and meta item validation in manager UI

Christian Bauer86695f8eb9fd
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
index 13e1831c7..9ff6ea77c 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
@@ -27,6 +27,7 @@ import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.message.MessageBrokerSetupService;
import org.openremote.container.timer.TimerService;
import org.openremote.model.AbstractValueHolder;
+import org.openremote.model.HasUniqueResourceName;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
import org.openremote.model.asset.agent.AgentLink;
@@ -260,7 +261,7 @@ public abstract class AbstractProtocol implements Protocol {
* Update a linked protocol configuration; allows protocols to reconfigure their
* own protocol configurations to persist changing data e.g. authorization tokens.
*/
- protected void updateLinkedProtocolConfiguration(AssetAttribute protocolConfiguration, HasMetaName metaName, MetaItem... newMetaItem) {
+ protected void updateLinkedProtocolConfiguration(AssetAttribute protocolConfiguration, HasUniqueResourceName metaName, MetaItem... newMetaItem) {
updateLinkedProtocolConfiguration(protocolConfiguration, metaName.getUrn(), newMetaItem);
}
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/trigger/TriggerProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/trigger/TriggerProtocol.java
index 24405899e..7f656d5d6 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/trigger/TriggerProtocol.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/trigger/TriggerProtocol.java
@@ -42,11 +42,11 @@ import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
* <p>
* A trigger is defined by creating a {@link TriggerConfiguration} attribute on an
* agent. A trigger consists of:
- * <p>
- * Trigger Type {@link TriggerType}
- * Trigger Value ({@link TriggerType#TIME} = CRON EXPRESSION, {@link TriggerType#ATTRIBUTE} = {@link AttributeRef})
- * Trigger Action {@link AttributeState} that should be sent when triggered
- * <p>
+ * <ul>
+ * <li>{@link TriggerType}</li>
+ * <li>Trigger Value: {@link TriggerType#TIME} = CRON EXPRESSION or {@link TriggerType#ATTRIBUTE} = {@link AttributeRef}</li>
+ * <li>Trigger Action {@link AttributeState} that should be sent when triggered</li>
+ * </ul>
* {@link AssetAttribute}s can link to time triggers to read/write the trigger time and/or enable/disable
* the trigger.
* <p>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
index 3486d34cb..9a5213b86 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
@@ -191,6 +191,10 @@ public class AssetEditActivity
public void update() {
view.setFormBusy(true);
clearViewMessages();
+ if (attributesEditor != null && !attributesEditor.validateAttributes()) {
+ view.setFormBusy(false);
+ return;
+ }
readFromView();
environment.getRequestService().execute(
assetMapper,
@@ -211,6 +215,10 @@ public class AssetEditActivity
public void create() {
view.setFormBusy(true);
clearViewMessages();
+ if (attributesEditor != null && !attributesEditor.validateAttributes()) {
+ view.setFormBusy(false);
+ return;
+ }
readFromView();
environment.getRequestService().execute(
assetMapper,
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.java
index 8683a8958..87d2c2d58 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
@@ -31,10 +31,11 @@ import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.ReadAssetAttributesEvent;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.attribute.AttributeExecuteStatus;
-import org.openremote.model.attribute.AttributeType;
+import org.openremote.model.attribute.AttributeState;
import org.openremote.model.datapoint.DatapointInterval;
import org.openremote.model.datapoint.NumberDatapoint;
import org.openremote.model.event.bus.EventRegistration;
+import org.openremote.model.value.ValueType;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -278,20 +279,21 @@ public abstract class AttributesBrowser
}
protected void writeAttributeValue(AssetAttribute attribute) {
+ if (!validateAttribute(attribute, true)) {
+ return;
+ }
+
attribute
- .getStateEvent()
- .map(state -> {
- environment.getEventService().dispatch(state);
+ .getReference()
+ .map(attributeRef -> new AttributeState(attributeRef, attribute.getValue().orElse(null)))
+ .map(attributeState -> new AttributeEvent(attributeState, System.currentTimeMillis())) // Event time is browser time
+ .ifPresent(attributeEvent -> {
+ environment.getEventService().dispatch(attributeEvent);
if (attribute.isExecutable()) {
- showSuccess(container.getMessages().commandRequestSent(state.getAttributeName()));
+ showSuccess(container.getMessages().commandRequestSent(attributeEvent.getAttributeName()));
} else {
- showSuccess(container.getMessages().attributeWriteSent(state.getAttributeName()));
+ showSuccess(container.getMessages().attributeWriteSent(attributeEvent.getAttributeName()));
}
- return state;
- })
- .orElseGet(() -> {
- showValidationError("Attribute is not valid");
- return null;
});
}
@@ -332,7 +334,7 @@ public abstract class AttributesBrowser
}
protected DatapointBrowser createDatapointBrowser(AssetAttribute attribute) {
- if (attribute.isStoreDatapoints() && (isAttributeTypeEqualTo(attribute, AttributeType.DECIMAL) || isAttributeTypeEqualTo(attribute, AttributeType.INTEGER))) {
+ if (attribute.isStoreDatapoints() && isAttributeTypeEqualTo(attribute, ValueType.NUMBER)) {
return new DatapointBrowser(environment.getMessages(), 580, 220) {
@Override
protected void queryDatapoints(DatapointInterval interval,
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
index f2c1b9a4f..20c494e10 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
@@ -25,6 +25,7 @@ import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.IsWidget;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.widget.*;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
import org.openremote.model.attribute.Attribute;
@@ -67,7 +68,7 @@ public class AttributesEditor
}
protected FormLabel createAttributeLabel(AssetAttribute attribute) {
- FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 30));
+ FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 30));
formLabel.setIcon("edit");
formLabel.addStyleName("larger");
return formLabel;
@@ -136,14 +137,22 @@ public class AttributesEditor
addButton.setText(container.getMessages().addAttribute());
addButton.setIcon("plus");
addButton.addClickHandler(clickEvent -> {
- if (attribute.isValid()) {
+
+ // Must initialize timestamp for proper attribute state (here it
+ // means: "When was the initial 'empty' attribute value state created?")
+ attribute.setValueTimestamp();
+
+ List<ValidationFailure> failures = attribute.getValidationFailures();
+ if (failures.isEmpty()) {
formGroup.setError(false);
getAttributes().add(attribute);
showInfo(environment.getMessages().attributeAdded(attribute.getName().get()));
build();
} else {
formGroup.setError(true);
- showValidationError(environment.getMessages().enterNameAndSelectType());
+ for (ValidationFailure failure : failures) {
+ showValidationError(attribute.getLabelOrName().orElse(null), failure);
+ }
}
});
formGroupActions.add(addButton);
@@ -168,6 +177,7 @@ public class AttributesEditor
nameInput.addValueChangeHandler(event -> {
if (!ATTRIBUTE_NAME_VALIDATOR.test(event.getValue())) {
formGroup.setError(true);
+ attribute.clearName();
showValidationError(environment.getMessages().invalidAttributeName());
} else {
formGroup.setError(false);
@@ -179,14 +189,16 @@ public class AttributesEditor
FormListBox typeListBox = new FormListBox();
typeListBox.addItem(environment.getMessages().selectType());
for (AttributeType attributeType : AttributeType.values()) {
- typeListBox.addItem(attributeType.getDisplayName());
+ typeListBox.addItem(environment.getMessages().attributeType(attributeType.name()));
}
typeListBox.addChangeHandler(event -> {
- AttributeType attributeType =
- typeListBox.getSelectedIndex() > 0
- ? AttributeType.values()[typeListBox.getSelectedIndex() - 1]
- : null;
- attribute.setTypeAndClearValue(attributeType);
+ if (typeListBox.getSelectedIndex() > 0) {
+ attribute.setTypeAndClearValue(
+ AttributeType.values()[typeListBox.getSelectedIndex() - 1]
+ );
+ } else {
+ attribute.clearType();
+ }
});
formField.add(typeListBox);
@@ -236,11 +248,14 @@ public class AttributesEditor
FormField formField = new FormField();
// Determine editor based on value type
- if (!item.getValue().isPresent())
- continue;
- ValueType valueType = item.getValue().get().getType();
- formField.add(createEditor(item, valueType, false, formGroup));
- formGroup.addFormField(formField);
+ if (item.getValue().isPresent()) {
+ ValueType valueType = item.getValue().get().getType();
+ formField.add(createEditor(item, valueType, false, formGroup));
+ formGroup.addFormField(formField);
+ } else {
+ formField.add(noValueItemEditor(item));
+ formGroup.addFormField(formField);
+ }
FormGroupActions formGroupActions = new FormGroupActions();
@@ -249,6 +264,7 @@ public class AttributesEditor
deleteButton.setIcon("remove");
int index = i;
deleteButton.addClickHandler(clickEvent -> {
+ attributeGroups.get(attribute).setErrorInExtension(false);
attribute.getMeta().remove(index);
buildItemList();
});
@@ -277,7 +293,12 @@ public class AttributesEditor
addButton.setText(container.getMessages().addItem());
addButton.setIcon("plus");
addButton.addClickHandler(clickEvent -> {
- if (item.isValid()) {
+
+ // We ask the attribute for validation failures instead of the
+ // item, because the item must be valid in its context
+ List<ValidationFailure> failures = attribute.getMetaItemValidationFailures(item);
+
+ if (failures.isEmpty()) {
itemNameEditorGroup.setError(false);
itemValueEditorGroup.setError(false);
attribute.getMeta().add(item);
@@ -286,7 +307,9 @@ public class AttributesEditor
} else {
itemNameEditorGroup.setError(true);
itemValueEditorGroup.setError(true);
- showValidationError(environment.getMessages().enterNameAndValue());
+ for (ValidationFailure failure : failures) {
+ showValidationError(item.getName().orElse(null), failure);
+ }
}
});
formGroupActions.add(addButton);
@@ -297,36 +320,32 @@ public class AttributesEditor
IsWidget editor;
AttributesEditor.Style style = container.getStyle();
- Consumer<String> errorConsumer = msg -> {
- formGroup.setError(true);
- showValidationError(msg);
- };
+
// For some meta items we know if we can edit them or not... custom items are always editable
- Boolean isEditable = AssetMeta.isEditable(item.getName().orElse(null));
+ boolean isEditable = item.getName().map(AssetMeta::isEditable).orElse(forceEditable);
- // TODO: We should support more JSON types, and have special editors for well-known meta items
- // Default to STRING editor if value is empty/no type available
- if (valueType == null || valueType.equals(ValueType.STRING)) {
+ // Validation failure of meta item marks the attribute form extension as error state
+ Consumer<Boolean> resultConsumer = !forceEditable
+ ? success -> attributeGroups.get(attribute).setErrorInExtension(!success)
+ : null;
+
+ if (valueType.equals(ValueType.STRING)) {
String currentValue = item.getValue().map(Object::toString).orElse(null);
- Consumer<String> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
- formGroup.setError(false);
- item.setValue(Values.create(value));
- } : null;
+ Consumer<String> updateConsumer = isEditable
+ ? rawValue -> STRING_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null),formGroup, item, resultConsumer, rawValue))
+ : null;
editor = createStringEditorWidget(style, currentValue, Optional.empty(), updateConsumer);
} else if (valueType.equals(ValueType.NUMBER)) {
String currentValue = item.getValue().map(Object::toString).orElse(null);
- Consumer<String> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
- Double decimalValue = Double.valueOf(value);
- formGroup.setError(false);
- item.setValue(Values.create(decimalValue));
- } : null;
- editor = createDecimalEditorWidget(style, currentValue, Optional.empty(), updateConsumer, errorConsumer);
+ Consumer<String> updateConsumer = isEditable
+ ? rawValue -> TO_DOUBLE_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
+ : null;
+ editor = createDecimalEditorWidget(style, currentValue, Optional.empty(), updateConsumer);
} else if (valueType.equals(ValueType.BOOLEAN)) {
- Boolean currentValue = item.getValueAsBoolean().orElse(false);
- Consumer<Boolean> updateConsumer = isEditable == null || isEditable || forceEditable ? value -> {
- formGroup.setError(false);
- item.setValue(Values.create(value));
- } : null;
+ Boolean currentValue = item.getValueAsBoolean().orElse(null);
+ Consumer<Boolean> updateConsumer = isEditable
+ ? rawValue -> BOOLEAN_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
+ : null;
editor = createBooleanEditorWidget(style, currentValue, Optional.empty(), updateConsumer);
} else {
FormField unsupportedField = new FormField();
@@ -338,6 +357,16 @@ public class AttributesEditor
return editor;
}
+ /**
+ * This should actually never be called as we don't allow storing of empty meta items. But
+ * because we don't have proper database constraints, who knows...
+ */
+ protected IsWidget noValueItemEditor(MetaItem item) {
+ FormField field = new FormField();
+ field.add(new FormOutputText(environment.getMessages().emptyMetaItem()));
+ return () -> field;
+ }
+
protected FormGroup createItemNameEditor(MetaItem item, FormListBox typeListBox) {
FormGroup formGroup = new FormGroup();
diff --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.java
index 805c7e268..f4731bb3a 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
@@ -33,11 +33,14 @@ import org.openremote.manager.client.util.CollectionsUtil;
import org.openremote.manager.client.widget.*;
import org.openremote.model.AbstractValueHolder;
import org.openremote.model.Constants;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
import org.openremote.model.attribute.AttributeType;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.util.TextUtil;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueType;
import org.openremote.model.value.Values;
import java.util.*;
@@ -70,15 +73,102 @@ public abstract class AttributesView<
public interface AttributeEditor extends IsWidget {
}
+ public class ValueUpdate<T> {
+
+ final String fieldLabel;
+ final FormGroup formGroup;
+ final AbstractValueHolder valueHolder;
+ final Consumer<Boolean> resultConsumer;
+ final T rawValue;
+
+ public ValueUpdate(String fieldLabel, FormGroup formGroup, AbstractValueHolder valueHolder, Consumer<Boolean> resultConsumer, T rawValue) {
+ this.fieldLabel = fieldLabel;
+ this.formGroup = formGroup;
+ this.valueHolder = valueHolder;
+ this.resultConsumer = resultConsumer;
+ this.rawValue = rawValue;
+ }
+ }
+
+ public abstract class ValueUpdater<T> implements Consumer<ValueUpdate<T>> {
+
+ @Override
+ public void accept(ValueUpdate<T> valueUpdate) {
+ valueUpdate.formGroup.setError(false);
+ List<ValidationFailure> failures = new ArrayList<>();
+ try {
+ valueUpdate.valueHolder.setValue(
+ valueUpdate.rawValue != null ? createValue(valueUpdate.rawValue) : null
+ );
+ failures.addAll(valueUpdate.valueHolder.getValidationFailures());
+ } catch (IllegalArgumentException ex) {
+ failures.add(ex::getMessage);
+ }
+ if (!failures.isEmpty()) {
+ valueUpdate.formGroup.setError(true);
+ for (ValidationFailure failure : failures) {
+ showValidationError(valueUpdate.fieldLabel, failure);
+ }
+ if (valueUpdate.resultConsumer != null) {
+ valueUpdate.resultConsumer.accept(false);
+ }
+ }
+ if (valueUpdate.resultConsumer != null) {
+ valueUpdate.resultConsumer.accept(failures.isEmpty());
+ }
+ }
+
+ abstract Value createValue(T rawValue) throws IllegalArgumentException;
+ }
+
+ public enum ConversionValidationFailure implements ValidationFailure {
+ NOT_A_VALID_INTEGER,
+ NOT_A_VALID_DECIMAL
+ }
+
+ public final ValueUpdater<String> STRING_UPDATER = new ValueUpdater<String>() {
+ @Override
+ Value createValue(String rawValue) throws IllegalArgumentException {
+ return Values.create(rawValue);
+ }
+ };
+
+ public final ValueUpdater<String> TO_INTEGER_UPDATER = new ValueUpdater<String>() {
+ @Override
+ Value createValue(String rawValue) throws IllegalArgumentException {
+ try {
+ return Values.create(Integer.valueOf(rawValue));
+ } catch (NumberFormatException ex) {
+ throw new IllegalArgumentException(ConversionValidationFailure.NOT_A_VALID_INTEGER.name());
+ }
+ }
+ };
+
+ public final ValueUpdater<String> TO_DOUBLE_UPDATER = new ValueUpdater<String>() {
+ @Override
+ Value createValue(String rawValue) throws IllegalArgumentException {
+ try {
+ return Values.create(Double.valueOf(rawValue));
+ } catch (NumberFormatException ex) {
+ throw new IllegalArgumentException(ConversionValidationFailure.NOT_A_VALID_DECIMAL.name());
+ }
+ }
+ };
+
+ public final ValueUpdater<Boolean> BOOLEAN_UPDATER = new ValueUpdater<Boolean>() {
+ @Override
+ Value createValue(Boolean rawValue) throws IllegalArgumentException {
+ return Values.create(rawValue);
+ }
+ };
+
public static class TimestampLabel extends FlowPanel {
static protected DateTimeFormat dateFormat = DateTimeFormat.getFormat(Constants.DEFAULT_DATE_FORMAT);
static protected DateTimeFormat timeFormat = DateTimeFormat.getFormat(Constants.DEFAULT_TIME_FORMAT);
public TimestampLabel(Long timestamp) {
- addStyleName("flex");
- getElement().getStyle().setFontSize(9, com.google.gwt.dom.client.Style.Unit.PX);
- getElement().getStyle().setTextAlign(com.google.gwt.dom.client.Style.TextAlign.RIGHT);
+ addStyleName("flex layout vertical end or-FormInfoLabel");
if (timestamp != null) {
setTimestamp(timestamp);
}
@@ -129,6 +219,38 @@ public abstract class AttributesView<
}
}
+ public boolean validateAttributes() {
+ boolean isValid = true;
+ for (AssetAttribute attribute : attributes) {
+ if (!validateAttribute(attribute, false))
+ isValid = false;
+ }
+ if (!isValid) {
+ showValidationError(environment.getMessages().invalidAssetAttributes());
+ }
+ return isValid;
+ }
+
+ public boolean validateAttribute(AssetAttribute attribute, boolean showValidationFailureMessage) {
+ // If there is already an error displayed, don't do other validation
+ FormGroup formGroup = attributeGroups.get(attribute);
+ if (formGroup.isError()) {
+ return false;
+ }
+
+ List<ValidationFailure> failures = attribute.getValidationFailures();
+ if (!failures.isEmpty()) {
+ attributeGroups.get(attribute).setError(true);
+ if (showValidationFailureMessage) {
+ for (ValidationFailure failure : failures) {
+ showValidationError(attribute.getLabelOrName().orElse(null), failure);
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
public void close() {
// Subclasses can manage lifecycle
}
@@ -164,14 +286,16 @@ public abstract class AttributesView<
}
protected FormGroup createAttributeGroup(AssetAttribute attribute) {
-
FormGroup formGroup = new FormGroup();
- FormLabel formLabel = createAttributeLabel(attribute);
- formGroup.addFormLabel(formLabel);
+ formGroup.addFormLabel(createAttributeLabel(attribute));
- Optional<String> description = getAttributeDescription(attribute);
- description.ifPresent(s -> formGroup.addInfolabel(new Label(s)));
+ attribute.getType()
+ .map(attributeType -> environment.getMessages().attributeType(attributeType.name()))
+ .map(typeDisplayName -> typeDisplayName + (
+ getAttributeDescription(attribute)
+ .map(description -> " - " + description).orElse("")
+ )).ifPresent(infoText -> formGroup.addInfolabel(new Label(infoText)));
FormGroupActions formGroupActions = new FormGroupActions();
@@ -196,7 +320,7 @@ public abstract class AttributesView<
}
protected FormLabel createAttributeLabel(AssetAttribute attribute) {
- FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 100));
+ FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 100));
formLabel.addStyleName("larger");
return formLabel;
}
@@ -215,15 +339,18 @@ public abstract class AttributesView<
Optional<MetaItem> defaultValueItem = attribute.getMetaItem(AssetMeta.DEFAULT);
S style = container.getStyle();
+ AttributeType attributeType = attribute.getType().orElse(null);
+ if (attributeType == null)
+ return null;
+
AttributeEditor attributeEditor;
- AttributeType attributeType = attribute.getType().orElse(AttributeType.STRING);
- if (attributeType == AttributeType.STRING) {
+ if (attributeType == AttributeType.STRING || attributeType.getValueType() == ValueType.STRING) {
attributeEditor = createStringEditor(attribute, defaultValueItem, style, formGroup);
} else if (attributeType == AttributeType.INTEGER) {
attributeEditor = createIntegerEditor(attribute, defaultValueItem, style, formGroup);
- } else if (attributeType == AttributeType.DECIMAL) {
+ } else if (attributeType == AttributeType.DECIMAL || attributeType.getValueType() == ValueType.NUMBER) {
attributeEditor = createDecimalEditor(attribute, defaultValueItem, style, formGroup);
- } else if (attributeType == AttributeType.BOOLEAN) {
+ } else if (attributeType == AttributeType.BOOLEAN || attributeType.getValueType() == ValueType.BOOLEAN) {
attributeEditor = createBooleanEditor(attribute, defaultValueItem, style, formGroup);
} else {
return null;
@@ -235,7 +362,7 @@ public abstract class AttributesView<
FormField unsupportedField = new FormField();
unsupportedField.add(new FormOutputText(
environment.getMessages().unsupportedAttributeType(
- attribute.getType().map(AttributeType::getDisplayName).orElse(null)
+ attribute.getType().map(AttributeType::name).orElse(null)
)
));
return () -> unsupportedField;
@@ -245,10 +372,9 @@ public abstract class AttributesView<
String currentValue = attribute.getValue().map(Object::toString).orElse(null);
Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);
- Consumer<String> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {
- formGroup.setError(false);
- attribute.setValue(Values.create(value));
- };
+ Consumer<String> updateConsumer = !isEditorReadOnly(attribute)
+ ? rawValue -> STRING_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ : null;
FlowPanel panel = new FlowPanel();
panel.setStyleName("flex layout horizontal center");
@@ -275,9 +401,7 @@ public abstract class AttributesView<
if (updateConsumer != null) {
input.addValueChangeHandler(
event -> updateConsumer.accept(
- event.getValue() != null && event.getValue().length() > 0
- ? event.getValue()
- : null
+ event.getValue() == null || event.getValue().length() == 0 ? null : event.getValue()
)
);
} else {
@@ -289,20 +413,14 @@ public abstract class AttributesView<
protected AttributeEditor createIntegerEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {
String currentValue = attribute.getValue().map(Object::toString).orElse(null);
Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);
- Consumer<String> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {
- Integer intValue = Integer.valueOf(value);
- formGroup.setError(false);
- attribute.setValue(Values.create(intValue));
- };
- Consumer<String> errorConsumer = msg -> {
- formGroup.setError(true);
- showValidationError(msg);
- };
+ Consumer<String> updateConsumer = !isEditorReadOnly(attribute)
+ ? rawValue -> TO_INTEGER_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ : null;
FlowPanel panel = new FlowPanel();
panel.setStyleName("flex layout horizontal center");
- FormInputNumber inputNumber = createIntegerEditorWidget(style, currentValue, defaultValue, updateConsumer, errorConsumer);
+ FormInputNumber inputNumber = createIntegerEditorWidget(style, currentValue, defaultValue, updateConsumer);
panel.add(inputNumber);
if (isShowTimestamp(attribute)) {
TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());
@@ -315,8 +433,7 @@ public abstract class AttributesView<
protected FormInputNumber createIntegerEditorWidget(S style,
String currentValue,
Optional<String> defaultValue,
- Consumer<String> updateConsumer,
- Consumer<String> errorConsumer) {
+ Consumer<String> updateConsumer) {
FormInputNumber input = createFormInputNumber(style.integerEditor());
if (currentValue != null) {
@@ -325,15 +442,9 @@ public abstract class AttributesView<
if (updateConsumer != null) {
input.addValueChangeHandler(event -> {
- try {
- updateConsumer.accept(
- event.getValue() != null && event.getValue().length() > 0
- ? event.getValue()
- : null
- );
- } catch (NumberFormatException ex) {
- errorConsumer.accept(environment.getMessages().enterOnlyNumbers());
- }
+ updateConsumer.accept(
+ event.getValue() == null || event.getValue().length() == 0 ? null : event.getValue()
+ );
});
} else {
input.setReadOnly(true);
@@ -344,20 +455,14 @@ public abstract class AttributesView<
protected AttributeEditor createDecimalEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {
String currentValue = attribute.getValue().map(Object::toString).orElse(null);
Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);
- Consumer<String> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {
- Double decimalValue = Double.valueOf(value);
- formGroup.setError(false);
- attribute.setValue(Values.create(decimalValue));
- };
- Consumer<String> errorConsumer = msg -> {
- formGroup.setError(true);
- showValidationError(msg);
- };
+ Consumer<String> updateConsumer = !isEditorReadOnly(attribute)
+ ? rawValue -> TO_DOUBLE_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ : null;
FlowPanel panel = new FlowPanel();
panel.setStyleName("flex layout horizontal center");
- FormInputText inputText = createDecimalEditorWidget(style, currentValue, defaultValue, updateConsumer, errorConsumer);
+ FormInputText inputText = createDecimalEditorWidget(style, currentValue, defaultValue, updateConsumer);
panel.add(inputText);
if (isShowTimestamp(attribute)) {
TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());
@@ -370,8 +475,7 @@ public abstract class AttributesView<
protected FormInputText createDecimalEditorWidget(S style,
String currentValue,
Optional<String> defaultValue,
- Consumer<String> updateConsumer,
- Consumer<String> errorConsumer) {
+ Consumer<String> updateConsumer) {
FormInputText input = createFormInputText(style.decimalEditor());
if (currentValue != null) {
@@ -380,15 +484,9 @@ public abstract class AttributesView<
if (updateConsumer != null) {
input.addValueChangeHandler(event -> {
- try {
- updateConsumer.accept(
- event.getValue() != null && event.getValue().length() > 0
- ? event.getValue()
- : null
- );
- } catch (NumberFormatException ex) {
- errorConsumer.accept(environment.getMessages().enterOnlyDecimals());
- }
+ updateConsumer.accept(
+ event.getValue() == null || event.getValue().length() == 0 ? null : event.getValue()
+ );
});
} else {
input.setReadOnly(true);
@@ -397,18 +495,20 @@ public abstract class AttributesView<
}
protected AttributeEditor createBooleanEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {
- // TODO: Should a boolean attribute with no value default to false?
- boolean currentValue = attribute.getValueAsBoolean().orElse(false);
+ boolean currentValue = attribute.getValueAsBoolean().orElse(false); // An empty boolean attribute value is false
Optional<Boolean> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsBoolean);
- Consumer<Boolean> updateConsumer = isEditorReadOnly(attribute) ? null : value -> {
- formGroup.setError(false);
- attribute.setValue(Values.create(value));
- };
+
+ Consumer<Boolean> updateConsumer = !isEditorReadOnly(attribute)
+ ? rawValue -> BOOLEAN_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ : null;
FlowPanel panel = new FlowPanel();
panel.setStyleName("flex layout horizontal center");
FormCheckBox checkBox = createBooleanEditorWidget(style, currentValue, defaultValue, updateConsumer);
- panel.add(checkBox);
+ FlowPanel checkBoxWrapper = new FlowPanel();
+ checkBoxWrapper.setStyleName("flex layout horizontal center");
+ checkBoxWrapper.add(checkBox);
+ panel.add(checkBoxWrapper);
if (isShowTimestamp(attribute)) {
TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());
panel.add(timestampLabel);
@@ -494,7 +594,17 @@ public abstract class AttributesView<
}
protected void showValidationError(String error) {
- environment.getEventBus().dispatch(new ShowFailureEvent(error, 3000));
+ environment.getEventBus().dispatch(new ShowFailureEvent(error, 5000));
}
+ protected void showValidationError(String fieldLabel, ValidationFailure validationFailure) {
+ StringBuilder error = new StringBuilder();
+ if (fieldLabel != null)
+ error.append(environment.getMessages().validationFailedFor(fieldLabel));
+ else
+ error.append(environment.getMessages().validationFailed());
+ if (validationFailure != null)
+ error.append(": ").append(environment.getMessages().validationFailure(validationFailure.name()));
+ showValidationError(error.toString());
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java
index 2bf7e0591..bdb0270d1 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java
@@ -57,8 +57,6 @@ public interface ManagerMessages extends Messages {
String enabled();
- String newTenant();
-
String editTenant();
String tenantDisplayName();
@@ -149,7 +147,9 @@ public interface ManagerMessages extends Messages {
String unsupportedAttributeType(String name);
- String unsupportedMetaItemType(String jsonType);
+ String unsupportedMetaItemType(String name);
+
+ String emptyMetaItem();
String loadingAssets();
@@ -173,8 +173,6 @@ public interface ManagerMessages extends Messages {
String assetDeleted(String name);
- String showDashboard();
-
String location();
String selectLocation();
@@ -193,6 +191,8 @@ public interface ManagerMessages extends Messages {
String invalidAssetParent();
+ String invalidAssetAttributes();
+
String centerMap();
String showHistory();
@@ -237,12 +237,6 @@ public interface ManagerMessages extends Messages {
String selectType();
- String enterNameAndValue();
-
- String enterOnlyDecimals();
-
- String enterOnlyNumbers();
-
String attributeDeleted(String name);
String attributeAdded(String name);
@@ -253,8 +247,6 @@ public interface ManagerMessages extends Messages {
String attributeName();
- String enterNameAndSelectType();
-
String fullscreen();
String selectConsoleApp();
@@ -336,4 +328,13 @@ public interface ManagerMessages extends Messages {
String getStatus();
String commandRequestSent(String name);
+
+ String attributeType(@Select String name);
+
+ String validationFailed();
+
+ String validationFailedFor(String field);
+
+ String validationFailure(@Select String name);
+
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java
index 79064f755..bf973a216 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java
@@ -28,7 +28,6 @@ import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.InlineLabel;
import com.google.inject.Provider;
import elemental.client.Browser;
import elemental.html.AnchorElement;
@@ -62,7 +61,7 @@ public class RulesEditorImpl
FormInputText nameInput;
@UiField
- PushButton rulesFileDownload;
+ FormButton rulesFileDownload;
@UiField
LabelElement rulesFileUploadLabel;
@UiField
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml
index 1861add51..199b05379 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.ui.xml
@@ -89,7 +89,7 @@
</w:field>
<w:actions>
<w:FormGroupActions>
- <w:PushButton ui:field="rulesFileDownload"
+ <w:FormButton ui:field="rulesFileDownload"
icon="download"
text="{managerMessages.downloadRulesFile}"/>
<g:HTMLPanel>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java
index 236690a5c..12310ee16 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormField.java
@@ -26,6 +26,7 @@ import com.google.gwt.user.client.ui.Widget;
public class FormField extends FlowPanel implements HasWidgets {
protected String formFieldId;
+ protected boolean error;
public FormField() {
getElement().addClassName("flex layout horizontal center or-FormField");
@@ -45,4 +46,17 @@ public class FormField extends FlowPanel implements HasWidgets {
}
super.add(w);
}
+
+ public void setError(boolean error) {
+ this.error = error;
+ removeStyleName("error");
+ if (error) {
+ addStyleName("error");
+ }
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java
index efd4e63b6..9ba013ca1 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java
@@ -21,7 +21,10 @@ package org.openremote.manager.client.widget;
import com.google.gwt.dom.client.Style;
import com.google.gwt.uibinder.client.UiChild;
-import com.google.gwt.user.client.ui.*;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HasWidgets;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.Widget;
import java.util.function.Consumer;
import java.util.logging.Logger;
@@ -53,6 +56,9 @@ public class FormGroup extends FlowPanel implements HasWidgets {
protected boolean expanded;
+ protected boolean errorInField;
+ protected boolean errorInExtension;
+
public FormGroup() {
setStyleName("layout vertical or-FormGroup");
@@ -62,6 +68,7 @@ public class FormGroup extends FlowPanel implements HasWidgets {
labelPanel.setStyleName("layout vertical");
mainPanel.add(labelPanel);
+ toggleExtensionButton.addStyleName("or-FormGroupExtensionButton");
toggleExtensionButton.setVisible(false);
toggleExtensionButton.setIcon("caret-down");
toggleExtensionButton.addClickHandler(clickEvent -> {
@@ -162,13 +169,31 @@ public class FormGroup extends FlowPanel implements HasWidgets {
return getElement().getStyle();
}
- public void setError(boolean error) {
- removeStyleName("error");
- if (error) {
- addStyleName("error");
+ public void setError(boolean errorInField) {
+ this.errorInField = errorInField;
+ if (getFormLabel() != null) {
+ getFormLabel().setError(errorInField || errorInExtension);
+ }
+ if (getFormField() != null) {
+ getFormField().setError(errorInField);
+ }
+ }
+
+ public void setErrorInExtension(boolean errorInExtension) {
+ this.errorInExtension = errorInExtension;
+ if (getFormLabel() != null) {
+ getFormLabel().setError(errorInField || errorInExtension);
+ }
+ toggleExtensionButton.removeStyleName("error");
+ if (errorInExtension) {
+ toggleExtensionButton.addStyleName("error");
}
}
+ public boolean isError() {
+ return errorInField || errorInExtension;
+ }
+
public void setAlignStart(boolean alignStart) {
if (alignStart) {
mainPanel.removeStyleName("center");
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroupActions.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroupActions.java
index ed4c8124d..22f540b2c 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroupActions.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroupActions.java
@@ -25,6 +25,6 @@ import com.google.gwt.user.client.ui.HasWidgets;
public class FormGroupActions extends FlowPanel implements HasWidgets {
public FormGroupActions() {
- getElement().addClassName("layout horizontal center or-FormGroupActions");
+ getElement().addClassName("layout horizontal center wrap end-justified or-FormGroupActions");
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java
index 1bb68779e..6c29ab933 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormLabel.java
@@ -29,6 +29,7 @@ public class FormLabel extends ComplexPanel {
protected LabelElement labelElement;
protected SpanElement requiredElement;
protected boolean required;
+ protected boolean error;
public FormLabel() {
this(null);
@@ -72,6 +73,18 @@ public class FormLabel extends ComplexPanel {
requiredElement.getStyle().setVisibility(required ? Style.Visibility.VISIBLE : Style.Visibility.HIDDEN);
}
+ public void setError(boolean error) {
+ this.error = error;
+ removeStyleName("error");
+ if (error) {
+ addStyleName("error");
+ }
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
public String getFormFieldId() {
return labelElement.getHtmlFor();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputText.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputText.java
index 8f542b7c4..32ef0ed71 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputText.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormOutputText.java
@@ -19,9 +19,10 @@
*/
package org.openremote.manager.client.widget;
+import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Label;
-public class FormOutputText extends Label {
+public class FormOutputText extends InlineLabel {
public FormOutputText() {
this(null);
diff --git a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties
index 1b63f1c41..61aab4701 100644
--- a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties
+++ b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties
@@ -9,7 +9,6 @@ fullscreen=Fullscreen
editAccount=Edit my account
manageTenants=Manage tenants
manageUsers=Manage users
-newTenant=New tenant
createTenant=Create tenant
tenantName=Tenant name
realm=Realm
@@ -71,8 +70,8 @@ showMoreAssets=Show more assets
emptyAsset=No assets found.
sessionTimedOut=Your session timed out. Please close or reload this browser window.
description=Description
-unsupportedAttributeType=Unsupported attribute type: {0}
-unsupportedMetaItemType=Unsupported meta item type : {0}
+unsupportedAttributeType=Not implemented attribute type: {0}
+unsupportedMetaItemType=Not implemented meta item type : {0}
loadingAssets=Loading assets...
assetName=Asset name
updateAsset=Save asset
@@ -84,7 +83,6 @@ selectedLocation=Selected location
assetCreated=Asset created: {0}
assetUpdated=Asset saved: {0}
assetDeleted=Asset deleted: {0}
-showDashboard=Show Dashboard
location=Location
selectLocation=Select location on map
confirmation=Confirmation
@@ -124,7 +122,6 @@ and=and
selectItem=Select item
enterCustomAssetAttributeMetaName=Enter a custom name
selectType=Select type
-enterNameAndValue=Please enter a name and value.
enterOnlyNumbers=Please enter only (integer) numbers.
enterOnlyDecimals=Please enter only (decimal) numbers.
attributeDeleted=Attribute deleted, save asset to persist: {0}
@@ -132,7 +129,6 @@ attributeAdded=Attribute added, save asset to persist: {0}
newAttribute=New attribute
attributes=Asset attributes
attributeName=Attribute name
-enterNameAndSelectType=Please enter a name and select a type.
selectConsoleApp=Please select a console application on the left-hand side.
manageGlobalRulesets=Manage global rulesets
manageTenantRulesets=Manage tenant rulesets
@@ -178,3 +174,56 @@ start=Start
repeat=Repeat
getStatus=Get Status
commandRequestSent=Sent command request: {0}
+attributeType=Unknown attribute type
+attributeType[STRING]=Text
+attributeType[INTEGER]=Whole number
+attributeType[DECIMAL]=Decimal number
+attributeType[BOOLEAN]=On/Off toggle
+attributeType[PERCENTAGE]=Percentage
+attributeType[TIMESTAMP_MILLIS]=Timestamp milliseconds
+attributeType[DATETIME]=Timestamp in ISO 8601
+attributeType[COLOR_RGB]=Color RGB
+attributeType[COLOR_ARGB]=Color ARGB
+attributeType[COLOR_HEX]=Color HEX
+attributeType[TEMPERATURE_CELCIUS]=Temperature in Celcius
+attributeType[TEMPERATURE_KELVIN]=Temperature in Kelvin
+attributeType[TEMPERATURE_FAHRENHEIT]=Temperature in Fahrenheit
+attributeType[DISTANCE_M]=Distance in meters
+attributeType[DISTANCE_CM]=Distance in centimeters
+attributeType[DISTANCE_MM]=Distance in millimeters
+attributeType[DISTANCE_IN]=Distance in inch
+attributeType[DISTANCE_FT]=Distance in feet
+attributeType[DISTANCE_YARD]=Dinstance in yard
+attributeType[CO2_PPM]=CO2 Level in PPM
+attributeType[HUMIDITY_PERCENTAGE]=Humidity percentage
+attributeType[HUMIDITY_GPCM]=Humidity in grams per cubic meter
+attributeType[POWER_WATT]=Power in watt
+attributeType[POWER_KILOWATT]=Power in kilowatt
+attributeType[POWER_MEGAWATT]=Power in megawatt
+attributeType[CHARGE_PERCENTAGE]=Charge percentage
+attributeType[CHARGE_KWH]=Charge in kilowatt-hours
+attributeType[ENERGY_KWH]=Energy in kilowatt-hours
+attributeType[ENERGY_JOULE]=Energy in joule
+attributeType[ENERGY_MEGAJOULE]=Energy in megajoule
+attributeType[FLOW_LPM]=Flow in litre per minute
+attributeType[FLOW_CMPS]=Flow in cubic metres per second
+attributeType[FLOW_SCCM]=Flow in cubic centimetres per minute
+attributeType[FLOW_CFPS]=Flow in cubic feet per second
+attributeType[FLOW_GPM]=Flow in gallons per minute
+emptyMetaItem=Empty item
+invalidAssetAttributes=Invalid asset attributes, please correct input.
+validationFailed=Validation failed
+validationFailedFor=Validation failed for {0}
+validationFailure=Unknown validation failure.
+validationFailure[NAME_IS_REQUIRED]=Name is required.
+validationFailure[VALUE_IS_REQUIRED]=Value is required.
+validationFailure[INVALID_ATTRIBUTE_NAME]=Invalid attribute name.
+validationFailure[MISSING_ATTRIBUTE_TYPE]=Missing attribute type.
+validationFailure[MISSING_ATTRIBUTE_VALUE_TIMESTAMP]=Missing attribute value timestamp.
+validationFailure[VALUE_DOES_NOT_MATCH_ATTRIBUTE_TYPE]=Value does not match attribute type.
+validationFailure[PERCENTAGE_NOT_WITHIN_BOUNDS]=Percentage value must be a number between 0 and 100.
+validationFailure[VALUE_DOES_NOT_MATCH_ASSET_META_TYPE]=Value does not match well-known meta item''s expected type.
+validationFailure[NOT_A_VALID_INTEGER]=Must be a whole number.
+validationFailure[NOT_A_VALID_DECIMAL]=Must be a decimal number.
+
+
diff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.html
index ac9e700d0..4a74665f4 100644
--- a/manager/client/src/main/webapp/css/style.html
+++ b/manager/client/src/main/webapp/css/style.html
@@ -319,6 +319,7 @@
}
.or-FormField {
+ min-width: 10em;
}
.or-FormField.larger {
@@ -398,7 +399,8 @@
.or-FormButton,
.or-FormButtonDown,
.or-FormButtonDanger,
- .or-FormButtonPrimary {
+ .or-FormButtonPrimary,
+ .or-FormFileUploadLabel {
padding: 0 0.4em;
border: 2px dotted transparent;
}
@@ -414,6 +416,10 @@
height: 1.8em;
}
+ .or-FormGroupActions .or-FormControl {
+ margin: 0.2em 0.4em;
+ }
+
.or-FormTableHeaderCell {
text-shadow: none;
border-bottom: 1px solid;
diff --git a/manager/client/src/main/webapp/css/theme.html b/manager/client/src/main/webapp/css/theme.html
index abcdcf0b5..23fbe6935 100644
--- a/manager/client/src/main/webapp/css/theme.html
+++ b/manager/client/src/main/webapp/css/theme.html
@@ -154,22 +154,34 @@
color: var(--theme-mediumgrey);
}
- .or-FormGroup.error .or-FormControl {
+ .or-FormLabel.error,
+ .or-FormLabel.error + .or-FormInfoLabel {
+ color: var(--theme-red);
+ }
+
+ .or-FormField.error .or-FormControl {
border-color: var(--theme-red);
}
+ .or-FormField.error .or-FormOutputText {
+ border-color: transparent;
+ }
+
+ .or-FormField.error .or-FormInfoLabel,
+ .or-FormField.error .or-FormInfoLabel .or-FormControl {
+ color: var(--theme-mediumgrey);
+ border-color: transparent;
+ }
+
.or-FormControl.error {
background-color: var(--theme-red);
+ color: var(--theme-white);
}
.or-FormControl.primary {
background-color: var(--theme-lightgreen);
}
- .or-FormGroup.error .or-FormLabel {
- color: var(--theme-red);
- }
-
.or-FormLabel {
color: var(--theme-darkgrey);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
index 35d4c94be..12aeb06f5 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
@@ -34,6 +34,7 @@ import org.openremote.manager.server.event.EventService;
import org.openremote.manager.server.security.ManagerIdentityService;
import org.openremote.manager.shared.security.ClientRole;
import org.openremote.manager.shared.security.Tenant;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.*;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.util.Pair;
@@ -239,8 +240,16 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
}
// Validate attributes
- if (!asset.getAttributesStream().allMatch(AssetAttribute::isValid)) {
- throw new IllegalStateException("One or more attributes are not valid");
+ int invalid = 0;
+ for (AssetAttribute attribute : asset.getAttributesList()) {
+ List<ValidationFailure> validationFailures = attribute.getValidationFailures();
+ if (validationFailures.size() > 0) {
+ LOG.warning("Validation failure(s) " + validationFailures + ", can't store: " + attribute);
+ invalid++;
+ }
+ }
+ if (invalid > 0) {
+ throw new IllegalStateException("Storing asset failed, invalid attributes: " + invalid);
}
return em.merge(asset);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java
index 716e08ff1..ee810f13a 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java
@@ -28,12 +28,14 @@ import org.openremote.manager.shared.http.RequestParams;
import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.datapoint.DatapointInterval;
import org.openremote.model.datapoint.NumberDatapoint;
+import org.openremote.model.value.ValueType;
import javax.ws.rs.BeanParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import static org.openremote.model.attribute.Attribute.isAttributeNameEqualTo;
+import static org.openremote.model.attribute.Attribute.isAttributeTypeEqualTo;
public class AssetDatapointResourceImpl extends ManagerWebResource implements AssetDatapointResource {
@@ -58,10 +60,15 @@ public class AssetDatapointResourceImpl extends ManagerWebResource implements As
// TODO Security etc.
ServerAsset asset = assetStorageService.find(assetId, true);
+ // TODO This only supports ValueType.NUMBER attributes
+
if (asset == null || asset
.getAttributesStream()
.noneMatch(
- attribute -> isAttributeNameEqualTo(attribute, attributeName) && attribute.isStoreDatapoints()
+ attribute ->
+ isAttributeNameEqualTo(attribute, attributeName)
+ && attribute.isStoreDatapoints()
+ && isAttributeTypeEqualTo(attribute, ValueType.NUMBER)
)) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
index 8a1d64a2c..4dad60409 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
@@ -163,9 +163,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
thing.setAttributes(
new AssetAttribute("light1Toggle", BOOLEAN, Values.create(true))
.setMeta(new Meta(
+ new MetaItem(
+ LABEL,
+ Values.create("Light 1 Toggle")),
new MetaItem(
DESCRIPTION,
- Values.create("The switch for the light in the living room")),
+ Values.create("Switch for living room light")),
new MetaItem(
AGENT_LINK,
new AttributeRef(agent.getId(), agentProtocolConfigName).toArrayValue()),
@@ -173,11 +176,14 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(SwitchSimulatorElement.ELEMENT_NAME)
))
),
- new AssetAttribute("light1Dimmer", INTEGER) // No initial value!
+ new AssetAttribute("light1Dimmer", PERCENTAGE) // No initial value!
.setMeta(new Meta(
+ new MetaItem(
+ LABEL,
+ Values.create("Light 1 Dimmer")),
new MetaItem(
DESCRIPTION,
- Values.create("The dimmer for the light in the living room")),
+ Values.create("Dimmer for living room light")),
new MetaItem(
RANGE_MIN,
Values.create(0)),
@@ -195,9 +201,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
),
new AssetAttribute("light1Color", COLOR_RGB, new ColorRGB(88, 123, 88).asArrayValue())
.setMeta(new Meta(
+ new MetaItem(
+ LABEL,
+ Values.create("Light 1 Color")),
new MetaItem(
DESCRIPTION,
- Values.create("The color of the living room light")),
+ Values.create("Color of living room light")),
new MetaItem(
AGENT_LINK,
new AttributeRef(agent.getId(), agentProtocolConfigName).toArrayValue()),
@@ -207,9 +216,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
),
new AssetAttribute("light1PowerConsumption", ENERGY_KWH, Values.create(12.345))
.setMeta(new Meta(
+ new MetaItem(
+ LABEL,
+ Values.create("Light 1 Usage")),
new MetaItem(
DESCRIPTION,
- Values.create("The total power consumption of the living room light")),
+ Values.create("Total energy consumption of living room light")),
new MetaItem(
READ_ONLY,
Values.create(true)),
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
index d6afbaf97..b06d84c4e 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
@@ -94,7 +94,7 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTrait
then: "the attribute value should match"
new PollingConditions(delay: 1, timeout: 5).eventually {
def asset = assetResource.get(null, testAsset.getId())
- assert asset.getAttribute("foo").get().hasValue() == false
+ assert !asset.getAttribute("foo").get().getValue().isPresent()
}
when: "an asset is updated with a different type"
diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
index eb1e305b0..babafc041 100644
--- a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
@@ -194,7 +194,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
mockThing.setAttributes(
new AssetAttribute("lightToggle1", AttributeType.BOOLEAN)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
@@ -202,7 +202,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("tempTarget1", AttributeType.DECIMAL)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
@@ -217,7 +217,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("lightToggle2", AttributeType.BOOLEAN)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig2").toArrayValue()
@@ -225,7 +225,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("tempTarget2", AttributeType.DECIMAL)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig2").toArrayValue()
@@ -233,7 +233,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("lightToggle3", AttributeType.BOOLEAN)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig3").toArrayValue()
@@ -241,7 +241,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("tempTarget3", AttributeType.DECIMAL)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig3").toArrayValue()
@@ -249,7 +249,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("lightToggle4", AttributeType.BOOLEAN)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig4").toArrayValue()
@@ -257,7 +257,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
),
new AssetAttribute("tempTarget4", AttributeType.DECIMAL)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
AssetMeta.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig4").toArrayValue()
@@ -267,7 +267,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
// protocol link/unlink attribute method
new AssetAttribute("protocolEnabled", AttributeType.BOOLEAN)
.setMeta(
- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META"),
+ new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(AssetMeta.PROTOCOL_PROPERTY, Values.create("ENABLED")),
new MetaItem(
AssetMeta.AGENT_LINK,
@@ -398,9 +398,9 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
then: "the update should reach the protocol as an attribute write request"
conditions.eventually {
- protocolWriteAttributeEvents.size() == 1
- protocolWriteAttributeEvents[0].attributeName == "tempTarget1"
- protocolWriteAttributeEvents[0].attributeRef.entityId == mockThing.getId()
+ assert protocolWriteAttributeEvents.size() == 1
+ assert protocolWriteAttributeEvents[0].attributeName == "tempTarget1"
+ assert protocolWriteAttributeEvents[0].attributeRef.entityId == mockThing.getId()
Values.getNumber(protocolWriteAttributeEvents[0].value.orElse(null)).orElse(0d) == 30d
}
@@ -412,5 +412,8 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
mockThing = assetStorageService.find(mockThing.getId(), true)
assert mockThing.getAttribute("tempTarget1").get().getValueAsNumber().orElse(0d) == 30d
}
+
+ cleanup: "the server should be stopped"
+ stopContainer(container)
}
}
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/AbstractValueHolder.java b/model/src/main/java/org/openremote/model/AbstractValueHolder.java
index f0ff05d3d..935211dbe 100644
--- a/model/src/main/java/org/openremote/model/AbstractValueHolder.java
+++ b/model/src/main/java/org/openremote/model/AbstractValueHolder.java
@@ -24,6 +24,8 @@ import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -78,13 +80,7 @@ public abstract class AbstractValueHolder {
return objectValue.getArray(VALUE_FIELD_NAME);
}
- /**
- * @throws IllegalArgumentException if the given value is invalid and failed constraint checking.
- */
- public void setValue(Value value) throws IllegalArgumentException {
- if (!isValidValue(value)) {
- throw new IllegalArgumentException("Invalid value: " + (value != null ? value.toJson() : "null"));
- }
+ public void setValue(Value value) {
if (value != null) {
objectValue.put(VALUE_FIELD_NAME, value);
} else {
@@ -109,18 +105,10 @@ public abstract class AbstractValueHolder {
}
/**
- * Override to implement constraints.
+ * Override to implement constraint checking.
*/
- public boolean isValidValue(Value value) {
- return true;
- }
-
- public boolean hasValue() {
- return getValue().isPresent();
- }
-
- public boolean isValid() {
- return true;
+ public List<ValidationFailure> getValidationFailures() {
+ return new ArrayList<>();
}
@Override
diff --git a/model/src/main/java/org/openremote/model/attribute/HasMetaName.java b/model/src/main/java/org/openremote/model/HasUniqueResourceName.java
similarity index 85%
rename from model/src/main/java/org/openremote/model/attribute/HasMetaName.java
rename to model/src/main/java/org/openremote/model/HasUniqueResourceName.java
index 3d5675240..d01739ddc 100644
--- a/model/src/main/java/org/openremote/model/attribute/HasMetaName.java
+++ b/model/src/main/java/org/openremote/model/HasUniqueResourceName.java
@@ -17,12 +17,13 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.model.attribute;
+package org.openremote.model;
/**
- * This is an interface for indicating that a type
- * provides a URN string.
+ * This is an interface for indicating that a type provides a URN string.
*/
-public interface HasMetaName {
+public interface HasUniqueResourceName {
+
String getUrn();
+
}
diff --git a/model/src/main/java/org/openremote/model/ValidationFailure.java b/model/src/main/java/org/openremote/model/ValidationFailure.java
new file mode 100644
index 000000000..d2c8c388a
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/ValidationFailure.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model;
+
+/**
+ * Unified naming of value holder validation failures. Names are supposed to be
+ * unique so user-readable strings can be created from names with I18N mapping.
+ */
+public interface ValidationFailure {
+
+ String name();
+}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
index 031ef5d08..2d9811b29 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
@@ -20,6 +20,7 @@
package org.openremote.model.asset;
import org.openremote.model.AbstractValueHolder;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.attribute.*;
import org.openremote.model.util.Pair;
import org.openremote.model.value.ObjectValue;
@@ -28,6 +29,7 @@ import org.openremote.model.value.Values;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -106,6 +108,16 @@ public class AssetAttribute extends Attribute {
return getReference().map(ref -> new AttributeState(ref, getValue().orElse(null)));
}
+ @Override
+ public List<ValidationFailure> getMetaItemValidationFailures(MetaItem item) {
+ List<ValidationFailure> failures = super.getMetaItemValidationFailures(item);
+
+ // We validation well-known meta items
+ AssetMeta.getValidationFailure(item).ifPresent(failures::add);
+
+ return failures;
+ }
+
@Override
public AssetAttribute setMeta(Meta meta) {
super.setMeta(meta);
@@ -144,6 +156,10 @@ public class AssetAttribute extends Attribute {
.orElseGet(() -> getName().orElse(null)));
}
+ public Optional<String> getLabelOrName() {
+ return getLabel().map(Optional::of).orElseGet(this::getName);
+ }
+
public void setLabel(String label) {
if (!isNullOrEmpty(label)) {
replaceMetaByName(getMeta(), LABEL, Values.create(label));
diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
index 32658ff08..231dc1263 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
@@ -19,9 +19,11 @@
*/
package org.openremote.model.asset;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.attribute.AttributeExecuteStatus;
-import org.openremote.model.attribute.HasMetaName;
+import org.openremote.model.HasUniqueResourceName;
import org.openremote.model.attribute.MetaItem;
+import org.openremote.model.util.Pair;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueType;
@@ -31,6 +33,7 @@ import java.util.List;
import java.util.Optional;
import static org.openremote.model.Constants.ASSET_META_NAMESPACE;
+import static org.openremote.model.asset.AssetMeta.AssetMetaValidationFailure.VALUE_DOES_NOT_MATCH_ASSET_META_TYPE;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;
/**
@@ -39,7 +42,7 @@ import static org.openremote.model.util.TextUtil.isNullOrEmpty;
* <p>
* TODO https://people.eecs.berkeley.edu/~arka/papers/buildsys2015_metadatasurvey.pdf
*/
-public enum AssetMeta implements HasMetaName {
+public enum AssetMeta implements HasUniqueResourceName {
/**
* Marks an attribute of an agent asset as a {@link org.openremote.model.asset.agent.ProtocolConfiguration}.
@@ -154,12 +157,17 @@ public enum AssetMeta implements HasMetaName {
EXECUTABLE(ASSET_META_NAMESPACE + ":executable", new Access(true, false, true), ValueType.BOOLEAN),
/**
- * Marks an agent linked attribute as being linked to a property of the linked protocol (e.g. an attribute
- * linked to the {@link #ENABLED} status of a protocol configuration) should use this meta with a value of
- * "ENABLED"; other supported values are protocol dependent.
+ * Marks an agent linked attribute as being linked to a property of the linked protocol. For example, an
+ * attribute linked to the {@link #ENABLED} status of a protocol configuration should use this meta with
+ * a value of "ENABLED"; other supported values are protocol dependent.
+ * TODO I don't understand what this does from the description
*/
PROTOCOL_PROPERTY(ASSET_META_NAMESPACE + ":protocolProperty", new Access(true, false, true), ValueType.STRING);
+ public enum AssetMetaValidationFailure implements ValidationFailure {
+ VALUE_DOES_NOT_MATCH_ASSET_META_TYPE
+ }
+
final protected String urn;
final protected Access access;
final protected ValueType valueType;
@@ -182,6 +190,20 @@ public enum AssetMeta implements HasMetaName {
return valueType;
}
+ /**
+ * If this is a well-known item, the value must match the defined type.
+ * Third-party items are always valid.
+ */
+ public Optional<ValidationFailure> isValidValue(Value value) {
+ if (value == null) {
+ return Optional.empty();
+ }
+ if (getValueType() != value.getType()) {
+ return Optional.of(VALUE_DOES_NOT_MATCH_ASSET_META_TYPE);
+ }
+ return Optional.empty();
+ }
+
public static AssetMeta[] editable() {
List<AssetMeta> list = new ArrayList<>();
for (AssetMeta meta : values()) {
@@ -194,16 +216,12 @@ public enum AssetMeta implements HasMetaName {
return list.toArray(new AssetMeta[list.size()]);
}
- public static Boolean isEditable(String urn) {
- if (urn == null) {
- return null;
- }
-
+ public static boolean isEditable(String urn) {
for (AssetMeta assetMeta : editable()) {
if (assetMeta.getUrn().equals(urn))
return assetMeta.getAccess().editable;
}
- return null;
+ return true;
}
public static Optional<AssetMeta> getAssetMeta(String urn) {
@@ -217,12 +235,16 @@ public enum AssetMeta implements HasMetaName {
return Optional.empty();
}
- public static boolean isAssetMeta(MetaItem metaItem) {
- return metaItem != null && getAssetMeta(metaItem.getName().orElse(null)).isPresent();
+ public static Optional<ValidationFailure> getValidationFailure(MetaItem item) {
+ return item.getName()
+ .flatMap(AssetMeta::getAssetMeta)
+ .map(assetMeta -> new Pair<>(assetMeta, item.getValue()))
+ .filter(pair -> pair.value.isPresent())
+ .flatMap(pair -> pair.key.isValidValue(pair.value.get()));
}
/**
- * Only well-known items can be protected readable.
+ * Some well-known items can be protected readable.
*
* @see Access#protectedRead
*/
@@ -233,7 +255,7 @@ public enum AssetMeta implements HasMetaName {
}
/**
- * Only well-known items can be protected readable.
+ * Some well-known items can be protected writable.
*
* @see Access#protectedWrite
*/
@@ -248,9 +270,9 @@ public enum AssetMeta implements HasMetaName {
* are the types we can edit/have editor UI for.
*/
public enum EditableType {
- STRING("String", ValueType.STRING),
- NUMBER("Number", ValueType.NUMBER),
- BOOLEAN("Boolean", ValueType.BOOLEAN);
+ STRING("Text", ValueType.STRING),
+ NUMBER("Decimal number", ValueType.NUMBER),
+ BOOLEAN("On/Off toggle", ValueType.BOOLEAN);
EditableType(String label, ValueType valueType) {
this.label = label;
diff --git a/model/src/main/java/org/openremote/model/attribute/Attribute.java b/model/src/main/java/org/openremote/model/attribute/Attribute.java
index 0f71817d9..f616efb94 100644
--- a/model/src/main/java/org/openremote/model/attribute/Attribute.java
+++ b/model/src/main/java/org/openremote/model/attribute/Attribute.java
@@ -21,17 +21,18 @@ package org.openremote.model.attribute;
import com.google.gwt.regexp.shared.RegExp;
import org.openremote.model.AbstractValueTimestampHolder;
+import org.openremote.model.HasUniqueResourceName;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueType;
import org.openremote.model.value.Values;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
+import static org.openremote.model.attribute.Attribute.AttributeValidationFailure.*;
import static org.openremote.model.util.TextUtil.requireNonNullAndNonEmpty;
/**
@@ -39,6 +40,12 @@ import static org.openremote.model.util.TextUtil.requireNonNullAndNonEmpty;
*/
public abstract class Attribute extends AbstractValueTimestampHolder {
+ public enum AttributeValidationFailure implements ValidationFailure {
+ INVALID_ATTRIBUTE_NAME,
+ MISSING_ATTRIBUTE_TYPE,
+ MISSING_ATTRIBUTE_VALUE_TIMESTAMP
+ }
+
/**
* Attribute names should be very simple, as we use them in SQL path
* expressions, etc. and must manually escape.
@@ -82,6 +89,10 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
this.name = name;
}
+ public void clearName() {
+ this.name = null;
+ }
+
public Optional<AttributeType> getType() {
return getObjectValue().getString(TYPE_FIELD_NAME).flatMap(AttributeType::optionalValueOf);
}
@@ -94,6 +105,10 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
clearValue();
}
+ public void clearType() {
+ getObjectValue().remove(TYPE_FIELD_NAME);
+ }
+
public boolean hasMetaItems() {
return getObjectValue().getArray(META_FIELD_NAME)
.filter(arrayValue -> arrayValue.length() > 0)
@@ -120,7 +135,7 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
return getMetaItem(metaName).isPresent();
}
- public boolean hasMetaItem(HasMetaName metaName) {
+ public boolean hasMetaItem(HasUniqueResourceName metaName) {
return getMetaItem(metaName).isPresent();
}
@@ -130,8 +145,8 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
.findFirst();
}
- public Optional<MetaItem> getMetaItem(HasMetaName hasMetaName) {
- return getMetaItem(hasMetaName.getUrn());
+ public Optional<MetaItem> getMetaItem(HasUniqueResourceName hasUniqueResourceName) {
+ return getMetaItem(hasUniqueResourceName.getUrn());
}
public void setMeta(List<MetaItem> metaItems) {
@@ -160,20 +175,42 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
}
@Override
- public boolean isValid() {
- return super.isValid()
- // Must have a valid name
- && getName().isPresent()
- && ATTRIBUTE_NAME_VALIDATOR.test(getName().get()) && (
- // and either have no value
- !getValue().isPresent()
- // or have a timestamp and a type that validates the value
- || (hasValueTimestamp() && isValidValue(getValue().get()))
- );
+ public List<ValidationFailure> getValidationFailures() {
+ List<ValidationFailure> failures = super.getValidationFailures();
+
+ if (!getName().isPresent() || !ATTRIBUTE_NAME_VALIDATOR.test(getName().get()))
+ failures.add(INVALID_ATTRIBUTE_NAME);
+
+ if (!getType().isPresent())
+ failures.add(MISSING_ATTRIBUTE_TYPE);
+
+ if (!hasValueTimestamp())
+ failures.add(MISSING_ATTRIBUTE_VALUE_TIMESTAMP);
+
+ // Value can be empty, if it's not it must validate with the type
+ getValue().flatMap(value ->
+ getType().flatMap(attributeType -> attributeType.isValidValue(value))
+ ).ifPresent(failures::add);
+
+ failures.addAll(getMetaItemsValidationFailures());
+
+ return failures;
+ }
+
+ public List<ValidationFailure> getMetaItemsValidationFailures() {
+ List<ValidationFailure> failures = new ArrayList<>();
+ if (hasMetaItems()) {
+ for (MetaItem metaItem : getMeta()) {
+ failures.addAll(getMetaItemValidationFailures(metaItem));
+ }
+ }
+ return failures;
}
- public boolean isValidValue(Value value) {
- return getType().filter(type -> type.isValid(value)).isPresent();
+ public List<ValidationFailure> getMetaItemValidationFailures(MetaItem item) {
+ List<ValidationFailure> failures = new ArrayList<>();
+ failures.addAll(item.getValidationFailures());
+ return failures;
}
// ---------------------------------------------------
@@ -192,7 +229,6 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
public static <A extends Attribute> boolean isAttributeTypeEqualTo(A attribute, AttributeType type) {
if (attribute == null)
return false;
-
return attribute
.getType()
.map(attributeType -> attributeType == type)
@@ -202,4 +238,19 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
public static <A extends Attribute> Predicate<A> isAttributeTypeEqualTo(AttributeType type) {
return attribute -> isAttributeTypeEqualTo(attribute, type);
}
+
+ public static <A extends Attribute> boolean isAttributeTypeEqualTo(A attribute, ValueType valueType) {
+ return isAttributeTypeEqualTo(valueType).test(attribute);
+ }
+
+ public static <A extends Attribute> Predicate<A> isAttributeTypeEqualTo(ValueType valueType) {
+ return attribute -> {
+ if (attribute == null)
+ return false;
+ return attribute
+ .getType()
+ .map(attributeType -> attributeType.getValueType() == valueType)
+ .orElse(valueType == null);
+ };
+ }
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeRef.java b/model/src/main/java/org/openremote/model/attribute/AttributeRef.java
index f0830a221..83ca9bcfb 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeRef.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeRef.java
@@ -26,6 +26,8 @@ import org.openremote.model.value.Values;
import java.util.Optional;
+import static org.openremote.model.util.TextUtil.requireNonNullAndNonEmpty;
+
/**
* A reference to an entity and an {@link Attribute}.
* <p>
@@ -44,6 +46,8 @@ public class AttributeRef {
}
public AttributeRef(String entityId, String attributeName) {
+ requireNonNullAndNonEmpty(entityId);
+ requireNonNullAndNonEmpty(attributeName);
this.entityId = entityId;
this.attributeName = attributeName;
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeState.java b/model/src/main/java/org/openremote/model/attribute/AttributeState.java
index b7023827f..ddf81be9e 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeState.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeState.java
@@ -27,8 +27,6 @@ import org.openremote.model.value.Values;
import java.util.Objects;
import java.util.Optional;
-import static org.openremote.model.util.TextUtil.requireNonNullAndNonEmpty;
-
/**
* The desired or current or past state of an {@link AttributeRef}.
*/
@@ -42,8 +40,6 @@ public class AttributeState {
public AttributeState(String entityId, String attributeName, Value value) {
this(new AttributeRef(entityId, attributeName), value);
- requireNonNullAndNonEmpty(entityId);
- requireNonNullAndNonEmpty(attributeName);
}
/**
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeType.java b/model/src/main/java/org/openremote/model/attribute/AttributeType.java
index bf579038e..d758d4648 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeType.java
@@ -19,12 +19,16 @@
*/
package org.openremote.model.attribute;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueType;
+import org.openremote.model.value.Values;
import java.util.Optional;
import java.util.function.Function;
+import static org.openremote.model.attribute.AttributeType.AttributeTypeValidationFailure.*;
+
/**
* The type of an {@link Attribute}, how its {@link Value} should be
* interpreted when working with an attribute (e.g. when testing, rendering,
@@ -35,108 +39,107 @@ import java.util.function.Function;
*/
public enum AttributeType {
- // TODO Implement validator functions!
+ // TODO Implement more validator functions!
+
+ STRING(ValueType.STRING, value -> Optional.empty()),
- STRING("String", ValueType.STRING, value -> Optional.empty()),
+ INTEGER(ValueType.NUMBER, value -> Optional.empty()),
- INTEGER("Integer", ValueType.NUMBER, value -> Optional.empty()),
+ DECIMAL(ValueType.NUMBER, value -> Optional.empty()),
- DECIMAL("Decimal", ValueType.NUMBER, value -> Optional.empty()),
+ BOOLEAN(ValueType.BOOLEAN, value -> Optional.empty()),
- BOOLEAN("Boolean", ValueType.BOOLEAN, value -> Optional.empty()),
+ PERCENTAGE(ValueType.NUMBER, value -> Values.getNumber(value)
+ .filter(number -> number < 0 || number > 100)
+ .map(number -> PERCENTAGE_NOT_WITHIN_BOUNDS)
+ ),
- PERCENTAGE("Percentage", ValueType.NUMBER, value -> Optional.empty()),
+ TIMESTAMP_MILLIS(ValueType.NUMBER, value -> Optional.empty()),
- TIMESTAMP_MILLIS("Timestamp milliseconds", ValueType.NUMBER, value -> Optional.empty()),
+ DATETIME(ValueType.STRING, value -> Optional.empty()),
- DATETIME("Timestamp in ISO 8601", ValueType.STRING, value -> Optional.empty()),
+ COLOR_RGB(ValueType.ARRAY, value -> Optional.empty()),
- COLOR_RGB("Color RGB", ValueType.ARRAY, value -> Optional.empty()),
+ COLOR_ARGB(ValueType.ARRAY, value -> Optional.empty()),
- COLOR_ARGB("Color ARGB", ValueType.ARRAY, value -> Optional.empty()),
+ COLOR_HEX(ValueType.STRING, value -> Optional.empty()),
- COLOR_HEX("Color HEX", ValueType.STRING, value -> Optional.empty()),
+ TEMPERATURE_CELCIUS(ValueType.NUMBER, value -> Optional.empty()),
- TEMPERATURE_CELCIUS("Temperature in Celcius", ValueType.NUMBER, value -> Optional.empty()),
+ TEMPERATURE_KELVIN(ValueType.NUMBER, value -> Optional.empty()),
- TEMPERATURE_KELVIN("Temperature in Kelvin", ValueType.NUMBER, value -> Optional.empty()),
+ TEMPERATURE_FAHRENHEIT(ValueType.NUMBER, value -> Optional.empty()),
- TEMPERATURE_FAHRENHEIT("Temperature in Fahrenheit", ValueType.NUMBER, value -> Optional.empty()),
+ DISTANCE_M(ValueType.NUMBER, value -> Optional.empty()),
- DISTANCE_M("Distance in meters", ValueType.NUMBER, value -> Optional.empty()),
+ DISTANCE_CM(ValueType.NUMBER, value -> Optional.empty()),
- DISTANCE_CM("Distance in centimeters", ValueType.NUMBER, value -> Optional.empty()),
+ DISTANCE_MM(ValueType.NUMBER, value -> Optional.empty()),
- DISTANCE_MM("Distance in millimeters", ValueType.NUMBER, value -> Optional.empty()),
+ DISTANCE_IN(ValueType.NUMBER, value -> Optional.empty()),
- DISTANCE_IN("Distance in inch", ValueType.NUMBER, value -> Optional.empty()),
+ DISTANCE_FT(ValueType.NUMBER, value -> Optional.empty()),
- DISTANCE_FT("Distance in feet", ValueType.NUMBER, value -> Optional.empty()),
+ DISTANCE_YARD(ValueType.NUMBER, value -> Optional.empty()),
- DISTANCE_YARD("Dinstance in yard", ValueType.NUMBER, value -> Optional.empty()),
+ CO2_PPM(ValueType.NUMBER, value -> Optional.empty()),
- CO2_PPM("CO2 Level in PPM", ValueType.NUMBER, value -> Optional.empty()),
+ HUMIDITY_PERCENTAGE(ValueType.NUMBER, value -> Optional.empty()),
- HUMIDITY_PERCENTAGE("Humidity percentage", ValueType.NUMBER, value -> Optional.empty()),
+ HUMIDITY_GPCM(ValueType.NUMBER, value -> Optional.empty()),
- HUMIDITY_GPCM("Humidity in grams per cubic meter", ValueType.NUMBER, value -> Optional.empty()),
+ POWER_WATT(ValueType.NUMBER, value -> Optional.empty()),
- POWER_WATT("Power in watt", ValueType.NUMBER, value -> Optional.empty()),
+ POWER_KILOWATT(ValueType.NUMBER, value -> Optional.empty()),
- POWER_KILOWATT("Power in kilowatt", ValueType.NUMBER, value -> Optional.empty()),
+ POWER_MEGAWATT(ValueType.NUMBER, value -> Optional.empty()),
- POWER_MEGAWATT("Power in megawatt", ValueType.NUMBER, value -> Optional.empty()),
+ CHARGE_PERCENTAGE(ValueType.NUMBER, value -> Optional.empty()),
- CHARGE_PERCENTAGE("Charge percentage", ValueType.NUMBER, value -> Optional.empty()),
+ CHARGE_KWH(ValueType.NUMBER, value -> Optional.empty()),
- CHARGE_KWH("Charge in kilowatt-hours", ValueType.NUMBER, value -> Optional.empty()),
+ ENERGY_KWH(ValueType.NUMBER, value -> Optional.empty()),
- ENERGY_KWH("Energy in kilowatt-hours", ValueType.NUMBER, value -> Optional.empty()),
+ ENERGY_JOULE(ValueType.NUMBER, value -> Optional.empty()),
- ENERGY_JOULE("Energy in joule", ValueType.NUMBER, value -> Optional.empty()),
+ ENERGY_MEGAJOULE(ValueType.NUMBER, value -> Optional.empty()),
- ENERGY_MEGAJOULE("Energy in megajoule", ValueType.NUMBER, value -> Optional.empty()),
+ FLOW_LPM(ValueType.NUMBER, value -> Optional.empty()),
- FLOW_LPM("Flow in litre per minute", ValueType.NUMBER, value -> Optional.empty()),
+ FLOW_CMPS(ValueType.NUMBER, value -> Optional.empty()),
- FLOW_CMPS("Flow in cubic metres per second", ValueType.NUMBER, value -> Optional.empty()),
+ FLOW_SCCM(ValueType.NUMBER, value -> Optional.empty()),
- FLOW_SCCM("Flow in cubic centimetres per minute", ValueType.NUMBER, value -> Optional.empty()),
+ FLOW_CFPS(ValueType.NUMBER, value -> Optional.empty()),
- FLOW_CFPS("Flow in cubic feet per second", ValueType.NUMBER, value -> Optional.empty()),
+ FLOW_GPM(ValueType.NUMBER, value -> Optional.empty());
- FLOW_GPM("Flow in gallons per minute", ValueType.NUMBER, value -> Optional.empty());
+ public enum AttributeTypeValidationFailure implements ValidationFailure {
+ VALUE_DOES_NOT_MATCH_ATTRIBUTE_TYPE,
+ PERCENTAGE_NOT_WITHIN_BOUNDS
+ }
- protected String displayName;
protected ValueType valueType;
- protected Function<Value, Optional<String>> validator;
+ protected Function<Value, Optional<ValidationFailure>> validator;
- AttributeType(String displayName, ValueType valueType, Function<Value, Optional<String>> validator) {
- this.displayName = displayName;
+ AttributeType(ValueType valueType, Function<Value, Optional<ValidationFailure>> validator) {
this.valueType = valueType;
this.validator = value -> {
// Always perform some basic validation
if (value != null && getValueType() != value.getType())
- return Optional.of("Value is " + value.getType() + ", but must be " + getValueType());
+ return Optional.of(VALUE_DOES_NOT_MATCH_ATTRIBUTE_TYPE);
// Custom attribute type validation
return validator.apply(value);
};
}
- public String getDisplayName() {
- return displayName;
- }
-
public ValueType getValueType() {
return valueType;
}
- public boolean isValid(Value value) {
- return !getValidationFailure(value).isPresent();
- }
- public Optional<String> getValidationFailure(Value value) {
+ public Optional<ValidationFailure> isValidValue(Value value) {
return validator.apply(value);
}
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItem.java b/model/src/main/java/org/openremote/model/attribute/MetaItem.java
index 1654a5a2c..c618957e2 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItem.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItem.java
@@ -20,23 +20,33 @@
package org.openremote.model.attribute;
import org.openremote.model.AbstractValueHolder;
+import org.openremote.model.HasUniqueResourceName;
+import org.openremote.model.ValidationFailure;
import org.openremote.model.util.TextUtil;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
import java.util.Collection;
+import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
+import static org.openremote.model.attribute.MetaItem.MetaItemValidationFailure.*;
+
/**
- * A named arbitrary {@link Value}.
+ * A named arbitrary {@link Value}. A meta item must have a value to be stored.
* <p>
* Name should be a URI, thus avoiding collisions and representing "ownership" of the meta item.
*/
public class MetaItem extends AbstractValueHolder {
+ public enum MetaItemValidationFailure implements ValidationFailure {
+ NAME_IS_REQUIRED,
+ VALUE_IS_REQUIRED
+ }
+
public MetaItem() {
this(Values.createObject());
}
@@ -45,22 +55,14 @@ public class MetaItem extends AbstractValueHolder {
super(objectValue);
}
- public MetaItem(String name) {
- this(name, null);
- }
-
public MetaItem(String name, Value value) {
super(Values.createObject());
setName(name);
setValue(value);
}
- public MetaItem(HasMetaName hasMetaName, Value value) {
- this(hasMetaName.getUrn(), value);
- }
-
- public boolean hasName() {
- return getName().isPresent();
+ public MetaItem(HasUniqueResourceName hasUniqueResourceName, Value value) {
+ this(hasUniqueResourceName.getUrn(), value);
}
public Optional<String> getName() {
@@ -72,8 +74,18 @@ public class MetaItem extends AbstractValueHolder {
}
@Override
- public boolean isValid() {
- return super.isValid() && hasName();
+ public List<ValidationFailure> getValidationFailures() {
+ List<ValidationFailure> failures = super.getValidationFailures();
+
+ if (!getName().isPresent())
+ failures.add(NAME_IS_REQUIRED);
+
+ // Meta items must have a value, unlike attributes
+ if (!getValue().isPresent()) {
+ failures.add(VALUE_IS_REQUIRED);
+ }
+
+ return failures;
}
public MetaItem copy() {
@@ -120,12 +132,12 @@ public class MetaItem extends AbstractValueHolder {
return metaItem -> isMetaNameEqualTo(metaItem, name);
}
- public static boolean isMetaNameEqualTo(MetaItem item, HasMetaName hasMetaName) {
- return hasMetaName != null && isMetaNameEqualTo(item, hasMetaName.getUrn());
+ public static boolean isMetaNameEqualTo(MetaItem item, HasUniqueResourceName hasUniqueResourceName) {
+ return hasUniqueResourceName != null && isMetaNameEqualTo(item, hasUniqueResourceName.getUrn());
}
- public static Predicate<MetaItem> isMetaNameEqualTo(HasMetaName hasMetaName) {
- return metaItem -> isMetaNameEqualTo(metaItem, hasMetaName);
+ public static Predicate<MetaItem> isMetaNameEqualTo(HasUniqueResourceName hasUniqueResourceName) {
+ return metaItem -> isMetaNameEqualTo(metaItem, hasUniqueResourceName);
}
// STREAM AND COLLECTION METHODS BELOW
@@ -153,19 +165,19 @@ public class MetaItem extends AbstractValueHolder {
.forEach(metaItems::add);
}
- public static <T extends Collection<MetaItem>> void replaceMetaByName(T metaItems, HasMetaName hasMetaName, MetaItem newMetaItem) {
- replaceMetaByName(metaItems, hasMetaName.getUrn(), newMetaItem);
+ public static <T extends Collection<MetaItem>> void replaceMetaByName(T metaItems, HasUniqueResourceName hasUniqueResourceName, MetaItem newMetaItem) {
+ replaceMetaByName(metaItems, hasUniqueResourceName.getUrn(), newMetaItem);
}
- public static <T extends Collection<MetaItem>> void replaceMetaByName(T metaItems, HasMetaName hasMetaName, Value newValue) {
- replaceMetaByName(metaItems, hasMetaName.getUrn(), newValue);
+ public static <T extends Collection<MetaItem>> void replaceMetaByName(T metaItems, HasUniqueResourceName hasUniqueResourceName, Value newValue) {
+ replaceMetaByName(metaItems, hasUniqueResourceName.getUrn(), newValue);
}
- public static <T extends Collection<MetaItem>> void replaceMetaByName(T metaItems, HasMetaName hasMetaName, T newMetaItems) {
- replaceMetaByName(metaItems, hasMetaName.getUrn(), newMetaItems);
+ public static <T extends Collection<MetaItem>> void replaceMetaByName(T metaItems, HasUniqueResourceName hasUniqueResourceName, T newMetaItems) {
+ replaceMetaByName(metaItems, hasUniqueResourceName.getUrn(), newMetaItems);
}
- public static <T extends Collection<MetaItem>, V extends Collection<Value>> void replaceMetaByNameWithValues(T metaItems, HasMetaName hasMetaName, V newValues) {
- replaceMetaByNameWithValues(metaItems, hasMetaName.getUrn(), newValues);
+ public static <T extends Collection<MetaItem>, V extends Collection<Value>> void replaceMetaByNameWithValues(T metaItems, HasUniqueResourceName hasUniqueResourceName, V newValues) {
+ replaceMetaByNameWithValues(metaItems, hasUniqueResourceName.getUrn(), newValues);
}
}
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/util/TextUtil.java b/model/src/main/java/org/openremote/model/util/TextUtil.java
index ad1c6982d..7c4c22059 100644
--- a/model/src/main/java/org/openremote/model/util/TextUtil.java
+++ b/model/src/main/java/org/openremote/model/util/TextUtil.java
@@ -21,9 +21,11 @@ package org.openremote.model.util;
import com.google.gwt.regexp.shared.RegExp;
+import java.text.MessageFormat;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
+import java.util.Properties;
import java.util.function.Predicate;
public class TextUtil {