Search in sources :

Example 31 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 32 with IdentityLink

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

the class ProcessInstanceIdentityLinksTest method testCustomLinkGroupLink.

@Deployment(resources = "org/activiti/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
    runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
    String processInstanceId = runtimeService.createProcessInstanceQuery().singleResult().getId();
    runtimeService.addGroupIdentityLink(processInstanceId, "muppets", "playing");
    List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
    IdentityLink identityLink = identityLinks.get(0);
    assertEquals("muppets", identityLink.getGroupId());
    assertNull("kermit", identityLink.getUserId());
    assertEquals("playing", identityLink.getType());
    assertEquals(processInstanceId, identityLink.getProcessInstanceId());
    assertEquals(1, identityLinks.size());
    runtimeService.deleteGroupIdentityLink(processInstanceId, "muppets", "playing");
    assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
Also used : IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 33 with IdentityLink

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

the class ProcessDefinitionIdentityLinksResourceTest method testAddCandidateStarterToProcessDefinition.

@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testAddCandidateStarterToProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    // Create user candidate
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("user", "kermit");
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINKS_COLLECTION, processDefinition.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("kermit", responseNode.get("user").textValue());
    assertEquals("candidate", responseNode.get("type").textValue());
    assertTrue(responseNode.get("group").isNull());
    assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "users", "kermit")));
    List<IdentityLink> createdLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
    assertEquals(1, createdLinks.size());
    assertEquals("kermit", createdLinks.get(0).getUserId());
    assertEquals("candidate", createdLinks.get(0).getType());
    repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "kermit");
    // Create group candidate
    requestNode = objectMapper.createObjectNode();
    requestNode.put("group", "admin");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("admin", responseNode.get("group").textValue());
    assertEquals("candidate", responseNode.get("type").textValue());
    assertTrue(responseNode.get("user").isNull());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "groups", "admin")));
    createdLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
    assertEquals(1, createdLinks.size());
    assertEquals("admin", createdLinks.get(0).getGroupId());
    assertEquals("candidate", createdLinks.get(0).getType());
    repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "admin");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 34 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;
            }
        }
    }
    assertFalse(candidateGroupTestFound);
    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;
            }
        }
    }
    assertTrue(candidateGroupTestFound);
    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;
            }
        }
    }
    assertTrue(candidateGroupTestFound);
    assertTrue(candidateGroupTest2Found);
    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)

Example 35 with IdentityLink

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

the class DynamicUserTaskTest method testChangeCandidateUsers.

@Deployment(resources = { "org/activiti/engine/test/bpmn/usertask/DynamicUserTaskTest.basictask.bpmn20.xml" })
public void testChangeCandidateUsers() {
    // 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 candidateUserTestFound = false;
    for (IdentityLink identityLink : taskIdentityLinks) {
        if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getUserId() != null && identityLink.getGroupId() == null) {
            if ("test".equals(identityLink.getUserId())) {
                candidateUserTestFound = true;
            }
        }
    }
    assertFalse(candidateUserTestFound);
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
    // now test with changing the form key
    ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateUser("task1", "test", true);
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
    candidateUserTestFound = false;
    for (IdentityLink identityLink : taskIdentityLinks) {
        if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getUserId() != null && identityLink.getGroupId() == null) {
            if ("test".equals(identityLink.getUserId())) {
                candidateUserTestFound = true;
            }
        }
    }
    assertTrue(candidateUserTestFound);
    taskService.complete(task.getId());
    infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);
    dynamicBpmnService.changeUserTaskCandidateUser("task1", "test2", false, infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
    candidateUserTestFound = false;
    boolean candidateUserTest2Found = false;
    for (IdentityLink identityLink : taskIdentityLinks) {
        if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getUserId() != null && identityLink.getGroupId() == null) {
            if ("test".equals(identityLink.getUserId())) {
                candidateUserTestFound = true;
            } else if ("test2".equals(identityLink.getUserId())) {
                candidateUserTest2Found = true;
            }
        }
    }
    assertTrue(candidateUserTestFound);
    assertTrue(candidateUserTest2Found);
    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)46 Deployment (org.activiti.engine.test.Deployment)21 Task (org.activiti.engine.task.Task)15 RestIdentityLink (org.activiti.rest.service.api.engine.RestIdentityLink)8 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 TaskService (org.activiti.engine.TaskService)3 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)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 Event (org.activiti.engine.task.Event)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)1