Search in sources :

Example 1 with SyncopePushResultHandler

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

the class PushJobDelegate method doExecuteProvisioning.

@Override
protected String doExecuteProvisioning(final PushTask pushTask, final Connector connector, final boolean dryRun) throws JobExecutionException {
    LOG.debug("Executing push on {}", pushTask.getResource());
    List<PushActions> actions = new ArrayList<>();
    pushTask.getActions().forEach(impl -> {
        try {
            actions.add(ImplementationManager.build(impl));
        } catch (Exception e) {
            LOG.warn("While building {}", impl, e);
        }
    });
    profile = new ProvisioningProfile<>(connector, pushTask);
    profile.getActions().addAll(actions);
    profile.setDryRun(dryRun);
    profile.setResAct(null);
    if (!profile.isDryRun()) {
        for (PushActions action : actions) {
            action.beforeAll(profile);
        }
    }
    status.set("Initialization completed");
    // First realms...
    if (pushTask.getResource().getOrgUnit() != null) {
        status.set("Pushing realms");
        rhandler = buildRealmHandler();
        for (Realm realm : realmDAO.findDescendants(profile.getTask().getSourceRealm())) {
            // Never push the root realm
            if (realm.getParent() != null) {
                try {
                    rhandler.handle(realm.getKey());
                    reportHandled(SyncopeConstants.REALM_ANYTYPE, realm.getName());
                } catch (Exception e) {
                    LOG.warn("Failure pushing '{}' on '{}'", realm, pushTask.getResource(), e);
                    throw new JobExecutionException("While pushing " + realm + " on " + pushTask.getResource(), e);
                }
            }
        }
    }
    // ...then provisions for any types
    ahandler = buildAnyObjectHandler();
    uhandler = buildUserHandler();
    ghandler = buildGroupHandler();
    for (Provision provision : pushTask.getResource().getProvisions()) {
        if (provision.getMapping() != null) {
            status.set("Pushing " + provision.getAnyType().getKey());
            AnyDAO<?> anyDAO = getAnyDAO(provision.getAnyType().getKind());
            SyncopePushResultHandler handler;
            switch(provision.getAnyType().getKind()) {
                case USER:
                    handler = uhandler;
                    break;
                case GROUP:
                    handler = ghandler;
                    break;
                case ANY_OBJECT:
                default:
                    handler = ahandler;
            }
            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(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());
                doHandle(anys, handler, pushTask.getResource());
            }
        }
    }
    if (!profile.isDryRun() && !interrupt) {
        for (PushActions action : actions) {
            action.afterAll(profile);
        }
    }
    if (interrupt) {
        interrupted = true;
    }
    status.set("Push done");
    String result = createReport(profile.getResults(), pushTask.getResource(), dryRun);
    LOG.debug("Push result: {}", result);
    return result;
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ArrayList(java.util.ArrayList) JobExecutionException(org.quartz.JobExecutionException) SyncopePushResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePushResultHandler) JobExecutionException(org.quartz.JobExecutionException) PushActions(org.apache.syncope.core.provisioning.api.pushpull.PushActions) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Aggregations

ArrayList (java.util.ArrayList)1 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)1 Realm (org.apache.syncope.core.persistence.api.entity.Realm)1 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)1 PushActions (org.apache.syncope.core.provisioning.api.pushpull.PushActions)1 SyncopePushResultHandler (org.apache.syncope.core.provisioning.api.pushpull.SyncopePushResultHandler)1 JobExecutionException (org.quartz.JobExecutionException)1