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

The following examples show how to use org.activiti.engine.task.Task#setDueDate() . 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: AbstractTaskResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public TaskRepresentation updateTask(String taskId, TaskUpdateRepresentation updated) {
  Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

  if (task == null) {
    throw new NotFoundException("Task with id: " + taskId + " does not exist");
  }

  permissionService.validateReadPermissionOnTask(SecurityUtils.getCurrentUserObject(), task.getId());

  if (updated.isNameSet()) {
    task.setName(updated.getName());
  }

  if (updated.isDescriptionSet()) {
    task.setDescription(updated.getDescription());
  }

  if (updated.isDueDateSet()) {
    task.setDueDate(updated.getDueDate());
  }

  taskService.saveTask(task);

  return new TaskRepresentation(task);
}
 
Example 2
Source File: HistoricTaskAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testWithoutDueDateQuery() throws Exception {
  if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().singleResult();
    assertNotNull(historicTask);
    assertNull(historicTask.getDueDate());
    
    // Set due-date on task
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
    task.setDueDate(dueDate);
    taskService.saveTask(task);

    assertEquals(0, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
    
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    
    // Clear due-date on task
    task.setDueDate(null);
    taskService.saveTask(task);
    
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
  }
}
 
Example 3
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskWithoutDueDate() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().singleResult();
  
  // Set due-date on task
  Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  
  // Clear due-date on task
  task.setDueDate(null);
  taskService.saveTask(task);
  
  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
}
 
Example 4
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueDateOr() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // Set due-date on task
  Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueDate(dueDate).count());

  Calendar otherDate = Calendar.getInstance();
  otherDate.add(Calendar.YEAR, 1);
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueDate(otherDate.getTime()).count());

  Calendar priorDate = Calendar.getInstance();
  priorDate.setTime(dueDate);
  priorDate.roll(Calendar.YEAR, -1);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(priorDate.getTime()).count());

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(otherDate.getTime()).count());
}
 
Example 5
Source File: HistoricTaskAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testWithoutDueDateQuery() throws Exception {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().singleResult();
    assertNotNull(historicTask);
    assertNull(historicTask.getDueDate());

    // Set due-date on task
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
    task.setDueDate(dueDate);
    taskService.saveTask(task);

    assertEquals(0, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());

    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    // Clear due-date on task
    task.setDueDate(null);
    taskService.saveTask(task);

    assertEquals(1, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
  }
}
 
Example 6
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskWithoutDueDate() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().singleResult();

  // Set due-date on task
  Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());

  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // Clear due-date on task
  task.setDueDate(null);
  taskService.saveTask(task);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
}
 
Example 7
Source File: TaskInfoQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Task createTask(String name, Date dueDate) {
	Task task = taskService.newTask();
	task.setName(name);
	task.setDueDate(dueDate);
	taskService.saveTask(task);
	return task;
}
 
Example 8
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueBefore() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  
  // Set due-date on task
  Calendar dueDateCal = Calendar.getInstance();
  task.setDueDate(dueDateCal.getTime());
  taskService.saveTask(task);
  
  Calendar oneHourAgo = Calendar.getInstance();
  oneHourAgo.setTime(dueDateCal.getTime());
  oneHourAgo.add(Calendar.HOUR, -1);
  
  Calendar oneHourLater = Calendar.getInstance();
  oneHourLater.setTime(dueDateCal.getTime());
  oneHourLater.add(Calendar.HOUR, 1);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(oneHourAgo.getTime()).count());
  
  // Update due-date to null, shouldn't show up anymore in query that matched before
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  task.setDueDate(null);
  taskService.saveTask(task);
  
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(oneHourAgo.getTime()).count());
}
 
Example 9
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 10
Source File: TaskDueDateTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Task createTask(String name, Date dueDate) {
  Task task = taskService.newTask();
  task.setName(name);
  task.setDueDate(dueDate);
  taskService.saveTask(task);
  return task;
}
 
Example 11
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 12
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueAfterOn() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // Set due-date on task
  Calendar dueDateCal = Calendar.getInstance();
  task.setDueDate(dueDateCal.getTime());
  taskService.saveTask(task);

  Calendar oneHourAgo = Calendar.getInstance();
  oneHourAgo.setTime(dueDateCal.getTime());
  oneHourAgo.add(Calendar.HOUR, -1);

  Calendar oneHourLater = Calendar.getInstance();
  oneHourLater.setTime(dueDateCal.getTime());
  oneHourLater.add(Calendar.HOUR, 1);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourAgo.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourLater.getTime()).count());

  // Update due-date to null, shouldn't show up anymore in query that
  // matched before
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  task.setDueDate(null);
  taskService.saveTask(task);

  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourAgo.getTime()).count());
}
 
Example 13
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 14
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueBeforeOr() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // Set due-date on task
  Calendar dueDateCal = Calendar.getInstance();
  task.setDueDate(dueDateCal.getTime());
  taskService.saveTask(task);

  Calendar oneHourAgo = Calendar.getInstance();
  oneHourAgo.setTime(dueDateCal.getTime());
  oneHourAgo.add(Calendar.HOUR, -1);

  Calendar oneHourLater = Calendar.getInstance();
  oneHourLater.setTime(dueDateCal.getTime());
  oneHourLater.add(Calendar.HOUR, 1);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueBefore(oneHourAgo.getTime()).count());

  // Update due-date to null, shouldn't show up anymore in query that
  // matched before
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  task.setDueDate(null);
  taskService.saveTask(task);

  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueBefore(oneHourAgo.getTime()).count());
}
 
Example 15
Source File: TaskDueDateTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Task createTask(String name, Date dueDate) {
	Task task = taskService.newTask();
	task.setName(name);
	task.setDueDate(dueDate);
	taskService.saveTask(task);
	return task;
}
 
Example 16
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueAfterOn() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  
  // Set due-date on task
  Calendar dueDateCal = Calendar.getInstance();
  task.setDueDate(dueDateCal.getTime());
  taskService.saveTask(task);
  
  Calendar oneHourAgo = Calendar.getInstance();
  oneHourAgo.setTime(dueDateCal.getTime());
  oneHourAgo.add(Calendar.HOUR, -1);
  
  Calendar oneHourLater = Calendar.getInstance();
  oneHourLater.setTime(dueDateCal.getTime());
  oneHourLater.add(Calendar.HOUR, 1);
  
  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueAfter(oneHourAgo.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueAfter(oneHourLater.getTime()).count());
  
  // Update due-date to null, shouldn't show up anymore in query that matched before
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  task.setDueDate(null);
  taskService.saveTask(task);
  
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueAfter(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueAfter(oneHourAgo.getTime()).count());
}
 
Example 17
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueBeforeOr() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  
  // Set due-date on task
  Calendar dueDateCal = Calendar.getInstance();
  task.setDueDate(dueDateCal.getTime());
  taskService.saveTask(task);
  
  Calendar oneHourAgo = Calendar.getInstance();
  oneHourAgo.setTime(dueDateCal.getTime());
  oneHourAgo.add(Calendar.HOUR, -1);
  
  Calendar oneHourLater = Calendar.getInstance();
  oneHourLater.setTime(dueDateCal.getTime());
  oneHourLater.add(Calendar.HOUR, 1);
  
  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueBefore(oneHourAgo.getTime()).count());
  
  // Update due-date to null, shouldn't show up anymore in query that matched before
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  task.setDueDate(null);
  taskService.saveTask(task);
  
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .or()
      .taskId("invalid")
      .taskDueBefore(oneHourAgo.getTime()).count());
}
 
Example 18
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 19
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());
  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());
}
 
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);
  }