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

The following examples show how to use org.camunda.bpm.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: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueDate() 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().dueDate(dueDate).count());

  Calendar otherDate = Calendar.getInstance();
  otherDate.add(Calendar.YEAR, 1);
  assertEquals(0, taskService.createTaskQuery().dueDate(otherDate.getTime()).count());

  Calendar priorDate = Calendar.getInstance();
  priorDate.setTime(dueDate);
  priorDate.roll(Calendar.YEAR, -1);
  assertEquals(1, taskService.createTaskQuery().dueAfter(priorDate.getTime())
      .count());

  assertEquals(1, taskService.createTaskQuery()
      .dueBefore(otherDate.getTime()).count());
}
 
Example 2
Source File: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueDateCombinations() throws ParseException {
  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);

  Date oneHourAgo = new Date(dueDate.getTime() - 60 * 60 * 1000);
  Date oneHourLater = new Date(dueDate.getTime() + 60 * 60 * 1000);

  assertEquals(1, taskService.createTaskQuery()
      .dueAfter(oneHourAgo).dueDate(dueDate).dueBefore(oneHourLater).count());
  assertEquals(0, taskService.createTaskQuery()
      .dueAfter(oneHourLater).dueDate(dueDate).dueBefore(oneHourAgo).count());
  assertEquals(0, taskService.createTaskQuery()
      .dueAfter(oneHourLater).dueDate(dueDate).count());
  assertEquals(0, taskService.createTaskQuery()
      .dueDate(dueDate).dueBefore(oneHourAgo).count());
}
 
Example 3
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
public void testDueDate() {
  // given
  Date date = new Date();
  String processInstanceId = runtimeService.startProcessInstanceByKey("oneTaskProcess").getId();

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

  task.setDueDate(date);

  taskService.saveTask(task);

  TaskQuery query = taskService.createTaskQuery()
    .dueDate(date);

  Filter filter = filterService.newTaskFilter("filter");
  filter.setQuery(query);

  // when
  filterService.saveFilter(filter);

  // then
  assertThat(filterService.count(filter.getId()), is(1L));
}
 
Example 4
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateTaskListenerOnPropertyUpdateOnlyOnce() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  task.setAssignee("test");
  task.setDueDate(new Date());
  task.setOwner("test");
  taskService.saveTask(task);

  // then
  assertEquals(1, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE));
}
 
Example 5
Source File: TaskDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void updateTask(Task task) {
  task.setName(getName());
  task.setDescription(getDescription());
  task.setPriority(getPriority());
  task.setAssignee(getAssignee());
  task.setOwner(getOwner());

  DelegationState state = null;
  if (getDelegationState() != null) {
    DelegationStateConverter converter = new DelegationStateConverter();
    state = converter.convertQueryParameterToType(getDelegationState());
  }
  task.setDelegationState(state);

  task.setDueDate(getDue());
  task.setFollowUpDate(getFollowUp());
  task.setParentTaskId(getParentTaskId());
  task.setCaseInstanceId(getCaseInstanceId());
  task.setTenantId(getTenantId());
}
 
Example 6
Source File: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/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().dueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().dueBefore(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().dueBefore(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().dueBefore(oneHourAgo.getTime()).count());
}
 
Example 7
Source File: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueAfter() 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().dueAfter(oneHourAgo.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().dueAfter(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().dueAfter(oneHourLater.getTime()).count());
  assertEquals(0, taskService.createTaskQuery().dueAfter(oneHourAgo.getTime()).count());
}
 
Example 8
Source File: TaskQueryExpressionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Task createTestTask(String taskId) {
  Task task = taskService.newTask(taskId);
  task.setDueDate(task.getCreateTime());
  task.setFollowUpDate(task.getCreateTime());
  taskService.saveTask(task);
  return task;
}
 
Example 9
Source File: TaskQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HashMap<String, Date> createFollowUpAndDueDateTasks() throws ParseException {
  final Date date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("27/07/2017 01:12:13"),
    oneHourAgo = new Date(date.getTime() - 60 * 60 * 1000),
    oneHourLater = new Date(date.getTime() + 60 * 60 * 1000);

  Task taskDueBefore = taskService.newTask();
  taskDueBefore.setFollowUpDate(new Date(oneHourAgo.getTime() - 1000));
  taskDueBefore.setDueDate(new Date(oneHourAgo.getTime() - 1000));
  taskService.saveTask(taskDueBefore);

  Task taskDueDate = taskService.newTask();
  taskDueDate.setFollowUpDate(date);
  taskDueDate.setDueDate(date);
  taskService.saveTask(taskDueDate);

  Task taskDueAfter = taskService.newTask();
  taskDueAfter.setFollowUpDate(new Date(oneHourLater.getTime() + 1000));
  taskDueAfter.setDueDate(new Date(oneHourLater.getTime() + 1000));
  taskService.saveTask(taskDueAfter);

  assertEquals(3, taskService.createTaskQuery().count());

  return new HashMap<String, Date>() {{
    put("date", date);
    put("oneHourAgo", oneHourAgo);
    put("oneHourLater", oneHourLater);
  }};
}
 
Example 10
Source File: HistoricTaskInstanceQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public HashMap<String, Date> createFollowUpAndDueDateTasks() throws ParseException {
  final Date date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("27/07/2017 01:12:13"),
    oneHourAgo = new Date(date.getTime() - 60 * 60 * 1000),
    oneHourLater = new Date(date.getTime() + 60 * 60 * 1000);

  Task taskDueBefore = taskService.newTask();
  taskDueBefore.setFollowUpDate(new Date(oneHourAgo.getTime() - 1000));
  taskDueBefore.setDueDate(new Date(oneHourAgo.getTime() - 1000));
  taskService.saveTask(taskDueBefore);

  Task taskDueDate = taskService.newTask();
  taskDueDate.setFollowUpDate(date);
  taskDueDate.setDueDate(date);
  taskService.saveTask(taskDueDate);

  Task taskDueAfter = taskService.newTask();
  taskDueAfter.setFollowUpDate(new Date(oneHourLater.getTime() + 1000));
  taskDueAfter.setDueDate(new Date(oneHourLater.getTime() + 1000));
  taskService.saveTask(taskDueAfter);

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

  return new HashMap<String, Date>() {{
    put("date", date);
    put("oneHourAgo", oneHourAgo);
    put("oneHourLater", oneHourLater);
  }};
}
 
Example 11
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateTaskListenerOnPropertyUpdate() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  task.setDueDate(new Date());
  taskService.saveTask(task);

  // then
  assertEquals(1, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE));
}
 
Example 12
Source File: GetHistoricOperationLogsForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
private void createLogEntriesThatShouldNotBeReturned(String processInstanceId) {
  ClockUtil.setCurrentTime(new Date());

  String processTaskId = taskService.createTaskQuery().singleResult().getId();

  // create and remove some links
  taskService.addCandidateUser(processTaskId, "er");
  taskService.deleteCandidateUser(processTaskId, "er");
  taskService.addCandidateGroup(processTaskId, "wir");
  taskService.deleteCandidateGroup(processTaskId, "wir");

  // assign and reassign the owner
  taskService.setOwner(processTaskId, "icke");

  // change priority of task
  taskService.setPriority(processTaskId, 10);

  // add and delete an attachment
  Attachment attachment = taskService.createAttachment(
    "image/ico",
    processTaskId,
    processInstanceId,
    "favicon.ico",
    "favicon",
    "http://camunda.com/favicon.ico"
  );
  taskService.deleteAttachment(attachment.getId());
  runtimeService.deleteProcessInstance(processInstanceId, "that's why");

  // create a standalone userTask
  Task userTask = taskService.newTask();
  userTask.setName("to do");
  taskService.saveTask(userTask);

  // change some properties manually to create an update event
  ClockUtil.setCurrentTime(new Date());
  userTask.setDescription("desc");
  userTask.setOwner("icke");
  userTask.setAssignee("er");
  userTask.setDueDate(new Date());
  taskService.saveTask(userTask);

  taskService.deleteTask(userTask.getId(), true);
}
 
Example 13
Source File: TaskQueryExpressionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testQueryOr() {
  // given
  Date date = DateTimeUtil.now().plusDays(2).toDate();

  Task task1 = taskService.newTask();
  task1.setFollowUpDate(date);
  task1.setOwner("Luke Optim");
  task1.setName("taskForOr");
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setDueDate(date);
  task2.setName("taskForOr");
  taskService.saveTask(task2);

  Task task3 = taskService.newTask();
  task3.setAssignee("John Munda");
  task3.setDueDate(date);
  task3.setName("taskForOr");
  taskService.saveTask(task3);

  Task task4 = taskService.newTask();
  task4.setName("taskForOr");
  taskService.saveTask(task4);

  // when
  List<Task> tasks = taskService.createTaskQuery()
    .taskName("taskForOr")
    .or()
      .followUpAfterExpression("${ now() }")
      .taskAssigneeLikeExpression("${ 'John%' }")
    .endOr()
    .or()
      .taskOwnerExpression("${ 'Luke Optim' }")
      .dueAfterExpression("${ now() }")
    .endOr()
    .list();

  // then
  assertEquals(2, tasks.size());
}
 
Example 14
Source File: UserOperationLogAnnotationTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void updateMultiplePropertiesOfTask(Task task) {
  task.setDueDate(new Date());
  task.setName(TASK_NAME);

  taskService.saveTask(task);
}
 
Example 15
Source File: HistoricTaskInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@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.getCaseDefinitionId());
  assertNull(historicTaskInstance.getCaseInstanceId());
  assertNull(historicTaskInstance.getCaseExecutionId());

  // the activity instance id is set
  assertEquals(((TaskEntity)runtimeTask).getExecution().getActivityInstanceId(), historicTaskInstance.getActivityInstanceId());

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

  // move clock by 1 second
  Date now = ClockUtil.getCurrentTime();
  ClockUtil.setCurrentTime(new Date(now.getTime() + 1000));

  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());
  assertTrue(historicTaskInstance.getDurationInMillis() >= 1000);
  assertTrue(((HistoricTaskInstanceEntity)historicTaskInstance).getDurationRaw() >= 1000);

  assertNull(historicTaskInstance.getCaseDefinitionId());
  assertNull(historicTaskInstance.getCaseInstanceId());
  assertNull(historicTaskInstance.getCaseExecutionId());

  historyService.deleteHistoricTaskInstance(taskId);

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