AnsweredAssumed Answered

List Folders,Subfolders as tree structure using JSON format

Question asked by sandeepreddy1 on Sep 27, 2018

Hi Everyone, 

 

I've done a fair bit of research, but haven't been able to find the right answer. I am trying to create a webscript that will grab all folders, subfolders, and files in a JavaScript webscript (JSON response).

 

Currently, my model looks like this:

// 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;

I then am able to get a JSON response of the children using this Freemarker:

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

Which returns the following:

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

This first response is great, but there are further subfolders/files beneath the four folders returned above. The end result will need to include these subfolders/files.

 

I have also tried the following threads advice, but it doesn't seem to list the files/folders nicely. See link here for the thread.

 

A second stackoverflow post gives advice, but I wasn't able to replicate billerby's advice correctly to traverse and store subfolders/files in a model. I believe this could be the right direction, but couldn't get it to run correctly.

 

 

Can anyone suggest me please

Outcomes