mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merge from BRANCHES/DEV/CLOUD1_SPRINT1 to HEAD:
40238: CLOUD-37 - Initial Commit to test Merged BRANCHES/DEV/AMILLER/CLOUD1_SPRINT1 to BRANCHES/DEV/CLOUD1_SPRINT1: 40077: CLOUD-37: Initial commit. 40101: CLOUD-37: Fix build error. 40114: CLOUD-37: Fix path names and missing files. 40122: CLOUD-37: Initial drop of UI code for investigation of progress issues 40124: CLOUD-37: A couple of minor UI tweaks (set icon and hide panel before archive download) 40125: CLOUD-37: Download files and folders as zip 40134: CLOUD-37: Updates to UI (javascript doc, CSS tweaks, intervals for requests, labels, etc). 40143: CLOUD-37: Error messages for failures, more JavaScript doc, archive naming, code tidy 40157: CLOUD-37 - Download files and folders as zip 40202: CLOUD-37: UI tweaks following UX review 40217: CLOUD-37: Add file count to status reports. 40222: CLOUD-37: Added information to download dialog to report on the number of files added to the zip 40240: CLOUD-37: Remove extraneous file, breaking build 40513: CLOUD-37: Add Action Service Metrics Merged BRANCHES/DEV/AMILLER/CLOUD1_SPRINT1 to BRANCHES/DEV/CLOUD1_SPRINT1: 40260: CLOUD-37: Add action service metrics 40309: CLOUD-37: Fix JMX configuration, pointing at renamed class. 40514: CLOUD-37: Enable the execution of the zip creation process on a remote transformation node Merged BRANCHES/DEV/AMILLER/CLOUD1_SPRINT1 to BRANCHES/DEV/CLOUD1_SPRINT1: 40369: CLOUD-37: Enable the execution of the zip creation process on a remote transformation node 40516: CLOUD-37: Implement clean up job. Merged BRANCHES/DEV/AMILLER/CLOUD1_SPRINT1 to BRANCHES/DEV/CLOUD1_SPRINT1: 40462: CLOUD-37: Implement clean up job. 40517: CLOUD-505: Add entries for folders. Merged BRANCHES/DEV/AMILLER/CLOUD1_SPRINT1 to BRANCHES/DEV/CLOUD1_SPRINT1: 40493: CLOUD-505: Add entries for folders. 40547: CLOUD-37: Fix broken test 40595: CLOUD-518: Add working copy/locked file filtering 40642: CLOUD-508: Prevent problems occurring when cancelling and restarting the same download 40643: CLOUD-507: When a single item is selected for download it the item name gets used for the archive name 41442: CLOUD-590: Limit the total size of the content which can be downloaded. This can be set via the property, download.maxContentSize. The default is 2GB. 41472: CLOUD-589: Added cancelled flag to download type and added checks in Zip creation action to act upon the setting of this flag. Also added webscript for canceling the download. 41692: Adds support to Alfresco.util.formatFileSize for file sizes with commas (as needed by zip download) 41693: Zip Download enhancements: CLOUD-590: Notifies the user when they've exceeded the maximum file size limit. CLOUD-626: Better handling when there are errors during zipping. (WIP) 41713: Zip Download Updates: CLOUD-589: A cancel download UI action now triggers a delete of the archive on the server. CLOUD-626: The UI now triggers a full download cancel (with node delete) in event of an error. 41737: Updates Alfresco.util.formatFileSize to support an optional decimal places param. (For CLOUD-685) 41739: CLOUD-685: Display total file size of files for download to two decimal places when there is an error. 41832: Fixes: CLOUD-704: new CANCELLED status is now handled correctly. 41887: CLOUD-686: Updated maximum download content size to 2152852358 bytes (2.005GB) 41965: CLOUD-703: Upload content now runs as system user, and Quota Service returns unlimited quota for system user. 42025: CLOUD-703: Fix test failures and ensure S3 content store works in the clustered and non-clustered environments git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42146 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<webscript>
|
||||
<shortname>Cancel a Download</shortname>
|
||||
<description>Cancel a Dwonload</description>
|
||||
<url>/api/internal/downloads/{store_type}/{store_id}/{node_id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readwrite"/>
|
||||
<lifecycle>internal</lifecycle>
|
||||
</webscript>
|
@@ -0,0 +1,5 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"status": "CANCELLED",
|
||||
}
|
||||
</#escape>
|
@@ -0,0 +1,9 @@
|
||||
<webscript>
|
||||
<shortname>Get Download Status</shortname>
|
||||
<description>Get Download Status</description>
|
||||
<url>/api/internal/downloads/{store_type}/{store_id}/{node_id}/status</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly"/>
|
||||
<lifecycle>internal</lifecycle>
|
||||
</webscript>
|
@@ -0,0 +1,9 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"status": "${downloadStatus.status?string}",
|
||||
"done": "${downloadStatus.done?string}",
|
||||
"total": "${downloadStatus.total?string}",
|
||||
"filesAdded": "${downloadStatus.filesAdded?string}",
|
||||
"totalFiles": "${downloadStatus.totalFiles?string}"
|
||||
}
|
||||
</#escape>
|
@@ -0,0 +1,7 @@
|
||||
<webscript>
|
||||
<shortname>Create Download</shortname>
|
||||
<description>Create Download</description>
|
||||
<url>/api/internal/downloads</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
</webscript>
|
@@ -0,0 +1,6 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"status": "success",
|
||||
"nodeRef": "${downloadNodeRef.nodeRef?string}"
|
||||
}
|
||||
</#escape>
|
@@ -1890,5 +1890,30 @@
|
||||
</bean>
|
||||
|
||||
<!-- END: QuickShare (aka PublicView) -->
|
||||
|
||||
|
||||
<!-- BEGIN: Download -->
|
||||
|
||||
<bean id="org.alfresco.repository.download.abstract" class="org.alfresco.repo.web.scripts.download.AbstractDownloadWebScript" abstract="true">
|
||||
<property name="downloadService" ref="DownloadService"/>
|
||||
</bean>
|
||||
|
||||
<!-- authenticated -->
|
||||
<bean id="webscript.org.alfresco.repository.download.downloads.post"
|
||||
class="org.alfresco.repo.web.scripts.download.DownloadPost"
|
||||
parent="org.alfresco.repository.download.abstract">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.download.download.delete"
|
||||
class="org.alfresco.repo.web.scripts.download.DownloadDelete"
|
||||
parent="org.alfresco.repository.download.abstract">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.download.downloadStatus.get"
|
||||
class="org.alfresco.repo.web.scripts.download.DownloadStatusGet"
|
||||
parent="org.alfresco.repository.download.abstract">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
</bean>
|
||||
|
||||
<!-- END: Download -->
|
||||
</beans>
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.download;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.download.DownloadService;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
|
||||
/**
|
||||
* Base class for download related webscripts.
|
||||
*
|
||||
* @author Alex Miller
|
||||
*/
|
||||
abstract class AbstractDownloadWebscript extends DeclarativeWebScript
|
||||
{
|
||||
// Shared dependencies
|
||||
protected DownloadService downloadService;
|
||||
|
||||
public void setDownloadService(DownloadService downloadSerivce)
|
||||
{
|
||||
this.downloadService = downloadSerivce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to embed error informaion in a map.
|
||||
*/
|
||||
protected Map<String,Object> buildError(String message)
|
||||
{
|
||||
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("error", message);
|
||||
|
||||
HashMap<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("error", message);
|
||||
model.put("result", result);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.download;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* Webscript for canceling a download.
|
||||
*
|
||||
* @author Alex Miller
|
||||
*/
|
||||
public class DownloadDelete extends AbstractDownloadWebscript
|
||||
{
|
||||
|
||||
protected NodeService nodeService;
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
downloadService.cancelDownload(nodeRef);
|
||||
|
||||
status.setCode(HttpServletResponse.SC_OK);
|
||||
|
||||
return new HashMap<String, Object>();
|
||||
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeSerivce)
|
||||
{
|
||||
this.nodeService = nodeSerivce;
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.download;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* Web script for creating a new download.
|
||||
*
|
||||
* @author Alex Miller
|
||||
*/
|
||||
public class DownloadPost extends AbstractDownloadWebscript
|
||||
{
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
// Parse the JSON, if supplied
|
||||
JSONArray json = null;
|
||||
String contentType = req.getContentType();
|
||||
if (contentType != null && contentType.indexOf(';') != -1)
|
||||
{
|
||||
contentType = contentType.substring(0, contentType.indexOf(';'));
|
||||
}
|
||||
|
||||
List<NodeRef> nodes = new LinkedList<NodeRef>();
|
||||
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
|
||||
{
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
json = (JSONArray)parser.parse(req.getContent().getContent());
|
||||
for (int i = 0 ; i < json.size() ; i++)
|
||||
{
|
||||
JSONObject obj = (JSONObject)json.get(i);
|
||||
String nodeRefString = (String)obj.get("nodeRef");
|
||||
if (nodeRefString != null)
|
||||
{
|
||||
nodes.add(new NodeRef(nodeRefString));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Unexpected IOException", io);
|
||||
}
|
||||
catch (org.json.simple.parser.ParseException je)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unexpected ParseException", je);
|
||||
}
|
||||
}
|
||||
|
||||
if (nodes.size() <= 0)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "No nodeRefs provided");
|
||||
}
|
||||
|
||||
NodeRef downloadNode = downloadService.createDownload(nodes.toArray(new NodeRef[nodes.size()]), true);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("downloadNodeRef", downloadNode);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.download;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
/**
|
||||
* Tests for the Download webscripts.
|
||||
*
|
||||
* @author Alex Miller
|
||||
*/
|
||||
public class DownloadRestApiTest extends BaseWebScriptTest
|
||||
{
|
||||
// Test COnstants
|
||||
private static final long MAX_TIME = 5000;
|
||||
private static final long PAUSE_TIME = 1000;
|
||||
|
||||
private static final String TEST_USERNAME = "downloadTestUser";
|
||||
|
||||
// Urls
|
||||
public static final String URL_DOWNLOADS = "/api/internal/downloads";
|
||||
public static final String URL_DOWNLOAD_STATUS = "/api/internal/downloads/{0}/{1}/{2}/status";
|
||||
|
||||
|
||||
// Various supporting services
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private MutableAuthenticationService authenticationService;
|
||||
private ContentService contentService;
|
||||
private NodeService nodeService;
|
||||
private PersonService personService;
|
||||
|
||||
// Test Content
|
||||
private NodeRef rootFolder;
|
||||
private NodeRef rootFile;
|
||||
private NodeRef level1File;
|
||||
private NodeRef level1Folder;
|
||||
private NodeRef level2File;
|
||||
|
||||
|
||||
public void setUp()
|
||||
{
|
||||
// Resolve required services
|
||||
authenticationService = getServer().getApplicationContext().getBean("AuthenticationService", MutableAuthenticationService.class);
|
||||
authenticationComponent = getServer().getApplicationContext().getBean("authenticationComponent", AuthenticationComponent.class);
|
||||
contentService = getServer().getApplicationContext().getBean("ContentService", ContentService.class);
|
||||
nodeService = getServer().getApplicationContext().getBean("NodeService", NodeService.class);
|
||||
personService = getServer().getApplicationContext().getBean("PersonService", PersonService.class);
|
||||
|
||||
// Authenticate as user
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// if user with given user name doesn't already exist then create user
|
||||
if (this.authenticationService.authenticationExists(TEST_USERNAME) == false)
|
||||
{
|
||||
// create user
|
||||
this.authenticationService.createAuthentication(TEST_USERNAME, "password".toCharArray());
|
||||
|
||||
// create person properties
|
||||
PropertyMap personProps = new PropertyMap();
|
||||
personProps.put(ContentModel.PROP_USERNAME, TEST_USERNAME);
|
||||
personProps.put(ContentModel.PROP_FIRSTNAME, "FirstName123");
|
||||
personProps.put(ContentModel.PROP_LASTNAME, "LastName123");
|
||||
personProps.put(ContentModel.PROP_EMAIL, "FirstName123.LastName123@email.com");
|
||||
personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123");
|
||||
personProps.put(ContentModel.PROP_JOBTITLE, "Organisation123");
|
||||
|
||||
// create person node for user
|
||||
this.personService.createPerson(personProps);
|
||||
}
|
||||
|
||||
Repository repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
|
||||
NodeRef companyHome = repositoryHelper.getCompanyHome();
|
||||
|
||||
|
||||
// Create some static test content
|
||||
rootFolder = createNode(companyHome, "rootFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
rootFile = createNodeWithTextContent(companyHome, "rootFile", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Root file content");
|
||||
|
||||
level1File = createNodeWithTextContent(rootFolder, "level1File", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 1 file content");
|
||||
level1Folder = createNode(rootFolder, "level1Folder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
level2File = createNodeWithTextContent(level1Folder, "level2File", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName(), "Level 2 file content");
|
||||
}
|
||||
|
||||
public void tearDown()
|
||||
{
|
||||
nodeService.deleteNode(level2File);
|
||||
nodeService.deleteNode(level1Folder);
|
||||
nodeService.deleteNode(level1File);
|
||||
nodeService.deleteNode(rootFolder);
|
||||
nodeService.deleteNode(rootFile);
|
||||
|
||||
personService.deletePerson(TEST_USERNAME);
|
||||
if (this.authenticationService.authenticationExists(TEST_USERNAME))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(TEST_USERNAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName, String content)
|
||||
{
|
||||
NodeRef nodeRef = createNode(parentNode, nodeCmName, nodeType, ownerUserName);
|
||||
|
||||
// If there is any content, add it.
|
||||
if (content != null)
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.putContent(content);
|
||||
}
|
||||
return nodeRef;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private NodeRef createNode(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName)
|
||||
{
|
||||
QName childName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, nodeCmName);
|
||||
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
props.put(ContentModel.PROP_NAME, nodeCmName);
|
||||
ChildAssociationRef childAssoc = nodeService.createNode(parentNode,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
childName,
|
||||
nodeType,
|
||||
props);
|
||||
return childAssoc.getChildRef();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndGetDownload() throws UnsupportedEncodingException, IOException, JSONException
|
||||
{
|
||||
// CReate the download
|
||||
String postData = "[{ \"nodeRef\": \"" +
|
||||
rootFile +
|
||||
"\"}, { \"nodeRef\": \"" +
|
||||
rootFolder +
|
||||
"\"}]";
|
||||
Response response = sendRequest(new PostRequest(URL_DOWNLOADS, postData, "application/json"), 200);
|
||||
|
||||
// Parse the response
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
NodeRef downloadNodeRef = new NodeRef(result.getString("nodeRef"));
|
||||
|
||||
// Get the status
|
||||
String statusUrl = MessageFormat.format(URL_DOWNLOAD_STATUS, downloadNodeRef.getStoreRef().getProtocol(), downloadNodeRef.getStoreRef().getIdentifier(), downloadNodeRef.getId());
|
||||
Response statusResponse = sendRequest(new GetRequest(statusUrl), 200);
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.download;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.download.DownloadStatus;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* Webscript for retrieving the status of a download.
|
||||
*
|
||||
* @author Alex Miller
|
||||
*/
|
||||
public class DownloadStatusGet extends AbstractDownloadWebscript
|
||||
{
|
||||
|
||||
protected NodeService nodeService;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeSerivce)
|
||||
{
|
||||
this.nodeService = nodeSerivce;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user