Search in sources :

Example 1 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class TestDownloads method test003CancelDownload.

/**
 * Tests canceling a download.
 *
 * <p>DELETE:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/private/alfresco/versions/1/downloads/<download_id>}
 */
@Test
public void test003CancelDownload() throws Exception {
    // cancel a running download operation.
    cancelWithRetry(() -> {
        Download download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableFolderId1, zippableDocId3_InFolder1, zippableDocId1, zippableDocId2);
        cancel(download.getId());
        assertCancelledDownload(download, 5, 65);
    });
    // cancel a completed download - should have no effect
    Download download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1, zippableDocId2);
    assertDoneDownload(download, 2, 26);
    cancel(download.getId());
    Thread.sleep(500);
    Download downloadStatus = getDownload(download.getId());
    assertTrue("A cancel operation on a DONE download has no effect.", downloadStatus.getStatus().equals(DownloadStatus.Status.DONE));
    // cancel a node which is not of a download type
    cancel(HttpServletResponse.SC_BAD_REQUEST, zippableDocId1);
    // user2 canceling user1 download operation - should not be allowed
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1);
    setRequestContext(user2);
    cancel(HttpServletResponse.SC_FORBIDDEN, download.getId());
}
Also used : Download(org.alfresco.rest.api.model.Download) Test(org.junit.Test)

Example 2 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class DownloadsImpl method getStatus.

private Download getStatus(NodeRef downloadNodeRef) {
    DownloadStatus status = downloadService.getDownloadStatus(downloadNodeRef);
    Download downloadInfo = new Download();
    downloadInfo.setId(downloadNodeRef.getId());
    downloadInfo.setBytesAdded(status.getDone());
    downloadInfo.setFilesAdded(status.getFilesAdded());
    downloadInfo.setStatus(status.getStatus());
    downloadInfo.setTotalFiles(status.getTotalFiles());
    downloadInfo.setTotalBytes(status.getTotal());
    return downloadInfo;
}
Also used : DownloadStatus(org.alfresco.service.cmr.download.DownloadStatus) Download(org.alfresco.rest.api.model.Download)

Example 3 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class DownloadsImpl method getDownloadStatus.

@Override
public Download getDownloadStatus(String downloadNodeId) {
    NodeRef downloadNodeRef = nodes.validateNode(downloadNodeId);
    checkIsDownloadNodeType(downloadNodeRef);
    Download downloadInfo = getStatus(downloadNodeRef);
    return downloadInfo;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Download(org.alfresco.rest.api.model.Download)

Example 4 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class DownloadsImpl method createDownloadNode.

@Override
public Download createDownloadNode(Download download) {
    checkEmptyNodeIds(download);
    checkDuplicateNodeId(download);
    NodeRef[] zipContentNodeRefs = validateAndGetNodeRefs(download);
    checkNodeIdsReadPermission(zipContentNodeRefs);
    NodeRef zipNodeRef = downloadService.createDownload(zipContentNodeRefs, true);
    String archiveName = zipContentNodeRefs.length > 1 ? DEFAULT_ARCHIVE_NAME : nodeService.getProperty(zipContentNodeRefs[0], ContentModel.PROP_NAME) + DEFAULT_ARCHIVE_EXTENSION;
    nodeService.setProperty(zipNodeRef, ContentModel.PROP_NAME, archiveName);
    Download downloadInfo = getStatus(zipNodeRef);
    return downloadInfo;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Download(org.alfresco.rest.api.model.Download)

Example 5 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class TestDownloads method test001CreateDownload.

/**
 * Tests the creation of download nodes.
 *
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/private/alfresco/versions/1/downloads}
 */
@Test
public void test001CreateDownload() throws Exception {
    // test creating a download with a single file
    Download download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1);
    assertPendingDownloadProps(download);
    assertValidZipNodeid(download);
    assertDoneDownload(download, 1, 13);
    // test creating a multiple file archive
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1, zippableDocId2);
    assertPendingDownloadProps(download);
    assertValidZipNodeid(download);
    assertDoneDownload(download, 2, 26);
    // test creating a zero file archive
    createDownload(HttpServletResponse.SC_BAD_REQUEST);
    // test creating an archive with the same file twice
    download = createDownload(HttpServletResponse.SC_BAD_REQUEST, zippableDocId1, zippableDocId1);
    // test creating an archive with a folder and a file which is contained in the folder
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableFolderId1, zippableDocId3_InFolder1);
    assertPendingDownloadProps(download);
    assertValidZipNodeid(download);
    assertDoneDownload(download, 3, 39);
    // test creating an archive with a file and a folder containing that file but only as a secondary parent child association
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1, zippableFolderId3);
    assertPendingDownloadProps(download);
    assertValidZipNodeid(download);
    assertDoneDownload(download, 2, 26);
    // test creating an archive with two files, one of which user1 does not have permissions for
    download = createDownload(HttpServletResponse.SC_FORBIDDEN, zippableDocId1, zippableDoc_user2);
}
Also used : Download(org.alfresco.rest.api.model.Download) Test(org.junit.Test)

Aggregations

Download (org.alfresco.rest.api.model.Download)9 Test (org.junit.Test)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1 DownloadStatus (org.alfresco.service.cmr.download.DownloadStatus)1