Search in sources :

Example 41 with IdentityLink

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

the class TaskDecoratorTest method testDecorateCandidateUsers.

public void testDecorateCandidateUsers() {
    // given
    List<String> aCandidateUserList = new ArrayList<String>();
    aCandidateUserList.add("john");
    aCandidateUserList.add("peter");
    aCandidateUserList.add("mary");
    for (String candidateUser : aCandidateUserList) {
        Expression candidateUserExpression = expressionManager.createExpression(candidateUser);
        taskDefinition.addCandidateUserIdExpression(candidateUserExpression);
    }
    // when
    decorate(task, taskDecorator);
    // then
    Set<IdentityLink> candidates = task.getCandidates();
    assertEquals(3, candidates.size());
    for (IdentityLink identityLink : candidates) {
        String taskId = identityLink.getTaskId();
        assertEquals(task.getId(), taskId);
        assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
        String userId = identityLink.getUserId();
        if ("john".equals(userId)) {
            assertEquals("john", userId);
        } else if ("peter".equals(userId)) {
            assertEquals("peter", userId);
        } else if ("mary".equals(userId)) {
            assertEquals("mary", userId);
        } else {
            fail("Unexpected user: " + userId);
        }
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression) ArrayList(java.util.ArrayList) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 42 with IdentityLink

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

the class TaskDecoratorTest method testDecorateCandidateGroupsFromVariable.

public void testDecorateCandidateGroupsFromVariable() {
    // given
    taskService.setVariable(task.getId(), "management", "management");
    taskService.setVariable(task.getId(), "accounting", "accounting");
    taskService.setVariable(task.getId(), "backoffice", "backoffice");
    List<String> aCandidateGroupList = new ArrayList<String>();
    aCandidateGroupList.add("${management}");
    aCandidateGroupList.add("${accounting}");
    aCandidateGroupList.add("${backoffice}");
    for (String candidateGroup : aCandidateGroupList) {
        Expression candidateGroupExpression = expressionManager.createExpression(candidateGroup);
        taskDefinition.addCandidateGroupIdExpression(candidateGroupExpression);
    }
    // when
    decorate(task, taskDecorator);
    // then
    Set<IdentityLink> candidates = task.getCandidates();
    assertEquals(3, candidates.size());
    for (IdentityLink identityLink : candidates) {
        String taskId = identityLink.getTaskId();
        assertEquals(task.getId(), taskId);
        assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
        String groupId = identityLink.getGroupId();
        if ("management".equals(groupId)) {
            assertEquals("management", groupId);
        } else if ("accounting".equals(groupId)) {
            assertEquals("accounting", groupId);
        } else if ("backoffice".equals(groupId)) {
            assertEquals("backoffice", groupId);
        } else {
            fail("Unexpected group: " + groupId);
        }
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression) ArrayList(java.util.ArrayList) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 43 with IdentityLink

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

the class TaskDecoratorTest method testDecorateCandidateUsersFromVariable.

public void testDecorateCandidateUsersFromVariable() {
    // given
    taskService.setVariable(task.getId(), "john", "john");
    taskService.setVariable(task.getId(), "peter", "peter");
    taskService.setVariable(task.getId(), "mary", "mary");
    List<String> aCandidateUserList = new ArrayList<String>();
    aCandidateUserList.add("${john}");
    aCandidateUserList.add("${peter}");
    aCandidateUserList.add("${mary}");
    for (String candidateUser : aCandidateUserList) {
        Expression candidateUserExpression = expressionManager.createExpression(candidateUser);
        taskDefinition.addCandidateUserIdExpression(candidateUserExpression);
    }
    // when
    decorate(task, taskDecorator);
    // then
    Set<IdentityLink> candidates = task.getCandidates();
    assertEquals(3, candidates.size());
    for (IdentityLink identityLink : candidates) {
        String taskId = identityLink.getTaskId();
        assertEquals(task.getId(), taskId);
        assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
        String userId = identityLink.getUserId();
        if ("john".equals(userId)) {
            assertEquals("john", userId);
        } else if ("peter".equals(userId)) {
            assertEquals("peter", userId);
        } else if ("mary".equals(userId)) {
            assertEquals("mary", userId);
        } else {
            fail("Unexpected user: " + userId);
        }
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression) ArrayList(java.util.ArrayList) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 44 with IdentityLink

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

the class TaskDecoratorTest method testDecorateCandidateGroups.

public void testDecorateCandidateGroups() {
    // given
    List<String> aCandidateGroupList = new ArrayList<String>();
    aCandidateGroupList.add("management");
    aCandidateGroupList.add("accounting");
    aCandidateGroupList.add("backoffice");
    for (String candidateGroup : aCandidateGroupList) {
        Expression candidateGroupExpression = expressionManager.createExpression(candidateGroup);
        taskDefinition.addCandidateGroupIdExpression(candidateGroupExpression);
    }
    // when
    decorate(task, taskDecorator);
    // then
    Set<IdentityLink> candidates = task.getCandidates();
    assertEquals(3, candidates.size());
    for (IdentityLink identityLink : candidates) {
        String taskId = identityLink.getTaskId();
        assertEquals(task.getId(), taskId);
        assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
        String groupId = identityLink.getGroupId();
        if ("management".equals(groupId)) {
            assertEquals("management", groupId);
        } else if ("accounting".equals(groupId)) {
            assertEquals("accounting", groupId);
        } else if ("backoffice".equals(groupId)) {
            assertEquals("backoffice", groupId);
        } else {
            fail("Unexpected group: " + groupId);
        }
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression) ArrayList(java.util.ArrayList) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 45 with IdentityLink

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

the class InvoiceTestCase method testApproveInvoiceAssignment.

@Deployment(resources = { "invoice.v2.bpmn", "invoiceBusinessDecisions.dmn" })
public void testApproveInvoiceAssignment() {
    InputStream invoiceInputStream = InvoiceProcessApplication.class.getClassLoader().getResourceAsStream("invoice.pdf");
    VariableMap variables = Variables.createVariables().putValue("creditor", "Great Pizza for Everyone Inc.").putValue("amount", 300.0d).putValue("invoiceCategory", "Travel Expenses").putValue("invoiceNumber", "GPFE-23232323").putValue("invoiceDocument", fileValue("invoice.pdf").file(invoiceInputStream).mimeType("application/pdf").create()).putValue("approverGroups", Arrays.asList("sales", "accounting"));
    ProcessInstance pi = runtimeService.createProcessInstanceByKey("invoice").setVariables(variables).startBeforeActivity("approveInvoice").execute();
    // givent that the process instance is waiting at task "approveInvoice"
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("approveInvoice", task.getTaskDefinitionKey());
    // and task has candidate groups
    List<IdentityLink> links = taskService.getIdentityLinksForTask(task.getId());
    Set<String> approverGroups = new HashSet<String>();
    for (IdentityLink link : links) {
        approverGroups.add(link.getGroupId());
    }
    assertEquals(2, approverGroups.size());
    assertTrue(approverGroups.contains("accounting"));
    assertTrue(approverGroups.contains("sales"));
    // and variable approver is null
    assertNull(taskService.getVariable(task.getId(), "approver"));
    // if mary claims the task
    taskService.claim(task.getId(), "mary");
    // then the variable "approver" exists and is set to mary
    assertEquals("mary", taskService.getVariable(task.getId(), "approver"));
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) InputStream(java.io.InputStream) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) IdentityLink(org.camunda.bpm.engine.task.IdentityLink) HashSet(java.util.HashSet) Deployment(org.camunda.bpm.engine.test.Deployment)

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