Search in sources :

Example 1 with ActivityExecutionMappingCollector

use of org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector 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);
    }
}
Also used : ActivityExecutionMappingCollector(org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) OutputVariablesPropagator(org.camunda.bpm.engine.impl.tree.OutputVariablesPropagator) ActivityExecutionTuple(org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ActivityExecutionHierarchyWalker(org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) ErrorEventDefinition(org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition)

Example 2 with ActivityExecutionMappingCollector

use of org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector 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);
    }
}
Also used : ActivityExecutionMappingCollector(org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector) ActivityExecutionHierarchyWalker(org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker) EscalationEventDefinition(org.camunda.bpm.engine.impl.bpmn.parser.EscalationEventDefinition) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) OutputVariablesPropagator(org.camunda.bpm.engine.impl.tree.OutputVariablesPropagator) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ActivityExecutionTuple(org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple)

Aggregations

PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)2 ActivityExecutionHierarchyWalker (org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker)2 ActivityExecutionMappingCollector (org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector)2 ActivityExecutionTuple (org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple)2 OutputVariablesPropagator (org.camunda.bpm.engine.impl.tree.OutputVariablesPropagator)2 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ErrorEventDefinition (org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition)1 EscalationEventDefinition (org.camunda.bpm.engine.impl.bpmn.parser.EscalationEventDefinition)1 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)1