Skip to content

armgit / core

Public Imported from GitHub
0

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

Fix for casting exception of list to array

Michael Rademakerad35c9d5ac4f
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 e906558fc..bc56ce5ee 100644
--- a/model/src/main/java/org/openremote/model/query/AssetQuery.java
+++ b/model/src/main/java/org/openremote/model/query/AssetQuery.java
@@ -385,7 +385,7 @@ public class AssetQuery {
return this;
}
- this.attributes = new LogicGroup<>(attributePredicates);
+ this.attributes = new LogicGroup<>(Arrays.asList(attributePredicates));
return this;
}
@@ -398,10 +398,15 @@ public class AssetQuery {
return attributes(new AttributePredicate(attributeName));
}
+
public AssetQuery attributeValue(String name, ValuePredicate valuePredicate) {
return attributes(new AttributePredicate(new StringPredicate(name), valuePredicate));
}
+ public AssetQuery attributeValue(String name) {
+ return attributeValue(name, new ValueNotEmptyPredicate());
+ }
+
public AssetQuery attributeValue(String name, boolean b) {
return attributeValue(name, new BooleanPredicate(b));
}
diff --git a/model/src/main/java/org/openremote/model/query/LogicGroup.java b/model/src/main/java/org/openremote/model/query/LogicGroup.java
index 097e7c454..02b7a0bfb 100644
--- a/model/src/main/java/org/openremote/model/query/LogicGroup.java
+++ b/model/src/main/java/org/openremote/model/query/LogicGroup.java
@@ -19,10 +19,7 @@
*/
package org.openremote.model.query;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.List;
public class LogicGroup<T> {
@@ -35,11 +32,11 @@ public class LogicGroup<T> {
public LogicGroup() {
}
- public LogicGroup(T[] items) {
+ public LogicGroup(List<T> items) {
this.items = items;
}
- public LogicGroup(Operator operator, T[] items, LogicGroup<T>[] groups) {
+ public LogicGroup(Operator operator, List<T> items, List<LogicGroup<T>> groups) {
this.operator = operator;
this.items = items;
this.groups = groups;
@@ -53,41 +50,24 @@ public class LogicGroup<T> {
/**
* Defines the items that the {@link #operator} should be applied to
*/
- @JsonIgnore
- public T[] items;
+ public List<T> items;
/**
* Nested groups allow for more complex logic with a mix of operators
*/
- @JsonIgnore
- public LogicGroup<T>[] groups;
-
- @JsonProperty("items")
- public T[] getItems() {
- return items;
- }
+ public List<LogicGroup<T>> groups;
- @JsonProperty("items")
- public void setItems(List<T> items) {
- this.items = items == null ? null : items.toArray((T[])new Object[0]);
- }
-
- @JsonProperty("groups")
- public LogicGroup<T>[] getGroups() {
- return groups;
- }
- @JsonProperty("groups")
- public void setGroups(List<LogicGroup<T>> groups) {
- this.groups = groups == null ? null : groups.toArray((LogicGroup<T>[])new Object[0]);
+ public List<T> getItems() {
+ return items == null ? new ArrayList<T>() : items;
}
@Override
public String toString() {
return LogicGroup.class.getSimpleName() + "{" +
"operator=" + operator +
- ", items=" + Arrays.toString(items) +
- ", groups=" + Arrays.toString(groups) +
+ ", items=" + items +
+ ", groups=" + groups +
'}';
}
}
diff --git a/model/src/main/java/org/openremote/model/query/filter/LocationAttributePredicate.java b/model/src/main/java/org/openremote/model/query/filter/LocationAttributePredicate.java
index 23be7dcd9..790bc7e57 100644
--- a/model/src/main/java/org/openremote/model/query/filter/LocationAttributePredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/LocationAttributePredicate.java
@@ -24,9 +24,7 @@ import org.openremote.model.query.AssetQuery;
import org.openremote.model.query.LogicGroup;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import static org.openremote.model.attribute.AttributeType.LOCATION;
@@ -39,7 +37,7 @@ public class LocationAttributePredicate extends AttributePredicate {
public static List<GeofencePredicate> getLocationPredicates(LogicGroup<AttributePredicate> attributePredicates) {
List<GeofencePredicate> geofences = new ArrayList<>();
- Arrays.stream(attributePredicates.items)
+ attributePredicates.getItems().stream()
.filter(attributePredicate -> attributePredicate.name != null
&& attributePredicate.name.match == AssetQuery.Match.EXACT
&& LOCATION.getAttributeName().equals(attributePredicate.name.value)
@@ -47,8 +45,8 @@ public class LocationAttributePredicate extends AttributePredicate {
.map(attributePredicate -> (GeofencePredicate) attributePredicate.value)
.forEach(geofences::add);
- if (attributePredicates.groups != null) {
- Arrays.stream(attributePredicates.groups).forEach(group ->
+ if (attributePredicates.groups != null && attributePredicates.groups.size() > 0) {
+ attributePredicates.groups.forEach(group ->
geofences.addAll(getLocationPredicates(group))
);
}