Skip to content
Permalink
Browse files

Fix for casting exception of list to array

  • Loading branch information...
Miggets7 committed Sep 11, 2019
1 parent 3811446 commit ad35c9d5ac4f91a589e88f2de7df0ddec0728b06
@@ -385,7 +385,7 @@ public AssetQuery attributes(AttributePredicate... attributePredicates) {
return this;
}

this.attributes = new LogicGroup<>(attributePredicates);
this.attributes = new LogicGroup<>(Arrays.asList(attributePredicates));
return this;
}

@@ -398,10 +398,15 @@ public AssetQuery attributeName(String attributeName) {
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));
}
@@ -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 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 LogicGroup(Operator operator, T[] items, LogicGroup<T>[] groups) {
/**
* 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 +
'}';
}
}
@@ -24,9 +24,7 @@
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,16 +37,16 @@ public LocationAttributePredicate(GeofencePredicate geofencePredicate) {
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)
&& attributePredicate.value instanceof GeofencePredicate)
.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))
);
}

0 comments on commit ad35c9d

Please sign in to comment.
You can’t perform that action at this time.