How to find all the documents and their sizes in a site?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
madhu_sudireddy
Active Member

How to find all the documents and their sizes in a site?

How to find all the documents and their sizes in a site?

any web script url or java script code?

1 Reply
Moderator
Moderator

Re: How to find all the documents and their sizes in a site?

madhu sudireddy You can do it by searching all nodes in a site and find the details of the nodes. You can implement a webscript in JavaScript or java. Here is an example written in JavaScript which provides necessary details based on input parameters. 

getNodeInfo.get.js

main();

function main() {
var objectTypes = args["objectTypes"];
var siteShortName = args["siteShortName"];
var folderPath = args["folderPath"];

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, objectTypes, 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 nodeDetails = [];
var nodeName = node.name;
var nodeReference = node.nodeRef;
try {
logger.log("Fetching details for node: " + nodeName);
nodeDetails["NodeName"] = nodeName;
nodeDetails["NodeRef"] = nodeReference;
nodeDetails["MimeType"] = node.mimetype;
nodeDetails["NodeSize"] = parseInt(node.size) + " (bytes)";
nodeDetails["DisplayPath"] = node.displayPath;
successNodes[nodeReference] = nodeDetails;
} catch (ex) {
logger.log("Exception occurred: " + ex.message);
failedNodes[nodeReference] = nodeName + " - " + ex.message;
}
}

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

function buildQuery(siteShortName, objectTypes, 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//*"';
}
var objectTypeArr = objectTypes.split(',');
var arrayLength = objectTypeArr.length;

if (arrayLength == 1) {
query = query + ' AND (TYPE:"' + objectTypeArr + '")';
} else {
query = query + ' AND (';
for (var each = 0; each < arrayLength; each++) {
query = query + 'TYPE:"' + objectTypeArr[each].trim() + '"';
if (each != arrayLength - 1) {
query = query + ' OR ';
}
}

query = query + ')';
}

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

getNodeInfo.get.desc.xml:

<webscript>
<shortname>Extract node information</shortname>
<description>
<![CDATA[
Parameter name : {objectTypes}
Possible values : It is a mandatory parameter. It can be comma (,) separated values of object types.
E.g. of object type: cm:content, custom:contentObject etc.
An OR query will be formed if multiple object types are provided separated by comma.
Example query: (TYPE:"cm:content" OR TYPE:"custom:contentObject")

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 a mandatory parameter. Possible values are 0 to n
Default value : 0

Parameter Name : {maxCount}
Description : It is a mandatory 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:"*.jpeg" (file name ends with .jpeg)
]]>

</description>

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

getNodeInfo.get.html.ftl:

<html>
<head>
<title>Node Information</title>
</head>
<body>
<h3>Total Nodes: <#if totalNodes??>${totalNodes}<#else>-</#if></h3>
<#if successNodes??>
<table border="1">
<tr>
<th align="center">NodeName</th>
<th align="center">NodeRef</th>
<th align="center">MimeType</th>
<th align="center">NodeSize</th>
<th align="center">DisplayPath</th>
</tr>

<#list successNodes?keys as nodeReference>
<tr>
<td align="center"> ${successNodes[nodeReference].NodeName}</td>
<td align="center"> ${successNodes[nodeReference].NodeRef}</td>
<td align="center"> ${successNodes[nodeReference].MimeType}</td>
<td align="center"> ${successNodes[nodeReference].NodeSize}</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>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍