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