Search in sources :

Example 1 with SubProcessActivityBehavior

use of org.activiti.engine.impl.delegate.SubProcessActivityBehavior in project Activiti by Activiti.

the class EndExecutionOperation method handleProcessInstanceExecution.

protected void handleProcessInstanceExecution(ExecutionEntity processInstanceExecution) {
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    // No parent execution == process instance id
    String processInstanceId = processInstanceExecution.getId();
    logger.debug("No parent execution found. Verifying if process instance {} can be stopped.", processInstanceId);
    ExecutionEntity superExecution = processInstanceExecution.getSuperExecution();
    SubProcessActivityBehavior subProcessActivityBehavior = null;
    // copy variables before destroying the ended sub process instance (call activity)
    if (superExecution != null) {
        FlowNode superExecutionElement = (FlowNode) superExecution.getCurrentFlowElement();
        subProcessActivityBehavior = (SubProcessActivityBehavior) superExecutionElement.getBehavior();
        try {
            subProcessActivityBehavior.completing(superExecution, processInstanceExecution);
        } catch (RuntimeException e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw e;
        } catch (Exception e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
        }
    }
    int activeExecutions = getNumberOfActiveChildExecutionsForProcessInstance(executionEntityManager, processInstanceId);
    if (activeExecutions == 0) {
        logger.debug("No active executions found. Ending process instance {} ", processInstanceId);
        // note the use of execution here vs processinstance execution for getting the flowelement
        executionEntityManager.deleteProcessInstanceExecutionEntity(processInstanceId, execution.getCurrentFlowElement() != null ? execution.getCurrentFlowElement().getId() : null, null, false, false);
    } else {
        logger.debug("Active executions found. Process instance {} will not be ended.", processInstanceId);
    }
    Process process = ProcessDefinitionUtil.getProcess(processInstanceExecution.getProcessDefinitionId());
    // Execute execution listeners for process end.
    if (CollectionUtil.isNotEmpty(process.getExecutionListeners())) {
        executeExecutionListeners(process, processInstanceExecution, ExecutionListener.EVENTNAME_END);
    }
    // and trigger execution afterwards if doing a call activity
    if (superExecution != null) {
        superExecution.setSubProcessInstance(null);
        try {
            subProcessActivityBehavior.completed(superExecution);
        } catch (RuntimeException e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw e;
        } catch (Exception e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) ActivitiException(org.activiti.engine.ActivitiException) SubProcessActivityBehavior(org.activiti.engine.impl.delegate.SubProcessActivityBehavior) FlowNode(org.activiti.bpmn.model.FlowNode)

Aggregations

FlowNode (org.activiti.bpmn.model.FlowNode)1 Process (org.activiti.bpmn.model.Process)1 SubProcess (org.activiti.bpmn.model.SubProcess)1 ActivitiException (org.activiti.engine.ActivitiException)1 SubProcessActivityBehavior (org.activiti.engine.impl.delegate.SubProcessActivityBehavior)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)1