use of org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker in project camunda-bpm-platform by camunda.
the class AbstractBpmnActivityBehavior method propagateError.
protected void propagateError(String errorCode, String errorMessage, Exception origException, ActivityExecution execution) throws Exception {
ActivityExecutionHierarchyWalker walker = new ActivityExecutionHierarchyWalker(execution);
final ErrorDeclarationForProcessInstanceFinder errorDeclarationFinder = new ErrorDeclarationForProcessInstanceFinder(origException, errorCode, execution.getActivity());
ActivityExecutionMappingCollector activityExecutionMappingCollector = new ActivityExecutionMappingCollector(execution);
walker.addScopePreVisitor(errorDeclarationFinder);
walker.addExecutionPreVisitor(activityExecutionMappingCollector);
// map variables to super executions in the hierarchy of called process instances
walker.addExecutionPreVisitor(new OutputVariablesPropagator());
try {
walker.walkUntil(new ReferenceWalker.WalkCondition<ActivityExecutionTuple>() {
@Override
public boolean isFulfilled(ActivityExecutionTuple element) {
return errorDeclarationFinder.getErrorEventDefinition() != null || element == null;
}
});
} catch (Exception e) {
// separate the exception handling to support a fail-safe error propagation
throw new ErrorPropagationException(e);
}
PvmActivity errorHandlingActivity = errorDeclarationFinder.getErrorHandlerActivity();
// process the error
if (errorHandlingActivity == null) {
if (origException == null) {
if (Context.getCommandContext().getProcessEngineConfiguration().isEnableExceptionsAfterUnhandledBpmnError()) {
throw LOG.missingBoundaryCatchEventError(execution.getActivity().getId(), errorCode);
} else {
LOG.missingBoundaryCatchEvent(execution.getActivity().getId(), errorCode);
execution.end(true);
}
} else {
// throw original exception
throw origException;
}
} else {
ErrorEventDefinition errorDefinition = errorDeclarationFinder.getErrorEventDefinition();
PvmExecutionImpl errorHandlingExecution = activityExecutionMappingCollector.getExecutionForScope(errorHandlingActivity.getEventScope());
if (errorDefinition.getErrorCodeVariable() != null) {
errorHandlingExecution.setVariable(errorDefinition.getErrorCodeVariable(), errorCode);
}
if (errorDefinition.getErrorMessageVariable() != null) {
errorHandlingExecution.setVariable(errorDefinition.getErrorMessageVariable(), errorMessage);
}
errorHandlingExecution.executeActivity(errorHandlingActivity);
}
}
use of org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker in project camunda-bpm-platform by camunda.
the class ThrowEscalationEventActivityBehavior method execute.
@Override
public void execute(ActivityExecution execution) throws Exception {
final PvmActivity currentActivity = execution.getActivity();
final EscalationEventDefinitionFinder escalationEventDefinitionFinder = new EscalationEventDefinitionFinder(escalation.getEscalationCode(), currentActivity);
ActivityExecutionMappingCollector activityExecutionMappingCollector = new ActivityExecutionMappingCollector(execution);
ActivityExecutionHierarchyWalker walker = new ActivityExecutionHierarchyWalker(execution);
walker.addScopePreVisitor(escalationEventDefinitionFinder);
walker.addExecutionPreVisitor(activityExecutionMappingCollector);
walker.addExecutionPreVisitor(new OutputVariablesPropagator());
walker.walkUntil(new ReferenceWalker.WalkCondition<ActivityExecutionTuple>() {
@Override
public boolean isFulfilled(ActivityExecutionTuple element) {
return escalationEventDefinitionFinder.getEscalationEventDefinition() != null || element == null;
}
});
EscalationEventDefinition escalationEventDefinition = escalationEventDefinitionFinder.getEscalationEventDefinition();
if (escalationEventDefinition != null) {
executeEscalationHandler(escalationEventDefinition, activityExecutionMappingCollector);
}
if (escalationEventDefinition == null || !escalationEventDefinition.isCancelActivity()) {
leaveExecution(execution, currentActivity, escalationEventDefinition);
}
}
Aggregations