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 2022/09/08 11:13:29 UTC

[syncope] branch master updated: Support for SyncDeltaType.CREATE and SyncDeltaType.UPDATE

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ce48ff23e Support for SyncDeltaType.CREATE and SyncDeltaType.UPDATE
1ce48ff23e is described below

commit 1ce48ff23ee08aa2a934b6d5b39ec0eac6dc6440
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Thu Sep 8 12:39:08 2022 +0200

    Support for SyncDeltaType.CREATE and SyncDeltaType.UPDATE
---
 .../java/pushpull/AbstractPullResultHandler.java   | 117 ++++++++++---------
 .../pushpull/DefaultRealmPullResultHandler.java    | 115 ++++++++++---------
 .../pushpull/DefaultUserPullResultHandler.java     | 125 ++++++++++++---------
 3 files changed, 194 insertions(+), 163 deletions(-)

diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AbstractPullResultHandler.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AbstractPullResultHandler.java
index 03fe521fe9..f9204488d5 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AbstractPullResultHandler.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AbstractPullResultHandler.java
@@ -68,7 +68,6 @@ import org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils;
 import org.apache.syncope.core.spring.security.DelegatedAdministrationException;
 import org.identityconnectors.framework.common.objects.Attribute;
 import org.identityconnectors.framework.common.objects.SyncDelta;
-import org.identityconnectors.framework.common.objects.SyncDeltaType;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -784,68 +783,78 @@ public abstract class AbstractPullResultHandler extends AbstractSyncopeResultHan
             return;
         }
 
-        if (SyncDeltaType.CREATE_OR_UPDATE == delta.getDeltaType()) {
-            if (matches.get(0).getAny() == null) {
-                switch (profile.getTask().getUnmatchingRule()) {
-                    case ASSIGN:
-                    case PROVISION:
-                        profile.getResults().addAll(
-                                provision(profile.getTask().getUnmatchingRule(), delta, anyTypeKind, provision));
-                        break;
-
-                    case IGNORE:
-                        profile.getResults().addAll(ignore(delta, null, provision, false));
-                        break;
-
-                    default:
-                    // do nothing
+        switch (delta.getDeltaType()) {
+            case CREATE:
+            case UPDATE:
+            case CREATE_OR_UPDATE:
+                if (matches.get(0).getAny() == null) {
+                    switch (profile.getTask().getUnmatchingRule()) {
+                        case ASSIGN:
+                        case PROVISION:
+                            profile.getResults().addAll(
+                                    provision(profile.getTask().getUnmatchingRule(), delta, anyTypeKind, provision));
+                            break;
+
+                        case IGNORE:
+                            profile.getResults().addAll(ignore(delta, null, provision, false));
+                            break;
+
+                        default:
+                        // do nothing
                     }
-            } else {
-                // update VirAttrCache
-                virSchemaDAO.find(profile.getTask().getResource().getKey(), matches.get(0).getAny().getType().getKey()).
-                        forEach(vs -> {
-                            Attribute attr = delta.getObject().getAttributeByName(vs.getExtAttrName());
-                            matches.forEach(match -> {
-                                VirAttrCacheKey cacheKey = new VirAttrCacheKey(
-                                        provision.getAnyType(), match.getAny().getKey(),
-                                        vs.getKey());
-                                if (attr == null) {
-                                    virAttrCache.expire(cacheKey);
-                                } else {
-                                    virAttrCache.put(cacheKey, new VirAttrCacheValue(attr.getValue()));
-                                }
+                } else {
+                    // update VirAttrCache
+                    virSchemaDAO.find(
+                            profile.getTask().getResource().getKey(),
+                            matches.get(0).getAny().getType().getKey()).
+                            forEach(vs -> {
+                                Attribute attr = delta.getObject().getAttributeByName(vs.getExtAttrName());
+                                matches.forEach(match -> {
+                                    VirAttrCacheKey cacheKey = new VirAttrCacheKey(
+                                            provision.getAnyType(), match.getAny().getKey(),
+                                            vs.getKey());
+                                    if (attr == null) {
+                                        virAttrCache.expire(cacheKey);
+                                    } else {
+                                        virAttrCache.put(cacheKey, new VirAttrCacheValue(attr.getValue()));
+                                    }
+                                });
                             });
-                        });
 
-                switch (profile.getTask().getMatchingRule()) {
-                    case UPDATE:
-                        profile.getResults().addAll(update(delta, matches, provision));
-                        break;
+                    switch (profile.getTask().getMatchingRule()) {
+                        case UPDATE:
+                            profile.getResults().addAll(update(delta, matches, provision));
+                            break;
 
-                    case DEPROVISION:
-                    case UNASSIGN:
-                        profile.getResults().addAll(
-                                deprovision(profile.getTask().getMatchingRule(), delta, matches, provision));
-                        break;
+                        case DEPROVISION:
+                        case UNASSIGN:
+                            profile.getResults().addAll(
+                                    deprovision(profile.getTask().getMatchingRule(), delta, matches, provision));
+                            break;
 
-                    case LINK:
-                        profile.getResults().addAll(link(delta, matches, provision, false));
-                        break;
+                        case LINK:
+                            profile.getResults().addAll(link(delta, matches, provision, false));
+                            break;
 
-                    case UNLINK:
-                        profile.getResults().addAll(link(delta, matches, provision, true));
-                        break;
+                        case UNLINK:
+                            profile.getResults().addAll(link(delta, matches, provision, true));
+                            break;
 
-                    case IGNORE:
-                        profile.getResults().addAll(ignore(delta, matches, provision, true));
-                        break;
+                        case IGNORE:
+                            profile.getResults().addAll(ignore(delta, matches, provision, true));
+                            break;
 
-                    default:
-                    // do nothing
+                        default:
+                        // do nothing
                     }
-            }
-        } else if (SyncDeltaType.DELETE == delta.getDeltaType()) {
-            profile.getResults().addAll(delete(delta, matches, provision));
+                }
+                break;
+
+            case DELETE:
+                profile.getResults().addAll(delete(delta, matches, provision));
+                break;
+
+            default:
         }
     }
 
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultRealmPullResultHandler.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultRealmPullResultHandler.java
index ed22cb265c..f7847e44ad 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultRealmPullResultHandler.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultRealmPullResultHandler.java
@@ -55,7 +55,6 @@ import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.apache.syncope.core.spring.security.DelegatedAdministrationException;
 import org.identityconnectors.framework.common.objects.Attribute;
 import org.identityconnectors.framework.common.objects.SyncDelta;
-import org.identityconnectors.framework.common.objects.SyncDeltaType;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -676,61 +675,69 @@ public class DefaultRealmPullResultHandler
         }
 
         try {
-            if (SyncDeltaType.CREATE_OR_UPDATE == finalDelta.getDeltaType()) {
-                if (realms.isEmpty()) {
-                    switch (profile.getTask().getUnmatchingRule()) {
-                        case ASSIGN:
-                            profile.getResults().addAll(assign(finalDelta, orgUnit));
-                            break;
-
-                        case PROVISION:
-                            profile.getResults().addAll(provision(finalDelta, orgUnit));
-                            break;
-
-                        case IGNORE:
-                            profile.getResults().add(ignore(finalDelta, false));
-                            break;
-
-                        default:
-                        // do nothing
+            switch (delta.getDeltaType()) {
+                case CREATE:
+                case UPDATE:
+                case CREATE_OR_UPDATE:
+                    if (realms.isEmpty()) {
+                        switch (profile.getTask().getUnmatchingRule()) {
+                            case ASSIGN:
+                                profile.getResults().addAll(assign(finalDelta, orgUnit));
+                                break;
+
+                            case PROVISION:
+                                profile.getResults().addAll(provision(finalDelta, orgUnit));
+                                break;
+
+                            case IGNORE:
+                                profile.getResults().add(ignore(finalDelta, false));
+                                break;
+
+                            default:
+                            // do nothing
+                        }
+                    } else {
+                        switch (profile.getTask().getMatchingRule()) {
+                            case UPDATE:
+                                profile.getResults().addAll(update(finalDelta, realms, false));
+                                break;
+
+                            case DEPROVISION:
+                                profile.getResults().addAll(deprovision(finalDelta, realms, false));
+                                break;
+
+                            case UNASSIGN:
+                                profile.getResults().addAll(deprovision(finalDelta, realms, true));
+                                break;
+
+                            case LINK:
+                                profile.getResults().addAll(link(finalDelta, realms, false));
+                                break;
+
+                            case UNLINK:
+                                profile.getResults().addAll(link(finalDelta, realms, true));
+                                break;
+
+                            case IGNORE:
+                                profile.getResults().add(ignore(finalDelta, true));
+                                break;
+
+                            default:
+                            // do nothing
+                        }
                     }
-                } else {
-                    switch (profile.getTask().getMatchingRule()) {
-                        case UPDATE:
-                            profile.getResults().addAll(update(finalDelta, realms, false));
-                            break;
-
-                        case DEPROVISION:
-                            profile.getResults().addAll(deprovision(finalDelta, realms, false));
-                            break;
-
-                        case UNASSIGN:
-                            profile.getResults().addAll(deprovision(finalDelta, realms, true));
-                            break;
-
-                        case LINK:
-                            profile.getResults().addAll(link(finalDelta, realms, false));
-                            break;
-
-                        case UNLINK:
-                            profile.getResults().addAll(link(finalDelta, realms, true));
-                            break;
-
-                        case IGNORE:
-                            profile.getResults().add(ignore(finalDelta, true));
-                            break;
-
-                        default:
-                        // do nothing
+                    break;
+
+                case DELETE:
+                    if (realms.isEmpty()) {
+                        finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, finalDelta);
+                        LOG.debug("No match found for deletion");
+                    } else {
+                        profile.getResults().addAll(delete(finalDelta, realms));
                     }
-                }
-            } else if (SyncDeltaType.DELETE == finalDelta.getDeltaType()) {
-                if (realms.isEmpty()) {
-                    finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, finalDelta);
-                    LOG.debug("No match found for deletion");
-                } else {
-                    profile.getResults().addAll(delete(finalDelta, realms));
-                }
+                    break;
+
+                default:
             }
         } catch (IllegalStateException | IllegalArgumentException e) {
             LOG.warn(e.getMessage());
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultUserPullResultHandler.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultUserPullResultHandler.java
index e1baf55511..9232e4b011 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultUserPullResultHandler.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultUserPullResultHandler.java
@@ -60,7 +60,6 @@ import org.apache.syncope.core.provisioning.api.pushpull.PullActions;
 import org.apache.syncope.core.provisioning.api.pushpull.UserPullResultHandler;
 import org.identityconnectors.framework.common.objects.AttributeUtil;
 import org.identityconnectors.framework.common.objects.SyncDelta;
-import org.identityconnectors.framework.common.objects.SyncDeltaType;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -158,62 +157,78 @@ public class DefaultUserPullResultHandler extends AbstractPullResultHandler impl
             if (found.isPresent()) {
                 LinkedAccount account = found.get();
 
-                if (SyncDeltaType.CREATE_OR_UPDATE == delta.getDeltaType()) {
-                    switch (profile.getTask().getMatchingRule()) {
-                        case UPDATE:
-                            update(delta, account, provision).ifPresent(profile.getResults()::add);
-                            break;
-
-                        case DEPROVISION:
-                        case UNASSIGN:
-                            deprovision(profile.getTask().getMatchingRule(), delta, account).
-                                    ifPresent(profile.getResults()::add);
-                            break;
-
-                        case LINK:
-                        case UNLINK:
-                            LOG.warn("{} not applicable to linked accounts, ignoring",
-                                    profile.getTask().getMatchingRule());
-                            break;
-
-                        case IGNORE:
-                            profile.getResults().add(ignore(delta, account, true));
-                            break;
-
-                        default:
-                        // do nothing
-                    }
-                } else if (SyncDeltaType.DELETE == delta.getDeltaType()) {
-                    delete(delta, account, provision).ifPresent(profile.getResults()::add);
+                switch (delta.getDeltaType()) {
+                    case CREATE:
+                    case UPDATE:
+                    case CREATE_OR_UPDATE:
+                        switch (profile.getTask().getMatchingRule()) {
+                            case UPDATE:
+                                update(delta, account, provision).ifPresent(profile.getResults()::add);
+                                break;
+
+                            case DEPROVISION:
+                            case UNASSIGN:
+                                deprovision(profile.getTask().getMatchingRule(), delta, account).
+                                        ifPresent(profile.getResults()::add);
+                                break;
+
+                            case LINK:
+                            case UNLINK:
+                                LOG.warn("{} not applicable to linked accounts, ignoring",
+                                        profile.getTask().getMatchingRule());
+                                break;
+
+                            case IGNORE:
+                                profile.getResults().add(ignore(delta, account, true));
+                                break;
+
+                            default:
+                            // do nothing
+                        }
+                        break;
+
+                    case DELETE:
+                        delete(delta, account, provision).ifPresent(profile.getResults()::add);
+                        break;
+
+                    default:
                 }
             } else {
-                if (SyncDeltaType.CREATE_OR_UPDATE == delta.getDeltaType()) {
-                    LinkedAccountTO accountTO = new LinkedAccountTO();
-                    accountTO.setConnObjectKeyValue(delta.getUid().getUidValue());
-                    accountTO.setResource(profile.getTask().getResource().getKey());
-
-                    switch (profile.getTask().getUnmatchingRule()) {
-                        case ASSIGN:
-                        case PROVISION:
-                            provision(profile.getTask().getUnmatchingRule(), delta, user, accountTO, provision).
-                                    ifPresent(profile.getResults()::add);
-                            break;
-
-                        case IGNORE:
-                            profile.getResults().add(ignore(delta, null, false));
-                            break;
-
-                        default:
-                        // do nothing
-                    }
-                } else if (SyncDeltaType.DELETE == delta.getDeltaType()) {
-                    end(AnyTypeKind.USER.name(),
-                            ResourceOperation.DELETE.name().toLowerCase(),
-                            AuditElements.Result.SUCCESS,
-                            null,
-                            null,
-                            delta);
-                    LOG.debug("No match found for deletion");
+                switch (delta.getDeltaType()) {
+                    case CREATE:
+                    case UPDATE:
+                    case CREATE_OR_UPDATE:
+                        LinkedAccountTO accountTO = new LinkedAccountTO();
+                        accountTO.setConnObjectKeyValue(delta.getUid().getUidValue());
+                        accountTO.setResource(profile.getTask().getResource().getKey());
+
+                        switch (profile.getTask().getUnmatchingRule()) {
+                            case ASSIGN:
+                            case PROVISION:
+                                provision(profile.getTask().getUnmatchingRule(), delta, user, accountTO, provision).
+                                        ifPresent(profile.getResults()::add);
+                                break;
+
+                            case IGNORE:
+                                profile.getResults().add(ignore(delta, null, false));
+                                break;
+
+                            default:
+                            // do nothing
+                        }
+                        break;
+
+                    case DELETE:
+                        end(AnyTypeKind.USER.name(),
+                                ResourceOperation.DELETE.name().toLowerCase(),
+                                AuditElements.Result.SUCCESS,
+                                null,
+                                null,
+                                delta);
+                        LOG.debug("No match found for deletion");
+                        break;
+
+                    default:
                 }
             }
         }