Search in sources :

Example 36 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testGetIdentityLinksWithAssignee.

@Test
public void testGetIdentityLinksWithAssignee() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    String taskId = task.getId();
    identityService.saveUser(identityService.newUser("kermit"));
    taskService.claim(taskId, "kermit");
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    assertEquals(1, identityLinks.size());
    assertEquals("kermit", identityLinks.get(0).getUserId());
    assertNull(identityLinks.get(0).getGroupId());
    assertEquals(IdentityLinkType.ASSIGNEE, identityLinks.get(0).getType());
    // cleanup
    taskService.deleteTask(taskId, true);
    identityService.deleteUser("kermit");
}
Also used : Task(org.camunda.bpm.engine.task.Task) IdentityLink(org.camunda.bpm.engine.task.IdentityLink) Test(org.junit.Test)

Example 37 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class TaskIdentityLinksTest method testAssigneeLink.

public void testAssigneeLink() {
    Task task = taskService.newTask("task");
    task.setAssignee("assignee");
    taskService.saveTask(task);
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
    assertNotNull(identityLinks);
    assertEquals(1, identityLinks.size());
    IdentityLink identityLink = identityLinks.get(0);
    assertEquals(IdentityLinkType.ASSIGNEE, identityLink.getType());
    assertEquals("assignee", identityLink.getUserId());
    assertEquals("task", identityLink.getTaskId());
    taskService.deleteTask(task.getId(), true);
}
Also used : Task(org.camunda.bpm.engine.task.Task) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 38 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class TaskIdentityLinksTest method testCandidateUserLink.

@Deployment(resources = "org/camunda/bpm/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCandidateUserLink() {
    runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
    String taskId = taskService.createTaskQuery().singleResult().getId();
    taskService.addCandidateUser(taskId, "kermit");
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    IdentityLink identityLink = identityLinks.get(0);
    assertNull(identityLink.getGroupId());
    assertEquals("kermit", identityLink.getUserId());
    assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
    assertEquals(taskId, identityLink.getTaskId());
    assertEquals(1, identityLinks.size());
    taskService.deleteCandidateUser(taskId, "kermit");
    assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
Also used : IdentityLink(org.camunda.bpm.engine.task.IdentityLink) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 39 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class TaskIdentityLinksTest method testCandidateGroupLink.

@Deployment(resources = "org/camunda/bpm/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCandidateGroupLink() {
    try {
        identityService.setAuthenticatedUserId("demo");
        runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
        String taskId = taskService.createTaskQuery().singleResult().getId();
        taskService.addCandidateGroup(taskId, "muppets");
        List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
        IdentityLink identityLink = identityLinks.get(0);
        assertEquals("muppets", identityLink.getGroupId());
        assertNull("kermit", identityLink.getUserId());
        assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
        assertEquals(taskId, identityLink.getTaskId());
        assertEquals(1, identityLinks.size());
        if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL) {
            List<Event> taskEvents = taskService.getTaskEvents(taskId);
            assertEquals(1, taskEvents.size());
            Event taskEvent = taskEvents.get(0);
            assertEquals(Event.ACTION_ADD_GROUP_LINK, taskEvent.getAction());
            List<String> taskEventMessageParts = taskEvent.getMessageParts();
            assertEquals("muppets", taskEventMessageParts.get(0));
            assertEquals(IdentityLinkType.CANDIDATE, taskEventMessageParts.get(1));
            assertEquals(2, taskEventMessageParts.size());
        }
        taskService.deleteCandidateGroup(taskId, "muppets");
        if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL) {
            List<Event> taskEvents = taskService.getTaskEvents(taskId);
            Event taskEvent = findTaskEvent(taskEvents, Event.ACTION_DELETE_GROUP_LINK);
            assertEquals(Event.ACTION_DELETE_GROUP_LINK, taskEvent.getAction());
            List<String> taskEventMessageParts = taskEvent.getMessageParts();
            assertEquals("muppets", taskEventMessageParts.get(0));
            assertEquals(IdentityLinkType.CANDIDATE, taskEventMessageParts.get(1));
            assertEquals(2, taskEventMessageParts.size());
            assertEquals(2, taskEvents.size());
        }
        assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
    } finally {
        identityService.clearAuthentication();
    }
}
Also used : Event(org.camunda.bpm.engine.task.Event) IdentityLink(org.camunda.bpm.engine.task.IdentityLink) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 40 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class DelegateTaskTestTaskListener method notify.

public void notify(DelegateTask delegateTask) {
    Set<IdentityLink> candidates = delegateTask.getCandidates();
    Set<String> candidateUsers = new HashSet<String>();
    Set<String> candidateGroups = new HashSet<String>();
    for (IdentityLink candidate : candidates) {
        if (candidate.getUserId() != null) {
            candidateUsers.add(candidate.getUserId());
        } else if (candidate.getGroupId() != null) {
            candidateGroups.add(candidate.getGroupId());
        }
    }
    delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
    delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);
}
Also used : IdentityLink(org.camunda.bpm.engine.task.IdentityLink) HashSet(java.util.HashSet)

Aggregations

IdentityLink (org.camunda.bpm.engine.task.IdentityLink)81 Task (org.camunda.bpm.engine.task.Task)13 Deployment (org.camunda.bpm.engine.test.Deployment)13 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)7 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 Expression (org.camunda.bpm.engine.delegate.Expression)4 HistoricIdentityLinkLog (org.camunda.bpm.engine.history.HistoricIdentityLinkLog)4 DeploymentBuilder (org.camunda.bpm.engine.repository.DeploymentBuilder)4 VariableMap (org.camunda.bpm.engine.variable.VariableMap)4 TaskService (org.camunda.bpm.engine.TaskService)3 HistoricIdentityLinkLogQuery (org.camunda.bpm.engine.history.HistoricIdentityLinkLogQuery)3 List (java.util.List)2 HalResource (org.camunda.bpm.engine.rest.hal.HalResource)2 Job (org.camunda.bpm.engine.runtime.Job)2 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)2 Matchers.anyString (org.mockito.Matchers.anyString)2