Search in sources :

Example 36 with Folder

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

the class DeletedNodesTest method testCreateAndRestore.

/**
 * Tests restoring deleted nodes
 * <p>post:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/deleted-nodes/<nodeId>/restore}
 */
@Test
public void testCreateAndRestore() throws Exception {
    setRequestContext(user1);
    Date now = new Date();
    String folder1 = "folder" + now.getTime() + "_1";
    Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
    assertNotNull(createdFolder);
    String f1Id = createdFolder.getId();
    // Create a folder outside a site
    Folder createdFolderNonSite = createFolder(Nodes.PATH_MY, folder1, null);
    assertNotNull(createdFolderNonSite);
    Document document = createEmptyTextFile(f1Id, "restoreme.txt");
    deleteNode(document.getId());
    // Create another document with the same name
    Document documentSameName = createEmptyTextFile(f1Id, "restoreme.txt");
    // Can't restore a node of the same name
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", null, null, Status.STATUS_CONFLICT);
    deleteNode(documentSameName.getId());
    // Now we can restore it.
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", null, null, 200);
    deleteNode(document.getId());
    // Create a new nodeTargetAssoc containing target id and association type
    NodeTargetAssoc nodeTargetAssoc = new NodeTargetAssoc();
    nodeTargetAssoc.setTargetParentId(f1Id);
    nodeTargetAssoc.setAssocType(ASSOC_TYPE_CM_CONTAINS);
    // restore to new location
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", toJsonAsStringNonNull(nodeTargetAssoc), null, 200);
    deleteNode(document.getId());
    // restore to nonexistent nodeId as the new location
    nodeTargetAssoc.setTargetParentId("nonexistentTargetNode");
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", toJsonAsStringNonNull(nodeTargetAssoc), null, 404);
    // restore to new location and using an invalid assocType
    nodeTargetAssoc.setTargetParentId(f1Id);
    nodeTargetAssoc.setAssocType("invalidAssociationType");
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", toJsonAsStringNonNull(nodeTargetAssoc), null, 400);
    // restore to new location without adding an association type
    nodeTargetAssoc.setTargetParentId(f1Id);
    nodeTargetAssoc.setAssocType(null);
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", toJsonAsStringNonNull(nodeTargetAssoc), null, 400);
    // create an folder as an admin
    setRequestContext(networkAdmin);
    String folderAdmin = "adminsFolder" + now.getTime() + "_1";
    Folder adminCreatedFolder = createFolder(Nodes.PATH_MY, folderAdmin, null);
    assertNotNull(adminCreatedFolder);
    String adminf1Id = adminCreatedFolder.getId();
    // switch context, re-delete the document and try to restore it to a
    // folder user1 does not have permissions to
    setRequestContext(user1);
    nodeTargetAssoc.setTargetParentId(adminf1Id);
    nodeTargetAssoc.setAssocType(ASSOC_TYPE_CM_CONTAINS);
    post(URL_DELETED_NODES + "/" + document.getId() + "/restore", toJsonAsStringNonNull(nodeTargetAssoc), null, 403);
    deleteNode(createdFolder.getId());
    // We deleted the parent folder so lets see if we can restore a child
    // doc, hopefully not.
    post(URL_DELETED_NODES + "/" + documentSameName.getId() + "/restore", null, null, Status.STATUS_NOT_FOUND);
    // Can't delete "nonsense" noderef
    post("deleted-nodes/nonsense/restore", null, null, Status.STATUS_NOT_FOUND);
    // User 2 can't restore it but user 1 can.
    setRequestContext(user2);
    post(URL_DELETED_NODES + "/" + createdFolder.getId() + "/restore", null, null, Status.STATUS_FORBIDDEN);
    setRequestContext(user1);
    post(URL_DELETED_NODES + "/" + createdFolder.getId() + "/restore", null, null, 200);
}
Also used : Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Date(java.util.Date) NodeTargetAssoc(org.alfresco.rest.api.model.NodeTargetAssoc) Test(org.junit.Test)

Example 37 with Folder

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

the class DeletedNodesTest method testDownloadRendition.

/**
 * Tests download rendition.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/deleted-nodes/<nodeId>/renditions/<renditionId>/content}
 */
@Test
public void testDownloadRendition() throws Exception {
    setRequestContext(user1);
    // Create a folder within the site document's library
    Date now = new Date();
    String folder1 = "folder" + now.getTime() + "_1";
    Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
    assertNotNull(createdFolder);
    String f1Id = createdFolder.getId();
    // Create multipart request using an existing file
    String fileName = "quick.pdf";
    File file = getResourceFile(fileName);
    MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new MultiPartBuilder.FileData(fileName, file));
    MultiPartBuilder.MultiPartRequest reqBody = multiPartBuilder.build();
    // Upload quick.pdf file into 'folder'
    HttpResponse response = post(getNodeChildrenUrl(f1Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
    Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    String contentNodeId = document.getId();
    Rendition rendition = createAndGetRendition(contentNodeId, "doclib");
    assertNotNull(rendition);
    assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
    deleteNode(contentNodeId);
    // Download rendition - by default with Content-Disposition header
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", 200);
    assertNotNull(response.getResponseAsBytes());
    Map<String, String> responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    String contentDisposition = responseHeaders.get("Content-Disposition");
    assertNotNull(contentDisposition);
    assertTrue(contentDisposition.contains("filename=\"doclib\""));
    String contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Download rendition - without Content-Disposition header
    // (attachment=false)
    Map<String, String> params = new HashMap<>();
    params = Collections.singletonMap("attachment", "false");
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    assertNull(responseHeaders.get("Content-Disposition"));
    contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Download rendition - with Content-Disposition header
    // (attachment=true) same as default
    params = Collections.singletonMap("attachment", "true");
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
    assertNotNull(response.getResponseAsBytes());
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    String cacheControl = responseHeaders.get("Cache-Control");
    assertNotNull(cacheControl);
    assertFalse(cacheControl.contains("must-revalidate"));
    assertTrue(cacheControl.contains("max-age=31536000"));
    contentDisposition = responseHeaders.get("Content-Disposition");
    assertNotNull(contentDisposition);
    assertTrue(contentDisposition.contains("filename=\"doclib\""));
    contentType = responseHeaders.get("Content-Type");
    assertNotNull(contentType);
    assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
    // Test 304 response - doclib rendition (attachment=true)
    String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
    assertNotNull(lastModifiedHeader);
    Map<String, String> headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader);
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 304);
    // -ve tests
    // nodeId in the path parameter does not represent a file
    deleteNode(f1Id);
    getSingle(getDeletedNodeRenditionsUrl(f1Id), "doclib/content", 400);
    // nodeId in the path parameter does not exist
    getSingle(getDeletedNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib/content", 404);
    // renditionId in the path parameter is not registered/available
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), 404);
    // The rendition does not exist, a placeholder is not available and the
    // placeholder parameter has a value of "true"
    params = Collections.singletonMap("placeholder", "true");
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), params, 404);
}
Also used : MultiPartBuilder(org.alfresco.rest.api.tests.util.MultiPartBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Rendition(org.alfresco.rest.api.tests.client.data.Rendition) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Folder (org.alfresco.rest.api.tests.client.data.Folder)37 Test (org.junit.Test)34 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)31 Document (org.alfresco.rest.api.tests.client.data.Document)29 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)28 HashMap (java.util.HashMap)20 LinkedHashMap (java.util.LinkedHashMap)19 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)12 Node (org.alfresco.rest.api.tests.client.data.Node)12 JSONObject (org.json.simple.JSONObject)10 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)8 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)6 UserInfo (org.alfresco.rest.api.tests.client.data.UserInfo)6 Date (java.util.Date)5 MultiValueMap (org.apache.commons.collections.map.MultiValueMap)5 RandomAccessFile (java.io.RandomAccessFile)4 Map (java.util.Map)4