Skip to content

armgit / core

Public Imported from GitHub
0

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

Did some renaming. Added AssetModelResource to expose AssetTypeDescriptor, AttributeTypeDescriptor, AttributeValueDescriptor and MetaItemDescriptor Test is still WIP.

Michael Rademakercc5a5daf9340
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetModelResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetModelResourceImpl.java
new file mode 100644
index 000000000..da6b26eae
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetModelResourceImpl.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.asset;
+
+import org.openremote.container.timer.TimerService;
+import org.openremote.manager.security.ManagerIdentityService;
+import org.openremote.manager.web.ManagerWebResource;
+import org.openremote.model.asset.AssetDescriptor;
+import org.openremote.model.asset.AssetModelResource;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
+import org.openremote.model.attribute.AttributeValueDescriptor;
+import org.openremote.model.attribute.MetaItemDescriptor;
+import org.openremote.model.http.RequestParams;
+import org.openremote.model.util.AssetModelUtil;
+
+public class AssetModelResourceImpl extends ManagerWebResource implements AssetModelResource {
+
+ public AssetModelResourceImpl(TimerService timerService, ManagerIdentityService identityService) {
+ super(timerService, identityService);
+ }
+
+ @Override
+ public AssetDescriptor[] getAssetDescriptors(RequestParams requestParams) {
+ return AssetModelUtil.getAssetDescriptors();
+ }
+
+ @Override
+ public AttributeTypeDescriptor[] getAttributeTypeDescriptors(RequestParams requestParams) {
+ return AssetModelUtil.getAttributeTypeDescriptors();
+ }
+
+ @Override
+ public AttributeValueDescriptor[] getAttributeValueDescriptors(RequestParams requestParams) {
+ return AssetModelUtil.getAttributeValueDescriptors();
+ }
+
+ @Override
+ public MetaItemDescriptor[] getMetaItemDescriptors(RequestParams requestParams) {
+ return AssetModelUtil.getMetaItemDescriptors();
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetModelService.java b/manager/src/main/java/org/openremote/manager/asset/AssetModelService.java
index 9fdd5894c..844549e51 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetModelService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetModelService.java
@@ -23,7 +23,7 @@ import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.model.asset.AssetDescriptor;
import org.openremote.model.asset.AssetModelProvider;
-import org.openremote.model.attribute.AttributeDescriptor;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.MetaItemDescriptor;
import org.openremote.model.util.AssetModelUtil;
@@ -51,7 +51,7 @@ public class AssetModelService implements ContainerService {
public void init(Container container) throws Exception {
List<AssetDescriptor> assetDescriptors = new ArrayList<>();
- List<AttributeDescriptor> attributeDescriptors = new ArrayList<>();
+ List<AttributeTypeDescriptor> attributeTypeDescriptors = new ArrayList<>();
List<AttributeValueDescriptor> attributeValueDescriptors = new ArrayList<>();
List<MetaItemDescriptor> metaItemDescriptors = new ArrayList<>();
@@ -59,13 +59,13 @@ public class AssetModelService implements ContainerService {
LOG.fine("Adding asset model descriptors of provider: " + assetModelProvider.getClass().getName());
assetDescriptors.addAll(Arrays.asList(assetModelProvider.getAssetDescriptors()));
- attributeDescriptors.addAll(Arrays.asList(assetModelProvider.getAttributeDescriptors()));
+ attributeTypeDescriptors.addAll(Arrays.asList(assetModelProvider.getAttributeTypeDescriptors()));
attributeValueDescriptors.addAll(Arrays.asList(assetModelProvider.getAttributeValueDescriptors()));
metaItemDescriptors.addAll(Arrays.asList(assetModelProvider.getMetaItemDescriptors()));
});
AssetModelUtil.setAssetDescriptors(assetDescriptors.toArray(new AssetDescriptor[0]));
- AssetModelUtil.setAttributeDescriptors(attributeDescriptors.toArray(new AttributeDescriptor[0]));
+ AssetModelUtil.setAttributeTypeDescriptors(attributeTypeDescriptors.toArray(new AttributeTypeDescriptor[0]));
AssetModelUtil.setAttributeValueDescriptors(attributeValueDescriptors.toArray(new AttributeValueDescriptor[0]));
AssetModelUtil.setMetaItemDescriptors(metaItemDescriptors.toArray(new MetaItemDescriptor[0]));
}
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 e6b37b475..33eac5785 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -465,7 +465,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// Add meta items to well known attributes if not present
newAsset.getAttributesStream().forEach(assetAttribute -> {
- Optional<AttributeDescriptor> attributeDescriptor = assetDescriptor.getAttributeDescriptors()
+ Optional<AttributeTypeDescriptor> attributeDescriptor = assetDescriptor.getAttributeTypeDescriptors()
.flatMap(attributeDescriptors ->
Arrays.stream(attributeDescriptors)
.filter(attrDescriptor -> attrDescriptor.getName().equals(assetAttribute.getNameOrThrow()))
@@ -481,7 +481,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
});
// Add attributes for this well known asset if not present
- assetDescriptor.getAttributeDescriptors().ifPresent(attributeDescriptors ->
+ assetDescriptor.getAttributeTypeDescriptors().ifPresent(attributeDescriptors ->
newAsset.addAttributes(
Arrays.stream(attributeDescriptors).filter(attributeDescriptor ->
!newAsset.hasAttribute(attributeDescriptor.getName())).map(AssetAttribute::new).toArray(AssetAttribute[]::new)
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 2b43f51ac..991e0e56e 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -144,6 +144,13 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
ClientRole.READ_ASSETS)
);
+ container.getService(ManagerWebService.class).getApiSingletons().add(
+ new AssetModelResourceImpl(
+ container.getService(TimerService.class),
+ identityService
+ )
+ );
+
container.getService(ManagerWebService.class).getApiSingletons().add(
new AssetResourceImpl(
container.getService(TimerService.class),
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 7b99ffb22..ed263d5ca 100644
--- a/model/src/main/java/org/openremote/model/asset/Asset.java
+++ b/model/src/main/java/org/openremote/model/asset/Asset.java
@@ -26,7 +26,7 @@ import org.openremote.model.AbstractValueHolder;
import org.openremote.model.IdentifiableEntity;
import org.openremote.model.ValidationFailure;
import org.openremote.model.attribute.Attribute;
-import org.openremote.model.attribute.AttributeDescriptor;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
import org.openremote.model.geo.GeoJSON;
import org.openremote.model.geo.GeoJSONFeature;
import org.openremote.model.geo.GeoJSONFeatureCollection;
@@ -300,7 +300,7 @@ public class Asset implements IdentifiableEntity {
public Asset(@NotNull String name, @NotNull AssetDescriptor type, Asset parent, String realm) {
this(name, type.getType(), type.getAccessPublicRead(), parent, realm);
- type.getAttributeDescriptors().ifPresent(attributeDescriptors ->
+ type.getAttributeTypeDescriptors().ifPresent(attributeDescriptors ->
addAttributes(Arrays.stream(attributeDescriptors).map(AssetAttribute::new).toArray(AssetAttribute[]::new)));
}
@@ -366,8 +366,8 @@ public class Asset implements IdentifiableEntity {
return this;
}
- public Asset removeAttribute(AttributeDescriptor attributeDescriptor) {
- return removeAttribute(attributeDescriptor.getName());
+ public Asset removeAttribute(AttributeTypeDescriptor attributeTypeDescriptor) {
+ return removeAttribute(attributeTypeDescriptor.getName());
}
public String getId() {
@@ -538,7 +538,7 @@ public class Asset implements IdentifiableEntity {
return attributes != null && attributes.hasKey(name);
}
- public Optional<AssetAttribute> getAttribute(AttributeDescriptor descriptor) {
+ public Optional<AssetAttribute> getAttribute(AttributeTypeDescriptor descriptor) {
return getAttribute(descriptor.getName());
}
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 cd1d2e4b8..d6e138ede 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
@@ -58,35 +58,35 @@ public class AssetAttribute extends Attribute {
super(name, type);
}
- public AssetAttribute(AttributeDescriptor attributeDescriptor) {
- this(attributeDescriptor.getName(), attributeDescriptor);
+ public AssetAttribute(AttributeTypeDescriptor attributeTypeDescriptor) {
+ this(attributeTypeDescriptor.getName(), attributeTypeDescriptor);
}
- public AssetAttribute(String name, AttributeDescriptor attributeDescriptor) {
- this(name, attributeDescriptor, attributeDescriptor.getInitialValue());
+ public AssetAttribute(String name, AttributeTypeDescriptor attributeTypeDescriptor) {
+ this(name, attributeTypeDescriptor, attributeTypeDescriptor.getInitialValue());
}
- public AssetAttribute(AttributeDescriptor attributeDescriptor, Value value) {
- this(attributeDescriptor.getName(), attributeDescriptor, value);
+ public AssetAttribute(AttributeTypeDescriptor attributeTypeDescriptor, Value value) {
+ this(attributeTypeDescriptor.getName(), attributeTypeDescriptor, value);
}
- public AssetAttribute(String name, AttributeDescriptor attributeDescriptor, Value value) {
- this(name, attributeDescriptor, value, 0L);
+ public AssetAttribute(String name, AttributeTypeDescriptor attributeTypeDescriptor, Value value) {
+ this(name, attributeTypeDescriptor, value, 0L);
}
- public AssetAttribute(AttributeDescriptor attributeDescriptor, Value value, long timestamp) {
- this(attributeDescriptor.getName(), attributeDescriptor, value, timestamp);
+ public AssetAttribute(AttributeTypeDescriptor attributeTypeDescriptor, Value value, long timestamp) {
+ this(attributeTypeDescriptor.getName(), attributeTypeDescriptor, value, timestamp);
}
- public AssetAttribute(String name, AttributeDescriptor attributeDescriptor, Value value, long timestamp) {
- super(name, attributeDescriptor.getValueDescriptor(), value);
+ public AssetAttribute(String name, AttributeTypeDescriptor attributeTypeDescriptor, Value value, long timestamp) {
+ super(name, attributeTypeDescriptor.getValueDescriptor(), value);
if (value != null) {
- if (value.getType() != attributeDescriptor.getValueDescriptor().getValueType()) {
+ if (value.getType() != attributeTypeDescriptor.getValueDescriptor().getValueType()) {
throw new IllegalArgumentException("Provided value type is not compatible with this attribute type");
}
}
setValue(value, timestamp);
- attributeDescriptor.getMetaItemDescriptors().ifPresent(metaItemDescriptors ->
+ attributeTypeDescriptor.getMetaItemDescriptors().ifPresent(metaItemDescriptors ->
addMeta(Arrays.stream(metaItemDescriptors).map(MetaItem::new).toArray(MetaItem[]::new))
);
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
index 37b4beceb..50f4d41c4 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
@@ -19,12 +19,16 @@
*/
package org.openremote.model.asset;
-import org.openremote.model.attribute.AttributeDescriptor;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
import java.util.Optional;
+@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public interface AssetDescriptor {
+ @JsonProperty
String getName();
String getType();
@@ -33,5 +37,5 @@ public interface AssetDescriptor {
boolean getAccessPublicRead();
- Optional<AttributeDescriptor[]> getAttributeDescriptors();
+ Optional<AttributeTypeDescriptor[]> getAttributeTypeDescriptors();
}
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 3bc760b0b..63fec11c1 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
@@ -19,7 +19,7 @@
*/
package org.openremote.model.asset;
-import org.openremote.model.attribute.AttributeDescriptor;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.MetaItemDescriptor;
@@ -32,7 +32,7 @@ public interface AssetModelProvider {
AssetDescriptor[] getAssetDescriptors();
- AttributeDescriptor[] getAttributeDescriptors();
+ AttributeTypeDescriptor[] getAttributeTypeDescriptors();
AttributeValueDescriptor[] getAttributeValueDescriptors();
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetModelResource.java b/model/src/main/java/org/openremote/model/asset/AssetModelResource.java
new file mode 100644
index 000000000..de9032041
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/asset/AssetModelResource.java
@@ -0,0 +1,81 @@
+/*
+ * 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.asset;
+
+
+import jsinterop.annotations.JsType;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
+import org.openremote.model.attribute.AttributeValueDescriptor;
+import org.openremote.model.attribute.MetaItemDescriptor;
+import org.openremote.model.http.RequestParams;
+import org.openremote.model.http.SuccessStatusCode;
+
+import javax.ws.rs.*;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+@Path("model")
+@JsType(isNative = true)
+public interface AssetModelResource {
+
+ /**
+ * Retrieve asset descriptors {@link AssetDescriptor} present.
+ * <p>
+ */
+ @GET
+ @Path("asset/descriptors")
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ @SuppressWarnings("unusable-by-js")
+ AssetDescriptor[] getAssetDescriptors(@BeanParam RequestParams requestParams);
+
+ /**
+ * Retrieve attribute type descriptors {@link AttributeTypeDescriptor} present.
+ * <p>
+ */
+ @GET
+ @Path("attribute/typeDescriptors")
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ @SuppressWarnings("unusable-by-js")
+ AttributeTypeDescriptor[] getAttributeTypeDescriptors(@BeanParam RequestParams requestParams);
+
+ /**
+ * Retrieve attribute type descriptors {@link AttributeValueDescriptor} present.
+ * <p>
+ */
+ @GET
+ @Path("attribute/valueDescriptors")
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ @SuppressWarnings("unusable-by-js")
+ AttributeValueDescriptor[] getAttributeValueDescriptors(@BeanParam RequestParams requestParams);
+
+ /**
+ * Retrieve meta type descriptors {@link MetaItemDescriptor} present.
+ * <p>
+ */
+ @GET
+ @Path("metaItem/descriptors")
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ @SuppressWarnings("unusable-by-js")
+ MetaItemDescriptor[] getMetaItemDescriptors(@BeanParam RequestParams requestParams);
+}
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 75c432f10..6720a692f 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetType.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetType.java
@@ -19,7 +19,7 @@
*/
package org.openremote.model.asset;
-import org.openremote.model.attribute.AttributeDescriptor;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
import java.util.*;
@@ -58,17 +58,17 @@ public enum AssetType implements AssetDescriptor {
final protected String type;
final protected String icon;
final protected boolean accessPublicRead;
- final protected AttributeDescriptor[] attributeDescriptors;
+ final protected AttributeTypeDescriptor[] attributeTypeDescriptors;
- AssetType(String type, String icon, AttributeDescriptor... attributeDescriptors) {
- this(type, icon, false, attributeDescriptors);
+ AssetType(String type, String icon, AttributeTypeDescriptor... attributeTypeDescriptors) {
+ this(type, icon, false, attributeTypeDescriptors);
}
- AssetType(String type, String icon, boolean accessPublicRead, AttributeDescriptor... attributeDescriptors) {
+ AssetType(String type, String icon, boolean accessPublicRead, AttributeTypeDescriptor... attributeTypeDescriptors) {
this.type = type;
this.icon = icon;
this.accessPublicRead = accessPublicRead;
- this.attributeDescriptors = attributeDescriptors;
+ this.attributeTypeDescriptors = attributeTypeDescriptors;
}
public static Optional<AssetType> getByValue(String value) {
@@ -103,7 +103,7 @@ public enum AssetType implements AssetDescriptor {
}
@Override
- public Optional<AttributeDescriptor[]> getAttributeDescriptors() {
- return Optional.ofNullable(attributeDescriptors);
+ public Optional<AttributeTypeDescriptor[]> getAttributeTypeDescriptors() {
+ return Optional.ofNullable(attributeTypeDescriptors);
}
}
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 4cd0107fe..13e59c16b 100644
--- a/model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
+++ b/model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
@@ -37,7 +37,7 @@ public class DefaultAssetModelProvider implements AssetModelProvider {
}
@Override
- public AttributeDescriptor[] getAttributeDescriptors() {
+ public AttributeTypeDescriptor[] getAttributeTypeDescriptors() {
return AttributeType.values();
}
diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java b/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
index c740d8541..e381256d9 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
@@ -23,8 +23,6 @@ import jsinterop.annotations.JsType;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetResource;
-import org.openremote.model.asset.agent.AgentStatusEvent;
-import org.openremote.model.asset.agent.ProtocolDescriptor;
import org.openremote.model.attribute.AttributeValidationResult;
import org.openremote.model.file.FileInfo;
import org.openremote.model.http.RequestParams;
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 22956b5e5..cd8d337bc 100644
--- a/model/src/main/java/org/openremote/model/attribute/Attribute.java
+++ b/model/src/main/java/org/openremote/model/attribute/Attribute.java
@@ -25,7 +25,6 @@ import org.openremote.model.AbstractValueTimestampHolder;
import org.openremote.model.HasUniqueResourceName;
import org.openremote.model.ValidationFailure;
import org.openremote.model.util.AssetModelUtil;
-import org.openremote.model.util.EnumUtil;
import org.openremote.model.value.*;
import java.util.*;
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 39e9679c0..b7e5db8f7 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeType.java
@@ -27,7 +27,7 @@ import java.util.Optional;
import static org.openremote.model.asset.MetaItemType.*;
import static org.openremote.model.attribute.AttributeValueType.*;
-public enum AttributeType implements AttributeDescriptor {
+public enum AttributeType implements AttributeTypeDescriptor {
CONSOLE_NAME("consoleName", STRING),
@@ -80,11 +80,11 @@ public enum AttributeType implements AttributeDescriptor {
this.initialValue = initialValue;
}
- public static Optional<AttributeDescriptor> getByValue(String name) {
+ public static Optional<AttributeTypeDescriptor> getByValue(String name) {
if (name == null)
return Optional.empty();
- for (AttributeDescriptor descriptor : values()) {
+ for (AttributeTypeDescriptor descriptor : values()) {
if (name.equals(descriptor.getName()))
return Optional.of(descriptor);
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java b/model/src/main/java/org/openremote/model/attribute/AttributeTypeDescriptor.java
similarity index 88%
rename from model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
rename to model/src/main/java/org/openremote/model/attribute/AttributeTypeDescriptor.java
index b8075fde7..87d814984 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeTypeDescriptor.java
@@ -19,11 +19,13 @@
*/
package org.openremote.model.attribute;
+import com.fasterxml.jackson.annotation.JsonFormat;
import org.openremote.model.value.Value;
import java.util.Optional;
-public interface AttributeDescriptor {
+@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+public interface AttributeTypeDescriptor {
String getName();
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
index 0800a36da..0b36c13a2 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
@@ -19,6 +19,8 @@
*/
package org.openremote.model.attribute;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
import org.openremote.model.ValidationFailure;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueType;
@@ -26,8 +28,10 @@ import org.openremote.model.value.ValueType;
import java.util.Optional;
import java.util.function.Function;
+@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public interface AttributeValueDescriptor {
+ @JsonProperty
String getName();
String getIcon();
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 f60a0c8d8..885302070 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -19,7 +19,6 @@
*/
package org.openremote.model.attribute;
-import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
@@ -200,18 +199,10 @@ public enum AttributeValueType implements AttributeValueDescriptor {
final protected Function<Value, Optional<ValidationFailure>> validator;
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, MetaItemDescriptor... metaItemDescriptors) {
this.icon = icon;
this.valueType = valueType;
diff --git a/model/src/main/java/org/openremote/model/attribute/LinkedAttributeDescriptor.java b/model/src/main/java/org/openremote/model/attribute/LinkedAttributeDescriptor.java
index 49c6c273c..880ee8782 100644
--- a/model/src/main/java/org/openremote/model/attribute/LinkedAttributeDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/LinkedAttributeDescriptor.java
@@ -31,13 +31,13 @@ public class LinkedAttributeDescriptor {
public LinkedAttributeDescriptor(
String name,
String displayName,
- AttributeValueType attributeValueDescriptor,
+ AttributeValueType attributeValueTypeDescriptor,
boolean readOnly,
boolean executable,
MetaItem[] metaItems) {
this.name = name;
this.displayName = displayName;
- this.attributeValueDescriptor = attributeValueDescriptor;
+ this.attributeValueDescriptor = attributeValueTypeDescriptor;
this.readOnly = readOnly;
this.executable = executable;
this.metaItems = metaItems;
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
index 077cab0d0..9e8c9af80 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
@@ -19,8 +19,8 @@
*/
package org.openremote.model.attribute;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
import org.openremote.model.HasUniqueResourceName;
import org.openremote.model.ValidationFailure;
import org.openremote.model.value.Value;
@@ -30,8 +30,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
-@JsonSerialize(as = MetaItemDescriptorImpl.class)
-@JsonDeserialize(as = MetaItemDescriptorImpl.class)
+@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public interface MetaItemDescriptor extends HasUniqueResourceName {
/**
@@ -108,6 +107,7 @@ public interface MetaItemDescriptor extends HasUniqueResourceName {
HTTP_URL
}
+ @JsonProperty
String name();
String getUrn();
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 bad4e73e6..835614305 100644
--- a/model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
+++ b/model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
@@ -24,8 +24,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.attribute.AttributeRef;
-import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.AttributeValueType;
+import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.simulator.element.ColorSimulatorElement;
import org.openremote.model.simulator.element.NumberSimulatorElement;
import org.openremote.model.simulator.element.SwitchSimulatorElement;
diff --git a/model/src/main/java/org/openremote/model/util/AssetModelUtil.java b/model/src/main/java/org/openremote/model/util/AssetModelUtil.java
index fe4179602..22948ac79 100644
--- a/model/src/main/java/org/openremote/model/util/AssetModelUtil.java
+++ b/model/src/main/java/org/openremote/model/util/AssetModelUtil.java
@@ -21,7 +21,7 @@ package org.openremote.model.util;
import org.openremote.model.asset.AssetDescriptor;
import org.openremote.model.asset.AssetModelProvider;
-import org.openremote.model.attribute.AttributeDescriptor;
+import org.openremote.model.attribute.AttributeTypeDescriptor;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.attribute.MetaItemDescriptor;
@@ -41,7 +41,7 @@ import static org.openremote.model.util.TextUtil.isNullOrEmpty;
public class AssetModelUtil {
protected static AssetDescriptor[] assetDescriptors = new AssetDescriptor[0];
- protected static AttributeDescriptor[] attributeDescriptors = new AttributeDescriptor[0];
+ protected static AttributeTypeDescriptor[] attributeTypeDescriptors = new AttributeTypeDescriptor[0];
protected static AttributeValueDescriptor[] attributeValueDescriptors = new AttributeValueDescriptor[0];
protected static MetaItemDescriptor[] metaItemDescriptors = new MetaItemDescriptor[0];
@@ -55,10 +55,10 @@ public class AssetModelUtil {
}
/**
- * This should be called by something in the VM at startup to populate the available {@link AttributeDescriptor}s.
+ * This should be called by something in the VM at startup to populate the available {@link AttributeTypeDescriptor}s.
*/
- public static void setAttributeDescriptors(AttributeDescriptor[] attributeDescriptors) {
- AssetModelUtil.attributeDescriptors = attributeDescriptors;
+ public static void setAttributeTypeDescriptors(AttributeTypeDescriptor[] attributeTypeDescriptors) {
+ AssetModelUtil.attributeTypeDescriptors = attributeTypeDescriptors;
}
/**
@@ -79,8 +79,8 @@ public class AssetModelUtil {
return assetDescriptors;
}
- public static AttributeDescriptor[] getAttributeDescriptors() {
- return attributeDescriptors;
+ public static AttributeTypeDescriptor[] getAttributeTypeDescriptors() {
+ return attributeTypeDescriptors;
}
public static AttributeValueDescriptor[] getAttributeValueDescriptors() {
@@ -112,13 +112,13 @@ public class AssetModelUtil {
return Optional.empty();
}
- public static Optional<AttributeDescriptor> getAttributeDescriptor(String name) {
+ public static Optional<AttributeTypeDescriptor> getAttributeDescriptor(String name) {
if (name == null)
return Optional.empty();
- for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
- if (name.equals(attributeDescriptor.getName()))
- return Optional.of(attributeDescriptor);
+ for (AttributeTypeDescriptor attributeTypeDescriptor : attributeTypeDescriptors) {
+ if (name.equals(attributeTypeDescriptor.getName()))
+ return Optional.of(attributeTypeDescriptor);
}
return Optional.empty();
}
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy
new file mode 100644
index 000000000..20985a0b0
--- /dev/null
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.test.assets
+
+import org.openremote.container.Container
+import org.openremote.container.persistence.PersistenceService
+import org.openremote.manager.asset.AssetStorageService
+import org.openremote.manager.setup.SetupService
+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.AssetModelResource
+import org.openremote.model.asset.AssetResource
+import org.openremote.model.attribute.MetaItem
+import org.openremote.model.query.AssetQuery
+import org.openremote.model.query.BaseAssetQuery
+import org.openremote.model.value.ValueType
+import org.openremote.model.value.Values
+import org.openremote.test.ManagerContainerTrait
+import spock.lang.Shared
+import spock.lang.Specification
+
+import static org.openremote.model.Constants.MASTER_REALM
+import static org.openremote.model.asset.AssetType.AGENT
+import static org.openremote.model.asset.AssetType.BUILDING
+import static org.openremote.model.asset.AssetType.CONSOLE
+import static org.openremote.model.asset.AssetType.CUSTOM
+import static org.openremote.model.asset.AssetType.FLOOR
+import static org.openremote.model.asset.AssetType.RESIDENCE
+import static org.openremote.model.asset.AssetType.ROOM
+import static org.openremote.model.asset.AssetType.THING
+import static org.openremote.model.asset.MetaItemType.ACCESS_PUBLIC_READ
+import static org.openremote.model.asset.MetaItemType.LABEL
+import static org.openremote.model.attribute.AttributeValueType.NUMBER
+
+class AssetModelResourceTest extends Specification implements ManagerContainerTrait {
+
+ @Shared
+ static Container container
+ @Shared
+ static AssetModelResource assetModelResource
+
+ def setupSpec() {
+ given: "the server container is started"
+ def serverPort = findEphemeralPort()
+ container = startContainer(defaultConfig(serverPort), defaultServices())
+ assetModelResource = getClientApiTarget(serverUri(serverPort), MASTER_REALM).proxy(AssetModelResource.class)
+ }
+
+ def cleanupSpec() {
+ given: "the server should be stopped"
+ stopContainer(container)
+ }
+
+ def "Request types"() {
+
+ when: "a request for Asset types is made"
+
+ def assetDescriptors = assetModelResource.getAssetDescriptors(null)
+
+ then: "the eight default types should be present"
+ assetDescriptors.size() == 8
+ assetDescriptors[0].name == CUSTOM.name
+ assetDescriptors[1].name == BUILDING.name
+ assetDescriptors[1].attributeTypeDescriptors.get().length == 4
+ assetDescriptors[1].attributeTypeDescriptors.get()[0].valueDescriptor.name == ValueType.STRING
+ assetDescriptors[2].name == FLOOR.name
+ assetDescriptors[3].name == RESIDENCE.name
+ assetDescriptors[4].name == ROOM.name
+ assetDescriptors[5].name == AGENT.name
+ assetDescriptors[6].name == CONSOLE.name
+ assetDescriptors[7].name == THING.name
+
+ when: "a request for Attribute types is made"
+
+ def attributeTypeDescriptors = assetModelResource.getAttributeTypeDescriptors(null)
+
+ then: "the eleven default types should be present"
+ attributeTypeDescriptors.size() == 11
+ attributeTypeDescriptors[0].name == "consoleName"
+ attributeTypeDescriptors[1].name == "consoleVersion"
+ attributeTypeDescriptors[2].name == "consolePlatform"
+ attributeTypeDescriptors[3].name == "consoleProviders"
+ attributeTypeDescriptors[4].name == "email"
+ attributeTypeDescriptors[5].name == "city"
+ attributeTypeDescriptors[6].name == "country"
+ attributeTypeDescriptors[7].name == "postalCode"
+ attributeTypeDescriptors[8].name == "street"
+ attributeTypeDescriptors[9].name == "location"
+ attributeTypeDescriptors[10].name == "surfaceArea"
+
+ when: "a request for Attribute value types is made"
+
+ def attributeValueTypeDescriptors = assetModelResource.getAttributeValueDescriptors(null)
+
+ then: "the 50 default value types should be present"
+ attributeValueTypeDescriptors.size() == 50
+
+ when: "a request for Attribute value types is made"
+
+ def metaItemDescriptors = assetModelResource.getMetaItemDescriptors(null)
+
+ then: "the 26 default MetaItem types should be present"
+ metaItemDescriptors.size() == 26
+ }
+}