Search in sources :

Example 36 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException 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 37 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException 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)

Example 38 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.

the class EnterpriseWorkflowTestApi method startAdhocProcess.

/**
 * Start an adhoc-process with possible business key through the public REST-API.
 */
@SuppressWarnings("unchecked")
protected ProcessInfo startAdhocProcess(final RequestContext requestContext, NodeRef[] documentRefs, String businessKey) throws PublicApiException {
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
    ProcessesClient processesClient = publicApiClient.processesClient();
    final JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionId", processDefinition.getId());
    if (businessKey != null) {
        createProcessObject.put("businessKey", businessKey);
    }
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_priority", 1);
    variablesObject.put("wf_notifyMe", Boolean.FALSE);
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
            return null;
        }
    }, requestContext.getRunAsUser(), requestContext.getNetworkId());
    if (documentRefs != null && documentRefs.length > 0) {
        final JSONArray itemsObject = new JSONArray();
        for (NodeRef nodeRef : documentRefs) {
            itemsObject.add(nodeRef.getId());
        }
        createProcessObject.put("items", itemsObject);
    }
    createProcessObject.put("variables", variablesObject);
    return processesClient.createProcess(createProcessObject.toJSONString());
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException)

Example 39 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.

the class EnterpriseWorkflowTestApi method startParallelReviewProcess.

/**
 * Start a review pooled process through the public REST-API.
 */
@SuppressWarnings("unchecked")
protected ProcessInfo startParallelReviewProcess(final RequestContext requestContext) throws PublicApiException {
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiParallelReview").singleResult();
    ProcessesClient processesClient = publicApiClient.processesClient();
    final JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionId", processDefinition.getId());
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_priority", 1);
    variablesObject.put("wf_notifyMe", Boolean.FALSE);
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            JSONArray assigneeArray = new JSONArray();
            assigneeArray.add(requestContext.getRunAsUser());
            TestPerson otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId());
            assigneeArray.add(otherPerson.getId());
            variablesObject.put("bpm_assignees", assigneeArray);
            return null;
        }
    }, requestContext.getRunAsUser(), requestContext.getNetworkId());
    createProcessObject.put("variables", variablesObject);
    return processesClient.createProcess(createProcessObject.toJSONString());
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException)

Example 40 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method getProcessImage.

@Test
public void getProcessImage() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    final ProcessInfo processRest = startAdhocProcess(requestContext, null);
    HttpResponse response = publicApiClient.processesClient().getImage(processRest.getId());
    assertEquals(200, response.getStatusCode());
    cleanupProcessInstance(processRest.getId());
    try {
        response = publicApiClient.processesClient().getImage("fakeId");
        fail("Exception expected");
    } catch (PublicApiException e) {
        assertEquals(404, e.getHttpResponse().getStatusCode());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) 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)

Aggregations

PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)81 Test (org.junit.Test)76 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)67 JSONObject (org.json.simple.JSONObject)40 ArrayList (java.util.ArrayList)24 Task (org.activiti.engine.task.Task)23 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)23 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)21 ProcessesClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient)19 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)18 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)16 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)16 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 HashMap (java.util.HashMap)14 List (java.util.List)13 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)13 JSONArray (org.json.simple.JSONArray)13 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)11 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)9