Skip to content
Permalink
Browse files

Did some renaming. Added AssetModelResource to expose AssetTypeDescri…

…ptor, AttributeTypeDescriptor, AttributeValueDescriptor and MetaItemDescriptor

Test is still WIP.
  • Loading branch information...
Michael Rademaker
Michael Rademaker committed Apr 8, 2019
1 parent 1f2c914 commit cc5a5daf934050c9a6a32df2873da3473da0023c
Showing with 340 additions and 72 deletions.
  1. +58 −0 manager/src/main/java/org/openremote/manager/asset/AssetModelResourceImpl.java
  2. +4 −4 manager/src/main/java/org/openremote/manager/asset/AssetModelService.java
  3. +2 −2 manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
  4. +7 −0 manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
  5. +5 −5 model/src/main/java/org/openremote/model/asset/Asset.java
  6. +14 −14 model/src/main/java/org/openremote/model/asset/AssetAttribute.java
  7. +6 −2 model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
  8. +2 −2 model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
  9. +81 −0 model/src/main/java/org/openremote/model/asset/AssetModelResource.java
  10. +8 −8 model/src/main/java/org/openremote/model/asset/AssetType.java
  11. +1 −1 model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
  12. +0 −2 model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
  13. +0 −1 model/src/main/java/org/openremote/model/attribute/Attribute.java
  14. +3 −3 model/src/main/java/org/openremote/model/attribute/AttributeType.java
  15. +3 −1 ...ain/java/org/openremote/model/attribute/{AttributeDescriptor.java → AttributeTypeDescriptor.java}
  16. +4 −0 model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
  17. +0 −9 model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
  18. +2 −2 model/src/main/java/org/openremote/model/attribute/LinkedAttributeDescriptor.java
  19. +4 −4 model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
  20. +1 −1 model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
  21. +11 −11 model/src/main/java/org/openremote/model/util/AssetModelUtil.java
  22. +124 −0 test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy
@@ -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();
}
}
@@ -23,7 +23,7 @@
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,21 +51,21 @@ public int getPriority() {
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<>();

ServiceLoader.load(AssetModelProvider.class).forEach(assetModelProvider -> {
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]));
}
@@ -465,7 +465,7 @@ public Asset create(RequestParams requestParams, Asset asset) {

// 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 Asset create(RequestParams requestParams, Asset asset) {
});

// 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)
@@ -144,6 +144,13 @@ public void init(Container container) throws Exception {
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),
@@ -26,7 +26,7 @@
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 Asset(@NotNull String name, @NotNull String type, Asset parent) {

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 Asset removeAttribute(String name) {
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 boolean hasAttribute(String name) {
return attributes != null && attributes.hasKey(name);
}

public Optional<AssetAttribute> getAttribute(AttributeDescriptor descriptor) {
public Optional<AssetAttribute> getAttribute(AttributeTypeDescriptor descriptor) {
return getAttribute(descriptor.getName());
}

@@ -58,35 +58,35 @@ public AssetAttribute(String name, AttributeValueDescriptor type) {
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))
);
}
@@ -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 @@

boolean getAccessPublicRead();

Optional<AttributeDescriptor[]> getAttributeDescriptors();
Optional<AttributeTypeDescriptor[]> getAttributeTypeDescriptors();
}
@@ -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 @@

AssetDescriptor[] getAssetDescriptors();

AttributeDescriptor[] getAttributeDescriptors();
AttributeTypeDescriptor[] getAttributeTypeDescriptors();

AttributeValueDescriptor[] getAttributeValueDescriptors();
}
@@ -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);
}
@@ -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 @@
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 boolean getAccessPublicRead() {
}

@Override
public Optional<AttributeDescriptor[]> getAttributeDescriptors() {
return Optional.ofNullable(attributeDescriptors);
public Optional<AttributeTypeDescriptor[]> getAttributeTypeDescriptors() {
return Optional.ofNullable(attributeTypeDescriptors);
}
}
@@ -37,7 +37,7 @@
}

@Override
public AttributeDescriptor[] getAttributeDescriptors() {
public AttributeTypeDescriptor[] getAttributeTypeDescriptors() {
return AttributeType.values();
}

@@ -23,8 +23,6 @@
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;
Oops, something went wrong.

0 comments on commit cc5a5da

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