Search in sources :

Example 1 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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 2 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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 3 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testDeleteProcessItemWithAdmin.

@Test
public void testDeleteProcessItemWithAdmin() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    publicApiClient.setRequestContext(adminContext);
    // start process with admin user
    NodeRef[] docNodeRefs = createTestDocuments(adminContext);
    final ProcessInfo processRest = startAdhocProcess(adminContext, 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());
        }
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
    // start process with default user and delete item with admin
    publicApiClient.setRequestContext(requestContext);
    docNodeRefs = createTestDocuments(requestContext);
    final ProcessInfo processRestDefaultUser = startAdhocProcess(requestContext, docNodeRefs);
    try {
        assertNotNull(processRestDefaultUser);
        publicApiClient.setRequestContext(adminContext);
        final String newProcessInstanceId = processRestDefaultUser.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());
        }
    } finally {
        cleanupProcessInstance(processRestDefaultUser.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 4 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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 5 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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)

Aggregations

ProcessesClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient)23 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)20 Test (org.junit.Test)20 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)17 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)16 JSONObject (org.json.simple.JSONObject)16 HashMap (java.util.HashMap)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 JSONArray (org.json.simple.JSONArray)6 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)4 Date (java.util.Date)3 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)3 Task (org.activiti.engine.task.Task)3 List (java.util.List)2 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)2 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 TaskService (org.activiti.engine.TaskService)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1