syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [01/10] syncope git commit: [SYNCOPE-712] Searching roles by parent
Date Thu, 29 Oct 2015 09:40:02 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 1ebc0bcd0 -> e486aaf3a


[SYNCOPE-712] Searching roles by parent


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

Branch: refs/heads/master
Commit: fb577531bd39cb80b8ab81eefc344e04e5672af4
Parents: 03c9bc2
Author: Marco Di Sabatino Di Diodoro <mdisabatino@apache.org>
Authored: Mon Oct 19 16:23:08 2015 +0200
Committer: Marco Di Sabatino Di Diodoro <mdisabatino@apache.org>
Committed: Mon Oct 19 16:23:08 2015 +0200

----------------------------------------------------------------------
 .../core/persistence/dao/impl/SubjectSearchDAOImpl.java  | 11 ++++++++---
 .../apache/syncope/core/services/RoleServiceImpl.java    | 11 ++++++++---
 .../org/apache/syncope/core/rest/SearchTestITCase.java   |  9 +++++++++
 3 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/fb577531/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 5550690..ebac233 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
@@ -31,6 +31,7 @@ import javax.persistence.TemporalType;
 import javax.validation.ValidationException;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
+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;
@@ -59,6 +60,8 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements SubjectSear
 
     private static final String EMPTY_ATTR_QUERY = "SELECT subject_id FROM user_search_attr
WHERE 1=2";
 
+    private static final String[] SUBJECT_FIELDS = new String[] { "parent", "userOwner",
"roleOwner" };
+
     @Autowired
     private UserDAO userDAO;
 
@@ -645,7 +648,10 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements
SubjectSear
 
         final AttributableUtil attrUtil = AttributableUtil.getInstance(type.asAttributableType());
 
-        Field subjectField = ReflectionUtils.findField(attrUtil.attributableClass(), cond.getSchema());
+        int subjFieldIdx = ArrayUtils.indexOf(SUBJECT_FIELDS, StringUtils.substringBeforeLast(cond.getSchema(),
"_"));
+        Field subjectField = ReflectionUtils.findField(
+                attrUtil.attributableClass(),
+                subjFieldIdx == -1 ? cond.getSchema() : SUBJECT_FIELDS[subjFieldIdx]);
         if (subjectField == null) {
             LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
             return EMPTY_ATTR_QUERY;
@@ -682,8 +688,7 @@ public class SubjectSearchDAOImpl extends AbstractDAOImpl implements SubjectSear
             if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(),
"getId") != null) {
                 cond.setSchema(cond.getSchema() + "_id");
                 schema.setType(AttributeSchemaType.Long);
-            }
-            if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(),
"getName") != null) {
+            } else if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(),
"getName") != null) {
                 cond.setSchema(cond.getSchema() + "_name");
                 schema.setType(AttributeSchemaType.String);
             }

http://git-wip-us.apache.org/repos/asf/syncope/blob/fb577531/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java b/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
index 04d48ea..639ab2e 100644
--- a/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
@@ -33,7 +33,6 @@ import org.apache.syncope.common.types.ResourceAssociationActionType;
 import org.apache.syncope.common.types.ResourceDeassociationActionType;
 import org.apache.syncope.common.util.CollectionWrapper;
 import org.apache.syncope.core.persistence.dao.search.OrderByClause;
-import org.apache.syncope.core.persistence.dao.search.SearchCond;
 import org.apache.syncope.core.rest.controller.RoleController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -117,10 +116,16 @@ public class RoleServiceImpl extends AbstractServiceImpl implements
RoleService
     public PagedResult<RoleTO> search(
             final String fiql, final Integer page, final Integer size, final String orderBy,
final boolean details) {
 
-        SearchCond cond = getSearchCond(fiql);
         List<OrderByClause> orderByClauses = getOrderByClauses(orderBy);
         return buildPagedResult(
-                controller.search(cond, page, size, orderByClauses, details), page, size,
controller.searchCount(cond));
+                controller.search(getSearchCond(fiql),
+                        page,
+                        size,
+                        orderByClauses,
+                        details),
+                page,
+                size,
+                controller.searchCount(getSearchCond(fiql)));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/fb577531/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 27751c5..406d9b6 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
@@ -178,4 +178,13 @@ public class SearchTestITCase extends AbstractTest {
             assertNotNull(user);
         }
     }
+
+    @Test
+    public void issueSYNCOPE712() {
+        final PagedResult<RoleTO> matchingRoles = roleService.search(
+                SyncopeClient.getRoleSearchConditionBuilder().is("parent").equalTo(1L).query());
+
+        assertNotNull(matchingRoles);
+        assertFalse(matchingRoles.getResult().isEmpty());
+    }
 }


Mime
View raw message