Search in sources :

Example 1 with DownloadStatus

use of org.alfresco.service.cmr.download.DownloadStatus 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 2 with DownloadStatus

use of org.alfresco.service.cmr.download.DownloadStatus in project alfresco-remote-api by Alfresco.

the class DownloadStatusGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    if (templateVars == null) {
        String error = "No parameters supplied";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    if (!(templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("node_id"))) {
        String error = "Missing template variables (store_type, store_id or node_id).";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
    NodeRef nodeRef = new NodeRef(store, templateVars.get("node_id"));
    if (!nodeService.exists(nodeRef)) {
        String error = "Could not find node: " + nodeRef;
        throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
    }
    DownloadStatus downloadStatus = downloadService.getDownloadStatus(nodeRef);
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("downloadStatus", downloadStatus);
    return result;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) DownloadStatus(org.alfresco.service.cmr.download.DownloadStatus)

Example 3 with DownloadStatus

use of org.alfresco.service.cmr.download.DownloadStatus in project alfresco-remote-api by Alfresco.

the class TestCustomModelExport method testCreateDownload.

@Test
public void testCreateDownload() throws Exception {
    setRequestContext(customModelAdmin);
    final String modelName = "testModel" + System.currentTimeMillis();
    final String modelExportFileName = modelName + ".xml";
    final String shareExtExportFileName = "CMM_" + modelName + "_module.xml";
    Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    createCustomModel(modelName, namespacePair, ModelStatus.DRAFT, null, "Mark Moe");
    // Add type
    String typeBaseName = "testTypeBase" + System.currentTimeMillis();
    createTypeAspect(CustomType.class, modelName, typeBaseName, "test typeBase title", "test typeBase Desc", "cm:content");
    // Create Share extension module
    downloadTestUtil.createShareExtModule(modelName);
    setRequestContext(nonAdminUserName);
    // Try to create download the model as a non Admin user
    post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 403);
    setRequestContext(customModelAdmin);
    // Create download for custom model only
    HttpResponse response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 201);
    CustomModelDownload returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class);
    assertNotNull(returnedDownload);
    assertNotNull(returnedDownload.getNodeRef());
    NodeRef downloadNode = new NodeRef(returnedDownload.getNodeRef());
    DownloadStatus status = downloadTestUtil.getDownloadStatus(downloadNode);
    while (status.getStatus() == DownloadStatus.Status.PENDING) {
        Thread.sleep(PAUSE_TIME);
        status = downloadTestUtil.getDownloadStatus(downloadNode);
    }
    Set<String> entries = downloadTestUtil.getDownloadEntries(downloadNode);
    assertEquals(1, entries.size());
    String modelEntry = downloadTestUtil.getDownloadEntry(entries, modelExportFileName);
    assertNotNull(modelEntry);
    assertEquals(modelEntry, modelExportFileName);
    // Create download for custom model and its share extension module
    response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(true), 201);
    returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class);
    assertNotNull(returnedDownload);
    assertNotNull(returnedDownload.getNodeRef());
    downloadNode = new NodeRef(returnedDownload.getNodeRef());
    status = downloadTestUtil.getDownloadStatus(downloadNode);
    while (status.getStatus() == DownloadStatus.Status.PENDING) {
        Thread.sleep(PAUSE_TIME);
        status = downloadTestUtil.getDownloadStatus(downloadNode);
    }
    entries = downloadTestUtil.getDownloadEntries(downloadNode);
    assertEquals(2, entries.size());
    modelEntry = downloadTestUtil.getDownloadEntry(entries, modelExportFileName);
    assertNotNull(modelEntry);
    assertEquals(modelEntry, modelExportFileName);
    String shareExtEntry = downloadTestUtil.getDownloadEntry(entries, shareExtExportFileName);
    assertNotNull(shareExtEntry);
    assertEquals(shareExtEntry, shareExtExportFileName);
}
Also used : CustomModelDownload(org.alfresco.rest.api.model.CustomModelDownload) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DownloadStatus(org.alfresco.service.cmr.download.DownloadStatus) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Test(org.junit.Test)

Aggregations

DownloadStatus (org.alfresco.service.cmr.download.DownloadStatus)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 HashMap (java.util.HashMap)1 CustomModelDownload (org.alfresco.rest.api.model.CustomModelDownload)1 Download (org.alfresco.rest.api.model.Download)1 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 Test (org.junit.Test)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1