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
Added MergeOptions to ProtocolAssetService, fixed asset attribute bugs
Christian Bauer785c95e949f7
diff --git a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.javaindex 98e4a8404..8813db8c9 100644--- a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java+++ b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java@@ -20,15 +20,72 @@package org.openremote.agent.protocol;import org.openremote.container.ContainerService;+import org.openremote.model.AbstractValueTimestampHolder;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.attribute.AttributeEvent;+import java.util.Objects;+/*** Interface for protocols to perform limited asset related operations.*/public interface ProtocolAssetService extends ContainerService {+ /**+ * Options when merging and storing assets from protocols.+ */+ class MergeOptions {++ final protected String assignToUserName;+ final protected boolean ignoreAttributeValueTimestamps;++ public MergeOptions(String assignToUserName) {+ this(assignToUserName, false);+ }++ public MergeOptions(boolean ignoreAttributeValueTimestamps) {+ this(null, ignoreAttributeValueTimestamps);+ }++ public MergeOptions(String assignToUserName, boolean ignoreAttributeValueTimestamps) {+ this.assignToUserName = assignToUserName;+ this.ignoreAttributeValueTimestamps = ignoreAttributeValueTimestamps;+ }++ /**+ * Assigns the merged asset to the given user, can be <code>null</code> to not assign+ * the asset to a user. The {@link #mergeAsset} call returns <code>null</code> if the+ * user doesn't exist or the asset couldn't be assigned.+ */+ public String getAssignToUserName() {+ return assignToUserName;+ }++ /**+ * Compare existing and merged asset state before storing, if only the+ * {@link AbstractValueTimestampHolder#getValueTimestamp()}s have changed, don't perform the merge.+ */+ public boolean isIgnoreAttributeValueTimestamps() {+ return ignoreAttributeValueTimestamps;+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;+ MergeOptions that = (MergeOptions) o;+ return ignoreAttributeValueTimestamps == that.ignoreAttributeValueTimestamps &&+ Objects.equals(assignToUserName, that.assignToUserName);+ }++ @Override+ public int hashCode() {++ return Objects.hash(assignToUserName, ignoreAttributeValueTimestamps);+ }+ }+/*** Protocols can update their own protocol configuration, for example, to store configuration* details such as temporary access (e.g. OAuth offline) tokens.@@ -38,17 +95,19 @@ public interface ProtocolAssetService extends ContainerService {/*** Protocols may store assets in the context or update existing assets. A unique identifier* must be set by the protocol implementor, as well as a parent identifier. This operation- * stores transient or detached state and returns the current state.+ * stores transient or detached state and returns the current state. It will override any+ * existing stored asset data, ignoring versions.*/Asset mergeAsset(Asset asset);/**- * Protocols may store assets in the context or update existing assets and assigns the given asset to the given user.- * A unique identifier must be set by the protocol implementor, as well as a parent identifier. This operation- * stores transient or detached state and returns the current state.- * Returns null if user doesn't exist or asset couldn't be assigned.+ * Protocols may store assets in the context or update existing assets. A unique identifier+ * must be set by the protocol implementor, as well as a parent identifier. This operation+ * stores transient or detached state and returns the current state. It will override any+ * existing stored asset data, ignoring versions. This call may return <code>null</code>+ * if the desired {@link MergeOptions} were not successful.*/- Asset mergeAsset(Asset asset, String userName);+ Asset mergeAsset(Asset asset, MergeOptions options);/*** Protocols may remove assets from the context store.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 fdf1fab1d..e617caab1 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@@ -35,7 +35,6 @@ import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.event.ClientEventService;import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.manager.shared.security.ClientRole;-import org.openremote.model.AbstractValueTimestampHolder;import org.openremote.model.asset.*;import org.openremote.model.asset.agent.*;import org.openremote.model.attribute.AttributeEvent;@@ -58,7 +57,9 @@ import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_import static org.openremote.manager.server.asset.AssetProcessingService.ASSET_QUEUE;import static org.openremote.manager.server.asset.AssetRoute.isPersistenceEventForAssetType;import static org.openremote.manager.server.asset.AssetRoute.isPersistenceEventForEntityType;+import static org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME;import static org.openremote.model.asset.AssetAttribute.attributesFromJson;+import static org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes;import static org.openremote.model.asset.AssetType.AGENT;import static org.openremote.model.asset.agent.AgentLink.getAgentLink;import static org.openremote.model.asset.agent.ConnectionStatus.*;@@ -220,23 +221,42 @@ public class AgentService extends RouteBuilder implements ContainerService, Conspublic Asset mergeAsset(Asset asset) {Objects.requireNonNull(asset.getId());Objects.requireNonNull(asset.getParentId());- LOG.fine("Merging (and overriding existing older version of) with protocol-provided: " + asset);- ServerAsset serverAsset = ServerAsset.map(asset, new ServerAsset());- // Use the unique identifier provided by the protocol, it manages its own identifier space- serverAsset.setId(asset.getId());- return assetStorageService.merge(serverAsset, true);+ return mergeAsset(asset, null);}@Override- public Asset mergeAsset(Asset asset, String userName) {+ public Asset mergeAsset(Asset asset, MergeOptions options) {Objects.requireNonNull(asset.getId());Objects.requireNonNull(asset.getParentId());- Objects.requireNonNull(userName);- LOG.fine("Merging (and overriding existing older version of) with protocol-provided: " + asset);- ServerAsset serverAsset = ServerAsset.map(asset, new ServerAsset());++ ServerAsset updatedAsset = ServerAsset.map(asset, new ServerAsset());// Use the unique identifier provided by the protocol, it manages its own identifier space- serverAsset.setId(asset.getId());- return assetStorageService.merge(serverAsset, true, userName);+ updatedAsset.setId(asset.getId());++ if (options != null && options.isIgnoreAttributeValueTimestamps()) {+ // Must check manually if asset exists and if any attributes were changed (ignoring different value timestamps)+ ServerAsset existingAsset = assetStorageService.find(updatedAsset.getId(), true);+ if (existingAsset != null) {+ List<AssetAttribute> existingAttributes = existingAsset.getAttributesList();+ List<AssetAttribute> updatedAttributes = updatedAsset.getAttributesList();++ List<AssetAttribute> addedOrModifiedAttributes =+ getAddedOrModifiedAttributes(existingAttributes, updatedAttributes, VALUE_TIMESTAMP_FIELD_NAME).collect(Collectors.toList());+ List<AssetAttribute> removedAttributes =+ getAddedOrModifiedAttributes(updatedAttributes, existingAttributes, VALUE_TIMESTAMP_FIELD_NAME).collect(Collectors.toList());+ if (addedOrModifiedAttributes.isEmpty() && removedAttributes.isEmpty()) {+ LOG.fine("Ignoring merge, protocol-provided asset unchanged (except maybe attribute value timestamps): " + asset);+ return existingAsset;+ }+ }+ }++ LOG.fine("Merging (and overriding existing older version of) with protocol-provided: " + asset);+ if (options != null && options.getAssignToUserName() != null) {+ return assetStorageService.merge(updatedAsset, true, options.getAssignToUserName());+ } else {+ return assetStorageService.merge(updatedAsset, true);+ }}@Override@@ -251,8 +271,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons}/**- * Looks for new, modified and obsolete protocol configurations and links / unlinks any associated- * attributes+ * Looks for new, modified and obsolete protocol configurations and links / unlinks any associated attributes*/protected void processAgentChange(Asset agent, PersistenceEvent persistenceEvent) {LOG.finest("Processing agent persistence event: " + persistenceEvent.getCause());@@ -378,36 +397,14 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons.collect(Collectors.toList());// Unlink thing attributes that are in old but not in new- Stream<AssetAttribute> attributesToUnlink = oldAgentLinkedAttributes- .stream()- .filter(oldAgentLinkedAttribute -> newAgentLinkedAttributes- .stream()- .noneMatch(newAgentLinkedAttribute ->- oldAgentLinkedAttribute.getObjectValue().equalsIgnoreKeys(- newAgentLinkedAttribute.getObjectValue(),- AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME- )- )- );-- getGroupedAgentLinkAttributes(attributesToUnlink, attribute -> true)- .forEach(this::unlinkAttributes);+ getGroupedAgentLinkAttributes(+ getAddedOrModifiedAttributes(newAgentLinkedAttributes, oldAgentLinkedAttributes, VALUE_TIMESTAMP_FIELD_NAME),+ attribute -> true+ ).forEach(this::unlinkAttributes);// Link thing attributes that are in new but not in old- Stream<AssetAttribute> attributesToLink = newAgentLinkedAttributes- .stream()- .filter(newThingAttribute -> oldAgentLinkedAttributes- .stream()- .noneMatch(oldThingAttribute ->- oldThingAttribute.getObjectValue().equalsIgnoreKeys(- newThingAttribute.getObjectValue(),- AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME- )- )- );-getGroupedAgentLinkAttributes(- attributesToLink,+ getAddedOrModifiedAttributes(oldAgentLinkedAttributes, newAgentLinkedAttributes, VALUE_TIMESTAMP_FIELD_NAME),attribute -> true,attribute -> LOG.warning("Linked protocol configuration not found: " + attribute)).forEach(this::linkAttributes);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 95c26734d..079346ec3 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@@ -35,7 +35,6 @@ import org.openremote.manager.server.concurrent.ManagerExecutorService;import org.openremote.manager.server.notification.NotificationService;import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.manager.shared.security.Tenant;-import org.openremote.model.AbstractValueTimestampHolder;import org.openremote.model.asset.*;import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeType;@@ -57,7 +56,9 @@ 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.AssetRoute.isPersistenceEventForEntityType;+import static org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME;import static org.openremote.model.asset.AssetAttribute.attributesFromJson;+import static org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes;/*** Responsible for creating Drools knowledge sessions for the rulesets@@ -301,44 +302,22 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons).filter(AssetAttribute::isRuleState).collect(Collectors.toList());// Retract facts for attributes that are obsolete- Stream<AssetAttribute> processAttributes = oldRuleStateAttributes- .stream()- .filter(oldRuleStateAttribute -> newRuleStateAttributes- .stream()- .noneMatch(newRuleStateAttribute ->- oldRuleStateAttribute.getObjectValue().equalsIgnoreKeys(- newRuleStateAttribute.getObjectValue(),- AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME- )- )- );-- processAttributes.forEach(obsoleteFactAttribute -> {- AssetState update = buildAssetState.apply(loadedAsset, obsoleteFactAttribute);- LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting: " + update);- retractAssetState(update);- });+ getAddedOrModifiedAttributes(newRuleStateAttributes, oldRuleStateAttributes, VALUE_TIMESTAMP_FIELD_NAME)+ .forEach(obsoleteFactAttribute -> {+ AssetState update = buildAssetState.apply(loadedAsset, obsoleteFactAttribute);+ LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting: " + update);+ retractAssetState(update);+ });// Insert facts for attributes that are new- processAttributes = newRuleStateAttributes- .stream()- .filter(newRuleStateAttribute -> oldRuleStateAttributes- .stream()- .noneMatch(oldRuleStateAttribute ->- oldRuleStateAttribute.getObjectValue().equalsIgnoreKeys(- newRuleStateAttribute.getObjectValue(),- AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME- )- )- );-- processAttributes.forEach(newFactAttribute -> {- AssetState assetState = buildAssetState.apply(loadedAsset, 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() + "), updating: " + assetState);- updateAssetState(assetState, true);- });+ getAddedOrModifiedAttributes(oldRuleStateAttributes, newRuleStateAttributes, VALUE_TIMESTAMP_FIELD_NAME)+ .forEach(newFactAttribute -> {+ AssetState assetState = buildAssetState.apply(loadedAsset, 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() + "), updating: " + assetState);+ updateAssetState(assetState, true);+ });break;case DELETE:diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex e77bfcdfb..fb86c98c8 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -340,7 +340,7 @@ public class Asset implements IdentifiableEntity {}- public void addAttributes(AssetAttribute... attributes) throws IllegalArgumentException {+ public Asset addAttributes(AssetAttribute... attributes) throws IllegalArgumentException {Arrays.asList(attributes).forEach(attribute -> {if (getAttributesStream().anyMatch(attr -> isAttributeNameEqualTo(attr, attribute.getName().orElse(null)))) {@@ -350,12 +350,13 @@ public class Asset implements IdentifiableEntity {replaceAttribute(attribute);});+ return this;}/*** Replaces existing or adds the attribute if it does not exist.*/- public void replaceAttribute(AssetAttribute attribute) throws IllegalArgumentException {+ public Asset replaceAttribute(AssetAttribute attribute) throws IllegalArgumentException {if (attribute == null || !attribute.getName().isPresent() || !attribute.getType().isPresent())throw new IllegalArgumentException("Attribute cannot be null and must have a name and type");@@ -363,11 +364,14 @@ public class Asset implements IdentifiableEntity {List<AssetAttribute> attributeList = getAttributesList();attributeList.removeIf(attr -> attr.getName().orElse("").equals(attribute.getName().orElse("")));attributeList.add(attribute);++ return this;}- public void removeAttribute(String name) {+ public Asset removeAttribute(String name) {List<AssetAttribute> attributeList = getAttributesList();attributeList.removeIf(attr -> attr.getName().orElse("").equals(name));+ return this;}public String getId() {@@ -376,6 +380,8 @@ public class Asset implements IdentifiableEntity {public void setId(String id) {this.id = id;+ // Must clear the cached list of attributes they can be recreated with the new identifier+ this.attributeList = null;}public long getVersion() {@@ -569,17 +575,19 @@ public class Asset implements IdentifiableEntity {.flatMap(objectValue -> AssetAttribute.attributeFromJson(objectValue, id, name));}- public void setAttributes(ObjectValue attributes) {+ public Asset setAttributes(ObjectValue attributes) {setAttributes(attributesFromJson(attributes, id).collect(Collectors.toList()));+ return this;}- public void setAttributes(List<AssetAttribute> attributes) {+ public Asset setAttributes(List<AssetAttribute> attributes) {((ObservableList)getAttributesList()).clear(false);getAttributesList().addAll(attributes);+ return this;}- public void setAttributes(AssetAttribute... attributes) {- setAttributes(Arrays.asList(attributes));+ public Asset setAttributes(AssetAttribute... attributes) {+ return setAttributes(Arrays.asList(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 22c24d3e8..6ec481e4b 100644--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java@@ -345,6 +345,7 @@ public class AssetAttribute extends Attribute {getMeta().removeIf(isMetaNameEqualTo(RULE_STATE));}}+public boolean isRuleEvent() {return getMetaStream().filter(isMetaNameEqualTo(RULE_EVENT))@@ -410,6 +411,17 @@ public class AssetAttribute extends Attribute {return Optional.of(attribute);}+ /**+ * @return All attributes that exist only in the new list or are different than any attribute in the old list.+ */+ public static Stream<AssetAttribute> getAddedOrModifiedAttributes(List<AssetAttribute> oldAttributes,+ List<AssetAttribute> newAttributes,+ String... ignoreAttributeKeys) {+ return newAttributes.stream().filter(newAttribute -> oldAttributes.stream().noneMatch(+ oldAttribute -> newAttribute.getObjectValue().equalsIgnoreKeys(oldAttribute.getObjectValue(), ignoreAttributeKeys))+ );+ }+public static Stream<AssetAttribute> attributesFromJson(ObjectValue objectValue, String assetId) {if (objectValue == null || objectValue.keys().length == 0) {return Stream.empty();diff --git a/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.java b/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.javaindex abf700069..b132b4ea1 100644--- a/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.java+++ b/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.java@@ -19,6 +19,7 @@ import org.openremote.model.util.Pair;import org.openremote.model.value.*;import java.util.*;+import java.util.stream.Collectors;import java.util.stream.Stream;public class ObjectValueImpl extends ValueImpl implements ObjectValue {@@ -186,16 +187,22 @@ public class ObjectValueImpl extends ValueImpl implements ObjectValue {public boolean equalsIgnoreKeys(ObjectValue that, String... ignoreKeys) {if (!(that instanceof ObjectValueImpl))return false;- ObjectValueImpl objectValueImpl = (ObjectValueImpl)that;+ ObjectValueImpl thatImpl = (ObjectValueImpl) that;- if (!this.map.keySet().equals(objectValueImpl.map.keySet()))+ List<String> ignoreKeysList = Arrays.asList(ignoreKeys);++ Set<String> thisKeys = this.map.keySet().stream()+ .filter(key -> !ignoreKeysList.contains(key)).collect(Collectors.toSet());+ Set<String> thatKeys = this.map.keySet().stream()+ .filter(key -> !ignoreKeysList.contains(key)).collect(Collectors.toSet());+ if (!thisKeys.equals(thatKeys))return false;for (Map.Entry<String, Value> entry : this.map.entrySet()) {- if (Arrays.asList(ignoreKeys).contains(entry.getKey()))+ if (ignoreKeysList.contains(entry.getKey()))continue;Value mapAValue = entry.getValue();- Value mapBValue = objectValueImpl.map.get(entry.getKey());+ Value mapBValue = thatImpl.map.get(entry.getKey());if (!mapAValue.equals(mapBValue)) {return false;}diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetModelTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetModelTest.groovynew file mode 100644index 000000000..a25cce4bd--- /dev/null+++ b/test/src/test/groovy/org/openremote/test/assets/AssetModelTest.groovy@@ -0,0 +1,126 @@+package org.openremote.test.assets++import com.fasterxml.uuid.Generators+import org.openremote.model.asset.Asset+import org.openremote.model.asset.AssetAttribute+import org.openremote.model.value.Values+import spock.lang.Specification++import java.util.stream.Collectors++import static org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME+import static org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes+import static org.openremote.model.asset.AssetType.THING+import static org.openremote.model.attribute.AttributeType.STRING++class AssetModelTest extends Specification {++ def "Modifying asset identifier"() {++ when: "an asset is created without identifier"+ Asset asset = new Asset("foo", THING).setAttributes(+ new AssetAttribute("foo1", STRING, Values.create("foo111")),+ new AssetAttribute("foo2", STRING, Values.create("foo222"))+ )++ then: "the attributes should not have an identifier"+ !asset.getAttribute("foo1").get().getAssetId().isPresent()+ !asset.getAttribute("foo2").get().getAssetId().isPresent()+ !asset.getAttributesList()[0].getAssetId().isPresent()+ !asset.getAttributesList()[1].getAssetId().isPresent()++ when: "the asset identifier is set later"+ def id = Generators.randomBasedGenerator().generate().toString()+ asset.setId(id)++ then: "the attributes should have an identifier"+ asset.getAttribute("foo1").get().getAssetId().get() == id+ asset.getAttribute("foo2").get().getAssetId().get() == id+ asset.getAttributesList()[0].getAssetId().get() == id+ asset.getAttributesList()[1].getAssetId().get() == id+ }++ def "Comparing asset attributes"() {++ when: "two attributes have different value timestamps"+ def timestamp = System.currentTimeMillis()+ def timestamp2 = timestamp + 1000++ def attributeA =new AssetAttribute("a", STRING, Values.create("foo"), timestamp)+ def attributeB =new AssetAttribute("b", STRING, Values.create("foo"), timestamp2)++ then: "they should be different"+ !attributeA.getObjectValue().equalsIgnoreKeys(attributeB.getObjectValue())++ and: "if we ignore the timestamp they should be equal"+ attributeA.getObjectValue().equalsIgnoreKeys(attributeB.getObjectValue(), VALUE_TIMESTAMP_FIELD_NAME)++ when: "an attribute has no timestamp"+ def attributeC = new AssetAttribute("c", STRING, Values.create("foo"))++ then: "it should be different than attributes with a timestamp"+ !attributeA.getObjectValue().equalsIgnoreKeys(attributeC.getObjectValue())+ !attributeB.getObjectValue().equalsIgnoreKeys(attributeC.getObjectValue())++ and: "if we ignore the timestamp they all should be equal"+ attributeA.getObjectValue().equalsIgnoreKeys(attributeC.getObjectValue(), VALUE_TIMESTAMP_FIELD_NAME)+ attributeB.getObjectValue().equalsIgnoreKeys(attributeC.getObjectValue(), VALUE_TIMESTAMP_FIELD_NAME)+ }++ def "Comparing asset attribute lists"() {++ when: "two lists of asset attributes are compared"+ def timestamp = System.currentTimeMillis()+ def attributesA = [+ new AssetAttribute("a1", STRING, Values.create("a111"), timestamp),+ new AssetAttribute("a2", STRING, Values.create("a222"), timestamp),+ ]+ def attributesB = [+ new AssetAttribute("a1", STRING, Values.create("a111"), timestamp),+ new AssetAttribute("a2", STRING, Values.create("a222"), timestamp),+ new AssetAttribute("a3", STRING, Values.create("a333"), timestamp),+ ]+ List<AssetAttribute> addedOrModifiedAttributes = getAddedOrModifiedAttributes(attributesA, attributesB).collect(Collectors.toList())++ then: "they should be different"+ addedOrModifiedAttributes.size() == 1+ addedOrModifiedAttributes[0].name.get() == "a3"++ when: "two lists of asset attributes with different value timestamp are compared"+ timestamp = System.currentTimeMillis()+ def timestamp2 = timestamp + 1000++ attributesA = [+ new AssetAttribute("a1", STRING, Values.create("a111"), timestamp),+ new AssetAttribute("a2", STRING, Values.create("a222"), timestamp),+ ]+ attributesB = [+ new AssetAttribute("a1", STRING, Values.create("a111"), timestamp2),+ new AssetAttribute("a2", STRING, Values.create("a222"), timestamp2),+ ]+ addedOrModifiedAttributes = getAddedOrModifiedAttributes(attributesA, attributesB).collect(Collectors.toList())++ then: "they should be different"+ addedOrModifiedAttributes.size() == 2+ addedOrModifiedAttributes[0].name.get() == "a1"+ addedOrModifiedAttributes[1].name.get() == "a2"++ when: "two lists of asset attributes with different value timestamp are compared, ignoring timestamps"+ timestamp = System.currentTimeMillis()+ timestamp2 = timestamp + 1000++ attributesA = [+ new AssetAttribute("a1", STRING, Values.create("a111"), timestamp),+ new AssetAttribute("a2", STRING, Values.create("a222"), timestamp),+ ]+ attributesB = [+ new AssetAttribute("a1", STRING, Values.create("a111"), timestamp2),+ new AssetAttribute("a2", STRING, Values.create("a222"), timestamp2),+ ]+ addedOrModifiedAttributes = getAddedOrModifiedAttributes(attributesA, attributesB, VALUE_TIMESTAMP_FIELD_NAME).collect(Collectors.toList())++ then: "they should be the same"+ addedOrModifiedAttributes.size() == 0+ }++}diff --git a/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovyindex b67cb8fda..5407cf175 100644--- a/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy+++ b/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy@@ -135,7 +135,7 @@ class TimerProtocolTest extends Specification implements ManagerContainerTrait {then: "the attributes value should contain the timers cron expression"conditions.eventually {apartment1 = assetStorageService.find(apartment1.id, true)- apartment1.getAttribute("awaySceneCronFRIDAY").get().getValueAsString() == "0 0 4 ? * FRI *"+ apartment1.getAttribute("awaySceneCronFRIDAY").get().getValueAsString().get() == "0 0 4 ? * FRI *"}when: "the trigger cron expression is modified"@@ -162,8 +162,8 @@ class TimerProtocolTest extends Specification implements ManagerContainerTrait {then: "the linked macro should have been executed"conditions.eventually {apartment1 = assetStorageService.find(apartment1.id, true)- apartment1.getAttribute("awayScene").get().getValueAsString() == "COMPLETED"- apartment1.getAttribute("lastExecutedScene").get().getValueAsString() == "AWAY"+ apartment1.getAttribute("awayScene").get().getValueAsString().get() == "COMPLETED"+ apartment1.getAttribute("lastExecutedScene").get().getValueAsString().get() == "AWAY"}when: "a trigger is deleted"diff --git a/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovy b/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovyindex 487b117cc..60863387b 100644--- a/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovy+++ b/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovy@@ -20,7 +20,7 @@ import java.time.DayOfWeekimport static java.util.concurrent.TimeUnit.DAYSimport static java.util.concurrent.TimeUnit.HOURS-import static org.openremote.manager.server.setup.builtin.BuiltinSetupTasks.SETUP_IMPORT_DEMO_SCENES+import static org.openremote.manager.server.setup.SetupTasks.SETUP_IMPORT_DEMO_SCENESimport static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_1_WITH_SCENESclass ApartmentVacationModeTest extends Specification implements ManagerContainerTrait {