diff --git a/data-model/src/main/java/org/alfresco/service/cmr/dictionary/CustomModelService.java b/data-model/src/main/java/org/alfresco/service/cmr/dictionary/CustomModelService.java index c0a63df4f5..c5cd90d96e 100644 --- a/data-model/src/main/java/org/alfresco/service/cmr/dictionary/CustomModelService.java +++ b/data-model/src/main/java/org/alfresco/service/cmr/dictionary/CustomModelService.java @@ -238,6 +238,17 @@ public interface CustomModelService */ public NodeRef createDownloadNode(String modelName, boolean withAssociatedForm); + /** + * Creates a downloadable archive file containing the custom model file and + * if specified, its associated Share extension module file. + * + * @param modelName the model name to be exported + * @param withAssociatedForm whether Share extension module file should be + * included or not + * @return reference to the node which will contain the archive file + */ + NodeRef createDownloadNode(String modelName, boolean withAssociatedForm, String downloadNodeName); + /** * Compiles the {@link M2Model}. * diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/CustomModelsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/CustomModelsImpl.java index 5231eac589..8368eb68b1 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/CustomModelsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/CustomModelsImpl.java @@ -712,8 +712,7 @@ public class CustomModelsImpl implements CustomModels boolean withForm = Boolean.valueOf(propName); try { - NodeRef nodeRef = customModelService.createDownloadNode(modelName, withForm); - nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, modelName + DownloadsImpl.DEFAULT_ARCHIVE_EXTENSION); + NodeRef nodeRef = customModelService.createDownloadNode(modelName, withForm, modelName + DownloadsImpl.DEFAULT_ARCHIVE_EXTENSION); return new CustomModelDownload(nodeRef); } catch (Exception ex) diff --git a/repository/src/main/java/org/alfresco/repo/dictionary/CustomModelServiceImpl.java b/repository/src/main/java/org/alfresco/repo/dictionary/CustomModelServiceImpl.java index 58bd7d6b39..f5f5c70194 100644 --- a/repository/src/main/java/org/alfresco/repo/dictionary/CustomModelServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/dictionary/CustomModelServiceImpl.java @@ -1077,6 +1077,12 @@ public class CustomModelServiceImpl implements CustomModelService @Override public NodeRef createDownloadNode(final String modelFileName, boolean withAssociatedForm) + { + return createDownloadNode(modelFileName, withAssociatedForm, null); + } + + @Override + public NodeRef createDownloadNode(final String modelFileName, boolean withAssociatedForm, String downloadNodeName) { List nodesToBeDownloaded = new ArrayList<>(2); @@ -1137,7 +1143,7 @@ public class CustomModelServiceImpl implements CustomModelService try { - NodeRef archiveNodeRef = downloadService.createDownload(nodesToBeDownloaded.toArray(new NodeRef[nodesToBeDownloaded.size()]), false); + NodeRef archiveNodeRef = downloadService.createDownload(nodesToBeDownloaded.toArray(new NodeRef[0]), false, downloadNodeName); if (logger.isDebugEnabled()) { diff --git a/repository/src/main/java/org/alfresco/repo/download/DownloadServiceImpl.java b/repository/src/main/java/org/alfresco/repo/download/DownloadServiceImpl.java index f14d702585..fc2d1b7b82 100644 --- a/repository/src/main/java/org/alfresco/repo/download/DownloadServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/download/DownloadServiceImpl.java @@ -28,12 +28,14 @@ package org.alfresco.repo.download; import java.util.Date; import java.util.List; +import org.alfresco.model.ContentModel; import org.alfresco.repo.download.cannedquery.DownloadEntity; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.download.DownloadService; import org.alfresco.service.cmr.download.DownloadStatus; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.util.ParameterCheck; /** @@ -50,6 +52,7 @@ public class DownloadServiceImpl implements DownloadService { private ActionServiceHelper actionServiceHelper; private DownloadStorage downloadStorage; private RetryingTransactionHelper transactionHelper; + private NodeService nodeService; // Dependency setters public void setActionServiceHelper(ActionServiceHelper actionServiceHelper) @@ -66,9 +69,19 @@ public class DownloadServiceImpl implements DownloadService { { this.downloadStorage = downloadStorage; } - - @Override + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + @Override public NodeRef createDownload(final NodeRef[] requestedNodes, final boolean recursive) { + return createDownload(requestedNodes, recursive, null); + } + + @Override + public NodeRef createDownload(final NodeRef[] requestedNodes, final boolean recursive, String downloadNodeName) { ParameterCheck.mandatory("nodeRefs", requestedNodes); if (requestedNodes.length < 1) { @@ -91,7 +104,12 @@ public class DownloadServiceImpl implements DownloadService { { downloadStorage.addNodeToDownload(downloadNode, node); } - + + if (downloadNodeName != null) + { + nodeService.setProperty(downloadNode, ContentModel.PROP_NAME, downloadNodeName); + } + return downloadNode; } }, false, true); diff --git a/repository/src/main/java/org/alfresco/service/cmr/download/DownloadService.java b/repository/src/main/java/org/alfresco/service/cmr/download/DownloadService.java index 04f1a1ffae..8e637d3a61 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/download/DownloadService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/download/DownloadService.java @@ -40,7 +40,7 @@ import org.alfresco.service.cmr.repository.NodeRef; public interface DownloadService { /** - * Start the creation of a downlaodable archive file containing the content + * Start the creation of a downloadable archive file containing the content * from the given nodeRefs. * * Implementations are expected to do this asynchronously, with clients @@ -50,10 +50,27 @@ public interface DownloadService * extended in the future, to support additional archive types. * * @param nodeRefs NodeRefs of content to be added to the archive file - * @param recusirsive Recurse into container nodes + * @param recursive Recurse into container nodes * @return Reference to node which will eventually contain the archive file */ - public NodeRef createDownload(NodeRef[] nodeRefs, boolean recusirsive); + NodeRef createDownload(NodeRef[] nodeRefs, boolean recursive); + + /** + * Start the creation of a downloadable archive file containing the content + * from the given nodeRefs. + * + * Implementations are expected to do this asynchronously, with clients + * using the returned NodeRef to check on progress. + + * Initially, only zip files will be supported, however this could be + * extended in the future, to support additional archive types. + * + * @param nodeRefs NodeRefs of content to be added to the archive file + * @param recursive Recurse into container nodes + * @param downloadNodeName Download node name + * @return Reference to node which will eventually contain the archive file + */ + NodeRef createDownload(NodeRef[] nodeRefs, boolean recursive, String downloadNodeName); /** * Get the status of the of the download identified by downloadNode. diff --git a/repository/src/main/resources/alfresco/download-services-context.xml b/repository/src/main/resources/alfresco/download-services-context.xml index 451db5b4a0..f39e7d12dd 100644 --- a/repository/src/main/resources/alfresco/download-services-context.xml +++ b/repository/src/main/resources/alfresco/download-services-context.xml @@ -115,6 +115,7 @@ + diff --git a/repository/src/test/java/org/alfresco/repo/download/DownloadServiceIntegrationTest.java b/repository/src/test/java/org/alfresco/repo/download/DownloadServiceIntegrationTest.java index ecd70f275a..b3e49a095e 100644 --- a/repository/src/test/java/org/alfresco/repo/download/DownloadServiceIntegrationTest.java +++ b/repository/src/test/java/org/alfresco/repo/download/DownloadServiceIntegrationTest.java @@ -349,6 +349,29 @@ public class DownloadServiceIntegrationTest validateEntries(entryNames, allEntries, true); } + @Test public void createDownloadWithName() throws IOException, InterruptedException + { + // Initiate the download + final NodeRef downloadNode = DOWNLOAD_SERVICE.createDownload(new NodeRef[] {rootFile}, false, "test.zip"); + Assert.assertNotNull(downloadNode); + + testNodes.addNodeRef(downloadNode); + + // Validate that the download node has been persisted correctly. + TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + Map properties = NODE_SERVICE.getProperties(downloadNode); + Assert.assertEquals(Boolean.FALSE, properties.get(DownloadModel.PROP_RECURSIVE)); + Assert.assertEquals("test.zip",properties.get(ContentModel.PROP_NAME)); + return null; + } + }); + } + private void validateEntries(final Set entryNames, final Set expectedEntries, boolean onlyExpected) { Set copy = new TreeSet(entryNames);