cancel
Showing results for 
Search instead for 
Did you mean: 

Download as Zip custom folder type

streetturtle
Confirmed Champ
Confirmed Champ
When I download folders as zip which type is not cm:folder I get empty zip archive. For folders with cm:content type and for documents it works properly.

More details:

In our project we have created a custom folder type with parent cm:folder:


<type name="ef:folder">
  <title>Parent of all folders</title>
  <parent>cm:folder</parent>
  <mandatory-aspects>
    <aspect>ef:typed</aspect>
  </mandatory-aspects>
</type>


The problem is that when I press Download as Zip button for selected folder I get empty zip file. It comes from startNode method of ZipDownloadExporter.java:


@Override
public void startNode(NodeRef nodeRef)
{
  this.currentName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
  path.push(new Pair<String, NodeRef>(currentName, nodeRef));
  if (ContentModel.TYPE_FOLDER.equals(nodeService.getType(nodeRef)))
  {
    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);
    }
  }
}


Since custom folder has type ef:folder this check returns false:


if (ContentModel.TYPE_FOLDER.equals(nodeService.getType(nodeRef)))


and folder is not added to the zip.

Is it a bug (maybe proper solution would be to check not only node's type but also parent type)?
How it could be fixed without creating custom exporter for custom folder types?
Due to project restriction type of folder couldn't be changed to cm:folder.

1 REPLY 1

streetturtle
Confirmed Champ
Confirmed Champ
I had got an answer from stackoverflow: http://stackoverflow.com/a/30937163/1252056

Basically in
ZipDownloadExporter
class
startNode
method checks if nodeRef has a type
cm:folder
:


if (ContentModel.TYPE_FOLDER.equals(nodeService.getType(nodeRef)))


Which in case of a custom folder type (
ep:folder
for example) will return false.
The solution is to check if a custom folder type is a child of
cm:content
using dictionaryService:


if (dictionaryService().isSubClass((nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER))


I raised a ticket: <a href="https://issues.alfresco.com/jira/browse/ALF-21374">ALF-21374</a>