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

The following examples show how to use org.camunda.bpm.engine.task.Task#setName() . 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: CamundaEventingIT.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEventHistoryTaskAttributeChanges() {
  // given
  startEventingInstance();
  Task task = taskService.createTaskQuery().active().singleResult();
  eventCaptor.clear();

  // when
  task.setName("new Name");
  taskService.saveTask(task);

  // then
  HistoryEvent taskChangeEvent = eventCaptor.historyEvents.pop();
  assertThat(taskChangeEvent.getEventType()).isEqualTo("update");
  if (taskChangeEvent instanceof HistoricTaskInstanceEventEntity) {
    assertThat(((HistoricTaskInstanceEventEntity) taskChangeEvent).getName()).isEqualTo("new Name");
  } else {
    fail("Expected task instance change event");
  }

}
 
Example 2
Source File: JavaSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStandaloneTaskVariable() {
  Task task = taskService.newTask();
  task.setName("gonzoTask");
  taskService.saveTask(task);

  String taskId = task.getId();

  try {
    taskService
      .setVariable(taskId, "instrument", Variables.serializedObjectValue("trumpet").serializationDataFormat(Variables.SerializationDataFormats.JAVA).create());
    fail("Exception is expected.");
  } catch (ProcessEngineException ex) {
    assertEquals("ENGINE-17007 Cannot set variable with name instrument. Java serialization format is prohibited", ex.getMessage());
  } finally {
    taskService.deleteTask(taskId, true);
  }

}
 
Example 3
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void createTasks() {
  Task task = taskService.newTask("task1");
  task.setName("Task 1");
  task.setOwner(testUser.getId());
  task.setDelegationState(DelegationState.PENDING);
  taskService.saveTask(task);
  taskService.addCandidateGroup(task.getId(), "accounting");

  task = taskService.newTask("task2");
  task.setName("Task 2");
  task.setOwner(testUser.getId());
  task.setDelegationState(DelegationState.RESOLVED);
  taskService.saveTask(task);
  taskService.setAssignee(task.getId(), "kermit");
  taskService.addCandidateGroup(task.getId(), "accounting");

  task = taskService.newTask("task3");
  task.setName("Task 3");
  task.setOwner(testUser.getId());
  task.setDelegationState(DelegationState.RESOLVED);
  taskService.saveTask(task);
}
 
Example 4
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testExtendingTaskQueryWithAssigneeIn() {
  // given
  Task task = taskService.newTask("assigneeTask");
  task.setName("Task 4");
  task.setOwner(testUser.getId());
  taskService.saveTask(task);
  taskService.setAssignee(task.getId(), "john");

  // then
  TaskQuery query = taskService.createTaskQuery().taskAssigneeIn("john");
  saveQuery(query);
  List<Task> origQueryTasks = filterService.list(filter.getId());
  List<Task> selfExtendQueryTasks = filterService.list(filter.getId(), query);

  TaskQuery extendingQuery = taskService.createTaskQuery();
  extendingQuery.taskAssigneeIn("john", "kermit");
  List<Task> extendingQueryTasks = filterService.list(filter.getId(), extendingQuery);

  // then
  assertEquals(1, origQueryTasks.size());
  assertEquals(1, selfExtendQueryTasks.size());
  assertEquals(2, extendingQueryTasks.size());
}
 
Example 5
Source File: HistoricTaskInstanceUpdateTest.java    From camunda-bpm-platform with Apache License 2.0 6 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());
}
 
Example 6
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 7
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteTaskWithDeleteReason() {
  // ACT-900: deleteReason can be manually specified - can only be validated when historyLevel > ACTIVITY
  if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {

    Task task = taskService.newTask();
    task.setName("test task");
    taskService.saveTask(task);

    assertNotNull(task.getId());

    taskService.deleteTask(task.getId(), "deleted for testing purposes");

    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery()
      .taskId(task.getId()).singleResult();

    assertNotNull(historicTaskInstance);
    assertEquals("deleted for testing purposes", historicTaskInstance.getDeleteReason());

    // Delete historic task that is left behind, will not be cleaned up because this is not part of a process
    taskService.deleteTask(task.getId(), true);

  }
}
 
Example 8
Source File: HistoricTaskInstanceQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnHistoricTasksWithTaskNameOrTaskDescription() {
  // given
  Task task1 = taskService.newTask();
  task1.setName("aTaskName");
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setDescription("aTaskDescription");
  taskService.saveTask(task2);

  // when
  List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
    .endOr()
    .list();

  // then
  assertEquals(2, tasks.size());
}
 
Example 9
Source File: SubTaskDataTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testSubTaskData() {
  //given simple process with user task
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subTaskTest");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // when set variable to user task
  taskService.setVariable(task.getId(), "testVariable", "testValue");

  // then variable is set in the scope of execution
  Assert.assertEquals("testValue", runtimeService.getVariable(task.getExecutionId(), "testVariable"));

  // when sub task is created create subtask for user task
  Task subTask = taskService.newTask("123456789");
  subTask.setParentTaskId(task.getId());
  subTask.setName("Test Subtask");
  taskService.saveTask(subTask);

  // and variable is update
  taskService.setVariable(subTask.getId(), "testVariable", "newTestValue");

  //then variable is also updated in the scope execution
  Assert.assertEquals("newTestValue", runtimeService.getVariable(task.getExecutionId(), "testVariable"));
}
 
Example 10
Source File: StandaloneTaskTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testCreateToComplete() {

    // Create and save task
    Task task = taskService.newTask();
    task.setName("testTask");
    taskService.saveTask(task);
    String taskId = task.getId();

    // Add user as candidate user
    taskService.addCandidateUser(taskId, "kermit");
    taskService.addCandidateUser(taskId, "gonzo");

    // Retrieve task list for jbarrez
    List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("kermit").list();
    assertEquals(1, tasks.size());
    assertEquals("testTask", tasks.get(0).getName());

    // Retrieve task list for tbaeyens
    tasks = taskService.createTaskQuery().taskCandidateUser("gonzo").list();
    assertEquals(1, tasks.size());
    assertEquals("testTask", tasks.get(0).getName());

    // Claim task
    taskService.claim(taskId, "kermit");

    // Tasks shouldn't appear in the candidate tasklists anymore
    assertTrue(taskService.createTaskQuery().taskCandidateUser("kermit").list().isEmpty());
    assertTrue(taskService.createTaskQuery().taskCandidateUser("gonzo").list().isEmpty());

    // Complete task
    taskService.deleteTask(taskId, true);

    // Task should be removed from runtime data
    // TODO: check for historic data when implemented!
    assertNull(taskService.createTaskQuery().taskId(taskId).singleResult());
  }
 
Example 11
Source File: HistoricTaskInstanceQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnHistoricTasksWithMultipleOrCriteria() {
  // given
  Task task1 = taskService.newTask();
  task1.setName("aTaskName");
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setDescription("aTaskDescription");
  taskService.saveTask(task2);

  Task task3 = taskService.newTask();
  taskService.saveTask(task3);

  Task task4 = taskService.newTask();
  task4.setPriority(5);
  taskService.saveTask(task4);

  Task task5 = taskService.newTask();
  task5.setOwner("aTaskOwner");
  taskService.saveTask(task5);

  // when
  List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
      .taskId(task3.getId())
      .taskPriority(5)
      .taskOwner("aTaskOwner")
    .endOr()
    .list();

  // then
  assertEquals(5, tasks.size());
}
 
Example 12
Source File: ManagementServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private List<String> generateDummyTasks(int nrOfTasks) {
  ArrayList<String> taskIds = new ArrayList<String>();
  for (int i = 0; i < nrOfTasks; i++) {
    Task task = taskService.newTask();
    task.setName(((char) ('A' + i)) + "");
    taskService.saveTask(task);
    taskIds.add(task.getId());
  }
  return taskIds;
}
 
Example 13
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void createTasksForOrQueries() {
  Task task1 = taskService.newTask();
  task1.setName("taskForOr");
  task1.setDescription("aTaskDescription");
  task1.setPriority(3);
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setName("taskForOr");
  task2.setDescription("aTaskDescription");
  task2.setAssignee("aTaskAssignee");
  task2.setTenantId("aTenantId");
  taskService.saveTask(task2);

  Task task3 = taskService.newTask();
  task3.setName("taskForOr");
  task3.setOwner("aTaskOwner");
  taskService.saveTask(task3);

  Task task4 = taskService.newTask();
  task4.setName("taskForOr");
  task4.setOwner("aTaskOwner");
  task4.setPriority(3);
  taskService.saveTask(task4);

  Task task5 = taskService.newTask();
  task5.setDescription("aTaskDescription");
  task5.setAssignee("aTaskAssignee");
  taskService.saveTask(task5);

  Task task6 = taskService.newTask();
  task6.setDescription("aTaskDescription");
  task6.setAssignee("aTaskAssignee");
  task6.setTenantId("aTenantId");
  taskService.saveTask(task6);

  Task task7 = taskService.newTask();
  task7.setTenantId("aTenantId");
  task7.setOwner("aTaskOwner");
  task7.setPriority(3);
  task7.setAssignee("aTaskAssignee");
  taskService.saveTask(task7);
}
 
Example 14
Source File: HistoricTaskInstanceQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnHistoricTasksFilteredByMultipleOrAndCriteria() {
  // given
  Task task1 = taskService.newTask();
  task1.setPriority(4);
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setName("aTaskName");
  task2.setOwner("aTaskOwner");
  task2.setAssignee("aTaskAssignee");
  task2.setPriority(4);
  taskService.saveTask(task2);

  Task task3 = taskService.newTask();
  task3.setName("aTaskName");
  task3.setOwner("aTaskOwner");
  task3.setAssignee("aTaskAssignee");
  task3.setPriority(4);
  task3.setDescription("aTaskDescription");
  taskService.saveTask(task3);

  Task task4 = taskService.newTask();
  task4.setOwner("aTaskOwner");
  task4.setAssignee("aTaskAssignee");
  task4.setPriority(4);
  task4.setDescription("aTaskDescription");
  taskService.saveTask(task4);

  Task task5 = taskService.newTask();
  task5.setDescription("aTaskDescription");
  task5.setOwner("aTaskOwner");
  taskService.saveTask(task5);

  // when
  List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
      .taskId(task3.getId())
    .endOr()
    .taskOwner("aTaskOwner")
    .taskPriority(4)
    .taskAssignee("aTaskAssignee")
    .list();

  // then
  assertEquals(3, tasks.size());
}
 
Example 15
Source File: SubTaskTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testSubTask() {
  Task gonzoTask = taskService.newTask();
  gonzoTask.setName("gonzoTask");
  taskService.saveTask(gonzoTask);

  Task subTaskOne = taskService.newTask();
  subTaskOne.setName("subtask one");
  String gonzoTaskId = gonzoTask.getId();
  subTaskOne.setParentTaskId(gonzoTaskId);
  taskService.saveTask(subTaskOne);

  Task subTaskTwo = taskService.newTask();
  subTaskTwo.setName("subtask two");
  subTaskTwo.setParentTaskId(gonzoTaskId);
  taskService.saveTask(subTaskTwo);

  String subTaskId = subTaskOne.getId();
  assertTrue(taskService.getSubTasks(subTaskId).isEmpty());
  assertTrue(historyService
          .createHistoricTaskInstanceQuery()
          .taskParentTaskId(subTaskId)
          .list()
          .isEmpty());

  List<Task> subTasks = taskService.getSubTasks(gonzoTaskId);
  Set<String> subTaskNames = new HashSet<String>();
  for (Task subTask: subTasks) {
    subTaskNames.add(subTask.getName());
  }

  if(processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
    Set<String> expectedSubTaskNames = new HashSet<String>();
    expectedSubTaskNames.add("subtask one");
    expectedSubTaskNames.add("subtask two");

    assertEquals(expectedSubTaskNames, subTaskNames);

    List<HistoricTaskInstance> historicSubTasks = historyService
      .createHistoricTaskInstanceQuery()
      .taskParentTaskId(gonzoTaskId)
      .list();

    subTaskNames = new HashSet<String>();
    for (HistoricTaskInstance historicSubTask: historicSubTasks) {
      subTaskNames.add(historicSubTask.getName());
    }

    assertEquals(expectedSubTaskNames, subTaskNames);
  }

  taskService.deleteTask(gonzoTaskId, true);
}
 
Example 16
Source File: TaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testQuerySortingByNameShouldBeCaseInsensitive() {
  // create task with capitalized name
  Task task = taskService.newTask("caseSensitiveTestTask");
  task.setName("CaseSensitiveTestTask");
  taskService.saveTask(task);

  // create task filter
  Filter filter = filterService.newTaskFilter("taskNameOrdering");
  filterService.saveFilter(filter);

  List<String> sortedNames = getTaskNamesFromTasks(taskService.createTaskQuery().list());
  Collections.sort(sortedNames, String.CASE_INSENSITIVE_ORDER);

  // ascending ordering
  TaskQuery taskQuery = taskService.createTaskQuery().orderByTaskNameCaseInsensitive().asc();
  List<String> ascNames = getTaskNamesFromTasks(taskQuery.list());
  assertEquals(sortedNames, ascNames);

  // test filter merging
  ascNames = getTaskNamesFromTasks(filterService.list(filter.getId(), taskQuery));
  assertEquals(sortedNames, ascNames);

  // descending ordering

  // reverse sorted names to test descending ordering
  Collections.reverse(sortedNames);

  taskQuery = taskService.createTaskQuery().orderByTaskNameCaseInsensitive().desc();
  List<String> descNames = getTaskNamesFromTasks(taskQuery.list());
  assertEquals(sortedNames, descNames);

  // test filter merging
  descNames = getTaskNamesFromTasks(filterService.list(filter.getId(), taskQuery));
  assertEquals(sortedNames, descNames);

  // delete test task
  taskService.deleteTask(task.getId(), true);

  // delete filter
  filterService.deleteFilter(filter.getId());
}
 
Example 17
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 18
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 19
Source File: TaskQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnTasksFilteredByMultipleOrAndCriteria() {
  // given
  Task task1 = taskService.newTask();
  task1.setPriority(4);
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setName("aTaskName");
  task2.setOwner("aTaskOwner");
  task2.setAssignee("aTaskAssignee");
  task2.setPriority(4);
  taskService.saveTask(task2);

  Task task3 = taskService.newTask();
  task3.setName("aTaskName");
  task3.setOwner("aTaskOwner");
  task3.setAssignee("aTaskAssignee");
  task3.setPriority(4);
  task3.setDescription("aTaskDescription");
  taskService.saveTask(task3);

  Task task4 = taskService.newTask();
  task4.setOwner("aTaskOwner");
  task4.setAssignee("aTaskAssignee");
  task4.setPriority(4);
  task4.setDescription("aTaskDescription");
  taskService.saveTask(task4);

  Task task5 = taskService.newTask();
  task5.setDescription("aTaskDescription");
  task5.setOwner("aTaskOwner");
  taskService.saveTask(task5);

  // when
  List<Task> tasks = taskService.createTaskQuery()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
      .taskId(task3.getId())
    .endOr()
    .taskOwner("aTaskOwner")
    .taskPriority(4)
    .taskAssignee("aTaskAssignee")
    .list();

  // then
  assertEquals(3, tasks.size());
}
 
Example 20
Source File: TaskQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnTasksFilteredByMultipleOrQueries() {
  // given
  Task task1 = taskService.newTask();
  task1.setName("aTaskName");
  taskService.saveTask(task1);

  Task task2 = taskService.newTask();
  task2.setName("aTaskName");
  task2.setDescription("aTaskDescription");
  taskService.saveTask(task2);

  Task task3 = taskService.newTask();
  task3.setName("aTaskName");
  task3.setDescription("aTaskDescription");
  task3.setOwner("aTaskOwner");
  taskService.saveTask(task3);

  Task task4 = taskService.newTask();
  task4.setName("aTaskName");
  task4.setDescription("aTaskDescription");
  task4.setOwner("aTaskOwner");
  task4.setAssignee("aTaskAssignee");
  taskService.saveTask(task4);

  Task task5 = taskService.newTask();
  task5.setName("aTaskName");
  task5.setDescription("aTaskDescription");
  task5.setOwner("aTaskOwner");
  task5.setAssignee("aTaskAssignee");
  task5.setPriority(4);
  taskService.saveTask(task5);

  Task task6 = taskService.newTask();
  task6.setName("aTaskName");
  task6.setDescription("aTaskDescription");
  task6.setOwner("aTaskOwner");
  task6.setAssignee("aTaskAssignee");
  task6.setPriority(4);
  taskService.saveTask(task6);

  // when
  List<Task> tasks = taskService.createTaskQuery()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
    .endOr()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
      .taskAssignee("aTaskAssignee")
    .endOr()
    .or()
      .taskName("aTaskName")
      .taskDescription("aTaskDescription")
      .taskOwner("aTaskOwner")
      .taskAssignee("aTaskAssignee")
    .endOr()
    .or()
      .taskAssignee("aTaskAssignee")
      .taskPriority(4)
    .endOr()
    .list();

  // then
  assertEquals(3, tasks.size());
}