Example usage for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage.

Prototype

public static String getRootCauseMessage(final Throwable th) 

Source Link

Document

Gets a short message summarising the root cause exception.

Usage

From source file:org.apache.syncope.core.provisioning.java.pushpull.DefaultRealmPullResultHandler.java

private List<ProvisioningReport> update(final SyncDelta delta, final List<String> keys)
        throws JobExecutionException {

    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(MatchingRule.toEventName(MatchingRule.UPDATE), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }//w  w w. j av  a 2s  . c  om

    LOG.debug("About to update {}", keys);

    List<ProvisioningReport> results = new ArrayList<>();

    for (String key : keys) {
        LOG.debug("About to update {}", key);

        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.UPDATE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);

        Realm realm = realmDAO.find(key);
        RealmTO before = binder.getRealmTO(realm, true);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Realm '%s' not found", key));
        } else {
            result.setName(before.getFullPath());
        }

        if (!profile.isDryRun()) {
            Result resultStatus;
            Object output;

            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    for (PullActions action : profile.getActions()) {
                        action.beforeUpdate(profile, delta, before, null);
                    }

                    PropagationByResource propByRes = binder.update(realm, before);
                    realm = realmDAO.save(realm);
                    RealmTO updated = binder.getRealmTO(realm, true);

                    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
                    taskExecutor.execute(tasks, false);

                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, updated, result);
                    }

                    output = updated;
                    resultStatus = Result.SUCCESS;
                    result.setName(updated.getFullPath());

                    LOG.debug("{} successfully updated", updated);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);

                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta);
        }
        results.add(result);
    }

    return results;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.DefaultRealmPullResultHandler.java

private List<ProvisioningReport> deprovision(final SyncDelta delta, final List<String> keys,
        final boolean unlink) throws JobExecutionException {

    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(/*from  w  w  w  .java2s.c o  m*/
                unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN)
                        : MatchingRule.toEventName(MatchingRule.DEPROVISION),
                Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }

    LOG.debug("About to deprovision {}", keys);

    final List<ProvisioningReport> results = new ArrayList<>();

    for (String key : keys) {
        LOG.debug("About to unassign resource {}", key);

        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.DELETE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);

        Realm realm = realmDAO.find(key);
        RealmTO before = binder.getRealmTO(realm, true);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Realm '%s' not found", key));
        } else {
            result.setName(before.getFullPath());
        }

        if (!profile.isDryRun()) {
            Object output;
            Result resultStatus;

            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnassign(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeDeprovision(profile, delta, before);
                        }
                    }

                    PropagationByResource propByRes = new PropagationByResource();
                    propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
                    taskExecutor.execute(propagationManager.createTasks(realm, propByRes, null), false);

                    if (unlink) {
                        realm.getResources().remove(profile.getTask().getResource());
                        output = binder.getRealmTO(realmDAO.save(realm), true);
                    } else {
                        output = binder.getRealmTO(realm, true);
                    }

                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, RealmTO.class.cast(output), result);
                    }

                    resultStatus = Result.SUCCESS;

                    LOG.debug("{} successfully updated", realm);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);

                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(
                    unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN)
                            : MatchingRule.toEventName(MatchingRule.DEPROVISION),
                    resultStatus, before, output, delta);
        }
        results.add(result);
    }

    return results;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.DefaultRealmPullResultHandler.java

private List<ProvisioningReport> link(final SyncDelta delta, final List<String> keys, final boolean unlink)
        throws JobExecutionException {

    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK)
                : MatchingRule.toEventName(MatchingRule.LINK), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }//from  w w  w.j  av a2  s .  c o m

    LOG.debug("About to link {}", keys);

    final List<ProvisioningReport> results = new ArrayList<>();

    for (String key : keys) {
        LOG.debug("About to unassign resource {}", key);

        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);

        Realm realm = realmDAO.find(key);
        RealmTO before = binder.getRealmTO(realm, true);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Realm '%s' not found", key));
        } else {
            result.setName(before.getFullPath());
        }

        Object output;
        Result resultStatus;
        if (!profile.isDryRun()) {
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnlink(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeLink(profile, delta, before);
                        }
                    }

                    if (unlink) {
                        realm.getResources().remove(profile.getTask().getResource());
                    } else {
                        realm.add(profile.getTask().getResource());
                    }
                    output = update(delta, Collections.singletonList(key));

                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, RealmTO.class.cast(output), result);
                    }

                    resultStatus = Result.SUCCESS;

                    LOG.debug("{} successfully updated", realm);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);

                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK)
                    : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta);
        }
        results.add(result);
    }

    return results;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.DefaultRealmPullResultHandler.java

private List<ProvisioningReport> delete(final SyncDelta delta, final List<String> keys)
        throws JobExecutionException {

    if (!profile.getTask().isPerformDelete()) {
        LOG.debug("PullTask not configured for delete");
        finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }/*from   ww  w.j  ava 2s .c  o  m*/

    LOG.debug("About to delete {}", keys);

    List<ProvisioningReport> results = new ArrayList<>();

    for (String key : keys) {
        Object output;
        Result resultStatus = Result.FAILURE;

        ProvisioningReport result = new ProvisioningReport();

        try {
            result.setKey(key);
            result.setOperation(ResourceOperation.DELETE);
            result.setAnyType(REALM_TYPE);
            result.setStatus(ProvisioningReport.Status.SUCCESS);

            Realm realm = realmDAO.find(key);
            RealmTO before = binder.getRealmTO(realm, true);
            if (before == null) {
                result.setStatus(ProvisioningReport.Status.FAILURE);
                result.setMessage(String.format("Realm '%s' not found", key));
            } else {
                result.setName(before.getFullPath());
            }

            if (!profile.isDryRun()) {
                for (PullActions action : profile.getActions()) {
                    action.beforeDelete(profile, delta, before);
                }

                try {
                    if (!realmDAO.findChildren(realm).isEmpty()) {
                        throw SyncopeClientException.build(ClientExceptionType.HasChildren);
                    }

                    Set<String> adminRealms = Collections.singleton(realm.getFullPath());
                    AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
                    keyCond.setSchema("key");
                    SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
                    int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
                    int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
                    int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);

                    if (users + groups + anyObjects > 0) {
                        SyncopeClientException containedAnys = SyncopeClientException
                                .build(ClientExceptionType.AssociatedAnys);
                        containedAnys.getElements().add(users + " user(s)");
                        containedAnys.getElements().add(groups + " group(s)");
                        containedAnys.getElements().add(anyObjects + " anyObject(s)");
                        throw containedAnys;
                    }

                    PropagationByResource propByRes = new PropagationByResource();
                    for (String resource : realm.getResourceKeys()) {
                        propByRes.add(ResourceOperation.DELETE, resource);
                    }
                    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
                    taskExecutor.execute(tasks, false);

                    realmDAO.delete(realm);

                    output = null;
                    resultStatus = Result.SUCCESS;

                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, before, result);
                    }
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);

                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not delete {}", realm, e);
                    output = e;
                }

                finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, delta);
            }

            results.add(result);
        } catch (DelegatedAdministrationException e) {
            LOG.error("Not allowed to read Realm {}", key, e);
        } catch (Exception e) {
            LOG.error("Could not delete Realm {}", key, e);
        }
    }

    return results;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.DefaultRealmPushResultHandler.java

private void doHandle(final Realm realm) throws JobExecutionException {
    ProvisioningReport result = new ProvisioningReport();
    profile.getResults().add(result);/*from w w  w  .ja va 2s.  co m*/

    result.setKey(realm.getKey());
    result.setAnyType(REALM_TYPE);
    result.setName(realm.getFullPath());

    LOG.debug("Propagating Realm with key {} towards {}", realm.getKey(), profile.getTask().getResource());

    Object output = null;
    Result resultStatus = null;

    // Try to read remote object BEFORE any actual operation
    OrgUnit orgUnit = profile.getTask().getResource().getOrgUnit();
    Optional<? extends OrgUnitItem> connObjectKey = orgUnit.getConnObjectKeyItem();
    String connObjecKeyValue = mappingManager.getConnObjectKeyValue(realm, orgUnit);

    ConnectorObject beforeObj = getRemoteObject(orgUnit.getObjectClass(), connObjectKey.get().getExtAttrName(),
            connObjecKeyValue, orgUnit.getItems().iterator());

    if (profile.isDryRun()) {
        if (beforeObj == null) {
            result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
        } else {
            result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
        }
        result.setStatus(ProvisioningReport.Status.SUCCESS);
    } else {
        String operation = beforeObj == null ? UnmatchingRule.toEventName(profile.getTask().getUnmatchingRule())
                : MatchingRule.toEventName(profile.getTask().getMatchingRule());

        boolean notificationsAvailable = notificationManager.notificationsAvailable(
                AuditElements.EventCategoryType.PUSH, REALM_TYPE.toLowerCase(),
                profile.getTask().getResource().getKey(), operation);
        boolean auditRequested = auditManager.auditRequested(AuditElements.EventCategoryType.PUSH,
                REALM_TYPE.toLowerCase(), profile.getTask().getResource().getKey(), operation);
        try {
            if (beforeObj == null) {
                result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));

                switch (profile.getTask().getUnmatchingRule()) {
                case ASSIGN:
                    for (PushActions action : profile.getActions()) {
                        action.beforeAssign(profile, realm);
                    }

                    if (!profile.getTask().isPerformCreate()) {
                        LOG.debug("PushTask not configured for create");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        assign(realm, result);
                    }

                    break;

                case PROVISION:
                    for (PushActions action : profile.getActions()) {
                        action.beforeProvision(profile, realm);
                    }

                    if (!profile.getTask().isPerformCreate()) {
                        LOG.debug("PushTask not configured for create");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        provision(realm, result);
                    }

                    break;

                case UNLINK:
                    for (PushActions action : profile.getActions()) {
                        action.beforeUnlink(profile, realm);
                    }

                    if (!profile.getTask().isPerformUpdate()) {
                        LOG.debug("PushTask not configured for update");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        link(realm, true, result);
                    }

                    break;

                case IGNORE:
                    LOG.debug("Ignored any: {}", realm);
                    result.setStatus(ProvisioningReport.Status.IGNORE);
                    break;

                default:
                    // do nothing
                }
            } else {
                result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));

                switch (profile.getTask().getMatchingRule()) {
                case UPDATE:
                    for (PushActions action : profile.getActions()) {
                        action.beforeUpdate(profile, realm);
                    }
                    if (!profile.getTask().isPerformUpdate()) {
                        LOG.debug("PushTask not configured for update");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        update(binder.getRealmTO(realm, true), result);
                    }

                    break;

                case DEPROVISION:
                    for (PushActions action : profile.getActions()) {
                        action.beforeDeprovision(profile, realm);
                    }

                    if (!profile.getTask().isPerformDelete()) {
                        LOG.debug("PushTask not configured for delete");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        deprovision(realm, result);
                    }

                    break;

                case UNASSIGN:
                    for (PushActions action : profile.getActions()) {
                        action.beforeUnassign(profile, realm);
                    }

                    if (!profile.getTask().isPerformDelete()) {
                        LOG.debug("PushTask not configured for delete");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        unassign(realm, result);
                    }

                    break;

                case LINK:
                    for (PushActions action : profile.getActions()) {
                        action.beforeLink(profile, realm);
                    }

                    if (!profile.getTask().isPerformUpdate()) {
                        LOG.debug("PushTask not configured for update");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        link(realm, false, result);
                    }

                    break;

                case UNLINK:
                    for (PushActions action : profile.getActions()) {
                        action.beforeUnlink(profile, realm);
                    }

                    if (!profile.getTask().isPerformUpdate()) {
                        LOG.debug("PushTask not configured for update");
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                    } else {
                        link(realm, true, result);
                    }

                    break;

                case IGNORE:
                    LOG.debug("Ignored any: {}", realm);
                    result.setStatus(ProvisioningReport.Status.IGNORE);
                    break;

                default:
                    // do nothing
                }
            }

            for (PushActions action : profile.getActions()) {
                action.after(profile, realm, result);
            }

            if (result.getStatus() == null) {
                result.setStatus(ProvisioningReport.Status.SUCCESS);
            }
            resultStatus = AuditElements.Result.SUCCESS;
            output = getRemoteObject(orgUnit.getObjectClass(), connObjectKey.get().getExtAttrName(),
                    connObjecKeyValue, orgUnit.getItems().iterator());
        } catch (IgnoreProvisionException e) {
            throw e;
        } catch (Exception e) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(ExceptionUtils.getRootCauseMessage(e));
            resultStatus = AuditElements.Result.FAILURE;
            output = e;

            LOG.warn("Error pushing {} towards {}", realm, profile.getTask().getResource(), e);

            for (PushActions action : profile.getActions()) {
                action.onError(profile, realm, result, e);
            }

            throw new JobExecutionException(e);
        } finally {
            if (notificationsAvailable || auditRequested) {
                Map<String, Object> jobMap = new HashMap<>();
                jobMap.put(AfterHandlingEvent.JOBMAP_KEY,
                        new AfterHandlingEvent(AuditElements.EventCategoryType.PUSH, REALM_TYPE.toLowerCase(),
                                profile.getTask().getResource().getKey(), operation, resultStatus, beforeObj,
                                output, realm));
                AfterHandlingJob.schedule(scheduler, jobMap);
            }
        }
    }
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.RealmPullResultHandlerImpl.java

private void create(final RealmTO realmTO, final SyncDelta delta, final String operation,
        final ProvisioningReport result) throws JobExecutionException {

    Object output;//from  w w w.java  2s.c om
    Result resultStatus;

    try {
        Realm realm = realmDAO
                .save(binder.create(profile.getTask().getDestinatioRealm().getFullPath(), realmTO));

        PropagationByResource propByRes = new PropagationByResource();
        for (String resource : realm.getResourceKeys()) {
            propByRes.add(ResourceOperation.CREATE, resource);
        }
        List<PropagationTask> tasks = propagationManager.createTasks(realm, propByRes, null);
        PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);

        RealmTO actual = binder.getRealmTO(realm);

        result.setKey(actual.getKey());
        result.setName(profile.getTask().getDestinatioRealm().getFullPath() + "/" + actual.getName());

        output = actual;
        resultStatus = Result.SUCCESS;

        for (PullActions action : profile.getActions()) {
            action.after(profile, delta, actual, result);
        }

        LOG.debug("Realm {} successfully created", actual.getKey());
    } catch (PropagationException e) {
        // A propagation failure doesn't imply a pull failure.
        // The propagation exception status will be reported into the propagation task execution.
        LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
    } catch (Exception e) {
        throwIgnoreProvisionException(delta, e);

        result.setStatus(ProvisioningReport.Status.FAILURE);
        result.setMessage(ExceptionUtils.getRootCauseMessage(e));
        LOG.error("Could not create Realm {} ", delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
    }

    finalize(operation, resultStatus, null, output, delta);
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.RealmPullResultHandlerImpl.java

private ProvisioningReport update(final SyncDelta delta, final Realm realm, final String name)
        throws JobExecutionException {

    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        return null;
    }//from  w  ww  . jav a  2  s  .c om

    LOG.debug("About to update {}", realm);

    RealmTO before = binder.getRealmTO(realm);

    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.UPDATE);
    result.setAnyType(REALM_TYPE);
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setKey(realm.getKey());

    Result resultStatus;
    Object output;
    if (!profile.isDryRun()) {
        try {
            before.setName(name);

            PropagationByResource propByRes = binder.update(realm, before);
            Realm updated = realmDAO.save(realm);

            List<PropagationTask> tasks = propagationManager.createTasks(updated, propByRes, null);
            PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);

            output = updated;
            resultStatus = Result.SUCCESS;
            result.setName(updated.getFullPath());

            LOG.debug("{} successfully updated", updated);
        } catch (PropagationException e) {
            // A propagation failure doesn't imply a pull failure.
            // The propagation exception status will be reported into the propagation task execution.
            LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
            output = e;
            resultStatus = Result.FAILURE;
        } catch (Exception e) {
            throwIgnoreProvisionException(delta, e);

            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(ExceptionUtils.getRootCauseMessage(e));
            LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
            output = e;
            resultStatus = Result.FAILURE;
        }
        finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta);
    }

    return result;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.RealmPullResultHandlerImpl.java

private ProvisioningReport deprovision(final SyncDelta delta, final Realm realm, final boolean unlink)
        throws JobExecutionException {

    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        return null;
    }/*from  w ww .j a  v a2 s  .c om*/

    LOG.debug("About to deprovision {}", realm);

    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.DELETE);
    result.setAnyType(REALM_TYPE);
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setKey(realm.getKey());

    RealmTO before = binder.getRealmTO(realm);

    Object output;
    Result resultStatus;
    if (!profile.isDryRun()) {
        result.setName(realm.getFullPath());

        try {
            if (unlink) {
                for (PullActions action : profile.getActions()) {
                    action.beforeUnassign(profile, delta, before);
                }
            } else {
                for (PullActions action : profile.getActions()) {
                    action.beforeDeprovision(profile, delta, before);
                }
            }

            PropagationByResource propByRes = new PropagationByResource();
            propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
            taskExecutor.execute(propagationManager.createTasks(realm, propByRes, null));

            if (unlink) {
                realm.getResources().remove(profile.getTask().getResource());
                output = binder.getRealmTO(realmDAO.save(realm));
            } else {
                output = binder.getRealmTO(realm);
            }

            for (PullActions action : profile.getActions()) {
                action.after(profile, delta, RealmTO.class.cast(output), result);
            }

            resultStatus = Result.SUCCESS;

            LOG.debug("{} successfully updated", realm);
        } catch (PropagationException e) {
            // A propagation failure doesn't imply a pull failure.
            // The propagation exception status will be reported into the propagation task execution.
            LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
            output = e;
            resultStatus = Result.FAILURE;
        } catch (Exception e) {
            throwIgnoreProvisionException(delta, e);

            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(ExceptionUtils.getRootCauseMessage(e));
            LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
            output = e;
            resultStatus = Result.FAILURE;
        }

        finalize(
                unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN)
                        : MatchingRule.toEventName(MatchingRule.DEPROVISION),
                resultStatus, before, output, delta);
    }

    return result;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.RealmPullResultHandlerImpl.java

private ProvisioningReport link(final SyncDelta delta, final Realm realm, final boolean unlink)
        throws JobExecutionException {

    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        return null;
    }//  www .  j  a v a  2s .c om

    LOG.debug("About to link {}", realm);

    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.NONE);
    result.setAnyType(REALM_TYPE);
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setKey(realm.getKey());

    RealmTO before = binder.getRealmTO(realm);

    Object output;
    Result resultStatus;
    if (!profile.isDryRun()) {
        result.setName(realm.getFullPath());

        try {
            if (unlink) {
                for (PullActions action : profile.getActions()) {
                    action.beforeUnlink(profile, delta, before);
                }
            } else {
                for (PullActions action : profile.getActions()) {
                    action.beforeLink(profile, delta, before);
                }
            }

            if (unlink) {
                realm.getResources().remove(profile.getTask().getResource());
            } else {
                realm.add(profile.getTask().getResource());
            }
            output = update(delta, realm, realm.getName());

            for (PullActions action : profile.getActions()) {
                action.after(profile, delta, RealmTO.class.cast(output), result);
            }

            resultStatus = Result.SUCCESS;

            LOG.debug("{} successfully updated", realm);
        } catch (PropagationException e) {
            // A propagation failure doesn't imply a pull failure.
            // The propagation exception status will be reported into the propagation task execution.
            LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
            output = e;
            resultStatus = Result.FAILURE;
        } catch (Exception e) {
            throwIgnoreProvisionException(delta, e);

            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(ExceptionUtils.getRootCauseMessage(e));
            LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
            output = e;
            resultStatus = Result.FAILURE;
        }

        finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK)
                : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta);
    }

    return result;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.RealmPullResultHandlerImpl.java

private ProvisioningReport delete(final SyncDelta delta, final Realm realm) throws JobExecutionException {

    if (!profile.getTask().isPerformDelete()) {
        LOG.debug("PullTask not configured for delete");
        return null;
    }//from  w w  w . j a  v  a 2  s.c om

    LOG.debug("About to delete {}", realm);

    SyncDelta workingDelta = delta;
    Object output;
    Result resultStatus = Result.FAILURE;

    ProvisioningReport result = new ProvisioningReport();

    try {
        RealmTO before = binder.getRealmTO(realm);

        result.setKey(realm.getKey());
        result.setName(realm.getFullPath());
        result.setOperation(ResourceOperation.DELETE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);

        if (!profile.isDryRun()) {
            for (PullActions action : profile.getActions()) {
                workingDelta = action.beforeDelete(profile, workingDelta, before);
            }

            try {
                if (!realmDAO.findChildren(realm).isEmpty()) {
                    throw SyncopeClientException.build(ClientExceptionType.HasChildren);
                }

                Set<String> adminRealms = Collections.singleton(realm.getFullPath());
                AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
                keyCond.setSchema("key");
                SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
                int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
                int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
                int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);

                if (users + groups + anyObjects > 0) {
                    SyncopeClientException containedAnys = SyncopeClientException
                            .build(ClientExceptionType.AssociatedAnys);
                    containedAnys.getElements().add(users + " user(s)");
                    containedAnys.getElements().add(groups + " group(s)");
                    containedAnys.getElements().add(anyObjects + " anyObject(s)");
                    throw containedAnys;
                }

                PropagationByResource propByRes = new PropagationByResource();
                for (String resource : realm.getResourceKeys()) {
                    propByRes.add(ResourceOperation.DELETE, resource);
                }
                List<PropagationTask> tasks = propagationManager.createTasks(realm, propByRes, null);
                PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);

                realmDAO.delete(realm);

                output = null;
                resultStatus = Result.SUCCESS;

                for (PullActions action : profile.getActions()) {
                    action.after(profile, workingDelta, before, result);
                }
            } catch (Exception e) {
                throwIgnoreProvisionException(delta, e);

                result.setStatus(ProvisioningReport.Status.FAILURE);
                result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                LOG.error("Could not delete {}", realm, e);
                output = e;
            }

            finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, workingDelta);
        }
    } catch (Exception e) {
        LOG.error("Could not delete {}", realm, e);
    }

    return result;
}