List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCauseMessage
public static String getRootCauseMessage(final Throwable th)
From source file:org.apache.metron.stellar.zeppelin.StellarInterpreter.java
/** * Generates an error message that is shown to the user. * * @param e An optional exception that occurred. * @param input The user input that led to the error condition. * @return An error message for the user. *//*w w w . j a v a 2s .co m*/ private String getErrorMessage(Optional<Throwable> e, String input) { String message; if (e.isPresent()) { // base the error message on the exception String error = ExceptionUtils.getRootCauseMessage(e.get()); String trace = ExceptionUtils.getStackTrace(e.get()); message = error + System.lineSeparator() + trace; } else { // no exception provided; create generic error message message = "Invalid expression: " + input; } return message; }
From source file:org.apache.syncope.core.misc.search.SearchCondConverter.java
/** * Parses a FIQL expression into Syncope's <tt>SearchCond</tt>, using CXF's <tt>FiqlParser</tt>. * * @param fiqlExpression FIQL string/*from ww w .j a va 2s .c o m*/ * @return {@link SearchCond} instance for given FIQL expression * @see FiqlParser */ public static SearchCond convert(final String fiqlExpression) { FiqlParser<SearchBean> fiqlParser = new FiqlParser<>(SearchBean.class, AbstractFiqlSearchConditionBuilder.CONTEXTUAL_PROPERTIES); try { SearchCondVisitor searchCondVisitor = new SearchCondVisitor(); searchCondVisitor.visit(fiqlParser.parse(fiqlExpression)); return searchCondVisitor.getQuery(); } catch (Exception e) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression); sce.getElements().add(fiqlExpression); sce.getElements().add(ExceptionUtils.getRootCauseMessage(e)); throw sce; } }
From source file:org.apache.syncope.core.persistence.api.search.SearchCondConverter.java
/** * Parses a FIQL expression into Syncope's {@link SearchCond}, using {@link SyncopeFiqlParser}. * * @param fiql FIQL string//from w w w. j a v a 2 s . c o m * @param realms optional realm to provide to {@link SearchCondVisitor} * @return {@link SearchCond} instance for given FIQL expression */ public static SearchCond convert(final String fiql, final String... realms) { SyncopeFiqlParser<SearchBean> parser = new SyncopeFiqlParser<>(SearchBean.class, AbstractFiqlSearchConditionBuilder.CONTEXTUAL_PROPERTIES); try { SearchCondVisitor visitor = new SearchCondVisitor(); if (realms != null && realms.length > 0) { visitor.setRealm(realms[0]); } SearchCondition<SearchBean> sc = parser.parse(URLDecoder.decode(fiql, StandardCharsets.UTF_8.name())); sc.accept(visitor); return visitor.getQuery(); } catch (Exception e) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression); sce.getElements().add(fiql); sce.getElements().add(ExceptionUtils.getRootCauseMessage(e)); throw sce; } }
From source file:org.apache.syncope.core.provisioning.java.pushpull.AbstractPullResultHandler.java
protected void create(final AnyTO anyTO, final SyncDelta delta, final String operation, final ProvisioningReport result) throws JobExecutionException { Object output;/*from ww w .ja va 2s.c o m*/ Result resultStatus; try { AnyTO created = doCreate(anyTO, delta); output = created; result.setKey(created.getKey()); result.setName(getName(created)); resultStatus = Result.SUCCESS; for (PullActions action : profile.getActions()) { action.after(profile, delta, created, result); } LOG.debug("{} {} successfully created", created.getType(), created.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 {} {}", anyTO.getType(), 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 {} {} ", anyTO.getType(), 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.AbstractPullResultHandler.java
protected List<ProvisioningReport> update(final SyncDelta delta, final List<String> anyKeys, final Provision provision) 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(); }/* ww w.j ava 2 s.c o m*/ LOG.debug("About to update {}", anyKeys); List<ProvisioningReport> results = new ArrayList<>(); for (String key : anyKeys) { LOG.debug("About to update {}", key); ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.UPDATE); result.setAnyType(provision.getAnyType().getKey()); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setKey(key); AnyTO before = getAnyTO(key); if (before == null) { result.setStatus(ProvisioningReport.Status.FAILURE); result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key)); } else { result.setName(getName(before)); } if (!profile.isDryRun()) { Result resultStatus; Object output; AnyPatch effectivePatch = null; if (before == null) { resultStatus = Result.FAILURE; output = null; } else { try { AnyPatch anyPatch = connObjectUtils.getAnyPatch(before.getKey(), delta.getObject(), before, profile.getTask(), provision, getAnyUtils()); for (PullActions action : profile.getActions()) { action.beforeUpdate(profile, delta, before, anyPatch); } effectivePatch = doUpdate(before, anyPatch, delta, result); AnyTO updated = AnyOperations.patch(before, effectivePatch); for (PullActions action : profile.getActions()) { action.after(profile, delta, updated, result); } output = updated; resultStatus = Result.SUCCESS; result.setName(getName(updated)); LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key); } 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 {} {}", provision.getAnyType().getKey(), 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 {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e); output = e; resultStatus = Result.FAILURE; } } finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta, effectivePatch); } results.add(result); } return results; }
From source file:org.apache.syncope.core.provisioning.java.pushpull.AbstractPullResultHandler.java
protected List<ProvisioningReport> deprovision(final SyncDelta delta, final List<String> anyKeys, final Provision provision, final boolean unlink) throws JobExecutionException { if (!profile.getTask().isPerformUpdate()) { LOG.debug("PullTask not configured for update"); finalize(//w w w. j a v a 2 s . c om unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), Result.SUCCESS, null, null, delta); return Collections.<ProvisioningReport>emptyList(); } LOG.debug("About to deprovision {}", anyKeys); final List<ProvisioningReport> results = new ArrayList<>(); for (String key : anyKeys) { LOG.debug("About to unassign resource {}", key); ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.DELETE); result.setAnyType(provision.getAnyType().getKey()); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setKey(key); AnyTO before = getAnyTO(key); if (before == null) { result.setStatus(ProvisioningReport.Status.FAILURE); result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key)); } if (!profile.isDryRun()) { Object output; Result resultStatus; if (before == null) { resultStatus = Result.FAILURE; output = null; } else { result.setName(getName(before)); 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.getDeleteTasks(provision.getAnyType().getKind(), key, propByRes, null), false); AnyPatch anyPatch = null; if (unlink) { anyPatch = newPatch(key); anyPatch.getResources() .add(new StringPatchItem.Builder().operation(PatchOperation.DELETE) .value(profile.getTask().getResource().getKey()).build()); } if (anyPatch == null) { output = getAnyTO(key); } else { output = doUpdate(before, anyPatch, delta, result); } for (PullActions action : profile.getActions()) { action.after(profile, delta, AnyTO.class.cast(output), result); } resultStatus = Result.SUCCESS; LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key); } 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 {} {}", provision.getAnyType().getKey(), 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 {} {}", provision.getAnyType().getKey(), 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.AbstractPullResultHandler.java
protected List<ProvisioningReport> link(final SyncDelta delta, final List<String> anyKeys, final Provision provision, 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(); }/*w ww.j av a 2s . c o m*/ LOG.debug("About to update {}", anyKeys); final List<ProvisioningReport> results = new ArrayList<>(); for (String key : anyKeys) { LOG.debug("About to unassign resource {}", key); ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.NONE); result.setAnyType(provision.getAnyType().getKey()); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setKey(key); AnyTO before = getAnyTO(key); if (before == null) { result.setStatus(ProvisioningReport.Status.FAILURE); result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key)); } if (!profile.isDryRun()) { Result resultStatus; Object output; AnyPatch effectivePatch = null; if (before == null) { resultStatus = Result.FAILURE; output = null; } else { result.setName(getName(before)); try { if (unlink) { for (PullActions action : profile.getActions()) { action.beforeUnlink(profile, delta, before); } } else { for (PullActions action : profile.getActions()) { action.beforeLink(profile, delta, before); } } AnyPatch anyPatch = newPatch(before.getKey()); anyPatch.getResources() .add(new StringPatchItem.Builder() .operation(unlink ? PatchOperation.DELETE : PatchOperation.ADD_REPLACE) .value(profile.getTask().getResource().getKey()).build()); effectivePatch = update(anyPatch).getResult(); output = AnyOperations.patch(before, effectivePatch); for (PullActions action : profile.getActions()) { action.after(profile, delta, AnyTO.class.cast(output), result); } resultStatus = Result.SUCCESS; LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key); } 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 {} {}", provision.getAnyType().getKey(), 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 {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e); output = e; resultStatus = Result.FAILURE; } } finalize( unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta, effectivePatch); } results.add(result); } return results; }
From source file:org.apache.syncope.core.provisioning.java.pushpull.AbstractPullResultHandler.java
protected List<ProvisioningReport> delete(final SyncDelta delta, final List<String> anyKeys, final Provision provision) 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 w w w . j ava 2 s. co m LOG.debug("About to delete {}", anyKeys); List<ProvisioningReport> results = new ArrayList<>(); for (String key : anyKeys) { Object output; Result resultStatus = Result.FAILURE; ProvisioningReport result = new ProvisioningReport(); try { AnyTO before = getAnyTO(key); result.setKey(key); result.setName(getName(before)); result.setOperation(ResourceOperation.DELETE); result.setAnyType(provision.getAnyType().getKey()); result.setStatus(ProvisioningReport.Status.SUCCESS); if (!profile.isDryRun()) { for (PullActions action : profile.getActions()) { action.beforeDelete(profile, delta, before); } try { doDelete(provision.getAnyType().getKind(), key); 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 {} {}", provision.getAnyType().getKey(), key, e); output = e; } finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, delta); } results.add(result); } catch (NotFoundException e) { LOG.error("Could not find {} {}", provision.getAnyType().getKey(), key, e); } catch (DelegatedAdministrationException e) { LOG.error("Not allowed to read {} {}", provision.getAnyType().getKey(), key, e); } catch (Exception e) { LOG.error("Could not delete {} {}", provision.getAnyType().getKey(), key, e); } } return results; }
From source file:org.apache.syncope.core.provisioning.java.pushpull.AbstractPushResultHandler.java
protected void doHandle(final Any<?> any) throws JobExecutionException { AnyUtils anyUtils = anyUtilsFactory.getInstance(any); ProvisioningReport result = new ProvisioningReport(); profile.getResults().add(result);/*from www. j av a 2 s. com*/ result.setKey(any.getKey()); result.setAnyType(any.getType().getKey()); result.setName(getName(any)); Boolean enabled = any instanceof User && profile.getTask().isSyncStatus() ? ((User) any).isSuspended() ? Boolean.FALSE : Boolean.TRUE : null; LOG.debug("Propagating {} with key {} towards {}", anyUtils.getAnyTypeKind(), any.getKey(), profile.getTask().getResource()); Object output = null; Result resultStatus = null; // Try to read remote object BEFORE any actual operation Optional<? extends Provision> provision = profile.getTask().getResource().getProvision(any.getType()); Optional<MappingItem> connObjectKey = MappingUtils.getConnObjectKeyItem(provision.get()); Optional<String> connObjecKeyValue = mappingManager.getConnObjectKeyValue(any, provision.get()); ConnectorObject beforeObj = getRemoteObject(provision.get().getObjectClass(), connObjectKey.get().getExtAttrName(), connObjecKeyValue.get(), provision.get().getMapping().getItems().iterator()); Boolean status = profile.getTask().isSyncStatus() ? enabled : null; 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, any.getType().getKind().name().toLowerCase(), profile.getTask().getResource().getKey(), operation); boolean auditRequested = auditManager.auditRequested(AuditElements.EventCategoryType.PUSH, any.getType().getKind().name().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, any); } if (!profile.getTask().isPerformCreate()) { LOG.debug("PushTask not configured for create"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { assign(any, status, result); } break; case PROVISION: for (PushActions action : profile.getActions()) { action.beforeProvision(profile, any); } if (!profile.getTask().isPerformCreate()) { LOG.debug("PushTask not configured for create"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { provision(any, status, result); } break; case UNLINK: for (PushActions action : profile.getActions()) { action.beforeUnlink(profile, any); } if (!profile.getTask().isPerformUpdate()) { LOG.debug("PushTask not configured for update"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { link(any, true, result); } break; case IGNORE: LOG.debug("Ignored any: {}", any); 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, any); } if (!profile.getTask().isPerformUpdate()) { LOG.debug("PushTask not configured for update"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { update(any, result); } break; case DEPROVISION: for (PushActions action : profile.getActions()) { action.beforeDeprovision(profile, any); } if (!profile.getTask().isPerformDelete()) { LOG.debug("PushTask not configured for delete"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { deprovision(any, result); } break; case UNASSIGN: for (PushActions action : profile.getActions()) { action.beforeUnassign(profile, any); } if (!profile.getTask().isPerformDelete()) { LOG.debug("PushTask not configured for delete"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { unassign(any, result); } break; case LINK: for (PushActions action : profile.getActions()) { action.beforeLink(profile, any); } if (!profile.getTask().isPerformUpdate()) { LOG.debug("PushTask not configured for update"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { link(any, false, result); } break; case UNLINK: for (PushActions action : profile.getActions()) { action.beforeUnlink(profile, any); } if (!profile.getTask().isPerformUpdate()) { LOG.debug("PushTask not configured for update"); result.setStatus(ProvisioningReport.Status.IGNORE); } else { link(any, true, result); } break; case IGNORE: LOG.debug("Ignored any: {}", any); result.setStatus(ProvisioningReport.Status.IGNORE); break; default: // do nothing } } for (PushActions action : profile.getActions()) { action.after(profile, any, result); } if (result.getStatus() == null) { result.setStatus(ProvisioningReport.Status.SUCCESS); } resultStatus = AuditElements.Result.SUCCESS; output = getRemoteObject(provision.get().getObjectClass(), connObjectKey.get().getExtAttrName(), connObjecKeyValue.get(), provision.get().getMapping().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 {}", any, profile.getTask().getResource(), e); for (PushActions action : profile.getActions()) { action.onError(profile, any, 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, any.getType().getKind().name().toLowerCase(), profile.getTask().getResource().getKey(), operation, resultStatus, beforeObj, output, any)); AfterHandlingJob.schedule(scheduler, jobMap); } } } }
From source file:org.apache.syncope.core.provisioning.java.pushpull.DefaultRealmPullResultHandler.java
private void create(final RealmTO realmTO, final SyncDelta delta, final String operation, final ProvisioningReport result) throws JobExecutionException { Object output;//from w w w . j ava2 s . c om Result resultStatus; try { Realm realm = realmDAO.save(binder.create(profile.getTask().getDestinatioRealm(), realmTO)); PropagationByResource propByRes = new PropagationByResource(); for (String resource : realm.getResourceKeys()) { propByRes.add(ResourceOperation.CREATE, resource); } List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null); taskExecutor.execute(tasks, false); RealmTO actual = binder.getRealmTO(realm, true); 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); }