100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Improved attribute model functions
Christian Bauerf40686ca195d
diff --git a/agent/src/main/java/org/openremote/agent/AgentService.java b/agent/src/main/java/org/openremote/agent/AgentService.javaindex 97197b179..6dfc8a3c0 100644--- a/agent/src/main/java/org/openremote/agent/AgentService.java+++ b/agent/src/main/java/org/openremote/agent/AgentService.java@@ -54,11 +54,6 @@ public class AgentService implements ContainerService {}}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {if (agentContext != null) {diff --git a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.javaindex 321087a55..8a43034b6 100644--- a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java+++ b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java@@ -30,7 +30,6 @@ import org.openremote.model.AttributeEvent;import org.openremote.model.AttributeRef;import org.openremote.model.AttributeState;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.agent.ProtocolConfiguration;import java.util.Collection;import java.util.HashMap;@@ -64,10 +63,7 @@ public abstract class AbstractProtocol implements Protocol {LOG.fine("Starting protocol: " + getProtocolName());this.messageBrokerContext = container.getService(MessageBrokerSetupService.class).getContext();this.producerTemplate = container.getService(MessageBrokerService.class).getProducerTemplate();- }- @Override- public void allStarted(Container container) throws Exception {synchronized (linkedAttributes) {messageBrokerContext.addRoutes(new RouteBuilder() {@Override@@ -98,7 +94,7 @@ public abstract class AbstractProtocol implements Protocol {}@Override- public void linkAttributes(Collection<AssetAttribute> attributes, ProtocolConfiguration protocolConfiguration) throws Exception {+ public void linkAttributes(Collection<AssetAttribute> attributes, AssetAttribute protocolConfiguration) throws Exception {synchronized (linkedAttributes) {attributes.forEach(attribute -> {if (linkedAttributes.containsKey(attribute.getReference())) {@@ -115,24 +111,24 @@ public abstract class AbstractProtocol implements Protocol {}@Override- public void unlinkAttributes(Collection<AssetAttribute> attributes, ProtocolConfiguration protocolConfiguration) throws Exception {+ public void unlinkAttributes(Collection<AssetAttribute> attributes, AssetAttribute protocolConfiguration) throws Exception {synchronized (linkedAttributes) {attributes+ .stream()+ .filter(attribute -> linkedAttributes.values().stream()- .filter(attribute -> linkedAttributes.values()- .stream()- .anyMatch(linkedAttribute ->- linkedAttribute- .getReference()- .equals(attribute.getReference()))- )- .forEach(attributeToRemove -> {- AttributeRef agentLinkedAttributeRef = attributeToRemove.getReference();-- linkedAttributes.remove(agentLinkedAttributeRef);- LOG.fine("Attribute removed on '" + getProtocolName() + "': " + attributeToRemove);- onAttributeRemoved(attributeToRemove, protocolConfiguration);- });+ .anyMatch(linkedAttribute ->+ linkedAttribute+ .getReference()+ .equals(attribute.getReference()))+ )+ .forEach(attributeToRemove -> {+ AttributeRef agentLinkedAttributeRef = attributeToRemove.getReference();++ linkedAttributes.remove(agentLinkedAttributeRef);+ LOG.fine("Attribute removed on '" + getProtocolName() + "': " + attributeToRemove);+ onAttributeRemoved(attributeToRemove, protocolConfiguration);+ });}}@@ -162,9 +158,9 @@ public abstract class AbstractProtocol implements Protocol {abstract protected void sendToActuator(AttributeEvent event);- abstract protected void onAttributeAdded(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration);+ abstract protected void onAttributeAdded(AssetAttribute attribute, AssetAttribute protocolConfiguration);- abstract protected void onAttributeUpdated(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration);+ abstract protected void onAttributeUpdated(AssetAttribute attribute, AssetAttribute protocolConfiguration);- abstract protected void onAttributeRemoved(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration);+ abstract protected void onAttributeRemoved(AssetAttribute attribute, AssetAttribute protocolConfiguration);}diff --git a/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent3/protocol/Protocol.javaindex 092b350ce..67a6cf83b 100644--- a/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java+++ b/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java@@ -23,7 +23,6 @@ import org.openremote.container.ContainerService;import org.openremote.model.AttributeEvent;import org.openremote.model.Constants;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.agent.ProtocolConfiguration;import java.util.Collection;@@ -39,7 +38,7 @@ import java.util.Collection;* <p>* The linked attributes of a protocol provide the model for the protocol to perform these operations. How* attributes and value changes map to actual device and service calls is up to the implementation. The method- * {@link #linkAttributes(Collection, ProtocolConfiguration)} is first called during startup of the protocol, after+ * {@link #linkAttributes} is first called during startup of the protocol, after* {@link #init} and before {@link #start}.* <p>* The linked protocol handles south-bound read and write of the attribute value: If the user writes@@ -67,8 +66,8 @@ public interface Protocol extends ContainerService {String getProtocolName();- void linkAttributes(Collection<AssetAttribute> attributes, ProtocolConfiguration protocolConfiguration) throws Exception;+ void linkAttributes(Collection<AssetAttribute> attributes, AssetAttribute protocolConfiguration) throws Exception;- void unlinkAttributes(Collection<AssetAttribute> attributes, ProtocolConfiguration protocolConfiguration) throws Exception;+ void unlinkAttributes(Collection<AssetAttribute> attributes, AssetAttribute protocolConfiguration) throws Exception;}diff --git a/agent/src/main/java/org/openremote/agent3/protocol/macro/MacroProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/macro/MacroProtocol.javaindex 9341fcf4d..56a3730f9 100644--- a/agent/src/main/java/org/openremote/agent3/protocol/macro/MacroProtocol.java+++ b/agent/src/main/java/org/openremote/agent3/protocol/macro/MacroProtocol.java@@ -24,7 +24,6 @@ import org.openremote.agent3.protocol.AbstractProtocol;import org.openremote.container.Container;import org.openremote.model.*;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.agent.ProtocolConfiguration;import org.openremote.model.asset.macro.MacroAction;import org.openremote.model.asset.macro.MacroAttributeCommand;import org.openremote.model.asset.macro.MacroConfiguration;@@ -39,10 +38,13 @@ import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;import java.util.logging.Level;import java.util.logging.Logger;+import java.util.stream.Collectors;++import static org.openremote.model.asset.macro.MacroConfiguration.getMacroActions;/*** This protocol is responsible for executing macros.- *+ * <p>* It expects a {@link MacroAttributeCommand} or the super type{@link AttributeCommand}* as the attribute event value on the sendToActuator. The protocol will then execute* the command and store the command status in the attribute value.@@ -97,10 +99,10 @@ public class MacroProtocol extends AbstractProtocol {actions.forEach(action -> {// Look for override value in executionAttributeState overrideState = execution.getActionOverrides() == null ? null : execution.getActionOverrides()- .stream()- .filter(actionOverride -> actionOverride.getAttributeRef().equals(action.getAttributeState().getAttributeRef()))- .findFirst()- .orElse(null);+ .stream()+ .filter(actionOverride -> actionOverride.getAttributeRef().equals(action.getAttributeState().getAttributeRef()))+ .findFirst()+ .orElse(null);AttributeState actionState = overrideState != null ? overrideState : action.getAttributeState();if (action.getDelay() > 0) {@@ -157,7 +159,7 @@ public class MacroProtocol extends AbstractProtocol {@Overridepublic String getProtocolName() {- return MacroConfiguration.PROTOCOL_NAME;+ return MacroConfiguration.MACRO_PROTOCOL_NAME;}@Override@@ -206,13 +208,12 @@ public class MacroProtocol extends AbstractProtocol {}@Override- protected void onAttributeAdded(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeAdded(AssetAttribute attribute, AssetAttribute macroConfiguration) {// Protocol configuration is actually a Macro- MacroConfiguration macroConfiguration = new MacroConfiguration(protocolConfiguration.getAttribute());// Store the macro actions for later execution requestsAttributeRef reference = attribute.getReference();- List<MacroAction> actions = macroConfiguration.getActions();+ List<MacroAction> actions = getMacroActions().apply(macroConfiguration).collect(Collectors.toList());synchronized (actionMap) {actionMap.put(reference, actions);@@ -220,12 +221,12 @@ public class MacroProtocol extends AbstractProtocol {}@Override- protected void onAttributeUpdated(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeUpdated(AssetAttribute attribute, AssetAttribute protocolConfiguration) {onAttributeAdded(attribute, protocolConfiguration);}@Override- protected void onAttributeRemoved(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeRemoved(AssetAttribute attribute, AssetAttribute protocolConfiguration) {// Store the macro actions for later execution requestsAttributeRef reference = attribute.getReference();diff --git a/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.javaindex 0f9620ee0..03eba1d53 100644--- a/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java+++ b/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java@@ -27,7 +27,6 @@ import org.openremote.model.AttributeRef;import org.openremote.model.AttributeState;import org.openremote.model.MetaItem;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.agent.ProtocolConfiguration;import java.util.HashMap;import java.util.Locale;@@ -114,15 +113,15 @@ public class SimulatorProtocol extends AbstractProtocol {}@Override- protected void onAttributeAdded(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeAdded(AssetAttribute attribute, AssetAttribute protocolConfiguration) {String elementType = attribute.firstMetaItemOrThrow(SIMULATOR_ELEMENT).getValueAsString();- String protocolConfigurationName = protocolConfiguration.getAttribute().getName();+ String protocolConfigurationName = protocolConfiguration.getName();Instance instance = instances.get(protocolConfigurationName);if (instance == null) {- MetaItem configModeMeta = protocolConfiguration.getAttribute().firstMetaItem(CONFIG_MODE);- MetaItem configDelayMeta = protocolConfiguration.getAttribute().firstMetaItem(CONFIG_WRITE_DELAY_MILLISECONDS);+ MetaItem configModeMeta = protocolConfiguration.firstMetaItem(CONFIG_MODE);+ MetaItem configDelayMeta = protocolConfiguration.firstMetaItem(CONFIG_WRITE_DELAY_MILLISECONDS);Mode mode = Mode.WRITE_THROUGH_IMMEDIATE;if (configModeMeta != null) {@@ -155,12 +154,12 @@ public class SimulatorProtocol extends AbstractProtocol {}@Override- protected void onAttributeUpdated(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeUpdated(AssetAttribute attribute, AssetAttribute protocolConfiguration) {onAttributeAdded(attribute, protocolConfiguration);}@Override- protected void onAttributeRemoved(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeRemoved(AssetAttribute attribute, AssetAttribute protocolConfiguration) {elements.remove(attribute.getReference());attributeInstanceMap.remove(attribute.getReference());}diff --git a/container/src/main/java/org/openremote/container/Container.java b/container/src/main/java/org/openremote/container/Container.javaindex 72a21020e..3711e7c7c 100644--- a/container/src/main/java/org/openremote/container/Container.java+++ b/container/src/main/java/org/openremote/container/Container.java@@ -36,6 +36,18 @@ import java.util.logging.Logger;import static org.openremote.container.util.MapAccess.getBoolean;+/**+ * A thread-safe registry of {@link ContainerService}s.+ * <p>+ * Create the container with {@link ContainerService}s, then let it+ * manage the life cycle of these services.+ * <p>+ * Access environment configuration through {@link #getConfig()} and the helper methods+ * in {@link org.openremote.container.util.MapAccess}. Consider using {@link #DEV_MODE}+ * to distinguish between development and production environments.+ * <p>+ * Read and write JSON with a sensible mapper configuration using {@link #JSON}.+ */public class Container {public static final Logger LOG;@@ -86,7 +98,7 @@ public class Container {}if (services != null) {- services.forEach(this::addService);+ services.forEach(svc -> this.services.put(svc.getClass(), svc));}Runtime.getRuntime().addShutdownHook(new Thread(this::stop));@@ -115,10 +127,6 @@ public class Container {LOG.fine("Starting service: " + service);service.start(Container.this);}- for (ContainerService service : getServices()) {- LOG.fine("Notifying service all started: " + service);- service.allStarted(Container.this);- }} catch (RuntimeException ex) {throw ex;} catch (Exception ex) {@@ -179,12 +187,6 @@ public class Container {containerThread.start();}- public void addService(ContainerService service) {- synchronized (service) {- services.put(service.getClass(), service);- }- }-public ContainerService[] getServices() {synchronized (services) {return services.values().toArray(new ContainerService[services.size()]);diff --git a/container/src/main/java/org/openremote/container/ContainerService.java b/container/src/main/java/org/openremote/container/ContainerService.javaindex 995ce5010..ef73e05ed 100644--- a/container/src/main/java/org/openremote/container/ContainerService.java+++ b/container/src/main/java/org/openremote/container/ContainerService.java@@ -20,19 +20,19 @@package org.openremote.container;/**- * Containers manage a list of services, the order of services in a container is important.+ * The {@link Container} is a registry of services, the order of services in a container is important.* <p>* Service startup lifecycle:* </p>* <ol>- * <li>{@link #init} in insertion order</li>- * <li>{@link #start} in insertion order</li>+ * <li>{@link #init} in registry insertion order</li>+ * <li>{@link #start} in registry insertion order</li>* </ol>* <p>* Service shutdown lifecycle:* </p>* <ol>- * <li>{@link #stop} in <b>reverse</b> order</li>+ * <li>{@link #stop} in <b>reverse</b> registry order</li>* </ol>*/public interface ContainerService {@@ -47,11 +47,6 @@ public interface ContainerService {*/void start(Container container) throws Exception;- /**- * Called once the container has finished starting all services- */- void allStarted(Container container) throws Exception;-/*** When the container is shutting down, it stops all services in the reverse order they have been added to container.*/diff --git a/container/src/main/java/org/openremote/container/message/MessageBrokerService.java b/container/src/main/java/org/openremote/container/message/MessageBrokerService.javaindex 5983d050a..f1410fbfe 100644--- a/container/src/main/java/org/openremote/container/message/MessageBrokerService.java+++ b/container/src/main/java/org/openremote/container/message/MessageBrokerService.java@@ -45,11 +45,6 @@ public class MessageBrokerService implements ContainerService {messageBrokerSetupService.getContext().start();}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {}diff --git a/container/src/main/java/org/openremote/container/message/MessageBrokerSetupService.java b/container/src/main/java/org/openremote/container/message/MessageBrokerSetupService.javaindex c74e0f1c2..55db6f22a 100644--- a/container/src/main/java/org/openremote/container/message/MessageBrokerSetupService.java+++ b/container/src/main/java/org/openremote/container/message/MessageBrokerSetupService.java@@ -97,11 +97,6 @@ public class MessageBrokerSetupService implements ContainerService {// 4. WebService#init() - configures HTTP routing paths, giving Camel routes a chance to add routes before}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {if (context != null) {diff --git a/container/src/main/java/org/openremote/container/persistence/PersistenceService.java b/container/src/main/java/org/openremote/container/persistence/PersistenceService.javaindex dc99f12c5..c50248d2b 100644--- a/container/src/main/java/org/openremote/container/persistence/PersistenceService.java+++ b/container/src/main/java/org/openremote/container/persistence/PersistenceService.java@@ -106,11 +106,6 @@ public class PersistenceService implements ContainerService {Persistence.createEntityManagerFactory(persistenceUnitName, persistenceUnitProperties);}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {LOG.info("Stopping persistence service...");diff --git a/container/src/main/java/org/openremote/container/security/IdentityService.java b/container/src/main/java/org/openremote/container/security/IdentityService.javaindex 901d5b32b..b99000b84 100644--- a/container/src/main/java/org/openremote/container/security/IdentityService.java+++ b/container/src/main/java/org/openremote/container/security/IdentityService.java@@ -198,11 +198,6 @@ public abstract class IdentityService implements ContainerService {LOG.info("Keycloak identity provider available: " + keycloakServiceUri.build());}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {if (getHttpClient() != null)diff --git a/container/src/main/java/org/openremote/container/web/WebService.java b/container/src/main/java/org/openremote/container/web/WebService.javaindex d53d5e92a..539674725 100644--- a/container/src/main/java/org/openremote/container/web/WebService.java+++ b/container/src/main/java/org/openremote/container/web/WebService.java@@ -122,11 +122,6 @@ public abstract class WebService implements ContainerService {}}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {if (undertow != null) {diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.javaindex 98735d26f..368c3c8e2 100644--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java@@ -22,7 +22,8 @@ package org.openremote.container.web.socket;import org.apache.camel.Exchange;import org.apache.camel.Processor;import org.apache.camel.impl.DefaultConsumer;-import org.openremote.model.Consumer;++import java.util.function.Consumer;public class WebsocketConsumer extends DefaultConsumer {diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.javaindex 8aae1b40b..31bb2844f 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java@@ -21,21 +21,21 @@ package org.openremote.manager.client.admin.tenant;import com.google.gwt.user.client.ui.AcceptsOneWidget;import org.openremote.manager.client.Environment;+import org.openremote.manager.client.TenantMapper;import org.openremote.manager.client.admin.AbstractAdminActivity;import org.openremote.manager.client.admin.AdminView;-import org.openremote.manager.client.TenantMapper;import org.openremote.manager.client.admin.navigation.AdminNavigation;import org.openremote.manager.client.event.ShowSuccessEvent;-import org.openremote.model.event.bus.EventBus;-import org.openremote.model.event.bus.EventRegistration;import org.openremote.manager.client.mvp.AppActivity;import org.openremote.manager.shared.security.Tenant;import org.openremote.manager.shared.security.TenantResource;import org.openremote.manager.shared.validation.ConstraintViolation;-import org.openremote.model.Consumer;+import org.openremote.model.event.bus.EventBus;+import org.openremote.model.event.bus.EventRegistration;import javax.inject.Inject;import java.util.Collection;+import java.util.function.Consumer;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.javaindex 9887376fc..fc13fdb27 100644--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java@@ -24,20 +24,21 @@ import org.openremote.manager.client.Environment;import org.openremote.manager.client.admin.*;import org.openremote.manager.client.admin.navigation.AdminNavigation;import org.openremote.manager.client.event.ShowSuccessEvent;-import org.openremote.model.event.bus.EventBus;-import org.openremote.model.event.bus.EventRegistration;import org.openremote.manager.client.mvp.AppActivity;import org.openremote.manager.shared.security.Credential;import org.openremote.manager.shared.security.Role;import org.openremote.manager.shared.security.User;import org.openremote.manager.shared.security.UserResource;import org.openremote.manager.shared.validation.ConstraintViolation;-import org.openremote.model.Consumer;-import org.openremote.model.Runnable;+import org.openremote.model.event.bus.EventBus;+import org.openremote.model.event.bus.EventRegistration;import javax.inject.Inject;-import java.util.*;-import java.util.logging.Logger;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.Collection;+import java.util.List;+import java.util.function.Consumer;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;@@ -45,8 +46,6 @@ public class AdminUserActivityextends AbstractAdminActivity<AdminUserPlace, AdminUser>implements AdminUser.Presenter {- private static final Logger LOG = Logger.getLogger(AdminUserActivity.class.getName());-final protected Environment environment;final protected UserResource userResource;final protected UserMapper userMapper;@@ -188,9 +187,7 @@ public class AdminUserActivityreadFromView();environment.getRequestService().execute(userMapper,- requestParams -> {- userResource.create(requestParams, realm, user);- },+ requestParams -> userResource.create(requestParams, realm, user),204,() -> {adminContent.setFormBusy(false);@@ -231,13 +228,9 @@ public class AdminUserActivityCredential credential = new Credential(password, false);environment.getRequestService().execute(credentialMapper,- requestParams -> {- userResource.resetPassword(requestParams, realm, userId, credential);- },+ requestParams -> userResource.resetPassword(requestParams, realm, userId, credential),204,- () -> {- adminContent.addFormMessageSuccess(environment.getMessages().passwordUpdated());- },+ () -> adminContent.addFormMessageSuccess(environment.getMessages().passwordUpdated()),ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages(), validationErrorHandler));}@@ -245,16 +238,12 @@ public class AdminUserActivityprotected void updateUser() {environment.getRequestService().execute(userMapper,- requestParams -> {- userResource.update(requestParams, realm, userId, user);- },+ requestParams -> userResource.update(requestParams, realm, userId, user),204,- () -> {- updateRoles(() -> {- adminContent.setFormBusy(false);- adminContent.addFormMessageSuccess(environment.getMessages().userUpdated(user.getUsername()));- });- },+ () -> updateRoles(() -> {+ adminContent.setFormBusy(false);+ adminContent.addFormMessageSuccess(environment.getMessages().userUpdated(user.getUsername()));+ }),ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages(), validationErrorHandler));}@@ -262,11 +251,9 @@ public class AdminUserActivityprotected void updateRoles(Runnable onComplete) {environment.getRequestService().execute(roleArrayMapper,- requestParams -> {- userResource.updateRoles(requestParams, realm, userId, roles);- },+ requestParams -> userResource.updateRoles(requestParams, realm, userId, roles),204,- onComplete::run,+ onComplete,ex -> handleRequestException(ex, environment));}@@ -281,9 +268,7 @@ public class AdminUserActivityadminContent.clearFormMessages();clearViewFieldErrors();environment.getRequestService().execute(- requestParams -> {- userResource.delete(requestParams, realm, userId);- },+ requestParams -> userResource.delete(requestParams, realm, userId),204,() -> {adminContent.setFormBusy(false);diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.java b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.javaindex 9da5abc15..f95e89902 100644--- a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.java+++ b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.java@@ -19,8 +19,6 @@*/package org.openremote.manager.client.app.dialog;-import org.openremote.model.Runnable;-public interface ConfirmationDialog {void setTitle(String title);diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.java b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.javaindex 6fef17f1b..47f9330d6 100644--- a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.java@@ -23,7 +23,6 @@ import com.google.gwt.user.client.ui.Label;import org.openremote.manager.client.i18n.ManagerMessages;import org.openremote.manager.client.style.WidgetStyle;import org.openremote.manager.client.widget.PushButton;-import org.openremote.model.Runnable;import javax.inject.Inject;diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.javaindex 710a91dd2..068a5f727 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java@@ -33,16 +33,15 @@ import org.openremote.manager.shared.asset.AssetResource;import org.openremote.manager.shared.map.MapResource;import org.openremote.manager.shared.security.Tenant;import org.openremote.manager.shared.validation.ConstraintViolation;-import org.openremote.model.Consumer;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetType;import org.openremote.model.event.bus.EventBus;import org.openremote.model.event.bus.EventRegistration;import javax.inject.Inject;-import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;+import java.util.function.Consumer;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;@@ -333,7 +332,7 @@ public class AssetEditActivityview.getAttributesEditorContainer(),assetId == null? Arrays.asList(asset.getWellKnownType().getDefaultAttributes())- : new ArrayList<>(),+ : asset.getAttributeList(),assetId == null);view.setAttributesEditor(attributesEditor);@@ -355,7 +354,7 @@ public class AssetEditActivityif (selectedCoordinates != null) {asset.setCoordinates(selectedCoordinates);}- asset.setAttributes(+ asset.setAttributeList(attributesEditor != null ? attributesEditor.getAttributes() : null);}diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.javaindex 632ea7592..36f541c7c 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java@@ -33,11 +33,9 @@ import org.openremote.manager.client.datapoint.NumberDatapointArrayMapper;import org.openremote.manager.client.interop.elemental.JsonObjectMapper;import org.openremote.manager.shared.asset.AssetResource;import org.openremote.manager.shared.datapoint.AssetDatapointResource;-import org.openremote.manager.shared.http.EntityWriter;import org.openremote.manager.shared.map.MapResource;import org.openremote.manager.shared.security.Tenant;import org.openremote.manager.shared.security.TenantResource;-import org.openremote.model.Consumer;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.datapoint.DatapointInterval;import org.openremote.model.datapoint.NumberDatapoint;@@ -46,6 +44,7 @@ import org.openremote.model.event.bus.EventRegistration;import javax.inject.Inject;import java.util.Collection;+import java.util.function.Consumer;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.javaindex fa20cf226..034f5db9d 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java@@ -27,7 +27,6 @@ import org.openremote.manager.client.datapoint.DatapointBrowser;import org.openremote.manager.client.widget.*;import org.openremote.model.AttributeEvent;import org.openremote.model.AttributeType;-import org.openremote.model.Consumer;import org.openremote.model.ReadAttributesEvent;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;@@ -37,6 +36,7 @@ import org.openremote.model.event.bus.EventRegistration;import java.util.ArrayList;import java.util.List;+import java.util.function.Consumer;import java.util.logging.Logger;public abstract class AttributesBrowser@@ -59,7 +59,7 @@ public abstract class AttributesBrowserprotected EventRegistration<AttributeEvent> eventRegistration;public AttributesBrowser(Environment environment, Container container, Asset asset) {- super(environment, container, asset.getAttributes());+ super(environment, container, asset.getAttributeList());this.asset = asset;eventRegistration = environment.getEventBus().register(diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.javaindex 3dce1f22d..9c4244b04 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java@@ -29,11 +29,17 @@ import elemental.json.JsonValue;import org.openremote.manager.client.Environment;import org.openremote.manager.client.util.JsUtil;import org.openremote.manager.client.widget.*;-import org.openremote.model.*;+import org.openremote.model.Attribute;+import org.openremote.model.AttributeType;+import org.openremote.model.Meta;+import org.openremote.model.MetaItem;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetMeta;-import org.openremote.model.util.AttributeUtil;+import java.util.List;+import java.util.function.Consumer;++import static org.openremote.model.Attribute.ATTRIBUTE_NAME_VALIDATOR;public class AttributesEditorextends AttributesView<AttributesEditor.Container, AttributesEditor.Style> {@@ -112,7 +118,7 @@ public class AttributesEditor/* ####################################################################### */protected FormGroup createNewAttributeEditor() {- AssetAttribute attribute = new AssetAttribute("NAME", AttributeType.STRING);+ AssetAttribute attribute = AssetAttribute.createEmpty();FormGroup formGroup = createAttributeNameEditor(attribute);@@ -153,7 +159,7 @@ public class AttributesEditorFormInputText nameInput = createFormInputText(container.getStyle().stringEditor());nameInput.setPlaceholder(environment.getMessages().attributeName());nameInput.addValueChangeHandler(event -> {- if (!AttributeUtil.nameIsValid(event.getValue())) {+ if (!ATTRIBUTE_NAME_VALIDATOR.test(event.getValue())) {formGroup.setError(true);showValidationError(environment.getMessages().invalidAttributeName());} else {@@ -369,8 +375,8 @@ public class AttributesEditorwellknownListBox.addChangeHandler(event -> {if (wellknownListBox.getSelectedIndex() > 0) {AssetMeta assetMeta = AssetMeta.editable()[wellknownListBox.getSelectedIndex() - 1];- itemNameInput.setText(assetMeta.getName());- item.setName(assetMeta.getName());+ itemNameInput.setText(assetMeta.getUrn());+ item.setName(assetMeta.getUrn());AssetMeta.EditableType editableType = AssetMeta.EditableType.byValueType(assetMeta.getValueType());typeListBox.setSelectedIndex(editableType != null ? editableType.ordinal() + 1 : 0diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.javaindex 136333de4..8e3f08916 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java@@ -32,13 +32,16 @@ import org.openremote.manager.client.event.ShowSuccessEvent;import org.openremote.manager.client.i18n.ManagerMessages;import org.openremote.manager.client.util.CollectionsUtil;import org.openremote.manager.client.widget.*;-import org.openremote.model.*;+import org.openremote.model.Attribute;+import org.openremote.model.AttributeType;+import org.openremote.model.Constants;+import org.openremote.model.MetaItem;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetMeta;-import org.openremote.model.util.AttributeUtil;import org.openremote.model.util.TextUtil;import java.util.*;+import java.util.function.Consumer;public abstract class AttributesView<C extends AttributesView.Container<S>,@@ -71,10 +74,6 @@ public abstract class AttributesView<static protected DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat(Constants.DEFAULT_DATETIME_FORMAT);- public TimestampLabel() {- this(null);- }-public TimestampLabel(Long timestamp) {addStyleName("flex");getElement().getStyle().setFontSize(0.8, com.google.gwt.dom.client.Style.Unit.EM);@@ -201,20 +200,11 @@ public abstract class AttributesView<}protected String getAttributeLabel(AssetAttribute attribute) {- String label = attribute.getName();- MetaItem labelItem = attribute.firstMetaItem(AssetMeta.LABEL);- if (labelItem != null) {- label = labelItem.getValueAsString();- }- return label;+ return attribute.getLabel();}protected String getAttributeDescription(AssetAttribute attribute) {- MetaItem description = attribute.firstMetaItem(AssetMeta.DESCRIPTION);- if (description != null) {- return description.getValueAsString();- }- return null;+ return attribute.getDescription();}protected AttributeEditor createEditor(AssetAttribute attribute, FormGroup formGroup) {@@ -475,7 +465,7 @@ public abstract class AttributesView<}protected void removeAttribute(AssetAttribute attribute) {- AttributeUtil.remove(attributes, attribute.getName());+ Attribute.removeAttribute(attributes, attribute.getName());editors.remove(attribute.getName());int attributeGroupIndex = container.getPanel().getWidgetIndex(attributeGroups.get(attribute));container.getPanel().remove(attributeGroupIndex);diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowser.javaindex 999c01207..3be1e4e2a 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowser.java@@ -21,9 +21,10 @@ package org.openremote.manager.client.assets.browser;import com.google.gwt.user.client.ui.IsWidget;import com.google.gwt.view.client.HasData;-import org.openremote.model.Consumer;import org.openremote.model.asset.Asset;+import java.util.function.Consumer;+/*** Browse tenants and assets in a tree view.*diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.javaindex c9b7db66e..77947c743 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java@@ -27,7 +27,6 @@ import org.openremote.manager.client.assets.AssetMapper;import org.openremote.manager.shared.asset.AssetResource;import org.openremote.manager.shared.security.Tenant;import org.openremote.manager.shared.security.TenantResource;-import org.openremote.model.Consumer;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetTreeModifiedEvent;import org.openremote.model.event.bus.EventRegistration;@@ -37,6 +36,7 @@ import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.List;+import java.util.function.Consumer;import java.util.logging.Logger;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.javaindex e6e072512..994db085f 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelector.java@@ -4,7 +4,8 @@ import com.google.gwt.user.client.ui.FlowPanel;import com.google.gwt.user.client.ui.Label;import org.openremote.manager.client.i18n.ManagerMessages;import org.openremote.manager.client.widget.*;-import org.openremote.model.Consumer;++import java.util.function.Consumer;/*** Shows a browser tree node in a form group and encapsulates the process ofdiff --git a/manager/client/src/main/java/org/openremote/manager/client/datapoint/DatapointBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/datapoint/DatapointBrowser.javaindex f5a615fad..707a87db9 100644--- a/manager/client/src/main/java/org/openremote/manager/client/datapoint/DatapointBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/datapoint/DatapointBrowser.java@@ -29,12 +29,12 @@ import org.openremote.manager.client.interop.chartjs.Chart;import org.openremote.manager.client.interop.chartjs.ChartUtil;import org.openremote.manager.client.widget.*;import org.openremote.model.Constants;-import org.openremote.model.Consumer;import org.openremote.model.datapoint.DatapointInterval;import org.openremote.model.datapoint.NumberDatapoint;import java.util.Arrays;import java.util.Date;+import java.util.function.Consumer;import static com.google.gwt.dom.client.Style.Unit.EM;import static com.google.gwt.dom.client.Style.Unit.PX;diff --git a/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java b/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.javaindex 1861a692f..84bb28e8e 100644--- a/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java+++ b/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java@@ -22,12 +22,12 @@ package org.openremote.manager.client.http;import org.openremote.manager.client.Environment;import org.openremote.model.event.bus.EventBus;import org.openremote.manager.client.i18n.ManagerMessages;-import org.openremote.model.Consumer;import org.openremote.manager.client.event.ShowFailureEvent;import org.openremote.manager.shared.http.*;import org.openremote.manager.shared.validation.ConstraintViolation;import java.util.Arrays;+import java.util.function.Consumer;public interface RequestExceptionHandler {diff --git a/model/src/main/java/org/openremote/model/BiConsumer.java b/manager/client/src/main/java/org/openremote/manager/client/interop/BiConsumer.javasimilarity index 92%rename from model/src/main/java/org/openremote/model/BiConsumer.javarename to manager/client/src/main/java/org/openremote/manager/client/interop/BiConsumer.javaindex 032212201..53f307f1e 100644--- a/model/src/main/java/org/openremote/model/BiConsumer.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/BiConsumer.java@@ -17,13 +17,10 @@* 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;+package org.openremote.manager.client.interop;import jsinterop.annotations.JsFunction;-/**- * TODO: Remove this when GWT emulates JDK 8- */@FunctionalInterface@JsFunctionpublic interface BiConsumer<T,U> {diff --git a/model/src/main/java/org/openremote/model/Consumer.java b/manager/client/src/main/java/org/openremote/manager/client/interop/Consumer.javasimilarity index 91%rename from model/src/main/java/org/openremote/model/Consumer.javarename to manager/client/src/main/java/org/openremote/manager/client/interop/Consumer.javaindex b8797b7e2..7710e4f83 100644--- a/model/src/main/java/org/openremote/model/Consumer.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/Consumer.java@@ -17,13 +17,10 @@* 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;+package org.openremote.manager.client.interop;import jsinterop.annotations.JsFunction;-/**- * TODO: Remove this when GWT emulates JDK 8- */@FunctionalInterface@JsFunctionpublic interface Consumer<T> {diff --git a/model/src/main/java/org/openremote/model/Function.java b/manager/client/src/main/java/org/openremote/manager/client/interop/Function.javasimilarity index 91%rename from model/src/main/java/org/openremote/model/Function.javarename to manager/client/src/main/java/org/openremote/manager/client/interop/Function.javaindex f4d4d9cc9..7eec1a461 100644--- a/model/src/main/java/org/openremote/model/Function.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/Function.java@@ -17,13 +17,10 @@* 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;+package org.openremote.manager.client.interop;import jsinterop.annotations.JsFunction;-/**- * TODO: Remove this when GWT emulates JDK 8- */@FunctionalInterface@JsFunctionpublic interface Function<T,U> {diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/promise/Promise.java b/manager/client/src/main/java/org/openremote/manager/client/interop/Promise.javasimilarity index 91%rename from manager/client/src/main/java/org/openremote/manager/client/interop/promise/Promise.javarename to manager/client/src/main/java/org/openremote/manager/client/interop/Promise.javaindex 9bfe1ce42..307aea546 100644--- a/manager/client/src/main/java/org/openremote/manager/client/interop/promise/Promise.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/Promise.java@@ -17,14 +17,11 @@* 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.client.interop.promise;+package org.openremote.manager.client.interop;import jsinterop.annotations.JsMethod;import jsinterop.annotations.JsPackage;import jsinterop.annotations.JsType;-import org.openremote.model.BiConsumer;-import org.openremote.model.Consumer;-import org.openremote.model.Function;@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Promise")public class Promise<T,U> {@@ -54,4 +51,5 @@ public class Promise<T,U> {public static native <T,U> Promise<T,U> all(Promise<T,U>... promises);public static native <T,U> Promise<T,U> race(Promise<T,U>... promises);+}diff --git a/model/src/main/java/org/openremote/model/Runnable.java b/manager/client/src/main/java/org/openremote/manager/client/interop/Runnable.javasimilarity index 91%rename from model/src/main/java/org/openremote/model/Runnable.javarename to manager/client/src/main/java/org/openremote/manager/client/interop/Runnable.javaindex 087bfd315..16224b17e 100644--- a/model/src/main/java/org/openremote/model/Runnable.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/Runnable.java@@ -17,13 +17,10 @@* 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;+package org.openremote.manager.client.interop;import jsinterop.annotations.JsFunction;-/**- * TODO: Remove this when GWT emulates JDK 8- */@FunctionalInterface@JsFunctionpublic interface Runnable {diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/Keycloak.java b/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/Keycloak.javaindex 3088bc6db..c9ab3fbd2 100644--- a/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/Keycloak.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/Keycloak.java@@ -23,7 +23,7 @@ import elemental.json.JsonArray;import elemental.json.JsonObject;import jsinterop.annotations.JsProperty;import jsinterop.annotations.JsType;-import org.openremote.model.Runnable;+import org.openremote.manager.client.interop.Runnable;import static jsinterop.annotations.JsPackage.GLOBAL;diff --git a/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/KeycloakCallback.java b/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/KeycloakCallback.javaindex 742b1387d..21b14004c 100644--- a/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/KeycloakCallback.java+++ b/manager/client/src/main/java/org/openremote/manager/client/interop/keycloak/KeycloakCallback.java@@ -20,8 +20,8 @@package org.openremote.manager.client.interop.keycloak;import jsinterop.annotations.JsType;-import org.openremote.model.Consumer;-import org.openremote.model.Runnable;+import org.openremote.manager.client.interop.Consumer;+import org.openremote.manager.client.interop.Runnable;// We have GWT compiler erasure problems if this is an interface, so let's use an abstract class@JsTypediff --git a/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java b/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.javaindex 54a85566a..20c383873 100644--- a/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/map/MapActivity.java@@ -33,6 +33,7 @@ import org.openremote.manager.client.mvp.AppActivity;import org.openremote.manager.shared.asset.AssetResource;import org.openremote.manager.shared.map.MapResource;import org.openremote.manager.shared.security.Tenant;+import org.openremote.model.Attribute;import org.openremote.model.AttributeEvent;import org.openremote.model.Pair;import org.openremote.model.asset.Asset;@@ -44,6 +45,7 @@ import org.openremote.model.geo.GeoJSON;import javax.inject.Inject;import java.util.ArrayList;import java.util.Collection;+import java.util.Comparator;import java.util.List;import java.util.logging.Logger;import java.util.stream.Collectors;@@ -158,8 +160,9 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapVif (assetId != null) {assetBrowserPresenter.loadAsset(assetId, loadedAsset -> {this.asset = loadedAsset;- this.dashboardAttributes = asset.getAttributes().stream()- .filter(AssetAttribute::isShowOnDashboard).collect(Collectors.toList());+ this.dashboardAttributes = asset.getAttributeStream()+ .filter(AssetAttribute::isShowOnDashboard)+ .collect(Collectors.toList());assetBrowserPresenter.selectAsset(asset);view.setAssetViewHistoryToken(environment.getPlaceHistoryMapper().getToken(new AssetViewPlace(assetId)@@ -189,6 +192,7 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapVprotected void showAssetInfoItems() {List<Pair<String, String>> infoItems = dashboardAttributes.stream().map(attribute -> new Pair<>(attribute.getLabel(), format(attribute.getFormat(), attribute.getValueAsString())))+ .sorted(Comparator.comparing(pair -> pair.key)).collect(Collectors.toList());if (asset.hasGeoFeature()) {infoItems.add(0, new Pair<>(diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/AbstractRulesEditorActivity.java b/manager/client/src/main/java/org/openremote/manager/client/rules/AbstractRulesEditorActivity.javaindex 4169460d8..993c74238 100644--- a/manager/client/src/main/java/org/openremote/manager/client/rules/AbstractRulesEditorActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/AbstractRulesEditorActivity.java@@ -35,10 +35,10 @@ import org.openremote.manager.shared.http.RequestParams;import org.openremote.manager.shared.rules.Ruleset;import org.openremote.manager.shared.rules.RulesetResource;import org.openremote.manager.shared.validation.ConstraintViolation;-import org.openremote.model.Consumer;import javax.inject.Inject;import java.util.Collection;+import java.util.function.Consumer;import java.util.logging.Logger;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesEditorActivity.java b/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesEditorActivity.javaindex 05b033104..a3c4225d5 100644--- a/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesEditorActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/asset/AssetRulesEditorActivity.java@@ -35,10 +35,10 @@ import org.openremote.manager.shared.http.EntityWriter;import org.openremote.manager.shared.http.RequestParams;import org.openremote.manager.shared.rules.AssetRuleset;import org.openremote.manager.shared.rules.RulesetResource;-import org.openremote.model.Consumer;import javax.inject.Inject;import java.util.Collection;+import java.util.function.Consumer;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesEditorActivity.java b/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesEditorActivity.javaindex 4a69118c3..14a03350e 100644--- a/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesEditorActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/global/GlobalRulesEditorActivity.java@@ -32,10 +32,10 @@ import org.openremote.manager.shared.http.EntityWriter;import org.openremote.manager.shared.http.RequestParams;import org.openremote.manager.shared.rules.GlobalRuleset;import org.openremote.manager.shared.rules.RulesetResource;-import org.openremote.model.Consumer;import javax.inject.Inject;import java.util.Collection;+import java.util.function.Consumer;public class GlobalRulesEditorActivityextends AbstractRulesEditorActivity<GlobalRuleset, GlobalRulesEditorPlace> {diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesEditorActivity.java b/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesEditorActivity.javaindex 4880affc1..d0f76ac8c 100644--- a/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesEditorActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/tenant/TenantRulesEditorActivity.java@@ -23,9 +23,6 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget;import org.openremote.manager.client.Environment;import org.openremote.manager.client.TenantMapper;import org.openremote.manager.client.assets.browser.AssetBrowser;-import org.openremote.manager.shared.security.Tenant;-import org.openremote.model.event.bus.EventBus;-import org.openremote.model.event.bus.EventRegistration;import org.openremote.manager.client.mvp.AppActivity;import org.openremote.manager.client.rules.AbstractRulesEditorActivity;import org.openremote.manager.client.rules.RulesEditor;@@ -34,11 +31,14 @@ import org.openremote.manager.shared.http.EntityWriter;import org.openremote.manager.shared.http.RequestParams;import org.openremote.manager.shared.rules.RulesetResource;import org.openremote.manager.shared.rules.TenantRuleset;+import org.openremote.manager.shared.security.Tenant;import org.openremote.manager.shared.security.TenantResource;-import org.openremote.model.Consumer;+import org.openremote.model.event.bus.EventBus;+import org.openremote.model.event.bus.EventRegistration;import javax.inject.Inject;import java.util.Collection;+import java.util.function.Consumer;import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;diff --git a/manager/client/src/main/java/org/openremote/manager/client/service/RequestService.java b/manager/client/src/main/java/org/openremote/manager/client/service/RequestService.javaindex 2b6b4d46e..592bc4f07 100644--- a/manager/client/src/main/java/org/openremote/manager/client/service/RequestService.java+++ b/manager/client/src/main/java/org/openremote/manager/client/service/RequestService.java@@ -19,13 +19,13 @@*/package org.openremote.manager.client.service;-import org.openremote.model.Consumer;import org.openremote.manager.shared.http.EntityReader;import org.openremote.manager.shared.http.EntityWriter;import org.openremote.manager.shared.http.RequestException;import org.openremote.manager.shared.http.RequestParams;import java.util.List;+import java.util.function.Consumer;public interface RequestService {diff --git a/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java b/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.javaindex 5008da8a0..24ffcbaec 100644--- a/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/service/RequestServiceImpl.java@@ -25,13 +25,13 @@ import elemental.html.Location;import jsinterop.annotations.JsPackage;import jsinterop.annotations.JsProperty;import jsinterop.annotations.JsType;-import org.openremote.model.Consumer;import org.openremote.manager.shared.http.*;import org.openremote.manager.shared.validation.ConstraintViolationReport;import java.util.Arrays;import java.util.Collections;import java.util.List;+import java.util.function.Consumer;import java.util.logging.Level;import java.util.logging.Logger;diff --git a/manager/client/src/main/java/org/openremote/manager/client/service/SecurityService.java b/manager/client/src/main/java/org/openremote/manager/client/service/SecurityService.javaindex 033a05b55..661e8dad8 100644--- a/manager/client/src/main/java/org/openremote/manager/client/service/SecurityService.java+++ b/manager/client/src/main/java/org/openremote/manager/client/service/SecurityService.java@@ -22,8 +22,8 @@ package org.openremote.manager.client.service;import org.openremote.manager.client.interop.keycloak.AuthToken;import org.openremote.manager.client.interop.keycloak.LoginOptions;import org.openremote.manager.client.interop.keycloak.LogoutOptions;-import org.openremote.model.Consumer;-import org.openremote.model.Runnable;++import java.util.function.Consumer;public interface SecurityService {diff --git a/manager/client/src/main/java/org/openremote/manager/client/service/SecurityServiceImpl.java b/manager/client/src/main/java/org/openremote/manager/client/service/SecurityServiceImpl.javaindex 318788826..95c474fd5 100644--- a/manager/client/src/main/java/org/openremote/manager/client/service/SecurityServiceImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/service/SecurityServiceImpl.java@@ -26,9 +26,8 @@ import org.openremote.manager.client.event.UserChangeEvent;import org.openremote.model.event.bus.EventBus;import org.openremote.manager.client.interop.keycloak.*;import org.openremote.model.Constants;-import org.openremote.model.Consumer;-import org.openremote.model.Runnable;+import java.util.function.Consumer;import java.util.logging.Logger;public class SecurityServiceImpl implements SecurityService {@@ -132,31 +131,66 @@ public class SecurityServiceImpl implements SecurityService {@Overridepublic void onTokenExpired(Runnable fn) {- keycloak.onTokenExpired(fn);+ keycloak.onTokenExpired(new org.openremote.manager.client.interop.Runnable(){+ @Override+ public void run() {+ fn.run();+ }+ });}@Overridepublic void onAuthSuccess(Runnable fn) {- keycloak.onAuthSuccess = fn;+ keycloak.onAuthSuccess = new org.openremote.manager.client.interop.Runnable(){+ @Override+ public void run() {+ fn.run();+ }+ };}@Overridepublic void onAuthLogout(Runnable fn) {- keycloak.onAuthLogout = fn;+ keycloak.onAuthLogout = new org.openremote.manager.client.interop.Runnable(){+ @Override+ public void run() {+ fn.run();+ }+ };}@Overridepublic void updateToken(Consumer<Boolean> successFn, Runnable errorFn) {KeycloakCallback kcCallback = keycloak.updateToken();- kcCallback.success(successFn);- kcCallback.error(errorFn);+ kcCallback.success(new org.openremote.manager.client.interop.Consumer<Boolean>(){+ @Override+ public void accept(Boolean o) {+ successFn.accept(o);+ }+ });+ kcCallback.error(new org.openremote.manager.client.interop.Runnable(){+ @Override+ public void run() {+ errorFn.run();+ }+ });}@Overridepublic void updateToken(int minValiditySeconds, Consumer<Boolean> successFn, Runnable errorFn) {KeycloakCallback kcCallback = keycloak.updateToken(minValiditySeconds);- kcCallback.success(successFn);- kcCallback.error(errorFn);+ kcCallback.success(new org.openremote.manager.client.interop.Consumer<Boolean>(){+ @Override+ public void accept(Boolean o) {+ successFn.accept(o);+ }+ });+ kcCallback.error(new org.openremote.manager.client.interop.Runnable(){+ @Override+ public void run() {+ errorFn.run();+ }+ });}@Overridediff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.javaindex 864f1ad03..efd4e63b6 100644--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java@@ -22,9 +22,8 @@ package org.openremote.manager.client.widget;import com.google.gwt.dom.client.Style;import com.google.gwt.uibinder.client.UiChild;import com.google.gwt.user.client.ui.*;-import org.openremote.model.Consumer;-import java.util.function.Function;+import java.util.function.Consumer;import java.util.logging.Logger;/**diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormView.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormView.javaindex 82bd42999..93fad452f 100644--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormView.java+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormView.java@@ -19,8 +19,6 @@*/package org.openremote.manager.client.widget;-import org.openremote.model.Runnable;-public interface FormView {void setFormBusy(boolean busy);diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.javaindex c6397f6e0..44a5371d0 100644--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java@@ -28,7 +28,6 @@ import com.google.inject.Provider;import org.openremote.manager.client.app.dialog.ConfirmationDialog;import org.openremote.manager.client.i18n.ManagerMessages;import org.openremote.manager.client.style.WidgetStyle;-import org.openremote.model.Runnable;public class FormViewImpl extends Composite implements FormView {diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java b/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.javaindex 6561b98be..562744ef1 100644--- a/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/Hyperlink.java@@ -23,10 +23,8 @@ import com.google.gwt.core.client.GWT;import com.google.gwt.dom.client.Element;import com.google.gwt.user.client.DOM;import com.google.gwt.user.client.Event;-import com.google.gwt.user.client.History;import com.google.gwt.user.client.ui.Label;import com.google.gwt.user.client.ui.impl.HyperlinkImpl;-import org.openremote.model.Runnable;public class Hyperlink extends com.google.gwt.user.client.ui.Hyperlink {diff --git a/manager/server/src/main/java/org/openremote/manager/server/Main.java b/manager/server/src/main/java/org/openremote/manager/server/Main.javaindex 6a2858ddc..3ec53e3fd 100644--- a/manager/server/src/main/java/org/openremote/manager/server/Main.java+++ b/manager/server/src/main/java/org/openremote/manager/server/Main.java@@ -19,6 +19,7 @@*/package org.openremote.manager.server;+import org.openremote.agent3.protocol.Protocol;import org.openremote.container.Container;import org.openremote.container.ContainerService;import org.openremote.container.message.MessageBrokerService;@@ -36,13 +37,13 @@ import org.openremote.manager.server.notification.NotificationService;import org.openremote.manager.server.rules.RulesService;import org.openremote.manager.server.rules.RulesetStorageService;import org.openremote.manager.server.security.ManagerIdentityService;-import org.openremote.manager.server.setup.RuntimeResolverService;import org.openremote.manager.server.setup.SetupService;import org.openremote.manager.server.web.ManagerWebService;import java.util.ArrayList;import java.util.Arrays;import java.util.List;+import java.util.ServiceLoader;public class Main {@@ -50,7 +51,6 @@ public class Main {List<ContainerService> services = new ArrayList<ContainerService>() {{addAll(Arrays.asList(- new RuntimeResolverService(),new I18NService(),new PersistenceService(),new MessageBrokerSetupService(),@@ -62,7 +62,10 @@ public class Main {new AssetStorageService(),new AssetDatapointService(),new AssetProcessingService(),- new AgentService(),+ new AgentService()+ ));+ ServiceLoader.load(Protocol.class).forEach(this::add);+ addAll(Arrays.asList(new MapService(),new NotificationService(),new MessageBrokerService(),diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.javaindex 6c5a66176..e7da4a917 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java@@ -30,28 +30,28 @@ import org.openremote.container.persistence.PersistenceEvent;import org.openremote.manager.server.asset.AssetStorageService;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.datapoint.AssetDatapointService;-import org.openremote.manager.server.setup.RuntimeResolverService;import org.openremote.model.AbstractValueTimestampHolder;import org.openremote.model.AttributeRef;-import org.openremote.model.Function;import org.openremote.model.asset.*;-import org.openremote.model.asset.agent.ProtocolConfiguration;-import org.openremote.model.asset.agent.AgentProtocolLink;-import org.openremote.model.util.AttributeUtil;import org.openremote.model.util.JsonUtil;import java.util.*;import java.util.function.Consumer;+import java.util.function.Function;import java.util.logging.Level;import java.util.logging.Logger;import java.util.stream.Collectors;+import java.util.stream.Stream;import static org.openremote.agent3.protocol.Protocol.ACTUATOR_TOPIC;import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForAssetType;import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;-import static org.openremote.model.asset.Asset.ATTRIBUTE_PROPERTY_NAME;+import static org.openremote.model.asset.AssetAttribute.getAssetAttributesFromJson;import static org.openremote.model.asset.AssetType.AGENT;+import static org.openremote.model.asset.agent.AgentLink.*;+import static org.openremote.model.asset.agent.ProtocolConfiguration.getProtocolName;+import static org.openremote.model.asset.agent.ProtocolConfiguration.isProtocolConfiguration;/*** Finds all {@link AssetType#AGENT} and {@link AssetType#THING} assets and starts the protocols for them.@@ -63,11 +63,8 @@ public class AgentService extends RouteBuilder implements ContainerService, Consprotected AssetStorageService assetStorageService;protected AssetDatapointService assetDatapointService;protected MessageBrokerService messageBrokerService;- protected RuntimeResolverService resolverService;- protected final Map<AttributeRef, ProtocolConfiguration> protocolConfigurations = new HashMap<>();- protected AgentProtocolLink.Filter agentLinkFilter;- protected ProtocolConfiguration.Filter protocolConfigFilter;- protected Function<AttributeRef, ProtocolConfiguration> protocolConfigurationResolver = (AttributeRef protocolRef) -> {+ protected final Map<AttributeRef, AssetAttribute> protocolConfigurations = new HashMap<>();+ protected Function<AttributeRef, AssetAttribute> protocolConfigurationResolver = (AttributeRef protocolRef) -> {synchronized (protocolConfigurations) {return protocolConfigurations.get(protocolRef);}@@ -79,24 +76,22 @@ public class AgentService extends RouteBuilder implements ContainerService, ConsassetStorageService = container.getService(AssetStorageService.class);assetDatapointService = container.getService(AssetDatapointService.class);messageBrokerService = container.getService(MessageBrokerService.class);- resolverService = container.getService(RuntimeResolverService.class);}@Overridepublic void start(Container container) throws Exception {container.getService(MessageBrokerSetupService.class).getContext().addRoutes(this);- agentLinkFilter = resolverService.resolve(AgentProtocolLink.Filter.class);- protocolConfigFilter = resolverService.resolve(ProtocolConfiguration.Filter.class);- }- @Override- public void allStarted(Container container) throws Exception {- List<ServerAsset> agents = assetStorageService.findAll(new AssetQuery().select(new AssetQuery.Select(true, false)).type(AssetType.AGENT));+ List<ServerAsset> agents = assetStorageService.findAll(new AssetQuery()+ .select(new AssetQuery.Select(true, false))+ .type(AssetType.AGENT));LOG.fine("Deploy all agents in all realms: " + agents.size());+ /// For all agents, go through their protocol configurations and find+ // assets that are linked to them, to create the binding on startupfor (Asset agent : agents) {- /// Link protocols for all attributes that are valid ProtocolAttributeWrappers- protocolConfigFilter.getAllWrapped(agent.getAttributes(), true)+ agent.getAttributeStream()+ .filter(isProtocolConfiguration()).forEach(this::linkProtocol);}}@@ -134,56 +129,64 @@ public class AgentService extends RouteBuilder implements ContainerService, Consswitch (persistenceEvent.getCause()) {case INSERT:- // Link protocols for all attributes that are valid ProtocolAttributeWrappers- protocolConfigFilter.getAllWrapped(agent.getAttributes(), true)+ agent.getAttributeStream()+ .filter(isProtocolConfiguration()).forEach(this::linkProtocol);+break;case UPDATE:// Check if any protocol config attributes have been added/removed or modified- int attributesIndex = Arrays.asList(persistenceEvent.getPropertyNames()).indexOf(ATTRIBUTE_PROPERTY_NAME);+ int attributesIndex = Arrays.asList(persistenceEvent.getPropertyNames()).indexOf("attributes");if (attributesIndex < 0) {return;}// Attributes have possibly changed so need to compare old and new state to determine// which protocol configs are affected- List<AssetAttribute> oldAttributes = AttributeUtil.getAssetAttributesFromJson(agent.getId(), (JsonObject) persistenceEvent.getPreviousState()[attributesIndex]);- List<AssetAttribute> newAttributes = AttributeUtil.getAssetAttributesFromJson(agent.getId(), (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]);- List<ProtocolConfiguration> oldProtocolConfigurations = protocolConfigFilter.getAllWrapped(oldAttributes, true);- List<ProtocolConfiguration> newProtocolConfigurations = protocolConfigFilter.getAllWrapped(newAttributes, true);+ List<AssetAttribute> oldProtocolConfigurations =+ getAssetAttributesFromJson(agent.getId()).apply(+ (JsonObject) persistenceEvent.getPreviousState()[attributesIndex]+ ).filter(isProtocolConfiguration())+ .collect(Collectors.toList());+ List<AssetAttribute> newProtocolConfigurations =+ getAssetAttributesFromJson(agent.getId()).apply(+ (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]+ ).filter(isProtocolConfiguration())+ .collect(Collectors.toList());// Compare protocol configurations by JSON value// Unlink protocols that are in oldConfigs but not in newConfigsoldProtocolConfigurations+ .stream()+ .filter(oldProtocolAttribute -> newProtocolConfigurations.stream()- .filter(oldProtocolAttribute -> newProtocolConfigurations- .stream()- .noneMatch(newProtocolAttribute -> JsonUtil.equals(- oldProtocolAttribute.getAttribute().getJsonObject(),- newProtocolAttribute.getAttribute().getJsonObject())- )+ .noneMatch(newProtocolAttribute -> JsonUtil.equals(+ oldProtocolAttribute.getJsonObject(),+ newProtocolAttribute.getJsonObject()))- .forEach(this::unlinkProtocol);+ )+ .forEach(this::unlinkProtocol);// Link protocols that are in newConfigs but not in oldConfigsnewProtocolConfigurations+ .stream()+ .filter(newProtocolAttribute -> oldProtocolConfigurations.stream()- .filter(newProtocolAttribute -> oldProtocolConfigurations- .stream()- .noneMatch(oldProtocolAttribute ->- JsonUtil.equals(- oldProtocolAttribute.getAttribute().getJsonObject(),- newProtocolAttribute.getAttribute().getJsonObject()- )- )+ .noneMatch(oldProtocolAttribute ->+ JsonUtil.equals(+ oldProtocolAttribute.getJsonObject(),+ newProtocolAttribute.getJsonObject()+ ))- .forEach(this::linkProtocol);+ ).forEach(this::linkProtocol);+break;case DELETE:// Unlink any attributes that have an agent link to this agent- protocolConfigFilter.getAllWrapped(agent.getAttributes(), true)+ agent.getAttributeStream()+ .filter(isProtocolConfiguration()).forEach(this::unlinkProtocol);break;}@@ -197,71 +200,75 @@ public class AgentService extends RouteBuilder implements ContainerService, ConsLOG.finest("Processing asset persistence event: " + persistenceEvent.getCause());switch (persistenceEvent.getCause()) {- case INSERT: {+ case INSERT:+// Asset insert persistence events can be fired before the agent insert persistence event// so need to check that all protocol configs exist - any that don't we will exclude here// and handle in agent insert// Link any AGENT_LINK attributes to the referenced protocol- Map<ProtocolConfiguration, List<AssetAttribute>> groupedAgentLinksAttributes = getGroupedAgentLinkAttributes(asset.getAttributes());+ Map<AssetAttribute, List<AssetAttribute>> groupedAgentLinksAttributes =+ getGroupedAgentLinkAttributes(asset.getAttributeStream());groupedAgentLinksAttributes.forEach(this::linkAttributes);+break;- }case UPDATE:// Check if attributes of the asset have been modified- int attributesIndex = Arrays.asList(persistenceEvent.getPropertyNames()).indexOf(ATTRIBUTE_PROPERTY_NAME);+ int attributesIndex = Arrays.asList(persistenceEvent.getPropertyNames()).indexOf("attributes");if (attributesIndex < 0) {return;}// Attributes have possibly changed so need to compare old and new state to determine any changes to// AGENT_LINK attributes- List<AssetAttribute> oldAttributes = AttributeUtil.getAssetAttributesFromJson(asset.getId(), (JsonObject) persistenceEvent.getPreviousState()[attributesIndex]);- List<AssetAttribute> newAttributes = AttributeUtil.getAssetAttributesFromJson(asset.getId(), (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]);- List<AssetAttribute> oldAgentLinkedAttributes = agentLinkFilter.getAll(oldAttributes, true);- List<AssetAttribute> newAgentLinkedAttributes = agentLinkFilter.getAll(newAttributes, true);+ List<AssetAttribute> oldAgentLinkedAttributes =+ getAssetAttributesFromJson(asset.getId()).apply(+ (JsonObject) persistenceEvent.getPreviousState()[attributesIndex]+ ).filter(isAgentLink())+ .collect(Collectors.toList());+ List<AssetAttribute> newAgentLinkedAttributes =+ getAssetAttributesFromJson(asset.getId()).apply(+ (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]+ ).filter(isAgentLink())+ .collect(Collectors.toList());// Unlink thing attributes that are in old but not in new- List<AssetAttribute> attributesToUnlink = oldAgentLinkedAttributes+ Stream<AssetAttribute> attributesToUnlink = oldAgentLinkedAttributes.stream().filter(oldAgentLinkedAttribute -> newAgentLinkedAttributes.stream().noneMatch(newAgentLinkedAttribute -> JsonUtil.equals( // Ignore the timestamp in comparison- oldAgentLinkedAttribute.getJsonObject(),- newAgentLinkedAttribute.getJsonObject(),- Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME))+ oldAgentLinkedAttribute.getJsonObject(),+ newAgentLinkedAttribute.getJsonObject(),+ Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)))- )- .collect(Collectors.toList());+ );getGroupedAgentLinkAttributes(attributesToUnlink)- .forEach(- this::unlinkAttributes- );+ .forEach(this::unlinkAttributes);// Link thing attributes that are in new but not in old- List<AssetAttribute> attributesToLink = newAgentLinkedAttributes+ Stream<AssetAttribute> attributesToLink = newAgentLinkedAttributes.stream().filter(newThingAttribute -> oldAgentLinkedAttributes- .stream()- .noneMatch(oldThingAttribute -> JsonUtil.equals( // Ignore the timestamp in comparison- oldThingAttribute.getJsonObject(),- newThingAttribute.getJsonObject(),- Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME))- )- )- .collect(Collectors.toList());+ .stream()+ .noneMatch(oldThingAttribute -> JsonUtil.equals( // Ignore the timestamp in comparison+ oldThingAttribute.getJsonObject(),+ newThingAttribute.getJsonObject(),+ Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME))+ )+ );getGroupedAgentLinkAttributes(attributesToLink)- .forEach(- this::linkAttributes- );+ .forEach(this::linkAttributes);+break;case DELETE: {// Unlink any AGENT_LINK attributes from the referenced protocol- Map<ProtocolConfiguration, List<AssetAttribute>> groupedAgentLinkAndProtocolAttributes = getGroupedAgentLinkAttributes(asset.getAttributes());+ Map<AssetAttribute, List<AssetAttribute>> groupedAgentLinkAndProtocolAttributes =+ getGroupedAgentLinkAttributes(asset.getAttributeStream());groupedAgentLinkAndProtocolAttributes.forEach(this::unlinkAttributes@@ -271,55 +278,55 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons}}- protected void linkProtocol(ProtocolConfiguration protocolConfiguration) {- AttributeRef protocolAttributeRef = protocolConfiguration.getAttributeReference();+ protected void linkProtocol(AssetAttribute protocolConfiguration) {+ LOG.finest("Linking all attributes that use protocol attribute: " + protocolConfiguration);++ AttributeRef protocolAttributeRef = protocolConfiguration.getReference();synchronized (protocolConfigurations) {// Store this protocol configuration for easy access laterprotocolConfigurations.put(protocolAttributeRef, protocolConfiguration);}- LOG.finest("Linking all attributes that use protocol attribute: " + protocolAttributeRef);-// Get all assets that have attributes that use this protocol configurationList<ServerAsset> assets = assetStorageService.findAll(new AssetQuery().select(new AssetQuery.Select(true, false)).attributeMeta(- new AssetQuery.AttributeRefPredicate(- AssetMeta.AGENT_LINK,- protocolAttributeRef.getEntityId(),- protocolAttributeRef.getAttributeName()+ new AssetQuery.AttributeRefPredicate(+ AssetMeta.AGENT_LINK,+ protocolAttributeRef.getEntityId(),+ protocolAttributeRef.getAttributeName()+ ))- ));assets.forEach(asset ->- getGroupedAgentLinkAttributes(asset.getAttributes())+ getGroupedAgentLinkAttributes(asset.getAttributeStream()).forEach(this::linkAttributes));}- protected void unlinkProtocol(ProtocolConfiguration protocolConfiguration) {- AttributeRef protocolAttributeRef = protocolConfiguration.getAttribute().getReference();+ protected void unlinkProtocol(AssetAttribute protocolConfiguration) {+ AttributeRef protocolAttributeRef = protocolConfiguration.getReference();// Get all assets that have attributes that use this protocol configurationList<ServerAsset> assets = assetStorageService.findAll(- new AssetQuery()- .select(new AssetQuery.Select(true, false))- .attributeMeta(- new AssetQuery.AttributeRefPredicate(- AssetMeta.AGENT_LINK,- protocolAttributeRef.getEntityId(),- protocolAttributeRef.getAttributeName()- )+ new AssetQuery()+ .select(new AssetQuery.Select(true, false))+ .attributeMeta(+ new AssetQuery.AttributeRefPredicate(+ AssetMeta.AGENT_LINK,+ protocolAttributeRef.getEntityId(),+ protocolAttributeRef.getAttributeName()+ )));assets.forEach(asset ->- getGroupedAgentLinkAttributes(asset.getAttributes())+ getGroupedAgentLinkAttributes(asset.getAttributeStream()).forEach(this::unlinkAttributes));@@ -328,20 +335,20 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons}}- protected Protocol getProtocol(ProtocolConfiguration protocolConfiguration) {+ protected Protocol getProtocol(AssetAttribute protocolConfiguration) {Collection<Protocol> protocols = container.getServices(Protocol.class);return protocols- .stream()- .filter(protocol -> {- if (protocol.getProtocolName() == null || protocol.getProtocolName().length() == 0)- throw new IllegalStateException("Protocol can't have empty name: " + protocol.getClass());- return protocol.getProtocolName().equals(protocolConfiguration.getProtocolName());- })- .findFirst()- .orElse(null);+ .stream()+ .filter(protocol -> {+ if (protocol.getProtocolName() == null || protocol.getProtocolName().length() == 0)+ throw new IllegalStateException("Protocol can't have empty name: " + protocol.getClass());+ return protocol.getProtocolName().equals(getProtocolName().apply(protocolConfiguration));+ })+ .findFirst()+ .orElse(null);}- protected void linkAttributes(ProtocolConfiguration protocolConfiguration, Collection<AssetAttribute> agentLinkedAttributes) {+ protected void linkAttributes(AssetAttribute protocolConfiguration, Collection<AssetAttribute> attributes) {Protocol protocol = getProtocol(protocolConfiguration);if (protocol == null) {@@ -351,14 +358,14 @@ public class AgentService extends RouteBuilder implements ContainerService, Constry {LOG.finest("Linking protocol attributes to: " + protocol.getProtocolName());- protocol.linkAttributes(agentLinkedAttributes, protocolConfiguration);+ protocol.linkAttributes(attributes, protocolConfiguration);} catch (Exception ex) {// TODO: Better error handling?LOG.log(Level.WARNING, "Ignoring error on linking attributes to protocol: " + protocol.getProtocolName(), ex);}}- protected void unlinkAttributes(ProtocolConfiguration protocolConfiguration, Collection<AssetAttribute> attributes) {+ protected void unlinkAttributes(AssetAttribute protocolConfiguration, Collection<AssetAttribute> attributes) {Protocol protocol = getProtocol(protocolConfiguration);if (protocol == null) {@@ -382,7 +389,6 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons* Otherwise we push the update to the protocol to handle and prevent any further* processing of this event by the processing chain, the protocol should raise* sensor updates as required (i.e. the protocol is responsible for synchronising state)- **/@Overridepublic void accept(AssetState assetState) {@@ -392,11 +398,11 @@ public class AgentService extends RouteBuilder implements ContainerService, Consreturn;}- AttributeRef protocolRef = AgentProtocolLink.getLink(assetState.getAttribute());+ AttributeRef protocolRef = getAgentLink().apply(assetState.getAttribute());if (protocolRef != null) {// Check attribute is linked to an actual agent- ProtocolConfiguration protocolConfiguration = protocolConfigurationResolver.apply(protocolRef);+ AssetAttribute protocolConfiguration = protocolConfigurationResolver.apply(protocolRef);if (protocolConfiguration == null) {LOG.warning("Cannot process as agent link is invalid:" + assetState);@@ -419,31 +425,30 @@ public class AgentService extends RouteBuilder implements ContainerService, ConsassetState.setProcessingStatus(AssetState.ProcessingStatus.HANDLED);}- public Function<AttributeRef, ProtocolConfiguration> getProtocolConfigurationResolver() {+ public Function<AttributeRef, AssetAttribute> getProtocolConfigurationResolver() {return protocolConfigurationResolver;}/*** Gets all agent link attributes and their linked protocol configuration and groups them by Protocol Configuration*/- protected Map<ProtocolConfiguration, List<AssetAttribute>> getGroupedAgentLinkAttributes(List<AssetAttribute> agentLinkAttributes) {- AgentProtocolLink.Filter filter = resolverService.resolve(AgentProtocolLink.Filter.class);- Map<ProtocolConfiguration, List<AssetAttribute>> map = new HashMap<>();+ protected Map<AssetAttribute, List<AssetAttribute>> getGroupedAgentLinkAttributes(Stream<AssetAttribute> attributes) {++ Map<AssetAttribute, List<AssetAttribute>> map = new HashMap<>();- filter.getAll(agentLinkAttributes, true)+ attributes+ .filter(isValidAgentLink()).forEach(agentLinkAttribute -> {- AttributeRef agentLink = AgentProtocolLink.getLink(agentLinkAttribute);- ProtocolConfiguration protocolConfiguration = protocolConfigurationResolver.apply(agentLink);+ AttributeRef protocolRef = getAgentLink().apply(agentLinkAttribute);+ AssetAttribute protocolConfiguration = protocolConfigurationResolver.apply(protocolRef);if (protocolConfiguration == null) {- LOG.warning("Invalid agent link '" + agentLink + "' on attribute '" + agentLinkAttribute.getReference() + "'");- }- else {+ LOG.warning("Invalid agent link '" + protocolRef + "' on attribute '" + agentLinkAttribute.getReference() + "'");+ } else {map.computeIfAbsent(protocolConfiguration, newProtocolConfiguration -> new ArrayList<>()).add(agentLinkAttribute);}});-return map;}diff --git a/manager/server/src/main/java/org/openremote/manager/server/apps/ConsoleAppService.java b/manager/server/src/main/java/org/openremote/manager/server/apps/ConsoleAppService.javaindex d915b6179..a9af07131 100644--- a/manager/server/src/main/java/org/openremote/manager/server/apps/ConsoleAppService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/apps/ConsoleAppService.java@@ -53,11 +53,6 @@ public class ConsoleAppService implements ContainerService {public void start(Container container) throws Exception {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {}diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.javaindex c5b463ff7..9a36e1181 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java@@ -33,9 +33,6 @@ import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.manager.shared.security.ClientRole;import org.openremote.model.AttributeEvent;import org.openremote.model.asset.*;-import org.openremote.model.asset.agent.ProtocolConfiguration;-import org.openremote.model.asset.agent.AgentProtocolLink;-import org.openremote.model.util.AttributeUtil;import java.util.ArrayList;import java.util.List;@@ -46,6 +43,11 @@ import java.util.logging.Logger;import static org.openremote.agent3.protocol.Protocol.SENSOR_QUEUE;import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TOPIC;import static org.openremote.manager.server.event.EventService.getWebsocketAuth;+import static org.openremote.model.asset.AssetAttribute.containsAssetAttributeNamed;+import static org.openremote.model.asset.AssetAttribute.findAssetAttribute;+import static org.openremote.model.asset.AssetAttribute.isMatchingAttributeEvent;+import static org.openremote.model.asset.agent.AgentLink.getAgentLink;+import static org.openremote.model.asset.agent.AgentLink.isValidAgentLink;/*** Receives {@link AttributeEvent}s and processes them.@@ -193,11 +195,6 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {@@ -267,7 +264,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerreturn;// Attribute must exist- if (!AttributeUtil.contains(asset.getAttributes(), event.getAttributeName()))+ if (!containsAssetAttributeNamed(event.getAttributeName()).test(asset))return;// Regular users can only write attribute events for assets in their realm@@ -319,7 +316,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// Pass attribute event through the processing chainLOG.fine("Processing " + attributeEvent + " for: " + asset);- AssetAttribute attribute = AttributeUtil.getAttributeByName(asset.getAttributes(), attributeEvent.getAttributeName());+ AssetAttribute attribute = findAssetAttribute(attributeEvent.getAttributeName()).apply(asset);if (attribute == null) {LOG.warning("Ignoring " + attributeEvent + ", attribute doesn't exist on asset: " + asset);@@ -338,7 +335,6 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer/*** We get here if a protocol pushes a sensor update message.- **/protected void processSensorUpdate(AttributeEvent attributeEvent) {ServerAsset asset = assetStorageService.find(attributeEvent.getEntityId(), true);@@ -349,16 +345,22 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// event comes from a Protocol, we can not assume that the attribute is still linked,// consider a protocol that receives a batch of messages because a gateway was offline// for a day)+ AssetAttribute attribute = asset.getAttributeStream()+ .filter(isMatchingAttributeEvent(attributeEvent))+ .filter(isValidAgentLink())+ .findFirst()+ .orElse(null);- // Look for a matching attribute- AssetAttribute attribute = AttributeUtil.getAttributeByName(asset.getAttributes(), attributeEvent.getAttributeName());+ if (attribute == null) {+ LOG.warning("Processing sensor update failed, no attribute or not linked to an agent: " + attributeEvent);+ return;+ }- // Wrap this as an agent link attribute and ensure that the protocol can be resolved- AgentProtocolLink agentProtocolLink = new AgentProtocolLink(attribute);- ProtocolConfiguration protocolConfiguration = agentService.getProtocolConfigurationResolver().apply(agentProtocolLink.getLink());+ AssetAttribute protocolConfiguration =+ getAgentLink().andThen(agentService.getProtocolConfigurationResolver()).apply(attribute);- if (!agentProtocolLink.isValid() || protocolConfiguration == null) {- LOG.warning("Processing sensor update failed attribute not linked to an agent or invalid agent link: " + attributeEvent);+ if (protocolConfiguration == null) {+ LOG.warning("Processing sensor update failed, linked agent protocol configuration not found: " + attributeEvent);return;}diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.javaindex f0625f7a1..6d53ba027 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java@@ -31,7 +31,6 @@ import org.openremote.model.AttributeRef;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetQuery;-import org.openremote.model.util.AttributeUtil;import javax.ws.rs.WebApplicationException;import javax.ws.rs.core.Response;@@ -41,6 +40,8 @@ import java.util.logging.Logger;import static javax.ws.rs.core.Response.Status.BAD_REQUEST;import static javax.ws.rs.core.Response.Status.NOT_FOUND;+import static org.openremote.model.asset.AssetAttribute.containsAssetAttributeNamed;+import static org.openremote.model.asset.AssetAttribute.isAssetAttribute;public class AssetResourceImpl extends ManagerWebResource implements AssetResource {@@ -244,10 +245,8 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResourthrow new WebApplicationException(NOT_FOUND);}- List<AssetAttribute> attributes = asset.getAttributes();-// Check attribute exists- if (!AttributeUtil.contains(attributes, attributeName))+ if (!containsAssetAttributeNamed(attributeName).test(asset))throw new WebApplicationException(NOT_FOUND);// Check realm, must be accessible@@ -257,7 +256,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour}// Check read-only- if (!isSuperUser() && AttributeUtil.getAttributeByName(attributes, attributeName).isReadOnly()) {+ if (!isSuperUser() && isAssetAttribute(attributeName, AssetAttribute::isReadOnly).test(asset)) {throw new WebApplicationException(Response.Status.FORBIDDEN);}diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.javaindex c635e9256..5f6b1bc13 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java@@ -39,15 +39,11 @@ import org.openremote.model.AttributeEvent;import org.openremote.model.Pair;import org.openremote.model.ReadAttributesEvent;import org.openremote.model.asset.*;-import org.openremote.model.util.AttributeUtil;import org.postgresql.util.PGobject;import javax.persistence.EntityManager;import java.sql.*;-import java.util.ArrayList;-import java.util.Arrays;-import java.util.List;-import java.util.Objects;+import java.util.*;import java.util.function.Consumer;import java.util.logging.Logger;import java.util.stream.Collectors;@@ -115,11 +111,6 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicpublic void start(Container container) throws Exception {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {@@ -208,7 +199,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicpublic ServerAsset find(String assetId, boolean loadComplete, boolean filterProtected) {if (assetId == null)throw new IllegalArgumentException("Can't query null asset identifier");- return find(new AssetQuery().select(new AssetQuery.Select(loadComplete, filterProtected)).id(assetId));+ return find(new AssetQuery().select(new AssetQuery.Select(loadComplete, filterProtected)).id(assetId));}public ServerAsset find(AssetQuery query) {@@ -245,8 +236,8 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicthrow new IllegalStateException("Invalid parent");}- // Validate attribute names- if (!asset.getAttributes().stream().allMatch(AssetAttribute::isValid)) {+ // Validate attributes+ if (!asset.getAttributeStream().allMatch(AssetAttribute::isValid)) {throw new IllegalStateException("One or more attributes are not valid");}@@ -596,9 +587,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServictry (PreparedStatement statement = connection.prepareStatement(update)) {// Bind the value (and check we don't have a SQL injection hole in attribute name!)- if (!AttributeUtil.nameIsValid(attributeName)) {+ if (!AssetAttribute.ATTRIBUTE_NAME_VALIDATOR.test(attributeName)) {LOG.fine(- "Invalid attribute name (must match '" + AttributeUtil.ATTRIBUTE_NAME_PATTERN + "'): " + attributeName+ "Invalid attribute name (must match '" + AssetAttribute.ATTRIBUTE_NAME_PATTERN + "'): " + attributeName);return false;}@@ -688,16 +679,13 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic}protected void replyWithAttributeEvents(String sessionKey, ServerAsset asset, String[] attributeNames) {- List<AssetAttribute> attributes = asset.getAttributes();-- // Client may want to read a subset or all attributes of the assetList<String> names = attributeNames != null && attributeNames.length > 0? Arrays.asList(attributeNames)- : AttributeUtil.getNames(attributes);+ : Collections.EMPTY_LIST;- LOG.fine("For client session '" + sessionKey + "', reading asset attributes " + names + " on: " + asset);- List<AttributeEvent> events = attributes.stream()- .filter(assetAttribute -> names.contains(assetAttribute.getName()))+ // Client may want to read a subset or all attributes of the asset+ List<AttributeEvent> events = asset.getAttributeStream()+ .filter(attribute -> names.isEmpty() || names.contains(attribute.getName())).map(AssetAttribute::getStateEvent).collect(Collectors.toList());diff --git a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.javaindex 7aa4cf53e..9dbf9d138 100644--- a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java+++ b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointResourceImpl.java@@ -29,12 +29,12 @@ import org.openremote.model.AttributeRef;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.datapoint.DatapointInterval;import org.openremote.model.datapoint.NumberDatapoint;-import org.openremote.model.util.AttributeUtil;import javax.ws.rs.BeanParam;import javax.ws.rs.WebApplicationException;import javax.ws.rs.core.Response;-import java.util.List;++import static org.openremote.model.asset.AssetAttribute.isAssetAttribute;public class AssetDatapointResourceImpl extends ManagerWebResource implements AssetDatapointResource {@@ -58,12 +58,8 @@ public class AssetDatapointResourceImpl extends ManagerWebResource implements Astry {// TODO Security etc.ServerAsset asset = assetStorageService.find(assetId, true);- List<AssetAttribute> assetAttributes = asset.getAttributes();- if (!AttributeUtil.contains(assetAttributes, attributeName)) {- throw new WebApplicationException(Response.Status.NOT_FOUND);- }- if (!AttributeUtil.getAttributeByName(assetAttributes, attributeName).isStoreDatapoints()) {+ if (!isAssetAttribute(attributeName, AssetAttribute::isStoreDatapoints).test(asset)) {throw new WebApplicationException(Response.Status.NOT_FOUND);}diff --git a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.javaindex 0dd19c1e1..35db7c0b1 100644--- a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java@@ -9,8 +9,6 @@ import org.openremote.container.web.WebService;import org.openremote.manager.server.asset.AssetStorageService;import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.model.AttributeRef;-import org.openremote.model.Function;-import org.openremote.model.Pair;import org.openremote.model.asset.AssetState;import org.openremote.model.datapoint.AssetDatapoint;import org.openremote.model.datapoint.DatapointInterval;@@ -22,6 +20,7 @@ import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.List;import java.util.function.Consumer;+import java.util.function.Function;import java.util.logging.Logger;/**@@ -51,11 +50,6 @@ public class AssetDatapointService implements ContainerService, Consumer<AssetStpublic void start(Container container) throws Exception {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {}diff --git a/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java b/manager/server/src/main/java/org/openremote/manager/server/event/EventService.javaindex 59c13d2f8..07072ff3c 100644--- a/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java@@ -185,11 +185,6 @@ public class EventService implements ContainerService {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) {diff --git a/manager/server/src/main/java/org/openremote/manager/server/i18n/I18NService.java b/manager/server/src/main/java/org/openremote/manager/server/i18n/I18NService.javaindex e143abbb7..7f2252eef 100644--- a/manager/server/src/main/java/org/openremote/manager/server/i18n/I18NService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/i18n/I18NService.java@@ -22,11 +22,6 @@ public class I18NService implements ContainerService {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {diff --git a/manager/server/src/main/java/org/openremote/manager/server/map/MapService.java b/manager/server/src/main/java/org/openremote/manager/server/map/MapService.javaindex 74f63ee8d..ac4afaa7a 100644--- a/manager/server/src/main/java/org/openremote/manager/server/map/MapService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/map/MapService.java@@ -85,11 +85,6 @@ public class MapService implements ContainerService {connection = DriverManager.getConnection("jdbc:sqlite:" + mapTilesPath.toAbsolutePath());}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {LOG.info("Stopping map service...");diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.javaindex e454bc942..350b45e80 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java@@ -70,11 +70,6 @@ public class NotificationService implements ContainerService {public void start(Container container) throws Exception {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {}diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.javaindex 75fa0c5fb..20301c9b3 100644--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java@@ -55,7 +55,6 @@ import org.openremote.manager.shared.rules.GlobalRuleset;import org.openremote.manager.shared.rules.Ruleset;import org.openremote.manager.shared.rules.TenantRuleset;import org.openremote.model.AttributeEvent;-import org.openremote.model.Consumer;import org.openremote.model.asset.AbstractAssetUpdate;import org.openremote.model.asset.AssetEvent;import org.openremote.model.asset.AssetQuery;@@ -69,6 +68,7 @@ import java.util.concurrent.Executors;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;+import java.util.function.Consumer;import java.util.logging.Level;import java.util.logging.Logger;diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.javaindex 91159d6eb..8e72270cc 100644--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java@@ -27,7 +27,6 @@ import org.openremote.container.ContainerService;import org.openremote.container.message.MessageBrokerSetupService;import org.openremote.container.persistence.PersistenceEvent;import org.openremote.container.persistence.PersistenceService;-import org.openremote.model.Pair;import org.openremote.manager.server.asset.AssetProcessingService;import org.openremote.manager.server.asset.AssetStorageService;import org.openremote.manager.server.asset.ServerAsset;@@ -39,9 +38,8 @@ import org.openremote.manager.shared.rules.Ruleset;import org.openremote.manager.shared.rules.TenantRuleset;import org.openremote.manager.shared.security.Tenant;import org.openremote.model.AbstractValueTimestampHolder;+import org.openremote.model.Pair;import org.openremote.model.asset.*;-import org.openremote.model.asset.AssetEvent;-import org.openremote.model.util.AttributeUtil;import org.openremote.model.util.JsonUtil;import java.util.*;@@ -49,10 +47,12 @@ import java.util.function.BiFunction;import java.util.function.Consumer;import java.util.logging.Logger;import java.util.stream.Collectors;+import java.util.stream.Stream;import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;import static org.openremote.container.util.MapAccess.getString;import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;+import static org.openremote.model.asset.AssetAttribute.getAssetAttributesFromJson;/*** Responsible for creating Drools knowledge sessions for the rulesets@@ -60,9 +60,9 @@ import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceE* <p>* Each message is processed in the following order:* <ol>- * <li>Global Rulesets</li>- * <li>Tenant Rulesets</li>- * <li>Asset Rulesets (in hierarchical order from oldest ancestor down - ordering of+ * <li>Global Rulesets</li>+ * <li>Tenant Rulesets</li>+ * <li>Asset Rulesets (in hierarchical order from oldest ancestor down - ordering of* asset rulesets with same parent asset are not guaranteed also processing order of rulesets* with the same scope is not guaranteed)</li>* </ol>@@ -137,11 +137,6 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons@Overridepublic void start(Container container) throws Exception {-- }-- @Override- public void allStarted(Container container) throws Exception {LOG.info("Deploying global rulesets");rulesetStorageService.findEnabledGlobalRulesets().forEach(this::deployGlobalRuleset);@@ -159,15 +154,14 @@ public class RulesService extends RouteBuilder implements ContainerService, ConsdeployAssetRulesets(rulesetStorageService.findEnabledAssetRulesets());LOG.info("Loading all assets with fact attributes to initialize state of rules engines");- List<Pair<ServerAsset, List<AssetAttribute>>> assetRuleAttributesList = findRuleStateAttributes();+ Stream<Pair<ServerAsset, Stream<AssetAttribute>>> assetRuleAttributes = findRuleStateAttributes();// Push each rule attribute as an asset update through the rule engine chain// that will ensure the insert only happens to the engines in scope- assetRuleAttributesList- .forEach(assetRuleAttributes -> {- ServerAsset asset = assetRuleAttributes.key;- List<AssetAttribute> ruleAttributes = assetRuleAttributes.value;- ruleAttributes.forEach(ruleAttribute -> {+ assetRuleAttributes+ .forEach(pair -> {+ ServerAsset asset = pair.key;+ pair.value.forEach(ruleAttribute -> {AssetState assetState = new AssetState(asset, ruleAttribute);// Set the status to completed already so rules cannot interfere with this initial insertassetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);@@ -259,15 +253,8 @@ public class RulesService extends RouteBuilder implements ContainerService, Conscase INSERT:// New asset has been created so get attributes that have RULE_STATE meta- List<AssetAttribute> addedAttributes = asset.getAttributes();- List<AssetAttribute> ruleAttributes = addedAttributes- .stream()- .filter(AssetAttribute::isRuleState)- .collect(Collectors.toList());-- if (ruleAttributes.size() == 0) {- return;- }+ List<AssetAttribute> ruleAttributes =+ asset.getAttributeStream().filter(AssetAttribute::isRuleState).collect(Collectors.toList());// Fully load the assetloadedAsset = assetStorageService.find(asset.getId(), true);@@ -289,22 +276,27 @@ public class RulesService extends RouteBuilder implements ContainerService, Consreturn;}+ // Fully load the asset+ loadedAsset = assetStorageService.find(asset.getId(), true);+ Asset finalLoadedAsset1 = loadedAsset;+// Attributes have possibly changed so need to compare old and new state to determine// which facts to retract and which to insert- List<AssetAttribute> oldAttributes = AttributeUtil.getAssetAttributesFromJson(asset.getId(), (JsonObject) persistenceEvent.getPreviousState()[attributesIndex]);- List<AssetAttribute> newAttributes = AttributeUtil.getAssetAttributesFromJson(asset.getId(), (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]);-- List<AssetAttribute> oldFactAttributes = oldAttributes.stream()- .filter(AssetAttribute::isRuleState)+ List<AssetAttribute> oldFactAttributes =+ getAssetAttributesFromJson(asset.getId()).apply(+ (JsonObject) persistenceEvent.getPreviousState()[attributesIndex]+ ).filter(AssetAttribute::isRuleState).collect(Collectors.toList());- List<AssetAttribute> newFactAttributes = newAttributes.stream()- .filter(AssetAttribute::isRuleState)+ List<AssetAttribute> newFactAttributes =+ getAssetAttributesFromJson(asset.getId()).apply(+ (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]+ ).filter(AssetAttribute::isRuleState).collect(Collectors.toList());// Compare attributes by JSON value// Retract facts for attributes that are in oldFactAttributes but not in newFactAttributes- List<AssetAttribute> processAttributes = oldFactAttributes+ Stream<AssetAttribute> processAttributes = oldFactAttributes.stream().filter(oldFactAttribute -> newFactAttributes.stream()@@ -313,19 +305,14 @@ public class RulesService extends RouteBuilder implements ContainerService, ConsnewFactAttribute.getJsonObject(),Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)))- )- .collect(Collectors.toList());+ );- if (processAttributes.size() > 0) {- // Fully load the asset- loadedAsset = assetStorageService.find(asset.getId(), true);- Asset finalLoadedAsset1 = loadedAsset;- processAttributes.forEach(obsoleteFactAttribute -> {- AssetState update = buildAssetState.apply(finalLoadedAsset1, obsoleteFactAttribute);- LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + update);- retractAssetState(update);- });- }++ processAttributes.forEach(obsoleteFactAttribute -> {+ AssetState update = buildAssetState.apply(finalLoadedAsset1, obsoleteFactAttribute);+ LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + update);+ retractAssetState(update);+ });// Insert facts for attributes that are in newFactAttributes but not in oldFactAttributesprocessAttributes = newFactAttributes@@ -339,29 +326,21 @@ public class RulesService extends RouteBuilder implements ContainerService, ConsCollections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)))- )- .collect(Collectors.toList());+ );- if (processAttributes.size() > 0) {- if (loadedAsset == null) {- // Fully load the asset- loadedAsset = assetStorageService.find(asset.getId(), true);- }+ processAttributes.forEach(newFactAttribute -> {+ AssetState assetState = buildAssetState.apply(finalLoadedAsset1, newFactAttribute);+ // Set the status to completed already so rules cannot interfere with this initial insert+ assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);+ LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);+ updateAssetState(assetState, true);+ });- Asset finalLoadedAsset2 = loadedAsset;- processAttributes.forEach(newFactAttribute -> {- AssetState assetState = buildAssetState.apply(finalLoadedAsset2, newFactAttribute);- // Set the status to completed already so rules cannot interfere with this initial insert- assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);- LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);- updateAssetState(assetState, true);- });- }break;+case DELETE:// Retract any facts that were associated with this asset- List<AssetAttribute> removedAttributes = asset.getAttributes();- removedAttributes.stream()+ asset.getAttributeStream().filter(AssetAttribute::isRuleState).forEach(attribute -> {// We can't load the asset again (it was deleted), so don't use buildAssetState() and@@ -658,7 +637,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Consreturn rulesDeployments;}- protected List<Pair<ServerAsset, List<AssetAttribute>>> findRuleStateAttributes() {+ protected Stream<Pair<ServerAsset, Stream<AssetAttribute>>> findRuleStateAttributes() {List<ServerAsset> assets = assetStorageService.findAll(new AssetQuery().select(new AssetQuery.Select(true))@@ -668,13 +647,10 @@ public class RulesService extends RouteBuilder implements ContainerService, Consnew AssetQuery.BooleanPredicate(true))));- return assets.stream().map((ServerAsset asset) -> {- List<AssetAttribute> attributes = asset.getAttributes();- List<AssetAttribute> ruleAttributes = attributes.stream()- .filter(AssetAttribute::isRuleState).collect(Collectors.toList());- return new Pair<>(asset, ruleAttributes);-- }).collect(Collectors.toList());+ return assets.stream()+ .map((ServerAsset asset) ->+ new Pair<>(asset, asset.getAttributeStream().filter(AssetAttribute::isRuleState))+ );}@Overridediff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesetStorageService.javaindex 850036a44..caf6e72dd 100644--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesetStorageService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesetStorageService.java@@ -55,11 +55,6 @@ public class RulesetStorageService implements ContainerService {public void start(Container container) throws Exception {}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) throws Exception {diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/RuntimeResolverService.java b/manager/server/src/main/java/org/openremote/manager/server/setup/RuntimeResolverService.javadeleted file mode 100644index c6fd27344..000000000--- a/manager/server/src/main/java/org/openremote/manager/server/setup/RuntimeResolverService.java+++ /dev/null@@ -1,104 +0,0 @@-/*- * 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.server.setup;--import org.openremote.agent3.protocol.Protocol;-import org.openremote.container.Container;-import org.openremote.container.ContainerService;-import org.openremote.model.asset.AttributeWrapperFilter;--import java.util.*;-import java.util.logging.Logger;-import java.util.stream.Collectors;--/**- * This is for resolving objects that are loaded at startup- * e.g. protocols and attribute wrappers. It uses the standard- * Java {@link ServiceLoader} to load the list of types defined- * here.- */-public class RuntimeResolverService implements ContainerService {- private static final Logger LOG = Logger.getLogger(RuntimeResolverService.class.getName());- protected static final List<Class> types;- protected static final Map<Class, Object> instances = new HashMap<>();-- static {- types = Arrays.asList(- Protocol.class,- AttributeWrapperFilter.class- );- }-- @Override- public void init(Container container) throws Exception {- // Load each type- for (Class type : types) {- ServiceLoader- .load(type)- .forEach(instance -> {- instances.put(instance.getClass(), instance);- });- }-- for (Object instance : instances.values()) {- // if it is a Container Service initialise it and pass it to the- // container; the container will then call start- if (instance instanceof ContainerService) {- ContainerService service = (ContainerService)instance;- container.addService(service);- LOG.fine("Initializing service: " + service);- service.init(container);- }- }- }-- @SuppressWarnings("unchecked")- @Override- public void start(Container container) throws Exception {- }-- @Override- public void allStarted(Container container) throws Exception {-- }-- @Override- public void stop(Container container) throws Exception {- }-- @SuppressWarnings("unchecked")- public <T> T resolve(Class<T> clazz) {- synchronized (instances) {- return (T)instances.get(clazz);- }- }-- public <T> List<T> resolveAll(Class<T> clazz) {- synchronized (instances) {- return instances- .values()- .stream()- .filter(instance -> clazz.isAssignableFrom(instance.getClass()))- .map(instance -> (T)instance)- .collect(Collectors.toList());-- }- }-}diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/SetupService.java b/manager/server/src/main/java/org/openremote/manager/server/setup/SetupService.javaindex eb29a0310..35b0f9690 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/SetupService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/SetupService.java@@ -90,11 +90,6 @@ public class SetupService implements ContainerService {}}- @Override- public void allStarted(Container container) throws Exception {-- }-@Overridepublic void stop(Container container) {}diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.javaindex 48d720734..d2fd60cd6 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java@@ -38,17 +38,17 @@ import org.openremote.model.asset.AssetType;import org.openremote.model.asset.agent.ProtocolConfiguration;import org.openremote.model.units.AttributeUnits;import org.openremote.model.units.ColorRGB;-import org.openremote.model.util.AttributeUtil;import java.time.LocalDateTime;import java.time.ZoneId;import java.time.ZonedDateTime;-import java.util.Arrays;import java.util.Collections;import java.util.List;+import java.util.stream.Stream;import static org.openremote.model.AttributeType.*;+import static org.openremote.model.asset.AssetAttribute.findAssetAttribute;import static org.openremote.model.asset.AssetMeta.*;import static org.openremote.model.asset.AssetType.*;@@ -110,7 +110,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCountry")))));- smartOffice.setAttributes(smartOfficeAttributes);+ smartOffice.setAttributeList(smartOfficeAttributes);smartOffice = assetStorageService.merge(smartOffice);smartOfficeId = smartOffice.getId();@@ -133,8 +133,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {agent.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));agent.setType(AssetType.AGENT);List<AssetAttribute> agentAttributes = Collections.singletonList(- new ProtocolConfiguration(agentProtocolConfigName, SimulatorProtocol.PROTOCOL_NAME)- .getAttribute()+ ProtocolConfiguration.initProtocolConfiguration(SimulatorProtocol.PROTOCOL_NAME)+ .apply(new AssetAttribute(agentProtocolConfigName)).setMeta(new Meta().add(new MetaItem(SimulatorProtocol.CONFIG_MODE,@@ -146,7 +146,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Json.create(500)))));- agent.setAttributes(agentAttributes);+ agent.setAttributeList(agentAttributes);agent = assetStorageService.merge(agent);agentId = agent.getId();@@ -154,7 +154,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {thing.setName("Demo Thing");thing.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));thing.setType(AssetType.THING);- List<AssetAttribute> thingAttributes = Arrays.asList(+ Stream<AssetAttribute> thingAttributes = Stream.<AssetAttribute>builder().add(new AssetAttribute("light1Toggle", BOOLEAN, Json.create(true)).setMeta(new Meta().add(new MetaItem(@@ -168,7 +168,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.add(new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(SwitchSimulatorElement.ELEMENT_NAME)))- ),+ )+ ).add(new AssetAttribute("light1Dimmer", INTEGER) // No initial value!.setMeta(new Meta().add(new MetaItem(@@ -193,7 +194,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.add(new MetaItem(SimulatorProtocol.CONFIG_MODE, Json.create(true)))- ),+ )+ ).add(new AssetAttribute("light1Color", INTEGER_ARRAY, new ColorRGB(88, 123, 88).asJsonValue()).setMeta(new Meta().add(new MetaItem(@@ -211,7 +213,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.add(new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(ColorSimulatorElement.ELEMENT_NAME)))- ),+ )+ ).add(new AssetAttribute("light1PowerConsumption", DECIMAL, Json.create(12.345)).setMeta(new Meta().add(new MetaItem(@@ -238,19 +241,20 @@ public class ManagerDemoSetup extends AbstractManagerSetup {SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(DecimalSimulatorElement.ELEMENT_NAME))).add(new MetaItem(- AssetMeta.STORE_DATA_POINTS.getName(), Json.create(true)+ AssetMeta.STORE_DATA_POINTS.getUrn(), Json.create(true))))- );- thing.setAttributes(thingAttributes);+ ).build();++ thing.setAttributeStream(thingAttributes);thing = assetStorageService.merge(thing);thingId = thing.getId();// Some sample datapointsthing = assetStorageService.find(thingId, true);- thingAttributes = thing.getAttributes();ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());- AssetAttribute light1PowerConsumptionAttribute =AttributeUtil.getAttributeByName(thingAttributes, "light1PowerConsumption");++ AssetAttribute light1PowerConsumptionAttribute = findAssetAttribute("light1PowerConsumption").apply(thing);assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute));@@ -330,7 +334,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCountry")))));- smartHome.setAttributes(smartHomeAttributes);+ smartHome.setAttributeList(smartHomeAttributes);smartHome = assetStorageService.merge(smartHome);smartHomeId = smartHome.getId();@@ -362,7 +366,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)));- apartment1.setAttributes(apartment1Attributes);+ apartment1.setAttributeList(apartment1Attributes);apartment1 = assetStorageService.merge(apartment1);apartment1Id = apartment1.getId();@@ -410,7 +414,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)));- apartment1Livingroom.setAttributes(apartment1LivingroomAttributes);+ apartment1Livingroom.setAttributeList(apartment1LivingroomAttributes);apartment1Livingroom = assetStorageService.merge(apartment1Livingroom);apartment1LivingroomId = apartment1Livingroom.getId();@@ -469,7 +473,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {));- apartment1LivingroomThermostat.setAttributes(apartment1LivingroomThermostatAttributes);+ apartment1LivingroomThermostat.setAttributeList(apartment1LivingroomThermostatAttributes);apartment1LivingroomThermostat = assetStorageService.merge(apartment1LivingroomThermostat);apartment1LivingroomThermostatId = apartment1LivingroomThermostat.getId();@@ -489,7 +493,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)));- apartment2.setAttributes(apartment2Attributes);+ apartment2.setAttributeList(apartment2Attributes);apartment2 = assetStorageService.merge(apartment2);apartment2Id = apartment2.getId();@@ -529,7 +533,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)));- apartment2Livingroom.setAttributes(apartment2LivingroomAttributes);+ apartment2Livingroom.setAttributeList(apartment2LivingroomAttributes);apartment2Livingroom = assetStorageService.merge(apartment2Livingroom);apartment2LivingroomId = apartment2Livingroom.getId();@@ -549,7 +553,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)));- apartment3.setAttributes(apartment3Attributes);+ apartment3.setAttributeList(apartment3Attributes);apartment3 = assetStorageService.merge(apartment3);apartment3Id = apartment3.getId();@@ -589,7 +593,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)));- apartment3Livingroom.setAttributes(apartment3LivingroomAttributes);+ apartment3Livingroom.setAttributeList(apartment3LivingroomAttributes);apartment3Livingroom = assetStorageService.merge(apartment3Livingroom);apartment3LivingroomId = apartment3Livingroom.getId();diff --git a/manager/test/src/main/groovy/org/openremote/test/ClientSecurityService.java b/manager/test/src/main/groovy/org/openremote/test/ClientSecurityService.javaindex ab928b6a9..0ce6edf25 100644--- a/manager/test/src/main/groovy/org/openremote/test/ClientSecurityService.java+++ b/manager/test/src/main/groovy/org/openremote/test/ClientSecurityService.java@@ -28,8 +28,8 @@ import org.openremote.manager.client.interop.keycloak.LoginOptions;import org.openremote.manager.client.interop.keycloak.LogoutOptions;import org.openremote.manager.client.service.SecurityService;import org.openremote.model.Constants;-import org.openremote.model.Consumer;-import org.openremote.model.Runnable;++import java.util.function.Consumer;/*** Does the same job as keycloak.js implementation.diff --git a/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy b/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovyindex 1c511546c..aba588e43 100644--- a/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy+++ b/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy@@ -1,7 +1,9 @@package org.openremote.test+import com.google.common.collect.Listsimport org.drools.core.time.impl.PseudoClockSchedulerimport org.kie.api.runtime.conf.ClockTypeOption+import org.openremote.agent3.protocol.Protocolimport org.openremote.container.Containerimport org.openremote.container.ContainerServiceimport org.openremote.container.message.MessageBrokerService@@ -20,7 +22,6 @@ import org.openremote.manager.server.rules.RulesDeploymentimport org.openremote.manager.server.rules.RulesServiceimport org.openremote.manager.server.rules.RulesetStorageServiceimport org.openremote.manager.server.security.ManagerIdentityService-import org.openremote.manager.server.setup.RuntimeResolverServiceimport org.openremote.manager.server.setup.SetupServiceimport org.openremote.manager.server.web.ManagerWebService@@ -30,7 +31,6 @@ trait ManagerContainerTrait extends ContainerTrait {static Iterable<ContainerService> defaultServices(Iterable<ContainerService> additionalServices) {[- new RuntimeResolverService(),new I18NService(),new PersistenceService(),new MessageBrokerSetupService(),@@ -42,6 +42,7 @@ trait ManagerContainerTrait extends ContainerTrait {new AssetStorageService(),new AssetDatapointService(),new AssetProcessingService(),+ *Lists.newArrayList(ServiceLoader.load(Protocol.class)),new AgentService(),new MapService(),new NotificationService(),diff --git a/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovyindex 329bdb25c..963517daf 100644--- a/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy@@ -10,11 +10,13 @@ import org.openremote.manager.server.setup.SetupServiceimport org.openremote.manager.server.setup.builtin.ManagerDemoSetupimport org.openremote.model.AttributeEventimport org.openremote.model.units.ColorRGB-import org.openremote.model.util.AttributeUtil+import org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions+import static org.openremote.model.Attribute.*+class AgentDeploymentTest extends Specification implements ManagerContainerTrait {def "Check agent and thing deployment"() {@@ -50,9 +52,10 @@ class AgentDeploymentTest extends Specification implements ManagerContainerTraitconditions.eventually {assert simulatorProtocol.getState(managerDemoSetup.thingId, "light1Dimmer").asNumber() == 66def thing = assetStorageService.find(managerDemoSetup.thingId, true)- def attributes = thing.getAttributes()- assert AttributeUtil.getAttributeByName(attributes, "light1Dimmer").getValue().getType() == JsonType.NUMBER- assert AttributeUtil.getAttributeByName(attributes, "light1Dimmer").getValueAsInteger() == 66+ def attributes = thing.getAttributeStream()+ def attribute = findAttribute("light1Dimmer").apply(attributes)+ assert attribute.getValue().getType() == JsonType.NUMBER+ assert attribute.getValueAsInteger() == 66}when: "a simulated sensor changes its value"@@ -62,9 +65,10 @@ class AgentDeploymentTest extends Specification implements ManagerContainerTraitthen: "the thing attribute value should be updated"conditions.eventually {def thing = assetStorageService.find(managerDemoSetup.thingId, true)- def attributes = thing.getAttributes()- assert AttributeUtil.getAttributeByName(attributes, "light1Dimmer").getValue().getType() == JsonType.NUMBER- assert AttributeUtil.getAttributeByName(attributes, "light1Dimmer").getValueAsInteger() == 77+ def attributes = thing.getAttributeStream()+ def attribute = findAttribute("light1Dimmer").apply(attributes)+ assert attribute.getValue().getType() == JsonType.NUMBER+ assert attribute.getValueAsInteger() == 77}cleanup: "the server should be stopped"diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovyindex 9eae1aa97..9ddcca4c6 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy@@ -7,11 +7,12 @@ import org.openremote.manager.server.datapoint.AssetDatapointServiceimport org.openremote.manager.server.setup.SetupServiceimport org.openremote.manager.server.setup.builtin.ManagerDemoSetupimport org.openremote.model.AttributeRef-import org.openremote.model.util.AttributeUtilimport org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions+import static org.openremote.model.asset.AssetAttribute.findAssetAttribute+class AssetDatapointTest extends Specification implements ManagerContainerTrait {def "Receive sensor values and store asset datapoints"() {@@ -44,8 +45,7 @@ class AssetDatapointTest extends Specification implements ManagerContainerTraitthen: "the thing attribute value should be updated and the datapoints stored"conditions.eventually {def thing = assetStorageService.find(managerDemoSetup.thingId, true)- def attributes = thing.getAttributes()- assert AttributeUtil.getAttributeByName(attributes, "light1PowerConsumption").getValueAsDecimal() == 15.5d+ assert findAssetAttribute("light1PowerConsumption").apply(thing).getValueAsDecimal() == 15.5ddef datapoints = assetDatapointService.getDatapoints(new AttributeRef(managerDemoSetup.thingId, "light1PowerConsumption"))datapoints.size() > 3datapoints.get(0).value.asNumber() == 13.3ddiff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovyindex 89170ebaf..7b5010b7f 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy@@ -10,7 +10,7 @@ import org.openremote.model.AttributeTypeimport org.openremote.model.asset.Assetimport org.openremote.model.asset.AssetAttributeimport org.openremote.model.asset.AssetType-import org.openremote.model.util.AttributeUtil+import org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions@@ -21,6 +21,7 @@ import static org.openremote.container.util.MapAccess.getStringimport static org.openremote.manager.server.setup.AbstractKeycloakSetup.SETUP_KEYCLOAK_ADMIN_PASSWORDimport static org.openremote.manager.server.setup.AbstractKeycloakSetup.SETUP_KEYCLOAK_ADMIN_PASSWORD_DEFAULTimport static org.openremote.model.Constants.*+import static org.openremote.model.asset.AssetAttribute.findAssetAttributeclass AssetIntegrityTest extends Specification implements ManagerContainerTrait {@@ -56,23 +57,26 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTraittestAsset.realmId == keycloakDemoSetup.masterTenant.idtestAsset.parentId == null- when: "an asset is created with an illegal attribute name"- def attributes = testAsset.getAttributes()+ when: "an asset is stored with an illegal attribute name"+ testAsset = assetResource.get(null, testAsset.getId())+ def attributes = testAsset.getAttributeList()attributes.add(new AssetAttribute(testAsset.id, "illegal- Attribute:name&&&", AttributeType.STRING))- testAsset.setAttributes(attributes)+ testAsset.setAttributeList(attributes)+ assetResource.update(null, testAsset.getId(), testAsset)then: "the request should be bad"- thrown(IllegalArgumentException)+ WebApplicationException ex = thrown()+ ex.response.status == 400when: "an asset is stored with a non-empty attribute value"testAsset = assetResource.get(null, testAsset.getId())- testAsset.setAttributes([new AssetAttribute("foo", AttributeType.STRING, Json.create("bar"))])+ testAsset.setAttributeList([new AssetAttribute("foo", AttributeType.STRING, Json.create("bar"))])assetResource.update(null, testAsset.id, testAsset)testAsset = assetResource.get(null, testAsset.getId())then: "the attribute should exist"- AttributeUtil.getAttributeByName(testAsset.getAttributes(), "foo") != null- AttributeUtil.getAttributeByName(testAsset.getAttributes(), "foo").getValueAsString() == "bar"+ findAssetAttribute("foo").apply(testAsset) != null+ findAssetAttribute("foo").apply(testAsset).getValueAsString() == "bar"when: "an asset attribute value is written directly"assetResource.writeAttributeValue(null, testAsset.getId(), "foo", "\"bar2\"")@@ -80,7 +84,7 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTraitthen: "the attribute value should match"new PollingConditions(delay: 1, timeout: 5).eventually {def asset = assetResource.get(null, testAsset.getId())- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "foo").getValueAsString() == "bar2"+ assert findAssetAttribute("foo").apply(asset).getValueAsString() == "bar2"}when: "an asset attribute value null is written directly"@@ -89,7 +93,7 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTraitthen: "the attribute value should match"new PollingConditions(delay: 1, timeout: 5).eventually {def asset = assetResource.get(null, testAsset.getId())- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "foo").hasValue() == false+ assert findAssetAttribute("foo").apply(asset).hasValue() == false}when: "an asset is updated with a different type"@@ -106,7 +110,7 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTraitassetResource.update(null, testAsset.id, testAsset)then: "the request should be bad"- WebApplicationException ex = thrown()+ ex = thrown()ex.response.status == 400when: "an asset is updated with a non-existent parent"diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovyindex 8b1ee48b9..ae6f06b61 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy@@ -11,7 +11,7 @@ import org.openremote.model.Metaimport org.openremote.model.asset.Assetimport org.openremote.model.asset.AssetMetaimport org.openremote.model.asset.AssetType-import org.openremote.model.util.AttributeUtil+import org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions@@ -22,6 +22,7 @@ import static org.openremote.container.util.MapAccess.getStringimport static org.openremote.manager.server.setup.AbstractKeycloakSetup.SETUP_KEYCLOAK_ADMIN_PASSWORDimport static org.openremote.manager.server.setup.AbstractKeycloakSetup.SETUP_KEYCLOAK_ADMIN_PASSWORD_DEFAULTimport static org.openremote.model.Constants.*+import static org.openremote.model.asset.AssetAttribute.findAssetAttributeclass AssetPermissionsTest extends Specification implements ManagerContainerTrait {@@ -167,7 +168,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraidef assetconditions.eventually {asset = assetResource.get(null, managerDemoSetup.smartOfficeId)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "geoStreet").getValue().toJson() == Json.create("Teststreet 123").toJson()+ assert findAssetAttribute("geoStreet").apply(asset).getValue().toJson() == Json.create("Teststreet 123").toJson()}when: "an non-existent attribute is written in the authenticated realm"@@ -190,7 +191,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraithen: "result should match"conditions.eventually {asset = assetResource.get(null, managerDemoSetup.smartHomeId)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "geoStreet").getValue().toJson() == Json.create("Teststreet 456").toJson()+ assert findAssetAttribute("geoStreet").apply(asset).getValue().toJson() == Json.create("Teststreet 456").toJson()}cleanup: "the server should be stopped"@@ -228,7 +229,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiassets[0].id == managerDemoSetup.smartOfficeId// Assets should not be completely loadedassets[0].path == null- assets[0].attributes.size() == 0+ assets[0].attributeList.size() == 0when: "the root assets of the authenticated realm are retrieved"assets = assetResource.getRoot(null, keycloakDemoSetup.masterTenant.id)@@ -339,7 +340,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraidef assetconditions.eventually {asset = assetResource.get(null, managerDemoSetup.smartOfficeId)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "geoStreet").getValue().toJson() == Json.create("Teststreet 123").toJson()+ assert findAssetAttribute("geoStreet").apply(asset).getValue().toJson() == Json.create("Teststreet 123").toJson()}when: "an asset attribute is written in a foreign realm"@@ -382,7 +383,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiassets[0].id == managerDemoSetup.smartHomeId// Assets should not be completely loadedassets[0].path == null- assets[0].attributes.size() == 0+ assets[0].attributeList.size() == 0when: "the root assets of a foreign realm are retrieved"assets = assetResource.getRoot(null, keycloakDemoSetup.masterTenant.id)@@ -521,7 +522,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiapartment1.coordinates[0] == 5.470945dapartment1.coordinates[1] == 51.438dapartment1.path == null- apartment1.attributes.size() == 0+ apartment1.attributeList.size() == 0Asset apartment1Livingroom = assets[1]apartment1Livingroom.id == managerDemoSetup.apartment1LivingroomId@@ -584,12 +585,12 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraithen: "the protected asset details should be available"apartment1LivingroomThermostat.id == managerDemoSetup.apartment1LivingroomThermostatIdapartment1LivingroomThermostat.name == "Livingroom Thermostat"- def protectedAttributes = apartment1LivingroomThermostat.getAttributes()+ def protectedAttributes = apartment1LivingroomThermostat.getAttributeList()protectedAttributes.size() == 2- assert AttributeUtil.getAttributeByName(protectedAttributes, "currentTemperature") != null- AttributeUtil.getAttributeByName(protectedAttributes, "currentTemperature").getType() == AttributeType.DECIMAL- AttributeUtil.getAttributeByName(protectedAttributes, "currentTemperature").getValueAsDecimal() == null- Meta protectedMeta = AttributeUtil.getAttributeByName(protectedAttributes, "currentTemperature").getMeta()+ def currentTemperature = findAssetAttribute("currentTemperature").apply(apartment1LivingroomThermostat)+ currentTemperature.getType() == AttributeType.DECIMAL+ currentTemperature.getValueAsDecimal() == null+ Meta protectedMeta = currentTemperature.getMeta()protectedMeta.all().size() == 3protectedMeta.first(AssetMeta.LABEL).getValueAsString() == "Current Temperature"protectedMeta.first(AssetMeta.READ_ONLY).getValueAsBoolean()@@ -665,7 +666,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraithen: "result should match"conditions.eventually {def asset = assetResource.get(null, managerDemoSetup.apartment1LivingroomThermostatId)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "comfortTemperature").getValue().toJson() == Json.create(22.123).toJson()+ assert findAssetAttribute("comfortTemperature").apply(asset).getValue().toJson() == Json.create(22.123).toJson()}when: "an attribute is written on a non-existent user asset"diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovyindex fda859b6c..2e74ad656 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy@@ -53,18 +53,18 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait}@Override- protected void onAttributeAdded(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeAdded(AssetAttribute attribute, AssetAttribute protocolConfiguration) {protocolDeployed = trueLOG.info("Mock Protocol: onAttributeAdded")}@Override- protected void onAttributeUpdated(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeUpdated(AssetAttribute attribute, AssetAttribute protocolConfiguration) {LOG.info("Mock Protocol: onAttributeUpdated")}@Override- protected void onAttributeRemoved(AssetAttribute attribute, ProtocolConfiguration protocolConfiguration) {+ protected void onAttributeRemoved(AssetAttribute attribute, AssetAttribute protocolConfiguration) {LOG.info("Mock Protocol: onAttributeRemoved")}@@ -123,8 +123,8 @@ class AssetProcessingTest extends Specification implements ManagerContainerTraitdef mockAgent = new ServerAsset()mockAgent.setName("Mock Agent")mockAgent.setType(AssetType.AGENT)- def mockProtocolConfig = new ProtocolConfiguration("mock123", mockProtocolName)- mockAgent.setAttributes(Collections.singletonList(mockProtocolConfig.getAttribute()))+ def mockProtocolConfig = ProtocolConfiguration.initProtocolConfiguration(mockProtocolName).apply(new AssetAttribute("mock123"))+ mockAgent.setAttributeList(Collections.singletonList(mockProtocolConfig))mockAgent.setRealmId(keycloakDemoSetup.masterTenant.id)mockAgent = assetStorageService.merge(mockAgent)//endregion@@ -169,7 +169,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait))]- mockThing.setAttributes(mockThingAttributes)+ mockThing.setAttributeList(mockThingAttributes)mockThing = assetStorageService.merge(mockThing)//endregiondiff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovyindex 999187c00..dc73bc8eb 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy@@ -9,7 +9,7 @@ import org.openremote.manager.server.setup.builtin.ManagerDemoSetupimport org.openremote.model.asset.AssetMetaimport org.openremote.model.asset.AssetQueryimport org.openremote.model.asset.AssetType-import org.openremote.model.util.AttributeUtil+import org.openremote.test.ManagerContainerTraitimport spock.lang.Specification@@ -20,6 +20,8 @@ import static org.openremote.model.asset.AssetQuery.*import static org.openremote.model.asset.AssetQuery.OrderBy.Property.NAMEimport static org.openremote.model.asset.AssetType.THING+import static org.openremote.model.asset.AssetAttribute.*+class AssetQueryTest extends Specification implements ManagerContainerTrait {def "Query assets"() {@@ -55,7 +57,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.path.length == 2asset.path[0] == managerDemoSetup.apartment1Idasset.path[1] == managerDemoSetup.smartHomeId- asset.attributes.size() > 0+ asset.attributeList.size() > 0when: "a query is executed"asset = assetStorageService.find(@@ -77,7 +79,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.tenantDisplayName == keycloakDemoSetup.masterTenant.displayNameasset.coordinates.length == 2asset.path == null- asset.attributes.size() == 0+ asset.attributeList.size() == 0when: "a query is executed"asset = assetStorageService.find(@@ -101,7 +103,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {asset.coordinates.length == 2asset.path.length == 1asset.path[0] == managerDemoSetup.smartOfficeId- AttributeUtil.getAttributeByName(asset.getAttributes(), "geoStreet").valueAsString == "Torenallee 20"+ findAssetAttribute("geoStreet").apply(asset).valueAsString == "Torenallee 20"when: "a query is executed"def assets = assetStorageService.findAll(@@ -125,7 +127,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).tenantDisplayName == keycloakDemoSetup.masterTenant.displayNameassets.get(0).coordinates.length == 2assets.get(0).path == null- assets.get(0).attributes.size() == 0+ assets.get(0).attributeList.size() == 0when: "a query is executed"assets = assetStorageService.findAll(@@ -151,7 +153,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).coordinates.length == 2assets.get(0).path.length == 1assets.get(0).path[0] == managerDemoSetup.smartOfficeId- AttributeUtil.getAttributeByName(assets.get(0).getAttributes(), "geoStreet").valueAsString == "Torenallee 20"+ findAssetAttribute("geoStreet").apply(assets.get(0)).valueAsString == "Torenallee 20"when: "a query is executed"assets = assetStorageService.findAll(@@ -174,7 +176,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).tenantDisplayName == keycloakDemoSetup.customerATenant.displayNameassets.get(0).coordinates.length == 2assets.get(0).path == null- assets.get(0).attributes.size() == 0+ assets.get(0).attributeList.size() == 0assets.get(1).id == managerDemoSetup.apartment2Idassets.get(2).id == managerDemoSetup.apartment3Id@@ -248,11 +250,11 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {assets.get(0).id == managerDemoSetup.apartment1Idassets.get(1).id == managerDemoSetup.apartment1LivingroomIdassets.get(2).id == managerDemoSetup.apartment1LivingroomThermostatId- assets.get(2).getAttributes().size() == 2- AttributeUtil.getAttributeByName(assets.get(2).getAttributes(), "currentTemperature").valueAsDecimal == null- AttributeUtil.getAttributeByName(assets.get(2).getAttributes(), "currentTemperature").meta.size() == 3- AttributeUtil.getAttributeByName(assets.get(2).getAttributes(), "comfortTemperature").valueAsDecimal == null- AttributeUtil.getAttributeByName(assets.get(2).getAttributes(), "comfortTemperature").meta.size() == 2+ assets.get(2).getAttributeList().size() == 2+ findAssetAttribute("currentTemperature").apply(assets.get(2)).valueAsDecimal == null+ findAssetAttribute("currentTemperature").apply(assets.get(2)).meta.size() == 3+ findAssetAttribute("comfortTemperature").apply(assets.get(2)).valueAsDecimal == null+ findAssetAttribute("comfortTemperature").apply(assets.get(2)).meta.size() == 2assets.get(3).id == managerDemoSetup.apartment2Idwhen: "a query is executed"diff --git a/manager/test/src/test/groovy/org/openremote/test/map/MapActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/map/MapActivityTest.groovyindex 108cf94e9..1423e0f05 100644--- a/manager/test/src/test/groovy/org/openremote/test/map/MapActivityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/map/MapActivityTest.groovy@@ -11,8 +11,6 @@ import org.openremote.manager.client.map.MapActivityimport org.openremote.manager.client.map.MapViewimport org.openremote.manager.client.service.RequestServiceImplimport org.openremote.manager.client.service.SecurityService-import org.openremote.model.Consumer-import org.openremote.model.Runnableimport org.openremote.manager.shared.http.EntityReaderimport org.openremote.manager.shared.map.MapResourceimport org.openremote.test.ContainerTrait@@ -24,8 +22,7 @@ import static org.openremote.container.util.MapAccess.getStringimport static org.openremote.model.Constants.*;// TODO Fix this when we do Asset testing-@Ignore-class MapActivityTest extends Specification implements ContainerTrait, GwtClientTrait {+class MapActivityTest { /* extends Specification implements ContainerTrait, GwtClientTrait {def "Initialize map"() {given: "The fake client environment"@@ -99,4 +96,5 @@ class MapActivityTest extends Specification implements ContainerTrait, GwtClientcleanup: "the server should be stopped"stopContainer(container);}+ */}diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovyindex 42427edca..c72367744 100644--- a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy@@ -8,14 +8,13 @@ import org.openremote.manager.server.rules.RulesServiceimport org.openremote.manager.server.setup.SetupServiceimport org.openremote.manager.server.setup.builtin.KeycloakDemoSetupimport org.openremote.manager.server.setup.builtin.ManagerDemoSetup-import org.openremote.manager.server.setup.builtin.RulesDemoSetupimport org.openremote.model.AttributeEvent-import org.openremote.model.util.AttributeUtilimport org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditionsimport static java.util.concurrent.TimeUnit.*+import static org.openremote.model.asset.AssetAttribute.findAssetAttributeclass ApartmentActionsTest extends Specification implements ManagerContainerTrait {@@ -28,7 +27,6 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraidef container = startContainer(defaultConfig(serverPort), defaultServices())def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)- def rulesDemoSetup = container.getService(SetupService.class).getTaskOfType(RulesDemoSetup.class)def rulesService = container.getService(RulesService.class)def assetProcessingService = container.getService(AssetProcessingService.class)def assetStorageService = container.getService(AssetStorageService.class)@@ -50,7 +48,7 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraiand: "the room lights in an apartment to be on"def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)- assert AttributeUtil.getAttributeByName(livingRoomAsset.getAttributes(), "lightSwitch").valueAsBoolean+ assert findAssetAttribute("lightSwitch").apply(livingRoomAsset).valueAsBooleanwhen: "the ALL LIGHTS OFF switch is pressed for an apartment"def apartment1AllLightsOffChange = new AttributeEvent(@@ -62,7 +60,7 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraiconditions.eventually {assert customerAEngine.knowledgeSession.factCount == 10livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)- assert !AttributeUtil.getAttributeByName(livingRoomAsset.getAttributes(), "lightSwitch").valueAsBoolean+ assert !findAssetAttribute("lightSwitch").apply(livingRoomAsset).valueAsBoolean}when: "time advanced"@@ -87,7 +85,6 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraidef container = startContainer(defaultConfig(serverPort), defaultServices())def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)- def rulesDemoSetup = container.getService(SetupService.class).getTaskOfType(RulesDemoSetup.class)def rulesService = container.getService(RulesService.class)def assetProcessingService = container.getService(AssetProcessingService.class)def assetStorageService = container.getService(AssetStorageService.class)@@ -103,11 +100,11 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraiand: "the presence latch of the room should not be set"def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)- assert !AttributeUtil.getAttributeByName(livingRoomAsset.getAttributes(), "presenceDetected").valueAsBoolean+ assert !findAssetAttribute("presenceDetected").apply(livingRoomAsset).valueAsBooleanand: "the presence latch of the other room should not be set"def otherLivingRoomAsset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)- assert !AttributeUtil.getAttributeByName(otherLivingRoomAsset.getAttributes(), "presenceDetected").valueAsBoolean+ assert !findAssetAttribute("presenceDetected").apply(otherLivingRoomAsset).valueAsBooleanand: "several presence sensor events are triggered in the room"for (i in 0..2) {@@ -138,13 +135,13 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraiand: "the presence latch of the room should be set"conditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "presenceDetected").valueAsBoolean+ assert findAssetAttribute("presenceDetected").apply(asset).valueAsBoolean}and: "the presence latch of the other room should NOT be set"conditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)- assert !AttributeUtil.getAttributeByName(asset.getAttributes(), "presenceDetected").valueAsBoolean+ assert !findAssetAttribute("presenceDetected").apply(asset).valueAsBoolean}when: "time is advanced enough to trigger event expiration"@@ -169,7 +166,6 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraidef container = startContainer(defaultConfig(serverPort), defaultServices())def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)- def rulesDemoSetup = container.getService(SetupService.class).getTaskOfType(RulesDemoSetup.class)def rulesService = container.getService(RulesService.class)def assetProcessingService = container.getService(AssetProcessingService.class)def assetStorageService = container.getService(AssetStorageService.class)@@ -197,7 +193,7 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraithen: "that value should be stored"conditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "vacationDays").valueAsInteger == 5+ assert findAssetAttribute("vacationDays").apply(asset).valueAsInteger == 5}when: "time advanced to the next day, which should trigger the cron rule"@@ -206,7 +202,7 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraithen: "the vacation days should be decremented"conditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "vacationDays").valueAsInteger == 4+ assert findAssetAttribute("vacationDays").apply(asset).valueAsInteger == 4}when: "time advanced again (to test that the rule only fires once per day)"@@ -215,7 +211,7 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraithen: "the vacation days should NOT be decremented"new PollingConditions(initialDelay: 2).eventually {def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "vacationDays").valueAsInteger == 4+ assert findAssetAttribute("vacationDays").apply(asset).valueAsInteger == 4}expect: "the remaining vacation days to be decremented with each passing day"@@ -228,7 +224,7 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTraiconditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)- assert AttributeUtil.getAttributeByName(asset.getAttributes(), "vacationDays").valueAsInteger == remainingDays+ assert findAssetAttribute("vacationDays").apply(asset).valueAsInteger == remainingDays}}diff --git a/model/src/main/java/org/openremote/model/Attribute.java b/model/src/main/java/org/openremote/model/Attribute.javaindex be90a0e46..1ca1636a2 100644--- a/model/src/main/java/org/openremote/model/Attribute.java+++ b/model/src/main/java/org/openremote/model/Attribute.java@@ -19,23 +19,34 @@*/package org.openremote.model;-import elemental.json.Json;-import elemental.json.JsonObject;-import elemental.json.JsonValue;-import org.openremote.model.util.AttributeUtil;+import com.google.gwt.regexp.shared.RegExp;+import elemental.json.*;import java.util.Collections;import java.util.List;import java.util.NoSuchElementException;+import java.util.function.Consumer;+import java.util.function.Function;import java.util.function.Predicate;+import java.util.stream.Stream;/*** Convenience overlay API for {@link JsonObject}.*/public abstract class Attribute extends AbstractValueTimestampHolder {+ /**+ * Attribute names should be very simple, as we use them in SQL path+ * expressions, etc. and must manually escape.+ */+ public static final String ATTRIBUTE_NAME_PATTERN = "^\\w+$";+ public static final RegExp ATTRIBUTE_NAME_REGEXP = RegExp.compile(ATTRIBUTE_NAME_PATTERN);+ public static final Predicate<String> ATTRIBUTE_NAME_VALIDATOR =+ name -> name != null && name.length() > 0 && ATTRIBUTE_NAME_REGEXP.test(name);+public static final String TYPE_FIELD_NAME = "type";public static final String META_FIELD_NAME = "meta";+protected String name;protected Attribute(String name) {@@ -51,11 +62,6 @@ public abstract class Attribute extends AbstractValueTimestampHolder {protected Attribute(String name, JsonObject jsonObject) {super(jsonObject);setName(name);-- // Verify jsonObject is valid- if (!isValid()) {- throw new IllegalArgumentException("Supplied JSON object is not valid for this type of attribute: " + jsonObject.toJson());- }}protected Attribute(String name, AttributeType type, JsonValue value) {@@ -75,11 +81,6 @@ public abstract class Attribute extends AbstractValueTimestampHolder {}public void setName(String name) {- if (!AttributeUtil.nameIsValid(name)) {- throw new IllegalArgumentException(- "Invalid attribute name (must match '" + AttributeUtil.ATTRIBUTE_NAME_PATTERN + "'): " + name- );- }this.name = name;}@@ -113,6 +114,10 @@ public abstract class Attribute extends AbstractValueTimestampHolder {return hasMeta() ? new Meta(jsonObject.getArray(META_FIELD_NAME)) : new Meta();}+ public Stream<MetaItem> getMetaItemStream() {+ return getMeta().stream();+ }+@SuppressWarnings("unchecked")public Attribute setMeta(Meta meta) {if (meta != null) {@@ -181,6 +186,68 @@ public abstract class Attribute extends AbstractValueTimestampHolder {@Overridepublic boolean isValid() {- return super.isValid() && AttributeUtil.nameIsValid(name) && getType() != null;+ return super.isValid() && ATTRIBUTE_NAME_VALIDATOR.test(name) && getType() != null;+ }++ public static Predicate<Attribute> isAttributeValid() {+ return Attribute::isValid;+ }++ public static Predicate<Attribute> isAttributeType(AttributeType attributeType) {+ return attribute -> attribute.getType().equals(attributeType);+ }++ public static Predicate<MetaItem> isMetaItem(String name) {+ return metaItem -> metaItem.getName().equals(name);+ }++ public static Function<Stream<? extends Attribute>, Attribute> findAttribute(String name) {+ return attributeStream -> attributeStream+ .filter(attribute -> attribute.getName().equals(name))+ .findFirst()+ .orElse(null);+ }++ public static Predicate<Stream<? extends Attribute>> containsAttributeNamed(String name) {+ return attributeStream -> findAttribute(name).apply(attributeStream) != null;+ }++ public static java.util.function.Function<Attribute, AttributeRef> getAttributeLink(String metaName) {+ return attribute -> {+ MetaItem metaItem = attribute.firstMetaItem(metaName);+ JsonArray array = metaItem != null && metaItem.getValue().getType() == JsonType.ARRAY+ ? metaItem.getValueAsArray()+ : null;+ return array != null && array.length() == 2 ? new AttributeRef(array) : null;+ };+ }++ public static void removeAttribute(List<? extends Attribute> attributes, String name) {+ attributes.removeIf(attribute -> attribute.getName().equals(name));+ }++ public static <A extends Attribute> A findAttribute(List<A> attributes, String name) {+ for (A attribute : attributes) {+ if (attribute.getName().equals(name))+ return attribute;+ }+ return null;+ }++ public static Consumer<Attribute> setAttributeLink(String metaName, AttributeRef attributeRef) {+ return attribute -> {+ if (attributeRef == null) {+ throw new IllegalArgumentException(+ "Attribute reference cannot be null for '" + metaName + "' on: " + attribute+ );+ }+ attribute.setMeta(+ attribute.getMeta().replace(metaName, new MetaItem(metaName, attributeRef.asJsonValue()))+ );+ };+ }++ public static Consumer<Attribute> removeAttributeLink(String metaName) {+ return attribute -> attribute.setMeta(attribute.getMeta().removeAll(metaName));}}diff --git a/model/src/main/java/org/openremote/model/AttributeEvent.java b/model/src/main/java/org/openremote/model/AttributeEvent.javaindex aec1f75c7..6b5cbbf4d 100644--- a/model/src/main/java/org/openremote/model/AttributeEvent.java+++ b/model/src/main/java/org/openremote/model/AttributeEvent.java@@ -51,7 +51,7 @@ public class AttributeEvent extends SharedEvent {NORTHBOUND}- static public class EntityIdFilter extends EventFilter<AttributeEvent> {+ public static class EntityIdFilter extends EventFilter<AttributeEvent> {public static final String FILTER_TYPE = "attribute-entity-id";diff --git a/model/src/main/java/org/openremote/model/Meta.java b/model/src/main/java/org/openremote/model/Meta.javaindex 1d532262c..d90566ec1 100644--- a/model/src/main/java/org/openremote/model/Meta.java+++ b/model/src/main/java/org/openremote/model/Meta.java@@ -29,6 +29,7 @@ import org.openremote.model.util.JsonUtil;import java.util.ArrayList;import java.util.List;import java.util.function.Predicate;+import java.util.stream.Stream;/*** An array of {@link MetaItem} elements.@@ -59,6 +60,10 @@ public class Meta {return get((Predicate<MetaItem>) null);}+ public Stream<MetaItem> stream() {+ return all().stream();+ }+public List<MetaItem> get(String name) {return get(item -> item.getName().equals(name)@@ -90,7 +95,7 @@ public class Meta {}public MetaItem first(AssetMeta assetMeta) {- return first(assetMeta.getName());+ return first(assetMeta.getUrn());}public MetaItem first(String name) {@@ -112,7 +117,7 @@ public class Meta {}public boolean contains(AssetMeta assetMeta) {- return contains(assetMeta.getName());+ return contains(assetMeta.getUrn());}public boolean contains(String name) {@@ -139,7 +144,7 @@ public class Meta {}public Meta removeAll(AssetMeta assetMeta) {- return removeAll(assetMeta.getName());+ return removeAll(assetMeta.getUrn());}public Meta removeAll(String name) {@@ -158,6 +163,12 @@ public class Meta {return this;}+ public Meta replace(String name, MetaItem item) {+ removeAll(name);+ add(item);+ return this;+ }+public Meta copy() {return new Meta((JsonArray) Json.parse(getJsonArray().toJson()));}diff --git a/model/src/main/java/org/openremote/model/MetaItem.java b/model/src/main/java/org/openremote/model/MetaItem.javaindex c6ace46ba..3ded7786b 100644--- a/model/src/main/java/org/openremote/model/MetaItem.java+++ b/model/src/main/java/org/openremote/model/MetaItem.java@@ -48,7 +48,7 @@ public class MetaItem extends AbstractValueHolder {}public MetaItem(AssetMeta assetMeta, JsonValue value) {- this(assetMeta.getName(), value);+ this(assetMeta.getUrn(), value);}public MetaItem(String name, JsonValue value) {diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAttributeWrapper.java b/model/src/main/java/org/openremote/model/asset/AbstractAttributeWrapper.javadeleted file mode 100644index f4f1e0cca..000000000--- a/model/src/main/java/org/openremote/model/asset/AbstractAttributeWrapper.java+++ /dev/null@@ -1,96 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.model.asset;--import org.openremote.model.AttributeRef;-import org.openremote.model.Meta;-import org.openremote.model.util.AttributeUtil;--/**- * This is a wrapper for AssetAttribute that can provide convenience- * methods for getting/setting the attribute value and/or meta items- * that should be in the dynamic part of the attribute class.- *- * It is deliberately minimal as any standard attribute manipulation- * should be done on the attribute class itself.- *- */-public abstract class AbstractAttributeWrapper<CHILD extends AbstractAttributeWrapper> {-- AssetAttribute attribute;-- /**- * Default constructor will also initialise the attribute, subclasses- * should provide both constructors for convenience and consistency.- *- */- protected AbstractAttributeWrapper(AssetAttribute attribute) {- this(attribute, true);- }-- /**- * Should optionally initialise the attribute by calling initialise method.- */- protected AbstractAttributeWrapper(AssetAttribute attribute, boolean initialise) {- this.attribute = attribute;- if (initialise) {- initialise();- }- }-- public AssetAttribute getAttribute() {- return attribute;- }-- public AttributeRef getAttributeReference() {- return attribute.getReference();- }-- public Meta getMeta() {- return attribute.getMeta();- }-- public void setMeta(Meta meta) {- attribute.setMeta(meta);- }-- /**- * Indicates whether or not the attribute is valid for this wrapper type. Should be overridden in sub classes- * where needed.- */- public boolean isValid() {- return isValid(getAttribute());- }-- /**- * Initialise this attribute with all the static data relating to- * this attribute wrapper type.- */- public abstract void initialise();-- /**- * @return a static filter for this wrapper type- */- public abstract AttributeWrapperFilter<CHILD> getFilter();-- public static boolean isValid(AssetAttribute assetAttribute) {- return AttributeUtil.nameIsValid(assetAttribute.getName()) && assetAttribute.getType() != null;- }-}diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex 59c2baa85..26299b154 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -19,8 +19,6 @@*/package org.openremote.model.asset;-import com.fasterxml.jackson.annotation.JsonIgnore;-import com.fasterxml.jackson.annotation.JsonProperty;import elemental.json.JsonObject;import org.hibernate.annotations.Formula;import org.openremote.model.IdentifiableEntity;@@ -28,7 +26,6 @@ import org.openremote.model.geo.GeoJSON;import org.openremote.model.geo.GeoJSONFeature;import org.openremote.model.geo.GeoJSONGeometry;import org.openremote.model.util.TextUtil;-import org.openremote.model.util.AttributeUtil;import javax.persistence.*;import javax.validation.constraints.NotNull;@@ -38,9 +35,14 @@ import java.math.RoundingMode;import java.util.Arrays;import java.util.Date;import java.util.List;+import java.util.stream.Collectors;+import java.util.stream.Stream;import static org.openremote.model.Constants.PERSISTENCE_JSON_OBJECT_TYPE;import static org.openremote.model.Constants.PERSISTENCE_UNIQUE_ID_GENERATOR;+import static org.openremote.model.asset.AssetAttribute.filterProtectedAssetAttribute;+import static org.openremote.model.asset.AssetAttribute.getAssetAttributesAsJson;+import static org.openremote.model.asset.AssetAttribute.getAssetAttributesFromJson;// @formatter:off/**@@ -215,7 +217,6 @@ import static org.openremote.model.Constants.PERSISTENCE_UNIQUE_ID_GENERATOR;// @formatter:on@MappedSuperclasspublic class Asset implements IdentifiableEntity {- public static final String ATTRIBUTE_PROPERTY_NAME = "attrs";@Id@Column(name = "ID", length = 27)@@ -270,9 +271,7 @@ public class Asset implements IdentifiableEntity {@Column(name = "ATTRIBUTES", columnDefinition = "jsonb")@org.hibernate.annotations.Type(type = PERSISTENCE_JSON_OBJECT_TYPE)- @JsonProperty- // We have to use a different name to the getter/setter because GWT Jackson ignores it otherwise- public JsonObject attrs;+ public JsonObject attributes;public Asset() {}@@ -310,11 +309,12 @@ public class Asset implements IdentifiableEntity {this.path = path;if (filterProtectedAttributes) {- List<AssetAttribute> assetAttributes = AttributeUtil.getAssetAttributesFromJson(id, attributes);- assetAttributes = AttributeUtil.filterByProtected(assetAttributes);- this.attrs = assetAttributes.size() > 0 ? AttributeUtil.getAssetAttributesAsJson(assetAttributes) : null;+ this.attributes = getAssetAttributesFromJson(id)+ .andThen(filterProtectedAssetAttribute())+ .andThen(getAssetAttributesAsJson())+ .apply(attributes);} else {- this.attrs = attributes;+ this.attributes = attributes;}}@@ -480,15 +480,28 @@ public class Asset implements IdentifiableEntity {return path != null && Arrays.asList(getPath()).contains(assetId);}- @JsonIgnore- public List<AssetAttribute> getAttributes() {- return AttributeUtil.getAssetAttributesFromJson(id, attrs);+ public JsonObject getAttributes() {+ return attributes;}- @JsonIgnore- public void setAttributes(List<AssetAttribute> attributes) {- // TODO: need to verify there are no duplicate attribute names- this.attrs = AttributeUtil.getAssetAttributesAsJson(attributes);+ public void setAttributes(JsonObject attributes) {+ this.attributes = attributes;+ }++ public Stream<AssetAttribute> getAttributeStream() {+ return getAssetAttributesFromJson(id).apply(getAttributes());+ }++ public void setAttributeStream(Stream<AssetAttribute> attributeStream) {+ setAttributes(getAssetAttributesAsJson().apply(attributeStream));+ }++ public List<AssetAttribute> getAttributeList() {+ return getAttributeStream().collect(Collectors.toList());+ }++ public void setAttributeList(List<AssetAttribute> attributes) {+ setAttributeStream(attributes.stream());}/**@@ -541,7 +554,7 @@ public class Asset implements IdentifiableEntity {", tenantDisplayName='" + tenantDisplayName + '\'' +", coordinates=" + Arrays.toString(coordinates) +", path=" + Arrays.toString(path) +- ", attributes=" + attrs ++ ", attributes=" + attributes +'}';}}diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AssetAttribute.javaindex 2a98091d5..46a87b99c 100644--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java@@ -19,19 +19,33 @@*/package org.openremote.model.asset;+import elemental.json.Json;import elemental.json.JsonObject;import elemental.json.JsonValue;import org.openremote.model.*;import java.util.List;+import java.util.function.Function;+import java.util.function.Predicate;+import java.util.stream.Collectors;+import java.util.stream.Stream;+import static org.openremote.model.Constants.NAMESPACE;import static org.openremote.model.asset.AssetMeta.*;-import static org.openremote.model.asset.AssetMeta.AGENT_LINK;public class AssetAttribute extends Attribute {final protected String assetId;+ public static AssetAttribute createEmpty() {+ return new AssetAttribute(null, Json.createObject());+ }++ public AssetAttribute(String name) {+ super(name);+ this.assetId = null;+ }+public AssetAttribute(String name, AttributeType type) {this(null, name, type);}@@ -101,29 +115,49 @@ public class AssetAttribute extends Attribute {}public boolean hasMetaItem(AssetMeta assetMeta) {- return hasMetaItem(assetMeta.getName());+ return hasMetaItem(assetMeta.getUrn());}public MetaItem firstMetaItem(AssetMeta assetMeta) {- return firstMetaItem(assetMeta.getName());+ return firstMetaItem(assetMeta.getUrn());}public List<MetaItem> getMetaItems(AssetMeta assetMeta) {- return getMetaItems(assetMeta.getName());+ return getMetaItems(assetMeta.getUrn());}public String getLabel() {return hasMetaItem(LABEL) ? firstMetaItem(LABEL).getValueAsString() : getName();}- public String getFormat() {- return hasMetaItem(FORMAT) ? firstMetaItem(FORMAT).getValueAsString() : null;+ public void setLabel(String label) {+ setMeta(+ getMeta().replace(AssetMeta.LABEL.getUrn(), new MetaItem(AssetMeta.LABEL, Json.create(label)))+ );}public boolean isShowOnDashboard() {return hasMetaItem(SHOWN_ON_DASHBOARD) && firstMetaItem(SHOWN_ON_DASHBOARD).isValueTrue();}+ public String getFormat() {+ return hasMetaItem(FORMAT) ? firstMetaItem(FORMAT).getValueAsString() : null;+ }++ public String getDescription() {+ return hasMetaItem(DESCRIPTION) ? firstMetaItem(DESCRIPTION).getValueAsString() : null;+ }++ public boolean isEnabled() {+ return hasMetaItem(ENABLED) && firstMetaItem(AssetMeta.ENABLED).isValueTrue();+ }++ public void setEnabled(boolean enabled) {+ setMeta(+ getMeta().replace(AssetMeta.ENABLED.getUrn(), new MetaItem(AssetMeta.ENABLED, Json.create(enabled)))+ );+ }+public boolean isProtected() {return hasMetaItem(PROTECTED) && firstMetaItem(PROTECTED).isValueTrue();}@@ -151,4 +185,98 @@ public class AssetAttribute extends Attribute {public boolean isAgentLinked() {return hasMetaItem(AGENT_LINK);}++ public static Predicate<Attribute> hasAssetMetaItem(AssetMeta assetMeta) {+ return attribute -> attribute.hasMetaItem(assetMeta.getUrn());+ }++ public static Predicate<MetaItem> isAssetMetaItem(AssetMeta assetMeta) {+ return isMetaItem(assetMeta.getUrn());+ }++ public static Function<Asset, AssetAttribute> findAssetAttribute(String name) {+ return asset -> asset.getAttributeStream()+ .filter(attribute -> attribute.getName().equals(name))+ .findFirst()+ .orElse(null);+ }++ public static Predicate<Asset> containsAssetAttributeNamed(String name) {+ return asset -> findAssetAttribute(name).apply(asset) != null;+ }++ public static Predicate<Asset> isAssetAttribute(String name, Predicate<AssetAttribute> predicate) {+ return asset -> {+ AssetAttribute attribute = findAssetAttribute(name).apply(asset);+ return attribute != null && predicate.test(attribute);+ };+ }++ public static Predicate<AssetAttribute> isMatchingAttributeEvent(AttributeEvent event) {+ return attribute -> attribute.getAssetId().equals(event.getEntityId())+ && attribute.getName().equals(event.getAttributeName());+ }++ /**+ * Returns either an attribute with protected-only meta items, or <code>null</code> if+ * the attribute is private.+ */+ public static Function<Stream<AssetAttribute>, Stream<AssetAttribute>> filterProtectedAssetAttribute() {+ return attributeStream ->+ attributeStream+ .filter(AssetAttribute::isProtected)+ .filter(Attribute::hasMeta)+ .map(attribute -> {+ // Any meta item of the attribute, if it's in our namespace, must be protected READ to be included+ Meta protectedMeta = new Meta();+ for (MetaItem metaItem : attribute.getMeta().all()) {+ if (!metaItem.getName().startsWith(NAMESPACE))+ continue;++ AssetMeta wellKnownMeta = AssetMeta.byUrn(metaItem.getName());+ if (wellKnownMeta != null && wellKnownMeta.getAccess().protectedRead) {+ protectedMeta.add(+ new MetaItem(metaItem.getName(), metaItem.getValue())+ );+ }+ }+ if (protectedMeta.size() > 0)+ attribute.setMeta(protectedMeta);++ return attribute;+ });+ }++ public static Function<JsonObject, Stream<AssetAttribute>> getAssetAttributesFromJson(String assetId) {+ return jsonObject -> {+ if (jsonObject == null || jsonObject.keys().length == 0) {+ return Stream.empty();+ }+ Stream.Builder<AssetAttribute> sb = Stream.builder();+ String[] keys = jsonObject.keys();+ for (String key : keys) {+ sb.add(new AssetAttribute(assetId, key, jsonObject.getObject(key)));+ }+ return sb.build();+ };+ }++ /**+ * Maps the attribute stream to a {@link JsonObject}, duplicate attribute names are not+ * allowed (internally this is a hash map in Elemental, thus not allowing duplicate+ * JSON object property names).+ */+ public static Function<Stream<AssetAttribute>, JsonObject> getAssetAttributesAsJson() {+ return attributeStream -> {+ List<AssetAttribute> list = attributeStream.collect(Collectors.toList());+ if (list.size() == 0)+ return null;+ JsonObject jsonObject = Json.createObject();+ for (AssetAttribute attribute : list) {+ jsonObject.put(attribute.getName(), attribute.getJsonObject());+ }+ return jsonObject;+ };+ }+}diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.javaindex e1eeeaa6b..8815e4e87 100644--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java@@ -39,7 +39,8 @@ import static org.openremote.model.Constants.ASSET_META_NAMESPACE;public enum AssetMeta {/**- * Links the attribute to an agent, connecting it to a sensor and/or actuator.+ * Links the attribute to an agent's {@link org.openremote.model.asset.agent.ProtocolConfiguration}, connecting it+ * to a sensor and/or actuator.*/AGENT_LINK(ASSET_META_NAMESPACE + ":agentLink", new Access(false, false, true), JsonType.ARRAY),@@ -142,7 +143,7 @@ public enum AssetMeta {ENABLED(ASSET_META_NAMESPACE + ":enabled", new Access(true, false, true), JsonType.BOOLEAN),/**- * Identifies a meta item as a {@link org.openremote.model.asset.macro.MacroAction}+ * Identifies a meta item as a {@link org.openremote.model.asset.macro.MacroAction}.*/MACRO_ACTION(ASSET_META_NAMESPACE + ":macroAction", new Access(true, false, true), JsonType.ARRAY),@@ -151,18 +152,18 @@ public enum AssetMeta {*/COMMAND(ASSET_META_NAMESPACE + ":command", new Access(true, false, true), JsonType.BOOLEAN);- final protected String name;+ final protected String urn;final protected Access access;final protected JsonType valueType;- AssetMeta(String name, Access access, JsonType valueType) {- this.name = name;+ AssetMeta(String urn, Access access, JsonType valueType) {+ this.urn = urn;this.access = access;this.valueType = valueType;}- public String getName() {- return name;+ public String getUrn() {+ return urn;}public Access getAccess() {@@ -185,24 +186,24 @@ public enum AssetMeta {return list.toArray(new AssetMeta[list.size()]);}- public static Boolean isEditable(String name) {+ public static Boolean isEditable(String urn) {for (AssetMeta assetMeta : editable()) {- if (assetMeta.getName().equals(name))+ if (assetMeta.getUrn().equals(urn))return assetMeta.getAccess().editable;}return null;}- public static AssetMeta byName(String name) {+ public static AssetMeta byUrn(String urn) {for (AssetMeta assetMeta : values()) {- if (assetMeta.getName().equals(name))+ if (assetMeta.getUrn().equals(urn))return assetMeta;}return null;}- public static MetaItem createMetaItem(AssetMeta name, JsonValue value) {- return new MetaItem(name.getName(), value);+ public static MetaItem createMetaItem(AssetMeta assetMeta, JsonValue value) {+ return new MetaItem(assetMeta.getUrn(), value);}/**diff --git a/model/src/main/java/org/openremote/model/asset/AssetQuery.java b/model/src/main/java/org/openremote/model/asset/AssetQuery.javaindex a06dd7fc8..6b5ad57a3 100644--- a/model/src/main/java/org/openremote/model/asset/AssetQuery.java+++ b/model/src/main/java/org/openremote/model/asset/AssetQuery.java@@ -28,7 +28,7 @@ import java.util.Locale;*/public class AssetQuery<CHILD extends AssetQuery<CHILD>> {- static public class Select {+ public static class Select {public boolean loadComplete;// TODO: Filtering attributes can be moved into database functionspublic boolean filterProtected;@@ -80,7 +80,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {public interface ValuePredicate {}- static public class StringPredicate implements ValuePredicate {+ public static class StringPredicate implements ValuePredicate {public Match match = Match.EXACT;public boolean caseSensitive = true;public String value;@@ -126,7 +126,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class BooleanPredicate implements ValuePredicate {+ public static class BooleanPredicate implements ValuePredicate {public boolean predicate;public BooleanPredicate() {@@ -142,7 +142,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class StringArrayPredicate implements ValuePredicate {+ public static class StringArrayPredicate implements ValuePredicate {public StringPredicate[] predicates = new StringPredicate[0];public StringArrayPredicate() {@@ -158,7 +158,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class ParentPredicate {+ public static class ParentPredicate {public String id;public String type;public boolean noParent;@@ -194,7 +194,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class PathPredicate {+ public static class PathPredicate {public String[] path;public PathPredicate() {@@ -214,7 +214,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class TenantPredicate {+ public static class TenantPredicate {public String realmId;public String realm;@@ -236,7 +236,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class AttributeMetaPredicate {+ public static class AttributeMetaPredicate {public StringPredicate itemNamePredicate;public ValuePredicate itemValuePredicate;@@ -248,7 +248,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}public AttributeMetaPredicate(AssetMeta assetMeta) {- this.itemNamePredicate = new StringPredicate(assetMeta.getName());+ this.itemNamePredicate = new StringPredicate(assetMeta.getUrn());}public AttributeMetaPredicate(ValuePredicate itemValuePredicate) {@@ -261,7 +261,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}public AttributeMetaPredicate(AssetMeta assetMeta, ValuePredicate itemValuePredicate) {- this(new StringPredicate(assetMeta.getName()), itemValuePredicate);+ this(new StringPredicate(assetMeta.getUrn()), itemValuePredicate);}public AttributeMetaPredicate itemName(StringPredicate itemNamePredicate) {@@ -270,7 +270,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}public AttributeMetaPredicate itemName(AssetMeta assetMeta) {- return itemName(new StringPredicate(assetMeta.getName()));+ return itemName(new StringPredicate(assetMeta.getUrn()));}public AttributeMetaPredicate itemValue(ValuePredicate itemValuePredicate) {@@ -279,7 +279,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}}- static public class AttributeRefPredicate extends AttributeMetaPredicate {+ public static class AttributeRefPredicate extends AttributeMetaPredicate {public AttributeRefPredicate() {}@@ -306,7 +306,7 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}public AttributeRefPredicate(AssetMeta assetMeta, String entityId, String attributeName) {- this(assetMeta.getName(), entityId, attributeName);+ this(assetMeta.getUrn(), entityId, attributeName);}public AttributeRefPredicate(StringPredicate name, AttributeRef attributeRef) {@@ -319,11 +319,11 @@ public class AssetQuery<CHILD extends AssetQuery<CHILD>> {}public AttributeRefPredicate(AssetMeta assetMeta, AttributeRef attributeRef) {- this(new StringPredicate(assetMeta.getName()), attributeRef);+ this(new StringPredicate(assetMeta.getUrn()), attributeRef);}}- static public class OrderBy {+ public static class OrderBy {public enum Property {CREATED_ON,diff --git a/model/src/main/java/org/openremote/model/asset/AttributeWrapperFilter.java b/model/src/main/java/org/openremote/model/asset/AttributeWrapperFilter.javadeleted file mode 100644index 7626152bd..000000000--- a/model/src/main/java/org/openremote/model/asset/AttributeWrapperFilter.java+++ /dev/null@@ -1,29 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.model.asset;--import java.util.List;--public interface AttributeWrapperFilter<CHILD> {-- List<CHILD> getAllWrapped(List<AssetAttribute> assetAttributes, boolean excludeInvalid);-- List<AssetAttribute> getAll(List<AssetAttribute> assetAttributes, boolean excludeInvalid);-}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.javanew file mode 100644index 000000000..daebd49f6--- /dev/null+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java@@ -0,0 +1,66 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.asset.agent;++import org.openremote.model.Attribute;+import org.openremote.model.AttributeRef;+import org.openremote.model.asset.AssetMeta;++import java.util.function.Consumer;+import java.util.function.Function;+import java.util.function.Predicate;++import static org.openremote.model.Attribute.*;+import static org.openremote.model.asset.AssetMeta.AGENT_LINK;++/**+ * An asset attribute can be linked to an agent's {@link ProtocolConfiguration},+ * connecting it to a sensor and/or actuator.+ * <p>+ * 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}.+ */+final public class AgentLink {++ private AgentLink() {+ }++ public static Predicate<Attribute> isAgentLink() {+ return attribute -> getAgentLink().apply(attribute) != null;+ }++ public static Predicate<Attribute> isValidAgentLink() {+ return isAttributeValid().and(isAgentLink());+ }++ public static Function<Attribute, AttributeRef> getAgentLink() {+ return getAttributeLink(AGENT_LINK.getUrn());+ }++ public static Consumer<Attribute> setAgentLink(AttributeRef protocolConfigurationRef) {+ return setAttributeLink(AGENT_LINK.getUrn(), protocolConfigurationRef);+ }++ public static Consumer<Attribute> removeAgentLink(Attribute attribute) {+ return removeAttributeLink(AGENT_LINK.getUrn());+ }+}diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentProtocolLink.java b/model/src/main/java/org/openremote/model/asset/agent/AgentProtocolLink.javadeleted file mode 100644index f8816d060..000000000--- a/model/src/main/java/org/openremote/model/asset/agent/AgentProtocolLink.java+++ /dev/null@@ -1,116 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.model.asset.agent;--import elemental.json.JsonArray;-import org.openremote.model.AttributeRef;-import org.openremote.model.Meta;-import org.openremote.model.MetaItem;-import org.openremote.model.asset.AbstractAttributeWrapper;-import org.openremote.model.asset.AttributeWrapperFilter;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;--import java.util.List;-import java.util.stream.Collectors;--public class AgentProtocolLink extends AbstractAttributeWrapper <AgentProtocolLink> {- public static class Filter implements AttributeWrapperFilter<AgentProtocolLink> {- @Override- public List<AgentProtocolLink> getAllWrapped(List<AssetAttribute> assetAttributes, boolean excludeInvalid) {- return getAll(assetAttributes, excludeInvalid)- .stream()- .map(assetAttribute -> new AgentProtocolLink(assetAttribute, false))- .collect(Collectors.toList());- }-- @Override- public List<AssetAttribute> getAll(List<AssetAttribute> assetAttributes, boolean excludeInvalid) {- // Agent Linked Attribute wrappers should have protocol URN as the attribute value- return assetAttributes- .stream()- .filter(attribute ->- AgentProtocolLink.hasAgentProtocolLink(attribute) && (!excludeInvalid || AgentProtocolLink.isValid(attribute))- )- .collect(Collectors.toList());- }- }-- protected static final AttributeWrapperFilter<AgentProtocolLink> filter = new Filter();-- public AgentProtocolLink(AssetAttribute attribute) {- super(attribute);- }-- public AgentProtocolLink(AssetAttribute attribute, boolean initialise) {- super(attribute, initialise);- }-- public AttributeRef getLink() {- return getLink(getAttribute());- }-- protected void setLink(AttributeRef attributeRef) {- if (attributeRef == null) {- throw new IllegalArgumentException("AttributeRef cannot be null");- }-- Meta meta = getMeta().removeAll(AssetMeta.AGENT_LINK);- meta.add(new MetaItem(AssetMeta.AGENT_LINK, attributeRef.asJsonValue()));- setMeta(meta);- }-- protected void removeAgentProtocolLink() {- Meta meta = getMeta().removeAll(AssetMeta.AGENT_LINK);- setMeta(meta);- }-- @Override- public void initialise() {- // Nothing to do here- }-- @Override- public AttributeWrapperFilter<AgentProtocolLink> getFilter() {- return null;- }-- /**- * Does super class checks and also checks for valid Protocol Ref- */- @Override- public boolean isValid() {- return isValid(getAttribute());- }-- public static boolean isValid(AssetAttribute assetAttribute) {- return AbstractAttributeWrapper.isValid(assetAttribute) && hasAgentProtocolLink(assetAttribute);- }-- public static AttributeRef getLink(AssetAttribute assetAttribute) {- MetaItem metaItem = assetAttribute.firstMetaItem(AssetMeta.AGENT_LINK);- JsonArray array = metaItem != null ? metaItem.getValueAsArray() : null;- return array != null && array.length() == 2 ? new AttributeRef(array) : null;- }-- public static boolean hasAgentProtocolLink(AssetAttribute assetAttribute) {- return getLink(assetAttribute) != null;- }-}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.javaindex b06c1fa68..d7e45d3cd 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@@ -20,120 +20,69 @@package org.openremote.model.asset.agent;import elemental.json.Json;+import org.openremote.model.Attribute;import org.openremote.model.AttributeType;import org.openremote.model.Constants;import org.openremote.model.Meta;-import org.openremote.model.MetaItem;-import org.openremote.model.asset.AbstractAttributeWrapper;-import org.openremote.model.asset.AttributeWrapperFilter;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;-import java.util.List;import java.util.Locale;-import java.util.stream.Collectors;+import java.util.function.Consumer;+import java.util.function.Function;+import java.util.function.Predicate;++import static org.openremote.model.Attribute.isAttributeType;+import static org.openremote.model.AttributeType.STRING;+import static org.openremote.model.asset.AssetAttribute.isAttributeValid;/**- * Agent attributes can be named protocol configurations, the value is a protocol URN.+ * Agent attributes can be named protocol configurations.+ * <p>+ * A protocol configuration attribute value must be a URN string representation+ * starting with {@link Constants#PROTOCOL_NAMESPACE}.+ * <p>+ * TODO: How can we integrate 3rd party protocol namespaces?* <p>* Configuration details are managed as {@link Meta} of the attribute.*/-public class ProtocolConfiguration extends AbstractAttributeWrapper<ProtocolConfiguration> {- public static class Filter implements AttributeWrapperFilter<ProtocolConfiguration> {- @Override- public List<ProtocolConfiguration> getAllWrapped(List<AssetAttribute> assetAttributes, boolean excludeInvalid) {- return getAll(assetAttributes, excludeInvalid)- .stream()- .map(assetAttribute -> new ProtocolConfiguration(assetAttribute, false))- .collect(Collectors.toList());- }-- @Override- public List<AssetAttribute> getAll(List<AssetAttribute> assetAttributes, boolean excludeInvalid) {- // Macro Attribute wrappers should have macro protocol name as the attribute value- return assetAttributes- .stream()- .filter(attribute ->- ProtocolConfiguration.valueIsProtocolUrn(attribute)- && (!excludeInvalid || ProtocolConfiguration.isValid(attribute)))- .collect(Collectors.toList());- }- }-- public static final AttributeWrapperFilter<ProtocolConfiguration> filter = new Filter();-- @Override- public void initialise() {- // Push enabled flag as true by default- if (!getAttribute().hasMetaItem(AssetMeta.ENABLED)) {- Meta meta = getAttribute().getMeta().add(new MetaItem(AssetMeta.ENABLED, Json.create(true)));- getAttribute().setMeta(meta);- }- }-- @Override- public AttributeWrapperFilter<ProtocolConfiguration> getFilter() {- return null;- }+final public class ProtocolConfiguration {- public ProtocolConfiguration(String attributeName, String protocolName) {- this(new AssetAttribute(attributeName, AttributeType.STRING));- setProtocolName(protocolName);+ private ProtocolConfiguration() {}- public ProtocolConfiguration(AssetAttribute attribute) {- super(attribute);- }-- public ProtocolConfiguration(AssetAttribute attribute, boolean initialise) {- super(attribute, initialise);- }-- public boolean isEnabled() {- MetaItem enabled = getMeta().first(AssetMeta.ENABLED);- return enabled != null ? enabled.getValueAsBoolean() : true;- }-- public void setEnabled(boolean enabled) {- Meta meta = getMeta();- meta.removeAll(AssetMeta.ENABLED.getName());- meta.add(new MetaItem(AssetMeta.ENABLED, Json.create(enabled)));- setMeta(meta);- }-- public ProtocolConfiguration setProtocolName(String protocolName) throws IllegalArgumentException {-- if (!valueIsProtocolUrn(protocolName)) {- throw new IllegalArgumentException("Protocol configuration value should contain a protocol URN");- }-- getAttribute().setValue(Json.create(protocolName));- return this;+ public static Function<AssetAttribute, AssetAttribute> initProtocolConfiguration(String protocolName) {+ return attribute -> {+ attribute.setEnabled(true);+ attribute.setType(AttributeType.STRING);+ attribute.setValue(Json.create(protocolName));+ return attribute;+ };}- public String getProtocolName() {- return getAttribute().getValueAsString();+ public static Predicate<Attribute> isProtocolConfiguration() {+ return attribute -> isProtocolUrn().test(attribute.getValueAsString());}- @Override- public boolean isValid() {- return super.isValid() && isValid(getAttribute());+ public static Predicate<Attribute> isValidProtocolConfiguration() {+ return isAttributeValid()+ .and(isAttributeType(STRING))+ .and(isProtocolConfiguration());}- /**- * A protocol configuration attribute value must be a URN string representation starting with {@link Constants#PROTOCOL_NAMESPACE}.- */- public static boolean isValid(AssetAttribute assetAttribute) {- // Value must be protocol name and must be at least one macro action- return assetAttribute.getType() == AttributeType.STRING && valueIsProtocolUrn(assetAttribute);+ public static Predicate<String> isProtocolUrn() {+ return value -> value != null && value.toLowerCase(Locale.ROOT).startsWith(Constants.PROTOCOL_NAMESPACE);}- protected static boolean valueIsProtocolUrn(AssetAttribute assetAttribute) {- String value = assetAttribute.getValueAsString();- return valueIsProtocolUrn(value);+ public static Consumer<AssetAttribute> setProtocolName(String protocolName) throws IllegalArgumentException {+ return attribute -> {+ if (!isProtocolUrn().test(protocolName)) {+ throw new IllegalArgumentException("Protocol configuration value should contain a protocol URN");+ }+ attribute.setValue(Json.create(protocolName));+ };}- protected static boolean valueIsProtocolUrn(String value) {- return value != null && value.toLowerCase(Locale.ROOT).startsWith(Constants.PROTOCOL_NAMESPACE);+ public static Function<AssetAttribute, String> getProtocolName() {+ return Attribute::getValueAsString;}}diff --git a/model/src/main/java/org/openremote/model/asset/macro/MacroAction.java b/model/src/main/java/org/openremote/model/asset/macro/MacroAction.javaindex 5a0c23336..70054cda1 100644--- a/model/src/main/java/org/openremote/model/asset/macro/MacroAction.java+++ b/model/src/main/java/org/openremote/model/asset/macro/MacroAction.java@@ -26,10 +26,25 @@ import org.openremote.model.AttributeState;import org.openremote.model.MetaItem;import org.openremote.model.asset.AssetMeta;+import java.util.function.Function;++/**+ * A desired {@link AttributeState} and a delay in seconds (TODO?) before that state+ * is applied when the macro executes.+ */public class MacroAction {+protected AttributeState attributeState;protected int delay;+ static Function<MetaItem, MacroAction> getMacroActionFromMetaItem() {+ return metaItem -> new MacroAction(metaItem.getValueAsObject());+ }++ static Function<MacroAction, MetaItem> getMetaItemFromMacroAction() {+ return macroAction -> new MetaItem(AssetMeta.MACRO_ACTION, macroAction.asJsonValue());+ }+public MacroAction(JsonObject jsonObject) {attributeState = new AttributeState(jsonObject.getObject("attributeState"));delay = new Double(jsonObject.getNumber("delay")).intValue();@@ -63,15 +78,11 @@ public class MacroAction {return jsonObect;}- public MetaItem asMetaItem() {- return new MetaItem(AssetMeta.MACRO_ACTION, asJsonValue());- }-@Overridepublic String toString() {return getClass().getSimpleName() + "{" +- "attributeState='" + attributeState + '\'' +- ", delay='" + delay + '\'' +- '}';+ "attributeState='" + attributeState + '\'' ++ ", delay='" + delay + '\'' ++ '}';}}diff --git a/model/src/main/java/org/openremote/model/asset/macro/MacroConfiguration.java b/model/src/main/java/org/openremote/model/asset/macro/MacroConfiguration.javaindex 4141bd089..4a2f9c03f 100644--- a/model/src/main/java/org/openremote/model/asset/macro/MacroConfiguration.java+++ b/model/src/main/java/org/openremote/model/asset/macro/MacroConfiguration.java@@ -20,119 +20,87 @@package org.openremote.model.asset.macro;import elemental.json.Json;+import org.openremote.model.Attribute;import org.openremote.model.AttributeType;-import org.openremote.model.Meta;import org.openremote.model.MetaItem;-import org.openremote.model.asset.AbstractAttributeWrapper;-import org.openremote.model.asset.AttributeWrapperFilter;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetMeta;import org.openremote.model.util.JsonUtil;import java.util.List;-import java.util.stream.Collectors;+import java.util.function.Consumer;+import java.util.function.Function;+import java.util.function.Predicate;import java.util.stream.IntStream;+import java.util.stream.Stream;+import static org.openremote.model.Attribute.isAttributeType;+import static org.openremote.model.Attribute.isAttributeValid;+import static org.openremote.model.AttributeType.STRING;import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;+import static org.openremote.model.asset.AssetAttribute.hasAssetMetaItem;+import static org.openremote.model.asset.AssetAttribute.isAssetMetaItem;+import static org.openremote.model.asset.AssetMeta.MACRO_ACTION;+import static org.openremote.model.asset.macro.MacroAction.getMacroActionFromMetaItem;+import static org.openremote.model.asset.macro.MacroAction.getMetaItemFromMacroAction;++/**+ * Agent attributes can be macro configurations.+ * <p>+ * A macro configuration attribute has {@link AssetMeta#MACRO_ACTION} items attached to it, each+ * item is a sequence of asset state changes to be executed.+ */+final public class MacroConfiguration {-public class MacroConfiguration extends AbstractAttributeWrapper<MacroConfiguration> {- public static class Filter implements AttributeWrapperFilter<MacroConfiguration> {- @Override- public List<MacroConfiguration> getAllWrapped(List<AssetAttribute> assetAttributes, boolean excludeInvalid) {- return getAll(assetAttributes, excludeInvalid)- .stream()- .map(assetAttribute -> new MacroConfiguration(assetAttribute, false))- .collect(Collectors.toList());- }-- @Override- public List<AssetAttribute> getAll(List<AssetAttribute> assetAttributes, boolean excludeInvalid) {- // Macro Attribute wrappers should have macro protocol name as the attribute value- return assetAttributes- .stream()- .filter(attribute ->- MacroConfiguration.valueIsProtocolName(attribute) && (!excludeInvalid || MacroConfiguration.isValid(attribute))- )- .collect(Collectors.toList());- }- }-- public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":macro";- protected static final AttributeWrapperFilter<MacroConfiguration> filter = new Filter();-- public MacroConfiguration(String attributeName) {- this(new AssetAttribute(attributeName, AttributeType.STRING, Json.create(PROTOCOL_NAME)));- }-- public MacroConfiguration(AssetAttribute attribute) {- super(attribute);- }-- public MacroConfiguration(AssetAttribute attribute, boolean initialise) {- super(attribute, initialise);- }-- @Override- public boolean isValid() {- return super.isValid() && isValid(getAttribute());- }-- @Override- public void initialise() {- // Set value as protocol name- getAttribute().setValue(Json.create(PROTOCOL_NAME));- }-- @Override- public AttributeWrapperFilter<MacroConfiguration> getFilter() {- return filter;- }+ public static final String MACRO_PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":macro";- public List<MacroAction> getActions() {- return getAttribute().getMeta().all()- .stream()- .filter(metaItem -> metaItem.getName().equals(AssetMeta.MACRO_ACTION.getName()))- .map(metaItem -> new MacroAction(metaItem.getValueAsObject()))- .collect(Collectors.toList());+ private MacroConfiguration() {}- public void setActions(List<MacroAction> actions) {- Meta meta = getAttribute().getMeta() != null ? getAttribute().getMeta() : new Meta();- meta = meta.removeAll(AssetMeta.MACRO_ACTION);- Meta finalMeta = meta;- actions.forEach(action -> finalMeta.add(action.asMetaItem()));+ public static Function<AssetAttribute, AssetAttribute> initMacroConfiguration() {+ return attribute -> {+ attribute.setType(AttributeType.STRING);+ attribute.setValue(Json.create(MACRO_PROTOCOL_NAME));+ return attribute;+ };}- public void addAction(MacroAction action) {- Meta meta = getAttribute().getMeta() != null ? getAttribute().getMeta() : new Meta();- meta.add(action.asMetaItem());- getAttribute().setMeta(meta);+ public static Predicate<Attribute> isMacroConfiguration() {+ return attribute -> {+ String value = attribute.getValueAsString();+ return value != null && value.equals(MACRO_PROTOCOL_NAME);+ };}- public void removeAction(MacroAction action) {- if (!getAttribute().hasMeta()) {- return;- }-- List<MetaItem> metaItems = getAttribute().getMeta().all();- IntStream.range(0, metaItems.size())- .filter(i -> metaItems.get(i).getName().equals(AssetMeta.MACRO_ACTION.getName()))- .filter(i -> JsonUtil.equals(metaItems.get(i).getValueAsObject(), action.asJsonValue()))- .forEach(i -> getAttribute().getMeta().remove(i));+ public static Predicate<Attribute> isValidMacroConfiguration() {+ return isAttributeValid()+ .and(isAttributeType(STRING))+ .and(isMacroConfiguration())+ .and(hasAssetMetaItem(MACRO_ACTION)); // Must have at least one macro action}- public String getProtocolName() {- return PROTOCOL_NAME;+ public static Function<AssetAttribute, Stream<MacroAction>> getMacroActions() {+ return attribute -> attribute.getMetaItemStream()+ .filter(isAssetMetaItem(MACRO_ACTION))+ .map(getMacroActionFromMetaItem());}- public static boolean isValid(AssetAttribute assetAttribute) {- MetaItem item = assetAttribute.firstMetaItem(AssetMeta.MACRO_ACTION);- return AbstractAttributeWrapper.isValid(assetAttribute) && valueIsProtocolName(assetAttribute) && item != null;+ public static Consumer<AssetAttribute> addMacroAction(MacroAction action) {+ return attribute -> attribute.setMeta(+ attribute.getMeta().add(getMetaItemFromMacroAction().apply(action))+ );}- public static boolean valueIsProtocolName(AssetAttribute assetAttribute) {- // Value must be protocol name and must be at least one macro action- String value = assetAttribute.getValueAsString();- return value != null && value.equals(PROTOCOL_NAME);+ public static Consumer<AssetAttribute> removeMacroAction(MacroAction action) {+ return attribute -> {+ if (!attribute.hasMeta()) {+ return;+ }+ List<MetaItem> metaItems = attribute.getMeta().all();+ IntStream.range(0, metaItems.size())+ .filter(i -> isAssetMetaItem(MACRO_ACTION).test(metaItems.get(i)))+ .filter(i -> JsonUtil.equals(metaItems.get(i).getValueAsObject(), action.asJsonValue()))+ .forEach(i -> attribute.getMeta().remove(i));+ };}}diff --git a/model/src/main/java/org/openremote/model/rules/Assets.java b/model/src/main/java/org/openremote/model/rules/Assets.javaindex 83e4e58b6..dde31c0af 100644--- a/model/src/main/java/org/openremote/model/rules/Assets.java+++ b/model/src/main/java/org/openremote/model/rules/Assets.java@@ -20,10 +20,10 @@package org.openremote.model.rules;import org.openremote.model.AttributeEvent;-import org.openremote.model.Consumer;import org.openremote.model.asset.AssetQuery;import java.util.List;+import java.util.function.Consumer;/*** Facade for writing rules RHS actions, supporting asset queries within the scopediff --git a/model/src/main/java/org/openremote/model/rules/Users.java b/model/src/main/java/org/openremote/model/rules/Users.javaindex c5c504de8..d0654e458 100644--- a/model/src/main/java/org/openremote/model/rules/Users.java+++ b/model/src/main/java/org/openremote/model/rules/Users.java@@ -19,11 +19,11 @@*/package org.openremote.model.rules;-import org.openremote.model.Consumer;import org.openremote.model.notification.AlertNotification;import org.openremote.model.user.UserQuery;import java.util.List;+import java.util.function.Consumer;/*** Facade for writing rules RHS actions, supporting asset queries within the scopediff --git a/model/src/main/java/org/openremote/model/util/AttributeUtil.java b/model/src/main/java/org/openremote/model/util/AttributeUtil.javadeleted file mode 100644index 4b4dcad19..000000000--- a/model/src/main/java/org/openremote/model/util/AttributeUtil.java+++ /dev/null@@ -1,193 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.model.util;--import com.google.gwt.regexp.shared.RegExp;-import elemental.json.Json;-import elemental.json.JsonObject;-import elemental.json.JsonValue;-import org.openremote.model.AttributeRef;-import org.openremote.model.Meta;-import org.openremote.model.MetaItem;-import org.openremote.model.asset.AbstractAttributeWrapper;-import org.openremote.model.asset.AttributeWrapperFilter;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;--import java.util.*;-import java.util.stream.Collectors;--import static org.openremote.model.Constants.NAMESPACE;--public class AttributeUtil {- /**- * Attribute names should be very simple, as we use them in SQL path expressions, etc. and must manually escape.- */- public static final String ATTRIBUTE_NAME_PATTERN = "^\\w+$";- protected static final RegExp attributeNamePattern = RegExp.compile(ATTRIBUTE_NAME_PATTERN);-- private AttributeUtil() {- }-- /**- * Returns only attributes and meta that are not private.- */- public static List<AssetAttribute> filterByProtected(List<AssetAttribute> attributes) {- if (attributes == null) {- return Collections.emptyList();- }-- List<AssetAttribute> filteredAttributes = new ArrayList<>(attributes);-- for (AssetAttribute attribute : attributes) {-- if (!attribute.isProtected()) {- filteredAttributes.remove(attribute);- continue;- }-- if (!attribute.hasMeta())- continue;-- // Any meta item of the attribute, if it's in our namespace, must be protected READ to be included- Meta protectedMeta = new Meta();- for (MetaItem metaItem : attribute.getMeta().all()) {- if (!metaItem.getName().startsWith(NAMESPACE))- continue;-- AssetMeta wellKnownMeta = AssetMeta.byName(metaItem.getName());- if (wellKnownMeta != null && wellKnownMeta.getAccess().protectedRead) {- protectedMeta.add(- new MetaItem(metaItem.getName(), metaItem.getValue())- );- }- }- if (protectedMeta.size() > 0)- attribute.setMeta(protectedMeta);- }-- return filteredAttributes;- }-- public static List<AssetAttribute> getAssetAttributesFromJson(String assetId, JsonObject jsonObject) {- if (jsonObject == null || jsonObject.keys().length == 0) {- return new ArrayList<>();- }-- List<AssetAttribute> assetAttributes = new ArrayList<>();- String[] keys = jsonObject.keys();- for (String key : keys) {- assetAttributes.add(new AssetAttribute(assetId, key, jsonObject.getObject(key)));- }- return assetAttributes;- }-- public static JsonObject getAssetAttributesAsJson(List<AssetAttribute> attributes) {- if (attributes == null) {- return null;- }-- JsonObject jsonObject = Json.createObject();- for (AssetAttribute attribute : attributes) {- jsonObject.put(attribute.getName(), attribute.getJsonObject());- }-- return jsonObject;- }-- public static boolean nameIsValid(String name) {- return name != null && name.length() > 0 && attributeNamePattern.test(name);- }--- /**- * Filter attributes that contain one or more meta items of the specified asset meta type.- */- public static List<AssetAttribute> filterByMeta(List<AssetAttribute> attributes, AssetMeta meta) {- return filterByMeta(attributes, meta.getName());- }-- /**- * Filter attributes that contain one or more meta items with the specified name.- */- public static List<AssetAttribute> filterByMeta(List<AssetAttribute> attributes, String metaName) {- return attributes- .stream()- .filter(assetAttribute -> assetAttribute.hasMetaItem(metaName))- .collect(Collectors.toList());- }-- /**- * Filter attributes that contain one or more meta items of the specified asset meta type and with the- * specified value.- *- * Value equality uses {@link JsonUtil#equals(JsonValue, JsonValue)} method.- */- public static List<AssetAttribute> filterByMeta(List<AssetAttribute> attributes, AssetMeta meta, JsonValue value) {- return filterByMeta(attributes, meta.getName(), value);- }-- /**- * Filter attributes that contain one or more meta items with the specified name and value.- *- * Value equality uses {@link JsonUtil#equals(JsonValue, JsonValue)} method.- */- public static List<AssetAttribute> filterByMeta(List<AssetAttribute> attributes, String metaName, JsonValue value) {- return attributes- .stream()- .filter(assetAttribute -> assetAttribute.getMetaItems(metaName, value).size() > 0)- .collect(Collectors.toList());- }-- public static boolean contains(List<AssetAttribute> attributes, String attributeName) {- return attributes.stream().anyMatch(assetAttribute -> assetAttribute.getName().equals(attributeName));- }-- public static AssetAttribute getAttributeByName(List<AssetAttribute> attributes, String attributeName) {- if (attributes == null || attributeName == null) {- return null;- }-- return attributes- .stream()- .filter(assetAttribute -> assetAttribute.getName().equals(attributeName))- .findFirst()- .orElse(null);- }-- public static void remove(List<AssetAttribute> attributes, String name) {- attributes.removeIf(assetAttribute -> assetAttribute.getName().equals(name));- }-- public static AttributeRef getAttributeRef(String assetId, String attributeName) {- return new AttributeRef(assetId, attributeName);- }-- public static AttributeRef getAttributeRef(String assetId, AbstractAttributeWrapper attributeWrapper) {- return getAttributeRef(assetId, attributeWrapper.getAttribute().getName());- }-- public static List<String> getNames(List<AssetAttribute> attributes) {- return attributes- .stream()- .map(attribute -> attribute.getName())- .collect(Collectors.toList());- }-}diff --git a/model/src/main/resources/META-INF/services/org.openremote.model.asset.AttributeWrapperFilter b/model/src/main/resources/META-INF/services/org.openremote.model.asset.AttributeWrapperFilterdeleted file mode 100644index 0b3c9b23e..000000000--- a/model/src/main/resources/META-INF/services/org.openremote.model.asset.AttributeWrapperFilter+++ /dev/null@@ -1,3 +0,0 @@-org.openremote.model.asset.agent.ProtocolConfiguration$Filter-org.openremote.model.asset.macro.MacroConfiguration$Filter-org.openremote.model.asset.agent.AgentProtocolLink$Filter\ No newline at end of file