Java Code Examples for org.activiti.engine.impl.pvm.delegate.ActivityExecution#getParent()

The following examples show how to use org.activiti.engine.impl.pvm.delegate.ActivityExecution#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBpmnActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void signalCompensationDone(ActivityExecution execution, Object signalData) {
    // default behavior is to join compensating executions and propagate the signal if all executions
    // have compensated

    // join compensating executions
    if (execution.getExecutions().isEmpty()) {
        if (execution.getParent() != null) {
            ActivityExecution parent = execution.getParent();
            ((InterpretableExecution) execution).remove();
            ((InterpretableExecution) parent).signal("compensationDone", signalData);
        }
    } else {
        ((ExecutionEntity) execution).forceUpdate();
    }

}
 
Example 2
Source File: ScopeUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Find the next scope execution in the parent execution hierarchy That method works different than
 * {@link #findScopeExecutionForScope(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.pvm.PvmScope)} which returns the most outer scope execution.
 * 
 * @param execution
 *            the execution from which to start the search
 * @return the next scope execution in the parent execution hierarchy
 */
public static ActivityExecution findScopeExecution(ActivityExecution execution) {

    while (execution.getParentId() != null && !execution.isScope()) {
        execution = execution.getParent();
    }

    if (execution != null && execution.isConcurrent()) {
        execution = execution.getParent();
    }

    return execution;

}
 
Example 3
Source File: MultiInstanceActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Integer getLoopVariable(ActivityExecution execution, String variableName) {
    Object value = execution.getVariableLocal(variableName);
    ActivityExecution parent = execution.getParent();
    while (value == null && parent != null) {
        value = parent.getVariableLocal(variableName);
        parent = parent.getParent();
    }
    return (Integer) (value != null ? value : 0);
}
 
Example 4
Source File: GatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void lockConcurrentRoot(ActivityExecution execution) {
    ActivityExecution concurrentRoot = null;
    if (execution.isConcurrent()) {
        concurrentRoot = execution.getParent();
    } else {
        concurrentRoot = execution;
    }
    ((ExecutionEntity) concurrentRoot).forceUpdate();
}
 
Example 5
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the parent execution that is a process instance. For a callactivity, this will be the process instance representing the called process instance and NOT the root process instance!
 */
protected ActivityExecution findProcessInstanceExecution(ActivityExecution execution) {
    ActivityExecution currentExecution = execution;
    while (currentExecution.getParent() != null) {
        currentExecution = currentExecution.getParent();
    }
    return currentExecution;
}
 
Example 6
Source File: ParallelMultiInstanceBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method. Handles the completion of one of the parallel instances
 */
@Override
public void leave(ActivityExecution execution) {
    callActivityEndListeners(execution);

    int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
    if (nrOfInstances == 0) {
        // Empty collection, just leave.
        super.leave(execution);
        return;
    }

    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
    int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;

    if (isExtraScopeNeeded()) {
        // In case an extra scope was created, it must be destroyed first before going further
        ExecutionEntity extraScope = (ExecutionEntity) execution;
        execution = execution.getParent();
        extraScope.remove();
    }

    if (execution.getParent() != null) { // will be null in case of empty collection
        setLoopVariable(execution.getParent(), NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
        setLoopVariable(execution.getParent(), NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
    }
    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);

    ExecutionEntity executionEntity = (ExecutionEntity) execution;

    if (executionEntity.getParent() != null) {

        executionEntity.inactivate();
        executionEntity.getParent().forceUpdate();

        List<ActivityExecution> joinedExecutions = executionEntity.findInactiveConcurrentExecutions(execution.getActivity());
        if (joinedExecutions.size() >= nrOfInstances || completionConditionSatisfied(execution)) {

            // Removing all active child executions (ie because completionCondition is true)
            List<ExecutionEntity> executionsToRemove = new ArrayList<>();
            for (ActivityExecution childExecution : executionEntity.getParent().getExecutions()) {
                if (childExecution.isActive()) {
                    executionsToRemove.add((ExecutionEntity) childExecution);
                }
            }
            for (ExecutionEntity executionToRemove : executionsToRemove) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Execution {} still active, but multi-instance is completed. Removing this execution.", executionToRemove);
                }
                executionToRemove.inactivate();
                executionToRemove.deleteCascade("multi-instance completed");
            }
            executionEntity.takeAll(executionEntity.getActivity().getOutgoingTransitions(), joinedExecutions);
        }

    } else {
        super.leave(executionEntity);
    }
}
 
Example 7
Source File: BpmnActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Actual implementation of leaving an activity.
 *
 * @param execution                      The current execution context
 * @param checkConditions                Whether or not to check conditions before determining whether or not to take a transition.
 * @param throwExceptionIfExecutionStuck If true, an {@link ActivitiException} will be thrown in case no transition could be found to leave the activity.
 */
protected void performOutgoingBehavior(ActivityExecution execution,
                                       boolean checkConditions, boolean throwExceptionIfExecutionStuck, List<ActivityExecution> reusableExecutions) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Leaving activity '{}'", execution.getActivity().getId());
    }

    String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
    List<PvmTransition> transitionsToTake = new ArrayList<>();

    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    for (PvmTransition outgoingTransition : outgoingTransitions) {
        Expression skipExpression = outgoingTransition.getSkipExpression();

        if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
            if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
                Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
                if (condition == null || !checkConditions || condition.evaluate(outgoingTransition.getId(), execution)) {
                    transitionsToTake.add(outgoingTransition);
                }
            }

        } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
            transitionsToTake.add(outgoingTransition);
        }
    }

    if (transitionsToTake.size() == 1) {

        execution.take(transitionsToTake.get(0));

    } else if (transitionsToTake.size() >= 1) {

        execution.inactivate();
        if (reusableExecutions == null || reusableExecutions.isEmpty()) {
            execution.takeAll(transitionsToTake, Collections.singletonList(execution));
        } else {
            execution.takeAll(transitionsToTake, reusableExecutions);
        }

    } else {

        if (defaultSequenceFlow != null) {
            PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
            if (defaultTransition != null) {
                execution.take(defaultTransition);
            } else {
                throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' could not be not found");
            }
        } else {

            Object isForCompensation = execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION);
            if (isForCompensation != null && (Boolean) isForCompensation) {
                if (execution instanceof ExecutionEntity) {
                    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution);
                }
                InterpretableExecution parentExecution = (InterpretableExecution) execution.getParent();
                ((InterpretableExecution) execution).remove();
                parentExecution.signal("compensationDone", null);

            } else {

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("No outgoing sequence flow found for {}. Ending execution.", execution.getActivity().getId());
                }
                execution.end();

                if (throwExceptionIfExecutionStuck) {
                    throw new ActivitiException("No outgoing sequence flow of the inclusive gateway '" + execution.getActivity().getId()
                            + "' could be selected for continuing the process");
                }
            }

        }
    }
}