Skip to content

armgit / core

Public Imported from GitHub
0

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

Cleanup of Asset, Attribute and Meta model including descriptors

Rich Turnerb57cf9577285
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
index 3f0607bb1..088aef8e8 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -32,7 +32,7 @@ import org.openremote.container.timer.TimerService;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.asset.agent.ProtocolConfiguration;
@@ -476,7 +476,7 @@ public abstract class AbstractProtocol implements Protocol {
AttributeValidationResult result = new AttributeValidationResult(protocolConfiguration.getName().orElse(""));
if (!ProtocolConfiguration.isProtocolConfiguration(protocolConfiguration)) {
- result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, AssetMeta.PROTOCOL_CONFIGURATION.name()));
+ result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, MetaItemType.PROTOCOL_CONFIGURATION.name()));
}
if (!ProtocolConfiguration.isValidProtocolName(protocolConfiguration.getValueAsString().orElse(null))) {
result.addAttributeFailure(new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID));
diff --git a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
index 5159a8072..e4c031344 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
@@ -29,7 +29,6 @@ import org.openremote.model.asset.agent.ProtocolConfiguration;
import org.openremote.model.asset.agent.ProtocolDescriptor;
import org.openremote.model.attribute.*;
import org.openremote.model.value.ArrayValue;
-import org.openremote.model.value.NumberValue;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.ValueType;
@@ -65,8 +64,8 @@ import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
* sensible logging to allow fault finding).
* <h3>Connecting attributes to actuators and sensors</h3>
* {@link AssetAttribute}s of {@link Asset}s can be linked to a protocol configuration
- * instance by creating an {@link AssetMeta#AGENT_LINK} {@link MetaItem} on an attribute.
- * Besides the {@link AssetMeta#AGENT_LINK}, other protocol-specific meta items may also be
+ * instance by creating an {@link MetaItemType#AGENT_LINK} {@link MetaItem} on an attribute.
+ * Besides the {@link MetaItemType#AGENT_LINK}, other protocol-specific meta items may also be
* required when an asset attribute is linked to a protocol configuration instance.
* Attributes linked to a protocol configuration instance will get passed to the protocol via
* a call to {@link #linkAttributes}.
@@ -180,7 +179,7 @@ public interface Protocol extends ContainerService {
* into an {@link ConnectionStatus#ERROR} state or to continue running (appropriate logging should
* always be used).
* <p>
- * Attributes are linked to a protocol configuration via an {@link AssetMeta#AGENT_LINK} meta item.
+ * Attributes are linked to a protocol configuration via an {@link MetaItemType#AGENT_LINK} meta item.
*/
void linkAttributes(Collection<AssetAttribute> attributes, AssetAttribute protocolConfiguration);
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java
index ba9d72ff2..de0140ba3 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/HttpClientProtocol.java
@@ -30,7 +30,7 @@ import org.openremote.model.AbstractValueHolder;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.asset.agent.ProtocolConfiguration;
import org.openremote.model.attribute.*;
@@ -76,7 +76,7 @@ import static org.openremote.model.util.TextUtil.*;
* #META_PROTOCOL_FOLLOW_REDIRECTS}</li> <li>{@link #META_FAILURE_CODES}</li> <li>{@link #META_HEADERS}</li> </ul>
* <h1>Linked Attributes</h1>
* <p>
- * {@link Attribute}s that are linked to this protocol using an {@link AssetMeta#AGENT_LINK} {@link MetaItem} support
+ * {@link Attribute}s that are linked to this protocol using an {@link MetaItemType#AGENT_LINK} {@link MetaItem} support
* the following meta items: <ul> <li>{@link #META_ATTRIBUTE_PATH} (<b>if not supplied then base URI is used</b>)</li>
* <li>{@link #META_ATTRIBUTE_METHOD}</li> <li>{@link #META_ATTRIBUTE_BODY}</li> <li>{@link
* #META_ATTRIBUTE_POLLING_SECONDS} (<b>required if attribute value should be set by the response received from this
diff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java
index 0ec12ca46..680ffb6fb 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java
@@ -7,7 +7,7 @@ import org.openremote.model.AbstractValueHolder;
import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.AssetType;
import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.ConnectionStatus;
@@ -519,7 +519,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttri
AttributeValueType type = TypeMapper.toAttributeType(datapoint);
AssetAttribute attr = asset.getAttribute(attrName).orElse(new AssetAttribute(attrName, type).setMeta(
- new MetaItem(AssetMeta.LABEL, Values.create(name)),
+ new MetaItem(MetaItemType.LABEL, Values.create(name)),
new MetaItem(KNXProtocol.META_KNX_DPT, Values.create(datapoint.getDPT())),
agentLink
));
diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
index 0f7357c5d..8f483cbf8 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
@@ -41,8 +41,8 @@ import java.util.stream.Collectors;
import static org.openremote.container.concurrent.GlobalLock.withLock;
import static org.openremote.container.concurrent.GlobalLock.withLockReturning;
import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
-import static org.openremote.model.asset.AssetMeta.RANGE_MAX;
-import static org.openremote.model.asset.AssetMeta.RANGE_MIN;
+import static org.openremote.model.asset.MetaItemType.RANGE_MAX;
+import static org.openremote.model.asset.MetaItemType.RANGE_MIN;
import static org.openremote.model.util.TextUtil.REGEXP_PATTERN_INTEGER_POSITIVE;
public class SimulatorProtocol extends AbstractProtocol {
diff --git a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
index ba6c63ff9..2cd4b9b42 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
@@ -21,7 +21,7 @@ package org.openremote.agent.protocol.timer;
import org.openremote.agent.protocol.AbstractProtocol;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.attribute.*;
import org.openremote.model.util.TextUtil;
@@ -50,7 +50,7 @@ import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
* </ul>
* <p>
* {@link AssetAttribute}s can be linked to time triggers to read/write the trigger time and/or enable/disable the
- * trigger. A linked attribute must have a valid {@link AssetMeta#AGENT_LINK} Meta Item and
+ * trigger. A linked attribute must have a valid {@link MetaItemType#AGENT_LINK} Meta Item and
* also a {@link #META_TIMER_VALUE_LINK} Meta Item to indicate what value of timer to link to {@link TimerValue}
*/
public class TimerProtocol extends AbstractProtocol {
diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
index 2fb502582..7a0361047 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
@@ -26,7 +26,7 @@ import org.openremote.agent.protocol.velbus.device.VelbusDeviceType;
import org.openremote.container.util.CodecUtil;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.AssetType;
import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.ConnectionStatus;
@@ -305,13 +305,13 @@ public abstract class AbstractVelbusProtocol extends AbstractProtocol implements
device.setAttributes(
new AssetAttribute("build", AttributeValueType.STRING, Values.create(build))
.setMeta(
- new MetaItem(AssetMeta.LABEL, Values.create("Build")),
- new MetaItem(AssetMeta.READ_ONLY, Values.create(true))
+ new MetaItem(MetaItemType.LABEL, Values.create("Build")),
+ new MetaItem(MetaItemType.READ_ONLY, Values.create(true))
),
new AssetAttribute("serialNumber", AttributeValueType.STRING, Values.create(serial))
.setMeta(
- new MetaItem(AssetMeta.LABEL, Values.create("Serial No")),
- new MetaItem(AssetMeta.READ_ONLY, Values.create(true))
+ new MetaItem(MetaItemType.LABEL, Values.create("Serial No")),
+ new MetaItem(MetaItemType.READ_ONLY, Values.create(true))
)
);
@@ -320,14 +320,14 @@ public abstract class AbstractVelbusProtocol extends AbstractProtocol implements
AssetAttribute attribute = new AssetAttribute(descriptor.getName(), descriptor.getAttributeValueType())
.setMeta(
agentLink,
- new MetaItem(AssetMeta.LABEL, Values.create(descriptor.getDisplayName()))
+ new MetaItem(MetaItemType.LABEL, Values.create(descriptor.getDisplayName()))
)
.addMeta(descriptor.getMetaItems());
if (descriptor.isReadOnly()) {
- attribute.addMeta(new MetaItem(AssetMeta.READ_ONLY, Values.create(true)));
+ attribute.addMeta(new MetaItem(MetaItemType.READ_ONLY, Values.create(true)));
} else if(descriptor.isExecutable()) {
- attribute.addMeta(new MetaItem(AssetMeta.EXECUTABLE, Values.create(true)));
+ attribute.addMeta(new MetaItem(MetaItemType.EXECUTABLE, Values.create(true)));
}
device.addAttributes(attribute);
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
index 7ee8120a3..1f198eb9a 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
@@ -45,7 +45,7 @@ import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.agent.ProtocolConfiguration;
import org.openremote.model.attribute.*;
import org.openremote.model.event.bus.EventBus;
@@ -359,7 +359,7 @@ public abstract class AbstractAssetActivity<V
protected Optional<MetaItemDescriptor> getMetaItemDescriptor(MetaItem item) {
// TODO Should use meta item descriptors from server
- return Arrays.stream(AssetMeta.values())
+ return Arrays.stream(MetaItemType.values())
.filter(assetMeta -> assetMeta.getUrn().equals(item.getName().orElse("")))
.findFirst()
.map(assetMeta -> (MetaItemDescriptor)assetMeta);
@@ -399,9 +399,9 @@ public abstract class AbstractAssetActivity<V
// Meta item value is read only if value is fixed
if (valueHolder instanceof MetaItem) {
// TODO Should use meta item descriptors from server
- return Arrays.stream(AssetMeta.values())
+ return Arrays.stream(MetaItemType.values())
.filter(assetMeta -> assetMeta.getUrn().equals(((MetaItem) valueHolder).getName()))
- .map(AssetMeta::isValueFixed)
+ .map(MetaItemType::isValueFixed)
.findFirst().orElse(false);
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEdit.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEdit.java
index d35619416..806775ccc 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEdit.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEdit.java
@@ -24,7 +24,7 @@ import org.openremote.app.client.widget.AttributeRefEditor;
import org.openremote.app.client.widget.FormView;
import org.openremote.model.ValueHolder;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetTypeDescriptor;
+import org.openremote.model.asset.AssetDescriptor;
import org.openremote.model.interop.Consumer;
import org.openremote.model.util.Pair;
@@ -41,7 +41,7 @@ public interface AssetEdit extends FormView, AssetBaseView<AssetEdit.Presenter>
void onAccessPublicRead(boolean enabled);
- void onAssetTypeSelected(AssetTypeDescriptor value);
+ void onAssetTypeSelected(AssetDescriptor value);
boolean addAttribute(String name, String type);
@@ -66,9 +66,9 @@ public interface AssetEdit extends FormView, AssetBaseView<AssetEdit.Presenter>
void hideMapPopup();
- void selectWellKnownType(AssetTypeDescriptor assetType);
+ void selectWellKnownType(AssetDescriptor assetType);
- void setAvailableWellKnownTypes(AssetTypeDescriptor[] assetTypes);
+ void setAvailableWellKnownTypes(AssetDescriptor[] assetTypes);
void setType(String type);
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
index c2b98e891..4c7566f74 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
@@ -61,6 +61,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import static org.openremote.model.asset.AssetAttribute.attributesFromJson;
+import static org.openremote.model.asset.AssetType.CUSTOM;
import static org.openremote.model.attribute.Attribute.ATTRIBUTE_NAME_VALIDATOR;
import static org.openremote.model.attribute.Attribute.isAttributeNameEqualTo;
import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;
@@ -83,7 +84,7 @@ public class AssetEditActivity
protected final AssetAttributeMapper assetAttributeMapper;
protected final Consumer<ConstraintViolation[]> validationErrorHandler;
protected List<ProtocolDescriptor> protocolDescriptors = new ArrayList<>();
- protected List<MetaItemDescriptor> metaItemDescriptors = new ArrayList<>(Arrays.asList(AssetMeta.values())); // TODO Get meta item descriptors from server
+ protected List<MetaItemDescriptor> metaItemDescriptors = new ArrayList<>(Arrays.asList(MetaItemType.values())); // TODO Get meta item descriptors from server
protected GeoJSONPoint selectedCoordinates;
protected List<AssetAttribute> initialAssetAttributes;
@@ -201,7 +202,7 @@ public class AssetEditActivity
}
@Override
- public void onAssetTypeSelected(AssetTypeDescriptor type) {
+ public void onAssetTypeSelected(AssetDescriptor type) {
asset.setType(type);
writeAttributeTypesToView(this::writeAttributesToView);
}
@@ -242,7 +243,7 @@ public class AssetEditActivity
attribute = new AssetAttribute();
attribute.setType(attributeValueType);
- attribute.addMeta(attributeValueType.getDefaultMetaItems());
+ attributeValueType.getMetaItemDescriptors().ifPresent(attribute::addMeta);
}
attribute.setName(name);
@@ -362,7 +363,7 @@ public class AssetEditActivity
}
// Agents must have protocol configurations
- query.attributeMeta(new AttributeMetaPredicate(AssetMeta.PROTOCOL_CONFIGURATION, new BooleanPredicate(true)));
+ query.attributeMeta(new AttributeMetaPredicate(MetaItemType.PROTOCOL_CONFIGURATION, new BooleanPredicate(true)));
// Only show protocol configurations
attributeFilter = ProtocolConfiguration::isProtocolConfiguration;
@@ -414,7 +415,7 @@ public class AssetEditActivity
switch (valueType) {
case ARRAY:
if (valueHolder instanceof MetaItem) {
- if (isMetaNameEqualTo((MetaItem) valueHolder, AssetMeta.AGENT_LINK)) {
+ if (isMetaNameEqualTo((MetaItem) valueHolder, MetaItemType.AGENT_LINK)) {
boolean isReadOnly = isValueReadOnly(valueHolder);
String assetWatermark = environment.getMessages().selectAgent();
String attributeWatermark = environment.getMessages().selectProtocolConfiguration();
@@ -432,7 +433,7 @@ public class AssetEditActivity
break;
case OBJECT:
if (valueHolder instanceof MetaItem) {
- if (isMetaNameEqualTo((MetaItem) valueHolder, AssetMeta.ATTRIBUTE_LINK)) {
+ if (isMetaNameEqualTo((MetaItem) valueHolder, MetaItemType.ATTRIBUTE_LINK)) {
boolean isReadOnly = isValueReadOnly(valueHolder);
String assetWatermark = environment.getMessages().selectAsset();
String attributeWatermark = environment.getMessages().selectAttribute();
@@ -570,7 +571,14 @@ public class AssetEditActivity
protected void writeAttributeTypesToView(Runnable onComplete) {
view.selectWellKnownType(asset.getWellKnownType());
//TODO replace with AssetModel getValuesSorted, through a http request
- view.setAvailableWellKnownTypes(AssetType.valuesSorted());
+ List<AssetDescriptor> list = new ArrayList<>(Arrays.asList(AssetType.values()));
+ list.sort(Comparator.comparing(AssetDescriptor::getName));
+ if (list.contains(CUSTOM)) {
+ // CUSTOM should be first
+ list.remove(CUSTOM);
+ list.add(0, CUSTOM);
+ }
+ view.setAvailableWellKnownTypes(list.toArray(new AssetDescriptor[list.size()]));
view.setType(asset.getType());
view.setTypeEditable(isNullOrEmpty(assetId));
@@ -655,7 +663,7 @@ public class AssetEditActivity
} else {
asset.setParentId(null);
}
- if (AssetType.CUSTOM.equals(asset.getWellKnownType())) {
+ if (CUSTOM.equals(asset.getWellKnownType())) {
asset.setType(view.getType());
}
if (selectedCoordinates != null) {
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java
index 439772b87..7f7293b35 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java
@@ -28,10 +28,7 @@ import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.*;
-import com.google.inject.Provider;
import org.openremote.app.client.Environment;
-import org.openremote.app.client.app.dialog.Confirmation;
-import org.openremote.app.client.app.dialog.JsonEditor;
import org.openremote.app.client.assets.attributes.AttributeView;
import org.openremote.app.client.assets.browser.AssetBrowser;
import org.openremote.app.client.assets.browser.AssetSelector;
@@ -42,7 +39,7 @@ import org.openremote.app.client.widget.PushButton;
import org.openremote.model.Constants;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetType;
-import org.openremote.model.asset.AssetTypeDescriptor;
+import org.openremote.model.asset.AssetDescriptor;
import org.openremote.model.geo.GeoJSON;
import org.openremote.model.geo.GeoJSONFeatureCollection;
import org.openremote.model.geo.GeoJSONPoint;
@@ -129,7 +126,7 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
@UiField
FormGroup typeGroup;
@UiField(provided = true)
- FormValueListBox<AssetTypeDescriptor> typeListBox;
+ FormValueListBox<AssetDescriptor> typeListBox;
@UiField
FormInputText typeInput;
@UiField
@@ -201,9 +198,9 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
};
typeListBox = new FormValueListBox<>(
- new AbstractRenderer<AssetTypeDescriptor>() {
+ new AbstractRenderer<AssetDescriptor>() {
@Override
- public String render(AssetTypeDescriptor assetType) {
+ public String render(AssetDescriptor assetType) {
if (assetType == null)
assetType = AssetType.CUSTOM;
return environment.getMessages().assetTypeLabel(assetType.getName());
@@ -436,13 +433,13 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
/* ############################################################################ */
@Override
- public void selectWellKnownType(AssetTypeDescriptor assetType) {
+ public void selectWellKnownType(AssetDescriptor assetType) {
typeListBox.setValue(assetType);
typeInput.setVisible(assetType == AssetType.CUSTOM);
}
@Override
- public void setAvailableWellKnownTypes(AssetTypeDescriptor[] assetTypes) {
+ public void setAvailableWellKnownTypes(AssetDescriptor[] assetTypes) {
typeListBox.setAcceptableValues(Arrays.asList(assetTypes));
}
@@ -450,7 +447,7 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
public void setType(String type) {
typeInput.setValue(type);
//TODO replace with AssetModel getValues, through a http request
- AssetTypeDescriptor assetType = AssetType.getByValue(type).orElse(AssetType.CUSTOM);
+ AssetDescriptor assetType = AssetType.getByValue(type).orElse(AssetType.CUSTOM);
if (assetType == AssetType.CUSTOM) {
headline.setSub(type);
} else {
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java b/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
index 6f64c307a..64c7e596e 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
@@ -25,7 +25,7 @@ import org.openremote.app.client.widget.*;
import org.openremote.app.client.Environment;
import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.ProtocolDescriptor;
import org.openremote.model.attribute.AttributeValidationResult;
@@ -67,7 +67,7 @@ public class MetaEditor extends AbstractAttributeViewExtension {
// Don't show protocol configuration item in main section
if (!newItem && item.getName()
- .map(name -> AssetMeta.PROTOCOL_CONFIGURATION.getUrn().equals(name))
+ .map(name -> MetaItemType.PROTOCOL_CONFIGURATION.getUrn().equals(name))
.orElse(false)) {
setVisible(false);
}
@@ -276,7 +276,7 @@ public class MetaEditor extends AbstractAttributeViewExtension {
this.attribute = attribute;
this.style = style;
this.protocolDescriptorSupplier = protocolDescriptorSupplier;
- isProtocolConfiguration = attribute.hasMetaItem(AssetMeta.PROTOCOL_CONFIGURATION);
+ isProtocolConfiguration = attribute.hasMetaItem(MetaItemType.PROTOCOL_CONFIGURATION);
refreshMetaItemDescriptors();
@@ -316,14 +316,14 @@ public class MetaEditor extends AbstractAttributeViewExtension {
}
}
- metaItemDescriptors.addAll(Arrays.asList(AssetMeta.values())); // TODO Get meta item descriptors from server
+ metaItemDescriptors.addAll(Arrays.asList(MetaItemType.values())); // TODO Get meta item descriptors from server
this.metaItemDescriptors = metaItemDescriptors.stream()
.filter(metaItemDescriptor -> {
// Always auto add protocol configuration using protocol from attribute drop down (don't allow manual add)
// Agent link shouldn't be allowed on protocol configurations
- return metaItemDescriptor != AssetMeta.PROTOCOL_CONFIGURATION &&
- (!isProtocolConfiguration || metaItemDescriptor != AssetMeta.AGENT_LINK);
+ return metaItemDescriptor != MetaItemType.PROTOCOL_CONFIGURATION &&
+ (!isProtocolConfiguration || metaItemDescriptor != MetaItemType.AGENT_LINK);
})
.sorted(Comparator.comparing(metaItemDescriptor -> getMetaItemDisplayName(environment, metaItemDescriptor.name())))
.toArray(MetaItemDescriptor[]::new);
@@ -401,7 +401,7 @@ public class MetaEditor extends AbstractAttributeViewExtension {
itemEditor.item.clearValue();
// TODO Should use meta item descriptors from server
- Value initialValue = Arrays.stream(AssetMeta.values())
+ Value initialValue = Arrays.stream(MetaItemType.values())
.filter(assetMeta -> assetMeta.getUrn().equals(itemEditor.nameList.getSelectedValue()))
.findFirst()
.map(MetaItemDescriptor::getInitialValue)
diff --git a/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java b/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
index 518f4b6f6..67272495c 100644
--- a/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
+++ b/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
@@ -27,7 +27,7 @@ import org.openremote.app.client.assets.attributes.AttributeView;
import org.openremote.app.client.assets.attributes.MetaEditor;
import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.attribute.*;
import org.openremote.model.interop.Consumer;
import org.openremote.model.util.EnumUtil;
@@ -213,7 +213,7 @@ public class AttributeLinkEditor extends FlowPanel {
// Check item with this name doesn't already exist
boolean canAdd = !converterAttribute.hasMetaItem(item.getName().orElse(null));
if (!canAdd) {
- String metaItemName = getMetaItemDisplayName(environment, AssetMeta.ATTRIBUTE_LINK.name());
+ String metaItemName = getMetaItemDisplayName(environment, MetaItemType.ATTRIBUTE_LINK.name());
showValidationError(attribute.getName().orElse(""), metaItemName, new ValidationFailure(FailureReason.CONVERTER_KEY_DUPLICATION, item.getName().orElse("")));
return false;
}
@@ -266,7 +266,7 @@ public class AttributeLinkEditor extends FlowPanel {
@SuppressWarnings("ParameterCanBeLocal")
protected void showConverterEditorValidationError(String attributeName, String metaItemName, ValidationFailure validationFailure) {
// Replace metaItemName with AttributeLink
- metaItemName = environment.getMessages().metaItemDisplayName(AssetMeta.ATTRIBUTE_LINK.name());
+ metaItemName = environment.getMessages().metaItemDisplayName(MetaItemType.ATTRIBUTE_LINK.name());
// Replace meta item validation failures
if (validationFailure != null) {
diff --git a/container/src/main/java/org/openremote/container/persistence/PersistenceEvent.java b/container/src/main/java/org/openremote/container/persistence/PersistenceEvent.java
index 554a90727..d5c9b4198 100644
--- a/container/src/main/java/org/openremote/container/persistence/PersistenceEvent.java
+++ b/container/src/main/java/org/openremote/container/persistence/PersistenceEvent.java
@@ -46,7 +46,7 @@ public class PersistenceEvent<T> {
}
public static Predicate isPersistenceEventForAssetType(AssetType assetType) {
- return isPersistenceEventForAssetType(assetType.getValue());
+ return isPersistenceEventForAssetType(assetType.getType());
}
public static Predicate isPersistenceEventForAssetType(String assetType) {
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index 2e919220a..ba3f3ef3c 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -37,7 +37,7 @@ import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.AssetType;
import org.openremote.model.asset.agent.*;
import org.openremote.model.attribute.AttributeEvent;
@@ -481,7 +481,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
.select(new AssetQuery.Select(AssetQuery.Include.ALL))
.attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
protocolAttributeRef.getEntityId(),
protocolAttributeRef.getAttributeName()
)
@@ -511,7 +511,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
.select(new AssetQuery.Select(AssetQuery.Include.ALL))
.attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
protocolAttributeRef.getEntityId(),
protocolAttributeRef.getAttributeName()
)
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java
index 28d926085..0fb3f5ed5 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java
@@ -24,7 +24,7 @@ import org.openremote.container.ContainerService;
import org.openremote.manager.asset.AssetProcessingException.Reason;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.attribute.*;
import org.openremote.model.attribute.AttributeEvent.Source;
@@ -43,10 +43,10 @@ import static org.openremote.model.attribute.AttributeEvent.Source.ATTRIBUTE_LIN
import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;
/**
- * This service processes asset updates on attributes that have one or more {@link AssetMeta#ATTRIBUTE_LINK} meta items.
+ * This service processes asset updates on attributes that have one or more {@link MetaItemType#ATTRIBUTE_LINK} meta items.
* <p>
* If such an event occurs then the event is 'forwarded' to the linked attribute; an attribute can contain multiple
- * {@link AssetMeta#ATTRIBUTE_LINK} meta items; optionally the value forwarded to the linked attribute can be modified
+ * {@link MetaItemType#ATTRIBUTE_LINK} meta items; optionally the value forwarded to the linked attribute can be modified
* by configuring the converter property in the meta item's value:
* <p>
* By default the exact value of the attribute is forwarded unless a key exists in the converter JSON Object that
@@ -57,7 +57,7 @@ import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;
* <p>
* To convert null values the converter key of "NULL" can be used.
* <p>
- * Example {@link AssetMeta#ATTRIBUTE_LINK} meta items:
+ * Example {@link MetaItemType#ATTRIBUTE_LINK} meta items:
* <blockquote><pre>{@code
* [
* "name": "urn:openremote:asset:meta:attributeLink",
@@ -120,7 +120,7 @@ public class AssetAttributeLinkingService implements ContainerService, AssetUpda
}
attribute.getMetaStream()
- .filter(isMetaNameEqualTo(AssetMeta.ATTRIBUTE_LINK))
+ .filter(isMetaNameEqualTo(MetaItemType.ATTRIBUTE_LINK))
.forEach(metaItem -> processLinkedAttributeUpdate(em, metaItem, attribute.getState().orElse(null)));
return false;
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetModel.java b/manager/src/main/java/org/openremote/manager/asset/AssetModel.java
index 4e203ceed..0b3d9814f 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetModel.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetModel.java
@@ -20,7 +20,7 @@
package org.openremote.manager.asset;
import org.openremote.model.asset.AssetModelProvider;
-import org.openremote.model.asset.AssetTypeDescriptor;
+import org.openremote.model.asset.AssetDescriptor;
import org.openremote.model.attribute.AttributeDescriptor;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.attribute.MetaItemDescriptor;
@@ -44,7 +44,7 @@ public class AssetModel {
public final static String META_ITEM_RESTRICTED_READ_SQL_FRAGMENT;
public final static String META_ITEM_PUBLIC_READ_SQL_FRAGMENT;
- public final static AssetTypeDescriptor[] WELL_KNOWN_ASSET_TYPES;
+ public final static AssetDescriptor[] WELL_KNOWN_ASSET_TYPES;
public final static AttributeDescriptor[] WELL_KNOWN_ATTRIBUTE_TYPES;
@@ -61,13 +61,13 @@ public class AssetModel {
META_ITEM_PUBLIC_READ_SQL_FRAGMENT =
" ('" + streamMetaItemDescriptors().filter(i -> i.getAccess().publicRead).map(MetaItemDescriptor::getUrn).collect(joining("','")) + "')";
- List<AssetTypeDescriptor> assetTypeList = new ArrayList<>();
+ List<AssetDescriptor> assetTypeList = new ArrayList<>();
ServiceLoader.load(AssetModelProvider.class).forEach(assetModelProvider -> {
LOG.fine("Adding asset type descriptors of: " + assetModelProvider);
assetTypeList.addAll(Arrays.asList(assetModelProvider.getAssetTypeDescriptors()));
});
- WELL_KNOWN_ASSET_TYPES = assetTypeList.toArray(new AssetTypeDescriptor[assetTypeList.size()]);
+ WELL_KNOWN_ASSET_TYPES = assetTypeList.toArray(new AssetDescriptor[assetTypeList.size()]);
List<AttributeDescriptor> attributeList = new ArrayList<>();
ServiceLoader.load(AssetModelProvider.class).forEach(assetModelProvider -> {
@@ -110,25 +110,25 @@ public class AssetModel {
.orElse(false);
}
- public static AssetTypeDescriptor[] getAssetTypesSorted() {
- List<AssetTypeDescriptor> list = new ArrayList<>(Arrays.asList(WELL_KNOWN_ASSET_TYPES));
+ public static AssetDescriptor[] getAssetTypesSorted() {
+ List<AssetDescriptor> list = new ArrayList<>(Arrays.asList(WELL_KNOWN_ASSET_TYPES));
- list.sort(Comparator.comparing(AssetTypeDescriptor::getName));
+ list.sort(Comparator.comparing(AssetDescriptor::getName));
if (list.contains(CUSTOM)) {
// CUSTOM should be first
list.remove(CUSTOM);
list.add(0, CUSTOM);
}
- return list.toArray(new AssetTypeDescriptor[list.size()]);
+ return list.toArray(new AssetDescriptor[list.size()]);
}
- public static Optional<AssetTypeDescriptor> getAssetTypeDescriptor(String urn) {
+ public static Optional<AssetDescriptor> getAssetDescriptor(String urn) {
if (urn == null)
return Optional.empty();
- for (AssetTypeDescriptor assetType : WELL_KNOWN_ASSET_TYPES) {
- if (urn.equals(assetType.getValue()))
+ for (AssetDescriptor assetType : WELL_KNOWN_ASSET_TYPES) {
+ if (urn.equals(assetType.getType()))
return Optional.of(assetType);
}
return Optional.empty();
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
index c93d72956..2736b4bb5 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
@@ -281,7 +281,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
if (authContext == null) {
// Check attribute has public write flag
- if (!oldAttribute.getMetaItem(AssetMeta.ACCESS_PUBLIC_WRITE).isPresent()) {
+ if (!oldAttribute.getMetaItem(MetaItemType.ACCESS_PUBLIC_WRITE).isPresent()) {
throw new AssetProcessingException(NO_AUTH_CONTEXT);
}
// Check read-only
@@ -351,8 +351,8 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
//Check if attribute is well known and the value is valid
AssetModel.getAttributeDescriptor(oldAttribute.name).ifPresent(wellKnownAttribute -> {
// Check if the value is valid
- wellKnownAttribute.getValueType()
- .isValidValue(event.getValue().orElse(null))
+ wellKnownAttribute.getValueDescriptor()
+ .getValidator().flatMap(v -> v.apply(event.getValue().orElse(null)))
.ifPresent(validationFailure -> {
throw new AssetProcessingException(
INVALID_VALUE_FOR_WELL_KNOWN_ATTRIBUTE
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index 1de0f430e..cb2b687fd 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -43,6 +43,7 @@ import javax.ws.rs.core.HttpHeaders;
import java.io.IOException;
import java.util.*;
import java.util.logging.Logger;
+import java.util.stream.Stream;
import static javax.ws.rs.core.Response.Status.*;
import static org.openremote.container.Container.JSON;
@@ -308,12 +309,12 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// An attribute added by a restricted user must be readable by restricted users
if (!updatedAttribute.isAccessRestrictedRead()) {
- updatedAttribute.addMeta(new MetaItem(AssetMeta.ACCESS_RESTRICTED_READ, Values.create(true)));
+ updatedAttribute.addMeta(new MetaItem(MetaItemType.ACCESS_RESTRICTED_READ, Values.create(true)));
}
// An attribute added by a restricted user must be writable by restricted users
if (!updatedAttribute.isAccessRestrictedWrite()) {
- updatedAttribute.addMeta(new MetaItem(AssetMeta.ACCESS_RESTRICTED_WRITE, Values.create(true)));
+ updatedAttribute.addMeta(new MetaItem(MetaItemType.ACCESS_RESTRICTED_WRITE, Values.create(true)));
}
// Add the new attribute
@@ -333,8 +334,8 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// TODO Implement "Saved Filter/Searches" properly, allowing restricted users to create rule state flags is not great
resultAsset.getAttributesStream().forEach(attribute -> {
if (attribute.getType().map(attributeType -> attributeType == AttributeValueType.RULES_TEMPLATE_FILTER).orElse(false)
- && !attribute.hasMetaItem(AssetMeta.RULE_STATE)) {
- attribute.addMeta(new MetaItem(AssetMeta.RULE_STATE, Values.create(true)));
+ && !attribute.hasMetaItem(MetaItemType.RULE_STATE)) {
+ attribute.addMeta(new MetaItem(MetaItemType.RULE_STATE, Values.create(true)));
}
});
@@ -352,15 +353,15 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
asset.getAttributesStream().forEach(assetAttribute -> {
AssetModel.getAttributeDescriptor(assetAttribute.name).ifPresent(wellKnownAttribute -> {
//Check if the type matches
- if (!wellKnownAttribute.getValueType().equals(assetAttribute.getTypeOrThrow())) {
+ if (!wellKnownAttribute.getValueDescriptor().equals(assetAttribute.getTypeOrThrow())) {
throw new IllegalStateException(
String.format("Well known attribute isn't of the correct type. Attribute name: %s. Expected type: %s",
- assetAttribute.name, wellKnownAttribute.getValueType().name()));
+ assetAttribute.name, wellKnownAttribute.getValueDescriptor().getName()));
}
//Check if the value is valid
- wellKnownAttribute.getValueType()
- .isValidValue(assetAttribute.getValue().orElseThrow(() -> new IllegalStateException("Value is empty for " + assetAttribute.name)))
+ wellKnownAttribute.getValueDescriptor()
+ .getValidator().flatMap(v -> v.apply(assetAttribute.getValue().orElseThrow(() -> new IllegalStateException("Value is empty for " + assetAttribute.name))))
.ifPresent(validationFailure -> {
throw new IllegalStateException(
String.format("Validation failed for %s with reason %s", assetAttribute.name, validationFailure.getReason().name())
@@ -458,31 +459,33 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
newAsset.setId(asset.getId());
}
- AssetModel.getAssetTypeDescriptor(asset.getType()).ifPresent(descriptor -> {
-
- newAsset.setAccessPublicRead(descriptor.getAccessPublicRead());
- //Add default meta items if not present
- newAsset.getAttributesStream().forEach(AssetAttribute ->
- descriptor.getDefaultAttributes().filter(defaultAttribute ->
- defaultAttribute.getNameOrThrow().equalsIgnoreCase(AssetAttribute.getNameOrThrow())
- ).findFirst().ifPresent(defaultAttribute -> {
- AssetAttribute.addMeta(
- defaultAttribute.getMetaStream().filter(defaultMeta ->
- AssetAttribute.getMetaStream().noneMatch(serverMeta ->
- serverMeta.equals(defaultMeta))
- ).toArray(MetaItem[]::new)
- );
- })
- );
+ AssetModel.getAssetDescriptor(asset.getType()).ifPresent(assetDescriptor -> {
- //Add missing attributes
- newAsset.addAttributes(descriptor.getDefaultAttributes()
- .filter(assetAttribute ->
- newAsset.getAttributesStream().noneMatch(serverAttribute ->
- serverAttribute.getNameOrThrow().equalsIgnoreCase(assetAttribute.getNameOrThrow())
- )
- ).toArray(AssetAttribute[]::new)
- );
+ newAsset.setAccessPublicRead(assetDescriptor.getAccessPublicRead());
+
+ // Add meta items to well known attributes if not present
+ newAsset.getAttributesStream().forEach(assetAttribute -> {
+ Optional<AttributeDescriptor> attributeDescriptor = assetDescriptor.getAttributeDescriptors()
+ .flatMap(attributeDescriptors ->
+ Arrays.stream(attributeDescriptors)
+ .filter(attrDescriptor -> attrDescriptor.getName().equals(assetAttribute.getNameOrThrow()))
+ .findFirst()
+ );
+
+ attributeDescriptor.ifPresent(defaultAttribute ->
+ defaultAttribute.getMetaItemDescriptors().ifPresent(metaItemDescriptors ->
+ assetAttribute.addMeta(
+ Arrays.stream(metaItemDescriptors).filter(metaItemDescriptor -> !assetAttribute.hasMetaItem(metaItemDescriptor)).map(MetaItem::new).toArray(MetaItem[]::new)
+ ))
+ );
+ });
+
+ // Add attributes for this well known asset if not present
+ assetDescriptor.getAttributeDescriptors().ifPresent(attributeDescriptors ->
+ newAsset.addAttributes(
+ Arrays.stream(attributeDescriptors).filter(attributeDescriptor ->
+ !newAsset.hasAttribute(attributeDescriptor.getName())).map(AssetAttribute::new).toArray(AssetAttribute[]::new)
+ ));
});
//Check if a well known attribute is added
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
index 9ab4da10a..f9829b4ad 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -732,7 +732,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
sb.append("select jsonb_agg(AM.VALUE)");
sb.append(" from jsonb_array_elements(AX.VALUE #> '{meta}') as AM");
sb.append(" where AM.VALUE #>> '{name}' = '");
- sb.append(AssetMeta.LABEL.getUrn());
+ sb.append(MetaItemType.LABEL.getUrn());
sb.append("'))) from jsonb_each(A.attributes) as AX");
if (access != PRIVATE_READ) {
// Use implicit inner join on meta array set to only select non-private attributes
@@ -772,7 +772,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
// Filter non-private access attributes
AttributeMetaPredicate accessPredicate =
new AttributeMetaPredicate()
- .itemName(access == RESTRICTED_READ ? AssetMeta.ACCESS_RESTRICTED_READ : AssetMeta.ACCESS_PUBLIC_READ)
+ .itemName(access == RESTRICTED_READ ? MetaItemType.ACCESS_RESTRICTED_READ : MetaItemType.ACCESS_PUBLIC_READ)
.itemValue(new BooleanPredicate(true));
sb.append(buildAttributeMetaFilter(accessPredicate, binders));
}
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
index 8dd2a80a7..6f8c439d2 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -6,7 +6,6 @@ import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.timer.TimerService;
-import org.openremote.container.web.WebService;
import org.openremote.manager.asset.AssetProcessingException;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.asset.AssetUpdateProcessor;
@@ -15,7 +14,7 @@ import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.attribute.AttributeEvent.Source;
import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.datapoint.AssetDatapoint;
@@ -49,7 +48,7 @@ import static java.util.stream.Collectors.toList;
/**
* Store and retrieve datapoints for asset attributes and periodically purge data points based on
- * {@link org.openremote.model.asset.AssetMeta#DATA_POINTS_MAX_AGE_DAYS} {@link org.openremote.model.attribute.MetaItem}
+ * {@link MetaItemType#DATA_POINTS_MAX_AGE_DAYS} {@link org.openremote.model.attribute.MetaItem}
* and {@link #DATA_POINTS_MAX_AGE_DAYS} setting; storage duration defaults to {@value #DATA_POINTS_MAX_AGE_DAYS_DEFAULT}
* days.
*/
@@ -295,8 +294,8 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
List<Asset> assets = assetStorageService.findAll(
new AssetQuery()
.attributeMeta(
- new AttributeMetaPredicate(AssetMeta.DATA_POINTS_MAX_AGE_DAYS),
- new AttributeMetaPredicate(AssetMeta.STORE_DATA_POINTS))
+ new AttributeMetaPredicate(MetaItemType.DATA_POINTS_MAX_AGE_DAYS),
+ new AttributeMetaPredicate(MetaItemType.STORE_DATA_POINTS))
.select(new BaseAssetQuery.Select(BaseAssetQuery.Include.ONLY_ID_AND_NAME_AND_ATTRIBUTES)));
List<AssetAttribute> attributes = assets.stream()
@@ -304,7 +303,7 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
.getAttributesStream()
.filter(assetAttribute ->
assetAttribute.isStoreDatapoints()
- && assetAttribute.hasMetaItem(AssetMeta.DATA_POINTS_MAX_AGE_DAYS))
+ && assetAttribute.hasMetaItem(MetaItemType.DATA_POINTS_MAX_AGE_DAYS))
.collect(toList()))
.flatMap(List::stream)
.collect(toList());
@@ -322,7 +321,7 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
Map<Integer, List<AssetAttribute>> ageAttributeRefMap = attributes.stream()
.collect(groupingBy(attribute ->
attribute
- .getMetaItem(AssetMeta.DATA_POINTS_MAX_AGE_DAYS)
+ .getMetaItem(MetaItemType.DATA_POINTS_MAX_AGE_DAYS)
.flatMap(metaItem ->
Values.getIntegerCoerced(metaItem.getValue().orElse(null)))
.orElse(maxDatapointAgeDays)));
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
index a3bf8dec0..f99eb9ca5 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
@@ -32,7 +32,7 @@ import org.openremote.manager.rules.facade.NotificationsFacade;
import org.openremote.manager.rules.facade.UsersFacade;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.model.asset.Asset;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.attribute.AttributeType;
import org.openremote.model.query.filter.GeofencePredicate;
import org.openremote.model.query.filter.LocationAttributePredicate;
@@ -506,7 +506,7 @@ public class RulesEngine<T extends Ruleset> {
}
/**
- * This is called with all the asset's that have a location attribute marked with {@link AssetMeta#RULE_STATE} and
+ * This is called with all the asset's that have a location attribute marked with {@link MetaItemType#RULE_STATE} and
* that are in the scope of a rule containing a location predicate.
*/
protected void processLocationRules(List<AssetStateLocationPredicates> assetStateLocationPredicates) {
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
index fb1b24232..f6c30e7d6 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -38,7 +38,7 @@ import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.model.Constants;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.attribute.AttributeEvent.Source;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.query.filter.AttributeMetaPredicate;
@@ -80,7 +80,7 @@ import static org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttrib
* If an updated attribute {@link AssetAttribute#isRuleEvent}, another temporary {@link AssetState} fact is inserted in
* the rules engines in scope. This fact expires automatically if the lifetime set in {@link
* RulesService#RULE_EVENT_EXPIRES} is reached, or if the lifetime set in the attribute {@link
- * AssetMeta#RULE_EVENT_EXPIRES} is reached.
+ * MetaItemType#RULE_EVENT_EXPIRES} is reached.
* <p>
* Each asset attribute update is processed in the following order:
* <ol>
@@ -756,7 +756,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
.select(new AssetQuery.Select(AssetQuery.Include.ALL))
.attributeMeta(
new AttributeMetaPredicate(
- AssetMeta.RULE_STATE,
+ MetaItemType.RULE_STATE,
new BooleanPredicate(true))
));
@@ -768,7 +768,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
/**
* Called when an engine's rules change identifying assets with location attributes marked with {@link
- * AssetMeta#RULE_STATE} that also have {@link LocationAttributePredicate} in the rules. The job here is to
+ * MetaItemType#RULE_STATE} that also have {@link LocationAttributePredicate} in the rules. The job here is to
* identify the asset's (via {@link AssetState}) that have modified {@link LocationAttributePredicate}s and to
* notify the {@link GeofenceAssetAdapter}s.
*/
diff --git a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
index 7a3fbd517..3c86dc866 100644
--- a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
@@ -45,7 +45,7 @@ import java.util.function.Supplier;
import static org.openremote.agent.protocol.macro.MacroProtocol.META_MACRO_ACTION_INDEX;
import static org.openremote.agent.protocol.timer.TimerConfiguration.initTimerConfiguration;
import static org.openremote.agent.protocol.timer.TimerProtocol.META_TIMER_VALUE_LINK;
-import static org.openremote.model.asset.AssetMeta.*;
+import static org.openremote.model.asset.MetaItemType.*;
import static org.openremote.model.asset.AssetType.*;
import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;
import static org.openremote.model.attribute.AttributeValueType.*;
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
index deed3aa18..c68d640d3 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
@@ -26,7 +26,7 @@ import org.openremote.manager.security.UserConfiguration;
import org.openremote.manager.setup.AbstractManagerSetup;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.asset.UserAsset;
import org.openremote.model.attribute.*;
import org.openremote.model.geo.GeoJSONPoint;
@@ -44,7 +44,7 @@ import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.List;
-import static org.openremote.model.asset.AssetMeta.*;
+import static org.openremote.model.asset.MetaItemType.*;
import static org.openremote.model.asset.AssetType.*;
import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;
import static org.openremote.model.attribute.AttributeValueType.*;
@@ -491,7 +491,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
switch (attributeIndex) {
case 2:
return new MetaItem[]{
- new MetaItem(AssetMeta.AGENT_LINK,
+ new MetaItem(MetaItemType.AGENT_LINK,
new AttributeRef(apartment1ServiceAgentId,
"apartmentSimulator").toArrayValue()),
new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT,
@@ -499,7 +499,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
};
case 3:
return new MetaItem[]{
- new MetaItem(AssetMeta.AGENT_LINK,
+ new MetaItem(MetaItemType.AGENT_LINK,
new AttributeRef(apartment1ServiceAgentId,
"apartmentSimulator").toArrayValue()),
new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT,
@@ -507,7 +507,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
};
case 4:
return new MetaItem[]{
- new MetaItem(AssetMeta.AGENT_LINK,
+ new MetaItem(MetaItemType.AGENT_LINK,
new AttributeRef(apartment1ServiceAgentId,
"apartmentSimulator").toArrayValue()),
new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT,
diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.java
index 60738d981..7b99ffb22 100644
--- a/model/src/main/java/org/openremote/model/asset/Asset.java
+++ b/model/src/main/java/org/openremote/model/asset/Asset.java
@@ -282,7 +282,7 @@ public class Asset implements IdentifiableEntity {
public Asset() {
}
- public Asset(String name, AssetType type) {
+ public Asset(String name, AssetDescriptor type) {
this(name, type, null, null);
}
@@ -290,19 +290,21 @@ public class Asset implements IdentifiableEntity {
this(name, type, false, null, null);
}
- public Asset(@NotNull String name, @NotNull AssetType type, Asset parent) {
- this(name, type.getValue(), parent);
+ public Asset(@NotNull String name, @NotNull AssetDescriptor type, Asset parent) {
+ this(name, type, parent, null);
}
public Asset(@NotNull String name, @NotNull String type, Asset parent) {
this(name, type, false, parent, null);
}
- public Asset(@NotNull String name, @NotNull AssetType type, Asset parent, @NotNull String realm) {
- this(name, type.getValue(), false, parent, realm);
+ public Asset(@NotNull String name, @NotNull AssetDescriptor type, Asset parent, String realm) {
+ this(name, type.getType(), type.getAccessPublicRead(), parent, realm);
+ type.getAttributeDescriptors().ifPresent(attributeDescriptors ->
+ addAttributes(Arrays.stream(attributeDescriptors).map(AssetAttribute::new).toArray(AssetAttribute[]::new)));
}
- public Asset(@NotNull String name, @NotNull String type, boolean accessPublicRead, Asset parent, @NotNull String realm) {
+ public Asset(@NotNull String name, @NotNull String type, boolean accessPublicRead, Asset parent, String realm) {
setRealm(realm);
setName(name);
setType(type);
@@ -416,8 +418,8 @@ public class Asset implements IdentifiableEntity {
this.type = type;
}
- public void setType(AssetTypeDescriptor type) {
- setType(type != null ? type.getValue() : null);
+ public void setType(AssetDescriptor type) {
+ setType(type != null ? type.getType() : null);
}
public boolean isAccessPublicRead() {
@@ -526,9 +528,8 @@ public class Asset implements IdentifiableEntity {
public List<AssetAttribute> getAttributesList() {
if (attributeList == null) {
- attributeList = new ObservableList<>(attributesFromJson(attributes, id).collect(Collectors.toList()), () -> {
- this.attributes = attributesToJson(attributeList).orElse(Values.createObject());
- });
+ attributeList = new ObservableList<>(attributesFromJson(attributes, id).collect(Collectors.toList()),
+ () -> this.attributes = attributesToJson(attributeList).orElse(Values.createObject()));
}
return attributeList;
}
@@ -610,12 +611,14 @@ public class Asset implements IdentifiableEntity {
public void setCoordinates(GeoJSONPoint coordinates) {
AssetAttribute locationAttribute = getAttributesStream()
.filter(attribute -> attribute.getNameOrThrow().equals(LOCATION.getName()))
- .findFirst().orElse(new AssetAttribute(LOCATION.getName(), LOCATION.getValueType()));
+ .findFirst().orElse(new AssetAttribute(LOCATION));
locationAttribute.setValue(coordinates == null ? null : coordinates.toValue());
replaceAttribute(locationAttribute);
}
+
+
public boolean hasGeoFeature() {
return getCoordinates() != null;
}
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 923fa29a2..13dcb8067 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
@@ -29,9 +29,10 @@ import org.openremote.model.value.Values;
import java.util.*;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.openremote.model.asset.AssetMeta.*;
+import static org.openremote.model.asset.MetaItemType.*;
import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;
import static org.openremote.model.attribute.MetaItem.replaceMetaByName;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;
@@ -58,22 +59,36 @@ public class AssetAttribute extends Attribute {
}
public AssetAttribute(AttributeDescriptor attributeDescriptor) {
- this(attributeDescriptor.getName(), attributeDescriptor.getValueType(), attributeDescriptor.getDefaultValue());
+ this(attributeDescriptor.getName(), attributeDescriptor);
+ }
+
+ public AssetAttribute(String name, AttributeDescriptor attributeDescriptor) {
+ this(name, attributeDescriptor, attributeDescriptor.getInitialValue());
}
public AssetAttribute(AttributeDescriptor attributeDescriptor, Value value) {
- this(attributeDescriptor, value, 0);
+ this(attributeDescriptor.getName(), attributeDescriptor, value);
+ }
+
+ public AssetAttribute(String name, AttributeDescriptor attributeDescriptor, Value value) {
+ this(name, attributeDescriptor, value, 0L);
}
public AssetAttribute(AttributeDescriptor attributeDescriptor, Value value, long timestamp) {
- super(attributeDescriptor.getName(), attributeDescriptor.getValueType(), value);
+ this(attributeDescriptor.getName(), attributeDescriptor, value, timestamp);
+ }
+
+ public AssetAttribute(String name, AttributeDescriptor attributeDescriptor, Value value, long timestamp) {
+ super(name, attributeDescriptor.getValueDescriptor(), value);
if (value != null) {
- if (value.getType() != attributeDescriptor.getValueType().getValueType()) {
+ if (value.getType() != attributeDescriptor.getValueDescriptor().getValueType()) {
throw new IllegalArgumentException("Provided value type is not compatible with this attribute type");
}
}
setValue(value, timestamp);
- addMeta(attributeDescriptor.getDefaultMetaItems());
+ attributeDescriptor.getMetaItemDescriptors().ifPresent(metaItemDescriptors ->
+ addMeta(Arrays.stream(metaItemDescriptors).map(MetaItem::new).toArray(MetaItem[]::new))
+ );
}
public AssetAttribute(String name, AttributeValueType type, Value value, long timestamp) {
@@ -104,8 +119,6 @@ public class AssetAttribute extends Attribute {
setAssetId(assetId);
}
- //TODO constructor which takes a AttributeDescriptor
-
public Optional<String> getAssetId() {
return Optional.ofNullable(assetId);
}
@@ -159,6 +172,13 @@ public class AssetAttribute extends Attribute {
return this;
}
+ public AssetAttribute addMeta(MetaItemDescriptor... metaItemDescriptors) {
+ if (metaItemDescriptors != null) {
+ getMeta().addAll(Arrays.stream(metaItemDescriptors).map(MetaItem::new).collect(Collectors.toList()));
+ }
+ return this;
+ }
+
/**
* @return The current value and its timestamp represented as an attribute event.
*/
@@ -273,7 +293,7 @@ public class AssetAttribute extends Attribute {
}
/**
- * Defaults to <code>true</code> if there is no {@link AssetMeta#DISABLED} item.
+ * Defaults to <code>true</code> if there is no {@link MetaItemType#DISABLED} item.
*/
public boolean isEnabled() {
return getMetaStream()
@@ -293,7 +313,7 @@ public class AssetAttribute extends Attribute {
public boolean isAccessRestrictedRead() {
return getMetaStream()
- .filter(isMetaNameEqualTo(AssetMeta.ACCESS_RESTRICTED_READ))
+ .filter(isMetaNameEqualTo(MetaItemType.ACCESS_RESTRICTED_READ))
.findFirst()
.map(metaItem -> metaItem.getValueAsBoolean().orElse(false))
.orElse(false);
@@ -301,7 +321,7 @@ public class AssetAttribute extends Attribute {
public boolean isAccessRestrictedWrite() {
return getMetaStream()
- .filter(isMetaNameEqualTo(AssetMeta.ACCESS_RESTRICTED_WRITE))
+ .filter(isMetaNameEqualTo(MetaItemType.ACCESS_RESTRICTED_WRITE))
.findFirst()
.map(metaItem -> metaItem.getValueAsBoolean().orElse(false))
.orElse(false);
@@ -309,7 +329,7 @@ public class AssetAttribute extends Attribute {
public boolean isAccessPublicRead() {
return getMetaStream()
- .filter(isMetaNameEqualTo(AssetMeta.ACCESS_PUBLIC_READ))
+ .filter(isMetaNameEqualTo(MetaItemType.ACCESS_PUBLIC_READ))
.findFirst()
.map(metaItem -> metaItem.getValueAsBoolean().orElse(false))
.orElse(false);
diff --git a/model/src/main/java/org/openremote/model/asset/AssetTypeDescriptor.java b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
similarity index 81%
rename from model/src/main/java/org/openremote/model/asset/AssetTypeDescriptor.java
rename to model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
index 2c3f89b52..37b4beceb 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetTypeDescriptor.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
@@ -19,17 +19,19 @@
*/
package org.openremote.model.asset;
-import java.util.stream.Stream;
+import org.openremote.model.attribute.AttributeDescriptor;
-public interface AssetTypeDescriptor {
+import java.util.Optional;
+
+public interface AssetDescriptor {
String getName();
- String getValue();
+ String getType();
String getIcon();
boolean getAccessPublicRead();
- Stream<AssetAttribute> getDefaultAttributes();
+ Optional<AttributeDescriptor[]> getAttributeDescriptors();
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetModelProvider.java b/model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
index f6bdee71a..4f69e5946 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
@@ -29,7 +29,7 @@ public interface AssetModelProvider {
MetaItemDescriptor[] getMetaItemDescriptors();
- AssetTypeDescriptor[] getAssetTypeDescriptors();
+ AssetDescriptor[] getAssetTypeDescriptors();
AttributeDescriptor[] getAttributeDescriptors();
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetResource.java b/model/src/main/java/org/openremote/model/asset/AssetResource.java
index f1a588220..071134905 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetResource.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetResource.java
@@ -197,7 +197,7 @@ public interface AssetResource {
* <p>
* If the asset or attribute doesn't exist then a 404 status is returned.
* <p>
- * If an attribute is marked as {@link AssetMeta#ACCESS_PUBLIC_WRITE} then the attribute can be written publicly
+ * If an attribute is marked as {@link MetaItemType#ACCESS_PUBLIC_WRITE} then the attribute can be written publicly
* <p>
* This operation is ultimately asynchronous, any call will return before the actual attribute value is changed in
* any storage or downstream processors. Thus any constraint violation or processing error will not be returned from
diff --git a/model/src/main/java/org/openremote/model/asset/AssetType.java b/model/src/main/java/org/openremote/model/asset/AssetType.java
index f5463c2ab..75c432f10 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetType.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetType.java
@@ -19,16 +19,12 @@
*/
package org.openremote.model.asset;
-import org.openremote.model.attribute.MetaItem;
-import org.openremote.model.value.Values;
+import org.openremote.model.attribute.AttributeDescriptor;
import java.util.*;
-import java.util.stream.Stream;
import static org.openremote.model.Constants.ASSET_NAMESPACE;
-import static org.openremote.model.asset.AssetMeta.*;
-import static org.openremote.model.attribute.AttributeValueType.NUMBER;
-import static org.openremote.model.attribute.AttributeValueType.STRING;
+import static org.openremote.model.attribute.AttributeType.*;
/**
* Asset type is an arbitrary string. It should be URI. This enum contains the well-known URIs for functionality we want
@@ -36,38 +32,16 @@ import static org.openremote.model.attribute.AttributeValueType.STRING;
* <p>
* TODO https://people.eecs.berkeley.edu/~arka/papers/buildsys2015_metadatasurvey.pdf
*/
-public enum AssetType implements AssetTypeDescriptor {
+public enum AssetType implements AssetDescriptor {
CUSTOM(null, "cube"),
BUILDING(ASSET_NAMESPACE + ":building", "building",
- new AssetAttribute("area", NUMBER)
- .setMeta(
- new MetaItem(LABEL, Values.create("Surface Area")),
- new MetaItem(DESCRIPTION, Values.create("Floor area of building measured in m²")),
- new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/area"))
- ),
- new AssetAttribute("geoStreet", STRING)
- .setMeta(
- new MetaItem(LABEL, Values.create("Street")),
- new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoStreet"))
- ),
- new AssetAttribute("geoPostalCode", NUMBER)
- .setMeta(
- new MetaItem(LABEL, Values.create("Postal Code")),
- new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoPostalCode"))
- ),
- new AssetAttribute("geoCity", STRING)
- .setMeta(
- new MetaItem(LABEL, Values.create("City")),
- new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoCity"))
- ),
- new AssetAttribute("geoCountry", STRING)
- .setMeta(
- new MetaItem(LABEL, Values.create("Country")),
- new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoCountry"))
- )
- ),
+ SURFACE_AREA,
+ GEO_STREET,
+ GEO_CITY,
+ GEO_COUNTRY,
+ GEO_POSTAL_CODE),
FLOOR(ASSET_NAMESPACE + ":floor", "server"),
@@ -81,33 +55,20 @@ public enum AssetType implements AssetTypeDescriptor {
THING(ASSET_NAMESPACE + ":thing", "cog");
- final protected String value;
+ final protected String type;
final protected String icon;
final protected boolean accessPublicRead;
- final protected AssetAttribute[] defaultAttributes;
+ final protected AttributeDescriptor[] attributeDescriptors;
- AssetType(String value, String icon, AssetAttribute... defaultAttributes) {
- this(value, icon, false, defaultAttributes);
+ AssetType(String type, String icon, AttributeDescriptor... attributeDescriptors) {
+ this(type, icon, false, attributeDescriptors);
}
- AssetType(String value, String icon, boolean accessPublicRead, AssetAttribute... defaultAttributes) {
- this.value = value;
+ AssetType(String type, String icon, boolean accessPublicRead, AttributeDescriptor... attributeDescriptors) {
+ this.type = type;
this.icon = icon;
this.accessPublicRead = accessPublicRead;
- this.defaultAttributes = defaultAttributes;
- }
-
- public static AssetTypeDescriptor[] valuesSorted() {
- List<AssetTypeDescriptor> list = new ArrayList<>(Arrays.asList(values()));
-
- list.sort(Comparator.comparing(AssetTypeDescriptor::getName));
- if (list.contains(CUSTOM)) {
- // CUSTOM should be first
- list.remove(CUSTOM);
- list.add(0, CUSTOM);
- }
-
- return list.toArray(new AssetTypeDescriptor[list.size()]);
+ this.attributeDescriptors = attributeDescriptors;
}
public static Optional<AssetType> getByValue(String value) {
@@ -115,7 +76,7 @@ public enum AssetType implements AssetTypeDescriptor {
return Optional.empty();
for (AssetType assetType : values()) {
- if (value.equals(assetType.getValue()))
+ if (value.equals(assetType.getType()))
return Optional.of(assetType);
}
return Optional.empty();
@@ -127,8 +88,8 @@ public enum AssetType implements AssetTypeDescriptor {
}
@Override
- public String getValue() {
- return value;
+ public String getType() {
+ return type;
}
@Override
@@ -142,7 +103,7 @@ public enum AssetType implements AssetTypeDescriptor {
}
@Override
- public Stream<AssetAttribute> getDefaultAttributes() {
- return defaultAttributes != null ? Arrays.stream(defaultAttributes) : Stream.empty();
+ public Optional<AttributeDescriptor[]> getAttributeDescriptors() {
+ return Optional.ofNullable(attributeDescriptors);
}
}
diff --git a/model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java b/model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
index 936f0b7e0..9aec0d55c 100644
--- a/model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
+++ b/model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
@@ -30,11 +30,11 @@ public class DefaultAssetModelProvider implements AssetModelProvider {
@Override
public MetaItemDescriptor[] getMetaItemDescriptors() {
- return AssetMeta.values();
+ return MetaItemType.values();
}
@Override
- public AssetTypeDescriptor[] getAssetTypeDescriptors() {
+ public AssetDescriptor[] getAssetTypeDescriptors() {
return AssetType.values();
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/MetaItemType.java
similarity index 96%
rename from model/src/main/java/org/openremote/model/asset/AssetMeta.java
rename to model/src/main/java/org/openremote/model/asset/MetaItemType.java
index 5ad9e3c8e..0fae0c1f4 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java
+++ b/model/src/main/java/org/openremote/model/asset/MetaItemType.java
@@ -44,7 +44,7 @@ import static org.openremote.model.util.TextUtil.REGEXP_PATTERN_INTEGER_POSITIVE
* <p>
* TODO https://people.eecs.berkeley.edu/~arka/papers/buildsys2015_metadatasurvey.pdf
*/
-public enum AssetMeta implements MetaItemDescriptor {
+public enum MetaItemType implements MetaItemDescriptor {
/**
* Marks an attribute of an agent asset as a {@link org.openremote.model.asset.agent.ProtocolConfiguration}. The
@@ -391,11 +391,11 @@ public enum AssetMeta implements MetaItemDescriptor {
final protected String patternFailureMessage;
final protected Function<Value, Optional<ValidationFailure>> validator;
- AssetMeta(String urn, Access access, ValueType valueType, String pattern, String patternFailureMessage, Value initialValue, boolean valueFixed) {
+ MetaItemType(String urn, Access access, ValueType valueType, String pattern, String patternFailureMessage, Value initialValue, boolean valueFixed) {
this(urn, access, valueType, pattern, patternFailureMessage, initialValue, valueFixed, null);
}
- AssetMeta(String urn, Access access, ValueType valueType, String pattern, String patternFailureMessage, Value initialValue, boolean valueFixed, Function<Value, Optional<ValidationFailure>> validator) {
+ MetaItemType(String urn, Access access, ValueType valueType, String pattern, String patternFailureMessage, Value initialValue, boolean valueFixed, Function<Value, Optional<ValidationFailure>> validator) {
if (initialValue != null && initialValue.getType() != valueType) {
throw new IllegalStateException("Initial asset meta value must be of the same type as the asset meta");
}
@@ -458,4 +458,8 @@ public enum AssetMeta implements MetaItemDescriptor {
public boolean isValueFixed() {
return valueFixed;
}
+
+ public MetaItemDescriptor withInitialValue(Value initialValue) {
+ return new MetaItemDescriptorImpl(this, initialValue);
+ }
}
diff --git a/model/src/main/java/org/openremote/model/asset/UserAsset.java b/model/src/main/java/org/openremote/model/asset/UserAsset.java
index 73dcabee1..851565cca 100644
--- a/model/src/main/java/org/openremote/model/asset/UserAsset.java
+++ b/model/src/main/java/org/openremote/model/asset/UserAsset.java
@@ -35,14 +35,14 @@ import java.util.Date;
* <ul>
* <li>
* When a restricted client reads assets, only dynamic attributes with
- * {@link AssetMeta#ACCESS_RESTRICTED_READ} and attribute meta items with {@link MetaItemDescriptor.Access#restrictedRead}
+ * {@link MetaItemType#ACCESS_RESTRICTED_READ} and attribute meta items with {@link MetaItemDescriptor.Access#restrictedRead}
* are included. A restricted client may submit a query for public assets and dynamic attributes with
- * {@link AssetMeta#ACCESS_PUBLIC_READ} and meta items with {@link MetaItemDescriptor.Access#publicRead}.
+ * {@link MetaItemType#ACCESS_PUBLIC_READ} and meta items with {@link MetaItemDescriptor.Access#publicRead}.
* </li>
* <li>
* When a restricted client updates existing assets, new dynamic attributes can be added, but
- * only attributes with {@link AssetMeta#ACCESS_RESTRICTED_WRITE} can be updated or deleted. Any new attributes
- * are automatically set with {@link AssetMeta#ACCESS_RESTRICTED_READ} and {@link AssetMeta#ACCESS_RESTRICTED_WRITE},
+ * only attributes with {@link MetaItemType#ACCESS_RESTRICTED_WRITE} can be updated or deleted. Any new attributes
+ * are automatically set with {@link MetaItemType#ACCESS_RESTRICTED_READ} and {@link MetaItemType#ACCESS_RESTRICTED_WRITE},
* thus ensuring that a restricted client can fully access its own attributes. Any added, updated, or removed meta
* items of attributes must be {@link MetaItemDescriptor.Access#restrictedWrite}.
* </li>
diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java b/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java
index f4cfe8fe1..f985c6292 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java
@@ -23,13 +23,13 @@ import org.openremote.model.AbstractValueHolder;
import org.openremote.model.attribute.Attribute;
import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.attribute.MetaItem;
-import org.openremote.model.asset.AssetMeta;
+import org.openremote.model.asset.MetaItemType;
import java.util.Optional;
import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;
import static org.openremote.model.attribute.MetaItem.replaceMetaByName;
-import static org.openremote.model.asset.AssetMeta.AGENT_LINK;
+import static org.openremote.model.asset.MetaItemType.AGENT_LINK;
/**
* An asset attribute can be linked to an agent's {@link ProtocolConfiguration},
@@ -38,7 +38,7 @@ import static org.openremote.model.asset.AssetMeta.AGENT_LINK;
* Value changes will be send to the protocol (actuators) and the protocol can update the attribute's
* value (sensors).
* <p>
- * The link is configured through an {@link AttributeRef} in {@link AssetMeta#AGENT_LINK}.
+ * The link is configured through an {@link AttributeRef} in {@link MetaItemType#AGENT_LINK}.
*/
final public class AgentLink {
diff --git a/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java b/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java
index 201a64ba2..c3ef315d5 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java
@@ -19,6 +19,7 @@
*/
package org.openremote.model.asset.agent;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.attribute.MetaItem;
/**
@@ -56,7 +57,7 @@ public enum ConnectionStatus {
* Disabled.
* <p>
* For protocol configurations this generally means that it is disabled (i.e. it has a
- * {@link org.openremote.model.asset.AssetMeta#DISABLED} {@link MetaItem} with a value of <code>true</code>).
+ * {@link MetaItemType#DISABLED} {@link MetaItem} with a value of <code>true</code>).
*/
DISABLED,
diff --git a/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java b/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java
index d8c001b25..bd0fcc3fa 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java
@@ -21,6 +21,7 @@ package org.openremote.model.asset.agent;
import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.AssetAttribute;
+import org.openremote.model.asset.MetaItemType;
import org.openremote.model.attribute.AttributeValueType;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.util.TextUtil;
@@ -29,14 +30,14 @@ import org.openremote.model.value.Values;
import java.util.Optional;
import java.util.function.UnaryOperator;
-import static org.openremote.model.asset.AssetMeta.PROTOCOL_CONFIGURATION;
+import static org.openremote.model.asset.MetaItemType.PROTOCOL_CONFIGURATION;
import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;
/**
* Agent attributes can be named protocol configurations, defining a logical instance of a protocol.
* <p>
* A protocol configuration attribute must be marked
- * {@link org.openremote.model.asset.AssetMeta#PROTOCOL_CONFIGURATION} and its
+ * {@link MetaItemType#PROTOCOL_CONFIGURATION} and its
* value must be valid RfC 2141 URN.
* <p>
* Protocol-specific settings and details are managed as {@link MetaItem} of the attribute.
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 8bf2f5e9e..bf17eab9b 100644
--- a/model/src/main/java/org/openremote/model/attribute/Attribute.java
+++ b/model/src/main/java/org/openremote/model/attribute/Attribute.java
@@ -72,19 +72,19 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
setName(name);
}
- protected Attribute(String name, AttributeValueType type) {
+ protected Attribute(String name, AttributeValueDescriptor type) {
this(name);
setName(name);
setType(type);
}
- protected Attribute(String name, AttributeValueType type, Value value, long timestamp) {
+ protected Attribute(String name, AttributeValueDescriptor type, Value value, long timestamp) {
this(name, type);
setValue(value);
setValueTimestamp(timestamp);
}
- protected Attribute(String name, AttributeValueType type, Value value) {
+ protected Attribute(String name, AttributeValueDescriptor type, Value value) {
this(name, type);
setValue(value);
}
@@ -118,9 +118,9 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
return getType().orElseThrow(() -> new IllegalStateException("Attribute doesn't have a type"));
}
- public void setType(AttributeValueType type) {
+ public void setType(AttributeValueDescriptor type) {
Objects.requireNonNull(type);
- getObjectValue().put(TYPE_FIELD_NAME, Values.create(type.name()));
+ getObjectValue().put(TYPE_FIELD_NAME, Values.create(type.getName()));
}
public void clearType() {
@@ -220,7 +220,7 @@ public abstract class Attribute extends AbstractValueTimestampHolder {
// Value can be empty, if it's not it must validate with the type
getValue().flatMap(value ->
- getType().flatMap(attributeType -> attributeType.isValidValue(value))
+ getType().flatMap(AttributeValueType::getValidator).flatMap(v -> v.apply(value))
).ifPresent(failures::add);
if (includeMeta) {
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
index 08b501779..b8075fde7 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
@@ -21,13 +21,15 @@ package org.openremote.model.attribute;
import org.openremote.model.value.Value;
+import java.util.Optional;
+
public interface AttributeDescriptor {
String getName();
- AttributeValueType getValueType();
+ AttributeValueDescriptor getValueDescriptor();
- MetaItem[] getDefaultMetaItems();
+ Optional<MetaItemDescriptor[]> getMetaItemDescriptors();
- Value getDefaultValue();
+ Value getInitialValue();
}
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 e547f6b3e..39e9679c0 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeType.java
@@ -19,34 +19,65 @@
*/
package org.openremote.model.attribute;
-import org.openremote.model.asset.AssetMeta;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
import java.util.Optional;
+import static org.openremote.model.asset.MetaItemType.*;
+import static org.openremote.model.attribute.AttributeValueType.*;
+
public enum AttributeType implements AttributeDescriptor {
- LOCATION("location", AttributeValueType.GEO_JSON_POINT, new MetaItem(AssetMeta.LABEL, Values.create("Location"))),
+ CONSOLE_NAME("consoleName", STRING),
+
+ CONSOLE_VERSION("consoleVersion", STRING),
+
+ CONSOLE_PLATFORM("consolePlatform", STRING),
+
+ CONSOLE_PROVIDERS("consoleProviders", OBJECT),
- CONSOLE_NAME("consoleName", AttributeValueType.STRING),
+ EMAIL("email", AttributeValueType.EMAIL, LABEL.withInitialValue(Values.create("Email"))),
- CONSOLE_VERSION("consoleVersion", AttributeValueType.STRING),
+ GEO_CITY("city", STRING,
+ LABEL.withInitialValue(Values.create("City")),
+ ABOUT.withInitialValue(Values.create("http://project-haystack.org/tag/geoCity"))),
- CONSOLE_PLATFORM("consolePlatform", AttributeValueType.STRING),
+ GEO_COUNTRY("country", STRING,
+ LABEL.withInitialValue(Values.create("Country")),
+ ABOUT.withInitialValue(Values.create("http://project-haystack.org/tag/geoCountry"))),
- CONSOLE_PROVIDERS("consoleProviders", AttributeValueType.OBJECT),
+ GEO_POSTAL_CODE("postalCode", NUMBER,
+ LABEL.withInitialValue(Values.create("Postal Code")),
+ ABOUT.withInitialValue(Values.create("http://project-haystack.org/tag/geoPostalCode"))),
- EMAIL("email", AttributeValueType.EMAIL, new MetaItem(AssetMeta.LABEL, Values.create("Email")));
+ GEO_STREET("street", STRING,
+ LABEL.withInitialValue(Values.create("Street")),
+ ABOUT.withInitialValue(Values.create("http://project-haystack.org/tag/geoStreet"))),
+
+ LOCATION("location", AttributeValueType.GEO_JSON_POINT, LABEL.withInitialValue(Values.create("Location"))),
+
+ SURFACE_AREA(
+ "surfaceArea",
+ NUMBER,
+ LABEL.withInitialValue(Values.create("Surface Area")),
+ DESCRIPTION.withInitialValue(Values.create("Floor area of building measured in m²")),
+ ABOUT.withInitialValue(Values.create("http://project-haystack.org/tag/area")));
final protected String name;
- final protected AttributeValueType attributeValueType;
- final protected MetaItem[] defaultMetaItems;
+ final protected AttributeValueDescriptor attributeValueDescriptor;
+ final protected Value initialValue;
+ final protected MetaItemDescriptor[] metaItemDescriptors;
+
+ AttributeType(String name, AttributeValueDescriptor attributeValueDescriptor, MetaItemDescriptor... metaItemDescriptors) {
+ this(name, attributeValueDescriptor, null, metaItemDescriptors);
+ }
- AttributeType(String name, AttributeValueType attributeValueType, MetaItem... defaultMetaItems) {
+ AttributeType(String name, AttributeValueDescriptor attributeValueDescriptor, Value initialValue, MetaItemDescriptor... metaItemDescriptors) {
this.name = name;
- this.attributeValueType = attributeValueType;
- this.defaultMetaItems = defaultMetaItems;
+ this.attributeValueDescriptor = attributeValueDescriptor;
+ this.metaItemDescriptors = metaItemDescriptors;
+ this.initialValue = initialValue;
}
public static Optional<AttributeDescriptor> getByValue(String name) {
@@ -66,17 +97,17 @@ public enum AttributeType implements AttributeDescriptor {
}
@Override
- public AttributeValueType getValueType() {
- return attributeValueType;
+ public AttributeValueDescriptor getValueDescriptor() {
+ return attributeValueDescriptor;
}
@Override
- public MetaItem[] getDefaultMetaItems() {
- return defaultMetaItems;
+ public Optional<MetaItemDescriptor[]> getMetaItemDescriptors() {
+ return Optional.ofNullable(metaItemDescriptors);
}
@Override
- public Value getDefaultValue() {
- return null;
+ public Value getInitialValue() {
+ return initialValue;
}
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
new file mode 100644
index 000000000..0800a36da
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2019, 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.attribute;
+
+import org.openremote.model.ValidationFailure;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueType;
+
+import java.util.Optional;
+import java.util.function.Function;
+
+public interface AttributeValueDescriptor {
+
+ String getName();
+
+ String getIcon();
+
+ ValueType getValueType();
+
+ Optional<MetaItemDescriptor[]> getMetaItemDescriptors();
+
+ Optional<Function<Value, Optional<ValidationFailure>>> getValidator();
+}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
index 9e52a1cd7..cd140c4ce 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -19,9 +19,9 @@
*/
package org.openremote.model.attribute;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
-import org.openremote.model.asset.AssetMeta;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueType;
import org.openremote.model.value.Values;
@@ -29,7 +29,7 @@ import org.openremote.model.value.Values;
import java.util.Optional;
import java.util.function.Function;
-import static org.openremote.model.asset.AssetMeta.FORMAT;
+import static org.openremote.model.asset.MetaItemType.*;
import static org.openremote.model.attribute.AttributeValueType.AttributeValueTypeFailureReason.ATTRIBUTE_TYPE_VALUE_DOES_NOT_MATCH;
/**
@@ -40,226 +40,178 @@ import static org.openremote.model.attribute.AttributeValueType.AttributeValueTy
* Additional constraints and integrity rules upon attribute values can be declared by
* adding arbitrary {@link Meta} to an {@link Attribute}.
*/
-public enum AttributeValueType {
+public enum AttributeValueType implements AttributeValueDescriptor {
- STRING("file-text-o", ValueType.STRING, value -> Optional.empty()),
+ STRING("file-text-o", ValueType.STRING),
- NUMBER("hashtag", ValueType.NUMBER, value -> Optional.empty()),
+ NUMBER("hashtag", ValueType.NUMBER),
- BOOLEAN("toggle-off", ValueType.BOOLEAN, value -> Optional.empty()),
+ BOOLEAN("toggle-off", ValueType.BOOLEAN),
- OBJECT("cubes", ValueType.OBJECT, value -> Optional.empty()),
+ OBJECT("cubes", ValueType.OBJECT),
- ARRAY("ellipsis-h", ValueType.ARRAY, value -> Optional.empty()),
+ ARRAY("ellipsis-h", ValueType.ARRAY),
// TODO Implement "Saved Filter/Searches" properly, see AssetResourceImpl
- RULES_TEMPLATE_FILTER("filter", ValueType.ARRAY, value -> Optional.empty()),
+ RULES_TEMPLATE_FILTER("filter", ValueType.ARRAY),
PERCENTAGE("percent", ValueType.NUMBER,
- value -> Values.getNumber(value)
- .filter(number -> number < 0 || number > 100)
- .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_PERCENTAGE_OUT_OF_RANGE)),
- new MetaItem(AssetMeta.RANGE_MIN, Values.create(0)),
- new MetaItem(AssetMeta.RANGE_MAX, Values.create(100)),
- new MetaItem(AssetMeta.FORMAT, Values.create("%3d %%"))
+ value -> Values.getNumber(value)
+ .filter(number -> number < 0 || number > 100)
+ .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_PERCENTAGE_OUT_OF_RANGE)),
+ RANGE_MIN.withInitialValue(Values.create(0)),
+ RANGE_MAX.withInitialValue(Values.create(100)),
+ FORMAT.withInitialValue(Values.create("%3d %%"))
),
- TIMESTAMP_MILLIS("clock-o", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%d ms"))
- ),
+ TIMESTAMP_MILLIS("clock-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%d ms"))),
- TIMESTAMP_SECONDS("clock-o", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%d s"))
- ),
+ TIMESTAMP_SECONDS("clock-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%d s"))),
- TIME_SECONDS("clock-o", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.1f s"))
- ),
+ TIME_SECONDS("clock-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f s"))),
- TIME_MINUTES("clock-o", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.1f min"))
- ),
+ TIME_MINUTES("clock-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f min"))),
- DATETIME("calendar", ValueType.STRING, value -> Optional.empty()),
+ DATETIME("calendar", ValueType.STRING),
COLOR_RGB("paint-brush", ValueType.ARRAY, value -> Values.getArray(value)
- .filter(array -> array.length() != 3)
- .map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_COLOR_FORMAT))
+ .filter(array -> array.length() != 3)
+ .map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_COLOR_FORMAT))
),
COLOR_ARGB("paint-brush", ValueType.ARRAY, value -> Values.getArray(value)
- .filter(array -> array.length() != 4)
- .map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_COLOR_FORMAT))
+ .filter(array -> array.length() != 4)
+ .map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_COLOR_FORMAT))
),
COLOR_HEX("paint-brush", ValueType.STRING, value -> Values.getString(value)
- .filter(s -> !s.matches("[a-fA-F0-9]{6}"))
- .map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_COLOR_FORMAT))
+ .filter(s -> !s.matches("[a-fA-F0-9]{6}"))
+ .map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_COLOR_FORMAT))
),
SOUND_DB("file-sound-o", ValueType.NUMBER, value -> Values.getNumber(value)
- .filter(n -> n < 0)
- .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_SOUND_OUT_OF_RANGE)),
- new MetaItem(FORMAT, Values.create("%d dB"))
+ .filter(n -> n < 0)
+ .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_SOUND_OUT_OF_RANGE)),
+ FORMAT.withInitialValue(Values.create("%d dB"))
),
TEMPERATURE_CELCIUS("thermometer", ValueType.NUMBER, value -> Values.getNumber(value)
- .filter(n -> n < -273.15)
- .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_TEMPERATURE_OUT_OF_RANGE)),
- new MetaItem(FORMAT, Values.create("%0.1f C")
- )
+ .filter(n -> n < -273.15)
+ .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_TEMPERATURE_OUT_OF_RANGE)),
+ FORMAT.withInitialValue(Values.create("%0.1f C")
+ )
),
TEMPERATURE_KELVIN("thermometer", ValueType.NUMBER, value -> Values.getNumber(value)
- .filter(n -> n < 0)
- .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_TEMPERATURE_OUT_OF_RANGE))
+ .filter(n -> n < 0)
+ .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_TEMPERATURE_OUT_OF_RANGE))
),
TEMPERATURE_FAHRENHEIT("thermometer", ValueType.NUMBER, value -> Values.getNumber(value)
- .filter(n -> n < -459.67)
- .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_TEMPERATURE_OUT_OF_RANGE))
+ .filter(n -> n < -459.67)
+ .map(n -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_TEMPERATURE_OUT_OF_RANGE))
),
- RAINFALL("tint", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.1f mm/h"))
- ),
+ RAINFALL("tint", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f mm/h"))),
- BRIGHTNESS_LUX("sun-o", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%d lx"))
- ),
+ BRIGHTNESS_LUX("sun-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%d lx"))),
- DISTANCE_M("arrows-h", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f m"))
- ),
+ DISTANCE_M("arrows-h", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f m"))),
- DISTANCE_CM("arrows-h", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f cm"))
- ),
+ DISTANCE_CM("arrows-h", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f cm"))),
- DISTANCE_MM("arrows-h", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f mm"))
- ),
+ DISTANCE_MM("arrows-h", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f mm"))),
- DISTANCE_IN("arrows-h", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f \""))
- ),
+ DISTANCE_IN("arrows-h", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f \""))),
- DISTANCE_FT("arrows-h", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f '"))
- ),
+ DISTANCE_FT("arrows-h", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f '"))),
- DISTANCE_YARD("arrows-h", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f yd"))
- ),
+ DISTANCE_YARD("arrows-h", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f yd"))),
- SPEED_MS("rocket", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.3f m/s"))
- ),
+ SPEED_MS("rocket", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.3f m/s"))),
- SPEED_KPH("rocket", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.1f km/h"))
- ),
+ SPEED_KPH("rocket", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f km/h"))),
- SPEED_MPH("rocket", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.1f mi/h"))
- ),
+ SPEED_MPH("rocket", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f mi/h"))),
- CO2_PPM("leaf", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%4d ppm"))
- ),
+ CO2_PPM("leaf", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%4d ppm"))),
HUMIDITY_PERCENTAGE("tint", ValueType.NUMBER, value -> Values.getNumber(value)
- .filter(number -> number < 0 || number > 100)
- .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_PERCENTAGE_OUT_OF_RANGE)),
- new MetaItem(AssetMeta.RANGE_MIN, Values.create(0)),
- new MetaItem(AssetMeta.RANGE_MAX, Values.create(100)),
- new MetaItem(FORMAT, Values.create("%3d %%"))
+ .filter(number -> number < 0 || number > 100)
+ .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_PERCENTAGE_OUT_OF_RANGE)),
+ RANGE_MIN.withInitialValue(Values.create(0)),
+ RANGE_MAX.withInitialValue(Values.create(100)),
+ FORMAT.withInitialValue(Values.create("%3d %%"))
),
- HUMIDITY_GPCM("tint", ValueType.NUMBER, value -> Optional.empty()),
+ HUMIDITY_GPCM("tint", ValueType.NUMBER),
- POWER_WATT("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f W"))
- ),
+ POWER_WATT("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f W"))),
- POWER_KILOWATT("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f KW"))
- ),
+ POWER_KILOWATT("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f KW"))),
- POWER_MEGAWATT("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f MW"))
- ),
+ POWER_MEGAWATT("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f MW"))),
- POWER_PERCENTAGE("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%3d %%"))
- ),
+ POWER_PERCENTAGE("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%3d %%"))),
CHARGE_PERCENTAGE("battery-full", ValueType.NUMBER, value -> Values.getNumber(value)
- .filter(number -> number < 0 || number > 100)
- .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_PERCENTAGE_OUT_OF_RANGE)),
- new MetaItem(AssetMeta.RANGE_MIN, Values.create(0)),
- new MetaItem(AssetMeta.RANGE_MAX, Values.create(100)),
- new MetaItem(FORMAT, Values.create("%3d %%"))
+ .filter(number -> number < 0 || number > 100)
+ .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_PERCENTAGE_OUT_OF_RANGE)),
+ RANGE_MIN.withInitialValue(Values.create(0)),
+ RANGE_MAX.withInitialValue(Values.create(100)),
+ FORMAT.withInitialValue(Values.create("%3d %%"))
),
- CHARGE_KWH("battery-full", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f KWh"))
- ),
+ CHARGE_KWH("battery-full", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f KWh"))),
- ENERGY_KWH("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f KWh"))
- ),
+ ENERGY_KWH("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f KWh"))),
- ENERGY_JOULE("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f J"))
- ),
+ ENERGY_JOULE("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f J"))),
- ENERGY_MEGAJOULE("plug", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f MJ"))),
+ ENERGY_MEGAJOULE("plug", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f MJ"))),
- FLOW_LPM("tachometer", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f L/m"))
- ),
+ FLOW_LPM("tachometer", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f L/m"))),
- FLOW_CMPS("tachometer", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f m³/s"))
- ),
+ FLOW_CMPS("tachometer", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f m³/s"))),
- FLOW_CCMPS("tachometer", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f cm³/s"))
- ),
+ FLOW_CCMPS("tachometer", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f cm³/s"))),
- FLOW_CFPS("tachometer", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f cfs"))
- ),
+ FLOW_CFPS("tachometer", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f cfs"))),
- FLOW_GPM("tachometer", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.5f gpm"))
- ),
+ FLOW_GPM("tachometer", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.5f gpm"))),
- DIRECTION_DECIMAL_DEGREES("compass", ValueType.NUMBER, value -> Optional.empty(),
- new MetaItem(FORMAT, Values.create("%0.1f deg"))
- ),
+ DIRECTION_DECIMAL_DEGREES("compass", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%0.1f deg"))),
- GEO_JSON_POINT("map-marker", ValueType.OBJECT, value -> Optional.empty()),
+ GEO_JSON_POINT("map-marker", ValueType.OBJECT),
EMAIL("at", ValueType.STRING, value -> Values.getString(value)
.filter(s -> !s.matches("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"))
.map(array -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID_EMAIL_FORMAT))
);
- public static final String DEFAULT_ICON = "circle-thin";
-
public enum AttributeValueTypeFailureReason implements ValidationFailure.Reason {
ATTRIBUTE_TYPE_VALUE_DOES_NOT_MATCH
}
-
+ public static final String DEFAULT_ICON = "circle-thin";
final protected String icon;
final protected ValueType valueType;
+ @JsonIgnore
final protected Function<Value, Optional<ValidationFailure>> validator;
- final protected MetaItem[] defaultMetaItems;
+ final protected MetaItemDescriptor[] metaItemDescriptors;
+
+ AttributeValueType(String icon, ValueType valueType) {
+ this(icon, valueType, (MetaItemDescriptor) null);
+ }
+
+ AttributeValueType(String icon, ValueType valueType, MetaItemDescriptor... metaItemDescriptors) {
+ this(icon, valueType, null, metaItemDescriptors);
+ }
+
+ AttributeValueType(String icon, ValueType valueType, Function<Value, Optional<ValidationFailure>> validator) {
+ this(icon, valueType, validator, (MetaItemDescriptor) null);
+ }
- AttributeValueType(String icon, ValueType valueType, Function<Value, Optional<ValidationFailure>> validator, MetaItem... defaultMetaItems) {
+ AttributeValueType(String icon, ValueType valueType, Function<Value, Optional<ValidationFailure>> validator, MetaItemDescriptor... metaItemDescriptors) {
this.icon = icon;
this.valueType = valueType;
this.validator = value -> {
@@ -268,24 +220,37 @@ public enum AttributeValueType {
return Optional.of(new ValidationFailure(ATTRIBUTE_TYPE_VALUE_DOES_NOT_MATCH, getValueType().name()));
// Custom attribute type validation
- return validator.apply(value);
+ if (validator != null) {
+ return validator.apply(value);
+ }
+
+ return Optional.empty();
};
- this.defaultMetaItems = defaultMetaItems;
+ this.metaItemDescriptors = metaItemDescriptors;
}
+ @Override
public String getIcon() {
return icon;
}
+ @Override
public ValueType getValueType() {
return valueType;
}
- public MetaItem[] getDefaultMetaItems() {
- return defaultMetaItems;
+ @Override
+ public Optional<MetaItemDescriptor[]> getMetaItemDescriptors() {
+ return Optional.ofNullable(metaItemDescriptors);
+ }
+
+ @Override
+ public String getName() {
+ return name();
}
- public Optional<ValidationFailure> isValidValue(Value value) {
- return validator.apply(value);
+ @Override
+ public Optional<Function<Value, Optional<ValidationFailure>>> getValidator() {
+ return Optional.ofNullable(validator);
}
}
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
index 95939d78c..7c3a2795b 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
@@ -42,6 +42,22 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
protected final boolean valueFixed;
protected final String patternFailureMessage;
+ public MetaItemDescriptorImpl(MetaItemDescriptor metaItemDescriptor) {
+ this(metaItemDescriptor, metaItemDescriptor.getInitialValue());
+ }
+
+ public MetaItemDescriptorImpl(MetaItemDescriptor metaItemDescriptor, Value initialValue) {
+ this(metaItemDescriptor.name(),
+ metaItemDescriptor.getUrn(),
+ metaItemDescriptor.getValueType(),
+ metaItemDescriptor.isRequired(),
+ metaItemDescriptor.getPattern(),
+ metaItemDescriptor.getPatternFailureMessage(),
+ metaItemDescriptor.getMaxPerAttribute(),
+ initialValue,
+ metaItemDescriptor.isValueFixed());
+ }
+
public MetaItemDescriptorImpl(String name,
String urn,
ValueType valueType,
@@ -51,7 +67,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
Integer maxPerAttribute,
Value initialValue,
boolean valueFixed) {
- this(name, urn, valueType, Access.ACCESS_PRIVATE,required, pattern, patternFailureMessage, maxPerAttribute, initialValue, valueFixed);
+ this(name, urn, valueType, Access.ACCESS_PRIVATE, required, pattern, patternFailureMessage, maxPerAttribute, initialValue, valueFixed);
}
@JsonCreator
@@ -136,16 +152,16 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "name='" + name + '\'' +
- ", urn='" + urn + '\'' +
- ", valueType=" + valueType +
- ", access=" + access +
- ", required=" + required +
- ", pattern='" + pattern + '\'' +
- ", maxPerAttribute=" + maxPerAttribute +
- ", initialValue=" + initialValue +
- ", valueFixed=" + valueFixed +
- ", patternFailureMessage='" + patternFailureMessage + '\'' +
- '}';
+ "name='" + name + '\'' +
+ ", urn='" + urn + '\'' +
+ ", valueType=" + valueType +
+ ", access=" + access +
+ ", required=" + required +
+ ", pattern='" + pattern + '\'' +
+ ", maxPerAttribute=" + maxPerAttribute +
+ ", initialValue=" + initialValue +
+ ", valueFixed=" + valueFixed +
+ ", patternFailureMessage='" + patternFailureMessage + '\'' +
+ '}';
}
}
diff --git a/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java b/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java
index f2e7ded0d..756eaceea 100644
--- a/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java
+++ b/model/src/main/java/org/openremote/model/console/ConsoleConfiguration.java
@@ -24,7 +24,6 @@ import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.asset.AssetMeta;
import org.openremote.model.asset.AssetType;
import org.openremote.model.attribute.AttributeType;
import org.openremote.model.attribute.Meta;
@@ -41,9 +40,9 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
-import static org.openremote.model.asset.AssetMeta.ACCESS_PUBLIC_WRITE;
-import static org.openremote.model.asset.AssetMeta.ACCESS_RESTRICTED_WRITE;
-import static org.openremote.model.asset.AssetMeta.RULE_STATE;
+import static org.openremote.model.asset.MetaItemType.ACCESS_PUBLIC_WRITE;
+import static org.openremote.model.asset.MetaItemType.ACCESS_RESTRICTED_WRITE;
+import static org.openremote.model.asset.MetaItemType.RULE_STATE;
public final class ConsoleConfiguration {
diff --git a/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java b/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
index df0d14f76..6064abba7 100644
--- a/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
+++ b/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
@@ -399,7 +399,7 @@ public class BaseAssetQuery<CHILD extends BaseAssetQuery<CHILD>> {
}
public CHILD type(AssetType assetType) {
- return type(new StringPredicate(assetType.getValue()));
+ return type(new StringPredicate(assetType.getType()));
}
public CHILD attributes(AttributePredicate... attributePredicates) {
diff --git a/model/src/main/java/org/openremote/model/query/filter/ParentPredicate.java b/model/src/main/java/org/openremote/model/query/filter/ParentPredicate.java
index a7df8bc91..e5c1bd521 100644
--- a/model/src/main/java/org/openremote/model/query/filter/ParentPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/ParentPredicate.java
@@ -50,7 +50,7 @@ public class ParentPredicate {
}
public ParentPredicate type(AssetType type) {
- return type(type.getValue());
+ return type(type.getType());
}
public ParentPredicate name(String name) {
diff --git a/model/src/main/java/org/openremote/model/rules/AssetState.java b/model/src/main/java/org/openremote/model/rules/AssetState.java
index dc799d0a4..42f0e5ab3 100644
--- a/model/src/main/java/org/openremote/model/rules/AssetState.java
+++ b/model/src/main/java/org/openremote/model/rules/AssetState.java
@@ -323,7 +323,7 @@ public class AssetState implements Comparable<AssetState> {
", parentName='" + getParentName() + '\'' +
", type='" + getType() + '\'' +
", attributeName='" + getAttributeName() + '\'' +
- ", attributeValueType=" + getAttributeValueType() +
+ ", attributeValueDescriptor=" + getAttributeValueType() +
", value=" + (getValue().isPresent() ? getValue().get().toJson() : "null") + // TODO Performance?
", timestamp=" + getTimestamp() +
", oldValue=" + (getOldValue().isPresent() ? getOldValue().get().toJson() : "null") +
diff --git a/model/src/main/java/org/openremote/model/simulator/SimulatorElement.java b/model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
index adae47476..660efcd20 100644
--- a/model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
+++ b/model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
@@ -120,7 +120,7 @@ public abstract class SimulatorElement implements ValueHolder {
public List<ValidationFailure> getValidationFailures() {
List<ValidationFailure> failures = new ArrayList<>();
if (elementValue != null) {
- expectedType.isValidValue(elementValue).ifPresent(failures::add);
+ expectedType.getValidator().flatMap(v -> v.apply(elementValue)).ifPresent(failures::add);
}
return failures;
}
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetAttributeLinkingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetAttributeLinkingTest.groovy
index fd4a7276f..fdf9342e9 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetAttributeLinkingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetAttributeLinkingTest.groovy
@@ -6,7 +6,7 @@ import org.openremote.manager.asset.AssetStorageService
import org.openremote.model.Constants
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.attribute.*
import org.openremote.model.value.Values
@@ -69,8 +69,8 @@ class AssetAttributeLinkingTest extends Specification implements ManagerContaine
attributeLinkCounter.put("attributeRef", new AttributeRef(asset2.id, "counter").toArrayValue())
attributeLinkCounter.put("converter", converterCounter)
- asset1.getAttribute("button").get().addMeta(new MetaItem(AssetMeta.ATTRIBUTE_LINK, attributeLinkOnOff))
- asset1.getAttribute("button").get().addMeta(new MetaItem(AssetMeta.ATTRIBUTE_LINK, attributeLinkCounter))
+ asset1.getAttribute("button").get().addMeta(new MetaItem(MetaItemType.ATTRIBUTE_LINK, attributeLinkOnOff))
+ asset1.getAttribute("button").get().addMeta(new MetaItem(MetaItemType.ATTRIBUTE_LINK, attributeLinkCounter))
asset1 = assetStorageService.merge(asset1)
and: "the button is pressed for a short period"
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
index 6701f04f3..1e2eef6b9 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
@@ -24,7 +24,7 @@ import static org.openremote.container.util.MapAccess.getString
import static org.openremote.manager.setup.AbstractKeycloakSetup.SETUP_ADMIN_PASSWORD
import static org.openremote.manager.setup.AbstractKeycloakSetup.SETUP_ADMIN_PASSWORD_DEFAULT
import static org.openremote.model.Constants.*
-import static org.openremote.model.asset.AssetMeta.*
+import static org.openremote.model.asset.MetaItemType.*
import static org.openremote.model.attribute.AttributeValueType.BOOLEAN
import static org.openremote.model.attribute.AttributeValueType.NUMBER
import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo
@@ -576,7 +576,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
apartment1.name == "Apartment 1"
apartment1.createdOn.getTime() < System.currentTimeMillis()
apartment1.realm == keycloakDemoSetup.tenantA.realm
- apartment1.type == AssetType.RESIDENCE.value
+ apartment1.type == AssetType.RESIDENCE.type
apartment1.parentId == managerDemoSetup.smartBuildingId
apartment1.path == null
apartment1.attributesList.size() == 0
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index b675bcd91..d8557e21f 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -7,7 +7,7 @@ import org.openremote.manager.setup.builtin.KeycloakDemoSetup
import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.asset.agent.ProtocolConfiguration
import org.openremote.model.attribute.*
@@ -176,29 +176,29 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
new AssetAttribute("light1Toggle", AttributeValueType.BOOLEAN, Values.create(true))
.setMeta(
new MetaItem(
- AssetMeta.DESCRIPTION,
+ MetaItemType.DESCRIPTION,
Values.create("The switch for the light 1 in the living room")
),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mock123").toArrayValue()
)
),
new AssetAttribute("light2Toggle", AttributeValueType.BOOLEAN, Values.create(true))
.setMeta(
new MetaItem(
- AssetMeta.DESCRIPTION,
+ MetaItemType.DESCRIPTION,
Values.create("The switch for the light 2 in the living room")
),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef("INVALID AGENT ID", managerDemoSetup.agentProtocolConfigName).toArrayValue()
)
),
new AssetAttribute("plainAttribute", AttributeValueType.STRING, Values.create("demo"))
.setMeta(
new MetaItem(
- AssetMeta.DESCRIPTION,
+ MetaItemType.DESCRIPTION,
Values.create("A plain string attribute for storing information")
)
)
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
index dfbdbaa16..6eeb49895 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
@@ -17,8 +17,8 @@ import spock.lang.Shared
import spock.lang.Specification
import static org.openremote.model.Constants.MASTER_REALM
-import static org.openremote.model.asset.AssetMeta.ACCESS_PUBLIC_READ
-import static org.openremote.model.asset.AssetMeta.LABEL
+import static org.openremote.model.asset.MetaItemType.ACCESS_PUBLIC_READ
+import static org.openremote.model.asset.MetaItemType.LABEL
import static org.openremote.model.asset.AssetType.THING
import static org.openremote.model.attribute.AttributeValueType.NUMBER
import static org.openremote.model.query.BaseAssetQuery.Include
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index c38835713..ee78b634d 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -79,7 +79,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.size() == 1
assets[0].id == managerDemoSetup.agentId
assets[0].name == "Demo Agent"
- assets[0].type == AssetType.AGENT.getValue()
+ assets[0].type == AssetType.AGENT.getType()
assets[0].parentId == null
assets[0].parentName == null
assets[0].parentType == null
@@ -160,7 +160,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets[1].id == managerDemoSetup.apartment1Id
assets[1].createdOn == null
assets[1].name == "Apartment 1"
- assets[1].type == AssetType.RESIDENCE.getValue()
+ assets[1].type == AssetType.RESIDENCE.getType()
assets[1].parentId == null
assets[1].parentName == null
assets[1].parentType == null
@@ -174,7 +174,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets[1].getAttribute("lastExecutedScene").isPresent()
assets[1].getAttribute("presenceDetected").isPresent()
assets[1].getAttribute("alarmEnabled").get().meta.size() == 1
- assets[1].getAttribute("alarmEnabled").get().getMetaItem(AssetMeta.LABEL).isPresent()
+ assets[1].getAttribute("alarmEnabled").get().getMetaItem(MetaItemType.LABEL).isPresent()
assets[1].getAttribute("alarmEnabled").get().getLabelOrName().get() == "Alarm enabled"
assets[2].id == managerDemoSetup.apartment1ServiceAgentId
assets[3].id == managerDemoSetup.apartment1LivingroomId
@@ -309,7 +309,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.get(0).wellKnownType == AssetType.RESIDENCE
assets.get(0).parentId == managerDemoSetup.smartBuildingId
assets.get(0).parentName == "Smart Building"
- assets.get(0).parentType == AssetType.BUILDING.value
+ assets.get(0).parentType == AssetType.BUILDING.type
assets.get(0).realm == keycloakDemoSetup.tenantA.realm
assets.get(0).path == null
assets.get(0).attributesList.size() == 0
@@ -462,7 +462,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
- .attributeMeta(new AttributeMetaPredicate(AssetMeta.STORE_DATA_POINTS, new BooleanPredicate(true)))
+ .attributeMeta(new AttributeMetaPredicate(MetaItemType.STORE_DATA_POINTS, new BooleanPredicate(true)))
)
then: "result should match"
@@ -483,7 +483,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
@@ -498,7 +498,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
@@ -513,7 +513,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
@@ -527,7 +527,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
@@ -542,7 +542,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery().attributeMeta(
new AttributeRefPredicate(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
@@ -581,7 +581,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.wellKnownType == AssetType.ROOM
asset.parentId != null
asset.parentName == "Apartment 1"
- asset.parentType == AssetType.RESIDENCE.getValue()
+ asset.parentType == AssetType.RESIDENCE.getType()
asset.realm == keycloakDemoSetup.tenantA.realm
asset.path != null
asset.getAttributesList().size() == 3
@@ -607,7 +607,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.wellKnownType == AssetType.ROOM
asset.parentId != null
asset.parentName == "Apartment 1"
- asset.parentType == AssetType.RESIDENCE.getValue()
+ asset.parentType == AssetType.RESIDENCE.getType()
asset.realm == keycloakDemoSetup.tenantA.realm
asset.path != null
asset.getAttributesList().size() == 1
diff --git a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
index 224c9bb53..725d84962 100644
--- a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
@@ -41,7 +41,7 @@ import java.util.stream.IntStream
import static org.openremote.manager.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_CUSTOMER_A
import static org.openremote.manager.setup.builtin.ManagerDemoSetup.SMART_BUILDING_LOCATION
import static org.openremote.model.Constants.KEYCLOAK_CLIENT_ID
-import static org.openremote.model.asset.AssetMeta.RULE_STATE
+import static org.openremote.model.asset.MetaItemType.RULE_STATE
import static org.openremote.model.asset.AssetResource.Util.WRITE_ATTRIBUTE_HTTP_METHOD
import static org.openremote.model.asset.AssetResource.Util.getWriteAttributeUrl
import static org.openremote.model.attribute.AttributeType.LOCATION
diff --git a/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy b/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy
index 871c34031..6b9ddd990 100644
--- a/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy
@@ -24,7 +24,7 @@ import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.setup.SetupService
import org.openremote.manager.setup.builtin.ManagerDemoSetup
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.LocationEvent
import org.openremote.model.asset.agent.AgentStatusEvent
import org.openremote.model.asset.agent.ConnectionStatus
@@ -93,7 +93,7 @@ class ClientEventTest extends Specification implements ManagerContainerTrait, Gw
and: "an existing protocol configuration is disabled"
def agent = assetStorageService.find(managerDemoSetup.agentId, true)
agent.getAttribute(managerDemoSetup.agentProtocolConfigName).get().addMeta(
- new MetaItem(AssetMeta.DISABLED)
+ new MetaItem(MetaItemType.DISABLED)
)
agent = assetStorageService.merge(agent)
@@ -120,7 +120,7 @@ class ClientEventTest extends Specification implements ManagerContainerTrait, Gw
and: "the existing protocol configuration is re-enabled"
agent.getAttribute(managerDemoSetup.agentProtocolConfigName).get().getMeta().removeIf(
- isMetaNameEqualTo(AssetMeta.DISABLED)
+ isMetaNameEqualTo(MetaItemType.DISABLED)
)
agent = assetStorageService.merge(agent)
diff --git a/test/src/test/groovy/org/openremote/test/model/SerialisationTest.groovy b/test/src/test/groovy/org/openremote/test/model/SerialisationTest.groovy
index 083eace16..18447b6ed 100644
--- a/test/src/test/groovy/org/openremote/test/model/SerialisationTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/model/SerialisationTest.groovy
@@ -24,7 +24,7 @@ import org.openremote.container.Container
import org.openremote.model.ValidationFailure
import org.openremote.model.ValueHolder
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.agent.ProtocolConfiguration
import org.openremote.model.attribute.AttributeValidationResult
import org.openremote.model.attribute.MetaItem
@@ -38,8 +38,8 @@ class SerialisationTest extends Specification {
AssetAttribute attribute = new AssetAttribute("testAttribute")
ProtocolConfiguration.initProtocolConfiguration(attribute, SimulatorProtocol.PROTOCOL_NAME)
attribute.addMeta(
- new MetaItem(AssetMeta.READ_ONLY, Values.create(true)),
- new MetaItem(AssetMeta.LABEL, Values.create("Test Attribute"))
+ new MetaItem(MetaItemType.READ_ONLY, Values.create(true)),
+ new MetaItem(MetaItemType.LABEL, Values.create("Test Attribute"))
)
String str = Container.JSON.writeValueAsString(attribute)
@@ -50,15 +50,15 @@ class SerialisationTest extends Specification {
attribute.getName().get().equals("testAttribute")
attribute.getValueAsString().isPresent()
attribute.getValueAsString().get().equals(SimulatorProtocol.PROTOCOL_NAME)
- attribute.getMetaItem(AssetMeta.PROTOCOL_CONFIGURATION).isPresent()
- attribute.getMetaItem(AssetMeta.PROTOCOL_CONFIGURATION).get().getValueAsBoolean().isPresent()
- attribute.getMetaItem(AssetMeta.PROTOCOL_CONFIGURATION).get().getValueAsBoolean().get()
- attribute.getMetaItem(AssetMeta.READ_ONLY).isPresent()
- attribute.getMetaItem(AssetMeta.READ_ONLY).get().getValueAsBoolean().isPresent()
- attribute.getMetaItem(AssetMeta.READ_ONLY).get().getValueAsBoolean().get()
- attribute.getMetaItem(AssetMeta.LABEL).isPresent()
- attribute.getMetaItem(AssetMeta.LABEL).get().getValueAsString().isPresent()
- attribute.getMetaItem(AssetMeta.LABEL).get().getValueAsString().get().equals("Test Attribute")
+ attribute.getMetaItem(MetaItemType.PROTOCOL_CONFIGURATION).isPresent()
+ attribute.getMetaItem(MetaItemType.PROTOCOL_CONFIGURATION).get().getValueAsBoolean().isPresent()
+ attribute.getMetaItem(MetaItemType.PROTOCOL_CONFIGURATION).get().getValueAsBoolean().get()
+ attribute.getMetaItem(MetaItemType.READ_ONLY).isPresent()
+ attribute.getMetaItem(MetaItemType.READ_ONLY).get().getValueAsBoolean().isPresent()
+ attribute.getMetaItem(MetaItemType.READ_ONLY).get().getValueAsBoolean().get()
+ attribute.getMetaItem(MetaItemType.LABEL).isPresent()
+ attribute.getMetaItem(MetaItemType.LABEL).get().getValueAsString().isPresent()
+ attribute.getMetaItem(MetaItemType.LABEL).get().getValueAsString().get().equals("Test Attribute")
}
def "Serialize/Deserialize AttributeValidationResult"() {
diff --git a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
index ce1410cc1..5771da440 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
@@ -28,7 +28,7 @@ import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.asset.agent.ConnectionStatus
import org.openremote.model.asset.agent.ProtocolConfiguration
@@ -191,7 +191,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("mockConfig4"), mockProtocolName)
.addMeta(
new MetaItem("MOCK_REQUIRED_META", Values.create(true)),
- new MetaItem(AssetMeta.DISABLED, Values.create(true))
+ new MetaItem(MetaItemType.DISABLED, Values.create(true))
)
)
mockAgent.setRealm(MASTER_REALM)
@@ -221,7 +221,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
)
),
@@ -229,14 +229,14 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
)
),
new AssetAttribute("invalidToggle1", AttributeValueType.BOOLEAN)
.setMeta(
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
)
),
@@ -244,7 +244,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig2").toArrayValue()
)
),
@@ -252,7 +252,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig2").toArrayValue()
)
),
@@ -260,7 +260,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig3").toArrayValue()
)
),
@@ -268,7 +268,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig3").toArrayValue()
)
),
@@ -276,7 +276,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig4").toArrayValue()
)
),
@@ -284,30 +284,30 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig4").toArrayValue()
)
),
new AssetAttribute("invalidToggle5", AttributeValueType.BOOLEAN, Values.create(false))
.setMeta(
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "INVALID CONFIG").toArrayValue()
)
),
new AssetAttribute("plainAttribute", AttributeValueType.STRING, Values.create("demo"))
.setMeta(
new MetaItem(
- AssetMeta.DESCRIPTION,
+ MetaItemType.DESCRIPTION,
Values.create("A plain string attribute for storing information")
),
- new MetaItem(AssetMeta.READ_ONLY, Values.create(true))
+ new MetaItem(MetaItemType.READ_ONLY, Values.create(true))
),
new AssetAttribute("filterRegex", AttributeValueType.NUMBER)
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
),
new MetaItem(
@@ -319,7 +319,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
),
new MetaItem(
@@ -331,7 +331,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
.setMeta(
new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(mockAgent.getId(), "mockConfig1").toArrayValue()
),
new MetaItem(
diff --git a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
index 9955aed49..7143e6e0b 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
@@ -23,8 +23,8 @@ import org.apache.commons.lang3.SystemUtils
import org.openremote.model.asset.Asset
import tuwien.auto.calimero.server.knxnetip.DefaultServiceContainer
-import static org.openremote.model.asset.AssetMeta.DESCRIPTION
-import static org.openremote.model.asset.AssetMeta.LABEL
+import static org.openremote.model.asset.MetaItemType.DESCRIPTION
+import static org.openremote.model.asset.MetaItemType.LABEL
import org.openremote.agent.protocol.knx.KNXProtocol
import org.openremote.model.asset.agent.ConnectionStatus
@@ -34,7 +34,7 @@ import org.openremote.manager.asset.AssetStorageService
import org.openremote.model.Constants
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.asset.agent.ProtocolConfiguration
import org.openremote.model.attribute.*
@@ -129,7 +129,7 @@ class KNXProtocolTest extends Specification implements ManagerContainerTrait {
new MetaItem(KNXProtocol.META_KNX_ACTION_GA, Values.create("1/0/17")),
new MetaItem(KNXProtocol.META_KNX_STATUS_GA, Values.create("0/4/14")),
new MetaItem(KNXProtocol.META_KNX_DPT, Values.create("1.001")),
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(knxAgent.getId(), "knxConfig").toArrayValue())
)
)
knxThing = assetStorageService.merge(knxThing)
diff --git a/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy
index 0d744fbde..2f023af1a 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy
@@ -29,7 +29,7 @@ import org.openremote.manager.asset.AssetStorageService
import org.openremote.model.Constants
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.asset.agent.ConnectionStatus
import org.openremote.model.asset.agent.ProtocolConfiguration
@@ -229,14 +229,14 @@ class ControllerProtocolTest extends Specification implements ManagerContainerTr
// attribute that sends requests to the server using PUT with dynamic body and custom header to override parent
new AssetAttribute("sensor", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, CONTROLLERPROTOCOL_ATTRIBUTE_NAME).toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, CONTROLLERPROTOCOL_ATTRIBUTE_NAME).toArrayValue()),
new MetaItem(ControllerProtocol.META_ATTRIBUTE_DEVICE_NAME, Values.create("MyDevice")),
new MetaItem(ControllerProtocol.META_ATTRIBUTE_SENSOR_NAME, Values.create("my_sensor1a")),
- new MetaItem(AssetMeta.READ_ONLY, Values.create(true))
+ new MetaItem(MetaItemType.READ_ONLY, Values.create(true))
),
new AssetAttribute("command", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, CONTROLLERPROTOCOL_ATTRIBUTE_NAME).toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, CONTROLLERPROTOCOL_ATTRIBUTE_NAME).toArrayValue()),
new MetaItem(ControllerProtocol.META_ATTRIBUTE_DEVICE_NAME, Values.create("MyDevice")),
new MetaItem(ControllerProtocol.META_ATTRIBUTE_COMMAND_NAME, Values.create("my_command"))
)
@@ -313,7 +313,7 @@ class ControllerProtocolTest extends Specification implements ManagerContainerTr
// attribute that sends requests to the server using PUT with dynamic body and custom header to override parent
new AssetAttribute("command", AttributeValueType.STRING, Values.create("command1"))
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, CONTROLLERPROTOCOL_ATTRIBUTE_NAME3).toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, CONTROLLERPROTOCOL_ATTRIBUTE_NAME3).toArrayValue()),
new MetaItem(ControllerProtocol.META_ATTRIBUTE_DEVICE_NAME, Values.create("DeviceName2")),
new MetaItem(ControllerProtocol.META_ATTRIBUTE_COMMANDS_MAP, Values.<ObjectValue>parse(/{"command1": "my_command", "command2": "wrong"}/).get())
)
diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
index e1b836016..18a6aada5 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
@@ -31,7 +31,7 @@ import org.openremote.manager.asset.AssetStorageService
import org.openremote.model.Constants
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.asset.agent.ConnectionStatus
import org.openremote.model.attribute.AttributeEvent
@@ -464,7 +464,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
// attribute that sends requests to the server using PUT with dynamic body and custom header to override parent
new AssetAttribute("putRequestWithHeaders", AttributeValueType.OBJECT)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("put_request_with_headers")),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_METHOD, Values.create(HttpMethod.PUT)),
new MetaItem(
@@ -483,13 +483,13 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
// attribute that sends requests to the server using GET with dynamic path
new AssetAttribute("getRequestWithDynamicPath", AttributeValueType.OBJECT)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create('value/{$value}/set'))
),
// attribute that polls the server using GET and uses regex filter on response
new AssetAttribute("getPollSlow", AttributeValueType.NUMBER)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_poll_slow")),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_POLLING_SECONDS, Values.create(50)), // This is ms in testing
new MetaItem(
@@ -500,7 +500,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
// attribute that polls the server using GET and uses regex filter on response
new AssetAttribute("getPollFast", AttributeValueType.NUMBER)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_poll_fast")),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_POLLING_SECONDS, Values.create(40)), // This is ms in testing
new MetaItem(
@@ -627,33 +627,33 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
asset2.addAttributes(
new AssetAttribute("getSuccess", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig2").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig2").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_success_200"))
),
new AssetAttribute("getFailure", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig2").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig2").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_failure_401"))
),
new AssetAttribute("pollFailure", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig3").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig3").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_failure_401")),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_POLLING_SECONDS, Values.create(50)), // This is ms in testing
),
new AssetAttribute("getSuccess2", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig4").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig4").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_success_200"))
),
new AssetAttribute("getFailure2", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig4").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig4").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("get_failure_401"))
),
new AssetAttribute("getRedirect", AttributeValueType.STRING)
.addMeta(
- new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig4").toArrayValue()),
+ new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig4").toArrayValue()),
new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create("redirect"))
),
)
diff --git a/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy
index a47a7133d..d1ae993a0 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy
@@ -11,7 +11,7 @@ import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.asset.agent.AgentLink
import org.openremote.model.asset.agent.AgentResource
@@ -121,7 +121,7 @@ class VelbusProtocolTest extends Specification implements ManagerContainerTrait
Values.create("CH1")
),
new MetaItem(
- AssetMeta.AGENT_LINK,
+ MetaItemType.AGENT_LINK,
new AttributeRef(agent.id, "protocolConfig").toArrayValue()
)
)
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index 92276c6c8..fd0364aeb 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -10,7 +10,7 @@ import org.openremote.manager.setup.builtin.KeycloakDemoSetup
import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.asset.AssetMeta
+import org.openremote.model.asset.MetaItemType
import org.openremote.model.asset.AssetType
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.attribute.AttributeValueType
@@ -213,7 +213,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
def attributes = [
new AssetAttribute("testString", AttributeValueType.STRING, Values.create("test"))
.setMeta(
- new Meta(new MetaItem(AssetMeta.RULE_STATE, Values.create(true))
+ new Meta(new MetaItem(MetaItemType.RULE_STATE, Values.create(true))
)
)
]
@@ -244,7 +244,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attributes = [
new AssetAttribute("testString", AttributeValueType.STRING, Values.create("test"))
.setMeta(
- new MetaItem(AssetMeta.RULE_STATE, Values.create(true))
+ new MetaItem(MetaItemType.RULE_STATE, Values.create(true))
),
new AssetAttribute("testInteger", AttributeValueType.NUMBER, Values.create(0))
]
@@ -270,7 +270,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attributes = [
new AssetAttribute("testString", AttributeValueType.STRING, Values.create("test"))
.setMeta(
- new MetaItem(AssetMeta.RULE_STATE, Values.create(false))
+ new MetaItem(MetaItemType.RULE_STATE, Values.create(false))
),
new AssetAttribute("testInteger", AttributeValueType.NUMBER, Values.create(0))
]
@@ -299,11 +299,11 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attributes = [
new AssetAttribute("testString", AttributeValueType.STRING, Values.create("test"))
.setMeta(
- new MetaItem(AssetMeta.RULE_STATE, Values.create(true))
+ new MetaItem(MetaItemType.RULE_STATE, Values.create(true))
),
new AssetAttribute("testInteger", AttributeValueType.NUMBER, Values.create(0))
.setMeta(
- new MetaItem(AssetMeta.RULE_STATE, Values.create(true))
+ new MetaItem(MetaItemType.RULE_STATE, Values.create(true))
)
]
asset.setAttributes(attributes)