Skip to content

armgit / core

Public Imported from GitHub
0

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

Bug fixes (Email notification duplication bug and AssetQueryPredicate geofence bug) also added AssetQueryPredicateTest

Rich Turner9e29c5f1792a
diff --git a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java
index b457530f9..f54ee5695 100644
--- a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java
+++ b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java
@@ -222,12 +222,14 @@ public class EmailNotificationHandler implements NotificationHandler {
}
EmailNotificationMessage email = (EmailNotificationMessage)message;
+ // Move to/cc/bcc to targets (for traceability) in sent notifications
if (email.getTo() != null) {
mappedTargets.addAll(
email.getTo().stream()
.map(recipient ->
new Notification.Target(Notification.TargetType.CUSTOM, recipient.getAddress()))
.collect(Collectors.toList()));
+ email.setTo((String) null);
}
if (email.getCc() != null) {
mappedTargets.addAll(
@@ -235,6 +237,7 @@ public class EmailNotificationHandler implements NotificationHandler {
.map(recipient ->
new Notification.Target(Notification.TargetType.CUSTOM, recipient.getAddress()))
.collect(Collectors.toList()));
+ email.setCc((String) null);
}
if (email.getBcc() != null) {
mappedTargets.addAll(
@@ -242,6 +245,7 @@ public class EmailNotificationHandler implements NotificationHandler {
.map(recipient ->
new Notification.Target(Notification.TargetType.CUSTOM, recipient.getAddress()))
.collect(Collectors.toList()));
+ email.setBcc((String) null);
}
return mappedTargets;
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 f33a6d114..8d18bd063 100644
--- a/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
+++ b/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
@@ -335,18 +335,18 @@ public class AssetQueryPredicate implements Predicate<AssetState> {
RadialGeofencePredicate radialLocationPredicate = (RadialGeofencePredicate) predicate;
GeodeticCalculator calculator = new GeodeticCalculator();
calculator.setStartingGeographicPoint(radialLocationPredicate.lng, radialLocationPredicate.lat);
- calculator.setDestinationGeographicPoint(coordinate.y, coordinate.x);
+ calculator.setDestinationGeographicPoint(coordinate.x, coordinate.y);
if (predicate.negated) {
return calculator.getOrthodromicDistance() > radialLocationPredicate.radius;
}
return calculator.getOrthodromicDistance() <= radialLocationPredicate.radius;
} 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)
+ // Again this is a euclidean plane so doesn't work perfectly for WGS lat/lng - the bigger the rectangle the less accurate it is)
RectangularGeofencePredicate rectangularLocationPredicate = (RectangularGeofencePredicate) predicate;
- Envelope envelope = new Envelope(rectangularLocationPredicate.latMin,
- rectangularLocationPredicate.lngMin,
- rectangularLocationPredicate.latMax,
- rectangularLocationPredicate.lngMax);
+ Envelope envelope = new Envelope(rectangularLocationPredicate.lngMin,
+ rectangularLocationPredicate.lngMax,
+ rectangularLocationPredicate.latMin,
+ rectangularLocationPredicate.latMax);
if (predicate.negated) {
return !envelope.contains(coordinate);
}
@@ -439,7 +439,7 @@ public class AssetQueryPredicate implements Predicate<AssetState> {
GeofencePredicate p = (GeofencePredicate) predicate;
return asPredicate(p).test(Optional.ofNullable(value)
.flatMap(GeoJSONPoint::fromValue)
- .map(point -> new Coordinate(point.getY(), point.getX()))
+ .map(point -> new Coordinate(point.getX(), point.getY()))
.orElse(null));
} else if (predicate instanceof ObjectValueKeyPredicate) {
diff --git a/model/src/main/java/org/openremote/model/notification/EmailNotificationMessage.java b/model/src/main/java/org/openremote/model/notification/EmailNotificationMessage.java
index 46480fcb8..0bc1ce4f6 100644
--- a/model/src/main/java/org/openremote/model/notification/EmailNotificationMessage.java
+++ b/model/src/main/java/org/openremote/model/notification/EmailNotificationMessage.java
@@ -137,8 +137,9 @@ public class EmailNotificationMessage extends AbstractNotificationMessage {
return replyTo;
}
- public void setReplyTo(Recipient replyTo) {
+ public EmailNotificationMessage setReplyTo(Recipient replyTo) {
this.replyTo = replyTo;
+ return this;
}
public List<Recipient> getTo() {
@@ -146,16 +147,17 @@ public class EmailNotificationMessage extends AbstractNotificationMessage {
}
public EmailNotificationMessage setTo(String...addresses) {
- return setTo(Arrays.stream(addresses).map(Recipient::new).collect(Collectors.toList()));
+ return setTo(addresses != null ? Arrays.stream(addresses).map(Recipient::new).collect(Collectors.toList()) : null);
}
public EmailNotificationMessage setTo(Recipient...recipients) {
- return setTo(Arrays.asList(recipients));
+ return setTo(recipients != null ? Arrays.asList(recipients) : null);
}
public EmailNotificationMessage setTo(List<Recipient> recipients) {
- if (to != null) {
- to.clear();
+ to = null;
+ if (recipients == null) {
+ return this;
}
return addTo(recipients);
@@ -183,16 +185,17 @@ public class EmailNotificationMessage extends AbstractNotificationMessage {
}
public EmailNotificationMessage setCc(String...addresses) {
- return setCc(Arrays.stream(addresses).map(Recipient::new).collect(Collectors.toList()));
+ return setCc(addresses != null ? Arrays.stream(addresses).map(Recipient::new).collect(Collectors.toList()) : null);
}
public EmailNotificationMessage setCc(Recipient...recipients) {
- return setCc(Arrays.asList(recipients));
+ return setCc(recipients != null ? Arrays.asList(recipients) : null);
}
public EmailNotificationMessage setCc(List<Recipient> recipients) {
- if (cc != null) {
- cc.clear();
+ cc = null;
+ if (recipients == null) {
+ return this;
}
return addCc(recipients);
@@ -220,16 +223,17 @@ public class EmailNotificationMessage extends AbstractNotificationMessage {
}
public EmailNotificationMessage setBcc(String...addresses) {
- return setBcc(Arrays.stream(addresses).map(Recipient::new).collect(Collectors.toList()));
+ return setBcc(addresses != null ? Arrays.stream(addresses).map(Recipient::new).collect(Collectors.toList()) : null);
}
public EmailNotificationMessage setBcc(Recipient...recipients) {
- return setBcc(Arrays.asList(recipients));
+ return setBcc(recipients != null ? Arrays.asList(recipients) : null);
}
public EmailNotificationMessage setBcc(List<Recipient> recipients) {
- if (bcc != null) {
- bcc.clear();
+ bcc = null;
+ if (recipients == null) {
+ return this;
}
return addBcc(recipients);
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryPredicateTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryPredicateTest.groovy
new file mode 100644
index 000000000..009fa93a9
--- /dev/null
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryPredicateTest.groovy
@@ -0,0 +1,37 @@
+package org.openremote.test.assets
+
+import com.vividsolutions.jts.geom.Coordinate
+import org.openremote.manager.rules.AssetQueryPredicate
+import org.openremote.model.query.filter.GeofencePredicate
+import org.openremote.model.query.filter.RadialGeofencePredicate
+import org.openremote.model.query.filter.RectangularGeofencePredicate
+import spock.lang.Specification
+
+import java.util.function.Predicate
+
+class AssetQueryPredicateTest extends Specification {
+
+ def "Rectangular Geofence Test"() {
+ given:
+ GeofencePredicate geofencePredicate = new RectangularGeofencePredicate(51.440914, 5.421723, 51.442755, 5.425151)
+ GeofencePredicate geofencePredicateNegated = new RectangularGeofencePredicate(51.440914, 5.421723, 51.442755, 5.425151).negate()
+ Predicate<Coordinate> coordinatePredicate = AssetQueryPredicate.asPredicate(geofencePredicate)
+ Predicate<Coordinate> coordinatePredicateNegated = AssetQueryPredicate.asPredicate(geofencePredicateNegated)
+
+ expect:
+ coordinatePredicate.test(new Coordinate(5.423, 51.441))
+ !coordinatePredicateNegated.test(new Coordinate(5.423, 51.441))
+ }
+
+ def "Radial geofence test"() {
+ given:
+ GeofencePredicate geofencePredicate = new RadialGeofencePredicate(100, 51.423, 5.441)
+ GeofencePredicate geofencePredicateNegated = new RadialGeofencePredicate(100, 51.423, 5.441).negate()
+ Predicate<Coordinate> coordinatePredicate = AssetQueryPredicate.asPredicate(geofencePredicate)
+ Predicate<Coordinate> coordinatePredicateNegated = AssetQueryPredicate.asPredicate(geofencePredicateNegated)
+
+ expect:
+ coordinatePredicate.test(new Coordinate(5.441, 51.423))
+ !coordinatePredicateNegated.test(new Coordinate(5.441, 51.423))
+ }
+}