Search in sources :

Example 1 with ReconFilterBuilder

use of org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder in project syncope by apache.

the class PullJobDelegate method doExecuteProvisioning.

@Override
protected String doExecuteProvisioning(final PullTask pullTask, final Connector connector, final boolean dryRun) throws JobExecutionException {
    LOG.debug("Executing pull on {}", pullTask.getResource());
    List<PullActions> actions = new ArrayList<>();
    pullTask.getActions().forEach(impl -> {
        try {
            actions.add(ImplementationManager.build(impl));
        } catch (Exception e) {
            LOG.warn("While building {}", impl, e);
        }
    });
    profile = new ProvisioningProfile<>(connector, pullTask);
    profile.getActions().addAll(actions);
    profile.setDryRun(dryRun);
    profile.setResAct(pullTask.getResource().getPullPolicy() == null ? ConflictResolutionAction.IGNORE : pullTask.getResource().getPullPolicy().getConflictResolutionAction());
    latestSyncTokens.clear();
    if (!profile.isDryRun()) {
        for (PullActions action : actions) {
            action.beforeAll(profile);
        }
    }
    status.set("Initialization completed");
    // First realms...
    if (pullTask.getResource().getOrgUnit() != null) {
        status.set("Pulling " + pullTask.getResource().getOrgUnit().getObjectClass().getObjectClassValue());
        OrgUnit orgUnit = pullTask.getResource().getOrgUnit();
        OperationOptions options = MappingUtils.buildOperationOptions(MappingUtils.getPullItems(orgUnit.getItems()).iterator());
        rhandler = buildRealmHandler();
        try {
            switch(pullTask.getPullMode()) {
                case INCREMENTAL:
                    if (!dryRun) {
                        latestSyncTokens.put(orgUnit.getObjectClass(), orgUnit.getSyncToken());
                    }
                    connector.sync(orgUnit.getObjectClass(), orgUnit.getSyncToken(), rhandler, options);
                    if (!dryRun) {
                        orgUnit.setSyncToken(latestSyncTokens.get(orgUnit.getObjectClass()));
                        resourceDAO.save(orgUnit.getResource());
                    }
                    break;
                case FILTERED_RECONCILIATION:
                    ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
                    connector.filteredReconciliation(orgUnit.getObjectClass(), filterBuilder, rhandler, options);
                    break;
                case FULL_RECONCILIATION:
                default:
                    connector.fullReconciliation(orgUnit.getObjectClass(), rhandler, options);
                    break;
            }
        } catch (Throwable t) {
            throw new JobExecutionException("While pulling from connector", t);
        }
    }
    // ...then provisions for any types
    ahandler = buildAnyObjectHandler();
    uhandler = buildUserHandler();
    ghandler = buildGroupHandler();
    for (Provision provision : pullTask.getResource().getProvisions()) {
        if (provision.getMapping() != null) {
            status.set("Pulling " + provision.getObjectClass().getObjectClassValue());
            SyncopePullResultHandler handler;
            switch(provision.getAnyType().getKind()) {
                case USER:
                    handler = uhandler;
                    break;
                case GROUP:
                    handler = ghandler;
                    break;
                case ANY_OBJECT:
                default:
                    handler = ahandler;
            }
            try {
                Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
                Iterator<MappingItem> mapItems = new IteratorChain<>(provision.getMapping().getItems().iterator(), linkingMappingItems.iterator());
                OperationOptions options = MappingUtils.buildOperationOptions(mapItems);
                switch(pullTask.getPullMode()) {
                    case INCREMENTAL:
                        if (!dryRun) {
                            latestSyncTokens.put(provision.getObjectClass(), provision.getSyncToken());
                        }
                        connector.sync(provision.getObjectClass(), provision.getSyncToken(), handler, options);
                        if (!dryRun) {
                            provision.setSyncToken(latestSyncTokens.get(provision.getObjectClass()));
                            resourceDAO.save(provision.getResource());
                        }
                        break;
                    case FILTERED_RECONCILIATION:
                        ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
                        connector.filteredReconciliation(provision.getObjectClass(), filterBuilder, handler, options);
                        break;
                    case FULL_RECONCILIATION:
                    default:
                        connector.fullReconciliation(provision.getObjectClass(), handler, options);
                        break;
                }
            } catch (Throwable t) {
                throw new JobExecutionException("While pulling from connector", t);
            }
        }
    }
    try {
        setGroupOwners(ghandler);
    } catch (Exception e) {
        LOG.error("While setting group owners", e);
    }
    if (!profile.isDryRun()) {
        for (PullActions action : actions) {
            action.afterAll(profile);
        }
    }
    status.set("Pull done");
    String result = createReport(profile.getResults(), pullTask.getResource(), dryRun);
    LOG.debug("Pull result: {}", result);
    return result;
}
Also used : OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ReconFilterBuilder(org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder) ProvisioningProfile(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) SyncopePullExecutor(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullExecutor) UserPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.UserPullResultHandler) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) GroupPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.GroupPullResultHandler) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Map(java.util.Map) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) SyncopePullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) Iterator(java.util.Iterator) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) ConflictResolutionAction(org.apache.syncope.common.lib.types.ConflictResolutionAction) Set(java.util.Set) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Name(org.identityconnectors.framework.common.objects.Name) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) JobExecutionException(org.quartz.JobExecutionException) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) Connector(org.apache.syncope.core.provisioning.api.Connector) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AnyObjectPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.AnyObjectPullResultHandler) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.RealmPullResultHandler) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) SyncopePullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) JobExecutionException(org.quartz.JobExecutionException) ReconFilterBuilder(org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 IteratorChain (org.apache.syncope.common.lib.collections.IteratorChain)1 ConflictResolutionAction (org.apache.syncope.common.lib.types.ConflictResolutionAction)1 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)1 VirSchemaDAO (org.apache.syncope.core.persistence.api.dao.VirSchemaDAO)1 Group (org.apache.syncope.core.persistence.api.entity.group.Group)1 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)1 OrgUnit (org.apache.syncope.core.persistence.api.entity.resource.OrgUnit)1 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)1