syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject syncope git commit: [SYNCOPE-906] Feature provided
Date Mon, 18 Jul 2016 12:01:25 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 31dfc1c51 -> a4c9cfbec


[SYNCOPE-906] Feature provided


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

Branch: refs/heads/master
Commit: a4c9cfbecc96ef444e58348da772a891c7afef01
Parents: 31dfc1c
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Mon Jul 18 14:01:19 2016 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Mon Jul 18 14:01:19 2016 +0200

----------------------------------------------------------------------
 .../api/dao/search/MembershipCond.java          | 12 ++---
 .../api/dao/search/RelationshipCond.java        | 12 ++---
 .../api/search/SearchCondVisitor.java           |  4 +-
 .../api/search/SearchCondConverterTest.java     |  4 +-
 .../persistence/jpa/dao/JPAAnySearchDAO.java    | 48 ++++++++++++++++++--
 .../persistence/jpa/inner/AnySearchTest.java    | 16 +++----
 .../GroupMemberProvisionTaskJobDelegate.java    |  4 +-
 .../apache/syncope/fit/core/SearchITCase.java   | 13 ++----
 8 files changed, 74 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/MembershipCond.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/MembershipCond.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/MembershipCond.java
index 7f9bca5..1d09753 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/MembershipCond.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/MembershipCond.java
@@ -22,18 +22,18 @@ public class MembershipCond extends AbstractSearchCond {
 
     private static final long serialVersionUID = -728155256293925989L;
 
-    private String groupKey;
+    private String group;
 
-    public String getGroupKey() {
-        return groupKey;
+    public String getGroup() {
+        return group;
     }
 
-    public void setGroupKey(final String groupKey) {
-        this.groupKey = groupKey;
+    public void setGroup(final String group) {
+        this.group = group;
     }
 
     @Override
     public final boolean isValid() {
-        return groupKey != null;
+        return group != null;
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/RelationshipCond.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/RelationshipCond.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/RelationshipCond.java
index 587634f..069278e 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/RelationshipCond.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/RelationshipCond.java
@@ -22,18 +22,18 @@ public class RelationshipCond extends AbstractSearchCond {
 
     private static final long serialVersionUID = 6865985945516722103L;
 
-    private String anyObjectKey;
+    private String anyObject;
 
-    public String getAnyObjectKey() {
-        return anyObjectKey;
+    public String getAnyObject() {
+        return anyObject;
     }
 
-    public void setAnyObjectKey(final String anyObjectKey) {
-        this.anyObjectKey = anyObjectKey;
+    public void setAnyObject(final String anyObject) {
+        this.anyObject = anyObject;
     }
 
     @Override
     public final boolean isValid() {
-        return anyObjectKey != null;
+        return anyObject != null;
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
index 4e8374f..76c752b 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
@@ -106,13 +106,13 @@ public class SearchCondVisitor extends AbstractSearchConditionVisitor<SearchBean
 
                         case GROUPS:
                             MembershipCond groupCond = new MembershipCond();
-                            groupCond.setGroupKey(value);
+                            groupCond.setGroup(value);
                             leaf = SearchCond.getLeafCond(groupCond);
                             break;
 
                         case RELATIONSHIPS:
                             RelationshipCond relationshipCond = new RelationshipCond();
-                            relationshipCond.setAnyObjectKey(value);
+                            relationshipCond.setAnyObject(value);
                             leaf = SearchCond.getLeafCond(relationshipCond);
                             break;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/persistence-api/src/test/java/org/apache/syncope/core/persistence/api/search/SearchCondConverterTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/test/java/org/apache/syncope/core/persistence/api/search/SearchCondConverterTest.java
b/core/persistence-api/src/test/java/org/apache/syncope/core/persistence/api/search/SearchCondConverterTest.java
index 6141808..c5306dd 100644
--- a/core/persistence-api/src/test/java/org/apache/syncope/core/persistence/api/search/SearchCondConverterTest.java
+++ b/core/persistence-api/src/test/java/org/apache/syncope/core/persistence/api/search/SearchCondConverterTest.java
@@ -96,7 +96,7 @@ public class SearchCondConverterTest {
         assertEquals(SpecialAttr.RELATIONSHIPS + "==ca20ffca-1305-442f-be9a-3723a0cd88ca",
fiqlExpression);
 
         RelationshipCond relationshipCond = new RelationshipCond();
-        relationshipCond.setAnyObjectKey("ca20ffca-1305-442f-be9a-3723a0cd88ca");
+        relationshipCond.setAnyObject("ca20ffca-1305-442f-be9a-3723a0cd88ca");
         SearchCond simpleCond = SearchCond.getLeafCond(relationshipCond);
 
         assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
@@ -126,7 +126,7 @@ public class SearchCondConverterTest {
         assertEquals(SpecialAttr.GROUPS + "==e7ff94e8-19c9-4f0a-b8b7-28327edbf6ed", fiqlExpression);
 
         MembershipCond groupCond = new MembershipCond();
-        groupCond.setGroupKey("e7ff94e8-19c9-4f0a-b8b7-28327edbf6ed");
+        groupCond.setGroup("e7ff94e8-19c9-4f0a-b8b7-28327edbf6ed");
         SearchCond simpleCond = SearchCond.getLeafCond(groupCond);
 
         assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
index 7c4ed1d..ae802fd 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
@@ -65,6 +65,8 @@ import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
 import org.apache.syncope.core.persistence.api.entity.Realm;
+import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
+import org.apache.syncope.core.persistence.api.entity.group.Group;
 import org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
@@ -533,6 +535,17 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>>
implements AnySearchDAO
     private String getQuery(final RelationshipCond cond, final boolean not, final List<Object>
parameters,
             final SearchSupport svs) {
 
+        String rightAnyObjectKey;
+        if (SyncopeConstants.UUID_PATTERN.matcher(cond.getAnyObject()).matches()) {
+            rightAnyObjectKey = cond.getAnyObject();
+        } else {
+            AnyObject anyObject = anyObjectDAO.findByName(cond.getAnyObject());
+            rightAnyObjectKey = anyObject == null ? null : anyObject.getKey();
+        }
+        if (rightAnyObjectKey == null) {
+            return EMPTY_QUERY;
+        }
+
         StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").
                 append(svs.field().name).append(" WHERE ");
 
@@ -544,7 +557,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements
AnySearchDAO
 
         query.append("SELECT DISTINCT any_id FROM ").
                 append(svs.relationship().name).append(" WHERE ").
-                append("right_any_id=?").append(setParameter(parameters, cond.getAnyObjectKey())).
+                append("right_any_id=?").append(setParameter(parameters, rightAnyObjectKey)).
                 append(')');
 
         return query.toString();
@@ -553,6 +566,17 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>>
implements AnySearchDAO
     private String getQuery(final MembershipCond cond, final boolean not, final List<Object>
parameters,
             final SearchSupport svs) {
 
+        String groupKey;
+        if (SyncopeConstants.UUID_PATTERN.matcher(cond.getGroup()).matches()) {
+            groupKey = cond.getGroup();
+        } else {
+            Group group = groupDAO.findByName(cond.getGroup());
+            groupKey = group == null ? null : group.getKey();
+        }
+        if (groupKey == null) {
+            return EMPTY_QUERY;
+        }
+
         StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").
                 append(svs.field().name).append(" WHERE ");
 
@@ -564,7 +588,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements
AnySearchDAO
 
         query.append("SELECT DISTINCT any_id FROM ").
                 append(svs.membership().name).append(" WHERE ").
-                append("group_id=?").append(setParameter(parameters, cond.getGroupKey())).
+                append("group_id=?").append(setParameter(parameters, groupKey)).
                 append(')');
 
         if (not) {
@@ -575,7 +599,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements
AnySearchDAO
 
         query.append("SELECT DISTINCT any_id FROM ").
                 append(svs.dyngroupmembership().name).append(" WHERE ").
-                append("group_id=?").append(setParameter(parameters, cond.getGroupKey())).
+                append("group_id=?").append(setParameter(parameters, groupKey)).
                 append(')');
 
         return query.toString();
@@ -668,6 +692,20 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>>
implements AnySearchDAO
     private String getQuery(final MemberCond cond, final boolean not, final List<Object>
parameters,
             final SearchSupport svs) {
 
+        String memberKey;
+        if (SyncopeConstants.UUID_PATTERN.matcher(cond.getMember()).matches()) {
+            memberKey = cond.getMember();
+        } else {
+            Any member = userDAO.findByUsername(cond.getMember());
+            if (member == null) {
+                member = anyObjectDAO.findByName(cond.getMember());
+            }
+            memberKey = member == null ? null : member.getKey();
+        }
+        if (memberKey == null) {
+            return EMPTY_QUERY;
+        }
+
         StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").
                 append(svs.field().name).append(" WHERE ");
 
@@ -679,7 +717,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements
AnySearchDAO
 
         query.append("SELECT DISTINCT group_id AS any_id FROM ").
                 append(new SearchSupport(AnyTypeKind.USER).membership().name).append(" WHERE
").
-                append("any_id=?").append(setParameter(parameters, cond.getMember())).
+                append("any_id=?").append(setParameter(parameters, memberKey)).
                 append(')');
 
         if (not) {
@@ -690,7 +728,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements
AnySearchDAO
 
         query.append("SELECT DISTINCT group_id AS any_id FROM ").
                 append(new SearchSupport(AnyTypeKind.ANY_OBJECT).membership().name).append("
WHERE ").
-                append("any_id=?").append(setParameter(parameters, cond.getMember())).
+                append("any_id=?").append(setParameter(parameters, memberKey)).
                 append(')');
 
         return query.toString();

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
----------------------------------------------------------------------
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 5d64425..aa891a3 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
@@ -78,7 +78,7 @@ public class AnySearchTest extends AbstractTest {
         assertNotNull(anyObject);
 
         RelationshipCond relationshipCond = new RelationshipCond();
-        relationshipCond.setAnyObjectKey("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
+        relationshipCond.setAnyObject("Canon MF 8030cn");
         assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipCond),
AnyTypeKind.ANY_OBJECT));
 
         RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
@@ -92,10 +92,10 @@ public class AnySearchTest extends AbstractTest {
         assertNotNull(user);
 
         MembershipCond groupCond = new MembershipCond();
-        groupCond.setGroupKey("a3c1a693-a6be-483f-a2b3-5cfec146f4bf");
+        groupCond.setGroup("secretary");
         assertFalse(searchDAO.matches(user, SearchCond.getLeafCond(groupCond), AnyTypeKind.USER));
 
-        groupCond.setGroupKey("37d15e4c-cdc1-460b-a591-8505c8133806");
+        groupCond.setGroup("root");
         assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(groupCond), AnyTypeKind.USER));
 
         RoleCond roleCond = new RoleCond();
@@ -106,7 +106,7 @@ public class AnySearchTest extends AbstractTest {
         assertNotNull(user);
 
         RelationshipCond relationshipCond = new RelationshipCond();
-        relationshipCond.setAnyObjectKey("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
+        relationshipCond.setAnyObject("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
         assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(relationshipCond), AnyTypeKind.USER));
 
         RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
@@ -133,7 +133,7 @@ public class AnySearchTest extends AbstractTest {
         fullnameLeafCond.setExpression("%o%");
 
         MembershipCond groupCond = new MembershipCond();
-        groupCond.setGroupKey("37d15e4c-cdc1-460b-a591-8505c8133806");
+        groupCond.setGroup("root");
 
         AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
         loginDateCond.setSchema("loginDate");
@@ -197,7 +197,7 @@ public class AnySearchTest extends AbstractTest {
         fullnameLeafCond.setExpression("%o%");
 
         MembershipCond groupCond = new MembershipCond();
-        groupCond.setGroupKey("37d15e4c-cdc1-460b-a591-8505c8133806");
+        groupCond.setGroup("root");
 
         AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
         loginDateCond.setSchema("loginDate");
@@ -228,14 +228,14 @@ public class AnySearchTest extends AbstractTest {
     @Test
     public void searchByGroup() {
         MembershipCond groupCond = new MembershipCond();
-        groupCond.setGroupKey("37d15e4c-cdc1-460b-a591-8505c8133806");
+        groupCond.setGroup("root");
 
         List<User> users = searchDAO.search(SearchCond.getLeafCond(groupCond), AnyTypeKind.USER);
         assertNotNull(users);
         assertEquals(2, users.size());
 
         groupCond = new MembershipCond();
-        groupCond.setGroupKey("a3c1a693-a6be-483f-a2b3-5cfec146f4bf");
+        groupCond.setGroup("secretary");
 
         users = searchDAO.search(SearchCond.getNotLeafCond(groupCond), AnyTypeKind.USER);
         assertNotNull(users);

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/GroupMemberProvisionTaskJobDelegate.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/GroupMemberProvisionTaskJobDelegate.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/GroupMemberProvisionTaskJobDelegate.java
index 3c115b7..f324359 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/GroupMemberProvisionTaskJobDelegate.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/GroupMemberProvisionTaskJobDelegate.java
@@ -82,7 +82,7 @@ public class GroupMemberProvisionTaskJobDelegate extends AbstractSchedTaskJobDel
         result.append("provision\n\n");
 
         MembershipCond membershipCond = new MembershipCond();
-        membershipCond.setGroupKey(groupKey);
+        membershipCond.setGroup(groupKey);
         List<User> users = searchDAO.search(SearchCond.getLeafCond(membershipCond),
AnyTypeKind.USER);
         for (User user : users) {
             List<PropagationStatus> statuses = actionType == BulkMembersActionType.DEPROVISION
@@ -101,7 +101,7 @@ public class GroupMemberProvisionTaskJobDelegate extends AbstractSchedTaskJobDel
         }
 
         membershipCond = new MembershipCond();
-        membershipCond.setGroupKey(groupKey);
+        membershipCond.setGroup(groupKey);
         List<AnyObject> anyObjects = searchDAO.search(SearchCond.getLeafCond(membershipCond),
AnyTypeKind.ANY_OBJECT);
         for (AnyObject anyObject : anyObjects) {
             List<PropagationStatus> statuses = actionType == BulkMembersActionType.DEPROVISION

http://git-wip-us.apache.org/repos/asf/syncope/blob/a4c9cfbe/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
----------------------------------------------------------------------
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 ce3bc3a..2d9a20d 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
@@ -104,8 +104,7 @@ public class SearchITCase extends AbstractITCase {
     public void searchByGroup() {
         PagedResult<UserTO> matchingUsers = userService.search(
                 new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
-                fiql(SyncopeClient.getUserSearchConditionBuilder().
-                        inGroups("37d15e4c-cdc1-460b-a591-8505c8133806").query()).
+                fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups("root").query()).
                 build());
         assertNotNull(matchingUsers);
         assertFalse(matchingUsers.getResult().isEmpty());
@@ -296,7 +295,7 @@ public class SearchITCase extends AbstractITCase {
         PagedResult<AnyObjectTO> anyObjects = anyObjectService.search(new AnyQuery.Builder().realm(
                 SyncopeConstants.ROOT_REALM).
                 fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").
-                        inRelationships("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").query()).
+                        inRelationships("Canon MF 8030cn").query()).
                 build());
         assertNotNull(anyObjects);
         assertTrue(IterableUtils.matchesAny(anyObjects.getResult(), new Predicate<AnyObjectTO>()
{
@@ -308,8 +307,7 @@ public class SearchITCase extends AbstractITCase {
         }));
 
         PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
-                fiql(SyncopeClient.getUserSearchConditionBuilder().
-                        inRelationships("fc6dbc3a-6c07-4965-8781-921e7401a4a5").query()).
+                fiql(SyncopeClient.getUserSearchConditionBuilder().inRelationships("HP LJ
1300n").query()).
                 build());
         assertNotNull(users);
         assertTrue(IterableUtils.matchesAny(users.getResult(), new Predicate<UserTO>()
{
@@ -395,9 +393,8 @@ public class SearchITCase extends AbstractITCase {
 
     @Test
     public void member() {
-        PagedResult<GroupTO> groups = groupService.search(new AnyQuery.Builder().realm("/").page(1).size(1000).
-                fiql(SyncopeClient.getGroupSearchConditionBuilder().
-                        withMembers("1417acbe-cbf6-4277-9372-e75e04f97000").query()).
+        PagedResult<GroupTO> groups = groupService.search(new AnyQuery.Builder().realm("/").
+                fiql(SyncopeClient.getGroupSearchConditionBuilder().withMembers("rossini").query()).
                 build());
         assertNotNull(groups);
 


Mime
View raw message