syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject syncope git commit: SYNCOPE-929 - Braces are ignored for FIQL strings. Tests added.
Date Mon, 05 Sep 2016 13:50:30 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X d3c779f6b -> 8a916bf1e


SYNCOPE-929 - Braces are ignored for FIQL strings. Tests added.


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/8a916bf1
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/8a916bf1
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/8a916bf1

Branch: refs/heads/1_2_X
Commit: 8a916bf1e5c7ab0811dfb655653f4dee84e83f7a
Parents: d3c779f
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Mon Sep 5 12:16:57 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Mon Sep 5 14:50:14 2016 +0100

----------------------------------------------------------------------
 .../dao/impl/SubjectSearchDAOImpl.java          | 14 +++++++---
 .../persistence/dao/AttributableSearchTest.java | 27 ++++++++++++++++++++
 .../syncope/core/rest/SearchTestITCase.java     | 13 ++++++++++
 3 files changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/8a916bf1/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/SubjectSearchDAOImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/SubjectSearchDAOImpl.java
b/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/SubjectSearchDAOImpl.java
index 0b1dfd8..00ba41a 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/SubjectSearchDAOImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/SubjectSearchDAOImpl.java
@@ -426,17 +426,23 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements
SubjectSear
                 break;
 
             case AND:
-                query.append(getQuery(nodeCond.getLeftNodeCond(), parameters, type, svs)).
+                String andSubQuery = getQuery(nodeCond.getLeftNodeCond(), parameters, type,
svs).toString();
+                // Add extra parentheses
+                andSubQuery = andSubQuery.replaceFirst("WHERE ", "WHERE (");
+                query.append(andSubQuery).
                         append(" AND subject_id IN ( ").
                         append(getQuery(nodeCond.getRightNodeCond(), parameters, type, svs)).
-                        append(")");
+                        append("))");
                 break;
 
             case OR:
-                query.append(getQuery(nodeCond.getLeftNodeCond(), parameters, type, svs)).
+                String orSubQuery = getQuery(nodeCond.getLeftNodeCond(), parameters, type,
svs).toString();
+                // Add extra parentheses
+                orSubQuery = orSubQuery.replaceFirst("WHERE ", "WHERE (");
+                query.append(orSubQuery).
                         append(" OR subject_id IN ( ").
                         append(getQuery(nodeCond.getRightNodeCond(), parameters, type, svs)).
-                        append(")");
+                        append("))");
                 break;
 
             default:

http://git-wip-us.apache.org/repos/asf/syncope/blob/8a916bf1/core/src/test/java/org/apache/syncope/core/persistence/dao/AttributableSearchTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/persistence/dao/AttributableSearchTest.java
b/core/src/test/java/org/apache/syncope/core/persistence/dao/AttributableSearchTest.java
index 259b522..df91642 100644
--- a/core/src/test/java/org/apache/syncope/core/persistence/dao/AttributableSearchTest.java
+++ b/core/src/test/java/org/apache/syncope/core/persistence/dao/AttributableSearchTest.java
@@ -478,4 +478,31 @@ public class AttributableSearchTest {
         assertNotNull(count);
         assertTrue(count > 0);
     }
+
+    @Test
+    public void issueSYNCOPE929() {
+        AttributeCond rossiniCond = new AttributeCond(AttributeCond.Type.EQ);
+        rossiniCond.setSchema("surname");
+        rossiniCond.setExpression("Rossini");
+
+        AttributeCond genderCond = new AttributeCond(AttributeCond.Type.EQ);
+        genderCond.setSchema("gender");
+        genderCond.setExpression("M");
+
+        SearchCond orCond =
+            SearchCond.getOrCond(SearchCond.getLeafCond(rossiniCond),
+                                 SearchCond.getLeafCond(genderCond));
+
+        AttributeCond belliniCond = new AttributeCond(AttributeCond.Type.EQ);
+        belliniCond.setSchema("surname");
+        belliniCond.setExpression("Bellini");
+
+        SearchCond searchCond =
+            SearchCond.getAndCond(orCond, SearchCond.getLeafCond(belliniCond));
+
+        List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
+                searchCond, SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(1, users.size());
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/8a916bf1/core/src/test/java/org/apache/syncope/core/rest/SearchTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/SearchTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/SearchTestITCase.java
index b58261c..24b5da5 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/SearchTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/SearchTestITCase.java
@@ -216,4 +216,17 @@ public class SearchTestITCase extends AbstractTest {
 
         assertTrue(matchedUsers.getResult().size() > usersWithType.size());
     }
+
+    @Test
+    public void issueSYNCOPE929() {
+        PagedResult<UserTO> matchingUsers = userService.search(
+                "(surname==Rossini,gender==M);surname==Bellini");
+
+        assertNotNull(matchingUsers);
+
+        assertFalse(matchingUsers.getResult().isEmpty());
+        for (UserTO user : matchingUsers.getResult()) {
+            assertTrue(user.getUsername().startsWith("bellini"));
+        }
+    }
 }


Mime
View raw message