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 2020/03/23 14:00:45 UTC

[syncope] 01/02: [SYNCOPE-1535] Extending to Push

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

commit c2e661ca8316ac3d68c3be038269a431d0b68df7
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Mon Mar 23 12:03:27 2020 +0100

    [SYNCOPE-1535] Extending to Push
---
 .../java/pushpull/PullJobDelegate.java             |  5 +-
 .../java/pushpull/PushJobDelegate.java             | 85 +++++++++++++---------
 2 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullJobDelegate.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullJobDelegate.java
index 7d47b85..829a6b8 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullJobDelegate.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullJobDelegate.java
@@ -275,6 +275,7 @@ public class PullJobDelegate extends AbstractProvisioningJobDelegate<PullTask> i
             }
         }
 
+        // ...then provisions for any types
         ProvisionSorter provisionSorter = new DefaultProvisionSorter();
         if (pullTask.getResource().getProvisionSorter() != null) {
             try {
@@ -283,8 +284,7 @@ public class PullJobDelegate extends AbstractProvisioningJobDelegate<PullTask> i
                 LOG.error("While building {}", pullTask.getResource().getProvisionSorter(), e);
             }
         }
-        // ...then provisions for any types
-        SyncopePullResultHandler handler;
+
         GroupPullResultHandler ghandler = buildGroupHandler();
         for (Provision provision : pullTask.getResource().getProvisions().stream().
                 filter(provision -> provision.getMapping() != null).sorted(provisionSorter).
@@ -292,6 +292,7 @@ public class PullJobDelegate extends AbstractProvisioningJobDelegate<PullTask> i
 
             status.set("Pulling " + provision.getObjectClass().getObjectClassValue());
 
+            SyncopePullResultHandler handler;
             switch (provision.getAnyType().getKind()) {
                 case USER:
                     handler = buildUserHandler();
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushJobDelegate.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushJobDelegate.java
index 603008f..25f20cd 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushJobDelegate.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushJobDelegate.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Collectors;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.MutablePair;
 import org.apache.syncope.common.lib.SyncopeConstants;
@@ -47,6 +48,7 @@ import org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter;
 import org.apache.syncope.core.persistence.api.entity.user.User;
 import org.apache.syncope.core.persistence.api.search.SearchCondVisitor;
 import org.apache.syncope.core.provisioning.api.Connector;
+import org.apache.syncope.core.provisioning.api.ProvisionSorter;
 import org.apache.syncope.core.provisioning.api.pushpull.AnyObjectPushResultHandler;
 import org.apache.syncope.core.provisioning.api.pushpull.GroupPushResultHandler;
 import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
@@ -54,6 +56,7 @@ import org.apache.syncope.core.provisioning.api.pushpull.PushActions;
 import org.apache.syncope.core.provisioning.api.pushpull.RealmPushResultHandler;
 import org.apache.syncope.core.provisioning.api.pushpull.SyncopePushResultHandler;
 import org.apache.syncope.core.provisioning.api.pushpull.UserPushResultHandler;
+import org.apache.syncope.core.provisioning.java.DefaultProvisionSorter;
 import org.apache.syncope.core.spring.ImplementationManager;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -204,49 +207,59 @@ public class PushJobDelegate extends AbstractProvisioningJobDelegate<PushTask> {
         }
 
         // ...then provisions for any types
-        for (Provision provision : pushTask.getResource().getProvisions()) {
-            if (provision.getMapping() != null) {
-                status.set("Pushing " + provision.getAnyType().getKey());
+        ProvisionSorter provisionSorter = new DefaultProvisionSorter();
+        if (pushTask.getResource().getProvisionSorter() != null) {
+            try {
+                provisionSorter = ImplementationManager.build(pushTask.getResource().getProvisionSorter());
+            } catch (Exception e) {
+                LOG.error("While building {}", pushTask.getResource().getProvisionSorter(), e);
+            }
+        }
 
-                AnyDAO<?> anyDAO = anyUtilsFactory.getInstance(provision.getAnyType().getKind()).dao();
+        for (Provision provision : pushTask.getResource().getProvisions().stream().
+                filter(provision -> provision.getMapping() != null).sorted(provisionSorter).
+                collect(Collectors.toList())) {
 
-                SyncopePushResultHandler handler;
-                switch (provision.getAnyType().getKind()) {
-                    case USER:
-                        handler = buildUserHandler();
-                        break;
+            status.set("Pushing " + provision.getAnyType().getKey());
 
-                    case GROUP:
-                        handler = buildGroupHandler();
-                        break;
+            AnyDAO<?> anyDAO = anyUtilsFactory.getInstance(provision.getAnyType().getKind()).dao();
 
-                    case ANY_OBJECT:
-                    default:
-                        handler = buildAnyObjectHandler();
-                }
-                handler.setProfile(profile);
-
-                Optional<? extends PushTaskAnyFilter> anyFilter = pushTask.getFilter(provision.getAnyType());
-                String filter = anyFilter.isPresent()
-                        ? anyFilter.get().getFIQLCond()
-                        : null;
-                SearchCond cond = StringUtils.isBlank(filter)
-                        ? anyDAO.getAllMatchingCond()
-                        : SearchCondConverter.convert(searchCondVisitor, filter);
-                int count = searchDAO.count(
+            SyncopePushResultHandler handler;
+            switch (provision.getAnyType().getKind()) {
+                case USER:
+                    handler = buildUserHandler();
+                    break;
+
+                case GROUP:
+                    handler = buildGroupHandler();
+                    break;
+
+                case ANY_OBJECT:
+                default:
+                    handler = buildAnyObjectHandler();
+            }
+            handler.setProfile(profile);
+
+            Optional<? extends PushTaskAnyFilter> anyFilter = pushTask.getFilter(provision.getAnyType());
+            String filter = anyFilter.isPresent()
+                    ? anyFilter.get().getFIQLCond()
+                    : null;
+            SearchCond cond = StringUtils.isBlank(filter)
+                    ? anyDAO.getAllMatchingCond()
+                    : SearchCondConverter.convert(searchCondVisitor, filter);
+            int count = searchDAO.count(
+                    Collections.singleton(profile.getTask().getSourceRealm().getFullPath()),
+                    cond,
+                    provision.getAnyType().getKind());
+            for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1 && !interrupt; page++) {
+                List<? extends Any<?>> anys = searchDAO.search(
                         Collections.singleton(profile.getTask().getSourceRealm().getFullPath()),
                         cond,
+                        page,
+                        AnyDAO.DEFAULT_PAGE_SIZE,
+                        Collections.<OrderByClause>emptyList(),
                         provision.getAnyType().getKind());
-                for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1 && !interrupt; page++) {
-                    List<? extends Any<?>> anys = searchDAO.search(
-                            Collections.singleton(profile.getTask().getSourceRealm().getFullPath()),
-                            cond,
-                            page,
-                            AnyDAO.DEFAULT_PAGE_SIZE,
-                            Collections.<OrderByClause>emptyList(),
-                            provision.getAnyType().getKind());
-                    doHandle(anys, handler, pushTask.getResource());
-                }
+                doHandle(anys, handler, pushTask.getResource());
             }
         }