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);
}
}
}
Aggregations