syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject syncope git commit: [SYNCOPE-768] this fix extends search to null attributes as well
Date Fri, 19 Feb 2016 08:42:48 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X 949d2e62e -> 80625d3fd


[SYNCOPE-768] this fix extends search to null attributes as well


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

Branch: refs/heads/1_2_X
Commit: 80625d3fd65ffade7c211b45f738e7555f5eaf03
Parents: 949d2e6
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Fri Feb 19 09:42:20 2016 +0100
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Fri Feb 19 09:42:20 2016 +0100

----------------------------------------------------------------------
 .../dao/impl/SubjectSearchDAOImpl.java          | 40 ++++++++++++--------
 .../syncope/core/rest/SearchTestITCase.java     |  9 +++++
 2 files changed, 33 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/80625d3f/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 ebac233..2b6d004 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
@@ -35,6 +35,10 @@ import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.types.AttributeSchemaType;
 import org.apache.syncope.common.types.SubjectType;
+import org.apache.syncope.common.types.SubjectType;
+import org.apache.syncope.common.types.SubjectType;
+import org.apache.syncope.common.types.SubjectType;
+import org.apache.syncope.common.types.SubjectType;
 import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
 import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
 import org.apache.syncope.core.persistence.beans.AbstractSubject;
@@ -235,9 +239,17 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements
SubjectSear
     }
 
     private StringBuilder buildWhere(final OrderBySupport orderBySupport, final SubjectType
type) {
+        SearchSupport svs = new SearchSupport(type);
         final StringBuilder where = new StringBuilder(" u");
         for (SearchSupport.SearchView searchView : orderBySupport.views) {
-            where.append(',').append(searchView.name).append(' ').append(searchView.alias);
+            where.append(',');
+            if (searchView.name.equals(svs.attr().name)) {
+                where.append(" (SELECT * FROM ").append(searchView.name).append(" UNION ").
+                        append("SELECT * FROM ").append(svs.nullAttr().name).append(")");
+            } else {
+                where.append(searchView.name);
+            }
+            where.append(' ').append(searchView.alias);
         }
         where.append(" WHERE ");
         for (SearchSupport.SearchView searchView : orderBySupport.views) {
@@ -378,10 +390,8 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements
SubjectSear
             if (subject == null) {
                 LOG.error("Could not find {} with id {}, even though returned by the native
query",
                         type, subjectId);
-            } else {
-                if (!result.contains(subject)) {
-                    result.add(subject);
-                }
+            } else if (!result.contains(subject)) {
+                result.add(subject);
             }
         }
 
@@ -623,20 +633,18 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements
SubjectSear
                     append(" WHERE subject_id NOT IN (SELECT subject_id FROM ").
                     append(svs.nullAttr().name).
                     append(" WHERE schema_name='").append(schema.getName()).append("')");
+        } else if (cond.getType() == AttributeCond.Type.ISNULL) {
+            query.append(svs.nullAttr().name).
+                    append(" WHERE schema_name='").append(schema.getName()).append("'");
         } else {
-            if (cond.getType() == AttributeCond.Type.ISNULL) {
-                query.append(svs.nullAttr().name).
-                        append(" WHERE schema_name='").append(schema.getName()).append("'");
+            if (schema.isUniqueConstraint()) {
+                query.append(svs.uniqueAttr().name);
             } else {
-                if (schema.isUniqueConstraint()) {
-                    query.append(svs.uniqueAttr().name);
-                } else {
-                    query.append(svs.attr().name);
-                }
-                query.append(" WHERE schema_name='").append(schema.getName());
-
-                fillAttributeQuery(query, attrValue, schema, cond, not, parameters, svs);
+                query.append(svs.attr().name);
             }
+            query.append(" WHERE schema_name='").append(schema.getName());
+
+            fillAttributeQuery(query, attrValue, schema, cond, not, parameters, svs);
         }
 
         return query.toString();

http://git-wip-us.apache.org/repos/asf/syncope/blob/80625d3f/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 406d9b6..d168f32 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
@@ -187,4 +187,13 @@ public class SearchTestITCase extends AbstractTest {
         assertNotNull(matchingRoles);
         assertFalse(matchingRoles.getResult().isEmpty());
     }
+
+    @Test
+    public void issueSYNCOPE768() {
+        final PagedResult<UserTO> matchedUsers = userService.search(
+                SyncopeClient.getUserSearchConditionBuilder().is("username").notNullValue().query(),
+                SyncopeClient.getOrderByClauseBuilder().asc("type").build());
+
+        assertTrue(matchedUsers.getResult().size() >= 5);
+    }
 }


Mime
View raw message