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
AttributeEvent Minor
Rich Turnerdd5610b70ecb
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 3c2625a7f..a3eba852f 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@@ -53,7 +53,6 @@ import java.util.logging.Level;import java.util.logging.Logger;import static org.openremote.agent.protocol.Protocol.SENSOR_QUEUE;-import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TOPIC;import static org.openremote.model.asset.agent.AgentLink.getAgentLink;/**@@ -268,7 +267,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer}// Process as non-client source (not southbound)- processUpdate(asset, attribute, event, true, protocol);+ processUpdate(asset, attribute, event, false, true, protocol);});@@ -294,24 +293,8 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// TODO: implement any rules specific validation}- processUpdate(asset, attribute, event, false, sender);- });-- // Client initiated attribute events - sender should always be a user- from(INCOMING_EVENT_TOPIC)- .filter(body().isInstanceOf(AttributeEvent.class))- .filter(header(SharedEvent.HEADER_SENDER).isInstanceOf(User.class))- .process(exchange -> {- AttributeEvent event = exchange.getIn().getBody(AttributeEvent.class);- User user = exchange.getIn().getHeader(SharedEvent.HEADER_SENDER, User.class);-- LOG.fine("Handling from client: " + event);-- if (event.getEntityId() == null || event.getEntityId().isEmpty() || user == null)- return;-- // Put it on the asset queue- sendAttributeEvent(event, user);+ boolean southbound = sender == null || sender instanceof User;+ processUpdate(asset, attribute, event, southbound, false, sender);});}@@ -352,7 +335,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// TODO: implement any rules specific validation}- processUpdate(asset, attribute, event, false, sender);+ processUpdate(asset, attribute, event, true, false, sender);}// TODO: Update tests to include sender and remove this@@ -483,6 +466,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerprotected void processUpdate(ServerAsset asset,AssetAttribute attribute,AttributeEvent attributeEvent,+ boolean isSouthbound,boolean isSensorUpdate,Object sender) {// Ensure timestamp of event is not in the future as that would essentially block access to@@ -527,6 +511,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerattribute,lastStateEvent.flatMap(AttributeEvent::getValue).orElse(null),lastStateEvent.map(AttributeEvent::getTimestamp).orElse(-1L),+ isSouthbound,isSensorUpdate,sender);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 520a68f34..85666ba9f 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@@ -244,10 +244,12 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour// TODO: Get this working using camel routeassetProcessingService.sendAttributeEventWithoutCamel(event, user);+ // Note camel SEDA endpoints seem to only support InOnly (if you try and set InOut) it will successfully+ // block and wait for a response but you'll get your original message back so cannot get any exception+ // information or anything.// messageBrokerService// .getProducerTemplate()-// .sendBodyAndHeader(INCOMING_EVENT_TOPIC, event, SharedEvent.HEADER_SENDER, user);-+// .sendBodyAndHeader(ASSET_QUEUE, event, SharedEvent.HEADER_SENDER, user);} catch (AssetProcessingException assetProcessingException) {switch (assetProcessingException.getReason()) {case INSUFFICIENT_ACCESS: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 3177ed883..b79ff3475 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@@ -33,6 +33,7 @@ import org.openremote.manager.server.asset.AssetStorageService;import org.openremote.manager.server.concurrent.ManagerExecutorService;import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.manager.shared.security.User;+import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.event.shared.CancelEventSubscription;import org.openremote.model.event.shared.EventSubscription;import org.openremote.model.event.shared.SharedEvent;@@ -44,6 +45,7 @@ import java.util.concurrent.CopyOnWriteArraySet;import java.util.logging.Logger;import static org.apache.camel.builder.PredicateBuilder.or;+import static org.openremote.manager.server.asset.AssetProcessingService.ASSET_QUEUE;/*** Receives and publishes messages, handles the client/server event bus.@@ -175,19 +177,19 @@ public class EventService implements ContainerService {eventSubscriptions.cancel(sessionKey, exchange.getIn().getBody(CancelEventSubscription.class));}).when(bodyAs(String.class).startsWith(SharedEvent.MESSAGE_PREFIX))- .convertBodyTo(SharedEvent.class)- .process(exchange -> {- WebsocketAuth auth = getWebsocketAuth(exchange);-- // Extract user object to use as the sender- User user = managerIdentityService.getUser(auth.getAccessToken());+ .convertBodyTo(SharedEvent.class)+ .process(exchange -> {+ WebsocketAuth auth = getWebsocketAuth(exchange);- // TODO: There's probably a better way of doing this in camel- SharedEvent event = exchange.getIn().getBody(SharedEvent.class);- messageBrokerService- .getProducerTemplate()- .sendBodyAndHeader(INCOMING_EVENT_TOPIC, event, SharedEvent.HEADER_SENDER, user);- })+ // Extract user object to use as the sender+ User user = managerIdentityService.getUser(auth.getAccessToken());+ exchange.getIn().setHeader(SharedEvent.HEADER_SENDER, user);+ }).end()+ .choice()+ .when(body().isInstanceOf(AttributeEvent.class))+ .to(ASSET_QUEUE).stop()+ .when(body().isInstanceOf(SharedEvent.class))+ .to(INCOMING_EVENT_TOPIC).otherwise().process(exchange -> LOG.fine("Unsupported message body: " + exchange.getIn().getBody())).end();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 5715668f9..9a24060a1 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@@ -172,7 +172,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons.forEach(pair -> {ServerAsset asset = pair.key;pair.value.forEach(ruleAttribute -> {- AssetState assetState = new AssetState(asset, ruleAttribute, false, null);+ AssetState assetState = new AssetState(asset, ruleAttribute, false, false, null);// Set the status to completed already so rules cannot interfere with this initial insertassetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);updateAssetState(assetState, true);@@ -256,6 +256,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Consnew AssetState(loadedAsset,attribute.deepCopy(),false,+ false,null);@@ -361,7 +362,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons.forEach(attribute -> {// We can't load the asset again (it was deleted), so don't use buildAssetState() and// hope that the path of the event asset has been loaded before deletion- AssetState assetState = new AssetState(asset, attribute, false, null);+ AssetState assetState = new AssetState(asset, attribute, false, false, null);LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + assetState);retractAssetState(assetState);});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 5115bb390..346e6ff5e 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@@ -32,7 +32,6 @@ import org.openremote.container.Container;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.setup.AbstractManagerSetup;import org.openremote.manager.shared.security.Tenant;-import org.openremote.model.Constants;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetState;import org.openremote.model.attribute.*;@@ -256,54 +255,54 @@ public class ManagerDemoSetup extends AbstractManagerSetup {AssetAttribute light1PowerConsumptionAttribute = thing.getAttribute("light1PowerConsumption").orElseThrow(() -> new RuntimeException("Invalid test data"));- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(0.11), now.minusDays(80).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(1.22), now.minusDays(40).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(2.33), now.minusDays(20).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(3.44), now.minusDays(10).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(4.55), now.minusDays(8).toEpochSecond() * 1000);light1PowerConsumptionAttribute.setValue(Values.create(5.66), now.minusDays(6).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(6.77), now.minusDays(3).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(7.88), now.minusDays(1).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(8.99), now.minusHours(10).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(9.11), now.minusHours(5).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(10.22), now.minusHours(2).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(11.33), now.minusHours(1).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(11.44), now.minusMinutes(30).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(12.00), now.minusMinutes(5).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(12.11), now.minusSeconds(5).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));light1PowerConsumptionAttribute.setValue(Values.create(12.22), now.minusSeconds(1).toEpochSecond() * 1000);- assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, null));+ assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute, false, false, null));// ################################ Demo assets for 'customerA' realm ###################################diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.javaindex 71b617da5..1dc15a3b7 100644--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java@@ -19,7 +19,7 @@*/package org.openremote.model.asset;-import org.kie.api.task.model.User;+import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeRef;import org.openremote.model.attribute.AttributeType;@@ -72,15 +72,18 @@ public abstract class AbstractAssetUpdate {final protected long oldValueTimestamp;+ final protected boolean southbound;+final protected boolean sensorUpdate;final protected Object sender;- public AbstractAssetUpdate(Asset asset, AssetAttribute attribute, boolean sensorUpdate, Object sender) {- this(asset, attribute, null, 0, sensorUpdate, sender);++ public AbstractAssetUpdate(Asset asset, AssetAttribute attribute, boolean southbound, boolean sensorUpdate, Object sender) {+ this(asset, attribute, null, 0, southbound, sensorUpdate, sender);}- public AbstractAssetUpdate(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean sensorUpdate, Object sender) {+ public AbstractAssetUpdate(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean southbound, boolean sensorUpdate, Object sender) {this(attribute,asset.getCreatedOn(),@@ -98,6 +101,7 @@ public abstract class AbstractAssetUpdate {asset.getCoordinates(),oldValue,oldValueTimestamp,+ southbound,sensorUpdate,sender);@@ -121,6 +125,7 @@ public abstract class AbstractAssetUpdate {that.coordinates,that.oldValue,that.oldValueTimestamp,+ that.southbound,that.sensorUpdate,that.sender);@@ -133,6 +138,7 @@ public abstract class AbstractAssetUpdate {double[] coordinates,Value oldValue,long oldValueTimestamp,+ boolean southbound,boolean sensorUpdate,Object sender) {this.attribute = attribute;@@ -154,6 +160,7 @@ public abstract class AbstractAssetUpdate {this.coordinates = coordinates;this.oldValue = oldValue;this.oldValueTimestamp = oldValueTimestamp;+ this.southbound = southbound;this.sensorUpdate = sensorUpdate;this.sender = sender;}@@ -223,9 +230,10 @@ public abstract class AbstractAssetUpdate {* is being processed southbound.*/public boolean isSouthbound() {- return sender == null || sender instanceof User;+ return southbound;}+public boolean isSensorUpdate() {return sensorUpdate;}diff --git a/model/src/main/java/org/openremote/model/asset/AssetState.java b/model/src/main/java/org/openremote/model/asset/AssetState.javaindex a0144ca17..e228f5c2d 100644--- a/model/src/main/java/org/openremote/model/asset/AssetState.java+++ b/model/src/main/java/org/openremote/model/asset/AssetState.java@@ -61,12 +61,12 @@ public class AssetState extends AbstractAssetUpdate {protected Throwable error;- public AssetState(Asset asset, AssetAttribute attribute, boolean isSensorUpdate, Object sender) {- super(asset, attribute, isSensorUpdate, sender);+ public AssetState(Asset asset, AssetAttribute attribute, boolean southbound, boolean sensorUpdate, Object sender) {+ super(asset, attribute, southbound, sensorUpdate, sender);}- public AssetState(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean isSensorUpdate, Object sender) {- super(asset, attribute, oldValue, oldValueTimestamp, isSensorUpdate, sender);+ public AssetState(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean southbound, boolean sensorUpdate, Object sender) {+ super(asset, attribute, oldValue, oldValueTimestamp, southbound, sensorUpdate, sender);}public ProcessingStatus getProcessingStatus() {