Search in sources :

Example 16 with ProcessInfo

use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.

the class ProcessesParser method parseEntry.

@SuppressWarnings("unchecked")
@Override
public ProcessInfo parseEntry(JSONObject entry) {
    ProcessInfo processesRest = new ProcessInfo();
    processesRest.setId((String) entry.get("id"));
    processesRest.setProcessDefinitionId((String) entry.get("processDefinitionId"));
    processesRest.setProcessDefinitionKey((String) entry.get("processDefinitionKey"));
    processesRest.setStartedAt(WorkflowApiClient.parseDate(entry, "startedAt"));
    processesRest.setEndedAt(WorkflowApiClient.parseDate(entry, "endedAt"));
    processesRest.setDurationInMs((Long) entry.get("durationInMs"));
    processesRest.setDeleteReason((String) entry.get("deleteReason"));
    processesRest.setBusinessKey((String) entry.get("businessKey"));
    processesRest.setSuperProcessInstanceId((String) entry.get("superProcessInstanceId"));
    processesRest.setStartActivityId((String) entry.get("startActivityId"));
    processesRest.setStartUserId((String) entry.get("startUserId"));
    processesRest.setEndActivityId((String) entry.get("endActivityId"));
    processesRest.setCompleted((Boolean) entry.get("completed"));
    processesRest.setVariables((Map<String, Object>) entry.get("variables"));
    processesRest.setItems((Set<String>) entry.get("item"));
    if (entry.get("processVariables") != null) {
        List<Variable> processVariables = new ArrayList<Variable>();
        JSONArray variables = (JSONArray) entry.get("processVariables");
        for (int i = 0; i < variables.size(); i++) {
            JSONObject variableJSON = (JSONObject) variables.get(i);
            Variable variable = new Variable();
            variable.setName((String) variableJSON.get("name"));
            variable.setType((String) variableJSON.get("type"));
            variable.setValue(variableJSON.get("value"));
            processVariables.add(variable);
        }
        processesRest.setProcessVariables(processVariables);
    }
    return processesRest;
}
Also used : Variable(org.alfresco.rest.workflow.api.model.Variable) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo)

Example 17 with ProcessInfo

use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testDeleteTaskItem.

@Test
@SuppressWarnings("unchecked")
public void testDeleteTaskItem() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
    RequestContext otherContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    // Create test-document and add to package
    NodeRef[] docNodeRefs = createTestDocuments(requestContext);
    ProcessInfo processInfo = startAdhocProcess(requestContext, docNodeRefs);
    final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
    assertNotNull(task);
    activitiProcessEngine.getTaskService().setAssignee(task.getId(), null);
    try {
        TasksClient tasksClient = publicApiClient.tasksClient();
        tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
        try {
            tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // delete item as admin
        JSONObject createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        JSONObject result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
        assertNotNull(result);
        assertEquals(docNodeRefs[0].getId(), result.get("id"));
        JSONObject itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        publicApiClient.setRequestContext(adminContext);
        tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
        try {
            tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // delete item with candidate user
        createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
        assertNotNull(result);
        assertEquals(docNodeRefs[0].getId(), result.get("id"));
        itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPerson);
        publicApiClient.setRequestContext(otherContext);
        tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
        try {
            tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // delete item with not involved user
        createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
        assertNotNull(result);
        assertEquals(docNodeRefs[0].getId(), result.get("id"));
        itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherPerson);
        publicApiClient.setRequestContext(otherContext);
        try {
            tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(403, e.getHttpResponse().getStatusCode());
        }
        // delete item with user from candidate group with no assignee
        List<MemberOfSite> memberships = getTestFixture().getNetwork(otherContext.getNetworkId()).getSiteMemberships(otherContext.getRunAsUser());
        assertTrue(memberships.size() > 0);
        MemberOfSite memberOfSite = memberships.get(0);
        String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
        activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherContext.getRunAsUser());
        activitiProcessEngine.getTaskService().addCandidateGroup(task.getId(), group);
        publicApiClient.setRequestContext(otherContext);
        createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
        assertNotNull(result);
        assertEquals(docNodeRefs[0].getId(), result.get("id"));
        itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
        try {
            tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // delete item with user from candidate group with assignee
        activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
        publicApiClient.setRequestContext(requestContext);
        createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
        assertNotNull(result);
        assertEquals(docNodeRefs[0].getId(), result.get("id"));
        itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        publicApiClient.setRequestContext(otherContext);
        try {
            tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(403, e.getHttpResponse().getStatusCode());
        }
        publicApiClient.setRequestContext(requestContext);
        itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
        try {
            tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // invalid task id
        publicApiClient.setRequestContext(requestContext);
        try {
            tasksClient.deleteTaskItem("fakeid", docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // invalid item id
        try {
            tasksClient.deleteTaskItem(task.getId(), "fakeid");
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
        // delete item from completed task
        createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
        assertNotNull(result);
        assertEquals(docNodeRefs[0].getId(), result.get("id"));
        itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                activitiProcessEngine.getTaskService().complete(task.getId());
                return null;
            }
        }, requestContext.getRunAsUser(), requestContext.getNetworkId());
        try {
            tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
            fail("Expected exception");
        } catch (PublicApiException e) {
            assertEquals(404, e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(processInfo.getId());
    }
}
Also used : Task(org.activiti.engine.task.Task) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 18 with ProcessInfo

use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testTaskStateTransitions.

@Test
@SuppressWarnings("unchecked")
public void testTaskStateTransitions() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInfo processInstance = startAdhocProcess(requestContext, null);
    try {
        Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        TasksClient tasksClient = publicApiClient.tasksClient();
        // Unclaimed to claimed
        JSONObject taskBody = new JSONObject();
        taskBody.put("state", "claimed");
        List<String> selectedFields = new ArrayList<String>();
        selectedFields.addAll(Arrays.asList(new String[] { "state", "assignee" }));
        JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
        assertEquals("claimed", result.get("state"));
        // claimed to unclaimed
        taskBody = new JSONObject();
        taskBody.put("state", "unclaimed");
        result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
        assertEquals("unclaimed", result.get("state"));
    } finally {
        cleanupProcessInstance(processInstance.getId());
    }
}
Also used : Task(org.activiti.engine.task.Task) JSONObject(org.json.simple.JSONObject) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ArrayList(java.util.ArrayList) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 19 with ProcessInfo

use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testSetOutcome.

@Test
@SuppressWarnings("unchecked")
public void testSetOutcome() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInfo processInf = startReviewPooledProcess(requestContext);
    Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInf.getId()).singleResult();
    TasksClient tasksClient = publicApiClient.tasksClient();
    activitiProcessEngine.getTaskService().saveTask(task);
    Map<String, String> params = new HashMap<String, String>();
    params.put("select", "state,variables");
    HttpResponse response = tasksClient.update("tasks", task.getId(), null, null, "{\"state\":\"completed\",\"variables\":[{\"name\":\"wf_reviewOutcome\",\"value\":\"Approve\",\"scope\":\"local\"},{\"name\":\"bpm_comment\",\"value\":\"approved by me\",\"scope\":\"local\"}]}", params, "Failed to update task", 200);
    HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().includeTaskLocalVariables().singleResult();
    String outcome = (String) historyTask.getTaskLocalVariables().get("bpm_outcome");
    assertEquals("Approve", outcome);
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 20 with ProcessInfo

use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testGetTaskVariablesReview.

@Test
public void testGetTaskVariablesReview() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInfo processInstance = startParallelReviewProcess(requestContext);
    try {
        Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).taskAssignee(requestContext.getRunAsUser()).singleResult();
        assertNotNull(task);
        TasksClient tasksClient = publicApiClient.tasksClient();
        JSONObject variables = tasksClient.findTaskVariables(task.getId());
        assertNotNull(variables);
        JSONObject list = (JSONObject) variables.get("list");
        assertNotNull(list);
        JSONArray entries = (JSONArray) list.get("entries");
        assertNotNull(entries);
        // Check pagination object for size
        JSONObject pagination = (JSONObject) list.get("pagination");
        assertNotNull(pagination);
        assertEquals(42L, pagination.get("count"));
        assertEquals(42L, pagination.get("totalItems"));
        assertEquals(0L, pagination.get("skipCount"));
        assertFalse((Boolean) pagination.get("hasMoreItems"));
    } finally {
        cleanupProcessInstance(processInstance.getId());
    }
}
Also used : Task(org.activiti.engine.task.Task) JSONObject(org.json.simple.JSONObject) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) JSONArray(org.json.simple.JSONArray) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Aggregations

ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)40 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)36 Test (org.junit.Test)36 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)26 JSONObject (org.json.simple.JSONObject)26 ProcessesClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient)16 Task (org.activiti.engine.task.Task)13 HashMap (java.util.HashMap)12 JSONArray (org.json.simple.JSONArray)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)8 ArrayList (java.util.ArrayList)6 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)4 Date (java.util.Date)3 List (java.util.List)3 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)3 Variable (org.alfresco.rest.workflow.api.model.Variable)3 Calendar (java.util.Calendar)2