Skip to content

armgit / core

Public Imported from GitHub
0

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

Updated AssetQuery default behaviour to select all if no select specified (select is then used to restrict the query projection)

Rich Turnercefffd366d61
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index 8017bc5e8..8550334b8 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -493,7 +493,6 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
// Get all assets that have attributes that use this protocol configuration
List<Asset> assets = assetStorageService.findAll(
new AssetQuery()
- .select(AssetQuery.Select.selectAll())
.attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
@@ -523,7 +522,6 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
// Get all assets that have attributes that use this protocol configuration
List<Asset> assets = assetStorageService.findAll(
new AssetQuery()
- .select(AssetQuery.Select.selectAll())
.attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
@@ -763,7 +761,6 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
return withLockReturning(getClass().getSimpleName() + "::getAgents", () -> {
if (agentMap == null) {
agentMap = assetStorageService.findAll(new AssetQuery()
- .select(AssetQuery.Select.selectAll())
.types(AssetType.AGENT))
.stream()
.collect(Collectors.toMap(Asset::getId, agent -> agent));
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java
index 64aa47de1..385d38598 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetAttributeLinkingService.java
@@ -258,7 +258,7 @@ public class AssetAttributeLinkingService implements ContainerService, AssetUpda
em,
new AssetQuery()
.ids(attributeRef.getEntityId())
- .select(Select.selectAll().attributes(attributeRef.getAttributeName()))
+ .select(new Select().attributes(attributeRef.getAttributeName()))
);
AssetAttribute attribute = asset != null ? asset.getAttribute(attributeRef.getAttributeName()).orElse(null) : null;
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index 9929881ae..774e3b900 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -53,6 +53,7 @@ import static org.openremote.container.Container.JSON;
import static org.openremote.model.attribute.AttributeEvent.Source.CLIENT;
import static org.openremote.model.attribute.MetaItemType.ACCESS_RESTRICTED_READ;
import static org.openremote.model.query.AssetQuery.Access;
+import static org.openremote.model.query.AssetQuery.Select.selectExcludePathAndAttributes;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;
public class AssetResourceImpl extends ManagerWebResource implements AssetResource {
@@ -82,6 +83,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
if (!isRestrictedUser()) {
List<Asset> result = assetStorageService.findAll(
new AssetQuery()
+ .select(selectExcludePathAndAttributes())
.parents(new ParentPredicate(true))
.tenant(new TenantPredicate(getAuthenticatedRealm()))
);
@@ -90,7 +92,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
List<Asset> assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectExcludePathAndAttributes().meta(ACCESS_RESTRICTED_READ))
+ .select(selectExcludePathAndAttributes().meta(ACCESS_RESTRICTED_READ))
.userIds(getUserId())
);
@@ -514,7 +516,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
if (isRestrictedUser()) {
throw new WebApplicationException(FORBIDDEN);
}
- List<Asset> assets = assetStorageService.findAll(new AssetQuery().ids(assetIds.toArray(new String[0])).select(Select.selectExcludePathAndAttributes()));
+ List<Asset> assets = assetStorageService.findAll(new AssetQuery().ids(assetIds.toArray(new String[0])).select(selectExcludePathAndAttributes()));
if (assets == null || assets.size() != assetIds.size()) {
LOG.fine("Request to delete one or more invalid assets");
return;
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
index b8987f922..e2dc6b424 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -263,7 +263,6 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
Asset asset = find(
new AssetQuery()
- .select(Select.selectAll())
.ids(event.getAssetId())
.access(access));
@@ -289,7 +288,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
public Asset find(String assetId, boolean loadComplete) {
if (assetId == null)
throw new IllegalArgumentException("Can't query null asset identifier");
- return find(new AssetQuery().select(loadComplete ? Select.selectAll() : Select.selectExcludePathAndAttributes()).ids(assetId));
+ return find(new AssetQuery().select(loadComplete ? null : Select.selectExcludePathAndAttributes()).ids(assetId));
}
/**
@@ -308,7 +307,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
throw new IllegalArgumentException("Can't query null asset identifier");
return find(new AssetQuery()
.select(loadComplete
- ? Select.selectAll()
+ ? null
: Select.selectExcludePathAndAttributes())
.ids(assetId)
.access(access));
@@ -672,7 +671,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
em,
new AssetQuery()
.select(loadComplete
- ? Select.selectAll()
+ ? null
: Select.selectExcludePathAndAttributes())
.ids(assetId)
.access(access)
@@ -681,9 +680,6 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
protected List<Asset> findAll(EntityManager em, AssetQuery query) {
- // Use a default projection if it's missing
- if (query.select == null)
- query.select = new Select();
if (query.access == null)
query.access = PRIVATE;
@@ -758,25 +754,25 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
sb.append(", A.CREATED_ON AS CREATED_ON, A.ASSET_TYPE AS ASSET_TYPE, A.PARENT_ID AS PARENT_ID");
sb.append(", A.REALM AS REALM, A.OBJ_VERSION as OBJ_VERSION");
- if (!select.excludeParentInfo) {
+ if (select == null || !select.excludeParentInfo) {
sb.append(", P.NAME as PARENT_NAME, P.ASSET_TYPE as PARENT_TYPE");
}
- if (!select.excludeRealm) {
+ if (select == null ||!select.excludeRealm) {
if (!query.recursive || level == 3) {
sb.append(", R.NAME as TENANT_NAME");
}
}
if (!query.recursive || level == 3) {
- if (!select.excludePath) {
+ if (select == null || !select.excludePath) {
sb.append(", get_asset_tree_path(A.ID) as PATH");
} else {
sb.append(", NULL as PATH");
}
}
- if (!select.excludeAttributes) {
+ if (select == null || !select.excludeAttributes) {
if (query.recursive && level != 3) {
sb.append(", A.ATTRIBUTES as ATTRIBUTES");
} else {
@@ -792,32 +788,32 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
protected String buildAttributeSelect(AssetQuery query, List<ParameterBinder> binders) {
Select select = query.select;
- boolean hasMetaFilter = !select.excludeAttributeMeta && select.meta != null && select.meta.length > 0;
- boolean fullyPopulateAttributes = !(select.excludeAttributeMeta || select.excludeAttributeValue || select.excludeAttributeTimestamp || select.meta != null);
+ boolean hasMetaFilter = select != null && !select.excludeAttributeMeta && select.meta != null && select.meta.length > 0;
+ boolean fullyPopulateAttributes = select == null || !(select.excludeAttributeMeta || select.excludeAttributeValue || select.excludeAttributeTimestamp || select.meta != null);
- if (select.attributes == null && query.access == PRIVATE && fullyPopulateAttributes) {
+ if ((select == null || select.attributes == null) && query.access == PRIVATE && fullyPopulateAttributes) {
return ", A.ATTRIBUTES as ATTRIBUTES";
}
StringBuilder attributeBuilder = new StringBuilder();
- if (select.excludeAttributeMeta) {
+ if (select != null && select.excludeAttributeMeta) {
attributeBuilder.append(" - 'meta'");
}
- if (select.excludeAttributeTimestamp) {
+ if (select != null && select.excludeAttributeTimestamp) {
attributeBuilder.append(" - 'valueTimestamp'");
}
- if (select.excludeAttributeValue) {
+ if (select != null && select.excludeAttributeValue) {
attributeBuilder.append(" - 'value'");
}
- if (select.excludeAttributeType) {
+ if (select != null && select.excludeAttributeType) {
attributeBuilder.append(" - 'type'");
}
StringBuilder sb = new StringBuilder();
sb.append(", (");
- if (select.excludeAttributeMeta) {
+ if (select != null && select.excludeAttributeMeta) {
sb.append("select json_object_agg(AX.key, AX.value");
sb.append(attributeBuilder);
sb.append(") from jsonb_each(A.attributes) as AX");
@@ -858,7 +854,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
sb.append(" where true");
// Filter attributes
- if (select.attributes != null && select.attributes.length > 0) {
+ if (select != null && select.attributes != null && select.attributes.length > 0) {
sb.append(" AND AX.key IN (");
for (int i = 0; i < select.attributes.length; i++) {
sb.append(i == select.attributes.length - 1 ? "?" : "?,");
@@ -888,7 +884,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
// level = 3 is CTE
StringBuilder sb = new StringBuilder();
boolean recursive = query.recursive;
- boolean includeRealmInfo = !query.select.excludeRealm;
+ boolean includeRealmInfo = query.select == null || !query.select.excludeRealm;
if (level == 1) {
sb.append(" from Asset A ");
@@ -1531,23 +1527,23 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
asset.setCreatedOn(rs.getTimestamp("CREATED_ON"));
asset.setAccessPublicRead(rs.getBoolean("ACCESS_PUBLIC_READ"));
- if (!query.select.excludeParentInfo) {
+ if (query.select == null || !query.select.excludeParentInfo) {
asset.setParentId(rs.getString("PARENT_ID"));
asset.setParentName(rs.getString("PARENT_NAME"));
asset.setParentType(rs.getString("PARENT_TYPE"));
}
- if (!query.select.excludeRealm) {
+ if (query.select == null || !query.select.excludeRealm) {
asset.setRealm(rs.getString("REALM"));
}
- if (!query.select.excludeAttributes) {
+ if (query.select == null || !query.select.excludeAttributes) {
if (rs.getString("ATTRIBUTES") != null) {
asset.setAttributes(Values.instance().<ObjectValue>parse(rs.getString("ATTRIBUTES")).orElse(null));
}
}
- if (!query.select.excludePath) {
+ if (query.select == null || !query.select.excludePath) {
Array path = rs.getArray("PATH");
if (path != null) {
asset.setPath((String[]) path.getArray());
@@ -1616,7 +1612,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
switch (persistenceEvent.getCause()) {
case CREATE:
// Fully load the asset
- Asset loadedAsset = find(new AssetQuery().select(Select.selectAll()).ids(asset.getId()));
+ Asset loadedAsset = find(new AssetQuery().ids(asset.getId()));
clientEventService.publishEvent(
new AssetEvent(AssetEvent.Cause.CREATE, loadedAsset, null)
@@ -1662,7 +1658,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
}).toArray(String[]::new);
// Fully load the asset
- loadedAsset = find(new AssetQuery().select(Select.selectAll()).ids(asset.getId()));
+ loadedAsset = find(new AssetQuery().ids(asset.getId()));
clientEventService.publishEvent(
new AssetEvent(AssetEvent.Cause.UPDATE, loadedAsset, updatedProperties)
diff --git a/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java
index 3c1cd6ce4..a8f902d49 100644
--- a/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java
+++ b/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java
@@ -121,7 +121,7 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatio
// Find all console assets that use this adapter
assetStorageService.findAll(
new AssetQuery()
- .select(AssetQuery.Select.selectAll().excludePath(true)
+ .select(new AssetQuery.Select().excludePath(true)
.attributes(AttributeType.CONSOLE_PROVIDERS.getAttributeName()))
.types(CONSOLE)
.attributeValue(AttributeType.CONSOLE_PROVIDERS.getAttributeName(),
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
index 5a1ffe141..825ed1e45 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -68,6 +68,7 @@ import static org.openremote.container.util.MapAccess.getString;
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.query.AssetQuery.Select.selectExcludePathAndAttributes;
/**
* Manages {@link RulesEngine}s for stored {@link Ruleset}s and processes asset attribute updates.
@@ -752,7 +753,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
protected Stream<Pair<Asset, Stream<AssetAttribute>>> findRuleStateAttributes() {
List<Asset> assets = assetStorageService.findAll(
new AssetQuery()
- .select(AssetQuery.Select.selectAll())
+ .select(selectExcludePathAndAttributes())
.attributeMeta(
new AttributeMetaPredicate(
MetaItemType.RULE_STATE,
diff --git a/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java b/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java
index dd6e04e00..9359c21c3 100644
--- a/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java
+++ b/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java
@@ -82,9 +82,6 @@ public class AssetsFacade<T extends Ruleset> extends Assets {
AssetQuery.Select oldValue = assetQuery.select;
- if (assetQuery.select == null)
- assetQuery.select = new AssetQuery.Select();
-
assetQuery.select = AssetQuery.Select.selectExcludeAll();
try {
diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
index 5a2c9d6fc..0494a6279 100644
--- a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
@@ -102,7 +102,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
assetStorageService.findAll(
new AssetQuery()
- .select(AssetQuery.Select.selectAll().excludePath(true)
+ .select(new AssetQuery.Select().excludePath(true)
.attributes(AttributeType.CONSOLE_PROVIDERS.getAttributeName()))
.types(CONSOLE)
.attributeValue(AttributeType.CONSOLE_PROVIDERS.getAttributeName(),
diff --git a/model/src/main/java/org/openremote/model/query/AssetQuery.java b/model/src/main/java/org/openremote/model/query/AssetQuery.java
index bc56ce5ee..e8ee0737e 100644
--- a/model/src/main/java/org/openremote/model/query/AssetQuery.java
+++ b/model/src/main/java/org/openremote/model/query/AssetQuery.java
@@ -36,30 +36,15 @@ public class AssetQuery {
public String[] attributes;
public String[] meta;
- public boolean excludePath = true;
- public boolean excludeAttributeMeta = true;
- public boolean excludeAttributes = true;
- public boolean excludeAttributeValue = true;
- public boolean excludeAttributeTimestamp = true;
- public boolean excludeAttributeType = true;
+ public boolean excludePath;
+ public boolean excludeAttributeMeta;
+ public boolean excludeAttributes;
+ public boolean excludeAttributeValue;
+ public boolean excludeAttributeTimestamp;
+ public boolean excludeAttributeType;
public boolean excludeParentInfo;
public boolean excludeRealm;
- public Select() {
- }
-
- public static Select selectAll() {
- return new Select()
- .excludeAttributes(false)
- .excludeAttributeMeta(false)
- .excludeAttributeType(false)
- .excludeAttributeTimestamp(false)
- .excludeAttributeValue(false)
- .excludePath(false)
- .excludeParentInfo(false)
- .excludeRealm(false);
- }
-
public static Select selectExcludePathAndParentAndRealm() {
return new Select()
.excludeAttributes(false)
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
index ec7fe29f6..a53f6a46b 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
@@ -83,7 +83,6 @@ class AssetPublicQueryTest extends Specification implements ManagerContainerTrai
when: "a query for a specific public asset is executed"
def query = new AssetQuery()
- .select(Select.selectAll())
.ids(returnedAssets.get(0).id)
def assets = assetResource.queryPublicAssets(null, query)
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index 123827889..1b0a083da 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -39,6 +39,7 @@ import static org.openremote.model.query.AssetQuery.Access.PRIVATE
import static org.openremote.model.query.AssetQuery.Access.PROTECTED
import static org.openremote.model.query.AssetQuery.OrderBy.Property.CREATED_ON
import static org.openremote.model.query.AssetQuery.OrderBy.Property.NAME
+import static org.openremote.model.query.AssetQuery.Select.selectExcludePathAndAttributes
class AssetQueryTest extends Specification implements ManagerContainerTrait {
@@ -145,7 +146,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed that returns a protected attribute without any other meta items"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll().excludePath(true))
+ .select(new Select().excludePath(true))
.ids(managerDemoSetup.apartment2LivingroomId)
.access(PROTECTED)
)
@@ -228,7 +229,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
asset = assetStorageService.find(
new AssetQuery()
- .ids(managerDemoSetup.smartOfficeId)
+ .select(selectExcludePathAndAttributes())
+ .ids(managerDemoSetup.smartOfficeId)
)
then: "result should match"
@@ -247,8 +249,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
asset = assetStorageService.find(
new AssetQuery()
- .select(Select.selectAll())
- .ids(managerDemoSetup.smartOfficeId)
+ .ids(managerDemoSetup.smartOfficeId)
)
then: "result should match"
@@ -268,8 +269,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .parents(new ParentPredicate(true))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .select(selectExcludePathAndAttributes())
+ .parents(new ParentPredicate(true))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -289,9 +291,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll())
- .parents(new ParentPredicate(true))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .parents(new ParentPredicate(true))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -312,7 +313,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
+ .select(selectExcludePathAndAttributes())
+ .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
)
then: "result should match"
@@ -333,8 +335,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
+ .select(selectExcludePathAndAttributes())
+ .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
)
then: "result should match"
@@ -346,9 +349,10 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
- .orderBy(new OrderBy(NAME, true))
+ .select(selectExcludePathAndAttributes())
+ .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
+ .orderBy(new OrderBy(NAME, true))
)
then: "result should match"
@@ -360,8 +364,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .select(selectExcludePathAndAttributes())
+ .parents(new ParentPredicate(managerDemoSetup.smartBuildingId))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -370,7 +375,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .paths(new PathPredicate(assetStorageService.find(managerDemoSetup.apartment1Id, true).getPath()))
+ .select(selectExcludePathAndAttributes())
+ .paths(new PathPredicate(assetStorageService.find(managerDemoSetup.apartment1Id, true).getPath()))
)
then: "result should match"
@@ -386,8 +392,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .paths(new PathPredicate(assetStorageService.find(managerDemoSetup.apartment1Id, true).getPath()))
- .types(AssetType.ROOM)
+ .select(selectExcludePathAndAttributes())
+ .paths(new PathPredicate(assetStorageService.find(managerDemoSetup.apartment1Id, true).getPath()))
+ .types(AssetType.ROOM)
)
then: "result should match"
@@ -401,7 +408,6 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll())
.userIds(keycloakDemoSetup.testuser3Id)
.access(PROTECTED)
)
@@ -422,7 +428,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().select(Select.selectAll())
+ new AssetQuery()
.userIds(keycloakDemoSetup.testuser2Id)
.access(PROTECTED)
)
@@ -447,7 +453,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
def assets = assetStorageService.findAll(
- new AssetQuery().types(AssetType.AGENT)
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .types(AssetType.AGENT)
)
then: "result should match"
@@ -457,7 +465,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.get(2).id == managerDemoSetup.smartCityServiceAgentId
when: "a query is executed"
- assets = assetStorageService.findAll(new AssetQuery()
+ assets = assetStorageService.findAll(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
.types(THING)
.parents(new ParentPredicate(managerDemoSetup.agentId))
)
@@ -467,7 +477,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.get(0).id == managerDemoSetup.thingId
when: "a query is executed"
- assets = assetStorageService.findAll(new AssetQuery()
+ assets = assetStorageService.findAll(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
.types(THING)
.parents(new ParentPredicate().type(AssetType.AGENT))
)
@@ -480,8 +492,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
- .attributeMeta(new AttributeMetaPredicate(MetaItemType.STORE_DATA_POINTS, new BooleanPredicate(true)))
+ .select(selectExcludePathAndAttributes())
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .attributeMeta(new AttributeMetaPredicate(MetaItemType.STORE_DATA_POINTS, new BooleanPredicate(true)))
)
then: "result should match"
@@ -491,7 +504,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .attributeMeta(new AttributeMetaPredicate().itemValue(new StringPredicate(Match.END, "kWh")))
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(new AttributeMetaPredicate().itemValue(new StringPredicate(Match.END, "kWh")))
)
then: "result should match"
@@ -500,13 +514,15 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().attributeMeta(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- )
+ )
)
then: "result should match"
@@ -515,13 +531,16 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().attributeMeta(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- ).names(new StringPredicate(Match.CONTAINS, false, "thing"))
+ )
+ .names(new StringPredicate(Match.CONTAINS, false, "thing"))
)
then: "result should match"
@@ -530,13 +549,16 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().attributeMeta(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- ).names(new StringPredicate(Match.CONTAINS, true, "thing"))
+ )
+ .names(new StringPredicate(Match.CONTAINS, true, "thing"))
)
then: "result should match"
@@ -544,13 +566,16 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().attributeMeta(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- ).parents(new ParentPredicate(managerDemoSetup.agentId))
+ )
+ .parents(new ParentPredicate(managerDemoSetup.agentId))
)
then: "result should match"
@@ -559,13 +584,16 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().attributeMeta(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(
new AttributeRefPredicate(
MetaItemType.AGENT_LINK,
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- ).parents(new ParentPredicate(managerDemoSetup.apartment1LivingroomId))
+ )
+ .parents(new ParentPredicate(managerDemoSetup.apartment1LivingroomId))
)
then: "result should match"
@@ -573,12 +601,15 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
- new AssetQuery().attributeMeta(
+ new AssetQuery()
+ .select(selectExcludePathAndAttributes())
+ .attributeMeta(
new AttributeRefPredicate(
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- ).tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ )
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -589,7 +620,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
def asset = assetStorageService.find(
new AssetQuery()
.ids(managerDemoSetup.apartment1LivingroomId)
- .select(Select.selectAll().attributes("co2Level", "lastPresenceDetected", "motionSensor"))
+ .select(new Select().attributes("co2Level", "lastPresenceDetected", "motionSensor"))
.access(PRIVATE)
)
@@ -616,7 +647,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset = assetStorageService.find(
new AssetQuery()
.ids(managerDemoSetup.apartment1LivingroomId)
- .select(Select.selectAll().attributes("co2Level", "lastPresenceDetected", "motionSensor"))
+ .select(new Select().attributes("co2Level", "lastPresenceDetected", "motionSensor"))
.access(PROTECTED)
)
@@ -855,7 +886,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a calendar event filtering query is executed for the correct date and time of the event"
def assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll().excludePath(true)) // Need attributes to do calendar filtering
+ .select(new Select().excludePath(true)) // Need attributes to do calendar filtering
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517155200) // 28/01/2018 @ 4:00pm (UTC)
.orderBy(new OrderBy(NAME))
@@ -877,7 +908,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a calendar event filtering query is executed for future event on a correct day but wrong time"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll().excludePath(true))
+ .select(new Select().excludePath(true))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517335200) // 30/01/2018 @ 6:00pm (UTC)
.orderBy(new OrderBy(NAME))
@@ -890,7 +921,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a calendar event filtering query is executed for a future event on a wrong day but correct time"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll().excludePath(true))
+ .select(new Select().excludePath(true))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517238600) // 29/01/2018 @ 3:10pm (UTC)
.orderBy(new OrderBy(NAME))
@@ -903,7 +934,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a calendar event filtering query is executed inside a valid future event date and time"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll().excludePath(true)) // Need attributes to do calendar filtering
+ .select(new Select().excludePath(true)) // Need attributes to do calendar filtering
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517849400) // 05/02/2018 @ 4:50pm (UTC))
.orderBy(new OrderBy(NAME))
@@ -925,7 +956,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a calendar event filtering query is executed for some time after the last occurrence"
assets = assetStorageService.findAll(
new AssetQuery()
- .select(Select.selectAll().excludePath(true))
+ .select(new Select().excludePath(true))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1518017520) // 02/07/2018 @ 3:32pm (UTC)
.orderBy(new OrderBy(NAME))
@@ -950,11 +981,12 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
def assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
- .attributeValue(
- "openingDate",
- new DateTimePredicate(rangeStart.format(ISO_ZONED_DATE_TIME), rangeEnd.format(ISO_ZONED_DATE_TIME))
- .operator(Operator.BETWEEN))
+ .select(selectExcludePathAndAttributes())
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .attributeValue(
+ "openingDate",
+ new DateTimePredicate(rangeStart.format(ISO_ZONED_DATE_TIME), rangeEnd.format(ISO_ZONED_DATE_TIME))
+ .operator(Operator.BETWEEN))
)
@@ -965,10 +997,11 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "the lobby has an opening date and the date is after the filtering date"
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
- .attributeValue(
- "openingDate",
- new DateTimePredicate(Operator.GREATER_THAN, rangeStart.format(ISO_ZONED_DATE_TIME)))
+ .select(selectExcludePathAndAttributes())
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .attributeValue(
+ "openingDate",
+ new DateTimePredicate(Operator.GREATER_THAN, rangeStart.format(ISO_ZONED_DATE_TIME)))
)
@@ -979,10 +1012,11 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "the lobby has an opening date and the date is before the filtering date"
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
- .attributeValue(
- "openingDate",
- new DateTimePredicate(Operator.LESS_THAN, rangeEnd.format(ISO_ZONED_DATE_TIME)))
+ .select(selectExcludePathAndAttributes())
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .attributeValue(
+ "openingDate",
+ new DateTimePredicate(Operator.LESS_THAN, rangeEnd.format(ISO_ZONED_DATE_TIME)))
)
@@ -995,10 +1029,11 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
- .attributeValue(
- "openingDate",
- new DateTimePredicate(Operator.EQUALS, rangeStart.format(ISO_ZONED_DATE_TIME)))
+ .select(selectExcludePathAndAttributes())
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
+ .attributeValue(
+ "openingDate",
+ new DateTimePredicate(Operator.EQUALS, rangeStart.format(ISO_ZONED_DATE_TIME)))
)