Search in sources :

Example 26 with IdentityLink

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());
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 27 with IdentityLink

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;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskService(org.activiti.engine.TaskService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) IdentityLink(org.activiti.engine.task.IdentityLink)

Example 28 with IdentityLink

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)");
}
Also used : TaskService(org.activiti.engine.TaskService) TaskQuery(org.activiti.engine.task.TaskQuery) IdentityLink(org.activiti.engine.task.IdentityLink) Test(org.testng.annotations.Test)

Example 29 with IdentityLink

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);
        }
    }
}
Also used : ObjectTypeUtil.toShortString(com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString) IdentityLink(org.activiti.engine.task.IdentityLink)

Example 30 with IdentityLink

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);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IdentityLink(org.activiti.engine.task.IdentityLink) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)

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