/**
   * Generates some test tasks. - 2 tasks where kermit is a candidate and 1 task where gonzo is
   * assignee
   */
  private List<String> generateTestTasks() throws Exception {
    List<String> ids = new ArrayList<String>();

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
    // 2 tasks for kermit
    ClockUtil.setCurrentTime(sdf.parse("01/01/2001 01:01:01.000"));
    for (int i = 0; i < 2; 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.addCandidateUser(task.getId(), "kermit");
    }

    ClockUtil.setCurrentTime(sdf.parse("02/02/2002 02:02:02.000"));
    // 1 task for gonzo
    Task task = taskService.newTask();
    task.setName("gonzoTask");
    task.setDescription("gonzo description");
    task.setPriority(4);
    taskService.saveTask(task);
    taskService.setAssignee(task.getId(), "gonzo");
    taskService.setVariableLocal(task.getId(), "testVar", "someVariable");
    taskService.setVariableLocal(task.getId(), "testVar2", 123);
    ids.add(task.getId());

    return ids;
  }
Esempio n. 2
0
  /**
   * Generates some test tasks. - 6 tasks where kermit is a candidate - 1 tasks where gonzo is
   * assignee - 2 tasks assigned to management group - 2 tasks assigned to accountancy group - 1
   * task assigned to both the management and accountancy group
   */
  private List<String> generateTestTasks() throws Exception {
    List<String> ids = new ArrayList<String>();

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
    // 6 tasks for kermit
    ClockUtil.setCurrentTime(sdf.parse("01/01/2001 01:01:01.000"));
    for (int i = 0; i < 6; i++) {
      Task task = taskService.newTask();
      task.setName("testTask");
      task.setDescription("testTask description");
      task.setPriority(3);
      taskService.saveTask(task);
      ids.add(task.getId());
      taskService.addCandidateUser(task.getId(), "kermit");
    }

    ClockUtil.setCurrentTime(sdf.parse("02/02/2002 02:02:02.000"));
    // 1 task for gonzo
    Task task = taskService.newTask();
    task.setName("gonzoTask");
    task.setDescription("gonzo description");
    task.setPriority(4);
    taskService.saveTask(task);
    taskService.setAssignee(task.getId(), "gonzo");
    taskService.setVariable(task.getId(), "testVar", "someVariable");
    ids.add(task.getId());

    ClockUtil.setCurrentTime(sdf.parse("03/03/2003 03:03:03.000"));
    // 2 tasks for management group
    for (int i = 0; i < 2; i++) {
      task = taskService.newTask();
      task.setName("managementTask");
      task.setPriority(10);
      taskService.saveTask(task);
      taskService.addCandidateGroup(task.getId(), "management");
      ids.add(task.getId());
    }

    ClockUtil.setCurrentTime(sdf.parse("04/04/2004 04:04:04.000"));
    // 2 tasks for accountancy group
    for (int i = 0; i < 2; i++) {
      task = taskService.newTask();
      task.setName("accountancyTask");
      task.setName("accountancy description");
      taskService.saveTask(task);
      taskService.addCandidateGroup(task.getId(), "accountancy");
      ids.add(task.getId());
    }

    ClockUtil.setCurrentTime(sdf.parse("05/05/2005 05:05:05.000"));
    // 1 task assigned to management and accountancy group
    task = taskService.newTask();
    task.setName("managementAndAccountancyTask");
    taskService.saveTask(task);
    taskService.addCandidateGroup(task.getId(), "management");
    taskService.addCandidateGroup(task.getId(), "accountancy");
    ids.add(task.getId());

    return ids;
  }
  protected void handleFormSubmit() {
    try {
      // Check for errors
      form.commit(); // will throw exception in case validation is false

      // Create task
      Task task = taskService.newTask();
      task.setName(nameField.getValue().toString());
      task.setDescription(descriptionArea.getValue().toString());
      task.setDueDate((Date) dueDateField.getValue());
      task.setPriority(priorityComboBox.getPriority());
      task.setOwner(ExplorerApp.get().getLoggedInUser().getId());
      taskService.saveTask(task);

      // close popup and navigate to new group
      close();
      ExplorerApp.get().getViewManager().showTasksPage(task.getId());

    } catch (InvalidValueException e) {
      // Do nothing: the Form component will render the errormsgs automatically
      setHeight(350, UNITS_PIXELS);
    }
  }
  @Deployment
  public void testHistoricTaskInstance() throws Exception {
    String processInstanceId =
        runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").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();

    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());
    assertNull(historicTaskInstance.getEndTime());
    assertNull(historicTaskInstance.getDurationInMillis());
    assertNull(historicTaskInstance.getWorkTimeInMillis());
    assertNull(historicTaskInstance.getDurationInMillis());

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

    taskService.claim(taskId, "kermit");
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());

    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertNotNull(historicTaskInstance.getClaimTime());
    assertNull(historicTaskInstance.getWorkTimeInMillis());

    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(TaskEntity.DELETE_REASON_COMPLETED, historicTaskInstance.getDeleteReason());
    assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
    assertNotNull(historicTaskInstance.getEndTime());
    assertNotNull(historicTaskInstance.getDurationInMillis());
    assertNotNull(historicTaskInstance.getClaimTime());
    assertNotNull(historicTaskInstance.getWorkTimeInMillis());

    historyService.deleteHistoricTaskInstance(taskId);

    assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
  }
  @Deployment
  public void testHistoricTaskInstanceQuery() throws Exception {
    // First instance is finished
    ProcessInstance finishedInstance =
        runtimeService.startProcessInstanceByKey("HistoricTaskQueryTest");

    // Set priority to non-default value
    Task task =
        taskService.createTaskQuery().processInstanceId(finishedInstance.getId()).singleResult();
    task.setPriority(1234);
    Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 04:05:06");
    task.setDueDate(dueDate);

    taskService.saveTask(task);

    // Complete the task
    String taskId = task.getId();
    taskService.complete(taskId);

    // Task id
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).count());
    assertEquals(
        0, historyService.createHistoricTaskInstanceQuery().taskId("unexistingtaskid").count());

    // Name
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskName("Clean up").count());
    assertEquals(
        0, historyService.createHistoricTaskInstanceQuery().taskName("unexistingname").count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskNameLike("Clean u%").count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskNameLike("%lean up").count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskNameLike("%lean u%").count());
    assertEquals(
        0,
        historyService.createHistoricTaskInstanceQuery().taskNameLike("%unexistingname%").count());

    // Description
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDescription("Historic task description")
            .count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDescription("unexistingdescription")
            .count());
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDescriptionLike("%task description")
            .count());
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDescriptionLike("Historic task %")
            .count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskDescriptionLike("%task%").count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDescriptionLike("%unexistingdescripton%")
            .count());

    // Execution id
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .executionId(finishedInstance.getId())
            .count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .executionId("unexistingexecution")
            .count());

    // Process instance id
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .processInstanceId(finishedInstance.getId())
            .count());
    assertEquals(
        0,
        historyService.createHistoricTaskInstanceQuery().processInstanceId("unexistingid").count());

    // Process definition id
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .processDefinitionId(finishedInstance.getProcessDefinitionId())
            .count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .processDefinitionId("unexistingdefinitionid")
            .count());

    // Process definition name
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .processDefinitionName("Historic task query test process")
            .count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .processDefinitionName("unexistingdefinitionname")
            .count());

    // Process definition key
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .processDefinitionKey("HistoricTaskQueryTest")
            .count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .processDefinitionKey("unexistingdefinitionkey")
            .count());

    // Assignee
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskAssignee("kermit").count());
    assertEquals(
        0, historyService.createHistoricTaskInstanceQuery().taskAssignee("johndoe").count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskAssigneeLike("%ermit").count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskAssigneeLike("kermi%").count());
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskAssigneeLike("%ermi%").count());
    assertEquals(
        0, historyService.createHistoricTaskInstanceQuery().taskAssigneeLike("%johndoe%").count());

    // Delete reason
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDeleteReason(TaskEntity.DELETE_REASON_COMPLETED)
            .count());
    assertEquals(
        0, historyService.createHistoricTaskInstanceQuery().taskDeleteReason("deleted").count());

    // Task definition ID
    assertEquals(
        1, historyService.createHistoricTaskInstanceQuery().taskDefinitionKey("task").count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDefinitionKey("unexistingkey")
            .count());

    // Task priority
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskPriority(1234).count());
    assertEquals(0, historyService.createHistoricTaskInstanceQuery().taskPriority(5678).count());

    // Due date
    Calendar anHourAgo = Calendar.getInstance();
    anHourAgo.setTime(dueDate);
    anHourAgo.add(Calendar.HOUR, -1);

    Calendar anHourLater = Calendar.getInstance();
    anHourLater.setTime(dueDate);
    anHourLater.add(Calendar.HOUR, 1);

    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskDueDate(dueDate).count());
    assertEquals(
        0,
        historyService.createHistoricTaskInstanceQuery().taskDueDate(anHourAgo.getTime()).count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDueDate(anHourLater.getTime())
            .count());

    // Due date before
    assertEquals(
        1,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDueBefore(anHourLater.getTime())
            .count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDueBefore(anHourAgo.getTime())
            .count());

    // Due date after
    assertEquals(
        1,
        historyService.createHistoricTaskInstanceQuery().taskDueAfter(anHourAgo.getTime()).count());
    assertEquals(
        0,
        historyService
            .createHistoricTaskInstanceQuery()
            .taskDueAfter(anHourLater.getTime())
            .count());

    // Finished and Unfinished - Add anther other instance that has a running task (unfinished)
    runtimeService.startProcessInstanceByKey("HistoricTaskQueryTest");

    assertEquals(1, historyService.createHistoricTaskInstanceQuery().finished().count());
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().unfinished().count());
  }