Search in sources :

Example 11 with ProcessesClient

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

the class EnterpriseWorkflowTestApi method startReviewPooledProcess.

/**
 * Start a review pooled process through the public REST-API.
 */
@SuppressWarnings("unchecked")
protected ProcessInfo startReviewPooledProcess(final RequestContext requestContext) throws PublicApiException {
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiReviewPooled").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("bpm_workflowDueDate", ISO8601DateFormat.format(new Date()));
    variablesObject.put("wf_notifyMe", Boolean.FALSE);
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            List<MemberOfSite> memberships = getTestFixture().getNetwork(requestContext.getNetworkId()).getSiteMemberships(requestContext.getRunAsUser());
            assertTrue(memberships.size() > 0);
            MemberOfSite memberOfSite = memberships.get(0);
            String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
            variablesObject.put("bpm_groupAssignee", group);
            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) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) Date(java.util.Date) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) List(java.util.List)

Example 12 with ProcessesClient

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

the class ProcessWorkflowApiTest method testDeleteProcessInstanceById.

@Test
public void testDeleteProcessInstanceById() 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);
    ProcessesClient processesClient = publicApiClient.processesClient();
    // delete with user starting the process instance
    ProcessInfo process = startAdhocProcess(requestContext, null);
    try {
        processesClient.deleteProcessById(process.getId());
        // Check if the process was actually deleted
        assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
        HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
        assertNotNull(deletedInstance);
        assertNotNull(deletedInstance.getEndTime());
        assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
        try {
            processesClient.deleteProcessById(process.getId());
            fail("expected exeception");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(process.getId());
    }
    // delete with admin in same network as the user starting the process instance
    process = startAdhocProcess(requestContext, null);
    try {
        publicApiClient.setRequestContext(adminContext);
        processesClient.deleteProcessById(process.getId());
        // Check if the process was actually deleted
        assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
        HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
        assertNotNull(deletedInstance);
        assertNotNull(deletedInstance.getEndTime());
        assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
    } finally {
        cleanupProcessInstance(process.getId());
    }
    // delete with admin from other network as the user starting the process instance
    process = startAdhocProcess(requestContext, null);
    try {
        publicApiClient.setRequestContext(otherContext);
        processesClient.deleteProcessById(process.getId());
        fail("Expect permission exception");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
    } finally {
        cleanupProcessInstance(process.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 13 with ProcessesClient

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

the class ProcessWorkflowApiTest method testCreateProcessInstanceWithKey.

@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceWithKey() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionKey", "activitiAdhoc");
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_dueDate", "2013-09-30T00:00:00.000+0300");
    variablesObject.put("bpm_priority", 1);
    variablesObject.put("bpm_description", "test description");
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
            return null;
        }
    }, requestContext.getRunAsUser(), requestContext.getNetworkId());
    createProcessObject.put("variables", variablesObject);
    ProcessInfo processRest = processesClient.createProcess(createProcessObject.toJSONString());
    assertNotNull(processRest);
    Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
    assertEquals("test description", variables.get("bpm_description"));
    assertEquals(1, variables.get("bpm_priority"));
    cleanupProcessInstance(processRest.getId());
    // Test same create method with an admin user
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
    processRest = processesClient.createProcess(createProcessObject.toJSONString());
    assertNotNull(processRest);
    variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
    assertEquals("test description", variables.get("bpm_description"));
    assertEquals(1, variables.get("bpm_priority"));
    cleanupProcessInstance(processRest.getId());
    // Test create process with wrong key
    publicApiClient.setRequestContext(requestContext);
    createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionKey", "activitiAdhoc2");
    try {
        processRest = processesClient.createProcess(createProcessObject.toJSONString());
        fail();
    } catch (PublicApiException e) {
        // Exception expected because of wrong process definition key
        assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
        assertErrorSummary("No workflow definition could be found with key 'activitiAdhoc2'.", e.getHttpResponse());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Test(org.junit.Test)

Example 14 with ProcessesClient

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

the class ProcessWorkflowApiTest method testGetProcessInstanceByIdUnexisting.

@Test
public void testGetProcessInstanceByIdUnexisting() throws Exception {
    initApiClientWithTestUser();
    ProcessesClient processesClient = publicApiClient.processesClient();
    try {
        processesClient.findProcessById("unexisting");
        fail("Exception expected");
    } catch (PublicApiException expected) {
        assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
        assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Test(org.junit.Test)

Example 15 with ProcessesClient

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

the class ProcessWorkflowApiTest method testGetProcessItems.

@Test
public void testGetProcessItems() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    NodeRef[] docNodeRefs = createTestDocuments(requestContext);
    final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
    assertNotNull(processRest);
    final String newProcessInstanceId = processRest.getId();
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject itemsJSON = processesClient.findProcessItems(newProcessInstanceId);
    assertNotNull(itemsJSON);
    JSONArray entriesJSON = (JSONArray) itemsJSON.get("entries");
    assertNotNull(entriesJSON);
    assertTrue(entriesJSON.size() == 2);
    boolean doc1Found = false;
    boolean doc2Found = false;
    for (Object entryObject : entriesJSON) {
        JSONObject entryObjectJSON = (JSONObject) entryObject;
        JSONObject entryJSON = (JSONObject) entryObjectJSON.get("entry");
        if (entryJSON.get("name").equals("Test Doc1")) {
            doc1Found = true;
            assertEquals(docNodeRefs[0].getId(), entryJSON.get("id"));
            assertEquals("Test Doc1", entryJSON.get("name"));
            assertEquals("Test Doc1 Title", entryJSON.get("title"));
            assertEquals("Test Doc1 Description", entryJSON.get("description"));
            assertNotNull(entryJSON.get("createdAt"));
            assertEquals(requestContext.getRunAsUser(), entryJSON.get("createdBy"));
            assertNotNull(entryJSON.get("modifiedAt"));
            assertEquals(requestContext.getRunAsUser(), entryJSON.get("modifiedBy"));
            assertNotNull(entryJSON.get("size"));
            assertNotNull(entryJSON.get("mimeType"));
        } else {
            doc2Found = true;
            assertEquals(docNodeRefs[1].getId(), entryJSON.get("id"));
            assertEquals("Test Doc2", entryJSON.get("name"));
            assertEquals("Test Doc2 Title", entryJSON.get("title"));
            assertEquals("Test Doc2 Description", entryJSON.get("description"));
            assertNotNull(entryJSON.get("createdAt"));
            assertEquals(requestContext.getRunAsUser(), entryJSON.get("createdBy"));
            assertNotNull(entryJSON.get("modifiedAt"));
            assertEquals(requestContext.getRunAsUser(), entryJSON.get("modifiedBy"));
            assertNotNull(entryJSON.get("size"));
            assertNotNull(entryJSON.get("mimeType"));
        }
    }
    assertTrue(doc1Found);
    assertTrue(doc2Found);
    cleanupProcessInstance(processRest.getId());
    try {
        processesClient.findProcessItems("fakeid");
        fail("Exception expected");
    } catch (PublicApiException e) {
        assertEquals(404, e.getHttpResponse().getStatusCode());
    }
}
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) JSONArray(org.json.simple.JSONArray) 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