use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class ProcessDefinitionIdentityLinksResourceTest method testDeleteCandidateStarterFromProcessDefinition.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testDeleteCandidateStarterFromProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.addCandidateStarterGroup(processDefinition.getId(), "admin");
repositoryService.addCandidateStarterUser(processDefinition.getId(), "kermit");
// Delete user candidate
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "users", "kermit"));
CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
// Check if group-link remains
List<IdentityLink> remainingLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
assertEquals(1, remainingLinks.size());
assertEquals("admin", remainingLinks.get(0).getGroupId());
// Delete group candidate
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "groups", "admin"));
response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
// Check if all links are removed
remainingLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
assertEquals(0, remainingLinks.size());
}
use of org.activiti.engine.task.IdentityLink in project midpoint by Evolveum.
the class MiscDataUtil method isAmongCandidates.
// principal != null, principal.getOid() != null, principal.getUser() != null
private boolean isAmongCandidates(MidPointPrincipal principal, String taskId) {
String currentUserOid = principal.getOid();
List<IdentityLink> identityLinks;
try {
TaskService taskService = activitiEngine.getTaskService();
identityLinks = taskService.getIdentityLinksForTask(taskId);
} catch (ActivitiException e) {
throw new SystemException("Couldn't determine user authorization, because the task candidate users and groups couldn't be retrieved: " + e.getMessage(), e);
}
for (IdentityLink identityLink : identityLinks) {
if (identityLink.getUserId() != null && identityLink.getUserId().equals(currentUserOid)) {
return true;
}
if (identityLink.getGroupId() != null) {
if (isMemberOfActivitiGroup(principal.getUser(), identityLink.getGroupId())) {
return true;
}
}
}
return false;
}
use of org.activiti.engine.task.IdentityLink in project midpoint by Evolveum.
the class TestActivitiQuery method test210TestQueryByIdentityLink.
@Test
public void test210TestQueryByIdentityLink() throws Exception {
final String TEST_NAME = "test210TestQueryByIdentityLink";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
TaskService taskService = activitiEngine.getTaskService();
TaskQuery tq = taskService.createTaskQuery();
org.activiti.engine.task.Task task = tq.singleResult();
System.out.println("Task = " + task);
assertNotNull("No task", task);
final String TASK_NAME = "Approve assigning Role1a to jack";
List<IdentityLink> linksBefore = taskService.getIdentityLinksForTask(task.getId());
System.out.println("Identity links (before)" + linksBefore);
taskService.addUserIdentityLink(task.getId(), "123", CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
taskService.addUserIdentityLink(task.getId(), "456", CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
List<IdentityLink> linksAfter = taskService.getIdentityLinksForTask(task.getId());
System.out.println("Identity links (after)" + linksAfter);
TaskQuery tq1 = taskService.createTaskQuery().taskInvolvedUser("UserType:" + userLead1Oid).taskName(TASK_NAME);
assertFound(tq1, "involved user (assignee)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("123").taskName(TASK_NAME), "involved user (midpoint-assignee 123)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("456").taskName(TASK_NAME), "involved user (midpoint-assignee 456)");
assertNotFound(taskService.createTaskQuery().taskInvolvedUser("123xxx").taskName(TASK_NAME), "involved user (wrong user)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("123;124").taskName(TASK_NAME), "involved user (123 or 124)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("124;123").taskName(TASK_NAME), "involved user (124 or 123)");
assertNotFound(taskService.createTaskQuery().taskInvolvedUser("124x;123x").taskName(TASK_NAME), "involved user (124x or 123x)");
assertFound(taskService.createTaskQuery().or().taskInvolvedUser("123").taskCandidateGroup("xxxxxxx").endOr().taskName(TASK_NAME), "involved user (123 or candidate group xxxxxxx)");
assertFound(taskService.createTaskQuery().or().taskInvolvedUser("123;124").taskCandidateGroup("xxxxxxx").endOr().taskName(TASK_NAME), "involved user (123 or 124 or candidate group xxxxxxx)");
assertNotFound(taskService.createTaskQuery().or().taskInvolvedUser("123x;124x").taskCandidateGroup("xxxxxxx").endOr().taskName(TASK_NAME), "involved user (123x or 124x or candidate group xxxxxxx)");
}
use of org.activiti.engine.task.IdentityLink in project midpoint by Evolveum.
the class WorkItemManager method setNewAssignees.
private void setNewAssignees(Task task, List<ObjectReferenceType> assigneeRefList, TaskService taskService) {
List<String> assignees = MiscDataUtil.refsToStrings(assigneeRefList);
// check and optionally set task assignee
if (task.getAssignee() != null && !assignees.contains(task.getAssignee()) || task.getAssignee() == null && !assignees.isEmpty()) {
// we will nominate the first delegate (if present) as a new assignee
taskService.setAssignee(task.getId(), !assignees.isEmpty() ? assignees.get(0) : null);
}
// set task identity links
List<IdentityLink> currentLinks = taskService.getIdentityLinksForTask(task.getId());
for (IdentityLink currentLink : currentLinks) {
if (!CommonProcessVariableNames.MIDPOINT_ASSIGNEE.equals(currentLink.getType())) {
continue;
}
String assigneeFromLink = currentLink.getUserId() != null ? currentLink.getUserId() : currentLink.getGroupId();
if (assignees.contains(assigneeFromLink)) {
assignees.remove(assigneeFromLink);
} else {
if (currentLink.getUserId() != null) {
taskService.deleteUserIdentityLink(task.getId(), currentLink.getUserId(), CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
} else {
taskService.deleteGroupIdentityLink(task.getId(), currentLink.getGroupId(), CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
}
}
}
// process remaining assignees
for (String assignee : assignees) {
ObjectReferenceType assigneeRef = MiscDataUtil.stringToRef(assignee);
if (assigneeRef.getType() == null || QNameUtil.match(UserType.COMPLEX_TYPE, assigneeRef.getType())) {
taskService.addUserIdentityLink(task.getId(), assignee, CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
} else {
taskService.addGroupIdentityLink(task.getId(), assignee, CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
}
}
}
use of org.activiti.engine.task.IdentityLink in project midpoint by Evolveum.
the class ActivitiInterface method notifyMidpointAboutTaskEvent.
public void notifyMidpointAboutTaskEvent(DelegateTask delegateTask) {
OperationResult result = new OperationResult(DOT_CLASS + "notifyMidpointAboutTaskEvent");
TaskEvent taskEvent;
if (TaskListener.EVENTNAME_CREATE.equals(delegateTask.getEventName())) {
// TODO distinguish created vs. assigned event
taskEvent = new TaskCreatedEvent();
} else if (TaskListener.EVENTNAME_COMPLETE.equals(delegateTask.getEventName())) {
taskEvent = new TaskCompletedEvent();
} else if (TaskListener.EVENTNAME_DELETE.equals(delegateTask.getEventName())) {
taskEvent = new TaskDeletedEvent();
} else {
// ignoring other events
return;
}
taskEvent.setVariables(delegateTask.getVariables());
taskEvent.setAssigneeOid(delegateTask.getAssignee());
taskEvent.setTaskId(delegateTask.getId());
taskEvent.setTaskName(delegateTask.getName());
taskEvent.setProcessInstanceName((String) delegateTask.getVariable(CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_NAME));
taskEvent.setProcessInstanceId(delegateTask.getProcessInstanceId());
taskEvent.setCreateTime(delegateTask.getCreateTime());
taskEvent.setDueDate(delegateTask.getDueDate());
taskEvent.setExecutionId(delegateTask.getExecutionId());
taskEvent.setOwner(delegateTask.getOwner());
for (IdentityLink identityLink : delegateTask.getCandidates()) {
if (identityLink.getUserId() != null) {
taskEvent.getCandidateUsers().add(identityLink.getUserId());
} else if (identityLink.getGroupId() != null) {
taskEvent.getCandidateGroups().add(identityLink.getGroupId());
} else {
throw new IllegalStateException("Neither candidate user nor group id is provided in delegateTask: " + delegateTask);
}
}
try {
WorkItemType workItem = workItemProvider.taskEventToWorkItemNew(taskEvent, null, true, true, true, result);
wfTaskController.onTaskEvent(workItem, taskEvent, result);
} catch (Exception e) {
// todo fix the exception processing e.g. think about situation where an event cannot be audited - should we allow to proceed?
String message = "Couldn't process an event coming from the workflow management system";
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.recordFatalError(message, e);
}
}
Aggregations