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
Solved! Go 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
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
Thanks @deepak1987 for detailed explanation.
Will have a look and let you know in case of any queries.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.