ref #7590 replacing not flag in restrictions by AND_NOT and OR_NOT operators
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 27 Jul 2018 06:49:53 +0000 (08:49 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 27 Jul 2018 06:50:10 +0000 (08:50 +0200)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/Restriction.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/NameServiceImplTest.java

index 452d43ea375ac932f382461a93b71f4fa7800589..0880423cd7c727a949dcff7bea7006235932dd85 100644 (file)
@@ -10,6 +10,7 @@ package eu.etaxonomy.cdm.persistence.dao.common;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.EnumSet;
 import java.util.List;
 
 import eu.etaxonomy.cdm.persistence.query.MatchMode;
@@ -25,15 +26,17 @@ public class Restriction<T extends Object> {
 
     public enum Operator {
         AND,
-        OR;
+        OR,
+        AND_NOT,
+        OR_NOT;
     }
 
+    private static final EnumSet<Operator> NOT_OPERATORS = EnumSet.of(Operator.AND_NOT, Operator.OR_NOT);
+
     private String propertyName;
 
     private MatchMode matchMode;
 
-    private boolean not = false;
-
     private Operator operator = Operator.AND;
 
     private List<T> values = null;
@@ -43,16 +46,11 @@ public class Restriction<T extends Object> {
      * @param matchMode is only applied if the <code>value</code> is a <code>String</code> object
      */
     public Restriction(String propertyName, MatchMode matchMode, T ... values ) {
-        this(propertyName, false, matchMode, values);
+        this(propertyName, Operator.AND, matchMode, values);
     }
 
-    public Restriction(String propertyName, boolean not, MatchMode matchMode, T ... values ) {
-        this(propertyName, false, Operator.AND, matchMode, values);
-    }
-
-    public Restriction(String propertyName, boolean not, Operator operator, MatchMode matchMode, T ... values ) {
+    public Restriction(String propertyName, Operator operator, MatchMode matchMode, T ... values ) {
         this.propertyName = propertyName;
-        this.not = not;
         this.operator = operator;
         if(values.length > 0){
             this.setValues(Arrays.asList(values));
@@ -115,21 +113,6 @@ public class Restriction<T extends Object> {
         getValues().add(value);
     }
 
-    /**
-     *
-     * @return the not
-     */
-    public boolean isNot() {
-        return not;
-    }
-
-    /**
-     * @param not the not to set
-     */
-    public void setNot(boolean not) {
-        this.not = not;
-    }
-
     /**
      * @return the operator
      */
@@ -144,4 +127,11 @@ public class Restriction<T extends Object> {
         this.operator = operator;
     }
 
+    /**
+     * @return
+     */
+    public boolean isNot() {
+        return NOT_OPERATORS.contains(operator);
+    }
+
 }
index a9caf7c1cf1777bba96ade76159d0316e85e475b..bd10da5b6f94a86ada96546b869b6f9193cbe4c5 100644 (file)
@@ -928,7 +928,7 @@ public class NameServiceImplTest extends CdmTransactionalIntegrationTest {
         result = nameService.findByTitleWithRestrictions(null, "Name2", MatchMode.EXACT, restrictions, null, null, null, null);
         assertEquals(0l, result.getCount().longValue());
 
-        restrictions = Arrays.asList(new Restriction<String>("typeDesignations.typeSpecimen.titleCache", false, Restriction.Operator.OR, MatchMode.EXACT, "Specimen1"));
+        restrictions = Arrays.asList(new Restriction<String>("typeDesignations.typeSpecimen.titleCache", Restriction.Operator.OR, MatchMode.EXACT, "Specimen1"));
         result = nameService.findByTitleWithRestrictions(null, "Name2", MatchMode.EXACT, restrictions, null, null, null, null);
         assertEquals(2l, result.getCount().longValue());