cancel
Showing results for 
Search instead for 
Did you mean: 

how can i get a path of folder and sub folder in a site ?

raju_gonda
Champ in-the-making
Champ in-the-making

please can anyone help me in this..

1 ACCEPTED ANSWER

abhinavmishra14
World-Class Innovator
World-Class Innovator

You can do it by searching all folder/subfolder nodes in a site and find the display path. You can implement a webscript in JavaScript or Java. Here is an example written in JavaScript which can provide display based on input parameters. 

getFolderInfo.get.js

main();

function main() {
var siteShortName = args["siteShortName"];
var folderPath = args["folderPath"]; //if you want to get to a folder level

var skipCount = (args["skipCount"] == null || args["skipCount"] == undefined) ? 0 : args["skipCount"];
var maxCount = (args["maxCount"] == null || args["maxCount"] == undefined) ? 10000 : args["maxCount"];
var additionalQuery = args["additionalQuery"];

var successNodes = [];
var failedNodes = [];
var totalNodes;

var query = buildQuery(siteShortName, folderPath, additionalQuery)
var page = {
skipCount: parseInt(skipCount),
maxItems: parseInt(maxCount)
};

var searchQuery = {
query: query,
language: "fts-alfresco",
page: page
};

logger.log("Executing SearchQuery: " + query)
var nodes = search.query(searchQuery);
totalNodes = nodes.length;
logger.log("Total Nodes: " + totalNodes)

for each(node in nodes) {
var folderDetails = [];
var folderName = node.name;
var nodeReference = node.nodeRef;
try {
logger.log("Fetching details for folder: " + folderName);
folderDetails["FolderName"] = folderName;
folderDetails["NodeRef"] = nodeReference;
folderDetails["DisplayPath"] = node.displayPath+"/"+folderName;
logger.log(node.displayPath+"/"+folderName);
//TODO:: Add more details as required.
successNodes[nodeReference] = folderDetails;
} catch (ex) {
logger.log("Exception occurred: " + ex.message);
failedNodes[nodeReference] = folderName + " - " + ex.message;
}
}

model.successNodes = successNodes;
model.failedNodes = failedNodes;
model.totalNodes = totalNodes;
}

function buildQuery(siteShortName, folderPath, additionalQuery) {
var query = 'PATH:"/app:company_home/st:sites/cm:' + siteShortName;

if (!!folderPath) { //if not null then process
query = query + '/cm:documentLibrary/';
var pathTokens = folderPath.split('/');
for (var each = 0; each < pathTokens.length; each++) {
query = query + 'cm:' + search.ISO9075Encode(pathTokens[each].trim()) + '/';
}
query = query + '/*"';
} else {
query = query + '/cm:documentLibrary//*"';
}

query = query + ' AND (TYPE:"cm:folder")';

//Append additionalQuery query if any
if ( !! additionalQuery) { //if not null then append
query = query + ' AND ' + additionalQuery;
}
return query;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

getFolderInfo.get.desc.xml:

<webscript>
<shortname>Extract folder information</shortname>
<description>
<![CDATA[
Parameter Name : {siteShortName}
Description : It is a mandatory parameter. E.g. of property name: test-site

Parameter Name : {folderPath}
Description : It is an optional parameter.

Parameter name : {skipCount}
Description : It is an optional parameter. Possible values are 0 to n
Default value : 0

Parameter Name : {maxCount}
Description : It is an optional parameter. Possible values are 0 to n
Default value : 10000

Parameter Name : {additionalQuery}
Description : It is an optional parameter. E.g. of additionalQuery is--> =@cm\\:name:"*Test" (folder name ends with Test)
]]>

</description>

<url>/abhinav/getFolderInfo?siteShortName={siteShortName}&amp;folderPath={folderPath}&amp;skipCount={skipCount}&amp;maxCount={maxCount}&amp;additionalQuery={additionalQuery}</url>
<authentication>admin</authentication>
</webscript>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

getFolderInfo.get.html.ftl:

<html>
<head>
<title>Folder Information</title>
</head>
<body>
<h3>Total Folders: <#if totalNodes??>${totalNodes}<#else>-</#if></h3>
<#if successNodes??>
<table border="1">
<tr>
<th align="center">FolderName</th>
<th align="center">Type And NodeRef</th>
<th align="center">DisplayPath</th>
</tr>

<#list successNodes?keys as nodeReference>
<tr>
<td align="center"> ${successNodes[nodeReference].FolderName}</td>
<td align="center"> ${successNodes[nodeReference].NodeRef}</td>
<td align="center"> ${successNodes[nodeReference].DisplayPath}</td>
</tr>
</#list>
</table>
</#if>

<#if failedNodes?is_hash_ex>
<table border="1">
<tr>
<th align="center">NodeRef</th>
<th align="center">ErrorMsg</th>
</tr>
<#assign keys = failedNodes ?keys>
<#list keys as key>
<tr>
<td align="center">${key}</td>
<td align="center">${failedNodes [key]}</td>
</tr>
</#list>
</table>
</#if>
</body>
</html>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

When you run the webscript:  http://127.0.0.1:8080/alfresco/service/abhinav/getFolderInfo?siteShortName=test&skipCount=0&maxCount...

You will see following result:

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View answer in original post

1 REPLY 1

abhinavmishra14
World-Class Innovator
World-Class Innovator

You can do it by searching all folder/subfolder nodes in a site and find the display path. You can implement a webscript in JavaScript or Java. Here is an example written in JavaScript which can provide display based on input parameters. 

getFolderInfo.get.js

main();

function main() {
var siteShortName = args["siteShortName"];
var folderPath = args["folderPath"]; //if you want to get to a folder level

var skipCount = (args["skipCount"] == null || args["skipCount"] == undefined) ? 0 : args["skipCount"];
var maxCount = (args["maxCount"] == null || args["maxCount"] == undefined) ? 10000 : args["maxCount"];
var additionalQuery = args["additionalQuery"];

var successNodes = [];
var failedNodes = [];
var totalNodes;

var query = buildQuery(siteShortName, folderPath, additionalQuery)
var page = {
skipCount: parseInt(skipCount),
maxItems: parseInt(maxCount)
};

var searchQuery = {
query: query,
language: "fts-alfresco",
page: page
};

logger.log("Executing SearchQuery: " + query)
var nodes = search.query(searchQuery);
totalNodes = nodes.length;
logger.log("Total Nodes: " + totalNodes)

for each(node in nodes) {
var folderDetails = [];
var folderName = node.name;
var nodeReference = node.nodeRef;
try {
logger.log("Fetching details for folder: " + folderName);
folderDetails["FolderName"] = folderName;
folderDetails["NodeRef"] = nodeReference;
folderDetails["DisplayPath"] = node.displayPath+"/"+folderName;
logger.log(node.displayPath+"/"+folderName);
//TODO:: Add more details as required.
successNodes[nodeReference] = folderDetails;
} catch (ex) {
logger.log("Exception occurred: " + ex.message);
failedNodes[nodeReference] = folderName + " - " + ex.message;
}
}

model.successNodes = successNodes;
model.failedNodes = failedNodes;
model.totalNodes = totalNodes;
}

function buildQuery(siteShortName, folderPath, additionalQuery) {
var query = 'PATH:"/app:company_home/st:sites/cm:' + siteShortName;

if (!!folderPath) { //if not null then process
query = query + '/cm:documentLibrary/';
var pathTokens = folderPath.split('/');
for (var each = 0; each < pathTokens.length; each++) {
query = query + 'cm:' + search.ISO9075Encode(pathTokens[each].trim()) + '/';
}
query = query + '/*"';
} else {
query = query + '/cm:documentLibrary//*"';
}

query = query + ' AND (TYPE:"cm:folder")';

//Append additionalQuery query if any
if ( !! additionalQuery) { //if not null then append
query = query + ' AND ' + additionalQuery;
}
return query;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

getFolderInfo.get.desc.xml:

<webscript>
<shortname>Extract folder information</shortname>
<description>
<![CDATA[
Parameter Name : {siteShortName}
Description : It is a mandatory parameter. E.g. of property name: test-site

Parameter Name : {folderPath}
Description : It is an optional parameter.

Parameter name : {skipCount}
Description : It is an optional parameter. Possible values are 0 to n
Default value : 0

Parameter Name : {maxCount}
Description : It is an optional parameter. Possible values are 0 to n
Default value : 10000

Parameter Name : {additionalQuery}
Description : It is an optional parameter. E.g. of additionalQuery is--> =@cm\\:name:"*Test" (folder name ends with Test)
]]>

</description>

<url>/abhinav/getFolderInfo?siteShortName={siteShortName}&amp;folderPath={folderPath}&amp;skipCount={skipCount}&amp;maxCount={maxCount}&amp;additionalQuery={additionalQuery}</url>
<authentication>admin</authentication>
</webscript>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

getFolderInfo.get.html.ftl:

<html>
<head>
<title>Folder Information</title>
</head>
<body>
<h3>Total Folders: <#if totalNodes??>${totalNodes}<#else>-</#if></h3>
<#if successNodes??>
<table border="1">
<tr>
<th align="center">FolderName</th>
<th align="center">Type And NodeRef</th>
<th align="center">DisplayPath</th>
</tr>

<#list successNodes?keys as nodeReference>
<tr>
<td align="center"> ${successNodes[nodeReference].FolderName}</td>
<td align="center"> ${successNodes[nodeReference].NodeRef}</td>
<td align="center"> ${successNodes[nodeReference].DisplayPath}</td>
</tr>
</#list>
</table>
</#if>

<#if failedNodes?is_hash_ex>
<table border="1">
<tr>
<th align="center">NodeRef</th>
<th align="center">ErrorMsg</th>
</tr>
<#assign keys = failedNodes ?keys>
<#list keys as key>
<tr>
<td align="center">${key}</td>
<td align="center">${failedNodes [key]}</td>
</tr>
</#list>
</table>
</#if>
</body>
</html>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

When you run the webscript:  http://127.0.0.1:8080/alfresco/service/abhinav/getFolderInfo?siteShortName=test&skipCount=0&maxCount...

You will see following result:

~Abhinav
(ACSCE, AWS SAA, Azure Admin)