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:25 UTC

[syncope] branch 2_1_X 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 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new 8d43a48c8e Support for SyncDeltaType.CREATE and SyncDeltaType.UPDATE
8d43a48c8e is described below

commit 8d43a48c8e644726632ab16cd4b438da47979ebe
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Thu Sep 8 13:13:16 2022 +0200

    Support for SyncDeltaType.CREATE and SyncDeltaType.UPDATE
---
 .../java/pushpull/AbstractPullResultHandler.java   | 113 +++++++++---------
 .../pushpull/DefaultRealmPullResultHandler.java    | 115 ++++++++++---------
 .../pushpull/DefaultUserPullResultHandler.java     | 127 ++++++++++++---------
 3 files changed, 192 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 ab1e665950..2188301bb8 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
@@ -63,7 +63,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;
@@ -771,67 +770,75 @@ 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, 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, provision));
+                            break;
+
+                        case IGNORE:
+                            profile.getResults().addAll(ignore(delta, null, provision, false));
+                            break;
+
+                        default:
+                        // do nothing
                     }
-            } else {
-                // update VirAttrCache
-                virSchemaDAO.findByProvision(provision).forEach(schema -> {
-                    Attribute attr = delta.getObject().getAttributeByName(schema.getExtAttrName());
-                    matches.forEach(match -> {
-                        VirAttrCacheKey cacheKey = new VirAttrCacheKey(
-                                provision.getAnyType().getKey(), match.getAny().getKey(),
-                                schema.getKey());
-                        if (attr == null) {
-                            virAttrCache.expire(cacheKey);
-                        } else {
-                            virAttrCache.put(cacheKey, new VirAttrCacheValue(attr.getValue()));
-                        }
+                } else {
+                    // update VirAttrCache
+                    virSchemaDAO.findByProvision(provision).forEach(schema -> {
+                        Attribute attr = delta.getObject().getAttributeByName(schema.getExtAttrName());
+                        matches.forEach(match -> {
+                            VirAttrCacheKey cacheKey = new VirAttrCacheKey(
+                                    provision.getAnyType().getKey(), match.getAny().getKey(),
+                                    schema.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 a274daa145..95c59daf0f 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
@@ -53,7 +53,6 @@ import org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils;
 import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.apache.syncope.core.spring.security.DelegatedAdministrationException;
 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;
@@ -662,61 +661,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 d64c4a3620..eed81e015f 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
@@ -53,7 +53,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;
 import java.util.Collections;
@@ -148,63 +147,79 @@ 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(provision.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,
-                            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(provision.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,
+                                ResourceOperation.DELETE.name().toLowerCase(),
+                                AuditElements.Result.SUCCESS,
+                                null,
+                                null,
+                                delta);
+                        LOG.debug("No match found for deletion");
+                        break;
+
+                    default:
                 }
             }
         }