How Download as Zip work in Background and how to modify File names in download packages?

cancel
Showing results for 
Search instead for 
Did you mean: 
jigirshah
Active Member II

How Download as Zip work in Background and how to modify File names in download packages?

Jump to solution

Hello Everyone,

We have ACS v7.1.x setup in our environments and using custom ADF Application as Front-end. 

For multiple document download as a zip, we're using Alfresco OOTB APIs (listed under Downloads in API Explorer) for Create a new Download, Checking status of it and then once done, we're providing Download link to ZIP document.

Here, I have few queries and need some customization in this functionality. Any help would be much appreciated.

1. I have gone throguh Download zip codebase from Alfresco Github. As per my understanding, if we are giving 10 nodeids as request parameter in create download API, it will create a temporary node id, create assoications with 10 nodeids and then, running Action named 'createDownloadArchiveAction' to get each node ids downloaded as a zip. Can anyone confirm if I've some misunderstanding? 

2. I would like to know how this Action 'createDownloadArchiveAction' works? What's actually running in background?

3. In zip, all 10 nodes will be having name same as 'cm:name' set in Alfresco. Now, My requirement is to have different names (based on certain custom content model metadata fields) for all 10 nodes inside zip. How can I achieve this? Any help?

 

Thanks & Regards,

Jigir

1 Solution

Accepted Solutions
deepak1987
Active Member II

Re: How Download as Zip work in Background and how to modify File names in download packages?

Jump to solution

Hi Jigir,

 

1. Yes, your understanding is correct. Download as Zip action calls org.alfresco.repo.web.scripts.download.DownloadPost in Share UI (org.alfresco.rest.api.impl.DownloadsImpl in ADF UI) -> org.alfresco.repo.download.DownloadServiceImpl -> org.alfresco.repo.download.CreateDownloadArchiveAction (Bean ID: 'createDownloadArchiveAction')

 

2. In createDownloadArchiveAction class, createDownload() method have two components: exporterService (Exporter Component traverse through all the requested nodes and excludes the nodes if any are mentioned in the parameters), org.alfresco.repo.download.ZipDownloadExporter (Handler that does the zipping of all the folder and files retrieved by the exporterService).

 

3. You need to customize createDownloadArchiveAction action with your custom class (say com.djk.alfresco.repo.download.CreateDownloadArchiveAction) and keep bean id as 'createDownloadArchiveAction', implement a custom ZipDownloadExporter (say com.djk.alfresco.repo.download.ZipDownloadExporter) and change the below startNode() method as:  

@Override
public void startNode(NodeRef nodeRef) {
	
	if (nodeService.getProperty(nodeRef, DJKContentModel.PROP_DJK_TITLE) != null) {
		this.currentName = (String) nodeService.getProperty(nodeRef, DJKContentModel.PROP_DJK_TITLE);
	}
	else {
		// For those nodes which don't have the above property set or are null/empty.
		this.currentName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
	}

	// this.currentName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
	path.push(new Pair<String, NodeRef>(currentName, nodeRef));
	if (dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER)) {
		String path = getPath() + PATH_SEPARATOR;
		ZipArchiveEntry archiveEntry = new ZipArchiveEntry(path);
		try {
			zipStream.putArchiveEntry(archiveEntry);
			zipStream.closeArchiveEntry();
		} catch (IOException e) {
			throw new ExporterException("Unexpected IOException adding folder entry", e);
		}
	}
}

 

Hope this helps.

Thanks

Deepak Keswani

View solution in original post

2 Replies
deepak1987
Active Member II

Re: How Download as Zip work in Background and how to modify File names in download packages?

Jump to solution

Hi Jigir,

 

1. Yes, your understanding is correct. Download as Zip action calls org.alfresco.repo.web.scripts.download.DownloadPost in Share UI (org.alfresco.rest.api.impl.DownloadsImpl in ADF UI) -> org.alfresco.repo.download.DownloadServiceImpl -> org.alfresco.repo.download.CreateDownloadArchiveAction (Bean ID: 'createDownloadArchiveAction')

 

2. In createDownloadArchiveAction class, createDownload() method have two components: exporterService (Exporter Component traverse through all the requested nodes and excludes the nodes if any are mentioned in the parameters), org.alfresco.repo.download.ZipDownloadExporter (Handler that does the zipping of all the folder and files retrieved by the exporterService).

 

3. You need to customize createDownloadArchiveAction action with your custom class (say com.djk.alfresco.repo.download.CreateDownloadArchiveAction) and keep bean id as 'createDownloadArchiveAction', implement a custom ZipDownloadExporter (say com.djk.alfresco.repo.download.ZipDownloadExporter) and change the below startNode() method as:  

@Override
public void startNode(NodeRef nodeRef) {
	
	if (nodeService.getProperty(nodeRef, DJKContentModel.PROP_DJK_TITLE) != null) {
		this.currentName = (String) nodeService.getProperty(nodeRef, DJKContentModel.PROP_DJK_TITLE);
	}
	else {
		// For those nodes which don't have the above property set or are null/empty.
		this.currentName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
	}

	// this.currentName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
	path.push(new Pair<String, NodeRef>(currentName, nodeRef));
	if (dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER)) {
		String path = getPath() + PATH_SEPARATOR;
		ZipArchiveEntry archiveEntry = new ZipArchiveEntry(path);
		try {
			zipStream.putArchiveEntry(archiveEntry);
			zipStream.closeArchiveEntry();
		} catch (IOException e) {
			throw new ExporterException("Unexpected IOException adding folder entry", e);
		}
	}
}

 

Hope this helps.

Thanks

Deepak Keswani

jigirshah
Active Member II

Re: How Download as Zip work in Background and how to modify File names in download packages?

Jump to solution

Thanks @deepak1987 for detailed explanation.

Will have a look and let you know in case of any queries.