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

The following examples show how to use org.activiti.engine.task.Task#setAssignee() . 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: TasksResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/rest/tasks", method = RequestMethod.POST)
public TaskRepresentation createNewTask(@RequestBody CreateTaskRepresentation taskRepresentation, HttpServletRequest request) {
  if (StringUtils.isEmpty(taskRepresentation.getName())) {
    throw new BadRequestException("Task name is required");
  }

  Task task = taskService.newTask();
  task.setName(taskRepresentation.getName());
  task.setDescription(taskRepresentation.getDescription());
  if (StringUtils.isNotEmpty(taskRepresentation.getCategory())) {
    task.setCategory(taskRepresentation.getCategory());
  }
  task.setAssignee(SecurityUtils.getCurrentUserId());
  taskService.saveTask(task);
  return new TaskRepresentation(taskService.createTaskQuery().taskId(task.getId()).singleResult());
}
 
Example 2
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 3
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 4
Source File: TaskRepresentation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void fillTask(Task task) {
  task.setName(name);
  task.setDescription(description);
  if (assignee != null && assignee.getId() != null) {
    task.setAssignee(String.valueOf(assignee.getId()));
  }
  task.setDueDate(dueDate);
  if (priority != null) {
    task.setPriority(priority);
  }
  task.setCategory(category);
}
 
Example 5
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testDeleteAssignee() {
  Task task = taskService.newTask();
  task.setAssignee("nonExistingUser");
  taskService.saveTask(task);

  taskService.deleteUserIdentityLink(task.getId(), "nonExistingUser", IdentityLinkType.ASSIGNEE);

  task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
  assertNull(task.getAssignee());
  assertEquals(0, taskService.getIdentityLinksForTask(task.getId()).size());
  
  // cleanup
  taskService.deleteTask(task.getId(), true);
}
 
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
/**
 * 添加子任务
 */
@RequestMapping("task/subtask/add/{taskId}")
public String addSubTask(@PathVariable("taskId") String parentTaskId, @RequestParam("taskName") String taskName,
                         @RequestParam(value = "description", required = false) String description, HttpSession session) {
    Task newTask = taskService.newTask();
    newTask.setParentTaskId(parentTaskId);
    String userId = UserUtil.getUserFromSession(session).getId();
    newTask.setOwner(userId);
    newTask.setAssignee(userId);
    newTask.setName(taskName);
    newTask.setDescription(description);

    taskService.saveTask(newTask);
    return "redirect:/chapter6/task/getform/" + parentTaskId;
}
 
Example 8
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 9
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 10
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 11
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private WorkflowTask endNormalTask(String taskId, String localTaskId, String transition)
{
    // Retrieve task
    Task task = taskService.createTaskQuery().taskId(localTaskId).singleResult();
    
    if(task == null)
    {
        String msg = messageService.getMessage(ERR_END_UNEXISTING_TASK, taskId);
        throw new WorkflowException(msg);
    }
    
    // Check if the assignee is equal to the current logged-in user. If not, assign task before ending
    String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
    if(task.getAssignee() == null || !task.getAssignee().equals(currentUserName)) {
        taskService.setAssignee(localTaskId, currentUserName);
        // Also update pojo used to set the outcome, this will read assignee as wel
        task.setAssignee(currentUserName);
        
        // Re-fetch the task-entity since it's revision has been updated by the setAssignee() call
        task = taskService.createTaskQuery().taskId(localTaskId).singleResult();
    }
    
    setOutcome(task, transition);
    taskService.complete(localTaskId);
    // The task should have a historicTaskInstance
    HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
    return typeConverter.convert(historicTask);
}
 
Example 12
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 添加子任务
 */
@RequestMapping("task/subtask/add/{taskId}")
public String addSubTask(@PathVariable("taskId") String parentTaskId, @RequestParam("taskName") String taskName,
                         @RequestParam(value = "description", required = false) String description, HttpSession session) {
    Task newTask = taskService.newTask();
    newTask.setParentTaskId(parentTaskId);
    String userId = UserUtil.getUserFromSession(session).getId();
    newTask.setOwner(userId);
    newTask.setAssignee(userId);
    newTask.setName(taskName);
    newTask.setDescription(description);

    taskService.saveTask(newTask);
    return "redirect:/chapter6/task/getform/" + parentTaskId;
}
 
Example 13
Source File: StandaloneTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricVariableOkOnUpdate() {
   if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
 		// 1. create a task
 		Task task = taskService.newTask();
 		task.setName("test execution");
 		task.setOwner("josOwner");
 		task.setAssignee("JosAssignee");
 		taskService.saveTask(task);
 		 
 		// 2. set task variables
 		Map<String, Object> taskVariables = new HashMap<String, Object>();
 		taskVariables.put("finishedAmount", 0);
 		taskService.setVariables(task.getId(), taskVariables);
 		 
 		// 3. complete this task with a new variable
 		Map<String, Object> finishVariables = new HashMap<String, Object>();
 		finishVariables.put("finishedAmount", 40);
 		taskService.complete(task.getId(), finishVariables);
 		 
 		// 4. get completed variable
 		List<HistoricVariableInstance> hisVarList = historyService.createHistoricVariableInstanceQuery().taskId(task.getId()).list();
 		assertEquals(1, hisVarList.size());
 		assertEquals(40, hisVarList.get(0).getValue());
 		
 		// Cleanup
 		historyService.deleteHistoricTaskInstance(task.getId());
   }
}
 
Example 14
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 15
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 16
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 17
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testTaskDelegation() {
  Task task = taskService.newTask();
  task.setOwner("johndoe");
  taskService.saveTask(task);
  taskService.delegateTask(task.getId(), "joesmoe");
  String taskId = task.getId();

  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("johndoe", task.getOwner());
  assertEquals("joesmoe", task.getAssignee());
  assertEquals(DelegationState.PENDING, task.getDelegationState());

  // try to complete (should fail)
  try {
    taskService.complete(task.getId());
    fail();
  } catch (ActivitiException e) {
  }

  taskService.resolveTask(taskId);
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("johndoe", task.getOwner());
  assertEquals("johndoe", task.getAssignee());
  assertEquals(DelegationState.RESOLVED, task.getDelegationState());

  task.setAssignee(null);
  task.setDelegationState(null);
  taskService.saveTask(task);
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("johndoe", task.getOwner());
  assertNull(task.getAssignee());
  assertNull(task.getDelegationState());

  task.setAssignee("jackblack");
  task.setDelegationState(DelegationState.RESOLVED);
  taskService.saveTask(task);
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("johndoe", task.getOwner());
  assertEquals("jackblack", task.getAssignee());
  assertEquals(DelegationState.RESOLVED, task.getDelegationState());

  // Finally, delete task
  taskService.deleteTask(taskId, true);
}
 
Example 18
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 19
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupOrUser2() {
    try {
        Task taskUser1WithGroups = taskService.newTask();
        taskUser1WithGroups.setAssignee("kermit");
        taskUser1WithGroups.setOwner("user1");
        taskUser1WithGroups.setPriority(10);
        taskService.saveTask(taskUser1WithGroups);
        taskService.addGroupIdentityLink(taskUser1WithGroups.getId(), "group1", IdentityLinkType.PARTICIPANT);


        Task taskUser1WithGroupsCandidateUser = taskService.newTask();
        taskUser1WithGroupsCandidateUser.setAssignee("kermit");
        taskUser1WithGroupsCandidateUser.setOwner("involvedUser");
        taskUser1WithGroupsCandidateUser.setPriority(10);
        taskService.saveTask(taskUser1WithGroupsCandidateUser);
        taskService.addGroupIdentityLink(taskUser1WithGroupsCandidateUser.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addCandidateUser(taskUser1WithGroupsCandidateUser.getId(), "candidateUser1");



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

        assertEquals(2, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskInvolvedUser("user1")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        assertEquals(2, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskCandidateUser("user1")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        assertEquals(2, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskCandidateGroup("group2")
                .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 20
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);
}