All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.engine.impl.agenda.DestroyScopeOperation Maven / Gradle / Ivy

There is a newer version: 3.0.Beta
Show newest version
package org.activiti.engine.impl.agenda;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.*;

import java.util.Collection;

/**
 * Destroys a scope (for example a subprocess): this means that all child executions,
 * tasks, jobs, variables, etc within that scope are deleted.
 * 

* The typical example is an interrupting boundary event that is on the boundary * of a subprocess and is triggered. At that point, everything within the subprocess would * need to be destroyed. */ public class DestroyScopeOperation extends AbstractOperation { public DestroyScopeOperation(CommandContext commandContext, ExecutionEntity execution) { super(commandContext, execution); } @Override public void run() { // Find the actual scope that needs to be destroyed. // This could be the incoming execution, or the first parent execution where isScope = true // Find parent scope execution ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution); if (scopeExecution == null) { throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event"); } ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); deleteAllChildExecutions(executionEntityManager, scopeExecution); // Delete all scope tasks TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager(); deleteAllScopeTasks(scopeExecution, taskEntityManager); // Delete all scope jobs TimerJobEntityManager timerJobEntityManager = commandContext.getTimerJobEntityManager(); deleteAllScopeJobs(scopeExecution, timerJobEntityManager); // Remove variables associated with this scope VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager(); removeAllVariablesFromScope(scopeExecution, variableInstanceEntityManager); commandContext.getHistoryManager().recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason()); executionEntityManager.delete(scopeExecution); } private void removeAllVariablesFromScope(ExecutionEntity scopeExecution, VariableInstanceEntityManager variableInstanceEntityManager) { Collection variablesForExecution = variableInstanceEntityManager.findVariableInstancesByExecutionId(scopeExecution.getId()); for (VariableInstanceEntity variable : variablesForExecution) { variableInstanceEntityManager.delete(variable); } } private void deleteAllScopeJobs(ExecutionEntity scopeExecution, TimerJobEntityManager timerJobEntityManager) { Collection timerJobsForExecution = timerJobEntityManager.findJobsByExecutionId(scopeExecution.getId()); for (TimerJobEntity job : timerJobsForExecution) { timerJobEntityManager.delete(job); } JobEntityManager jobEntityManager = commandContext.getJobEntityManager(); Collection jobsForExecution = jobEntityManager.findJobsByExecutionId(scopeExecution.getId()); for (JobEntity job : jobsForExecution) { jobEntityManager.delete(job); } SuspendedJobEntityManager suspendedJobEntityManager = commandContext.getSuspendedJobEntityManager(); Collection suspendedJobsForExecution = suspendedJobEntityManager.findJobsByExecutionId(scopeExecution.getId()); for (SuspendedJobEntity job : suspendedJobsForExecution) { suspendedJobEntityManager.delete(job); } DeadLetterJobEntityManager deadLetterJobEntityManager = commandContext.getDeadLetterJobEntityManager(); Collection deadLetterJobsForExecution = deadLetterJobEntityManager.findJobsByExecutionId(scopeExecution.getId()); for (DeadLetterJobEntity job : deadLetterJobsForExecution) { deadLetterJobEntityManager.delete(job); } } private void deleteAllScopeTasks(ExecutionEntity scopeExecution, TaskEntityManager taskEntityManager) { Collection tasksForExecution = taskEntityManager.findTasksByExecutionId(scopeExecution.getId()); for (TaskEntity taskEntity : tasksForExecution) { taskEntityManager.deleteTask(taskEntity, execution.getDeleteReason(), false, false); } } private ExecutionEntityManager deleteAllChildExecutions(ExecutionEntityManager executionEntityManager, ExecutionEntity scopeExecution) { // Delete all child executions Collection childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(scopeExecution.getId()); for (ExecutionEntity childExecution : childExecutions) { executionEntityManager.deleteExecutionAndRelatedData(childExecution, execution.getDeleteReason(), false); } return executionEntityManager; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy