Search in sources :

Example 6 with PvmActivity

use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.

the class AbstractBpmnActivityBehavior method doLeave.

/**
 * Subclasses that call leave() will first pass through this method, before
 * the regular {@link FlowNodeActivityBehavior#leave(ActivityExecution)} is
 * called.
 */
@Override
public void doLeave(ActivityExecution execution) {
    PvmActivity currentActivity = execution.getActivity();
    ActivityImpl compensationHandler = ((ActivityImpl) currentActivity).findCompensationHandler();
    // subscription for compensation event subprocess is already created
    if (compensationHandler != null && !isCompensationEventSubprocess(compensationHandler)) {
        createCompensateEventSubscription(execution, compensationHandler);
    }
    super.doLeave(execution);
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 7 with PvmActivity

use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.

the class InclusiveGatewayActivityBehavior method isReachable.

protected boolean isReachable(PvmActivity srcActivity, PvmActivity targetActivity, Set<PvmActivity> visitedActivities) {
    if (srcActivity.equals(targetActivity)) {
        return true;
    }
    // To avoid infinite looping, we must capture every node we visit and
    // check before going further in the graph if we have already visited the node.
    visitedActivities.add(srcActivity);
    List<PvmTransition> outgoingTransitions = srcActivity.getOutgoingTransitions();
    if (outgoingTransitions.isEmpty()) {
        ScopeImpl flowScope = srcActivity.getFlowScope();
        if (flowScope == null || !(flowScope instanceof PvmActivity)) {
            return false;
        }
        return isReachable((PvmActivity) flowScope, targetActivity, visitedActivities);
    } else {
        for (PvmTransition pvmTransition : outgoingTransitions) {
            PvmActivity destinationActivity = pvmTransition.getDestination();
            if (destinationActivity != null && !visitedActivities.contains(destinationActivity)) {
                boolean reachable = isReachable(destinationActivity, targetActivity, visitedActivities);
                // If false, we should investigate other paths, and not yet return the result
                if (reachable) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 8 with PvmActivity

use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.

the class InclusiveGatewayActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    execution.inactivate();
    lockConcurrentRoot(execution);
    PvmActivity activity = execution.getActivity();
    if (activatesGateway(execution, activity)) {
        LOG.activityActivation(activity.getId());
        List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
        String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
        List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();
        // find matching non-default sequence flows
        for (PvmTransition outgoingTransition : execution.getActivity().getOutgoingTransitions()) {
            if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
                Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
                if (condition == null || condition.evaluate(execution)) {
                    transitionsToTake.add(outgoingTransition);
                }
            }
        }
        // if none found, add default flow
        if (transitionsToTake.isEmpty()) {
            if (defaultSequenceFlow != null) {
                PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
                if (defaultTransition == null) {
                    throw LOG.missingDefaultFlowException(execution.getActivity().getId(), defaultSequenceFlow);
                }
                transitionsToTake.add(defaultTransition);
            } else {
                // No sequence flow could be found, not even a default one
                throw LOG.stuckExecutionException(execution.getActivity().getId());
            }
        }
        // take the flows found
        execution.leaveActivityViaTransitions(transitionsToTake, joinedExecutions);
    } else {
        LOG.noActivityActivation(activity.getId());
    }
}
Also used : Condition(org.camunda.bpm.engine.impl.Condition) ArrayList(java.util.ArrayList) ActivityExecution(org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition)

Example 9 with PvmActivity

use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.

the class ParallelGatewayActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    // Join
    PvmActivity activity = execution.getActivity();
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    execution.inactivate();
    lockConcurrentRoot(execution);
    List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
    int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
    int nbrOfExecutionsJoined = joinedExecutions.size();
    if (nbrOfExecutionsJoined == nbrOfExecutionsToJoin) {
        // Fork
        LOG.activityActivation(activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
        execution.leaveActivityViaTransitions(outgoingTransitions, joinedExecutions);
    } else {
        LOG.noActivityActivation(activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
    }
}
Also used : ActivityExecution(org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition)

Example 10 with PvmActivity

use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmd method validateAndSwitchVersionOfExecution.

protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {
    // check that the new process definition version contains the current activity
    if (execution.getActivity() != null) {
        String activityId = execution.getActivity().getId();
        PvmActivity newActivity = newProcessDefinition.findActivity(activityId);
        if (newActivity == null) {
            throw new ProcessEngineException("The new process definition " + "(key = '" + newProcessDefinition.getKey() + "') " + "does not contain the current activity " + "(id = '" + activityId + "') " + "of the process instance " + "(id = '" + processInstanceId + "').");
        }
        // clear cached activity so that outgoing transitions are refreshed
        execution.setActivity(newActivity);
    }
    // switch the process instance to the new process definition version
    execution.setProcessDefinition(newProcessDefinition);
    // and change possible existing tasks (as the process definition id is stored there too)
    List<TaskEntity> tasks = commandContext.getTaskManager().findTasksByExecutionId(execution.getId());
    for (TaskEntity taskEntity : tasks) {
        taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
    }
}
Also used : TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)39 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)13 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)9 PvmTransition (org.camunda.bpm.engine.impl.pvm.PvmTransition)7 ActivityExecution (org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution)6 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)6 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 TransitionImpl (org.camunda.bpm.engine.impl.pvm.process.TransitionImpl)4 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)4 ArrayList (java.util.ArrayList)3 PvmScope (org.camunda.bpm.engine.impl.pvm.PvmScope)3 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)3 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)3 List (java.util.List)2 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)2 ProcessDefinitionImpl (org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl)2 ExecutionStartContext (org.camunda.bpm.engine.impl.pvm.runtime.ExecutionStartContext)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