Search in sources :

Example 41 with IdentityLink

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

the class TaskIdentityLinksTest method testCandidateUserLink.

@Deployment(resources = "org/activiti/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.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 42 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);
    assertEquals("muppets", identityLink.getGroupId());
    assertNull("kermit", identityLink.getUserId());
    assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
    assertEquals(taskId, identityLink.getTaskId());
    assertEquals(1, identityLinks.size());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        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().isAtLeast(HistoryLevel.AUDIT)) {
        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());
}
Also used : Event(org.activiti.engine.task.Event) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 43 with IdentityLink

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

the class TaskServiceTest method testGetIdentityLinksWithOwner.

public void testGetIdentityLinksWithOwner() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    String taskId = task.getId();
    identityService.saveUser(identityService.newUser("kermit"));
    identityService.saveUser(identityService.newUser("fozzie"));
    taskService.claim(taskId, "kermit");
    taskService.delegateTask(taskId, "fozzie");
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    assertEquals(2, identityLinks.size());
    IdentityLink assignee = identityLinks.get(0);
    assertEquals("fozzie", assignee.getUserId());
    assertNull(assignee.getGroupId());
    assertEquals(IdentityLinkType.ASSIGNEE, assignee.getType());
    IdentityLink owner = identityLinks.get(1);
    assertEquals("kermit", owner.getUserId());
    assertNull(owner.getGroupId());
    assertEquals(IdentityLinkType.OWNER, owner.getType());
    //cleanup
    taskService.deleteTask(taskId, true);
    identityService.deleteUser("kermit");
    identityService.deleteUser("fozzie");
}
Also used : Task(org.activiti.engine.task.Task) IdentityLink(org.activiti.engine.task.IdentityLink)

Example 44 with IdentityLink

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

the class TaskIdentityLinkResource method getIdentityLink.

@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}/{identityId}/{type}", method = RequestMethod.GET, produces = "application/json")
public RestIdentityLink getIdentityLink(@PathVariable("taskId") String taskId, @PathVariable("family") String family, @PathVariable("identityId") String identityId, @PathVariable("type") String type, HttpServletRequest request) {
    Task task = getTaskFromRequest(taskId);
    validateIdentityLinkArguments(family, identityId, type);
    IdentityLink link = getIdentityLink(family, identityId, type, task.getId());
    return restResponseFactory.createRestIdentityLink(link);
}
Also used : Task(org.activiti.engine.task.Task) IdentityLink(org.activiti.engine.task.IdentityLink) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with IdentityLink

use of org.activiti.engine.task.IdentityLink in project midpoint by Evolveum.

the class WorkItemManager method releaseWorkItem.

public void releaseWorkItem(String workItemId, OperationResult parentResult) throws ObjectNotFoundException, SecurityViolationException {
    OperationResult result = parentResult.createSubresult(OPERATION_RELEASE_WORK_ITEM);
    result.addParam("workItemId", workItemId);
    try {
        MidPointPrincipal principal = securityEnforcer.getPrincipal();
        result.addContext("user", toShortString(principal.getUser()));
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Releasing work item {} by {}", workItemId, toShortString(principal.getUser()));
        }
        TaskService taskService = activitiEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(workItemId).singleResult();
        if (task == null) {
            throw new ObjectNotFoundException("The work item does not exist");
        }
        if (task.getAssignee() == null) {
            throw new SystemException("The work item is not assigned to a user");
        }
        if (!MiscDataUtil.stringToRef(task.getAssignee()).getOid().equals(principal.getOid())) {
            throw new SystemException("The work item is not assigned to the current user");
        }
        boolean candidateFound = false;
        for (IdentityLink link : taskService.getIdentityLinksForTask(workItemId)) {
            if (IdentityLinkType.CANDIDATE.equals(link.getType())) {
                candidateFound = true;
                break;
            }
        }
        if (!candidateFound) {
            throw new SystemException("It has no candidates to be offered to");
        }
        taskService.unclaim(workItemId);
        task = taskService.createTaskQuery().taskId(workItemId).singleResult();
        if (task == null) {
            throw new ObjectNotFoundException("The work item does not exist");
        }
        setNewAssignees(task, Collections.emptyList(), taskService);
    } catch (ObjectNotFoundException | SecurityViolationException | RuntimeException e) {
        result.recordFatalError("Couldn't release work item " + workItemId + ": " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Task(org.activiti.engine.task.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) TaskService(org.activiti.engine.TaskService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IdentityLink(org.activiti.engine.task.IdentityLink) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

IdentityLink (org.activiti.engine.task.IdentityLink)45 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)3 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