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

The following examples show how to use org.camunda.bpm.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: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testSaveProcessTaskUpdateWithTaskAssignPermissionOnAnyTask() {
  // given
  startProcessInstanceByKey(PROCESS_KEY);
  Task task = selectSingleTask();
  task.setAssignee("demo");

  createGrantAuthorization(TASK, ANY, userId, TASK_ASSIGN);

  // when
  taskService.saveTask(task);

  // then
  task = selectSingleTask();
  assertNotNull(task);
  assertEquals("demo", task.getAssignee());
}
 
Example 2
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testPermissionsOnAssignSameAssigneeAndOwnerToTask() {

    try {
      // given
      createGrantAuthorization(Resources.TASK, Authorization.ANY, userId, Permissions.CREATE, Permissions.DELETE, Permissions.READ);
      processEngineConfiguration.setResourceAuthorizationProvider(new MyExtendedPermissionDefaultAuthorizationProvider());

      // when
      Task newTask = taskService.newTask();
      newTask.setAssignee("Horst");
      newTask.setOwner("Horst");
      taskService.saveTask(newTask);

      // then
      Authorization auth = authorizationService.createAuthorizationQuery().userIdIn("Horst").singleResult();
      assertTrue(auth.isPermissionGranted(Permissions.DELETE));

      taskService.deleteTask(newTask.getId(), true);

    } finally {
      processEngineConfiguration.setResourceAuthorizationProvider(new DefaultAuthorizationProvider());
    }


  }
 
Example 3
Source File: HistoricIdentityLinkLogAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryForStandaloneTaskHistoricIdentityLinkWithoutAuthrorization() {
  // given
  disableAuthorization();

  Task taskAssignee = taskService.newTask("newTask");
  taskAssignee.setAssignee("aUserId");
  taskService.saveTask(taskAssignee);

  enableAuthorization();

  // when
  HistoricIdentityLinkLogQuery query = historyService.createHistoricIdentityLinkLogQuery();

  // then
  verifyQueryResults(query, 1);

  disableAuthorization();
  taskService.deleteTask("newTask", true);
  enableAuthorization();
}
 
Example 4
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 5
Source File: HistoricTaskInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskHadCandidateUser() {
  // given
  runtimeService.startProcessInstanceByKey("oneTaskProcess");
  String taskId = taskService.createTaskQuery().singleResult().getId();
  // if
  identityService.setAuthenticatedUserId("aAssignerId");
  taskService.addCandidateUser(taskId, "aUserId");
  taskService.addCandidateUser(taskId, "bUserId");
  taskService.deleteCandidateUser(taskId, "bUserId");
  Task taskAssignee = taskService.newTask("newTask");
  taskAssignee.setAssignee("aUserId");
  taskService.saveTask(taskAssignee);
  // query test
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskHadCandidateUser("aUserId").count());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskHadCandidateUser("bUserId").count());
  assertEquals(0, historyService.createHistoricTaskInstanceQuery().taskHadCandidateUser("invalidUserId").count());
  // delete test
  taskService.deleteTask("newTask",true);
}
 
Example 6
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testSaveProcessTaskUpdateWithUpdatePermissionOnTask() {
  // given
  startProcessInstanceByKey(PROCESS_KEY);
  Task task = selectSingleTask();
  task.setAssignee("demo");

  createGrantAuthorization(TASK, task.getId(), userId, UPDATE);

  // when
  taskService.saveTask(task);

  // then
  task = selectSingleTask();
  assertNotNull(task);
  assertEquals("demo", task.getAssignee());
}
 
Example 7
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testSaveStandaloneTaskUpdate() {
  // given
  String taskId = "myTask";
  createTask(taskId);

  Task task = selectSingleTask();
  task.setAssignee("demo");

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.saveTask(task);

  // then
  task = selectSingleTask();
  assertNotNull(task);
  assertEquals("demo", task.getAssignee());

  deleteTask(taskId, true);
}
 
Example 8
Source File: TaskReadVariablePermissionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
public void testSaveProcessTaskAndCheckAssigneePermissions() {
  // given
  startProcessInstanceByKey(PROCESS_KEY);
  Task task = selectSingleTask();
  task.setAssignee(DEMO);

  authRule.createGrantAuthorization(TASK, task.getId(), userId, UPDATE);

  // when
  taskService.saveTask(task);

  // then
  task = selectSingleTask();
  assertNotNull(task);
  assertEquals(DEMO, task.getAssignee());
  verifyUserAuthorization(DEMO);
}
 
Example 9
Source File: TaskReadVariablePermissionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSaveStandaloneTaskAndCheckAssigneePermissions() {
  // given
  String taskId = "myTask";
  createTask(taskId);

  Task task = selectSingleTask();
  task.setAssignee(DEMO);

  authRule.createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.saveTask(task);

  // then
  task = selectSingleTask();
  assertNotNull(task);
  assertEquals(DEMO, task.getAssignee());
  verifyUserAuthorization(DEMO);
  taskService.deleteTask(taskId, true);
}
 
Example 10
Source File: TaskListenerErrorThrowTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowErrorOnAssignmentExpressionListenerAndCatchOnUserTask() {
  // given
  processEngineConfiguration.getBeans().put("myListener", new ThrowBPMNErrorListener());
  BpmnModelInstance model = Bpmn.createExecutableProcess("process")
                                .startEvent()
                                  .userTask("mainTask")
                                    .camundaTaskListenerExpression(TaskListener.EVENTNAME_ASSIGNMENT, "${myListener.notify(task)}")
                                    .camundaTaskListenerClass(TaskListener.EVENTNAME_DELETE, RecorderTaskListener.class.getName())
                                    .boundaryEvent("throw")
                                      .error(ERROR_CODE)
                                  .userTask("afterCatch")
                                  .moveToActivity("mainTask")
                                  .userTask("afterThrow")
                                .endEvent()
                                .done();
  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");

  Task firstTask = taskService.createTaskQuery().singleResult();
  assertNotNull(firstTask);

  // when
  firstTask.setAssignee("elmo");
  engineRule.getTaskService().saveTask(firstTask);

  // then
  verifyErrorGotCaught();
}
 
Example 11
Source File: BusinessProcessBeanTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testSaveTask() {
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);

  // cannot save task in absence of an association:
  try {
    businessProcess.saveTask();
    fail();
  } catch (ProcessEngineCdiException e) {
    assertEquals("No task associated. Call businessProcess.startTask() first.", e.getMessage());
  }

  // start the process
  String processInstanceId = businessProcess.startProcessByKey("businessProcessBeanTest", Collections.singletonMap("key", (Object) "value")).getId();
  assertEquals("value", runtimeService.getVariable(processInstanceId, "key"));

  businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());

  // assignee is not set to jonny
  assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
  Task task = businessProcess.getTask();
  task.setAssignee("jonny");

  assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());

  // if we save the task
  businessProcess.saveTask();

  // THEN

  // assignee is now set to jonny
  assertNotNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
  // business process is still associated with task:
  assertTrue(businessProcess.isTaskAssociated());
}
 
Example 12
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testSaveCaseTaskUpdate() {
  // given
  createCaseInstanceByKey(CASE_KEY);
  Task task = selectSingleTask();
  task.setAssignee("demo");

  // when
  taskService.saveTask(task);

  // then
  task = selectSingleTask();
  assertNotNull(task);
  assertEquals("demo", task.getAssignee());
}
 
Example 13
Source File: HistoricIdentityLinkLogTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testShouldAddIdentityLinkForTaskCreationWithAssigneeAndOwner() {

    String taskAssigneeId = "Assigneee";
    String taskOwnerId = "Owner";
    // Pre test
    List<HistoricIdentityLinkLog> historicIdentityLinks = historyService.createHistoricIdentityLinkLogQuery().list();
    assertEquals(historicIdentityLinks.size(), 0);

    Task taskAssignee = taskService.newTask(taskAssigneeId);
    taskAssignee.setAssignee(USER_1);
    taskService.saveTask(taskAssignee);

    Task taskOwner = taskService.newTask(taskOwnerId);
    taskOwner.setOwner(OWNER_1);
    taskService.saveTask(taskOwner);

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

    // then
    historicIdentityLinks = historyService.createHistoricIdentityLinkLogQuery().list();
    assertEquals(historicIdentityLinks.size(), 2);

    // Basic Query test
    HistoricIdentityLinkLogQuery query = historyService.createHistoricIdentityLinkLogQuery();
    assertEquals(query.type(IdentityLinkType.ASSIGNEE).count(), 1);
    assertEquals(query.userId(USER_1).count(), 1);

    query = historyService.createHistoricIdentityLinkLogQuery();
    assertEquals(query.type(IdentityLinkType.OWNER).count(), 1);
    assertEquals(query.userId(OWNER_1).count(), 1);

    taskService.deleteTask(taskAssigneeId,true);
    taskService.deleteTask(taskOwnerId,true);
    taskService.deleteTask(taskEmpty.getId(), true);
  }
 
Example 14
Source File: HistoricTaskInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskWasUnassigned() {
  // given
  Task taskOne = taskService.newTask("taskOne");
  Task taskTwo = taskService.newTask("taskTwo");
  Task taskThree = taskService.newTask("taskThree");

  // when
  taskOne.setAssignee("aUserId");
  taskService.saveTask(taskOne);

  taskTwo.setAssignee("anotherUserId");
  taskService.saveTask(taskTwo);

  taskService.saveTask(taskThree);

  List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskUnassigned().list();

  // then
  assertEquals(list.size(), 1);

  // cleanup
  taskService.deleteTask("taskOne",true);
  taskService.deleteTask("taskTwo",true);
  taskService.deleteTask("taskThree",true);
}
 
Example 15
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testStandaloneTaskSaveWithGenericResourceIdAssignee() {
  createGrantAuthorization(TASK, ANY, userId, CREATE);

  Task task = taskService.newTask();
  task.setAssignee("*");

  try {
    taskService.saveTask(task);
    fail("it should not be possible to save a task with the generic resource id *");
  } catch (ProcessEngineException e) {
    assertTextPresent("Cannot create default authorization for assignee *: "
        + "id cannot be *. * is a reserved identifier", e.getMessage());
  }
}
 
Example 16
Source File: TaskIdentityLinksTest.java    From camunda-bpm-platform 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 17
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 18
Source File: TaskQueryOrTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnTasksWithProcessInstanceBusinessKeyOrProcessInstanceBusinessKeyLikeOrStandaloneAssignee() {
  // given
  BpmnModelInstance aProcessDefinition = Bpmn.createExecutableProcess("aProcessDefinition")
    .startEvent()
      .userTask()
    .endEvent()
    .done();

  repositoryService
    .createDeployment()
    .addModelInstance("foo.bpmn", aProcessDefinition)
    .deploy();

  runtimeService
    .startProcessInstanceByKey("aProcessDefinition", "aBusinessKey");
  
  BpmnModelInstance anotherProcessDefinition = Bpmn.createExecutableProcess("anotherProcessDefinition")
    .startEvent()
      .userTask()
    .endEvent()
    .done();

   repositoryService
     .createDeployment()
     .addModelInstance("foo.bpmn", anotherProcessDefinition)
     .deploy();

  runtimeService
    .startProcessInstanceByKey("anotherProcessDefinition", "anotherBusinessKey");

  // create a standalone task with assignee
  String assignee = "testUser4";
  Task newTask = taskService.newTask();
  newTask.setAssignee(assignee);
  taskService.saveTask(newTask);

  // when
  List<Task> tasks = taskService.createTaskQuery()
    .or()
      .processInstanceBusinessKey("aBusinessKey")
      .processInstanceBusinessKeyLike("anotherBusinessKey")
      .taskAssignee(assignee)
    .endOr()
    .list();

  // then
  assertEquals(3, tasks.size());
}
 
Example 19
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());
}
 
Example 20
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());
}