Java Code Examples for org.activiti.engine.task.Task#setPriority()

The following examples show how to use org.activiti.engine.task.Task#setPriority() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandaloneTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testRevisionUpdatedOnSaveWhenFetchedUsingQuery() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  assertEquals(1, ((TaskEntity) task).getRevision());

  task.setAssignee("kermit");
  taskService.saveTask(task);
  assertEquals(2, ((TaskEntity) task).getRevision());

  // Now fetch the task through the query api
  task = taskService.createTaskQuery().singleResult();
  assertEquals(2, ((TaskEntity) task).getRevision());
  task.setPriority(1);
  taskService.saveTask(task);

  assertEquals(3, ((TaskEntity) task).getRevision());

  taskService.deleteTask(task.getId(), true);
}
 
Example 2
Source File: TaskAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generates 100 test tasks.
 */
private List<String> generateMultipleTestTasks() throws Exception {
  List<String> ids = new ArrayList<String>();
  
  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
  processEngineConfiguration.getClock().setCurrentTime(sdf.parse("01/01/2001 01:01:01.000"));
  for (int i = 0; i < 100; i++) {
    Task task = taskService.newTask();
    task.setName("testTask");
    task.setDescription("testTask description");
    task.setPriority(3);
    taskService.saveTask(task);
    ids.add(task.getId());
    taskService.setVariableLocal(task.getId(), "test", "test");
    taskService.setVariableLocal(task.getId(), "testBinary", "This is a binary variable".getBytes());
    taskService.addCandidateUser(task.getId(), "kermit");
  }
  return ids;
}
 
Example 3
Source File: StandaloneTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testRevisionUpdatedOnSaveWhenFetchedUsingQuery() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  assertEquals(1, ((TaskEntity) task).getRevision());
  
  task.setAssignee("kermit");
  taskService.saveTask(task);
  assertEquals(2, ((TaskEntity) task).getRevision());
  
  // Now fetch the task through the query api
  task = taskService.createTaskQuery().singleResult();
  assertEquals(2, ((TaskEntity) task).getRevision());
  task.setPriority(1);
  taskService.saveTask(task);
  
  assertEquals(3, ((TaskEntity) task).getRevision());
  
  taskService.deleteTask(task.getId(), true);
}
 
Example 4
Source File: TaskAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generates 100 test tasks.
 */
private List<String> generateMultipleTestTasks() throws Exception {
  List<String> ids = new ArrayList<String>();
  
  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
  processEngineConfiguration.getClock().setCurrentTime(sdf.parse("01/01/2001 01:01:01.000"));
  for (int i = 0; i < 100; i++) {
    Task task = taskService.newTask();
    task.setName("testTask");
    task.setDescription("testTask description");
    task.setPriority(3);
    taskService.saveTask(task);
    ids.add(task.getId());
    taskService.setVariableLocal(task.getId(), "test", "test");
    taskService.setVariableLocal(task.getId(), "testBinary", "This is a binary variable".getBytes());
    taskService.addCandidateUser(task.getId(), "kermit");
  }
  return ids;
}
 
Example 5
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByCandidateOrAssigned() {
  TaskQuery query = taskService.createTaskQuery().taskCandidateOrAssigned("kermit");
  assertEquals(11, query.count());
  List<Task> tasks = query.list();
  assertEquals(11, tasks.size());

  // if dbIdentityUsed set false in process engine configuration of using
  // custom session factory of GroupIdentityManager
  ArrayList<String> candidateGroups = new ArrayList<String>();
  candidateGroups.add("management");
  candidateGroups.add("accountancy");
  candidateGroups.add("noexist");
  query = taskService.createTaskQuery().taskCandidateGroupIn(candidateGroups).taskCandidateOrAssigned("kermit");
  assertEquals(11, query.count());
  tasks = query.list();
  assertEquals(11, tasks.size());

  query = taskService.createTaskQuery().taskCandidateOrAssigned("fozzie");
  assertEquals(3, query.count());
  assertEquals(3, query.list().size());

  // create a new task that no identity link and assignee to kermit
  Task task = taskService.newTask();
  task.setName("assigneeToKermit");
  task.setDescription("testTask description");
  task.setPriority(3);
  task.setAssignee("kermit");
  taskService.saveTask(task);

  query = taskService.createTaskQuery().taskCandidateOrAssigned("kermit");
  assertEquals(12, query.count());
  tasks = query.list();
  assertEquals(12, tasks.size());

  Task assigneeToKermit = taskService.createTaskQuery().taskName("assigneeToKermit").singleResult();
  taskService.deleteTask(assigneeToKermit.getId());
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    historyService.deleteHistoricTaskInstance(assigneeToKermit.getId());
  }
}
 
Example 6
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByCandidateOrAssignedOr() {
  TaskQuery query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateOrAssigned("kermit");
  assertEquals(11, query.count());
  List<Task> tasks = query.list();
  assertEquals(11, tasks.size());

  // if dbIdentityUsed set false in process engine configuration of using
  // custom session factory of GroupIdentityManager
  ArrayList<String> candidateGroups = new ArrayList<String>();
  candidateGroups.add("management");
  candidateGroups.add("accountancy");
  candidateGroups.add("noexist");
  query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateGroupIn(candidateGroups).taskCandidateOrAssigned("kermit");
  assertEquals(11, query.count());
  tasks = query.list();
  assertEquals(11, tasks.size());

  query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateOrAssigned("fozzie");
  assertEquals(3, query.count());
  assertEquals(3, query.list().size());

  // create a new task that no identity link and assignee to kermit
  Task task = taskService.newTask();
  task.setName("assigneeToKermit");
  task.setDescription("testTask description");
  task.setPriority(3);
  task.setAssignee("kermit");
  taskService.saveTask(task);

  query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateOrAssigned("kermit");
  assertEquals(12, query.count());
  tasks = query.list();
  assertEquals(12, tasks.size());

  Task assigneeToKermit = taskService.createTaskQuery().or().taskId("invalid").taskName("assigneeToKermit").singleResult();
  taskService.deleteTask(assigneeToKermit.getId());
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    historyService.deleteHistoricTaskInstance(assigneeToKermit.getId());
  }
}
 
Example 7
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 更改任务属性
 *
 * @throws ParseException
 */
@RequestMapping("task/property/{taskId}")
@ResponseBody
public String changeTaskProperty(@PathVariable("taskId") String taskId, @RequestParam("propertyName") String propertyName, @RequestParam("value") String value)
        throws ParseException {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    // 更改到期日
    if (StringUtils.equals(propertyName, "dueDate")) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(value);
        task.setDueDate(parse);
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "priority")) {
        // 更改任务优先级
        task.setPriority(Integer.parseInt(value));
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "owner")) {
        // 更改拥有人
        task.setOwner(value);
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "assignee")) {
        // 更改办理人
        task.setAssignee(value);
        taskService.saveTask(task);
    } else {
        return "不支持[" + propertyName + "]属性!";
    }
    return "success";
}
 
Example 8
Source File: TaskBaseResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the task based on the values that are present in the given {@link TaskRequest}.
 */
protected void populateTaskFromRequest(Task task, TaskRequest taskRequest) {
  if (taskRequest.isNameSet()) {
    task.setName(taskRequest.getName());
  }
  if (taskRequest.isAssigneeSet()) {
    task.setAssignee(taskRequest.getAssignee());
  }
  if (taskRequest.isDescriptionSet()) {
    task.setDescription(taskRequest.getDescription());
  }
  if (taskRequest.isDuedateSet()) {
    task.setDueDate(taskRequest.getDueDate());
  }
  if (taskRequest.isOwnerSet()) {
    task.setOwner(taskRequest.getOwner());
  }
  if (taskRequest.isParentTaskIdSet()) {
    task.setParentTaskId(taskRequest.getParentTaskId());
  }
  if (taskRequest.isPrioritySet()) {
    task.setPriority(taskRequest.getPriority());
  }
  if (taskRequest.isCategorySet()) {
    task.setCategory(taskRequest.getCategory());
  }
  if (taskRequest.isTenantIdSet()) {
    task.setTenantId(taskRequest.getTenantId());
  }
  if (taskRequest.isFormKeySet()) {
    task.setFormKey(taskRequest.getFormKey());
  }

  if (taskRequest.isDelegationStateSet()) {
    DelegationState delegationState = getDelegationState(taskRequest.getDelegationState());
    task.setDelegationState(delegationState);
  }
}
 
Example 9
Source File: ActivitiTestBase.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
protected Task addTask(String name, int priority) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.newTask();
    task.setName(name);
    task.setPriority(priority);
    task.setAssignee("john");
    task.setCategory("testCategory");
    task.setDueDate(new Date());
    task.setOwner("jane");
    task.setDescription("testDescription");
    task.setTenantId("testTenant");
    taskService.saveTask(task);
    return task;

}
 
Example 10
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 更改任务属性
 *
 * @throws ParseException
 */
@RequestMapping("task/property/{taskId}")
@ResponseBody
public String changeTaskProperty(@PathVariable("taskId") String taskId, @RequestParam("propertyName") String propertyName, @RequestParam("value") String value)
        throws ParseException {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    // 更改到期日
    if (StringUtils.equals(propertyName, "dueDate")) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(value);
        task.setDueDate(parse);
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "priority")) {
        // 更改任务优先级
        task.setPriority(Integer.parseInt(value));
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "owner")) {
        // 更改拥有人
        task.setOwner(value);
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "assignee")) {
        // 更改办理人
        task.setAssignee(value);
        taskService.saveTask(task);
    } else {
        return "不支持[" + propertyName + "]属性!";
    }
    return "success";
}
 
Example 11
Source File: ActivitiPriorityPropertyHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* {@inheritDoc}
*/

@Override
protected Object handleTaskProperty(Task task, TypeDefinition type, QName key, Serializable value)
{
    int priority;
    // ACE-3121: Workflow Admin Console: Cannot change priority for activiti
    // It could be a String that converts to an int, like when coming from WorkflowInterpreter.java
    if (value instanceof String)
    {
        try
        {
            priority = Integer.parseInt((String) value);
        }
        catch (NumberFormatException e)
        {
            throw getInvalidPropertyValueException(key, value);
        }
    }
    else
    {
        checkType(key, value, Integer.class);
        priority = (Integer) value;
    }

    // Priority value validation not performed to allow for future model changes
    task.setPriority(priority);

    return DO_NOT_ADD;
}
 
Example 12
Source File: CustomMybatisXMLMapperTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String createTask(String name, String owner, String assignee, int priority){
  Task task = taskService.newTask();
  task.setName(name);
  task.setOwner(owner);
  task.setAssignee(assignee);
  task.setPriority(priority);
  taskService.saveTask(task);
  return task.getId();
}
 
Example 13
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 更改任务属性
 *
 * @throws ParseException
 */
@RequestMapping("task/property/{taskId}")
@ResponseBody
public String changeTaskProperty(@PathVariable("taskId") String taskId, @RequestParam("propertyName") String propertyName, @RequestParam("value") String value)
        throws ParseException {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    // 更改到期日
    if (StringUtils.equals(propertyName, "dueDate")) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(value);
        task.setDueDate(parse);
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "priority")) {
        // 更改任务优先级
        task.setPriority(Integer.parseInt(value));
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "owner")) {
        // 更改拥有人
        task.setOwner(value);
        taskService.saveTask(task);
    } else if (StringUtils.equals(propertyName, "assignee")) {
        // 更改办理人
        task.setAssignee(value);
        taskService.saveTask(task);
    } else {
        return "不支持[" + propertyName + "]属性!";
    }
    return "success";
}
 
Example 14
Source File: HistoricTaskInstanceUpdateTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testHistoricTaskInstanceUpdate() {
  runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").getId();
  
  Task task = taskService.createTaskQuery().singleResult();
  
  // Update and save the task's fields before it is finished
  task.setPriority(12345);
  task.setDescription("Updated description");
  task.setName("Updated name");
  task.setAssignee("gonzo");
  taskService.saveTask(task);   

  taskService.complete(task.getId());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());

  HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals("Updated name", historicTaskInstance.getName());
  assertEquals("Updated description", historicTaskInstance.getDescription());
  assertEquals("gonzo", historicTaskInstance.getAssignee());
  assertEquals("task", historicTaskInstance.getTaskDefinitionKey());

  
  // Validate fix of ACT-1923: updating assignee to null should be reflected in history
  ProcessInstance secondInstance = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest");
  
  task = taskService.createTaskQuery().singleResult();
  
  task.setDescription(null);
  task.setName(null);
  task.setAssignee(null);
  taskService.saveTask(task);   

  taskService.complete(task.getId());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().processInstanceId(secondInstance.getId()).count());

  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(secondInstance.getId()).singleResult();
  assertNull(historicTaskInstance.getName());
  assertNull(historicTaskInstance.getDescription());
  assertNull(historicTaskInstance.getAssignee());
}
 
Example 15
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupAndUser() {
    try {
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("kermit");
        adhocTask.setOwner("involvedUser");
        adhocTask.setPriority(10);
        taskService.saveTask(adhocTask);
        taskService.addGroupIdentityLink(adhocTask.getId(), "group1", IdentityLinkType.PARTICIPANT);



        List<String> groups = new ArrayList<String>();
        groups.add("group2");

        assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
        assertEquals(0, taskService.createTaskQuery()

                .taskInvolvedUser("involvedUser")
                .taskInvolvedGroupsIn(groups)

                .count());

        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            assertEquals(0, historyService.createHistoricTaskInstanceQuery()

                    .taskInvolvedUser("involvedUser")
                    .taskInvolvedGroupsIn(groups)

                    .count());
        }

    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 16
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryMultipleAndAndSingleOr() {
    try {
        Task taskUser1Group1 = taskService.newTask();
        taskUser1Group1.setAssignee("kermit");
        taskUser1Group1.setOwner("user1");
        taskUser1Group1.setPriority(10);
        taskService.saveTask(taskUser1Group1);
        taskService.addGroupIdentityLink(taskUser1Group1.getId(), "group1", IdentityLinkType.PARTICIPANT);

        Task taskUser1Group2 = taskService.newTask();
        taskUser1Group2.setAssignee("kermit");
        taskUser1Group2.setOwner("user1");
        taskUser1Group2.setPriority(10);
        taskService.saveTask(taskUser1Group2);
        taskService.addGroupIdentityLink(taskUser1Group2.getId(), "group2", IdentityLinkType.PARTICIPANT);

        Task taskUser1Group1and2 = taskService.newTask();
        taskUser1Group1and2.setAssignee("kermit");
        taskUser1Group1and2.setOwner("user1");
        taskUser1Group1and2.setPriority(10);
        taskService.saveTask(taskUser1Group1and2);
        taskService.addGroupIdentityLink(taskUser1Group2.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addGroupIdentityLink(taskUser1Group2.getId(), "group2", IdentityLinkType.PARTICIPANT);


        Task taskUser1Group1and3 = taskService.newTask();
        taskUser1Group1and3.setAssignee("kermit");
        taskUser1Group1and3.setOwner("user1");
        taskUser1Group1and3.setPriority(10);
        taskService.saveTask(taskUser1Group1and3);
        taskService.addGroupIdentityLink(taskUser1Group1and3.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addGroupIdentityLink(taskUser1Group1and3.getId(), "group3", IdentityLinkType.PARTICIPANT);


        Task taskUser1Group1and4 = taskService.newTask();
        taskUser1Group1and4.setAssignee("kermit");
        taskUser1Group1and4.setOwner("user1");
        taskUser1Group1and4.setPriority(10);
        taskService.saveTask(taskUser1Group1and4);
        taskService.addGroupIdentityLink(taskUser1Group1and4.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addGroupIdentityLink(taskUser1Group1and4.getId(), "group4", IdentityLinkType.PARTICIPANT);



        List<String> andGroup = new ArrayList<String>();
        andGroup.add("group1");

        List<String> orGroup = new ArrayList<String>();
        orGroup.add("group2");
        orGroup.add("group4");

        assertEquals(2, taskService.createTaskQuery()

                .taskInvolvedUser("user1")
                .taskInvolvedGroupsIn(andGroup)

                .or().taskInvolvedGroupsIn(orGroup).endOr()

                .count());



    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 17
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testSaveTaskUpdate() throws Exception {

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    Task task = taskService.newTask();
    task.setDescription("description");
    task.setName("taskname");
    task.setPriority(0);
    task.setAssignee("taskassignee");
    task.setOwner("taskowner");
    Date dueDate = sdf.parse("01/02/2003 04:05:06");
    task.setDueDate(dueDate);
    taskService.saveTask(task);

    // Fetch the task again and update
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("description", task.getDescription());
    assertEquals("taskname", task.getName());
    assertEquals("taskassignee", task.getAssignee());
    assertEquals("taskowner", task.getOwner());
    assertEquals(dueDate, task.getDueDate());
    assertEquals(0, task.getPriority());

    task.setName("updatedtaskname");
    task.setDescription("updateddescription");
    task.setPriority(1);
    task.setAssignee("updatedassignee");
    task.setOwner("updatedowner");
    dueDate = sdf.parse("01/02/2003 04:05:06");
    task.setDueDate(dueDate);
    taskService.saveTask(task);

    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("updatedtaskname", task.getName());
    assertEquals("updateddescription", task.getDescription());
    assertEquals("updatedassignee", task.getAssignee());
    assertEquals("updatedowner", task.getOwner());
    assertEquals(dueDate, task.getDueDate());
    assertEquals(1, task.getPriority());

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
      HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
      assertEquals("updatedtaskname", historicTaskInstance.getName());
      assertEquals("updateddescription", historicTaskInstance.getDescription());
      assertEquals("updatedassignee", historicTaskInstance.getAssignee());
      assertEquals("updatedowner", historicTaskInstance.getOwner());
      assertEquals(dueDate, historicTaskInstance.getDueDate());
      assertEquals(1, historicTaskInstance.getPriority());
    }

    // Finally, delete task
    taskService.deleteTask(task.getId(), true);
  }
 
Example 18
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupOrUser() {
    try {
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("kermit");
        adhocTask.setOwner("involvedUser");
        adhocTask.setPriority(10);
        taskService.saveTask(adhocTask);
        taskService.addGroupIdentityLink(adhocTask.getId(), "group1", IdentityLinkType.PARTICIPANT);

        List<String> groups = new ArrayList<String>();
        groups.add("group1");

        assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
        assertEquals(1, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskInvolvedUser("involvedUser")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            assertEquals(1, historyService.createHistoricTaskInstanceQuery()
                    .or().taskCategory("j").taskPriority(10).endOr()
                    .or()
                    .taskInvolvedUser("involvedUser")
                    .taskInvolvedGroupsIn(groups)
                    .endOr()
                    .count());
        }
    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 19
Source File: HistoricTaskInstanceUpdateTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testHistoricTaskInstanceUpdate() {
  runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").getId();

  Task task = taskService.createTaskQuery().singleResult();

  // Update and save the task's fields before it is finished
  task.setPriority(12345);
  task.setDescription("Updated description");
  task.setName("Updated name");
  task.setAssignee("gonzo");
  taskService.saveTask(task);

  taskService.complete(task.getId());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());

  HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals("Updated name", historicTaskInstance.getName());
  assertEquals("Updated description", historicTaskInstance.getDescription());
  assertEquals("gonzo", historicTaskInstance.getAssignee());
  assertEquals("task", historicTaskInstance.getTaskDefinitionKey());

  // Validate fix of ACT-1923: updating assignee to null should be
  // reflected in history
  ProcessInstance secondInstance = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest");

  task = taskService.createTaskQuery().singleResult();

  task.setDescription(null);
  task.setName(null);
  task.setAssignee(null);
  taskService.saveTask(task);

  taskService.complete(task.getId());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().processInstanceId(secondInstance.getId()).count());

  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(secondInstance.getId()).singleResult();
  assertNull(historicTaskInstance.getName());
  assertNull(historicTaskInstance.getDescription());
  assertNull(historicTaskInstance.getAssignee());
}
 
Example 20
Source File: HistoricTaskInstanceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testHistoricTaskInstance() throws Exception {
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("formKeyVar", "expressionFormKey");
  String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest", varMap).getId();

  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

  // Set priority to non-default value
  Task runtimeTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
  runtimeTask.setPriority(1234);

  // Set due-date
  Date dueDate = sdf.parse("01/02/2003 04:05:06");
  runtimeTask.setDueDate(dueDate);
  taskService.saveTask(runtimeTask);

  String taskId = runtimeTask.getId();
  String taskDefinitionKey = runtimeTask.getTaskDefinitionKey();

  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
  HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals(taskId, historicTaskInstance.getId());
  assertEquals(1234, historicTaskInstance.getPriority());
  assertEquals("Clean up", historicTaskInstance.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
  assertEquals(dueDate, historicTaskInstance.getDueDate());
  assertEquals("kermit", historicTaskInstance.getAssignee());
  assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  assertNull(historicTaskInstance.getEndTime());
  assertNull(historicTaskInstance.getDurationInMillis());
  assertNull(historicTaskInstance.getWorkTimeInMillis());

  runtimeService.setVariable(processInstanceId, "deadline", "yesterday");

  taskService.claim(taskId, "kermit");

  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertNotNull(historicTaskInstance.getClaimTime());
  assertNull(historicTaskInstance.getWorkTimeInMillis());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());

  taskService.complete(taskId);

  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());

  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals(taskId, historicTaskInstance.getId());
  assertEquals(1234, historicTaskInstance.getPriority());
  assertEquals("Clean up", historicTaskInstance.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
  assertEquals(dueDate, historicTaskInstance.getDueDate());
  assertEquals("kermit", historicTaskInstance.getAssignee());
  assertNull(historicTaskInstance.getDeleteReason());
  assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  assertNotNull(historicTaskInstance.getEndTime());
  assertNotNull(historicTaskInstance.getDurationInMillis());
  assertNotNull(historicTaskInstance.getClaimTime());
  assertNotNull(historicTaskInstance.getWorkTimeInMillis());

  historyService.deleteHistoricTaskInstance(taskId);

  assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
}