100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Model updates: Removed ValueNotEmptyPredicate and added negate option to ValueEmptyPredicate also added some JSON schema annotations.
Rich Turnerb43728e5af70
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.javaindex 2ed6db7ba..96e9946df 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java@@ -1896,12 +1896,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic.append(location.latMax).append("))");}- } else if (nameValuePredicate.value instanceof ValueNotEmptyPredicate) {- valuePathInserter.accept(attributeBuilder, binders);- attributeBuilder.append("\\:\\:text IS NOT NULL");} else if (nameValuePredicate.value instanceof ValueEmptyPredicate) {valuePathInserter.accept(attributeBuilder, binders);- attributeBuilder.append("\\:\\:text IS NULL");+ attributeBuilder.append(((ValueEmptyPredicate) nameValuePredicate.value).negate ? "\\:\\:text IS NOT NULL" : "\\:\\:text IS NULL");} else if (nameValuePredicate.value instanceof CalendarEventPredicate) {final int pos = binders.size() + 1;java.sql.Timestamp when = new java.sql.Timestamp(((CalendarEventPredicate)nameValuePredicate.value).timestamp.getTime());diff --git a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.javaindex 1299d5a9b..f9dbeec9b 100644--- a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java+++ b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java@@ -193,7 +193,7 @@ public class EmailNotificationHandler implements NotificationHandler {.paths(new PathPredicate(targetId)).attributes(new AttributePredicate(new StringPredicate(Asset.EMAIL.getName()),- new ValueNotEmptyPredicate())));+ new ValueEmptyPredicate().negate(true))));if (assets.isEmpty()) {LOG.fine("No assets with email attribute descendants of target asset");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.javaindex 6b69a4661..a928c0301 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@@ -108,7 +108,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe.select(new AssetQuery.Select().excludePath(true).attributes(ConsoleAsset.CONSOLE_PROVIDERS.getName())).types(ConsoleAsset.class)- .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, new ValueNotEmptyPredicate(), false, new NameValuePredicate.Path("geofence"))))+ .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, new ValueEmptyPredicate().negate(true), false, new NameValuePredicate.Path("geofence")))).stream().map(asset -> (ConsoleAsset)asset).filter(ORConsoleGeofenceAssetAdapter::isLinkedToORConsoleGeofenceAdapter)diff --git a/model/src/main/java/org/openremote/model/provisioning/ProvisioningConfig.java b/model/src/main/java/org/openremote/model/provisioning/ProvisioningConfig.javaindex 49fccf906..e3248aa0f 100644--- a/model/src/main/java/org/openremote/model/provisioning/ProvisioningConfig.java+++ b/model/src/main/java/org/openremote/model/provisioning/ProvisioningConfig.java@@ -19,8 +19,10 @@*/package org.openremote.model.provisioning;+import com.fasterxml.jackson.annotation.JsonProperty;import com.fasterxml.jackson.annotation.JsonSubTypes;import com.fasterxml.jackson.annotation.JsonTypeInfo;+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;import org.openremote.model.Constants;import org.openremote.model.security.ClientRole;@@ -65,11 +67,12 @@ public abstract class ProvisioningConfig<T, U extends ProvisioningConfig<T, U>>@NotNull@Column(name = "NAME", nullable = false)- @Size(min = 3, max = 255, message = "{ProvisioningConfig.name.Size}")+ @Size(min = 1, max = 255, message = "{ProvisioningConfig.name.Size}")protected String name;@Column(name = "TYPE", nullable = false, updatable = false, insertable = false, length = 100, columnDefinition = "char(100)")@Size(min = 3, max = 100, message = "{ProvisioningConfig.type.Size}")+ @JsonDeserializeprotected String type;@Column(name = "REALM", nullable = false, updatable = false)@@ -165,6 +168,7 @@ public abstract class ProvisioningConfig<T, U extends ProvisioningConfig<T, U>>/*** Implementors must annotate the data field with @Column as JPA (Hibernate) doesn't work with generic fields*/+ @JsonPropertypublic abstract T getData();public abstract U setData(T data);diff --git a/model/src/main/java/org/openremote/model/provisioning/ProvisioningResource.java b/model/src/main/java/org/openremote/model/provisioning/ProvisioningResource.javaindex 71c4f2f9b..befa5af4d 100644--- a/model/src/main/java/org/openremote/model/provisioning/ProvisioningResource.java+++ b/model/src/main/java/org/openremote/model/provisioning/ProvisioningResource.java@@ -19,37 +19,32 @@*/package org.openremote.model.provisioning;-import org.openremote.model.Constants;import org.openremote.model.http.RequestParams;-import javax.annotation.security.RolesAllowed;import javax.validation.Valid;import javax.ws.rs.*;import static javax.ws.rs.core.MediaType.APPLICATION_JSON;+@Path("provisioning")public interface ProvisioningResource {@GET@Produces(APPLICATION_JSON)- @RolesAllowed({Constants.REALM_ADMIN_ROLE})- ProvisioningConfig<?, ?> getProvisioningConfigs();+ ProvisioningConfig<?, ?>[] getProvisioningConfigs();@POST@Consumes(APPLICATION_JSON)@Produces(APPLICATION_JSON)- @RolesAllowed({Constants.REALM_ADMIN_ROLE})long createProvisioningConfig(ProvisioningConfig<?, ?> provisioningConfig);@PUT@Path("{id}")@Consumes(APPLICATION_JSON)- @RolesAllowed({Constants.REALM_ADMIN_ROLE})void updateProvisioningConfig(@BeanParam RequestParams requestParams, @PathParam("id") Long id, @Valid ProvisioningConfig<?, ?> provisioningConfig);@DELETE@Path("{id}")@Produces(APPLICATION_JSON)- @RolesAllowed({Constants.REALM_ADMIN_ROLE})void deleteProvisioningConfig(@BeanParam RequestParams requestParams, @PathParam("id") Long id);}diff --git a/model/src/main/java/org/openremote/model/provisioning/X509ProvisioningConfig.java b/model/src/main/java/org/openremote/model/provisioning/X509ProvisioningConfig.javaindex 9cefe2f79..f33279cbf 100644--- a/model/src/main/java/org/openremote/model/provisioning/X509ProvisioningConfig.java+++ b/model/src/main/java/org/openremote/model/provisioning/X509ProvisioningConfig.java@@ -19,6 +19,7 @@*/package org.openremote.model.provisioning;+import com.fasterxml.jackson.annotation.JsonIgnore;import org.openremote.model.util.TextUtil;import javax.persistence.Column;@@ -34,10 +35,13 @@ import static org.openremote.model.Constants.PERSISTENCE_JSON_VALUE_TYPE;@DiscriminatorValue("x509")public class X509ProvisioningConfig extends ProvisioningConfig<X509ProvisioningData, X509ProvisioningConfig> {+ @JsonIgnore@Transientprotected X509Certificate certificate;- @Transient boolean valid = true;+ @JsonIgnore+ @Transient+ boolean valid = true;@Column(name = DATA_PROPERTY_NAME, columnDefinition = "jsonb")@org.hibernate.annotations.Type(type = PERSISTENCE_JSON_VALUE_TYPE)diff --git a/model/src/main/java/org/openremote/model/query/AssetQuery.java b/model/src/main/java/org/openremote/model/query/AssetQuery.javaindex 01836a1f6..74d10697e 100644--- a/model/src/main/java/org/openremote/model/query/AssetQuery.java+++ b/model/src/main/java/org/openremote/model/query/AssetQuery.java@@ -401,7 +401,7 @@ public class AssetQuery {}public AssetQuery attributeValue(String name) {- return attributeValue(name, new ValueNotEmptyPredicate());+ return attributeValue(name, new ValueEmptyPredicate().negate(true));}public AssetQuery attributeValue(String name, boolean b) {diff --git a/model/src/main/java/org/openremote/model/query/filter/ArrayPredicate.java b/model/src/main/java/org/openremote/model/query/filter/ArrayPredicate.javaindex 9481494bc..02cf6c68c 100644--- a/model/src/main/java/org/openremote/model/query/filter/ArrayPredicate.java+++ b/model/src/main/java/org/openremote/model/query/filter/ArrayPredicate.java@@ -19,6 +19,7 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import com.fasterxml.jackson.annotation.JsonCreator;import com.fasterxml.jackson.annotation.JsonProperty;import org.openremote.model.util.ValueUtil;@@ -40,6 +41,7 @@ import java.util.function.Supplier;* There is an implicit 'and' between each specified condition; the negation is applied once all the criteria are* evaluated.*/+@JsonClassDescription("Predicate for array values; will match based on configured options.")public class ArrayPredicate extends ValuePredicate {public static final String name = "array";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.javaindex 9cbc55e76..69c53de67 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@@ -19,11 +19,17 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import org.openremote.model.util.ValueUtil;import java.util.function.Predicate;import java.util.function.Supplier;+/**+ * Predicate for boolean values; will evaluate the value as a boolean and match against this predicates value, any value+ * that is not a boolean will not match.+ */+@JsonClassDescription("Predicate for boolean values; will evaluate the value as a boolean and match against this predicates value, any value that is not a boolean will not match")public class BooleanPredicate extends ValuePredicate {public static final String name = "boolean";diff --git a/model/src/main/java/org/openremote/model/query/filter/CalendarEventPredicate.java b/model/src/main/java/org/openremote/model/query/filter/CalendarEventPredicate.javaindex 17fae85aa..d4f7617ca 100644--- a/model/src/main/java/org/openremote/model/query/filter/CalendarEventPredicate.java+++ b/model/src/main/java/org/openremote/model/query/filter/CalendarEventPredicate.java@@ -19,8 +19,10 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import com.fasterxml.jackson.annotation.JsonCreator;import com.fasterxml.jackson.annotation.JsonProperty;+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle;import org.openremote.model.calendar.CalendarEvent;import org.openremote.model.util.Pair;import org.openremote.model.util.ValueUtil;@@ -31,9 +33,10 @@ import java.util.function.Predicate;import java.util.function.Supplier;/**- * Can be applied to {@link org.openremote.model.attribute.Attribute}s of type- * {@link ValueType#CALENDAR_EVENT}.+ * Can be applied to {@link org.openremote.model.attribute.Attribute}s of type {@link ValueType#CALENDAR_EVENT}.*/+@JsonSchemaTitle("Calendar")+@JsonClassDescription("Predicate for calendar event values; will match based on whether the calendar event is active for the specified time.")public class CalendarEventPredicate extends ValuePredicate {public static final String name = "calendar-event";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.javaindex e5fc9d370..d7e6181fa 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@@ -19,6 +19,7 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import org.openremote.model.query.AssetQuery;import org.openremote.model.util.Pair;import org.openremote.model.util.TimeUtil;@@ -33,6 +34,7 @@ import java.util.function.Supplier;* (e.g. yyyy-MM-dd'T'HH:mm:ssZ or yyyy-MM-dd'T'HH:mm:ss\u00b1HH:mm), offset and time are optional, if no offset* information is supplied then UTC is assumed.*/+@JsonClassDescription("Predicate for date time values; provided values should be valid ISO 8601 datetime strings (e.g. yyyy-MM-dd'T'HH:mm:ssZ or yyyy-MM-dd'T'HH:mm:ss\\u00b1HH:mm), offset and time are optional, if no offset information is supplied then UTC is assumed.")public class DateTimePredicate extends ValuePredicate {public static final String name = "datetime";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.javaindex bdf80d7ff..e9a38dcdb 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@@ -19,6 +19,7 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import org.openremote.model.query.AssetQuery;import org.openremote.model.util.NumberComparator;import org.openremote.model.util.ValueUtil;@@ -26,6 +27,10 @@ import org.openremote.model.util.ValueUtil;import java.util.function.Predicate;import java.util.function.Supplier;+/**+ * Predicate for number values; will match based on configured options.+ */+@JsonClassDescription("Predicate for number values; will match based on configured options.")public class NumberPredicate extends ValuePredicate {public static final String name = "number";diff --git a/model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.java b/model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.javaindex 4741d731e..bc43b9180 100644--- a/model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.java+++ b/model/src/main/java/org/openremote/model/query/filter/RadialGeofencePredicate.java@@ -19,8 +19,10 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import com.fasterxml.jackson.annotation.JsonCreator;import com.fasterxml.jackson.annotation.JsonProperty;+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle;import com.vividsolutions.jts.geom.Coordinate;import org.geotools.referencing.GeodeticCalculator;import org.openremote.model.geo.GeoJSONPoint;@@ -30,6 +32,12 @@ import java.util.Objects;import java.util.function.Predicate;import java.util.function.Supplier;+/**+ * Predicate for GEO JSON point values; will return true if the point is within the specified radius of the specified+ * latitude and longitude unless negated.+ */+@JsonSchemaTitle("Radial geofence")+@JsonClassDescription("Predicate for GEO JSON point values; will return true if the point is within the specified radius of the specified latitude and longitude unless negated.")public class RadialGeofencePredicate extends GeofencePredicate {public static final String name = "radial";@@ -102,7 +110,7 @@ public class RadialGeofencePredicate extends GeofencePredicate {Coordinate coordinate;if (obj instanceof Coordinate) {- coordinate = (Coordinate)obj;+ coordinate = (Coordinate) obj;} else {coordinate = ValueUtil.getValue(obj, GeoJSONPoint.class).map(GeoJSONPoint::getCoordinates).orElse(null);}diff --git a/model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.java b/model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.javaindex 104198fca..20569dd3b 100644--- a/model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.java+++ b/model/src/main/java/org/openremote/model/query/filter/RectangularGeofencePredicate.java@@ -19,8 +19,10 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import com.fasterxml.jackson.annotation.JsonCreator;import com.fasterxml.jackson.annotation.JsonProperty;+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle;import com.vividsolutions.jts.geom.Coordinate;import com.vividsolutions.jts.geom.Envelope;import org.openremote.model.geo.GeoJSONPoint;@@ -30,6 +32,12 @@ import java.util.Objects;import java.util.function.Predicate;import java.util.function.Supplier;+/**+ * Predicate for GEO JSON point values; will return true if the point is within the specified rectangle specified as+ * latitude and longitude values of two corners unless negated.+ */+@JsonSchemaTitle("Rectangular geofence")+@JsonClassDescription("Predicate for GEO JSON point values; will return true if the point is within the specified rectangle specified as latitude and longitude values of two corners unless negated.")public class RectangularGeofencePredicate extends GeofencePredicate {public static final String name = "rect";@@ -103,7 +111,7 @@ public class RectangularGeofencePredicate extends GeofencePredicate {double y = (latMin + latMax) / 2;return new double[]{x, y};}-+@Overridepublic Predicate<Object> asPredicate(Supplier<Long> currentMillisSupplier) {return obj -> {@@ -112,7 +120,7 @@ public class RectangularGeofencePredicate extends GeofencePredicate {Coordinate coordinate;if (obj instanceof Coordinate) {- coordinate = (Coordinate)obj;+ coordinate = (Coordinate) obj;} else {coordinate = ValueUtil.getValue(obj, GeoJSONPoint.class).map(GeoJSONPoint::getCoordinates).orElse(null);}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.javaindex bf4366ea7..505573986 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@@ -19,15 +19,20 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;import org.openremote.model.query.AssetQuery;-import org.openremote.model.value.NameHolder;import org.openremote.model.util.ValueUtil;+import org.openremote.model.value.NameHolder;import java.util.Locale;import java.util.Objects;import java.util.function.Predicate;import java.util.function.Supplier;+/**+ * Predicate for string values; will match based on configured options.+ */+@JsonClassDescription("Predicate for string values; will match based on configured options.")public class StringPredicate extends ValuePredicate {public static final String name = "string";diff --git a/model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.java b/model/src/main/java/org/openremote/model/query/filter/ValueAnyPredicate.javasimilarity index 73%rename from model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.javarename to model/src/main/java/org/openremote/model/query/filter/ValueAnyPredicate.javaindex 53bd9e4b5..0e24c5e90 100644--- a/model/src/main/java/org/openremote/model/query/filter/ValueNotEmptyPredicate.java+++ b/model/src/main/java/org/openremote/model/query/filter/ValueAnyPredicate.java@@ -19,16 +19,20 @@*/package org.openremote.model.query.filter;-import java.util.Objects;+import com.fasterxml.jackson.annotation.JsonClassDescription;+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle;+import java.util.function.Predicate;import java.util.function.Supplier;-public class ValueNotEmptyPredicate extends ValuePredicate {+@JsonSchemaTitle("Any value")+@JsonClassDescription("Predicate that matches any value including null.")+public class ValueAnyPredicate extends ValuePredicate {- public static final String name = "value-not-empty";+ public static final String name = "value-any";@Overridepublic Predicate<Object> asPredicate(Supplier<Long> currentMillisSupplier) {- return obj -> !Objects.isNull(obj);+ return obj -> true;}}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.javaindex 409b5f6e0..62e0b9371 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@@ -19,16 +19,27 @@*/package org.openremote.model.query.filter;+import com.fasterxml.jackson.annotation.JsonClassDescription;+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle;+import java.util.Objects;import java.util.function.Predicate;import java.util.function.Supplier;+@JsonSchemaTitle("Empty value")+@JsonClassDescription("Predicate that matches any empty/null value; unless negated.")public class ValueEmptyPredicate extends ValuePredicate {public static final String name = "value-empty";+ public boolean negate;++ public ValueEmptyPredicate negate(boolean negate) {+ this.negate = negate;+ return this;+ }@Overridepublic Predicate<Object> asPredicate(Supplier<Long> currentMillisSupplier) {- return Objects::isNull;+ return obj -> negate != Objects.isNull(obj);}}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.javaindex 7eec30040..d553ba443 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@@ -35,8 +35,8 @@ import java.util.function.Supplier;@JsonSubTypes.Type(value = RadialGeofencePredicate.class, name = RadialGeofencePredicate.name),@JsonSubTypes.Type(value = RectangularGeofencePredicate.class, name = RectangularGeofencePredicate.name),@JsonSubTypes.Type(value = ArrayPredicate.class, name = ArrayPredicate.name),+ @JsonSubTypes.Type(value = ValueAnyPredicate.class, name = ValueAnyPredicate.name),@JsonSubTypes.Type(value = ValueEmptyPredicate.class, name = ValueEmptyPredicate.name),- @JsonSubTypes.Type(value = ValueNotEmptyPredicate.class, name = ValueNotEmptyPredicate.name),@JsonSubTypes.Type(value = CalendarEventPredicate.class, name = CalendarEventPredicate.name)})@JsonTypeInfo(