Search in sources :

Example 1 with ProcessInstanceQueryImpl

use of org.activiti.engine.impl.ProcessInstanceQueryImpl in project Activiti by Activiti.

the class ExecutionEntityManager method deleteProcessInstanceCascade.

private void deleteProcessInstanceCascade(ExecutionEntity execution, String deleteReason, boolean deleteHistory) {
    CommandContext commandContext = Context.getCommandContext();
    ProcessInstanceQueryImpl processInstanceQuery = new ProcessInstanceQueryImpl(commandContext);
    List<ProcessInstance> subProcesses = processInstanceQuery.superProcessInstanceId(execution.getProcessInstanceId()).list();
    for (ProcessInstance subProcess : subProcesses) {
        deleteProcessInstanceCascade((ExecutionEntity) subProcess, deleteReason, deleteHistory);
    }
    commandContext.getTaskEntityManager().deleteTasksByProcessInstanceId(execution.getId(), deleteReason, deleteHistory);
    // fill default reason if none provided
    if (deleteReason == null) {
        deleteReason = "ACTIVITY_DELETED";
    }
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && execution.isProcessInstanceType()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createCancelledEvent(execution.getProcessInstanceId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), deleteReason));
    }
    // delete the execution BEFORE we delete the history, otherwise we will produce orphan HistoricVariableInstance instances
    execution.deleteCascade(deleteReason);
    if (deleteHistory) {
        commandContext.getHistoricProcessInstanceEntityManager().deleteHistoricProcessInstanceById(execution.getId());
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessInstanceQueryImpl(org.activiti.engine.impl.ProcessInstanceQueryImpl)

Aggregations

ProcessInstanceQueryImpl (org.activiti.engine.impl.ProcessInstanceQueryImpl)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1