Skip to content

armgit / core

Public Imported from GitHub
0

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

Cleanup of location predicate code and further WIP on JSON rules

Rich Turnerc0e485c6d57d
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 3495a9cac..90ffee0fd 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -57,7 +57,6 @@ import org.openremote.model.security.ClientRole;
import org.openremote.model.security.User;
import org.openremote.model.util.Pair;
import org.openremote.model.util.TextUtil;
-import org.openremote.model.util.TimeUtil;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
@@ -67,13 +66,8 @@ import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import java.sql.*;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.temporal.ChronoUnit;
-import java.time.temporal.TemporalUnit;
import java.util.*;
import java.util.Date;
-import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -89,6 +83,7 @@ import static org.openremote.model.query.BaseAssetQuery.Access.PRIVATE_READ;
import static org.openremote.model.query.BaseAssetQuery.Access.RESTRICTED_READ;
import static org.openremote.model.query.BaseAssetQuery.Include.ALL;
import static org.openremote.model.query.BaseAssetQuery.Include.ALL_EXCEPT_PATH_AND_ATTRIBUTES;
+import static org.openremote.model.query.filter.LocationAttributePredicate.getLocationPredicate;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;
public class AssetStorageService extends RouteBuilder implements ContainerService {
@@ -894,37 +889,6 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
binders.add(st -> st.setString(pos, query.name.prepareValue()));
}
- if (level == 1 && query.location != null) {
- if (query.location instanceof RadialLocationPredicate) {
- RadialLocationPredicate location = (RadialLocationPredicate) query.location;
- sb.append(" and ST_Distance_Sphere(ST_MakePoint(");
- sb.append("(A.attributes #>> '{location,value,coordinates,0}')::numeric");
- sb.append(", (A.attributes #>> '{location,value,coordinates,1}')::numeric");
- sb.append("), ST_MakePoint(");
- sb.append(location.lng);
- sb.append(",");
- sb.append(location.lat);
- sb.append(location.negated ? ")) > " : ")) <= ");
- sb.append(location.radius);
- } else if (query.location instanceof RectangularLocationPredicate) {
- RectangularLocationPredicate location = (RectangularLocationPredicate) query.location;
- sb.append(location.negated ? " and NOT" : " and");
- sb.append(" ST_Within(ST_MakePoint(");
- sb.append("(A.attributes #>> '{location,value,coordinates,0}')::numeric");
- sb.append(", (A.attributes #>> '{location,value,coordinates,1}')::numeric");
- sb.append(")");
- sb.append(", ST_MakeEnvelope(");
- sb.append(location.lngMin);
- sb.append(",");
- sb.append(location.latMin);
- sb.append(",");
- sb.append(location.lngMax);
- sb.append(",");
- sb.append(location.latMax);
- sb.append("))");
- }
- }
-
if (query.parent != null) {
// Can only restrict recursive query parent by asset type
if (level == 1 && query.parent.id != null) {
@@ -1178,7 +1142,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
binders.add(st -> st.setDouble(pos, numberPredicate.value));
if (numberPredicate.operator == Operator.BETWEEN) {
final int pos2 = binders.size() + 1;
- binders.add(st -> st.setDouble(pos, numberPredicate.rangeValue));
+ binders.add(st -> st.setDouble(pos2, numberPredicate.rangeValue));
}
break;
case INTEGER:
@@ -1198,6 +1162,35 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
}
final int pos = binders.size() + 1;
binders.add(st -> st.setString(pos, keyPredicate.key));
+ } else if (attributePredicate.value instanceof GeofencePredicate) {
+ if (attributePredicate.value instanceof RadialGeofencePredicate) {
+ RadialGeofencePredicate location = (RadialGeofencePredicate) attributePredicate.value;
+ attributeBuilder.append(" and ST_Distance_Sphere(ST_MakePoint(");
+ attributeBuilder.append("(AX.VALUE #>> '{value,coordinates,0}')::numeric");
+ attributeBuilder.append(", (AX.VALUE #>> '{value,coordinates,1}')::numeric");
+ attributeBuilder.append("), ST_MakePoint(");
+ attributeBuilder.append(location.lng);
+ attributeBuilder.append(",");
+ attributeBuilder.append(location.lat);
+ attributeBuilder.append(location.negated ? ")) > " : ")) <= ");
+ attributeBuilder.append(location.radius);
+ } else if (attributePredicate.value instanceof RectangularGeofencePredicate) {
+ RectangularGeofencePredicate location = (RectangularGeofencePredicate) attributePredicate.value;
+ attributeBuilder.append(location.negated ? " and NOT" : " and");
+ attributeBuilder.append(" ST_Within(ST_MakePoint(");
+ attributeBuilder.append("(AX.VALUE #>> '{value,coordinates,0}')::numeric");
+ attributeBuilder.append(", (AX.VALUE #>> '{value,coordinates,1}')::numeric");
+ attributeBuilder.append(")");
+ attributeBuilder.append(", ST_MakeEnvelope(");
+ attributeBuilder.append(location.lngMin);
+ attributeBuilder.append(",");
+ attributeBuilder.append(location.latMin);
+ attributeBuilder.append(",");
+ attributeBuilder.append(location.lngMax);
+ attributeBuilder.append(",");
+ attributeBuilder.append(location.latMax);
+ attributeBuilder.append("))");
+ }
}
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java b/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
index a8b3ec54e..3cc135a8f 100644
--- a/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
+++ b/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
@@ -40,6 +40,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Locale;
+import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -107,16 +108,6 @@ public class AssetQueryPredicate implements Predicate<AssetState> {
throw new UnsupportedOperationException("Sorting with 'orderBy' not supported in rules matching");
}
- if (query.location != null) {
- GeoJSONPoint coords = AttributeType.LOCATION.getName().equals(assetState.getAttributeName()) ? assetState.getValue().flatMap(GeoJSONPoint::fromValue).orElse(null) : null;
-
- if (coords != null) {
- Coordinate coordinate = new Coordinate(coords.getY(), coords.getX());
- return asPredicate(query.location).test(coordinate);
- }
- return false;
- }
-
return true;
}
@@ -257,18 +248,22 @@ public class AssetQueryPredicate implements Predicate<AssetState> {
&& (predicate.realmId == null || predicate.realmId.equals(assetState.getRealmId()));
}
- public static Predicate<Coordinate> asPredicate(LocationPredicate predicate) {
+ public static Predicate<Coordinate> asPredicate(GeofencePredicate predicate) {
return coordinate -> {
- if (predicate instanceof RadialLocationPredicate) {
+ if (coordinate == null) {
+ return false;
+ }
+
+ if (predicate instanceof RadialGeofencePredicate) {
//TODO geotools version to gradle properties
- RadialLocationPredicate radialLocationPredicate = (RadialLocationPredicate) predicate;
+ RadialGeofencePredicate radialLocationPredicate = (RadialGeofencePredicate) predicate;
GeodeticCalculator calculator = new GeodeticCalculator();
calculator.setStartingGeographicPoint(radialLocationPredicate.lng, radialLocationPredicate.lat);
calculator.setDestinationGeographicPoint(coordinate.y, coordinate.x);
return calculator.getOrthodromicDistance() < radialLocationPredicate.radius;
- } else if (predicate instanceof RectangularLocationPredicate) {
+ } else if (predicate instanceof RectangularGeofencePredicate) {
// Again this is a euclidean plane so doesn't work perfectly for WGS lat/lng - the bigger the rectangle to less accurate it is)
- RectangularLocationPredicate rectangularLocationPredicate = (RectangularLocationPredicate) predicate;
+ RectangularGeofencePredicate rectangularLocationPredicate = (RectangularGeofencePredicate) predicate;
Envelope envelope = new Envelope(rectangularLocationPredicate.latMin,
rectangularLocationPredicate.lngMin,
rectangularLocationPredicate.latMax,
@@ -320,7 +315,13 @@ public class AssetQueryPredicate implements Predicate<AssetState> {
DateTimePredicate p = (DateTimePredicate) predicate;
return asPredicate(currentMillisProducer, p).test(Values.getNumber(value).map(Double::longValue).orElse(null));
+ } else if (predicate instanceof GeofencePredicate) {
+ GeofencePredicate p = (GeofencePredicate) predicate;
+ return asPredicate(p).test(Optional.ofNullable(value)
+ .flatMap(GeoJSONPoint::fromValue)
+ .map(point -> new Coordinate(point.getY(), point.getX()))
+ .orElse(null));
} else {
// TODO Implement more
throw new UnsupportedOperationException(
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
index 3e7c8bf5d..3ed0be056 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
@@ -34,7 +34,8 @@ import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetMeta;
import org.openremote.model.attribute.AttributeType;
-import org.openremote.model.query.filter.LocationPredicate;
+import org.openremote.model.query.filter.GeofencePredicate;
+import org.openremote.model.query.filter.LocationAttributePredicate;
import org.openremote.model.rules.*;
import java.util.*;
@@ -49,14 +50,14 @@ import static org.openremote.model.rules.RulesetStatus.*;
public class RulesEngine<T extends Ruleset> {
/**
- * Identifies a set of {@link LocationPredicate}s associated with a particular {@link Asset}
+ * Identifies a set of {@link LocationAttributePredicate}s associated with a particular {@link Asset}
*/
public static final class AssetStateLocationPredicates {
protected final String assetId;
- protected final Set<LocationPredicate> locationPredicates;
+ protected final Set<GeofencePredicate> locationPredicates;
- public AssetStateLocationPredicates(String assetId, Set<LocationPredicate> locationPredicates) {
+ public AssetStateLocationPredicates(String assetId, Set<GeofencePredicate> locationPredicates) {
this.assetId = assetId;
this.locationPredicates = locationPredicates;
}
@@ -65,7 +66,7 @@ public class RulesEngine<T extends Ruleset> {
return assetId;
}
- public Set<LocationPredicate> getLocationPredicates() {
+ public Set<GeofencePredicate> getLocationPredicates() {
return locationPredicates;
}
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
index bf447b219..2d5f6d5aa 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
@@ -23,11 +23,13 @@ import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.RuleListener;
import org.openremote.container.timer.TimerService;
-import org.openremote.model.attribute.AttributeType;
-import org.openremote.model.query.AssetQuery;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.attribute.AttributeExecuteStatus;
-import org.openremote.model.query.filter.LocationPredicate;
+import org.openremote.model.query.AssetQuery;
+import org.openremote.model.query.BaseAssetQuery;
+import org.openremote.model.query.filter.AttributePredicate;
+import org.openremote.model.query.filter.GeofencePredicate;
+import org.openremote.model.query.filter.LocationAttributePredicate;
import org.openremote.model.rules.AssetState;
import org.openremote.model.rules.Assets;
import org.openremote.model.rules.TemporaryFact;
@@ -43,6 +45,9 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.openremote.model.attribute.AttributeType.LOCATION;
+import static org.openremote.model.query.filter.LocationAttributePredicate.getLocationPredicate;
+
public class RulesFacts extends Facts implements RuleListener {
// Loop detection
@@ -61,15 +66,12 @@ public class RulesFacts extends Facts implements RuleListener {
final protected Assets assetsFacade;
final protected Object loggingContext;
final protected Logger LOG;
-
- public RulesClock clock;
-
final protected Map<String, Collection<AssetState>> assetIdIndex = new HashMap<>();
final protected Map<String, Collection<AssetState>> assetTypeIndex = new HashMap<>();
-
+ public RulesClock clock;
protected int triggerCount;
protected boolean trackLocationRules;
- protected Map<String, Set<LocationPredicate>> assetStateLocationPredicateMap = null;
+ protected Map<String, Set<GeofencePredicate>> assetStateLocationPredicateMap = null;
public RulesFacts(TimerService timerService, Assets assetsFacade, Object loggingContext, Logger logger) {
this.timerService = timerService;
@@ -91,13 +93,17 @@ public class RulesFacts extends Facts implements RuleListener {
protected List<RulesEngine.AssetStateLocationPredicates> stopTrackingLocationRules() {
LOG.finer("Tracking location predicate rules: stopping");
trackLocationRules = false;
- Map<String, Set<LocationPredicate>> assetStateLocationPredicateMap = this.assetStateLocationPredicateMap;
+ Map<String, Set<GeofencePredicate>> assetStateLocationPredicateMap = this.assetStateLocationPredicateMap;
this.assetStateLocationPredicateMap = null;
return assetStateLocationPredicateMap.entrySet().stream()
- .map(assetStateSetEntry ->
- new RulesEngine.AssetStateLocationPredicates(
- assetStateSetEntry.getKey(),
- assetStateSetEntry.getValue())).collect(Collectors.toList());
+ .map(assetStateSetEntry ->
+ new RulesEngine.AssetStateLocationPredicates(
+ assetStateSetEntry.getKey(),
+ assetStateSetEntry.getValue())).collect(Collectors.toList());
+ }
+
+ public RulesClock getClock() {
+ return clock;
}
public void setClock(RulesClock clock) {
@@ -105,10 +111,6 @@ public class RulesFacts extends Facts implements RuleListener {
asMap().put(CLOCK, clock);
}
- public RulesClock getClock() {
- return clock;
- }
-
@SuppressWarnings("unchecked")
public Collection<AssetState> getAssetStates() {
return (Collection<AssetState>) get(ASSET_STATES);
@@ -126,26 +128,26 @@ public class RulesFacts extends Facts implements RuleListener {
public Map<String, Object> getNamedFacts() {
return asMap().entrySet().stream().filter(entry ->
- !entry.getKey().equals(CLOCK)
- && !entry.getKey().equals(ASSET_STATES)
- && !entry.getKey().equals(ASSET_EVENTS)
- && !entry.getKey().equals(EXECUTION_VARS)
- && !entry.getKey().equals(ANONYMOUS_FACTS)
+ !entry.getKey().equals(CLOCK)
+ && !entry.getKey().equals(ASSET_STATES)
+ && !entry.getKey().equals(ASSET_EVENTS)
+ && !entry.getKey().equals(EXECUTION_VARS)
+ && !entry.getKey().equals(ANONYMOUS_FACTS)
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
public Stream<Object> getAllFacts() {
return
- Stream.concat(
- getNamedFacts().values().stream().parallel(),
Stream.concat(
- getAnonymousFacts().stream().parallel(),
- Stream.concat(
- getAssetStates().stream().parallel(),
- getAssetEvents().stream().parallel()
- )
- )
- ).parallel();
+ getNamedFacts().values().stream().parallel(),
+ Stream.concat(
+ getAnonymousFacts().stream().parallel(),
+ Stream.concat(
+ getAssetStates().stream().parallel(),
+ getAssetEvents().stream().parallel()
+ )
+ )
+ ).parallel();
}
@SuppressWarnings("unchecked")
@@ -294,11 +296,11 @@ public class RulesFacts extends Facts implements RuleListener {
public Stream<TemporaryFact> getTemporaryFacts() {
return Stream.concat(
- Stream.concat(
- getAssetEvents().stream().parallel(),
- getNamedFacts().values().stream().parallel().filter(fact -> fact instanceof TemporaryFact).map(fact -> (TemporaryFact) fact)
- ),
- getAnonymousFacts().stream().parallel().filter(fact -> fact instanceof TemporaryFact).map(fact -> (TemporaryFact) fact)
+ Stream.concat(
+ getAssetEvents().stream().parallel(),
+ getNamedFacts().values().stream().parallel().filter(fact -> fact instanceof TemporaryFact).map(fact -> (TemporaryFact) fact)
+ ),
+ getAnonymousFacts().stream().parallel().filter(fact -> fact instanceof TemporaryFact).map(fact -> (TemporaryFact) fact)
).parallel();
}
@@ -342,9 +344,9 @@ public class RulesFacts extends Facts implements RuleListener {
triggerCount++;
if (triggerCount >= MAX_RULES_TRIGGERED_PER_EXECUTION) {
throw new IllegalStateException(
- "Possible rules loop detected, exceeded max trigger count of "
- + MAX_RULES_TRIGGERED_PER_EXECUTION
- + " for rule: " + rule.getName()
+ "Possible rules loop detected, exceeded max trigger count of "
+ + MAX_RULES_TRIGGERED_PER_EXECUTION
+ + " for rule: " + rule.getName()
);
}
}
@@ -374,7 +376,7 @@ public class RulesFacts extends Facts implements RuleListener {
fact = temporaryFact.getFact();
}
return Optional.ofNullable(
- factType.isAssignableFrom(fact.getClass()) && predicate.test((T) fact) ? (T) fact : null
+ factType.isAssignableFrom(fact.getClass()) && predicate.test((T) fact) ? (T) fact : null
);
}
@@ -415,14 +417,14 @@ public class RulesFacts extends Facts implements RuleListener {
@SuppressWarnings("unchecked")
public <T> Stream<T> match(Class<T> factType, Predicate<T> predicate) {
return getAllFacts()
- .filter(fact -> matchFact(fact, factType, predicate).isPresent())
- .map(fact -> {
- if (fact instanceof TemporaryFact) {
- return ((TemporaryFact) fact).getFact();
- }
- return fact;
- })
- .map(fact -> (T) fact);
+ .filter(fact -> matchFact(fact, factType, predicate).isPresent())
+ .map(fact -> {
+ if (fact instanceof TemporaryFact) {
+ return ((TemporaryFact) fact).getFact();
+ }
+ return fact;
+ })
+ .map(fact -> (T) fact);
}
public Optional<AssetState> matchFirstAssetState(AssetQuery assetQuery) {
@@ -431,19 +433,21 @@ public class RulesFacts extends Facts implements RuleListener {
public Stream<AssetState> matchAssetState(AssetQuery assetQuery) {
- if (trackLocationRules) {
- if (assetQuery.location != null) {
+ if (trackLocationRules && assetQuery.attribute != null && assetQuery.attribute.length > 0) {
+
+ GeofencePredicate locationPredicate = getLocationPredicate(Arrays.asList(assetQuery.attribute)).orElse(null);
+
+ if (locationPredicate != null) {
LOG.fine("Location predicate found");
// Collect asset states only where the attribute is location (location predicates only make sense when the location
// attribute is exposed to rules - we don't support RULE_EVENT facts just RULE_STATE
if (assetStateLocationPredicateMap == null) {
- // TODO: Use static reference to well known location attribute when it is implemented
- Collection<AssetState> locationAssetStates = getAssetStates().stream().filter(assetState -> assetState.getAttributeName().equalsIgnoreCase(AttributeType.LOCATION.getName())).collect(Collectors.toSet());
+ Collection<AssetState> locationAssetStates = getAssetStates().stream().filter(assetState -> assetState.getAttributeName().equalsIgnoreCase(LOCATION.getName())).collect(Collectors.toSet());
assetStateLocationPredicateMap = new HashMap<>(locationAssetStates.size());
locationAssetStates.forEach(assetState -> assetStateLocationPredicateMap.put(assetState.getId(), new HashSet<>()));
}
- assetStateLocationPredicateMap.forEach((assetState, locationPredicates) -> locationPredicates.add(assetQuery.location));
+ assetStateLocationPredicateMap.forEach((assetState, locationPredicates) -> locationPredicates.add(locationPredicate));
}
}
@@ -478,7 +482,7 @@ public class RulesFacts extends Facts implements RuleListener {
public Stream<TemporaryFact<AssetState>> matchAssetEvent(AssetQuery assetQuery) {
Predicate<AssetState> p = new AssetQueryPredicate(timerService, assetQuery);
return getAssetEvents().stream().parallel()
- .filter(fact -> matchFact(fact, AssetState.class, p).isPresent());
+ .filter(fact -> matchFact(fact, AssetState.class, p).isPresent());
}
public RulesFacts updateAssetState(String assetId, String attributeName, Value value) {
@@ -508,25 +512,25 @@ public class RulesFacts extends Facts implements RuleListener {
protected RulesFacts invalidateAssetStateAndDispatch(String assetId, String attributeName, Value value) {
// Remove the asset state from the facts, it is invalid now
getAssetStates()
- .removeIf(assetState -> {
- boolean invalid = assetState.getId().equals(assetId) && assetState.getAttributeName().equals(attributeName);
- if (invalid) {
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Fact change (INTERNAL DELETE): " + assetState + " - on: " + loggingContext);
+ .removeIf(assetState -> {
+ boolean invalid = assetState.getId().equals(assetId) && assetState.getAttributeName().equals(attributeName);
+ if (invalid) {
+ if (LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Fact change (INTERNAL DELETE): " + assetState + " - on: " + loggingContext);
+ }
+ // Maintain index of all asset states for this asset by ID
+ Collection<AssetState> assetIdIndexCollection = assetIdIndex.get(assetState.getId());
+ if (assetIdIndexCollection != null) {
+ assetIdIndexCollection.remove(assetState);
+ }
+ // Maintain index of all asset states for this asset by type
+ Collection<AssetState> assetTypeIndexCollection = assetTypeIndex.get(assetState.getTypeString());
+ if (assetTypeIndexCollection != null) {
+ assetTypeIndexCollection.remove(assetState);
+ }
}
- // Maintain index of all asset states for this asset by ID
- Collection<AssetState> assetIdIndexCollection = assetIdIndex.get(assetState.getId());
- if (assetIdIndexCollection != null) {
- assetIdIndexCollection.remove(assetState);
- }
- // Maintain index of all asset states for this asset by type
- Collection<AssetState> assetTypeIndexCollection = assetTypeIndex.get(assetState.getTypeString());
- if (assetTypeIndexCollection != null) {
- assetTypeIndexCollection.remove(assetState);
- }
- }
- return invalid;
- });
+ return invalid;
+ });
// Dispatch the update to the asset processing service
AttributeEvent attributeEvent = new AttributeEvent(assetId, attributeName, value);
@@ -547,11 +551,11 @@ public class RulesFacts extends Facts implements RuleListener {
});
asMap().entrySet().removeIf(entry -> {
if (entry.getKey().equals(CLOCK)
- || entry.getKey().equals(ASSET_STATES)
- || entry.getKey().equals(ASSET_EVENTS)
- || entry.getKey().equals(EXECUTION_VARS)
- || entry.getKey().equals(ANONYMOUS_FACTS)
- || !(entry.getValue() instanceof TemporaryFact)) {
+ || entry.getKey().equals(ASSET_STATES)
+ || entry.getKey().equals(ASSET_EVENTS)
+ || entry.getKey().equals(EXECUTION_VARS)
+ || entry.getKey().equals(ANONYMOUS_FACTS)
+ || !(entry.getValue() instanceof TemporaryFact)) {
return false;
}
boolean result = ((TemporaryFact) entry.getValue()).isExpired(currentTimestamp);
@@ -637,7 +641,7 @@ public class RulesFacts extends Facts implements RuleListener {
String ruleName = rule.getName();
if (ruleName.startsWith("-") && LOG.isLoggable(Level.INFO)) {
LOG.log(Level.INFO,
- String.format("*** %s: %s - on %s", msg, ruleName, loggingContext)
+ String.format("*** %s: %s - on %s", msg, ruleName, loggingContext)
);
}
if (ruleName.startsWith("--") && LOG.isLoggable(Level.INFO)) {
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 0de152c74..d960de2e7 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -43,7 +43,7 @@ import org.openremote.model.attribute.AttributeEvent.Source;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.query.filter.AttributeMetaPredicate;
import org.openremote.model.query.filter.BooleanPredicate;
-import org.openremote.model.query.filter.LocationPredicate;
+import org.openremote.model.query.filter.LocationAttributePredicate;
import org.openremote.model.rules.*;
import org.openremote.model.rules.geofence.GeofenceDefinition;
import org.openremote.model.security.ClientRole;
@@ -778,8 +778,8 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
/**
* Called when an engine's rules change identifying assets with location attributes marked with {@link
- * AssetMeta#RULE_STATE} that also have {@link LocationPredicate} in the rules. The job here is to
- * identify the asset's (via {@link AssetState}) that have modified {@link LocationPredicate}s and to
+ * AssetMeta#RULE_STATE} that also have {@link LocationAttributePredicate} in the rules. The job here is to
+ * identify the asset's (via {@link AssetState}) that have modified {@link LocationAttributePredicate}s and to
* notify the {@link GeofenceAssetAdapter}s.
*/
protected void onEngineLocationRulesChanged(RulesEngine rulesEngine, List<RulesEngine.AssetStateLocationPredicates> newEngineAssetStateLocationPredicates) {
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java b/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java
index 34db97f67..bf1d8ba45 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java
@@ -43,6 +43,7 @@ import org.openremote.model.rules.json.JsonRulesetDefinition;
import javax.script.*;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -163,9 +164,17 @@ public class RulesetDeployment {
private boolean registerRulesJson(Ruleset ruleset) {
try {
- JsonRulesetDefinition simpleRulesetDefinition = Container.JSON.readValue(ruleset.getRules(), JsonRulesetDefinition.class);
+ JsonRulesetDefinition jsonRulesetDefinition = Container.JSON.readValue(ruleset.getRules(), JsonRulesetDefinition.class);
+ JsonRulesBuilder jsonRulesBuilder = new JsonRulesBuilder(timerService, assetStorageService);
+
+ Arrays.stream(jsonRulesetDefinition.rules).forEach(jsonRulesBuilder::add);
+
+ for (Rule rule : jsonRulesBuilder.build()) {
+ RulesEngine.LOG.info("Registering simple rule: " + rule.getName());
+ rules.register(rule);
+ }
+ RulesEngine.LOG.info("Evaluated ruleset deployment: " + ruleset);
- JsonRulesBuilder simpleRulesBuilder = new JsonRulesBuilder(timerService, assetStorageService);
return true;
} catch (IOException e) {
diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/GeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/GeofenceAssetAdapter.java
index 469ac40a2..bd2288d26 100644
--- a/manager/src/main/java/org/openremote/manager/rules/geofence/GeofenceAssetAdapter.java
+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/GeofenceAssetAdapter.java
@@ -21,14 +21,14 @@ package org.openremote.manager.rules.geofence;
import org.openremote.manager.rules.RulesEngine;
import org.openremote.model.asset.Asset;
-import org.openremote.model.query.filter.LocationPredicate;
+import org.openremote.model.query.filter.LocationAttributePredicate;
import org.openremote.model.rules.geofence.GeofenceDefinition;
import java.util.List;
/**
- * Defines an adapter that can take a collection of {@link LocationPredicate} that apply to a given
- * {@link Asset} and can convert the {@link LocationPredicate}s into Geofences that can be implemented by
+ * Defines an adapter that can take a collection of {@link LocationAttributePredicate} that apply to a given
+ * {@link Asset} and can convert the {@link LocationAttributePredicate}s into Geofences that can be implemented by
* the asset(s) itself.
* <p>
* The adapter is notified when the {@link Asset}s {@link RulesEngine.AssetStateLocationPredicates} change; if the
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 6c859593d..35db627bb 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
@@ -38,9 +38,9 @@ import org.openremote.model.notification.Notification;
import org.openremote.model.notification.PushNotificationMessage;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.query.BaseAssetQuery;
-import org.openremote.model.query.filter.LocationPredicate;
+import org.openremote.model.query.filter.GeofencePredicate;
import org.openremote.model.query.filter.ObjectValueKeyPredicate;
-import org.openremote.model.query.filter.RadialLocationPredicate;
+import org.openremote.model.query.filter.RadialGeofencePredicate;
import org.openremote.model.rules.geofence.GeofenceDefinition;
import org.openremote.model.syslog.SyslogCategory;
import org.openremote.model.util.TextUtil;
@@ -162,7 +162,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
assetStateLocationPredicates
.getLocationPredicates()
.removeIf(locationPredicate ->
- !(locationPredicate instanceof RadialLocationPredicate));
+ !(locationPredicate instanceof RadialGeofencePredicate));
RulesEngine.AssetStateLocationPredicates existingPredicates = assetLocationPredicatesMap.get(
@@ -241,8 +241,8 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
return geofences;
}
- protected GeofenceDefinition locationPredicateToGeofenceDefinition(String assetId, LocationPredicate locationPredicate) {
- RadialLocationPredicate radialLocationPredicate = (RadialLocationPredicate) locationPredicate;
+ protected GeofenceDefinition locationPredicateToGeofenceDefinition(String assetId, GeofencePredicate geofencePredicate) {
+ RadialGeofencePredicate radialLocationPredicate = (RadialGeofencePredicate) geofencePredicate;
String id = assetId + "_" + Integer.toString(radialLocationPredicate.hashCode());
String url = getWriteAttributeUrl(new AttributeRef(assetId, AttributeType.LOCATION.getName()));
return new GeofenceDefinition(id,
diff --git a/manager/src/main/resources/demo/rules/DemoConsoleLocation.groovy b/manager/src/main/resources/demo/rules/DemoConsoleLocation.groovy
index 2d5b6212f..bbb713221 100644
--- a/manager/src/main/resources/demo/rules/DemoConsoleLocation.groovy
+++ b/manager/src/main/resources/demo/rules/DemoConsoleLocation.groovy
@@ -2,12 +2,13 @@ package demo.rules
import org.openremote.manager.rules.RulesBuilder
import org.openremote.manager.setup.builtin.ManagerDemoSetup
-import org.openremote.model.notification.Notification
-import org.openremote.model.query.AssetQuery
import org.openremote.model.asset.AssetType
import org.openremote.model.attribute.AttributeType
+import org.openremote.model.notification.Notification
import org.openremote.model.notification.PushNotificationMessage
-import org.openremote.model.query.filter.RadialLocationPredicate
+import org.openremote.model.query.AssetQuery
+import org.openremote.model.query.filter.LocationAttributePredicate
+import org.openremote.model.query.filter.RadialGeofencePredicate
import org.openremote.model.query.filter.ValueEmptyPredicate
import org.openremote.model.rules.Assets
import org.openremote.model.rules.Notifications
@@ -20,70 +21,70 @@ Notifications notifications = binding.notifications
Assets assets = binding.assets
rules.add()
- .name("Welcome home")
- .when({
- facts ->
+ .name("Welcome home")
+ .when({
+ facts ->
- def consoleIds = facts.matchAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .location(
- new RadialLocationPredicate(100, ManagerDemoSetup.SMART_HOME_LOCATION.y, ManagerDemoSetup.SMART_HOME_LOCATION.x)))
- .filter({!facts.getOptional("welcomeHome" + "_${it.id}").isPresent()})
- .map({it.id})
- .collect()
+ def consoleIds = facts.matchAssetState(new AssetQuery()
+ .type(AssetType.CONSOLE)
+ .attributes(new LocationAttributePredicate(
+ new RadialGeofencePredicate(100, ManagerDemoSetup.SMART_HOME_LOCATION.y, ManagerDemoSetup.SMART_HOME_LOCATION.x))))
+ .filter({ !facts.getOptional("welcomeHome" + "_${it.id}").isPresent() })
+ .map({ it.id })
+ .collect()
- if (consoleIds.size() > 0) {
- facts.bind("consoleIds", consoleIds)
- true
- } else {
- false
- }
- })
- .then({
- facts ->
+ if (consoleIds.size() > 0) {
+ facts.bind("consoleIds", consoleIds)
+ true
+ } else {
+ false
+ }
+})
+ .then({
+ facts ->
- List<String> consoleIds = facts.bound("consoleIds")
- Notification notification = new Notification(
- "Welcome Home",
- new PushNotificationMessage("Welcome Home", "No new events to report", null, null, null),
- new Notification.Targets(Notification.TargetType.ASSET, consoleIds), null, null)
+ List<String> consoleIds = facts.bound("consoleIds")
+ Notification notification = new Notification(
+ "Welcome Home",
+ new PushNotificationMessage("Welcome Home", "No new events to report", null, null, null),
+ new Notification.Targets(Notification.TargetType.ASSET, consoleIds), null, null)
- notifications.send(notification)
+ notifications.send(notification)
- consoleIds.forEach({
- LOG.info("Welcome Home triggered: $it")
- facts.put("welcomeHome" + "_${it}", it)
- })
- })
+ consoleIds.forEach({
+ LOG.info("Welcome Home triggered: $it")
+ facts.put("welcomeHome" + "_${it}", it)
+ })
+})
rules.add()
- .name("Welcome home reset")
- .when({
- facts ->
+ .name("Welcome home reset")
+ .when({
+ facts ->
- def consoleIds = facts.matchAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .attributeValue(AttributeType.LOCATION.name, new ValueEmptyPredicate()))
- .filter({facts.getOptional("welcomeHome" + "_${it.id}").isPresent()})
- .map({it.id})
- .collect()
+ def consoleIds = facts.matchAssetState(new AssetQuery()
+ .type(AssetType.CONSOLE)
+ .attributeValue(AttributeType.LOCATION.name, new ValueEmptyPredicate()))
+ .filter({ facts.getOptional("welcomeHome" + "_${it.id}").isPresent() })
+ .map({ it.id })
+ .collect()
- if (consoleIds.size() > 0) {
- facts.bind("consoleIds", consoleIds)
- true
- } else {
- false
- }
+ if (consoleIds.size() > 0) {
+ facts.bind("consoleIds", consoleIds)
+ true
+ } else {
+ false
+ }
- })
- .then(
- {
- facts ->
+})
+ .then(
+ {
+ facts ->
- List<String> consoleIds = facts.bound("consoleIds")
+ List<String> consoleIds = facts.bound("consoleIds")
- consoleIds.forEach({
- LOG.info("Welcome Home Reset Triggered: $it")
- facts.remove("welcomeHome" + "_${it}")
- })
- })
+ consoleIds.forEach({
+ LOG.info("Welcome Home Reset Triggered: $it")
+ facts.remove("welcomeHome" + "_${it}")
+ })
+ })
diff --git a/model/src/main/java/org/openremote/model/notification/AbstractNotificationMessage.java b/model/src/main/java/org/openremote/model/notification/AbstractNotificationMessage.java
index 6aaf547dd..6fc353ecc 100644
--- a/model/src/main/java/org/openremote/model/notification/AbstractNotificationMessage.java
+++ b/model/src/main/java/org/openremote/model/notification/AbstractNotificationMessage.java
@@ -23,9 +23,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openremote.model.value.ObjectValue;
-@JsonSubTypes(
- @JsonSubTypes.Type(value = PushNotificationMessage.class, name = PushNotificationMessage.TYPE)
-)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = PushNotificationMessage.class, name = PushNotificationMessage.TYPE),
+ @JsonSubTypes.Type(value = EmailNotificationMessage.class, name = EmailNotificationMessage.TYPE)
+})
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
diff --git a/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java b/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
index 8d37c17bc..bbe0845ea 100644
--- a/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
+++ b/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
@@ -246,7 +246,6 @@ public class BaseAssetQuery<CHILD extends BaseAssetQuery<CHILD>> {
public AttributePredicate[] attribute;
public AttributeMetaPredicate[] attributeMeta;
public CalendarEventActivePredicate calendarEventActive;
- public LocationPredicate location;
// Ordering
public OrderBy orderBy;
public int limit;
@@ -476,11 +475,6 @@ public class BaseAssetQuery<CHILD extends BaseAssetQuery<CHILD>> {
return (CHILD) this;
}
- public CHILD location(LocationPredicate locationPredicate) {
- this.location = locationPredicate;
- return (CHILD) this;
- }
-
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
diff --git a/model/src/main/java/org/openremote/model/query/filter/BooleanPredicate.java b/model/src/main/java/org/openremote/model/query/filter/BooleanPredicate.java
index 2e9c5c6b5..894cb137d 100644
--- a/model/src/main/java/org/openremote/model/query/filter/BooleanPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/BooleanPredicate.java
@@ -22,8 +22,9 @@ package org.openremote.model.query.filter;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Values;
-public class BooleanPredicate implements ValuePredicate<Boolean> {
+public class BooleanPredicate implements ValuePredicate {
+ public static final String name = "boolean";
public boolean value;
public BooleanPredicate() {
@@ -56,7 +57,7 @@ public class BooleanPredicate implements ValuePredicate<Boolean> {
@Override
public ObjectValue toModelValue() {
ObjectValue objectValue = Values.createObject();
- objectValue.put("predicateType", "BooleanPredicate");
+ objectValue.put("predicateType", name);
objectValue.put("value", Values.create(value));
return objectValue;
}
diff --git a/model/src/main/java/org/openremote/model/query/filter/DateTimePredicate.java b/model/src/main/java/org/openremote/model/query/filter/DateTimePredicate.java
index b77dcc862..7db256f47 100644
--- a/model/src/main/java/org/openremote/model/query/filter/DateTimePredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/DateTimePredicate.java
@@ -23,8 +23,9 @@ import org.openremote.model.query.BaseAssetQuery;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Values;
-public class DateTimePredicate implements ValuePredicate<Long> {
+public class DateTimePredicate implements ValuePredicate {
+ public static final String name = "datetime";
public String value; // Sliding window value e.g. 1h or fixed date time
public String rangeValue; // Sliding window value e.g. 1h or fixed date time (used as upper bound when Operator.BETWEEN)
public BaseAssetQuery.Operator operator = BaseAssetQuery.Operator.EQUALS;
@@ -85,7 +86,7 @@ public class DateTimePredicate implements ValuePredicate<Long> {
public ObjectValue toModelValue() {
ObjectValue objectValue = Values.createObject();
- objectValue.put("predicateType", "StringPredicate");
+ objectValue.put("predicateType", name);
objectValue.put("dateFormat", Values.create(dateFormat));
objectValue.put("value", Values.create(value));
objectValue.put("rangeValue", Values.create(rangeValue));
diff --git a/model/src/main/java/org/openremote/model/query/filter/LocationPredicate.java b/model/src/main/java/org/openremote/model/query/filter/GeofencePredicate.java
similarity index 65%
rename from model/src/main/java/org/openremote/model/query/filter/LocationPredicate.java
rename to model/src/main/java/org/openremote/model/query/filter/GeofencePredicate.java
index 01fe3eacf..cd04b4fc1 100644
--- a/model/src/main/java/org/openremote/model/query/filter/LocationPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/GeofencePredicate.java
@@ -19,21 +19,15 @@
*/
package org.openremote.model.query.filter;
-import com.fasterxml.jackson.annotation.JsonSubTypes;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
+public abstract class GeofencePredicate implements ValuePredicate {
-@JsonSubTypes({
- @JsonSubTypes.Type(value = RadialLocationPredicate.class, name = RadialLocationPredicate.name),
- @JsonSubTypes.Type(value = RectangularLocationPredicate.class, name = RectangularLocationPredicate.name)
-})
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.NAME,
- include = JsonTypeInfo.As.PROPERTY,
- property = "predicateType"
-)
-
-public abstract class LocationPredicate {
+ public boolean negated;
// TODO: switch return type to location object
public abstract double[] getCentrePoint();
+
+ public GeofencePredicate negate() {
+ negated = true;
+ return this;
+ }
}
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
new file mode 100644
index 000000000..0ce854217
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/query/filter/LocationAttributePredicate.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.query.filter;
+
+import org.openremote.model.attribute.AttributeType;
+import org.openremote.model.query.BaseAssetQuery;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.openremote.model.attribute.AttributeType.LOCATION;
+
+public class LocationAttributePredicate extends AttributePredicate {
+
+ public LocationAttributePredicate(GeofencePredicate geofencePredicate) {
+ super(new StringPredicate(AttributeType.LOCATION.getName()), geofencePredicate);
+ }
+
+ public static Optional<GeofencePredicate> getLocationPredicate(List<AttributePredicate> attributePredicates) {
+ return attributePredicates.stream()
+ .filter(attributePredicate -> attributePredicate.name != null
+ && attributePredicate.name.match == BaseAssetQuery.Match.EXACT
+ && LOCATION.getName().equals(attributePredicate.name.value)
+ && attributePredicate.value instanceof GeofencePredicate)
+ .findFirst()
+ .map(attributePredicate -> (GeofencePredicate) attributePredicate.value);
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/query/filter/NumberPredicate.java b/model/src/main/java/org/openremote/model/query/filter/NumberPredicate.java
index 251e63981..55990e580 100644
--- a/model/src/main/java/org/openremote/model/query/filter/NumberPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/NumberPredicate.java
@@ -23,8 +23,9 @@ import org.openremote.model.query.BaseAssetQuery;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Values;
-public class NumberPredicate implements ValuePredicate<Double> {
+public class NumberPredicate implements ValuePredicate {
+ public static final String name = "number";
public double value;
public double rangeValue; // Used as upper bound when Operator.BETWEEN
public BaseAssetQuery.Operator operator = BaseAssetQuery.Operator.EQUALS;
@@ -90,7 +91,7 @@ public class NumberPredicate implements ValuePredicate<Double> {
public ObjectValue toModelValue() {
ObjectValue objectValue = Values.createObject();
- objectValue.put("predicateType", "StringPredicate");
+ objectValue.put("predicateType", name);
objectValue.put("value", Values.create(value));
objectValue.put("rangeValue", Values.create(rangeValue));
objectValue.put("operator", Values.create(operator.toString()));
diff --git a/model/src/main/java/org/openremote/model/query/filter/ObjectValueKeyPredicate.java b/model/src/main/java/org/openremote/model/query/filter/ObjectValueKeyPredicate.java
index e619b4346..da1a1faa9 100644
--- a/model/src/main/java/org/openremote/model/query/filter/ObjectValueKeyPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/ObjectValueKeyPredicate.java
@@ -22,7 +22,7 @@ package org.openremote.model.query.filter;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Values;
-public class ObjectValueKeyPredicate implements ValuePredicate<String> {
+public class ObjectValueKeyPredicate implements ValuePredicate {
public boolean negated;
public String key;
diff --git a/model/src/main/java/org/openremote/model/query/filter/RadialLocationPredicate.java b/model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.java
similarity index 76%
rename from model/src/main/java/org/openremote/model/query/filter/RadialLocationPredicate.java
rename to model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.java
index 5c3cb4952..233aa0bd3 100644
--- a/model/src/main/java/org/openremote/model/query/filter/RadialLocationPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.java
@@ -21,19 +21,20 @@ package org.openremote.model.query.filter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Values;
import java.util.Objects;
-public class RadialLocationPredicate extends LocationPredicate {
+public class RadialGeofencePredicate extends GeofencePredicate {
public static final String name = "radial";
- public boolean negated;
public int radius;
public double lat;
public double lng;
@JsonCreator
- public RadialLocationPredicate(@JsonProperty("radius") int radius,
+ public RadialGeofencePredicate(@JsonProperty("radius") int radius,
@JsonProperty("lat") double lat,
@JsonProperty("lng") double lng,
@JsonProperty("negated") boolean negated) {
@@ -43,13 +44,14 @@ public class RadialLocationPredicate extends LocationPredicate {
this.negated = negated;
}
- public RadialLocationPredicate(@JsonProperty("radius") int radius,
+ public RadialGeofencePredicate(@JsonProperty("radius") int radius,
@JsonProperty("lat") double lat,
@JsonProperty("lng") double lng) {
this(radius, lat, lng, false);
}
- public RadialLocationPredicate negate() {
+ @Override
+ public RadialGeofencePredicate negate() {
negated = true;
return this;
}
@@ -70,7 +72,7 @@ public class RadialLocationPredicate extends LocationPredicate {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- RadialLocationPredicate that = (RadialLocationPredicate) o;
+ RadialGeofencePredicate that = (RadialGeofencePredicate) o;
return negated == that.negated &&
radius == that.radius &&
Double.compare(that.lat, lat) == 0 &&
@@ -86,4 +88,15 @@ public class RadialLocationPredicate extends LocationPredicate {
public double[] getCentrePoint() {
return new double[]{lng, lat};
}
+
+ @Override
+ public ObjectValue toModelValue() {
+ ObjectValue objectValue = Values.createObject();
+ objectValue.put("predicateType", name);
+ objectValue.put("radius", radius);
+ objectValue.put("lat", lat);
+ objectValue.put("lng", lng);
+ objectValue.put("negated", negated);
+ return objectValue;
+ }
}
diff --git a/model/src/main/java/org/openremote/model/query/filter/RectangularLocationPredicate.java b/model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.java
similarity index 78%
rename from model/src/main/java/org/openremote/model/query/filter/RectangularLocationPredicate.java
rename to model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.java
index 53cf7e588..ac5483e21 100644
--- a/model/src/main/java/org/openremote/model/query/filter/RectangularLocationPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.java
@@ -21,20 +21,21 @@ package org.openremote.model.query.filter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Values;
import java.util.Objects;
-public class RectangularLocationPredicate extends LocationPredicate {
+public class RectangularGeofencePredicate extends GeofencePredicate {
public static final String name = "rect";
- public boolean negated;
public double latMin;
public double lngMin;
public double latMax;
public double lngMax;
@JsonCreator
- public RectangularLocationPredicate(@JsonProperty("latMin") double latMin,
+ public RectangularGeofencePredicate(@JsonProperty("latMin") double latMin,
@JsonProperty("lngMin") double lngMin,
@JsonProperty("latMax") double latMax,
@JsonProperty("lngMax") double lngMax,
@@ -46,14 +47,15 @@ public class RectangularLocationPredicate extends LocationPredicate {
this.negated = negated;
}
- public RectangularLocationPredicate(@JsonProperty("latMin") double latMin,
+ public RectangularGeofencePredicate(@JsonProperty("latMin") double latMin,
@JsonProperty("lngMin") double lngMin,
@JsonProperty("latMax") double latMax,
@JsonProperty("lngMax") double lngMax) {
this(latMin, lngMin, latMax, lngMax, false);
}
- public RectangularLocationPredicate negate() {
+ @Override
+ public RectangularGeofencePredicate negate() {
negated = true;
return this;
}
@@ -78,7 +80,7 @@ public class RectangularLocationPredicate extends LocationPredicate {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- RectangularLocationPredicate that = (RectangularLocationPredicate) o;
+ RectangularGeofencePredicate that = (RectangularGeofencePredicate) o;
return negated == that.negated &&
Double.compare(that.latMin, latMin) == 0 &&
Double.compare(that.lngMin, lngMin) == 0 &&
@@ -97,4 +99,16 @@ public class RectangularLocationPredicate extends LocationPredicate {
double y = (latMin + latMax) / 2;
return new double[]{x, y};
}
+
+ @Override
+ public ObjectValue toModelValue() {
+ ObjectValue objectValue = Values.createObject();
+ objectValue.put("predicateType", name);
+ objectValue.put("latMin", latMin);
+ objectValue.put("lngMin", lngMin);
+ objectValue.put("latMax", latMax);
+ objectValue.put("lngMax", lngMax);
+ objectValue.put("negated", negated);
+ return objectValue;
+ }
}
diff --git a/model/src/main/java/org/openremote/model/query/filter/StringArrayPredicate.java b/model/src/main/java/org/openremote/model/query/filter/StringArrayPredicate.java
index ad3ea78ca..4ce6e579d 100644
--- a/model/src/main/java/org/openremote/model/query/filter/StringArrayPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/StringArrayPredicate.java
@@ -25,8 +25,9 @@ import org.openremote.model.value.Values;
import java.util.Arrays;
-public class StringArrayPredicate implements ValuePredicate<String[]> {
+public class StringArrayPredicate implements ValuePredicate {
+ public static final String name = "string-array";
public StringPredicate[] predicates = new StringPredicate[0];
public StringArrayPredicate() {
@@ -56,7 +57,7 @@ public class StringArrayPredicate implements ValuePredicate<String[]> {
@Override
public ObjectValue toModelValue() {
ObjectValue objectValue = Values.createObject();
- objectValue.put("predicateType", "StringArrayPredicate");
+ objectValue.put("predicateType", name);
ArrayValue valuesArray = Values.createArray();
for (StringPredicate stringPredicate : predicates) {
valuesArray.add(stringPredicate.toModelValue());
diff --git a/model/src/main/java/org/openremote/model/query/filter/StringPredicate.java b/model/src/main/java/org/openremote/model/query/filter/StringPredicate.java
index ca900de0a..d1791b005 100644
--- a/model/src/main/java/org/openremote/model/query/filter/StringPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/StringPredicate.java
@@ -25,8 +25,9 @@ import org.openremote.model.value.Values;
import java.util.Locale;
-public class StringPredicate implements ValuePredicate<String> {
+public class StringPredicate implements ValuePredicate {
+ public static final String name = "string";
public BaseAssetQuery.Match match = BaseAssetQuery.Match.EXACT;
public boolean caseSensitive = true;
public String value;
@@ -87,7 +88,7 @@ public class StringPredicate implements ValuePredicate<String> {
public ObjectValue toModelValue() {
ObjectValue objectValue = Values.createObject();
- objectValue.put("predicateType", "StringPredicate");
+ objectValue.put("predicateType", name);
objectValue.put("match", Values.create(match.toString()));
objectValue.put("caseSensitive", Values.create(caseSensitive));
objectValue.put("value", Values.create(value));
diff --git a/model/src/main/java/org/openremote/model/query/filter/ValueEmptyPredicate.java b/model/src/main/java/org/openremote/model/query/filter/ValueEmptyPredicate.java
index d27c4cf8a..a0d7bae1e 100644
--- a/model/src/main/java/org/openremote/model/query/filter/ValueEmptyPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/ValueEmptyPredicate.java
@@ -20,10 +20,9 @@
package org.openremote.model.query.filter;
import org.openremote.model.value.ObjectValue;
-import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
-public class ValueEmptyPredicate implements ValuePredicate<Value> {
+public class ValueEmptyPredicate implements ValuePredicate {
@Override
public ObjectValue toModelValue() {
diff --git a/model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.java b/model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.java
index 72ce2ad94..34bed26d7 100644
--- a/model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.java
@@ -20,10 +20,9 @@
package org.openremote.model.query.filter;
import org.openremote.model.value.ObjectValue;
-import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
-public class ValueNotEmptyPredicate implements ValuePredicate<Value> {
+public class ValueNotEmptyPredicate implements ValuePredicate {
@Override
public ObjectValue toModelValue() {
diff --git a/model/src/main/java/org/openremote/model/query/filter/ValuePredicate.java b/model/src/main/java/org/openremote/model/query/filter/ValuePredicate.java
index e9d8e1f8d..1fe4e993d 100644
--- a/model/src/main/java/org/openremote/model/query/filter/ValuePredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/ValuePredicate.java
@@ -24,18 +24,19 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openremote.model.value.ObjectValue;
@JsonSubTypes({
- @JsonSubTypes.Type(value = StringPredicate.class, name = "string"),
- @JsonSubTypes.Type(value = BooleanPredicate.class, name = "boolean"),
- @JsonSubTypes.Type(value = StringArrayPredicate.class, name = "string-array"),
- @JsonSubTypes.Type(value = DateTimePredicate.class, name = "datetime"),
- @JsonSubTypes.Type(value = NumberPredicate.class, name = "number")
+ @JsonSubTypes.Type(value = StringPredicate.class, name = StringPredicate.name),
+ @JsonSubTypes.Type(value = BooleanPredicate.class, name = BooleanPredicate.name),
+ @JsonSubTypes.Type(value = StringArrayPredicate.class, name = StringArrayPredicate.name),
+ @JsonSubTypes.Type(value = DateTimePredicate.class, name = DateTimePredicate.name),
+ @JsonSubTypes.Type(value = NumberPredicate.class, name = NumberPredicate.name),
+ @JsonSubTypes.Type(value = RadialGeofencePredicate.class, name = RadialGeofencePredicate.name),
+ @JsonSubTypes.Type(value = RectangularGeofencePredicate.class, name = RectangularGeofencePredicate.name)
})
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
- include = JsonTypeInfo.As.PROPERTY,
property = "predicateType"
)
-public interface ValuePredicate<T> {
+public interface ValuePredicate {
ObjectValue toModelValue();
}
diff --git a/model/src/main/java/org/openremote/model/rules/json/JsonRulesetDefinition.java b/model/src/main/java/org/openremote/model/rules/json/JsonRulesetDefinition.java
index 51b56bf36..86a2c2be8 100644
--- a/model/src/main/java/org/openremote/model/rules/json/JsonRulesetDefinition.java
+++ b/model/src/main/java/org/openremote/model/rules/json/JsonRulesetDefinition.java
@@ -20,5 +20,5 @@
package org.openremote.model.rules.json;
public class JsonRulesetDefinition {
- protected Rule[] rules;
+ public Rule[] rules;
}
diff --git a/model/src/main/java/org/openremote/model/rules/json/predicate/AttributePredicate.java b/model/src/main/java/org/openremote/model/rules/json/predicate/AttributePredicate.java
index ea5d2ff69..304e1b16d 100644
--- a/model/src/main/java/org/openremote/model/rules/json/predicate/AttributePredicate.java
+++ b/model/src/main/java/org/openremote/model/rules/json/predicate/AttributePredicate.java
@@ -28,10 +28,8 @@ import org.openremote.model.query.filter.ValuePredicate;
* There is an implicit AND condition between each value
*/
// TODO: Introduce value converter functionality and merge with existing AttributePredicate
-public class AttributePredicate {
- public StringPredicate name;
+public class AttributePredicate extends org.openremote.model.query.filter.AttributePredicate {
public AttributeMetaPredicate[] meta;
- public ValuePredicate value;
public ValuePredicate lastValue;
public DateTimePredicate valueTimestamp;
}
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 163ec1386..2d710286a 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -16,6 +16,7 @@ import org.openremote.model.asset.CalendarEventConfiguration
import org.openremote.model.calendar.CalendarEvent
import org.openremote.model.calendar.RecurrenceRule
import org.openremote.model.geo.GeoJSONPoint
+import org.openremote.model.query.filter.LocationAttributePredicate
import org.openremote.model.query.filter.PathPredicate
import org.openremote.model.query.filter.AttributeMetaPredicate
import org.openremote.model.query.filter.AttributePredicate
@@ -23,8 +24,8 @@ import org.openremote.model.query.filter.AttributeRefPredicate
import org.openremote.model.query.filter.BooleanPredicate
import org.openremote.model.query.filter.NumberPredicate
import org.openremote.model.query.filter.ParentPredicate
-import org.openremote.model.query.filter.RadialLocationPredicate
-import org.openremote.model.query.filter.RectangularLocationPredicate
+import org.openremote.model.query.filter.RadialGeofencePredicate
+import org.openremote.model.query.filter.RectangularGeofencePredicate
import org.openremote.model.query.filter.StringPredicate
import org.openremote.model.query.filter.TenantPredicate
import org.openremote.test.ManagerContainerTrait
@@ -661,7 +662,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
def assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
- .location(new RadialLocationPredicate(10, 51.44541688237109d, 5.460315214821094d))
+ .attributes(new LocationAttributePredicate(new RadialGeofencePredicate(10, 51.44541688237109d, 5.460315214821094d)))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
.orderBy(new OrderBy(NAME))
)
@@ -693,7 +694,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
- .location(new RadialLocationPredicate(10, 51.44541688237109d, 5.460315214821094d))
+ .attributes(new LocationAttributePredicate(new RadialGeofencePredicate(10, 51.44541688237109d, 5.460315214821094d)))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
.orderBy(new OrderBy(NAME))
)
@@ -706,7 +707,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
- .location(new RectangularLocationPredicate(51.44540d, 5.46031d, 51.44594d, 5.46110d))
+ .attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(51.44540d, 5.46031d, 51.44594d, 5.46110d)))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
.orderBy(new OrderBy(NAME))
)
@@ -728,7 +729,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
- .location(new RectangularLocationPredicate(51.44542d, 5.46032d, 51.44590d, 5.46100d))
+ .attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(51.44542d, 5.46032d, 51.44590d, 5.46100d)))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
.orderBy(new OrderBy(NAME))
)
@@ -740,7 +741,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
- .location(new RectangularLocationPredicate(51.44542d, 5.46032d, 51.44590d, 5.46100d).negate())
+ .attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(51.44542d, 5.46032d, 51.44590d, 5.46100d).negate()))
.tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
.orderBy(new OrderBy(NAME))
)
diff --git a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
index 0b406c4ad..2f5e7aec6 100644
--- a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
@@ -24,7 +24,7 @@ import org.openremote.model.notification.AbstractNotificationMessage
import org.openremote.model.notification.Notification
import org.openremote.model.notification.NotificationSendResult
import org.openremote.model.notification.PushNotificationMessage
-import org.openremote.model.query.filter.RadialLocationPredicate
+import org.openremote.model.query.filter.RadialGeofencePredicate
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.RulesResource
import org.openremote.model.rules.Ruleset
@@ -425,7 +425,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
when: "the geofences of a user linked console are requested by the authenticated user"
def geofences = authenticatedRulesResource.getAssetGeofences(null, testUser3Console1.id)
- def expectedLocationPredicate = new RadialLocationPredicate(100, SMART_HOME_LOCATION.y, SMART_HOME_LOCATION.x)
+ def expectedLocationPredicate = new RadialGeofencePredicate(100, SMART_HOME_LOCATION.y, SMART_HOME_LOCATION.x)
then: "the welcome home geofence should be retrieved"
assert expectedLocationPredicate.centrePoint.size() == 2
@@ -500,7 +500,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
)
newRuleset = rulesetStorageService.merge(newRuleset)
RulesEngine consoleParentEngine = null
- def newLocationPredicate = new RadialLocationPredicate(50, 0, -60)
+ def newLocationPredicate = new RadialGeofencePredicate(50, 0, -60)
then: "the new rule engine should be created and be running"
conditions.eventually {
@@ -548,7 +548,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
when: "an existing ruleset containing a radial location predicate is updated"
newRuleset.rules = getClass().getResource("/org/openremote/test/rules/BasicLocationPredicates2.groovy").text
newRuleset = rulesetStorageService.merge(newRuleset)
- newLocationPredicate = new RadialLocationPredicate(150, 10, 40)
+ newLocationPredicate = new RadialGeofencePredicate(150, 10, 40)
then: "a push notification should have been sent to the two remaining consoles telling them to refresh their geofences"
conditions.eventually {
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceLightsOnGeofenceTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceLightsOnGeofenceTest.groovy
index ce6a19409..0701b73f2 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceLightsOnGeofenceTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceLightsOnGeofenceTest.groovy
@@ -1,6 +1,6 @@
package org.openremote.test.rules.residence
-import org.junit.Ignore
+
import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.rules.RulesEngine
@@ -27,7 +27,6 @@ import static org.openremote.model.Constants.KEYCLOAK_CLIENT_ID
import static org.openremote.model.attribute.AttributeType.LOCATION
import static org.openremote.model.value.Values.parse
-@Ignore
class ResidenceLightsOnGeofenceTest extends Specification implements ManagerContainerTrait {
def "Turn all lights off when console exits the residence geofence"() {
@@ -49,7 +48,7 @@ class ResidenceLightsOnGeofenceTest extends Specification implements ManagerCont
"Demo Apartment - All Lights Off",
keycloakDemoSetup.customerATenant.id,
getClass().getResource("/org/openremote/test/rules/BasicLocationPredicates.json").text,
- Ruleset.Lang.SIMPLE
+ Ruleset.Lang.JSON
)
rulesetStorageService.merge(ruleset)
diff --git a/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.groovy b/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.groovy
index e53935116..febc098df 100644
--- a/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.groovy
+++ b/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.groovy
@@ -3,8 +3,9 @@ package org.openremote.test.rules
import org.openremote.manager.rules.RulesBuilder
import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.query.AssetQuery
-import org.openremote.model.query.filter.RadialLocationPredicate
-import org.openremote.model.query.filter.RectangularLocationPredicate
+import org.openremote.model.query.filter.LocationAttributePredicate
+import org.openremote.model.query.filter.RadialGeofencePredicate
+import org.openremote.model.query.filter.RectangularGeofencePredicate
RulesBuilder rules = binding.rules
@@ -12,7 +13,7 @@ rules.add()
.name("Another radial location predicate")
.when(
{ facts ->
- facts.matchFirstAssetState(new AssetQuery().location(new RadialLocationPredicate(50, 0, -60))).isPresent() &&
+ facts.matchFirstAssetState(new AssetQuery().attributes(new LocationAttributePredicate((new RadialGeofencePredicate(50, 0, -60))))).isPresent() &&
!facts.matchFirst("RadialLocation2").isPresent()
})
.then(
@@ -24,7 +25,7 @@ rules.add()
.name("Duplicate radial location predicate")
.when(
{ facts ->
- facts.matchFirstAssetState(new AssetQuery().location(new RadialLocationPredicate(100, ManagerDemoSetup.SMART_HOME_LOCATION.y, ManagerDemoSetup.SMART_HOME_LOCATION.x))).isPresent() &&
+ facts.matchFirstAssetState(new AssetQuery().attributes(new LocationAttributePredicate(new RadialGeofencePredicate(100, ManagerDemoSetup.SMART_HOME_LOCATION.y, ManagerDemoSetup.SMART_HOME_LOCATION.x)))).isPresent() &&
!facts.matchFirst("DuplicateLocation").isPresent()
})
.then(
@@ -36,7 +37,7 @@ rules.add()
.name("Rectangular location predicate")
.when(
{ facts ->
- facts.matchFirstAssetState(new AssetQuery().location(new RectangularLocationPredicate(0, 50, 50, 100))).isPresent() &&
+ facts.matchFirstAssetState(new AssetQuery().attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(0, 50, 50, 100)))).isPresent() &&
!facts.matchFirst("RectLocation").isPresent()
})
.then(
diff --git a/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.json b/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.json
index 11c7d0a7f..6937f65ec 100644
--- a/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.json
+++ b/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates.json
@@ -37,8 +37,8 @@
},
"notification": {
"name": "test",
+ "type": "push",
"message": {
- "type": "push",
"title": "Test title"
}
}
diff --git a/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates2.groovy b/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates2.groovy
index 32db053e1..00c30927d 100644
--- a/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates2.groovy
+++ b/test/src/test/resources/org/openremote/test/rules/BasicLocationPredicates2.groovy
@@ -3,8 +3,9 @@ package org.openremote.test.rules
import org.openremote.manager.rules.RulesBuilder
import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.query.AssetQuery
-import org.openremote.model.query.filter.RadialLocationPredicate
-import org.openremote.model.query.filter.RectangularLocationPredicate
+import org.openremote.model.query.filter.LocationAttributePredicate
+import org.openremote.model.query.filter.RadialGeofencePredicate
+import org.openremote.model.query.filter.RectangularGeofencePredicate
RulesBuilder rules = binding.rules
@@ -12,7 +13,7 @@ rules.add()
.name("Another radial location predicate")
.when(
{ facts ->
- facts.matchFirstAssetState(new AssetQuery().location(new RadialLocationPredicate(150, 10, 40))).isPresent() &&
+ facts.matchFirstAssetState(new AssetQuery().attributes(new LocationAttributePredicate(new RadialGeofencePredicate(150, 10, 40)))).isPresent() &&
!facts.matchFirst("RadialLocation2").isPresent()
})
.then(
@@ -24,7 +25,7 @@ rules.add()
.name("Duplicate radial location predicate")
.when(
{ facts ->
- facts.matchFirstAssetState(new AssetQuery().location(new RadialLocationPredicate(100, ManagerDemoSetup.SMART_HOME_LOCATION.y, ManagerDemoSetup.SMART_HOME_LOCATION.x))).isPresent() &&
+ facts.matchFirstAssetState(new AssetQuery().attributes(new LocationAttributePredicate(new RadialGeofencePredicate(100, ManagerDemoSetup.SMART_HOME_LOCATION.y, ManagerDemoSetup.SMART_HOME_LOCATION.x)))).isPresent() &&
!facts.matchFirst("Location").isPresent()
})
.then(
@@ -36,7 +37,7 @@ rules.add()
.name("Rectangular location predicate")
.when(
{ facts ->
- facts.matchFirstAssetState(new AssetQuery().location(new RectangularLocationPredicate(0, 50, 50, 100))).isPresent() &&
+ facts.matchFirstAssetState(new AssetQuery().attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(0, 50, 50, 100)))).isPresent() &&
!facts.matchFirst("RectLocation").isPresent()
})
.then(