Search in sources :

Example 1 with HistoricIdentityLink

use of org.activiti.engine.history.HistoricIdentityLink in project Activiti by Activiti.

the class GetHistoricIdentityLinksForTaskCmd method getLinksForTask.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected List<HistoricIdentityLink> getLinksForTask(CommandContext commandContext) {
    HistoricTaskInstanceEntity task = commandContext.getHistoricTaskInstanceEntityManager().findHistoricTaskInstanceById(taskId);
    if (task == null) {
        throw new ActivitiObjectNotFoundException("No historic task exists with the given id: " + taskId, HistoricTaskInstance.class);
    }
    List<HistoricIdentityLink> identityLinks = (List) commandContext.getHistoricIdentityLinkEntityManager().findHistoricIdentityLinksByTaskId(taskId);
    // Similar to GetIdentityLinksForTask, return assignee and owner as identity link
    if (task.getAssignee() != null) {
        HistoricIdentityLinkEntity identityLink = new HistoricIdentityLinkEntity();
        identityLink.setUserId(task.getAssignee());
        identityLink.setTaskId(task.getId());
        identityLink.setType(IdentityLinkType.ASSIGNEE);
        identityLinks.add(identityLink);
    }
    if (task.getOwner() != null) {
        HistoricIdentityLinkEntity identityLink = new HistoricIdentityLinkEntity();
        identityLink.setTaskId(task.getId());
        identityLink.setUserId(task.getOwner());
        identityLink.setType(IdentityLinkType.OWNER);
        identityLinks.add(identityLink);
    }
    return identityLinks;
}
Also used : HistoricIdentityLink(org.activiti.engine.history.HistoricIdentityLink) List(java.util.List) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) HistoricTaskInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity) HistoricIdentityLinkEntity(org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntity)

Example 2 with HistoricIdentityLink

use of org.activiti.engine.history.HistoricIdentityLink in project Activiti by Activiti.

the class RestResponseFactory method createHistoricIdentityLinkResponseList.

public List<HistoricIdentityLinkResponse> createHistoricIdentityLinkResponseList(List<HistoricIdentityLink> identityLinks) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<HistoricIdentityLinkResponse> responseList = new ArrayList<HistoricIdentityLinkResponse>();
    for (HistoricIdentityLink instance : identityLinks) {
        responseList.add(createHistoricIdentityLinkResponse(instance, urlBuilder));
    }
    return responseList;
}
Also used : HistoricIdentityLinkResponse(org.activiti.rest.service.api.history.HistoricIdentityLinkResponse) HistoricIdentityLink(org.activiti.engine.history.HistoricIdentityLink) ArrayList(java.util.ArrayList)

Example 3 with HistoricIdentityLink

use of org.activiti.engine.history.HistoricIdentityLink in project Activiti by Activiti.

the class HistoricProcessInstanceTest method testHistoricIdenityLinksOnProcessInstance.

@Deployment(resources = { "org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricIdenityLinksOnProcessInstance() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        runtimeService.addUserIdentityLink(pi.getId(), "kermit", "myType");
        // Check historic links
        List<HistoricIdentityLink> historicLinks = historyService.getHistoricIdentityLinksForProcessInstance(pi.getId());
        assertEquals(1, historicLinks.size());
        assertEquals("myType", historicLinks.get(0).getType());
        assertEquals("kermit", historicLinks.get(0).getUserId());
        assertNull(historicLinks.get(0).getGroupId());
        assertEquals(pi.getId(), historicLinks.get(0).getProcessInstanceId());
        // When process is ended, link should remain
        taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
        assertNull(runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult());
        assertEquals(1, historyService.getHistoricIdentityLinksForProcessInstance(pi.getId()).size());
        // When process is deleted, identitylinks shouldn't exist anymore
        historyService.deleteHistoricProcessInstance(pi.getId());
        assertEquals(0, historyService.getHistoricIdentityLinksForProcessInstance(pi.getId()).size());
    }
}
Also used : HistoricIdentityLink(org.activiti.engine.history.HistoricIdentityLink) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 4 with HistoricIdentityLink

use of org.activiti.engine.history.HistoricIdentityLink in project Activiti by Activiti.

the class HistoricTaskInstanceTest method testHistoricIdentityLinksOnTask.

@Deployment
public void testHistoricIdentityLinksOnTask() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("historicIdentityLinks");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    // Set additional identity-link not coming from process
    taskService.addUserIdentityLink(task.getId(), "gonzo", "customUseridentityLink");
    assertEquals(4, taskService.getIdentityLinksForTask(task.getId()).size());
    // Check historic identity-links when task is still active
    List<HistoricIdentityLink> historicIdentityLinks = historyService.getHistoricIdentityLinksForTask(task.getId());
    assertEquals(4, historicIdentityLinks.size());
    // Validate all links
    boolean foundCandidateUser = false, foundCandidateGroup = false, foundAssignee = false, foundCustom = false;
    for (HistoricIdentityLink link : historicIdentityLinks) {
        assertEquals(task.getId(), link.getTaskId());
        if (link.getGroupId() != null) {
            assertEquals("sales", link.getGroupId());
            foundCandidateGroup = true;
        } else {
            if (link.getType().equals("candidate")) {
                assertEquals("fozzie", link.getUserId());
                foundCandidateUser = true;
            } else if (link.getType().equals("assignee")) {
                assertEquals("kermit", link.getUserId());
                foundAssignee = true;
            } else if (link.getType().equals("customUseridentityLink")) {
                assertEquals("gonzo", link.getUserId());
                foundCustom = true;
            }
        }
    }
    assertTrue(foundAssignee);
    assertTrue(foundCandidateGroup);
    assertTrue(foundCandidateUser);
    assertTrue(foundCustom);
    // Now complete the task and check if links are still there
    taskService.complete(task.getId());
    assertEquals(4, historyService.getHistoricIdentityLinksForTask(task.getId()).size());
    // After deleting historic task, exception should be thrown when trying to get links
    historyService.deleteHistoricTaskInstance(task.getId());
    try {
        historyService.getHistoricIdentityLinksForTask(task.getId()).size();
        fail("Exception expected");
    } catch (ActivitiObjectNotFoundException aonfe) {
        assertEquals(HistoricTaskInstance.class, aonfe.getObjectClass());
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricIdentityLink(org.activiti.engine.history.HistoricIdentityLink) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricIdentityLink (org.activiti.engine.history.HistoricIdentityLink)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Deployment (org.activiti.engine.test.Deployment)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 HistoricIdentityLinkEntity (org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntity)1 HistoricTaskInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity)1 Task (org.activiti.engine.task.Task)1 HistoricIdentityLinkResponse (org.activiti.rest.service.api.history.HistoricIdentityLinkResponse)1