use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class Photo method launchPhotoProcess.
public void launchPhotoProcess(String... photoLabels) {
List<Photo> photos = new ArrayList<Photo>();
for (String l : photoLabels) {
Photo x = this.photoRepository.save(new Photo(l));
photos.add(x);
}
Map<String, Object> procVars = new HashMap<String, Object>();
procVars.put("photos", photos);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dogeProcess", procVars);
List<Execution> waitingExecutions = runtimeService.createExecutionQuery().activityId("wait").list();
System.out.println("--> # executions = " + waitingExecutions.size());
for (Execution execution : waitingExecutions) {
runtimeService.signal(execution.getId());
}
Task reviewTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(reviewTask.getId(), Collections.singletonMap("approved", (Object) true));
long count = runtimeService.createProcessInstanceQuery().count();
System.out.println("Proc count " + count);
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class DemoDataConfiguration method generateReportData.
protected void generateReportData() {
// Report data is generated in background thread
Thread thread = new Thread(new Runnable() {
public void run() {
// We need to temporarily disable the job executor or it would interfere with the process execution
if (processEngineConfiguration.isAsyncExecutorEnabled() && processEngineConfiguration.getAsyncExecutor() != null) {
processEngineConfiguration.getAsyncExecutor().shutdown();
} else if (processEngineConfiguration.isAsyncExecutorEnabled() == false && processEngineConfiguration.getJobExecutor() != null) {
processEngineConfiguration.getJobExecutor().shutdown();
}
Random random = new Random();
Date now = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
processEngineConfiguration.getClock().setCurrentTime(now);
for (int i = 0; i < 50; i++) {
if (random.nextBoolean()) {
runtimeService.startProcessInstanceByKey("fixSystemFailure");
}
if (random.nextBoolean()) {
identityService.setAuthenticatedUserId("kermit");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("customerName", "testCustomer");
variables.put("details", "Looks very interesting!");
variables.put("notEnoughInformation", false);
runtimeService.startProcessInstanceByKey("reviewSaledLead", variables);
}
if (random.nextBoolean()) {
runtimeService.startProcessInstanceByKey("escalationExample");
}
if (random.nextInt(100) < 20) {
now = new Date(now.getTime() - ((24 * 60 * 60 * 1000) - (60 * 60 * 1000)));
processEngineConfiguration.getClock().setCurrentTime(now);
}
}
List<Job> jobs = managementService.createJobQuery().list();
for (int i = 0; i < jobs.size() / 2; i++) {
processEngineConfiguration.getClock().setCurrentTime(jobs.get(i).getDuedate());
managementService.executeJob(jobs.get(i).getId());
}
List<Task> tasks = taskService.createTaskQuery().list();
while (!tasks.isEmpty()) {
for (Task task : tasks) {
if (task.getAssignee() == null) {
String assignee = random.nextBoolean() ? "kermit" : "fozzie";
taskService.claim(task.getId(), assignee);
}
processEngineConfiguration.getClock().setCurrentTime(new Date(task.getCreateTime().getTime() + random.nextInt(60 * 60 * 1000)));
taskService.complete(task.getId());
}
tasks = taskService.createTaskQuery().list();
}
processEngineConfiguration.getClock().reset();
if (processEngineConfiguration.isAsyncExecutorEnabled() && processEngineConfiguration.getAsyncExecutor() != null) {
processEngineConfiguration.getAsyncExecutor().start();
} else if (processEngineConfiguration.isAsyncExecutorEnabled() == false && processEngineConfiguration.getJobExecutor() != null) {
processEngineConfiguration.getJobExecutor().start();
}
LOGGER.info("Demo report data generated");
}
});
thread.start();
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class WorkflowConversionTest method testThreeUserTasksInParallel.
@Test
public void testThreeUserTasksInParallel() throws Exception {
TaskService taskService = activitiRule.getTaskService();
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inParallel().inList().addHumanStep("first task", "kermit").endList().inList().addHumanStep("second step", "gonzo").endList().inList().addHumanStep("third task", "mispiggy").endList().endParallel().addHumanStep("Task in between", "kermit").inParallel().inList().addHumanStep("fourth task", "gonzo").endList().inList().addHumanStep("fifth step", "gonzo").endList().endParallel();
// Validate
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
// Complete tasks
for (Task task : taskService.createTaskQuery().list()) {
activitiRule.getTaskService().complete(task.getId());
}
// In between task should be active
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Task in between", task.getName());
taskService.complete(task.getId());
// There should be two task open now for gonzo
assertEquals(2, taskService.createTaskQuery().taskAssignee("gonzo").count());
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class WorkflowConversionTest method testFeedbackStepWithFixedUsersFeedbackHaltedByInitiator.
@Test
public void testFeedbackStepWithFixedUsersFeedbackHaltedByInitiator() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addFeedbackStep("Test feedback", "kermit", Arrays.asList("gonzo", "mispiggy", "fozzie"));
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
// First, a task should be assigned to kermit to select the people
assertEquals(1, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
// Four tasks should be available now
assertEquals(4, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("fozzie").count());
// Completing only one feedback task
for (Task feedbackTask : taskService.createTaskQuery().list()) {
if (!feedbackTask.getAssignee().equals("kermit")) {
activitiRule.getTaskService().complete(feedbackTask.getId());
break;
}
}
assertEquals(3, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
// Completing the 'gather feedback' task by kermit should cancel the remaining feedback tasks
activitiRule.getTaskService().complete(activitiRule.getTaskService().createTaskQuery().taskAssignee("kermit").singleResult().getId());
assertEquals(0, taskService.createTaskQuery().count());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class SpringJobExecutorTest method testHappyJobExecutorPath.
@Test
public void testHappyJobExecutorPath() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("process1");
assertNotNull(instance);
waitForTasksToExpire();
List<Task> activeTasks = taskService.createTaskQuery().processInstanceId(instance.getId()).list();
assertTrue(activeTasks.isEmpty());
}
Aggregations