use of org.activiti.engine.impl.persistence.entity.SuspendedJobEntity in project Activiti by Activiti.
the class AbstractSetProcessInstanceStateCmd method execute.
public Void execute(CommandContext commandContext) {
if (processInstanceId == null) {
throw new ActivitiIllegalArgumentException("ProcessInstanceId cannot be null.");
}
ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(processInstanceId);
if (executionEntity == null) {
throw new ActivitiObjectNotFoundException("Cannot find processInstance for id '" + processInstanceId + "'.", Execution.class);
}
if (!executionEntity.isProcessInstanceType()) {
throw new ActivitiException("Cannot set suspension state for execution '" + processInstanceId + "': not a process instance.");
}
SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());
commandContext.getExecutionEntityManager().update(executionEntity, false);
// All child executions are suspended
Collection<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity childExecution : childExecutions) {
if (!childExecution.getId().equals(processInstanceId)) {
SuspensionStateUtil.setSuspensionState(childExecution, getNewState());
commandContext.getExecutionEntityManager().update(childExecution, false);
}
}
// All tasks are suspended
List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(processInstanceId);
for (TaskEntity taskEntity : tasks) {
SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
commandContext.getTaskEntityManager().update(taskEntity, false);
}
// All jobs are suspended
if (getNewState() == SuspensionState.ACTIVE) {
List<SuspendedJobEntity> suspendedJobs = commandContext.getSuspendedJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (SuspendedJobEntity suspendedJob : suspendedJobs) {
commandContext.getJobManager().activateSuspendedJob(suspendedJob);
}
} else {
List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (TimerJobEntity timerJob : timerJobs) {
commandContext.getJobManager().moveJobToSuspendedJob(timerJob);
}
List<JobEntity> jobs = commandContext.getJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (JobEntity job : jobs) {
commandContext.getJobManager().moveJobToSuspendedJob(job);
}
}
return null;
}
use of org.activiti.engine.impl.persistence.entity.SuspendedJobEntity in project Activiti by Activiti.
the class DefaultJobManager method activateSuspendedJob.
@Override
public AbstractJobEntity activateSuspendedJob(SuspendedJobEntity job) {
AbstractJobEntity activatedJob = null;
if (Job.JOB_TYPE_TIMER.equals(job.getJobType())) {
activatedJob = createTimerJobFromOtherJob(job);
processEngineConfiguration.getTimerJobEntityManager().insert((TimerJobEntity) activatedJob);
} else {
activatedJob = createExecutableJobFromOtherJob(job);
JobEntity jobEntity = (JobEntity) activatedJob;
processEngineConfiguration.getJobEntityManager().insert(jobEntity);
triggerExecutorIfNeeded(jobEntity);
}
processEngineConfiguration.getSuspendedJobEntityManager().delete(job);
return activatedJob;
}
use of org.activiti.engine.impl.persistence.entity.SuspendedJobEntity in project Activiti by Activiti.
the class DefaultJobManager method moveJobToTimerJob.
@Override
public TimerJobEntity moveJobToTimerJob(AbstractJobEntity job) {
TimerJobEntity timerJob = createTimerJobFromOtherJob(job);
boolean insertSuccesful = processEngineConfiguration.getTimerJobEntityManager().insertTimerJobEntity(timerJob);
if (insertSuccesful) {
if (job instanceof JobEntity) {
processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
} else if (job instanceof SuspendedJobEntity) {
processEngineConfiguration.getSuspendedJobEntityManager().delete((SuspendedJobEntity) job);
}
return timerJob;
}
return null;
}
use of org.activiti.engine.impl.persistence.entity.SuspendedJobEntity in project Activiti by Activiti.
the class DefaultJobManager method moveJobToSuspendedJob.
@Override
public SuspendedJobEntity moveJobToSuspendedJob(AbstractJobEntity job) {
SuspendedJobEntity suspendedJob = createSuspendedJobFromOtherJob(job);
processEngineConfiguration.getSuspendedJobEntityManager().insert(suspendedJob);
if (job instanceof TimerJobEntity) {
processEngineConfiguration.getTimerJobEntityManager().delete((TimerJobEntity) job);
} else if (job instanceof JobEntity) {
processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
}
return suspendedJob;
}
use of org.activiti.engine.impl.persistence.entity.SuspendedJobEntity in project Activiti by Activiti.
the class DestroyScopeOperation method deleteAllScopeJobs.
private void deleteAllScopeJobs(ExecutionEntity scopeExecution, TimerJobEntityManager timerJobEntityManager) {
Collection<TimerJobEntity> timerJobsForExecution = timerJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (TimerJobEntity job : timerJobsForExecution) {
timerJobEntityManager.delete(job);
}
JobEntityManager jobEntityManager = commandContext.getJobEntityManager();
Collection<JobEntity> jobsForExecution = jobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (JobEntity job : jobsForExecution) {
jobEntityManager.delete(job);
}
SuspendedJobEntityManager suspendedJobEntityManager = commandContext.getSuspendedJobEntityManager();
Collection<SuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (SuspendedJobEntity job : suspendedJobsForExecution) {
suspendedJobEntityManager.delete(job);
}
DeadLetterJobEntityManager deadLetterJobEntityManager = commandContext.getDeadLetterJobEntityManager();
Collection<DeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (DeadLetterJobEntity job : deadLetterJobsForExecution) {
deadLetterJobEntityManager.delete(job);
}
}
Aggregations