changeset 1244:86ef81592f67

Implement negation of query filter closer to underlying API. Previously andNot() negated the whole filter and it's usage in IsUnique was actually a misunderstanding. Having not() as in javax.persistence.criteria.Predicate seems to be more intuitive for negating the whole filter and more flexible.
author Tom Gottfried <tom@intevation.de>
date Fri, 16 Dec 2016 12:06:34 +0100
parents b652f4c9b75c
children e0b461d4cd8e
files src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java src/main/java/de/intevation/lada/util/data/QueryBuilder.java src/main/java/de/intevation/lada/validation/rules/ort/IsUnique.java
diffstat 3 files changed, 10 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Thu Dec 15 16:16:32 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Fri Dec 16 12:06:34 2016 +0100
@@ -104,7 +104,7 @@
         QueryBuilder<Deskriptoren> builder = new QueryBuilder<Deskriptoren>(
             repository.entityManager("stamm"),
             Deskriptoren.class);
-        builder.andNot("sn", 0);
+        builder.and("sn", 0).not();
         if (params.containsKey("layer") &&
             !params.containsKey("parents")) {
             String layer = params.getFirst("layer");
--- a/src/main/java/de/intevation/lada/util/data/QueryBuilder.java	Thu Dec 15 16:16:32 2016 +0100
+++ b/src/main/java/de/intevation/lada/util/data/QueryBuilder.java	Fri Dec 16 12:06:34 2016 +0100
@@ -79,20 +79,14 @@
     }
 
     /**
-     * Logical AND NOT operation.
+     * Negate filter.
      *
-     * @param id    The database column name.
-     * @param value The filter value
-     * @return The builder itself.
      */
-    public QueryBuilder<T> andNot(String id, Object value) {
-        Predicate p = this.builder.equal(this.root.get(id), value);
-        if (this.filter != null) {
-            this.filter = this.builder.and(this.filter, p).not();
+    public QueryBuilder<T> not() {
+        if (this.filter == null) {
+            return this;
         }
-        else {
-            this.filter = this.builder.and(p).not();
-        }
+        this.filter = this.filter.not();
         return this;
     }
 
--- a/src/main/java/de/intevation/lada/validation/rules/ort/IsUnique.java	Thu Dec 15 16:16:32 2016 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/ort/IsUnique.java	Fri Dec 16 12:06:34 2016 +0100
@@ -31,12 +31,12 @@
 
         QueryBuilder<Ort> builder = new QueryBuilder<Ort>(
             repository.entityManager("stamm"), Ort.class);
+        if (ort.getId() != null) {
+            // Consider UPDATE
+            builder.and("id", ort.getId()).not();
+        }
         builder.and("netzbetreiberId", ort.getNetzbetreiberId());
         builder.and("ortId", ort.getOrtId());
-        if (ort.getId() != null) {
-            // Consider UPDATE
-            builder.andNot("id", ort.getId());
-        }
         if (!repository.filterPlain(builder.getQuery(), "stamm").isEmpty()) {
             Violation violation = new Violation();
             violation.addError("ortId", 672);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)