Search in sources :

Example 86 with Task

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);
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 87 with Task

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();
}
Also used : Task(org.activiti.engine.task.Task) Random(java.util.Random) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 88 with Task

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());
}
Also used : Task(org.activiti.engine.task.Task) TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 89 with Task

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());
}
Also used : Task(org.activiti.engine.task.Task) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 90 with Task

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());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Test(org.junit.Test)

Aggregations

Task (org.activiti.engine.task.Task)955 Deployment (org.activiti.engine.test.Deployment)548 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)502 HashMap (java.util.HashMap)197 Test (org.junit.Test)123 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)109 ArrayList (java.util.ArrayList)74 Date (java.util.Date)65 Execution (org.activiti.engine.runtime.Execution)59 DelegateTask (org.activiti.engine.delegate.DelegateTask)54 TaskQuery (org.activiti.engine.task.TaskQuery)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 Job (org.activiti.engine.runtime.Job)49 Calendar (java.util.Calendar)44 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)44 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)44 JsonNode (com.fasterxml.jackson.databind.JsonNode)41 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)41 JSONObject (org.json.simple.JSONObject)40 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)38