Skip to content
Permalink
Browse files

Renamed AssetModel to AssetModelUtil and moved into model module and …

…descriptors are injected at start up by the AssetModelService
  • Loading branch information...
richturner committed Apr 8, 2019
1 parent d1754bd commit 9486aa8f02c4f3fde902c7d0e4b0c59f91dc0f02
Showing with 299 additions and 179 deletions.
  1. +1 −1 agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
  2. +1 −1 agent/src/main/java/org/openremote/agent/protocol/controller/ControllerProtocol.java
  3. +1 −1 agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
  4. +1 −1 agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java
  5. +4 −3 client/src/main/java/org/openremote/app/client/assets/attributes/AttributeViewImpl.java
  6. +2 −1 client/src/main/java/org/openremote/app/client/map/MapActivity.java
  7. +0 −147 manager/src/main/java/org/openremote/manager/asset/AssetModel.java
  8. +80 −0 manager/src/main/java/org/openremote/manager/asset/AssetModelService.java
  9. +2 −1 manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
  10. +6 −6 manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
  11. +12 −1 manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
  12. +1 −0 manager/src/main/resources/META-INF/services/org.openremote.container.ContainerService
  13. +1 −1 model/src/main/java/org/openremote/model/asset/AssetAttribute.java
  14. +8 −4 model/src/main/java/org/openremote/model/attribute/Attribute.java
  15. +1 −0 model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
  16. +5 −5 model/src/main/java/org/openremote/model/attribute/LinkedAttributeDescriptor.java
  17. +3 −3 model/src/main/java/org/openremote/model/rules/AssetState.java
  18. +3 −2 model/src/main/java/org/openremote/model/simulator/SimulatorElement.java
  19. +167 −0 model/src/main/java/org/openremote/model/util/AssetModelUtil.java
  20. +0 −1 model/src/main/java/org/openremote/model/util/EnumUtil.java
@@ -382,7 +382,7 @@ final protected void updateLinkedAttribute(final AttributeState finalState, long
}

// Do basic value conversion
Optional<ValueType> attributeValueType = attribute.getType().map(AttributeValueType::getValueType);
Optional<ValueType> attributeValueType = attribute.getType().map(AttributeValueDescriptor::getValueType);

if (value != null && attributeValueType.isPresent()) {
if (attributeValueType.get() != value.getType()) {
@@ -517,7 +517,7 @@ private void onPollingResponse(PollingKey pollingKey, List<String> sensorNameLis
*/
private void updateAttributeValue(AttributeRef attributeRef, String value) {
LOG.fine("### Updating attribute " + attributeRef + " with value " + value);
AttributeValueType attributeType = this.linkedAttributes.get(attributeRef).getTypeOrThrow();
AttributeValueDescriptor attributeType = this.linkedAttributes.get(attributeRef).getTypeOrThrow();

ValueType valueType = attributeType.getValueType();
try {
@@ -243,7 +243,7 @@ protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocol
// Verify the type of the attribute matches the action value
if (attribute
.getType()
.map(AttributeValueType::getValueType)
.map(AttributeValueDescriptor::getValueType)
.orElse(null) != actionValue.getType()) {
// Use a value of null so it is clear that the attribute isn't linked correctly
actionValue = null;
@@ -317,7 +317,7 @@ protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute

getLinkedAttributeDescriptors(deviceType.get(), baseAddress)
.forEach(descriptor -> {
AssetAttribute attribute = new AssetAttribute(descriptor.getName(), descriptor.getAttributeValueType())
AssetAttribute attribute = new AssetAttribute(descriptor.getName(), descriptor.getAttributeValueDescriptor())
.setMeta(
agentLink,
new MetaItem(MetaItemType.LABEL, Values.create(descriptor.getDisplayName()))
@@ -27,6 +27,7 @@
import org.openremote.app.client.Environment;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.AttributeValueType;
import org.openremote.model.attribute.AttributeValidationResult;
import org.openremote.model.interop.Consumer;
@@ -195,7 +196,7 @@ protected void notifyAttributeModified(Value newValue) {

protected IsWidget createAttributeValueEditor() {
return valueEditorSupplier.createValueEditor(attribute,
attribute.getType().map(AttributeValueType::getValueType).orElse(null),
attribute.getType().map(AttributeValueDescriptor::getValueType).orElse(null),
style,
null,
this::notifyAttributeModified);
@@ -250,7 +251,7 @@ protected void refresh() {
} else if (attribute.isProtocolConfiguration()) {
formLabel.setIcon("cogs");
} else {
formLabel.setIcon(attribute.getType().map(AttributeValueType::getIcon).orElse(AttributeValueType.DEFAULT_ICON));
formLabel.setIcon(attribute.getType().map(AttributeValueDescriptor::getIcon).orElse(AttributeValueType.DEFAULT_ICON));
}

getFormLabel().setText(getAttributeLabel());
@@ -265,7 +266,7 @@ protected void refresh() {
infoText.append(connectionStatus != null ? connectionStatus.toString() : environment.getMessages().waitingForStatus());
}
} else if (attribute.getType().isPresent()) {
infoText.append(environment.getMessages().attributeValueType(attribute.getType().get().name()));
infoText.append(environment.getMessages().attributeValueType(attribute.getTypeOrThrow().getName()));
}
getAttributeDescription()
.ifPresent(description -> {
@@ -35,6 +35,7 @@
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetResource;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.attribute.AttributeValueDescriptor;
import org.openremote.model.attribute.AttributeValueType;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
@@ -205,7 +206,7 @@ protected void showAssetInfoItems() {
List<MapInfoItem> infoItems = dashboardAttributes.stream()
.filter(attribute -> attribute.getLabel().isPresent())
.map(attribute -> new MapInfoItem(
attribute.getType().map(AttributeValueType::getIcon).orElse(AttributeValueType.DEFAULT_ICON),
attribute.getType().map(AttributeValueDescriptor::getIcon).orElse(AttributeValueType.DEFAULT_ICON),
attribute.getLabel().get(),
attribute.getFormat().orElse(null),
attribute.getValue().orElse(null)

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,80 @@
/*
* 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.manager.asset;

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.AttributeValueDescriptor;
import org.openremote.model.attribute.MetaItemDescriptor;
import org.openremote.model.util.AssetModelUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ServiceLoader;
import java.util.logging.Logger;

/**
* This service populates the descriptors in {@link org.openremote.model.util.AssetModelUtil} by looking for
* {@link AssetModelProvider}s through {@link ServiceLoader}.
*/
public class AssetModelService implements ContainerService {

private static final Logger LOG = Logger.getLogger(AssetModelService.class.getName());

@Override
public int getPriority() {
return Integer.MIN_VALUE + 10;
}

@Override
public void init(Container container) throws Exception {

List<AssetDescriptor> assetDescriptors = new ArrayList<>();
List<AttributeDescriptor> attributeDescriptors = 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()));
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.setAttributeValueDescriptors(attributeValueDescriptors.toArray(new AttributeValueDescriptor[0]));
AssetModelUtil.setMetaItemDescriptors(metaItemDescriptors.toArray(new MetaItemDescriptor[0]));
}

@Override
public void start(Container container) throws Exception {
}

@Override
public void stop(Container container) throws Exception {
}
}
@@ -42,6 +42,7 @@
import org.openremote.model.attribute.AttributeEvent.Source;
import org.openremote.model.attribute.AttributeExecuteStatus;
import org.openremote.model.security.ClientRole;
import org.openremote.model.util.AssetModelUtil;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;

@@ -349,7 +350,7 @@ public void configure() throws Exception {
}

//Check if attribute is well known and the value is valid
AssetModel.getAttributeDescriptor(oldAttribute.name).ifPresent(wellKnownAttribute -> {
AssetModelUtil.getAttributeDescriptor(oldAttribute.name).ifPresent(wellKnownAttribute -> {
// Check if the value is valid
wellKnownAttribute.getValueDescriptor()
.getValidator().flatMap(v -> v.apply(event.getValue().orElse(null)))
@@ -32,6 +32,7 @@
import org.openremote.model.query.filter.ParentPredicate;
import org.openremote.model.query.filter.TenantPredicate;
import org.openremote.model.security.Tenant;
import org.openremote.model.util.AssetModelUtil;
import org.openremote.model.util.TextUtil;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueException;
@@ -43,7 +44,6 @@
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;
@@ -285,10 +285,10 @@ public void update(RequestParams requestParams, String assetId, Asset asset) {
Meta existingMetaItems = existingAttribute.getMeta().copy();

// Remove any writable existing meta items
existingMetaItems.removeIf(AssetModel::isMetaItemRestrictedWrite);
existingMetaItems.removeIf(AssetModelUtil::isMetaItemRestrictedWrite);

// Add any writable updated meta items
updatedMetaItems.stream().filter(AssetModel::isMetaItemRestrictedWrite).forEach(existingMetaItems::add);
updatedMetaItems.stream().filter(AssetModelUtil::isMetaItemRestrictedWrite).forEach(existingMetaItems::add);

// Replace existing with updated attribute
updatedAttribute.setMeta(existingMetaItems);
@@ -298,7 +298,7 @@ public void update(RequestParams requestParams, String assetId, Asset asset) {

// An attribute added by a restricted user can only have meta items which are writable
updatedAttribute.getMetaStream().forEach(metaItem -> {
if (!AssetModel.isMetaItemRestrictedWrite(metaItem)) {
if (!AssetModelUtil.isMetaItemRestrictedWrite(metaItem)) {
LOG.fine("Attribute has " + metaItem + " not writable by restricted client: " + updatedAttributeName);
throw new WebApplicationException(
"Attribute has meta item not writable by restricted client: " + updatedAttributeName,
@@ -351,7 +351,7 @@ public void update(RequestParams requestParams, String assetId, Asset asset) {

private void checkForWellKnownAttributes(Asset asset) {
asset.getAttributesStream().forEach(assetAttribute -> {
AssetModel.getAttributeDescriptor(assetAttribute.name).ifPresent(wellKnownAttribute -> {
AssetModelUtil.getAttributeDescriptor(assetAttribute.name).ifPresent(wellKnownAttribute -> {
//Check if the type matches
if (!wellKnownAttribute.getValueDescriptor().equals(assetAttribute.getTypeOrThrow())) {
throw new IllegalStateException(
@@ -459,7 +459,7 @@ public Asset create(RequestParams requestParams, Asset asset) {
newAsset.setId(asset.getId());
}

AssetModel.getAssetDescriptor(asset.getType()).ifPresent(assetDescriptor -> {
AssetModelUtil.getAssetDescriptor(asset.getType()).ifPresent(assetDescriptor -> {

newAsset.setAccessPublicRead(assetDescriptor.getAccessPublicRead());

Oops, something went wrong.

0 comments on commit 9486aa8

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