Skip to content

armgit / core

Public Imported from GitHub
0

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

Added AssetPredicate to AbstractAssetQuery so a certain type or specific Asset can be requested.

Michael Rademaker9083f9dc0c1f
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
index 9008c5669..6f0b0508f 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
@@ -708,6 +708,18 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
binders.add(st -> st.setString(pos, query.namePredicate.prepareValue()));
}
+ if(level == 1 && query.assetPredicate != null) {
+ if(query.assetPredicate.id != null) {
+ sb.append(" and A.ID = ?");
+ final int pos = binders.size() + 1;
+ binders.add(st -> st.setString(pos, query.assetPredicate.id));
+ } else if(query.assetPredicate.type != null) {
+ sb.append(" and A.ASSET_TYPE = ?");
+ final int pos = binders.size() + 1;
+ binders.add(st -> st.setString(pos, query.assetPredicate.type));
+ }
+ }
+
if (query.parentPredicate != null) {
// Can only restrict recursive query parent by asset type
if (level == 1 && query.parentPredicate.id != null) {
diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetQuery.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetQuery.java
index 53f523d13..fea2443ce 100644
--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetQuery.java
+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetQuery.java
@@ -56,7 +56,7 @@ public class AbstractAssetQuery<CHILD extends AbstractAssetQuery<CHILD>> {
}
public Select(Include include, boolean filterProtected, boolean recursive) {
- this(include, filterProtected, recursive, (String[])null);
+ this(include, filterProtected, recursive, (String[]) null);
}
public Select(Include include, boolean filterProtected, boolean recursive, String... attributeNames) {
@@ -187,27 +187,46 @@ public class AbstractAssetQuery<CHILD extends AbstractAssetQuery<CHILD>> {
}
}
- public static class ParentPredicate {
+ public static class AssetPredicate {
public String id;
public String type;
+
+ public AssetPredicate() {
+ }
+
+ public AssetPredicate(String id) {
+ this.id = id;
+ }
+
+ public AssetPredicate id(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public AssetPredicate type(String type) {
+ this.type = type;
+ return this;
+ }
+
+ public AssetPredicate type(AssetType type) {
+ return type(type.getValue());
+ }
+ }
+
+ public static class ParentPredicate extends AssetPredicate {
public boolean noParent;
public ParentPredicate() {
}
public ParentPredicate(String id) {
- this.id = id;
+ super(id);
}
public ParentPredicate(boolean noParent) {
this.noParent = noParent;
}
- public ParentPredicate id(String id) {
- this.id = id;
- return this;
- }
-
public ParentPredicate type(String type) {
this.type = type;
return this;
@@ -394,6 +413,7 @@ public class AbstractAssetQuery<CHILD extends AbstractAssetQuery<CHILD>> {
// Restriction predicates
public String id;
public StringPredicate namePredicate;
+ public AssetPredicate assetPredicate;
public ParentPredicate parentPredicate;
public PathPredicate pathPredicate;
public TenantPredicate tenantPredicate;
@@ -431,6 +451,19 @@ public class AbstractAssetQuery<CHILD extends AbstractAssetQuery<CHILD>> {
return (CHILD) this;
}
+ public CHILD asset(String id) {
+ return asset(new AssetPredicate(id));
+ }
+
+ public CHILD asset(AssetType assetType) {
+ return asset(new AssetPredicate().type(assetType));
+ }
+
+ public CHILD asset(AssetPredicate assetPredicate) {
+ this.assetPredicate = assetPredicate;
+ return (CHILD) this;
+ }
+
public CHILD parent(String id) {
return parent(new ParentPredicate(id));
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetType.java b/model/src/main/java/org/openremote/model/asset/AssetType.java
index 2e27c391b..648628c00 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetType.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetType.java
@@ -74,7 +74,12 @@ public enum AssetType {
ROOM(ASSET_NAMESPACE + ":room", "cube"),
- PIER(ASSET_NAMESPACE + ":pier", "cube"),
+ PIER(ASSET_NAMESPACE + ":pier", "cube",
+ new AssetAttribute("flights", ARRAY)
+ .setMeta(
+ new MetaItem(LABEL, Values.create("Flights"))
+ )
+ ),
FLIGHT(ASSET_NAMESPACE + ":flight", "plane",
new AssetAttribute("code", STRING)