Search in sources :

Example 36 with IdentityLink

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

the class IdentityLinkEventsTest method testProcessDefinitionIdentityLinkEvents.

/**
	 * Check identity links on process definitions. 
	 */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessDefinitionIdentityLinkEvents() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").singleResult();
    assertNotNull(processDefinition);
    // Add candidate user and group
    repositoryService.addCandidateStarterUser(processDefinition.getId(), "kermit");
    repositoryService.addCandidateStarterGroup(processDefinition.getId(), "sales");
    assertEquals(4, listener.getEventsReceived().size());
    ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    listener.clearEventsReceived();
    // Delete identity links
    repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "kermit");
    repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), "sales");
    assertEquals(2, listener.getEventsReceived().size());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 37 with IdentityLink

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

the class IdentityLinkEventsTest method testProcessInstanceIdentityLinkEvents.

/**
	 * Check identity links on process instances. 
	 */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceIdentityLinkEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // Add identity link
    runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "test");
    assertEquals(2, listener.getEventsReceived().size());
    ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    IdentityLink link = (IdentityLink) event.getEntity();
    assertEquals("kermit", link.getUserId());
    assertEquals("test", link.getType());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    listener.clearEventsReceived();
    // Deleting process should delete identity link
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    assertEquals(1, listener.getEventsReceived().size());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    link = (IdentityLink) event.getEntity();
    assertEquals("kermit", link.getUserId());
    assertEquals("test", link.getType());
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 38 with IdentityLink

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

the class StartAuthorizationTest method testIdentityLinks.

@Deployment
public void testIdentityLinks() throws Exception {
    setUpUsersAndGroups();
    try {
        ProcessDefinition latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").singleResult();
        assertNotNull(latestProcessDef);
        List<IdentityLink> links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
        assertEquals(0, links.size());
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
        assertNotNull(latestProcessDef);
        links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
        assertEquals(2, links.size());
        assertEquals(true, containsUserOrGroup("user1", null, links));
        assertEquals(true, containsUserOrGroup("user2", null, links));
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process3").singleResult();
        assertNotNull(latestProcessDef);
        links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
        assertEquals(1, links.size());
        assertEquals("user1", links.get(0).getUserId());
        latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process4").singleResult();
        assertNotNull(latestProcessDef);
        links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
        assertEquals(4, links.size());
        assertEquals(true, containsUserOrGroup("userInGroup2", null, links));
        assertEquals(true, containsUserOrGroup(null, "group1", links));
        assertEquals(true, containsUserOrGroup(null, "group2", links));
        assertEquals(true, containsUserOrGroup(null, "group3", links));
    } finally {
        tearDownUsersAndGroups();
    }
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 39 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);
    assertEquals("muppets", identityLink.getGroupId());
    assertNull("kermit", identityLink.getUserId());
    assertEquals("playing", identityLink.getType());
    assertEquals(taskId, identityLink.getTaskId());
    assertEquals(1, identityLinks.size());
    taskService.deleteGroupIdentityLink(taskId, "muppets", "playing");
    assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
Also used : IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 40 with IdentityLink

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

the class TaskIdentityLinksTest method testEmptyCandidateUserLink.

@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testEmptyCandidateUserLink() {
    runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
    String taskId = taskService.createTaskQuery().singleResult().getId();
    taskService.addCandidateGroup(taskId, "muppets");
    taskService.deleteCandidateUser(taskId, "kermit");
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    assertNotNull(identityLinks);
    assertEquals(1, identityLinks.size());
    IdentityLink identityLink = identityLinks.get(0);
    assertEquals("muppets", identityLink.getGroupId());
    assertEquals(null, identityLink.getUserId());
    assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
    assertEquals(taskId, identityLink.getTaskId());
    taskService.deleteCandidateGroup(taskId, "muppets");
    assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
Also used : 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