Search in sources :

Example 21 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef 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 22 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef 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 23 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testUpdateInitiatorAndGetProcessVariables.

// MNT-17918
@SuppressWarnings("unchecked")
@Test
public void testUpdateInitiatorAndGetProcessVariables() 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 initiator variable to "admin"
        JSONObject variableJson = new JSONObject();
        variableJson.put("name", "initiator");
        variableJson.put("type", "d:noderef");
        NodeRef personRef = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

            @Override
            public NodeRef doWork() throws Exception {
                String assignee = adminContext.getRunAsUser();
                NodeRef personRef = getPersonNodeRef(assignee).getNodeRef();
                variableJson.put("value", personRef.toString());
                return personRef;
            }
        }, adminContext.getRunAsUser(), adminContext.getNetworkId());
        JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "initiator", variableJson);
        assertNotNull(resultEntry);
        final JSONObject updateInitiatorResult = (JSONObject) resultEntry.get("entry");
        assertEquals("initiator", updateInitiatorResult.get("name"));
        assertEquals("d:noderef", updateInitiatorResult.get("type"));
        assertNotNull("Variable value should be returned", updateInitiatorResult.get("value"));
        assertEquals(personRef.getId(), updateInitiatorResult.get("value"));
        // Get process variables after updating "initiator"
        publicApiClient.setRequestContext(adminContext);
        resultEntry = publicApiClient.processesClient().getProcessvariables(processId);
        assertNotNull(resultEntry);
        validateVariableField(resultEntry, "initiator", adminContext.getRunAsUser());
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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 24 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testGetProcessItem.

@Test
public void testGetProcessItem() 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 itemJSON = processesClient.findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
    assertNotNull(itemJSON);
    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"));
    cleanupProcessInstance(processRest.getId());
}
Also used : 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 25 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testUploadUsingRelativePath.

/**
 * Test upload using relativePath
 */
@Test
public void testUploadUsingRelativePath() throws Exception {
    setRequestContext(user1);
    // user1 creates a private site and adds user2 as a site consumer
    String site1Title = "site-testGetPathElements_DocLib-" + RUNID;
    String site1Id = createSite(site1Title, SiteVisibility.PRIVATE).getId();
    addSiteMember(site1Id, user2, SiteRole.SiteConsumer);
    String site1DocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
    String folderA = "folder" + RUNID + "_A";
    String folderA_Id = createFolder(site1DocLibNodeId, folderA).getId();
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
    String folderB = "folder" + RUNID + "_B";
    String folderB_Id = createFolder(folderA_Id, folderB).getId();
    NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB_Id);
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
    String folderC = "folder" + RUNID + "_C";
    String folderC_Id = createFolder(folderB_Id, folderC).getId();
    NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderC_Id);
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
    String content = "content" + RUNID;
    String content_Id = createTextFile(folderC_Id, content, "The quick brown fox jumps over the lazy dog.").getId();
    Map<String, String> params = new HashMap<>();
    params.put("include", "path");
    params.put("relativePath", folderA + "/" + folderB + "/" + folderC);
    // call get with relativePathParam
    HttpResponse response = getAll(getNodeChildrenUrl(site1DocLibNodeId), null, params, 200);
    List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
    assertEquals(1, nodes.size());
    assertEquals("/" + folderA + "/" + folderB + "/" + folderC, ((Node) (nodes.get(0))).getPath().getRelativePath());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1239 HashMap (java.util.HashMap)244 QName (org.alfresco.service.namespace.QName)242 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)209 Test (org.junit.Test)195 ArrayList (java.util.ArrayList)159 Serializable (java.io.Serializable)136 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Map (java.util.Map)81 Node (org.alfresco.web.bean.repository.Node)81 JSONObject (org.json.JSONObject)80 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)74 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 List (java.util.List)58 IOException (java.io.IOException)55 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52 Date (java.util.Date)51