You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2021/11/05 09:07:04 UTC

[syncope] branch 2_1_X updated: [SYNCOPE-1648] Cleanup AnyCond conditions

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new 42607fb  [SYNCOPE-1648] Cleanup AnyCond conditions
42607fb is described below

commit 42607fb6eb210f27ef79f4c6cd55dca3dbb1777f
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Fri Nov 5 09:01:59 2021 +0100

    [SYNCOPE-1648] Cleanup AnyCond conditions
---
 .../persistence/jpa/dao/PGJPAJSONAnySearchDAO.java | 24 ++++++++--------------
 .../core/persistence/jpa/inner/AnySearchTest.java  | 18 +++++++++++++++-
 .../org/apache/syncope/fit/core/SearchITCase.java  | 10 +++++++++
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
index 538bcbc..6ef0786 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
@@ -106,14 +106,13 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
             final List<Object> parameters,
             final SearchSupport svs) {
 
-        // This first branch is required for handling with not conditions given on multivalue fields (SYNCOPE-1419)
-        if (not && !(cond instanceof AnyCond)) {
+        if (not && cond.getType() == AttrCond.Type.ISNULL) {
+            cond.setType(AttrCond.Type.ISNOTNULL);
+            fillAttrQuery(anyUtils, query, attrValue, schema, cond, true, parameters, svs);
+        } else if (not) {
             query.append("NOT (");
             fillAttrQuery(anyUtils, query, attrValue, schema, cond, false, parameters, svs);
             query.append(')');
-        } else if (not && cond.getType() == AttrCond.Type.ISNULL) {
-            cond.setType(AttrCond.Type.ISNOTNULL);
-            fillAttrQuery(anyUtils, query, attrValue, schema, cond, true, parameters, svs);
         } else {
             String key = key(schema.getType());
 
@@ -231,15 +230,6 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
             return ALWAYS_FALSE_ASSERTION;
         }
 
-        // normalize NULL / NOT NULL checks
-        if (not) {
-            if (cond.getType() == AttrCond.Type.ISNULL) {
-                cond.setType(AttrCond.Type.ISNOTNULL);
-            } else if (cond.getType() == AttrCond.Type.ISNOTNULL) {
-                cond.setType(AttrCond.Type.ISNULL);
-            }
-        }
-
         StringBuilder query = new StringBuilder();
 
         switch (cond.getType()) {
@@ -737,8 +727,10 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
             final List<Object> parameters,
             final SearchSupport svs) {
 
-        // This first branch is required for handling with not conditions given on multivalue fields (SYNCOPE-1419)
-        if (not && !(cond instanceof AnyCond)) {
+        if (not && cond.getType() == AttrCond.Type.ISNULL) {
+            cond.setType(AttrCond.Type.ISNOTNULL);
+            fillAttrQuery(query, attrValue, schema, cond, true, parameters, svs);
+        } else if (not) {
             query.append("NOT (");
             fillAttrQuery(query, attrValue, schema, cond, false, parameters, svs);
             query.append(')');
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
index 8e543fe..e6692f9 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
@@ -147,7 +147,7 @@ public class AnySearchTest extends AbstractTest {
     }
 
     @Test
-    public void searchWithNotCondition() {
+    public void searchWithNotCondition_AttrCond() {
         AttrCond fullnameLeafCond = new AttrCond(AttrCond.Type.EQ);
         fullnameLeafCond.setSchema("fullname");
         fullnameLeafCond.setExpression("Giuseppe Verdi");
@@ -165,6 +165,22 @@ public class AnySearchTest extends AbstractTest {
     }
 
     @Test
+    public void searchWithNotCondition_AnyCond() {
+        AnyCond usernameLeafCond = new AnyCond(AttrCond.Type.EQ);
+        usernameLeafCond.setSchema("username");
+        usernameLeafCond.setExpression("verdi");
+
+        SearchCond cond = SearchCond.getNotLeaf(usernameLeafCond);
+        assertTrue(cond.isValid());
+
+        List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
+        assertNotNull(users);
+        assertEquals(4, users.size());
+
+        assertTrue(users.stream().noneMatch(user -> "verdi".equals(user.getUsername())));
+    }
+
+    @Test
     public void searchCaseInsensitiveWithNotCondition() {
         AttrCond fullnameLeafCond = new AttrCond(AttrCond.Type.IEQ);
         fullnameLeafCond.setSchema("fullname");
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
index 1a4272b..7e5ba76 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
@@ -772,4 +772,14 @@ public class SearchITCase extends AbstractITCase {
 
         assertEquals(total.getTotalCount(), matching.getTotalCount() + unmatching.getTotalCount());
     }
+
+    @Test
+    public void issueSYNCOPE1648() {
+        PagedResult<UserTO> matching = userService.search(
+                new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+                        fiql(SyncopeClient.getUserSearchConditionBuilder().
+                                is("username").notEqualTo("verdi").query()).
+                        build());
+        assertTrue(matching.getResult().stream().noneMatch(user -> "verdi".equals(user.getUsername())));
+    }
 }