1

I have been working on a webscript that will spit back all folders, subfolders, and files via an Alfresco webscript.

My current JavaScript model:

// search for folder within Alfresco content repository
var folder = roothome.childByNamePath("PATH");

// validate that folder has been found
if (folder == undefined || !folder.isContainer) {
   status.code = 404;
   status.message = "Folder " + " not found.";
   status.redirect = true;
}

// construct model for response template to render
model.folder = folder; 

My JSON response is created like this:

<#assign datetimeformat="EEE, dd MMM yyyy HH:mm:ss zzz">
{"corporates" : [
    <#list folder.children as child>
      {
      "folder" : "${child.properties.name}"
      }
    </#list>
    ]
}

This Freemarker JSON template responds with the following:

{"corporates" : [
      {
      "folder" : "Example Folder 1"
      }
      {
      "folder" : "Example Folder 2"
      }
      {
      "folder" : "Example Folder 3"
      }
      {
      "folder" : "Example Folder 4"
      }
    ]
}

This looks great, but I need to dive into each of these four folders to list subfolders/files.

These threads (here and here) give examples of how to traverse folders, but I can't get a proper response.

This Alfresco thread cites how to use Lucene search to get all folders/subfolders/files, but I can't get it formatted correctly.

Any help or building upon the linked threads would be much appreciated!

tlapinsk
  • 15
  • 1
  • 6

1 Answers1

1

You're obviously using Freemarker to produce your response; why don't you simply traverse the children there? Create a macro/function that will accept a node, and return all of it's children. Then call that macro as many times and you need, recursively.

http://docs.alfresco.com/5.2/references/API-FreeMarker-TemplateNode.html

http://freemarker.org/docs/

Lista
  • 2,186
  • 1
  • 15
  • 18
  • thanks @Lista! This advice worked great and now I'm diving recursively through each folder. Code below: `<#macro recurse_macro node depth> <#list node.children?sort_by(["properties","name"]) as child> { "folder" : "${child.properties.name}" }, <#if child.isContainer> { <@recurse_macro node=child depth=depth+1/> } #if> #list> #macro>` – tlapinsk Oct 24 '17 at 19:19