[MNT-24555] Set download node name on node creation (#2901)

* [MNT-24555] Set download node name on node creation

* [MNT-24555] PMD scan changes
This commit is contained in:
Tiago Salvado
2024-09-19 09:28:52 +01:00
committed by GitHub
parent b7642b5813
commit 1c1c9704a1
7 changed files with 84 additions and 9 deletions

View File

@@ -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<NodeRef> 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())
{

View File

@@ -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);

View File

@@ -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.

View File

@@ -115,6 +115,7 @@
<property name="actionServiceHelper" ref="downloadActionServiceHelper"/>
<property name="downloadStorage" ref="downloadStorage"/>
<property name="transactionHelper" ref="retryingTransactionHelper"/>
<property name="nodeService" ref="NodeService"/>
</bean>
<bean id="downloadCleanerSchedulerAccessor" class="org.springframework.scheduling.quartz.SchedulerAccessorBean">

View File

@@ -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<Object>()
{
@Override
public Object execute() throws Throwable
{
Map<QName, Serializable> 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<String> entryNames, final Set<String> expectedEntries, boolean onlyExpected)
{
Set<String> copy = new TreeSet<String>(entryNames);