Search in sources :

Example 6 with ProcessInfo

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

the class ProcessWorkflowApiTest method testDeleteProcessItem.

@Test
public void testDeleteProcessItem() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    NodeRef[] docNodeRefs = createTestDocuments(requestContext);
    final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
    try {
        assertNotNull(processRest);
        final String newProcessInstanceId = processRest.getId();
        ProcessesClient processesClient = publicApiClient.processesClient();
        // Delete the item
        processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
        // Fetching the item should result in 404
        try {
            publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("The entity with id: " + docNodeRefs[0].getId() + " was not found", expected.getHttpResponse());
        }
        // Deleting the item again should give an error
        try {
            processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
            fail("Expected not found");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 7 with ProcessInfo

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

the class ProcessWorkflowApiTest method testAddProcessItem.

@Test
@SuppressWarnings("unchecked")
public void testAddProcessItem() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    NodeRef[] docNodeRefs = createTestDocuments(requestContext);
    final ProcessInfo processRest = startAdhocProcess(requestContext, null);
    try {
        assertNotNull(processRest);
        final String newProcessInstanceId = processRest.getId();
        ProcessesClient processesClient = publicApiClient.processesClient();
        JSONObject createItemObject = new JSONObject();
        createItemObject.put("id", docNodeRefs[0].getId());
        // Add the item
        processesClient.addProcessItem(newProcessInstanceId, createItemObject.toJSONString());
        // Fetching the item
        JSONObject itemJSON = publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
        assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
        assertEquals("Test Doc1", itemJSON.get("name"));
        assertEquals("Test Doc1 Title", itemJSON.get("title"));
        assertEquals("Test Doc1 Description", itemJSON.get("description"));
        assertNotNull(itemJSON.get("createdAt"));
        assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
        assertNotNull(itemJSON.get("modifiedAt"));
        assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
        assertNotNull(itemJSON.get("size"));
        assertNotNull(itemJSON.get("mimeType"));
        // add non existing item
        createItemObject = new JSONObject();
        createItemObject.put("id", "blablabla");
        // Add the item
        try {
            processesClient.addProcessItem(newProcessInstanceId, createItemObject.toJSONString());
            fail("not found expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 8 with ProcessInfo

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

the class ProcessWorkflowApiTest method testUpdateProcessVariables.

@SuppressWarnings("unchecked")
@Test
public void testUpdateProcessVariables() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    ProcessInfo processRest = startAdhocProcess(requestContext, null);
    try {
        assertNotNull(processRest);
        String processId = processRest.getId();
        // Update an unexisting variable, creates a new one using explicit typing (d:long)
        JSONObject variableJson = new JSONObject();
        variableJson.put("name", "newVariable");
        variableJson.put("value", 1234L);
        variableJson.put("type", "d:long");
        JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
        assertNotNull(resultEntry);
        JSONObject result = (JSONObject) resultEntry.get("entry");
        assertEquals("newVariable", result.get("name"));
        assertEquals(1234L, result.get("value"));
        assertEquals("d:long", result.get("type"));
        assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
        // Update an unexisting variable, creates a new one using no tying
        variableJson = new JSONObject();
        variableJson.put("name", "stringVariable");
        variableJson.put("value", "This is a string value");
        resultEntry = publicApiClient.processesClient().updateVariable(processId, "stringVariable", variableJson);
        assertNotNull(resultEntry);
        result = (JSONObject) resultEntry.get("entry");
        assertEquals("stringVariable", result.get("name"));
        assertEquals("This is a string value", result.get("value"));
        assertEquals("d:text", result.get("type"));
        assertEquals("This is a string value", activitiProcessEngine.getRuntimeService().getVariable(processId, "stringVariable"));
        // Update an existing variable, creates a new one using explicit typing (d:long)
        variableJson = new JSONObject();
        variableJson.put("name", "newVariable");
        variableJson.put("value", 4567L);
        variableJson.put("type", "d:long");
        resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
        assertNotNull(resultEntry);
        result = (JSONObject) resultEntry.get("entry");
        assertEquals("newVariable", result.get("name"));
        assertEquals(4567L, result.get("value"));
        assertEquals("d:long", result.get("type"));
        assertEquals(4567L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
        JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processId);
        assertNotNull(processvariables);
        JSONObject newVariableEntry = null;
        JSONArray entries = (JSONArray) processvariables.get("entries");
        assertNotNull(entries);
        for (int i = 0; i < entries.size(); i++) {
            JSONObject entry = (JSONObject) entries.get(i);
            assertNotNull(entry);
            entry = (JSONObject) entry.get("entry");
            assertNotNull(entry);
            if ("newVariable".equals((String) entry.get("name"))) {
                newVariableEntry = entry;
            }
        }
        assertNotNull(newVariableEntry);
        assertEquals(4567L, newVariableEntry.get("value"));
        // Update an existing variable, creates a new one using no explicit typing
        variableJson = new JSONObject();
        variableJson.put("name", "stringVariable");
        variableJson.put("value", "Updated string variable");
        resultEntry = publicApiClient.processesClient().updateVariable(processId, "stringVariable", variableJson);
        assertNotNull(resultEntry);
        result = (JSONObject) resultEntry.get("entry");
        assertEquals("stringVariable", result.get("name"));
        assertEquals("Updated string variable", result.get("value"));
        assertEquals("d:text", result.get("type"));
        assertEquals("Updated string variable", activitiProcessEngine.getRuntimeService().getVariable(processId, "stringVariable"));
        // Update an unexisting variable with wrong variable data
        variableJson = new JSONObject();
        variableJson.put("name", "newLongVariable");
        variableJson.put("value", "text");
        variableJson.put("type", "d:long");
        try {
            publicApiClient.processesClient().updateVariable(processId, "newLongVariable", variableJson);
            fail("Expected server error exception");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
        }
        // Update an unexisting variable with no variable data
        variableJson = new JSONObject();
        variableJson.put("name", "newNoValueVariable");
        variableJson.put("type", "d:datetime");
        resultEntry = publicApiClient.processesClient().updateVariable(processId, "newNoValueVariable", variableJson);
        assertNotNull(resultEntry);
        result = (JSONObject) resultEntry.get("entry");
        assertEquals("newNoValueVariable", result.get("name"));
        assertNotNull(result.get("value"));
        assertEquals("d:datetime", result.get("type"));
        assertNotNull(activitiProcessEngine.getRuntimeService().getVariable(processId, "newNoValueVariable"));
        // Test update variable with admin user
        publicApiClient.setRequestContext(adminContext);
        variableJson = new JSONObject();
        variableJson.put("name", "newVariable");
        variableJson.put("value", 1234L);
        variableJson.put("type", "d:long");
        resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
        assertNotNull(resultEntry);
        result = (JSONObject) resultEntry.get("entry");
        assertEquals("newVariable", result.get("name"));
        assertEquals(1234L, result.get("value"));
        assertEquals("d:long", result.get("type"));
        assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
    // test update variable with admin user that also started the process instance
    processRest = startAdhocProcess(adminContext, null);
    try {
        assertNotNull(processRest);
        String processId = processRest.getId();
        // Update an unexisting variable, creates a new one using explicit typing (d:long)
        JSONObject variableJson = new JSONObject();
        variableJson.put("name", "newVariable");
        variableJson.put("value", 1234L);
        variableJson.put("type", "d:long");
        JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
        assertNotNull(resultEntry);
        JSONObject result = (JSONObject) resultEntry.get("entry");
        assertEquals("newVariable", result.get("name"));
        assertEquals(1234L, result.get("value"));
        assertEquals("d:long", result.get("type"));
        assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
        // test update variable with user not involved in the process instance
        publicApiClient.setRequestContext(requestContext);
        try {
            publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
            fail("Expected forbidden exception");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) 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)

Example 9 with ProcessInfo

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

the class ProcessWorkflowApiTest method testGetProcessInstances.

@Test
public void testGetProcessInstances() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    final ProcessInfo process1 = startAdhocProcess(requestContext, null);
    final ProcessInfo process2 = startAdhocProcess(requestContext, null);
    final ProcessInfo process3 = startAdhocProcess(requestContext, null);
    try {
        ProcessesClient processesClient = publicApiClient.processesClient();
        Map<String, String> paramMap = new HashMap<String, String>();
        ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        Map<String, ProcessInfo> processMap = new HashMap<String, ProcessInfo>();
        for (ProcessInfo processRest : processList.getList()) {
            processMap.put(processRest.getId(), processRest);
        }
        assertTrue(processMap.containsKey(process1.getId()));
        assertTrue(processMap.containsKey(process2.getId()));
        assertTrue(processMap.containsKey(process3.getId()));
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        assertNull(processList.getList().get(0).getProcessVariables());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc2')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "2");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(2, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "3");
        paramMap.put("skipCount", "1");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(2, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "5");
        paramMap.put("skipCount", "2");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "5");
        paramMap.put("skipCount", "5");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'completed')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'any')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'active')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'active2')");
        try {
            processList = processesClient.getProcesses(paramMap);
            fail();
        } catch (PublicApiException e) {
        // expected exception
        }
        // Test the variable where-clause
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority = 'd_int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority = 'd:int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority > 'd:int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority >= 'd:int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority < 'd:int 5')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority <= 'd:int 4')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority = 'd_int 5')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        // test with date variable
        Calendar dateCal = Calendar.getInstance();
        Map<String, Object> variablesToSet = new HashMap<String, Object>();
        variablesToSet.put("testVarDate", dateCal.getTime());
        activitiProcessEngine.getRuntimeService().setVariables(process1.getId(), variablesToSet);
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/testVarDate = 'd_datetime " + ISO8601DateFormat.format(dateCal.getTime()) + "')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        // include process variables as well
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(includeVariables=true)");
        paramMap.put("maxItems", "1");
        paramMap.put("skipCount", "0");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
        paramMap.put("maxItems", "1");
        paramMap.put("skipCount", "0");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        ProcessInfo processInfo = processList.getList().get(0);
        assertNotNull(processInfo.getProcessVariables());
        boolean foundDescription = false;
        boolean foundAssignee = false;
        for (Variable variable : processInfo.getProcessVariables()) {
            if ("bpm_description".equals(variable.getName())) {
                assertEquals("d:text", variable.getType());
                assertNull(variable.getValue());
                foundDescription = true;
            } else if ("bpm_assignee".equals(variable.getName())) {
                assertEquals("cm:person", variable.getType());
                assertEquals(requestContext.getRunAsUser(), variable.getValue());
                foundAssignee = true;
            }
        }
        assertTrue(foundDescription);
        assertTrue(foundAssignee);
        // include process variables with paging
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
        paramMap.put("maxItems", "3");
        paramMap.put("skipCount", "1");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(2, processList.getList().size());
        processInfo = processList.getList().get(0);
        assertNotNull(processInfo.getProcessVariables());
        foundDescription = false;
        foundAssignee = false;
        for (Variable variable : processInfo.getProcessVariables()) {
            if ("bpm_description".equals(variable.getName())) {
                assertEquals("d:text", variable.getType());
                assertNull(variable.getValue());
                foundDescription = true;
            } else if ("bpm_assignee".equals(variable.getName())) {
                assertEquals("cm:person", variable.getType());
                assertEquals(requestContext.getRunAsUser(), variable.getValue());
                foundAssignee = true;
            }
        }
        assertTrue(foundDescription);
        assertTrue(foundAssignee);
        // include process variables with paging outside boundaries
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
        paramMap.put("maxItems", "4");
        paramMap.put("skipCount", "5");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
    } finally {
        cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Variable(org.alfresco.rest.workflow.api.model.Variable) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 10 with ProcessInfo

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

the class ProcessWorkflowApiTest method testGetProcessTasks.

@Test
public void testGetProcessTasks() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
    RequestContext otherPersonContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
    final ProcessInfo process1 = startAdhocProcess(requestContext, null);
    try {
        ProcessesClient processesClient = publicApiClient.processesClient();
        Map<String, String> paramMap = new HashMap<String, String>();
        JSONObject tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        JSONArray entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        JSONObject taskJSONObject = (JSONObject) ((JSONObject) entriesJSON.get(0)).get("entry");
        assertNotNull(taskJSONObject.get("id"));
        assertEquals(process1.getId(), taskJSONObject.get("processId"));
        assertEquals(process1.getProcessDefinitionId(), taskJSONObject.get("processDefinitionId"));
        assertEquals("adhocTask", taskJSONObject.get("activityDefinitionId"));
        assertEquals("Adhoc Task", taskJSONObject.get("name"));
        assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
        assertEquals(2l, taskJSONObject.get("priority"));
        assertEquals("wf:adhocTask", taskJSONObject.get("formResourceKey"));
        assertNull(taskJSONObject.get("endedAt"));
        assertNull(taskJSONObject.get("durationInMs"));
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "active");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "completed");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 0);
        paramMap = new HashMap<String, String>();
        try {
            processesClient.getTasks("fakeid", paramMap);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("The entity with id: fakeid was not found", expected.getHttpResponse());
        }
        // get tasks with admin from the same tenant as the process initiator
        publicApiClient.setRequestContext(adminContext);
        paramMap = new HashMap<String, String>();
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        // get tasks with admin from another tenant as the process initiator
        publicApiClient.setRequestContext(otherContext);
        paramMap = new HashMap<String, String>();
        try {
            tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
        // get task with other not-involved person
        publicApiClient.setRequestContext(otherPersonContext);
        paramMap = new HashMap<String, String>();
        try {
            tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
        // involve other person and get task
        final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(process1.getId()).singleResult();
        activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPersonContext.getRunAsUser());
        publicApiClient.setRequestContext(otherPersonContext);
        paramMap = new HashMap<String, String>();
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        // complete task and get tasks
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                activitiProcessEngine.getTaskService().complete(task.getId());
                return null;
            }
        }, requestContext.getRunAsUser(), requestContext.getNetworkId());
        publicApiClient.setRequestContext(requestContext);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "any");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
        publicApiClient.setRequestContext(otherPersonContext);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "any");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
    } finally {
        cleanupProcessInstance(process1.getId());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) 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