Search in sources :

Example 26 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ParallelMultiInstanceBehavior method leave.

/**
   * Called when the wrapped {@link ActivityBehavior} calls the 
   * {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method.
   * Handles the completion of one of the parallel instances
   */
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<ExecutionEntity>();
            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);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ArrayList(java.util.ArrayList) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Example 27 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class SubProcessActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    PvmActivity activity = execution.getActivity();
    ActivityImpl initialActivity = (ActivityImpl) activity.getProperty(BpmnParse.PROPERTYNAME_INITIAL);
    if (initialActivity == null) {
        throw new ActivitiException("No initial activity found for subprocess " + execution.getActivity().getId());
    }
    // initialize the template-defined data objects as variables
    initializeDataObjects(execution, activity);
    if (initialActivity.getActivityBehavior() != null && initialActivity.getActivityBehavior() instanceof NoneStartEventActivityBehavior) {
        // embedded subprocess: only none start allowed
        ((ExecutionEntity) execution).setActivity(initialActivity);
        Context.getCommandContext().getHistoryManager().recordActivityStart((ExecutionEntity) execution);
    }
    execution.executeActivity(initialActivity);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity)

Example 28 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class TerminateEndEventActivityBehavior method deleteProcessInstance.

protected void deleteProcessInstance(ExecutionEntity processInstanceExecution, ActivityExecution execution, String deleteReason) {
    List<ExecutionEntity> orderedExecutions = orderExecutionsRootToLeaf(processInstanceExecution);
    Collections.reverse(orderedExecutions);
    endAllHistoricActivities(processInstanceExecution.getId());
    for (ExecutionEntity executionToDelete : orderedExecutions) {
        executionToDelete.setDeleteReason(deleteReason);
        executionToDelete.setEnded(true);
        executionToDelete.setActive(false);
        executionToDelete.setDeleteRoot(true);
        executionToDelete.remove();
    }
    Context.getCommandContext().getHistoryManager().recordProcessInstanceEnd(processInstanceExecution.getId(), deleteReason, execution.getActivity().getId());
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity)

Example 29 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class AbstractBpmnActivityBehavior method createCompensateEventSubscription.

protected void createCompensateEventSubscription(ActivityExecution execution) {
    String compensationHandlerId = (String) execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_COMPENSATION_HANDLER_ID);
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    ActivityImpl compensationHandlder = executionEntity.getProcessDefinition().findActivity(compensationHandlerId);
    PvmScope scopeActivitiy = compensationHandlder.getParent();
    ExecutionEntity scopeExecution = ScopeUtil.findScopeExecutionForScope(executionEntity, scopeActivitiy);
    CompensateEventSubscriptionEntity compensateEventSubscriptionEntity = CompensateEventSubscriptionEntity.createAndInsert(scopeExecution);
    compensateEventSubscriptionEntity.setActivity(compensationHandlder);
}
Also used : PvmScope(org.activiti.engine.impl.pvm.PvmScope) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)

Example 30 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class AbstractBpmnActivityBehavior method signalCompensationDone.

protected void signalCompensationDone(ActivityExecution execution, Object signalData) {
    // 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();
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution)

Aggregations

ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)58 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)15 ActivitiException (org.activiti.engine.ActivitiException)12 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)11 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)8 HashMap (java.util.HashMap)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)5 Deployment (org.activiti.engine.test.Deployment)5 ArrayList (java.util.ArrayList)4 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)4 AttachmentEntity (org.activiti.engine.impl.persistence.entity.AttachmentEntity)3 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 List (java.util.List)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2