Search in sources :

Example 56 with IdentityLink

use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.

the class TaskIdentityLinksTest method testCustomLinkGroupLink.

@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
    runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
    String taskId = taskService.createTaskQuery().singleResult().getId();
    taskService.addGroupIdentityLink(taskId, "muppets", "playing");
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    IdentityLink identityLink = identityLinks.get(0);
    assertThat(identityLink.getGroupId()).isEqualTo("muppets");
    assertThat(identityLink.getUserId()).as("kermit").isNull();
    assertThat(identityLink.getType()).isEqualTo("playing");
    assertThat(identityLink.getTaskId()).isEqualTo(taskId);
    assertThat(identityLinks).hasSize(1);
    taskService.deleteGroupIdentityLink(taskId, "muppets", "playing");
    assertThat(taskService.getIdentityLinksForTask(taskId)).hasSize(0);
}
Also used : IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 57 with IdentityLink

use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.

the class TaskIdentityLinksTest method testCandidateGroupLink.

@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCandidateGroupLink() {
    runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
    String taskId = taskService.createTaskQuery().singleResult().getId();
    taskService.addCandidateGroup(taskId, "muppets");
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    IdentityLink identityLink = identityLinks.get(0);
    assertThat(identityLink.getGroupId()).isEqualTo("muppets");
    assertThat(identityLink.getUserId()).as("kermit").isNull();
    assertThat(identityLink.getType()).isEqualTo(IdentityLinkType.CANDIDATE);
    assertThat(identityLink.getTaskId()).isEqualTo(taskId);
    assertThat(identityLinks).hasSize(1);
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        List<Event> taskEvents = taskService.getTaskEvents(taskId);
        assertThat(taskEvents).hasSize(1);
        Event taskEvent = taskEvents.get(0);
        assertThat(taskEvent.getAction()).isEqualTo(Event.ACTION_ADD_GROUP_LINK);
        List<String> taskEventMessageParts = taskEvent.getMessageParts();
        assertThat(taskEventMessageParts.get(0)).isEqualTo("muppets");
        assertThat(taskEventMessageParts.get(1)).isEqualTo(IdentityLinkType.CANDIDATE);
        assertThat(taskEventMessageParts).hasSize(2);
    }
    taskService.deleteCandidateGroup(taskId, "muppets");
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        List<Event> taskEvents = taskService.getTaskEvents(taskId);
        Event taskEvent = findTaskEvent(taskEvents, Event.ACTION_DELETE_GROUP_LINK);
        assertThat(taskEvent.getAction()).isEqualTo(Event.ACTION_DELETE_GROUP_LINK);
        List<String> taskEventMessageParts = taskEvent.getMessageParts();
        assertThat(taskEventMessageParts.get(0)).isEqualTo("muppets");
        assertThat(taskEventMessageParts.get(1)).isEqualTo(IdentityLinkType.CANDIDATE);
        assertThat(taskEventMessageParts).hasSize(2);
        assertThat(taskEvents).hasSize(2);
    }
    assertThat(taskService.getIdentityLinksForTask(taskId)).hasSize(0);
}
Also used : Event(org.activiti.engine.task.Event) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 58 with IdentityLink

use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.

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.activiti.engine.task.IdentityLink) HashSet(java.util.HashSet)

Example 59 with IdentityLink

use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.

the class SerializePOJOJsonTest method testJsonVarInExpression.

@Deployment
public void testJsonVarInExpression() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("assignee", "bob");
    map.put("category", "test");
    Map<String, Object> mapInMap = new HashMap<String, Object>();
    mapInMap.put("user", "bob");
    map.put("mapInMap", mapInMap);
    vars.put("userMap", map);
    List<String> list = asList("bob", "john", "hannah");
    vars.put("userCollection", list);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJsonVarInExpression", vars);
    String taskId = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId();
    taskService.complete(taskId);
    taskId = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId();
    taskService.getIdentityLinksForTask(taskId).stream().forEach(new Consumer<IdentityLink>() {

        @Override
        public void accept(IdentityLink i) {
            if ("candidate".equals(i.getType())) {
                assertThat(i.getUserId()).isEqualTo("bob");
            }
        }
    });
    taskService.complete(taskId);
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
    assertThat(task.getAssignee()).isEqualTo("bob");
    assertThat(task.getCategory()).isEqualTo("test");
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 60 with IdentityLink

use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.

the class DynamicUserTaskTest method testChangeCandidateGroups.

@Deployment(resources = { "org/activiti/engine/test/bpmn/usertask/DynamicUserTaskTest.basictask.bpmn20.xml" })
public void testChangeCandidateGroups() {
    // first test without changing the form key
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
    String processDefinitionId = processInstance.getProcessDefinitionId();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    List<IdentityLink> taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
    boolean candidateGroupTestFound = false;
    for (IdentityLink identityLink : taskIdentityLinks) {
        if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getGroupId() != null && identityLink.getUserId() == null) {
            if ("test".equals(identityLink.getGroupId())) {
                candidateGroupTestFound = true;
            }
        }
    }
    assertThat(candidateGroupTestFound).isFalse();
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
    // now test with changing the form key
    ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateGroup("task1", "test", true);
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
    candidateGroupTestFound = false;
    for (IdentityLink identityLink : taskIdentityLinks) {
        if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getGroupId() != null && identityLink.getUserId() == null) {
            if ("test".equals(identityLink.getGroupId())) {
                candidateGroupTestFound = true;
            }
        }
    }
    assertThat(candidateGroupTestFound).isTrue();
    taskService.complete(task.getId());
    infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);
    dynamicBpmnService.changeUserTaskCandidateGroup("task1", "test2", false, infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
    candidateGroupTestFound = false;
    boolean candidateGroupTest2Found = false;
    for (IdentityLink identityLink : taskIdentityLinks) {
        if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getGroupId() != null && identityLink.getUserId() == null) {
            if ("test".equals(identityLink.getGroupId())) {
                candidateGroupTestFound = true;
            } else if ("test2".equals(identityLink.getGroupId())) {
                candidateGroupTest2Found = true;
            }
        }
    }
    assertThat(candidateGroupTestFound).isTrue();
    assertThat(candidateGroupTest2Found).isTrue();
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Aggregations

IdentityLink (org.activiti.engine.task.IdentityLink)64 Deployment (org.activiti.engine.test.Deployment)21 Task (org.activiti.engine.task.Task)16 ArrayList (java.util.ArrayList)13 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 RestIdentityLink (org.activiti.rest.service.api.engine.RestIdentityLink)7 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 List (java.util.List)4 TaskService (org.activiti.engine.TaskService)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 TaskQuery (org.activiti.engine.task.TaskQuery)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)2 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)2 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)2 RepositoryService (org.activiti.engine.RepositoryService)2