Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Changed consoles asset type to group and lookup by asset query rather than fixed ID and also updated gateway code to use altered asset IDs for mirrored assets

Rich Turner01f2e30e2091
diff --git a/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
index 70c924591..81f31ff42 100644
--- a/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
@@ -34,8 +34,14 @@ import org.openremote.model.console.ConsoleConfiguration;
import org.openremote.model.console.ConsoleRegistration;
import org.openremote.model.console.ConsoleResource;
import org.openremote.model.http.RequestParams;
+import org.openremote.model.query.AssetQuery;
+import org.openremote.model.query.filter.AttributePredicate;
+import org.openremote.model.query.filter.ParentPredicate;
+import org.openremote.model.query.filter.StringPredicate;
+import org.openremote.model.query.filter.TenantPredicate;
import org.openremote.model.security.Tenant;
import org.openremote.model.util.TextUtil;
+import org.openremote.model.value.Values;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.core.Response;
@@ -141,18 +147,25 @@ public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleRe
}
public static Asset getConsoleParentAsset(AssetStorageService assetStorageService, Tenant tenant) {
- String id = consoleParentAssetIdGenerator(tenant.getRealm());
- Asset consoleParent = assetStorageService.find(id, false);
+
+ // Look for a group asset with a child type of console in the realm root
+ Asset consoleParent = assetStorageService.find(
+ new AssetQuery()
+ .select(AssetQuery.Select.selectExcludeAll())
+ .names(CONSOLE_PARENT_ASSET_NAME)
+ .parents(new ParentPredicate(true))
+ .types(AssetType.GROUP)
+ .tenant(new TenantPredicate(tenant.getRealm()))
+ .attributes(new AttributePredicate("childAssetType").value(new StringPredicate(AssetType.CONSOLE.getType())))
+ );
+
if (consoleParent == null) {
- consoleParent = new Asset(CONSOLE_PARENT_ASSET_NAME, AssetType.THING);
- consoleParent.setId(id);
+ consoleParent = new Asset(CONSOLE_PARENT_ASSET_NAME, AssetType.GROUP);
+ consoleParent.getAttribute("childAssetType").ifPresent(attr ->
+ attr.setValue(Values.create(AssetType.CONSOLE.getType())));
consoleParent.setRealm(tenant.getRealm());
consoleParent = assetStorageService.merge(consoleParent);
}
return consoleParent;
}
-
- protected static String consoleParentAssetIdGenerator(String realm) {
- return UniqueIdentifierGenerator.generateId(realm + "Consoles");
- }
}
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java
index 136b62400..de95af033 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java
@@ -31,16 +31,21 @@ import org.openremote.model.event.shared.SharedEvent;
import org.openremote.model.gateway.GatewayDisconnectEvent;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.syslog.SyslogCategory;
+import org.openremote.model.util.Pair;
import org.openremote.model.value.Values;
import java.util.*;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.function.ToIntFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
import static org.openremote.model.query.AssetQuery.Select.selectExcludeAll;
import static org.openremote.model.syslog.SyslogCategory.GATEWAY;
@@ -57,6 +62,7 @@ public class GatewayConnector {
public static int SYNC_ASSET_BATCH_SIZE = 20;
public static final String ASSET_READ_EVENT_NAME_INITIAL = "INITIAL";
public static final String ASSET_READ_EVENT_NAME_BATCH = "BATCH";
+ protected static final Map<String, Pair<Function<String, String>, Function<String, String>>> ASSET_ID_MAPPERS = new HashMap<>();
protected final String realm;
protected final String gatewayId;
protected final AssetStorageService assetStorageService;
@@ -77,6 +83,44 @@ public class GatewayConnector {
Asset gateway;
String expectedSyncResponseName;
+ protected static List<Integer> ALPHA_NUMERIC_CHARACTERS = new ArrayList<>(62);
+
+ static {
+ ALPHA_NUMERIC_CHARACTERS.addAll(
+ Stream.concat(
+ Stream.concat(
+ IntStream.rangeClosed('a', 'z').boxed(),
+ IntStream.rangeClosed('A', 'Z').boxed()
+ ),
+ IntStream.rangeClosed('0', '9').boxed()
+ ).collect(Collectors.toList())
+ );
+ }
+
+ /**
+ * An easily reversible mathematical way of ensuring gateway asset IDs are unique by incrementing the first two
+ * characters by adding the first two characters of the gateway ID for inbound IDs and the reverse for outbound.
+ */
+ public static String mapAssetId(String gatewayId, String assetId, boolean outbound) {
+ Pair<Function<String, String>, Function<String, String>> gatewayIdMappers = ASSET_ID_MAPPERS.computeIfAbsent(gatewayId, gwId -> {
+ int g1 = gatewayId.charAt(0) % ALPHA_NUMERIC_CHARACTERS.size();
+ int g2 = gatewayId.charAt(1) % ALPHA_NUMERIC_CHARACTERS.size();
+
+ BiFunction<Integer, String, String> mapper = (sign, id) -> {
+ int a1 = (ALPHA_NUMERIC_CHARACTERS.indexOf((int)id.charAt(0)) + (sign * g1) + ALPHA_NUMERIC_CHARACTERS.size()) % ALPHA_NUMERIC_CHARACTERS.size();
+ int a2 = (ALPHA_NUMERIC_CHARACTERS.indexOf((int)id.charAt(1)) + (sign * g2) + ALPHA_NUMERIC_CHARACTERS.size()) % ALPHA_NUMERIC_CHARACTERS.size();
+ return String.valueOf((char)ALPHA_NUMERIC_CHARACTERS.get(a1).intValue()) + ((char)ALPHA_NUMERIC_CHARACTERS.get(a2).intValue()) + id.substring(2);
+ };
+
+ return new Pair<>(
+ id -> mapper.apply(1, id), // Inbound
+ id -> mapper.apply(-1, id) // Outbound
+ );
+ });
+
+ return outbound ? gatewayIdMappers.value.apply(assetId) : gatewayIdMappers.key.apply(assetId);
+ }
+
public GatewayConnector(
AssetStorageService assetStorageService,
AssetProcessingService assetProcessingService,
@@ -309,8 +353,9 @@ public class GatewayConnector {
if (isInitialResponse) {
+ // Put assets in hierarchical order
Map<String, String> gatewayAssetIdParentIdMap = e.getAssets().stream()
- .collect(HashMap::new, (m,v)->m.put(v.getId(), v.getParentId()), HashMap::putAll);
+ .collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getParentId()), HashMap::putAll);
ToIntFunction<Asset> assetLevelExtractor = asset -> {
int level = 0;
@@ -436,7 +481,7 @@ public class GatewayConnector {
// Delete obsolete assets
List<String> obsoleteLocalAssetIds = localAssets.stream()
- .filter(localAsset -> !syncAssetIds.contains(localAsset.getId()))
+ .filter(localAsset -> !syncAssetIds.contains(mapAssetId(gatewayId, localAsset.getId(), true)))
.map(Asset::getId).collect(Collectors.toList());
if (!obsoleteLocalAssetIds.isEmpty()) {
@@ -473,14 +518,19 @@ public class GatewayConnector {
throw new IllegalStateException(msg);
}
-
if (id == null) {
// Generate an ID to allow tracking the asset when it is returned from the gateway
asset.setId(UniqueIdentifierGenerator.generateId());
+ } else {
+ // Put original gateway asset ID back
+ asset.setId(mapAssetId(gatewayId, id, true));
}
if (gatewayId.equals(parentId)) {
asset.setParentId(null);
+ } else if (parentId != null) {
+ // Put original parent asset ID back
+ asset.setParentId(mapAssetId(gatewayId, parentId, true));
}
sendMessageToGateway(new AssetEvent(isUpdate ? AssetEvent.Cause.UPDATE : AssetEvent.Cause.CREATE, asset, null));
@@ -497,13 +547,13 @@ public class GatewayConnector {
}
if (mergedAsset == null) {
- throw new IllegalStateException("Gateway asset merge failed: Gateway ID=" + gatewayId + ", Asset ID=" + asset.getId());
+ throw new IllegalStateException("Gateway asset merge failed: Gateway ID=" + gatewayId + ", Asset ID=" + asset.getId() + ", Asset ID Mapped=" + id);
}
return mergedAsset;
} catch (InterruptedException e) {
- String msg = "Gateway asset merge interrupted: Gateway ID=" + gatewayId + ", Asset ID=" + id;
+ String msg = "Gateway asset merge interrupted: Gateway ID=" + gatewayId + ", Asset ID=" + asset.getId() + ", Asset ID Mapped=" + id;
LOG.info(msg);
throw new IllegalStateException(msg);
} finally {
@@ -527,25 +577,27 @@ public class GatewayConnector {
synchronized (pendingAssetDelete) {
if (pendingAssetDelete.get() != null) {
- String msg = "Gateway asset delete already pending: Gateway ID=" + gatewayId + ", Asset IDs=" + Arrays.toString(assetIds.toArray());
+ String msg = "Gateway asset delete already pending: Gateway ID=" + gatewayId + ", Asset IDs Mapped=" + Arrays.toString(pendingAssetDelete.get().getEvent().getAssetIds().toArray());
LOG.info(msg);
throw new IllegalStateException(msg);
}
+ List<String> originalIds = assetIds.stream().map(id -> mapAssetId(gatewayId, id, true)).collect(Collectors.toList());
+
pendingAssetDelete.set(new EventRequestResponseWrapper<>(
UniqueIdentifierGenerator.generateId(),
- new DeleteAssetsRequestEvent(new ArrayList<>(assetIds))
+ new DeleteAssetsRequestEvent(new ArrayList<>(originalIds))
));
try {
sendMessageToGateway(pendingAssetDelete.get());
pendingAssetDelete.wait(ASSET_CRUD_TIMEOUT_MILLIS);
if (pendingAssetDelete.get() != null) {
- throw new IllegalStateException("Gateway asset delete failed: Gateway ID=" + gatewayId + ", Asset IDs=" + Arrays.toString(assetIds.toArray()));
+ throw new IllegalStateException("Gateway asset delete failed: Gateway ID=" + gatewayId + ", Asset IDs=" + originalIds + ", Asset IDs Mapped=" + Arrays.toString(assetIds.toArray()));
}
return true;
} catch (InterruptedException e) {
- String msg = "Gateway asset delete interrupted: Gateway ID=" + gatewayId + ", Asset IDs=" + Arrays.toString(assetIds.toArray());
+ String msg = "Gateway asset delete interrupted: Gateway ID=" + gatewayId + ", Asset IDs=" + originalIds + ", Asset IDs Mapped=" + Arrays.toString(assetIds.toArray());
LOG.info(msg);
throw new IllegalStateException(msg);
} finally {
@@ -581,12 +633,13 @@ public class GatewayConnector {
case CREATE:
case READ:
case UPDATE:
+ String assetId = e.getEntityId();
Asset mergedAsset = saveAssetLocally(e.getAsset());
synchronized (pendingAssetMerges) {
- if (pendingAssetMerges.containsKey(e.getEntityId())) {
+ if (pendingAssetMerges.containsKey(assetId)) {
@SuppressWarnings("OptionalGetWithoutIsPresent")
- Map.Entry<String, Asset> pendingAssetMergeEntry = pendingAssetMerges.entrySet().stream().filter(entry -> entry.getKey().equals(e.getEntityId())).findFirst().get();
+ Map.Entry<String, Asset> pendingAssetMergeEntry = pendingAssetMerges.entrySet().stream().filter(entry -> entry.getKey().equals(assetId)).findFirst().get();
String id = pendingAssetMergeEntry.getKey();
pendingAssetMergeEntry.setValue(mergedAsset);
@@ -600,7 +653,7 @@ public class GatewayConnector {
break;
case DELETE:
try {
- deleteAssetsLocally(Collections.singletonList(e.getEntityId()));
+ deleteAssetsLocally(Collections.singletonList(mapAssetId(gatewayId, e.getEntityId(), false)));
} catch (Exception ex) {
LOG.log(Level.SEVERE, "Removing obsolete asset failed: " + e.getEntityId(), ex);
}
@@ -610,13 +663,18 @@ public class GatewayConnector {
protected void onAttributeEvent(AttributeEvent e) {
// Just push the event through the processing chain
- assetProcessingService.sendAttributeEvent(e, AttributeEvent.Source.GATEWAY);
+ assetProcessingService.sendAttributeEvent(
+ new AttributeEvent(mapAssetId(gatewayId, e.getEntityId(), false), e.getAttributeName(), e.getValue().orElse(null), e.getTimestamp()),
+ AttributeEvent.Source.GATEWAY
+ );
}
protected Asset saveAssetLocally(Asset asset) {
- asset.setParentId(asset.getParentId() != null ? asset.getParentId() : gatewayId);
+ String assetId = asset.getId();
+ asset.setId(mapAssetId(gatewayId, assetId, false));
+ asset.setParentId(asset.getParentId() != null ? mapAssetId(gatewayId, asset.getParentId(), false) : gatewayId);
asset.setRealm(realm);
- LOG.fine("Creating/updating gateway asset: Gateway ID=" + gatewayId + ", Asset ID=" + asset.getId());
+ LOG.fine("Creating/updating gateway asset: Gateway ID=" + gatewayId + ", Asset ID=" + assetId + ", Asset ID Mapped=" + asset.getId());
return assetStorageService.merge(asset, true, true, null);
}
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java
index d13d2e2b8..c235fc8e0 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java
@@ -63,6 +63,7 @@ import static org.apache.camel.builder.PredicateBuilder.or;
import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
import static org.openremote.container.persistence.PersistenceEvent.isPersistenceEventForEntityType;
import static org.openremote.manager.event.ClientEventService.*;
+import static org.openremote.manager.gateway.GatewayConnector.mapAssetId;
import static org.openremote.model.asset.AssetAttribute.attributeFromJson;
import static org.openremote.model.syslog.SyslogCategory.GATEWAY;
@@ -267,11 +268,11 @@ public class GatewayService extends RouteBuilder implements ContainerService, As
LOG.fine("Attribute event for a gateway descendant asset being forwarded to the gateway (Asset ID=" + asset.getId() + ", Gateway ID=" + gatewayId + "): " + attribute);
connector.sendMessageToGateway(
new AttributeEvent(
- asset.getId(),
+ mapAssetId(gatewayId, asset.getId(), true),
attribute.getNameOrThrow(),
attribute.getValue().orElse(null),
attribute.getValueTimestamp().orElse(0L))
- .setParentId(asset.getParentId()).setRealm(asset.getRealm()));
+ .setParentId(mapAssetId(gatewayId, asset.getParentId(), true)).setRealm(asset.getRealm()));
}
// Consume this event as it is for a gateway descendant and we've sent it to that gateway for processing
diff --git a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
index 531081a47..f19536449 100644
--- a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
@@ -30,6 +30,7 @@ import org.openremote.model.gateway.GatewayClientResource
import org.openremote.model.gateway.GatewayConnection
import org.openremote.model.geo.GeoJSONPoint
import org.openremote.model.query.AssetQuery
+import org.openremote.model.query.filter.TenantPredicate
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -42,6 +43,7 @@ import java.util.stream.Collectors
import java.util.stream.IntStream
import static org.openremote.container.util.MapAccess.getString
+import static org.openremote.manager.gateway.GatewayConnector.mapAssetId
import static org.openremote.manager.security.ManagerIdentityProvider.SETUP_ADMIN_PASSWORD
import static org.openremote.manager.security.ManagerIdentityProvider.SETUP_ADMIN_PASSWORD_DEFAULT
import static org.openremote.model.Constants.*
@@ -282,43 +284,43 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
conditions.eventually {
def syncedAssets = assetStorageService.findAll(new AssetQuery().parents(gateway.getId()).recursive(true))
assert syncedAssets.size() == sendAssets.size()
- assert syncedAssets.stream().filter{syncedAsset -> sendAssets.stream().anyMatch{it.id == syncedAsset.id}}.count() == sendAssets.size()
- assert syncedAssets.find {it.id == agentAssetIds[0]}.getName() == "Test Agent 1"
- assert syncedAssets.find {it.id == agentAssetIds[0]}.getType() == AssetType.AGENT.type
- assert syncedAssets.find {it.id == agentAssetIds[0]}.getRealm() == managerTestSetup.realmBuildingTenant
- assert syncedAssets.find {it.id == agentAssetIds[0]}.getParentId() == gateway.getId()
- assert syncedAssets.find {it.id == agentAssetIds[4]}.getName() == "Test Agent 5"
- assert syncedAssets.find {it.id == agentAssetIds[4]}.getType() == AssetType.AGENT.type
- assert syncedAssets.find {it.id == agentAssetIds[4]}.getRealm() == managerTestSetup.realmBuildingTenant
- assert syncedAssets.find {it.id == agentAssetIds[4]}.getParentId() == gateway.getId()
- assert syncedAssets.find {it.id == assetIds[0]}.getName() == "Test Building 1"
- assert syncedAssets.find {it.id == assetIds[0]}.getType() == AssetType.BUILDING.type
- assert syncedAssets.find {it.id == assetIds[0]}.getRealm() == managerTestSetup.realmBuildingTenant
- assert syncedAssets.find {it.id == assetIds[0]}.getParentId() == gateway.getId()
- assert syncedAssets.find {it.id == assetIds[0]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().x == 10
- assert syncedAssets.find {it.id == assetIds[0]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().y == 11
- assert syncedAssets.find {it.id == assetIds[0]}.getAttribute(AttributeType.LOCATION).flatMap{it.getMetaItem(MetaItemType.ACCESS_PUBLIC_READ)}.isPresent()
- assert syncedAssets.find {it.id == assetIds[0]}.getAttribute(AttributeType.SURFACE_AREA).flatMap {it.getValueAsNumber()}.orElse(0d) == 1000
- assert syncedAssets.find {it.id == assetIds[1]}.getName() == "Test Building 1 Room 1"
- assert syncedAssets.find {it.id == assetIds[1]}.getType() == AssetType.ROOM.type
- assert syncedAssets.find {it.id == assetIds[1]}.getRealm() == managerTestSetup.realmBuildingTenant
- assert syncedAssets.find {it.id == assetIds[1]}.getParentId() == assetIds[0]
- assert syncedAssets.find {it.id == assetIds[1]}.getAttribute("temp").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
- assert syncedAssets.find {it.id == assetIds[1]}.getAttribute("tempSetpoint").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
- assert syncedAssets.find {it.id == assetIds[5]}.getName() == "Test Building 2"
- assert syncedAssets.find {it.id == assetIds[5]}.getType() == AssetType.BUILDING.type
- assert syncedAssets.find {it.id == assetIds[5]}.getRealm() == managerTestSetup.realmBuildingTenant
- assert syncedAssets.find {it.id == assetIds[5]}.getParentId() == gateway.getId()
- assert syncedAssets.find {it.id == assetIds[5]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().x == 10
- assert syncedAssets.find {it.id == assetIds[5]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().y == 11
- assert syncedAssets.find {it.id == assetIds[5]}.getAttribute(AttributeType.LOCATION).flatMap{it.getMetaItem(MetaItemType.ACCESS_PUBLIC_READ)}.isPresent()
- assert syncedAssets.find {it.id == assetIds[5]}.getAttribute(AttributeType.SURFACE_AREA).flatMap {it.getValueAsNumber()}.orElse(0d) == 1000
- assert syncedAssets.find {it.id == assetIds[6]}.getName() == "Test Building 2 Room 1"
- assert syncedAssets.find {it.id == assetIds[6]}.getType() == AssetType.ROOM.type
- assert syncedAssets.find {it.id == assetIds[6]}.getRealm() == managerTestSetup.realmBuildingTenant
- assert syncedAssets.find {it.id == assetIds[6]}.getParentId() == assetIds[5]
- assert syncedAssets.find {it.id == assetIds[6]}.getAttribute("temp").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
- assert syncedAssets.find {it.id == assetIds[6]}.getAttribute("tempSetpoint").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
+ assert syncedAssets.stream().filter{syncedAsset -> sendAssets.stream().anyMatch{mapAssetId(gateway.getId(), it.id, false) == syncedAsset.id}}.count() == sendAssets.size()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[0]}.getName() == "Test Agent 1"
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[0]}.getType() == AssetType.AGENT.type
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[0]}.getRealm() == managerTestSetup.realmBuildingTenant
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[0]}.getParentId() == gateway.getId()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[4]}.getName() == "Test Agent 5"
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[4]}.getType() == AssetType.AGENT.type
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[4]}.getRealm() == managerTestSetup.realmBuildingTenant
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == agentAssetIds[4]}.getParentId() == gateway.getId()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getName() == "Test Building 1"
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getType() == AssetType.BUILDING.type
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getRealm() == managerTestSetup.realmBuildingTenant
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getParentId() == gateway.getId()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().x == 10
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().y == 11
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getAttribute(AttributeType.LOCATION).flatMap{it.getMetaItem(MetaItemType.ACCESS_PUBLIC_READ)}.isPresent()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[0]}.getAttribute(AttributeType.SURFACE_AREA).flatMap {it.getValueAsNumber()}.orElse(0d) == 1000
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[1]}.getName() == "Test Building 1 Room 1"
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[1]}.getType() == AssetType.ROOM.type
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[1]}.getRealm() == managerTestSetup.realmBuildingTenant
+ assert mapAssetId(gateway.getId(), syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[1]}.getParentId(), true) == assetIds[0]
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[1]}.getAttribute("temp").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[1]}.getAttribute("tempSetpoint").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getName() == "Test Building 2"
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getType() == AssetType.BUILDING.type
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getRealm() == managerTestSetup.realmBuildingTenant
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getParentId() == gateway.getId()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().x == 10
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getAttribute(AttributeType.LOCATION).flatMap {GeoJSONPoint.fromValue(it.getValue().orElse(null))}.get().y == 11
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getAttribute(AttributeType.LOCATION).flatMap{it.getMetaItem(MetaItemType.ACCESS_PUBLIC_READ)}.isPresent()
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[5]}.getAttribute(AttributeType.SURFACE_AREA).flatMap {it.getValueAsNumber()}.orElse(0d) == 1000
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[6]}.getName() == "Test Building 2 Room 1"
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[6]}.getType() == AssetType.ROOM.type
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[6]}.getRealm() == managerTestSetup.realmBuildingTenant
+ assert mapAssetId(gateway.getId(), syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[6]}.getParentId(), true) == assetIds[5]
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[6]}.getAttribute("temp").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
+ assert syncedAssets.find {mapAssetId(gateway.getId(), it.id, true) == assetIds[6]}.getAttribute("tempSetpoint").map{it.hasMetaItem(MetaItemType.AGENT_LINK)}.orElse(false)
}
and: "the central manager should have requested the full loading of the second batch of assets"
@@ -369,7 +371,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
advancePseudoClock(1, TimeUnit.SECONDS, container)
and: "an attribute event for a gateway descendant asset (building 1 room 1) is sent to the local manager"
- assetProcessingService.sendAttributeEvent(new AttributeEvent(assetIds[1], "tempSetpoint", Values.create(20d)))
+ assetProcessingService.sendAttributeEvent(new AttributeEvent(mapAssetId(gateway.id, assetIds[1], false), "tempSetpoint", Values.create(20d)))
then: "the event should have been forwarded to the gateway"
conditions.eventually {
@@ -383,7 +385,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the descendant asset in the local manager should contain the new attribute value"
conditions.eventually {
- def building1Room1Asset = assetStorageService.find(assetIds[1])
+ def building1Room1Asset = assetStorageService.find(mapAssetId(gateway.id, assetIds[1], false))
assert building1Room1Asset.getAttribute("tempSetpoint").flatMap {it.getValueAsNumber()}.orElse(0d) == 20d
}
@@ -420,14 +422,15 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
gatewayClient.sendMessage(SharedEvent.MESSAGE_PREFIX + Container.JSON.writeValueAsString(new AssetEvent(AssetEvent.Cause.CREATE, building1Room5Asset, null)))
then: "the asset should be replicated in the local manager"
+ def localBuilding1Room5Asset
conditions.eventually {
- building1Room5Asset = assetStorageService.find(building1Room5AssetId)
- assert building1Room5Asset != null
- assert building1Room5Asset.getName() == "Test Building 1 Room 5"
- assert building1Room5Asset.getType() == AssetType.ROOM.type
- assert building1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
- assert building1Room5Asset.getParentId() == assetIds[0]
- assert building1Room5Asset.getAttributesList().size() == 3
+ localBuilding1Room5Asset = assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false))
+ assert localBuilding1Room5Asset != null
+ assert localBuilding1Room5Asset.getName() == "Test Building 1 Room 5"
+ assert localBuilding1Room5Asset.getType() == AssetType.ROOM.type
+ assert localBuilding1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
+ assert localBuilding1Room5Asset.getParentId() == mapAssetId(gateway.id, assetIds[0], false)
+ assert localBuilding1Room5Asset.getAttributesList().size() == 3
}
when: "an asset is modified on the gateway and the local manager is notified"
@@ -444,15 +447,15 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the asset should also be updated in the local manager"
conditions.eventually {
- building1Room5Asset = assetStorageService.find(building1Room5AssetId)
- assert building1Room5Asset != null
- assert building1Room5Asset.getVersion() == 1
- assert building1Room5Asset.getName() == "Test Building 1 Room 5 Updated"
- assert building1Room5Asset.getType() == AssetType.ROOM.type
- assert building1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
- assert building1Room5Asset.getParentId() == assetIds[0]
- assert building1Room5Asset.getAttributesList().size() == 4
- assert building1Room5Asset.getAttribute("co2Level").flatMap{it.getValueAsNumber()}.orElse(0d) == 500d
+ localBuilding1Room5Asset = assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false))
+ assert localBuilding1Room5Asset != null
+ assert localBuilding1Room5Asset.getVersion() == 1
+ assert localBuilding1Room5Asset.getName() == "Test Building 1 Room 5 Updated"
+ assert localBuilding1Room5Asset.getType() == AssetType.ROOM.type
+ assert localBuilding1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
+ assert localBuilding1Room5Asset.getParentId() == mapAssetId(gateway.id, assetIds[0], false)
+ assert localBuilding1Room5Asset.getAttributesList().size() == 4
+ assert localBuilding1Room5Asset.getAttribute("co2Level").flatMap{it.getValueAsNumber()}.orElse(0d) == 500d
}
when: "an asset is deleted on the gateway and the local manager is notified"
@@ -460,7 +463,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the asset should also be deleted in the local manager"
conditions.eventually {
- def asset = assetStorageService.find(building1Room5AssetId)
+ def asset = assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false))
assert asset == null
}
@@ -478,40 +481,43 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
}
}
}, 100, 100))
- building1Room5Asset = assetStorageService.merge(building1Room5Asset)
- building1Room5Asset = assetStorageService.find(building1Room5AssetId) // Re-fetch asset as modifying instance returned by merge will cause concurrency issues
+ assetStorageService.merge(localBuilding1Room5Asset)
+ localBuilding1Room5Asset = assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false)) // Re-fetch asset as modifying instance returned by merge will cause concurrency issues
then: "the asset should have been added to the gateway and eventually replicated in the local manager"
- assert building1Room5Asset != null
- assert assetStorageService.find(building1Room5AssetId).version == building1Room5Asset.version
+ assert localBuilding1Room5Asset != null
+ assert assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false)).version == localBuilding1Room5Asset.version
when: "the client received messages are cleared"
clientReceivedMessages.clear()
and: "an asset is modified under the gateway in the local manager and the gateway responds that it successfully updated the asset"
- building1Room5Asset.setName("Test Building 1 Room 5")
- building1Room5Asset.removeAttribute("co2Level")
+ localBuilding1Room5Asset.setName("Test Building 1 Room 5")
+ localBuilding1Room5Asset.removeAttribute("co2Level")
responseFuture.set(executorService.scheduleAtFixedRate({
if (!clientReceivedMessages.isEmpty()) {
def assetAddEvent = Container.JSON.readValue(clientReceivedMessages[0].substring(SharedEvent.MESSAGE_PREFIX.length()), AssetEvent.class)
if (assetAddEvent.cause == AssetEvent.Cause.UPDATE && assetAddEvent.asset.id.equals(building1Room5AssetId)) {
+ building1Room5Asset.setName(localBuilding1Room5Asset.name)
+ building1Room5Asset.removeAttribute("co2Level")
gatewayClient.sendMessage(SharedEvent.MESSAGE_PREFIX + Container.JSON.writeValueAsString(new AssetEvent(AssetEvent.Cause.UPDATE, building1Room5Asset, null)))
responseFuture.get().cancel(false)
}
}
}, 100, 100))
- building1Room5Asset = assetStorageService.merge(building1Room5Asset)
- building1Room5Asset = assetStorageService.find(building1Room5AssetId) // Re-fetch asset as modifying instance returned by merge will cause concurrency issues
+ localBuilding1Room5Asset = assetStorageService.merge(localBuilding1Room5Asset)
+ def version = localBuilding1Room5Asset.version
+ localBuilding1Room5Asset = assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false)) // Re-fetch asset as modifying instance returned by merge will cause concurrency issues
then: "the asset should also be updated in the local manager"
- assert building1Room5Asset != null
- assert building1Room5Asset.getVersion() == 2
- assert building1Room5Asset.getName() == "Test Building 1 Room 5"
- assert building1Room5Asset.getType() == AssetType.ROOM.type
- assert building1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
- assert building1Room5Asset.getParentId() == assetIds[0]
- assert building1Room5Asset.getAttributesList().size() == 3
- assert assetStorageService.find(building1Room5AssetId).version == building1Room5Asset.version
+ assert localBuilding1Room5Asset != null
+ assert localBuilding1Room5Asset.getVersion() == 2
+ assert localBuilding1Room5Asset.getName() == "Test Building 1 Room 5"
+ assert localBuilding1Room5Asset.getType() == AssetType.ROOM.type
+ assert localBuilding1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
+ assert localBuilding1Room5Asset.getParentId() == mapAssetId(gateway.id, assetIds[0], false)
+ assert localBuilding1Room5Asset.getAttributesList().size() == 3
+ assert localBuilding1Room5Asset.version == version
when: "the client received messages are cleared"
clientReceivedMessages.clear()
@@ -528,12 +534,12 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
}
}
}, 100, 100))
- def deleted = assetStorageService.delete([building1Room5AssetId])
+ def deleted = assetStorageService.delete([mapAssetId(gateway.id, building1Room5AssetId, false)])
then: "the asset should have been deleted"
assert deleted
conditions.eventually {
- assert assetStorageService.find(building1Room5AssetId) == null
+ assert assetStorageService.find(mapAssetId(gateway.id, building1Room5AssetId, false)) == null
}
when: "time advances"
@@ -739,7 +745,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "all descendant assets should have been removed"
conditions.eventually {
- assert assetStorageService.find(assets[0].id) == null
+ assert assetStorageService.find(mapAssetId(gateway.id, assets[0].id, true)) == null
}
then: "the keycloak client should also be removed"
@@ -751,99 +757,9 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
def "Verify gateway client service"() {
- given: "a spy gateway client service"
- // This spy maps asset IDs to fake IDs to allow both the client and central manager to actually be the same
- // manager instance
- Map<String, String> realIdToFakeIdMap = new HashMap<>()
- Map<String, String> fakeIdToRealIdMap = new HashMap<>()
- GatewayClientService spyGatewayClientService = Spy(GatewayClientService) {
- messageToString(_ as String, _ as Object) >> {
- String prefix, Object ev ->
- String messageId
- Object event = ev
-
- if (ev instanceof EventRequestResponseWrapper) {
- messageId = ev.messageId
- event = ev.event
- }
-
- if (event instanceof AssetsEvent) {
- if (GatewayConnector.ASSET_READ_EVENT_NAME_INITIAL.equals(messageId)) {
- // Store real IDs and map to a fake IDs
- event.getAssets().forEach {
- String oldId = it.id
- it.id = UniqueIdentifierGenerator.generateId()
- realIdToFakeIdMap.put(oldId, it.id)
- fakeIdToRealIdMap.put(it.id, oldId)
- }
- } else {
- event.getAssets().forEach {
- it.id = realIdToFakeIdMap.get(it.id)
- it.parentId = it.parentId == null ? null : realIdToFakeIdMap.get(it.parentId)
- }
- }
- } else if (event instanceof AssetEvent) {
- if (!realIdToFakeIdMap.containsKey(event.asset.id)) {
- def fakeId = UniqueIdentifierGenerator.generateId()
- realIdToFakeIdMap.put(event.asset.id, fakeId)
- fakeIdToRealIdMap.put(fakeId, event.asset.id)
- }
- event.asset.id = realIdToFakeIdMap.get(event.entityId)
- event.asset.parentId = event.parentId == null ? null : realIdToFakeIdMap.get(event.parentId)
- } else if (event instanceof AttributeEvent) {
- event.attributeState = new AttributeState(
- realIdToFakeIdMap.get(event.entityId),
- event.attributeState.attributeRef.attributeName,
- event.attributeState.value.orElse(null)
- )
- event.parentId = event.parentId == null ? null : realIdToFakeIdMap.get(event.parentId)
- }
-
- return callRealMethodWithArgs(prefix, ev)
- }
-
- messageFromString(_ as String, _ as String, _ as Class) >> {
- String message, String prefix, Class clazz ->
- Object ev = callRealMethod()
- Object event = ev
-
- if (event instanceof EventRequestResponseWrapper) {
- event = event.event
- }
- if (event instanceof ReadAssetsEvent) {
- if (event.assetQuery.ids != null && event.assetQuery.ids.length > 0) {
- event.assetQuery.ids(Arrays.stream(event.assetQuery.ids).map{fakeIdToRealIdMap.get(it)}.toArray{new String[it]})
- }
- }
- if (event instanceof AssetEvent) {
- if (fakeIdToRealIdMap.containsKey(event.entityId)) {
- event.asset.id = fakeIdToRealIdMap.get(event.entityId)
- } else {
- // This is a new asset creation originating from the central manager
- def id = UniqueIdentifierGenerator.generateId()
- realIdToFakeIdMap.put(id, event.entityId)
- fakeIdToRealIdMap.put(event.entityId, id)
- }
- event.asset.id = fakeIdToRealIdMap.get(event.entityId)
- event.asset.parentId = event.parentId == null ? null : fakeIdToRealIdMap.get(event.parentId)
- } else if (event instanceof AttributeEvent) {
- event.attributeState = new AttributeState(
- fakeIdToRealIdMap.get(event.entityId),
- event.attributeState.attributeRef.attributeName,
- event.attributeState.value.orElse(null)
- )
- event.parentId = event.parentId == null ? null : fakeIdToRealIdMap.get(event.parentId)
- } else if (event instanceof DeleteAssetsRequestEvent) {
- event.assetIds = event.assetIds.stream().map{fakeIdToRealIdMap.get(it)}.collect(Collectors.toList())
- }
- return ev
- }
- }
-
- and: "the container environment is started with the spy gateway client service"
+ given: "the container environment is started with the spy gateway client service"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
def services = Lists.newArrayList(defaultServices())
- services.replaceAll{it instanceof GatewayClientService ? spyGatewayClientService : it}
def container = startContainer(defaultConfig(), services)
def assetProcessingService = container.getService(AssetProcessingService.class)
def assetStorageService = container.getService(AssetStorageService.class)
@@ -886,7 +802,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
assert gatewayService.gatewayConnectorMap.get(gateway.getId()).gatewayId == gateway.getId()
}
- when: "a gateway client connection is created to connect the city realm to the gateway"
+ when: "a gateway client connection is created to connect the city realm to the gateway in the building realm"
def gatewayConnection = new GatewayConnection(
"127.0.0.1",
serverPort,
@@ -909,10 +825,11 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
assert gateway.getAttribute("status").flatMap{it.getValueAsString()}.orElse(null) == ConnectionStatus.CONNECTED.name()
}
- and: "the fake mirrored assets should have been created under the gateway asset"
+ and: "the assets should have been created under the gateway asset"
conditions.eventually {
- def fakeAssets = assetStorageService.findAll(new AssetQuery().parents(gateway.id).recursive(true))
- assert fakeAssets.size() == realIdToFakeIdMap.size()
+ def gatewayAssets = assetStorageService.findAll(new AssetQuery().parents(gateway.id).recursive(true))
+ def cityAssets = assetStorageService.findAll(new AssetQuery().tenant(new TenantPredicate(managerTestSetup.realmCityTenant)))
+ assert gatewayAssets.size() == cityAssets.size()
}
when: "a gateway client asset is modified"
@@ -926,7 +843,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the mirrored asset under the gateway should have also been updated"
conditions.eventually {
- def mirroredMicrophone = assetStorageService.find(realIdToFakeIdMap.get(managerTestSetup.microphone1Id))
+ def mirroredMicrophone = assetStorageService.find(mapAssetId(gateway.id, managerTestSetup.microphone1Id, false))
assert mirroredMicrophone != null
assert mirroredMicrophone.getAttribute("microphoneLevel").flatMap{it.getMetaItem(MetaItemType.UNIT_TYPE)}.flatMap{it.getValueAsString()}.orElse("") == UNITS_SOUND_DECIBELS
assert mirroredMicrophone.getAttribute("test").isPresent()
@@ -943,21 +860,21 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the new asset should have been created in the gateway and also mirrored under the gateway asset"
assert microphone2.id != null
conditions.eventually {
- def mirroredMicrophone2 = assetStorageService.find(realIdToFakeIdMap.get(microphone2.id))
+ def mirroredMicrophone2 = assetStorageService.find(mapAssetId(gateway.id, microphone2.id, false))
assert mirroredMicrophone2 != null
assert mirroredMicrophone2.getAttribute("microphoneLevel").isPresent()
assert mirroredMicrophone2.getAttribute("test").flatMap{it.getValueAsString()}.orElse("") == "testValue"
}
- when: "an asset is added under the gateway client"
+ when: "an asset is added under the gateway asset"
def microphone3 = new Asset()
- Asset.map(microphone1, microphone3, "Microphone 3", managerTestSetup.realmBuildingTenant, realIdToFakeIdMap.get(managerTestSetup.area1Id), null, null, null)
+ Asset.map(microphone1, microphone3, "Microphone 3", managerTestSetup.realmBuildingTenant, mapAssetId(gateway.id, managerTestSetup.area1Id, false), null, null, null)
microphone3 = assetStorageService.merge(microphone3)
then: "the new asset should have been created in the gateway and also mirrored under the gateway asset"
assert microphone3.id != null
conditions.eventually {
- def gatewayMicrophone3 = assetStorageService.find(fakeIdToRealIdMap.get(microphone3.id))
+ def gatewayMicrophone3 = assetStorageService.find(mapAssetId(gateway.id, microphone3.id, true))
assert gatewayMicrophone3 != null
assert gatewayMicrophone3.getAttribute("microphoneLevel").isPresent()
}
@@ -965,7 +882,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
and: "the new asset microphone level should be correctly linked to the simulator protocol only on the gateway"
conditions.eventually {
assert !simulatorProtocol.elements.containsKey(new AttributeRef(microphone3.id, "microphoneLevel"))
- assert simulatorProtocol.elements.containsKey(new AttributeRef(fakeIdToRealIdMap.get(microphone3.id), "microphoneLevel"))
+ assert simulatorProtocol.elements.containsKey(new AttributeRef(mapAssetId(gateway.id, microphone3.id, true), "microphoneLevel"))
}
when: "an attribute is updated on the gateway client"
@@ -973,7 +890,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the mirrored asset attribute should also be updated"
conditions.eventually {
- def mirroredMicrophone2 = assetStorageService.find(realIdToFakeIdMap.get(microphone2.id))
+ def mirroredMicrophone2 = assetStorageService.find(mapAssetId(gateway.id, microphone2.id, false))
assert mirroredMicrophone2 != null
assert mirroredMicrophone2.getAttribute("test").flatMap{it.getValueAsString()}.orElse("") == "newValue"
}
@@ -982,12 +899,12 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
advancePseudoClock(1, TimeUnit.SECONDS, container)
and: "a mirrored asset attribute is updated"
- assetProcessingService.sendAttributeEvent(new AttributeEvent(realIdToFakeIdMap.get(microphone2.id), "test", Values.create("newerValue")))
+ assetProcessingService.sendAttributeEvent(new AttributeEvent(mapAssetId(gateway.id, microphone2.id, false), "test", Values.create("newerValue")))
then: "the attribute should be updated on the gateway client and the mirrored asset"
conditions.eventually {
microphone2 = assetStorageService.find(microphone2.id)
- def mirroredMicrophone2 = assetStorageService.find(realIdToFakeIdMap.get(microphone2.id))
+ def mirroredMicrophone2 = assetStorageService.find(mapAssetId(gateway.id, microphone2.id, false))
assert microphone2 != null
assert mirroredMicrophone2 != null
assert microphone2.getAttribute("test").flatMap{it.getValueAsString()}.orElse("") == "newerValue"
@@ -1000,7 +917,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
then: "the client asset should have been deleted and also the mirrored asset under the gateway should also be deleted"
assert deleted
conditions.eventually {
- assert assetStorageService.find(realIdToFakeIdMap.get(managerTestSetup.microphone1Id)) == null
+ assert assetStorageService.find(mapAssetId(gateway.id, managerTestSetup.microphone1Id, false)) == null
}
}
}