use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testJobsNotVisibleToAcquisitionIfInstanceSuspended.
@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisibleToAcquisitionIfInstanceSuspended() {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
ProcessInstance pi = runtimeService.startProcessInstanceByKey(pd.getKey());
// now there is one job:
Job job = managementService.createTimerJobQuery().singleResult();
assertThat(job).isNotNull();
makeSureJobDue(job);
// the acquirejobs command sees the job:
List<TimerJobEntity> acquiredJobs = executeAcquireJobsCommand();
assertThat(acquiredJobs).hasSize(1);
// suspend the process instance:
runtimeService.suspendProcessInstanceById(pi.getId());
// now, the acquirejobs command does not see the job:
acquiredJobs = executeAcquireJobsCommand();
assertThat(acquiredJobs).hasSize(0);
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testJobsNotVisibleToAcquisitionIfDefinitionSuspended.
@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisibleToAcquisitionIfDefinitionSuspended() {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(pd.getKey());
// now there is one job:
Job job = managementService.createTimerJobQuery().singleResult();
assertThat(job).isNotNull();
makeSureJobDue(job);
// the acquire jobs command sees the job:
List<TimerJobEntity> acquiredJobs = executeAcquireJobsCommand();
assertThat(acquiredJobs).hasSize(1);
// suspend the process instance:
repositoryService.suspendProcessDefinitionById(pd.getId(), true, null);
// now, the acquire jobs command does not see the job:
acquiredJobs = executeAcquireJobsCommand();
assertThat(acquiredJobs).hasSize(0);
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class JobExecutorTestCase method createTweetTimer.
protected TimerJobEntity createTweetTimer(String msg, Date duedate) {
TimerJobEntity timer = new TimerJobEntityImpl();
timer.setJobType(JobEntity.JOB_TYPE_TIMER);
timer.setJobHandlerType("tweet");
timer.setJobHandlerConfiguration(msg);
timer.setDuedate(duedate);
return timer;
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class TimerEventCompatibilityTest method changeConfigurationToPlainText.
protected void changeConfigurationToPlainText(TimerJobEntity job) {
String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
final TimerJobEntity finalJob = job;
CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
final String finalActivityId = activityId;
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession session = commandContext.getDbSqlSession();
session.delete(finalJob);
session.flush();
session.commit();
return null;
}
});
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession session = commandContext.getDbSqlSession();
finalJob.setJobHandlerConfiguration(finalActivityId);
finalJob.setId(null);
session.insert(finalJob);
session.flush();
session.commit();
return null;
}
});
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntity 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;
}
Aggregations