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;
}
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;
}
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());
}
}
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());
}
}
Aggregations