07-16-2019 01:23 AM
How to find how many folders and documents are present in a site?
Can someone please help with this?
07-16-2019 01:52 AM
You can use this webscript to get list.(inbuilt webscript)
You can create custom webscript to list folder.
https://docs.alfresco.com/5.2/concepts/ws-folderListing-intro.html
07-16-2019 05:55 AM
If alfresco has a web script for getting number of folders in a site, can you please share?
07-16-2019 12:23 PM
This should do: http://localhost:8080/alfresco/service/slingshot/doclib/doclist/node/site/{siteId}/documentlibrary/
07-18-2019 01:12 AM
With this web script, i'm only getting count of folders in document library not their sub folders, I need to get the sub-folders count also included, sorry din't mention it before.
07-18-2019 03:21 AM
For that type of structure,you have to create your own script.
07-23-2019 03:47 AM
this is only giving the folders in document library not sub folders , can you provide me the script for sub folders count also.
11-22-2019 02:21 AM
How can one use this api in java code, I have similar kind of requirement and I tried calling this api through the code but could not achieve this due to authentication issue(401 error).
11-22-2019 09:56 AM
Create a javascript of java backed webscript. Write search query that will take siteshortname and object type (your custom content type, custom folder type, cm:content, cm:folder etc.) and performs a search and returns the count.
There is a high level code which you can implement in your java backed webscript:
Query would be something like: String countQuery = 'PATH:"/app:company_home/st:sites/cm:' + search.ISO9075Encode(siteShortName) + '//*" AND TYPE:"'+type+'"'; Where siteShortName and type you will pass for getting the related results. You will below sample method to get the count and use it whereever you want: long countResult = getObjectCount(countQuery); public long getObjectCount(String query) { SearchParameters searchParameters = new SearchParameters(); searchParameters.setQuery(query); searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE); searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setMaxItems(Integer.MAX_VALUE); searchParameters.setMaxPermissionChecks(Integer.MAX_VALUE); ResultSet results = null; long objectCount = 0; try { results = searchService.query(searchParameters); if (null != results) { objectCount = results.getNumberFound(); } } catch (AlfrescoRuntimeException alfException) { LOGGER.error(alfException.getMessage(), alfException); } finally { if (results != null) { results.close(); } } return objectCount; }
For javascript you can refer below sample and customize as per your need:
<webscript> <shortname>Count Files/folder</shortname> <description> Counts Objects of given type Parameter name : {type} Example : custom:contentType, cm:content, cm:folder etc. Parameter name : {siteShortName} Example : test-site </description> <url>/countObjects?type={type}&siteShortName={siteShortName}&skipCount={skipCount}&maxCount={maxCount}</url> <format>any</format> </webscript>
function main(){ var siteCount = []; var type = args["type"]; var siteShortName = args["siteShortName"]; var skipCount = (args["skipCount"]==null || args["skipCount"]==undefined)?0:args["skipCount"]; var maxCount = (args["maxCount"]==null || args["maxCount"]==undefined)?100000:args["maxCount"]; var countQuery = 'PATH:"/app:company_home/st:sites/cm:' + search.ISO9075Encode(siteShortName) + '//*" AND TYPE:"'+type+'"'; logger.log("CountQuery: "+countQuery); var page = { skipCount : parseInt(skipCount), maxItems : parseInt(maxCount) }; var searchQuery = { query : countQuery, language : "lucene", page : page }; var nodes = search.query(searchQuery); var nodeCount = nodes.length; siteCount[siteShortName] = nodeCount; model.siteCount=siteCount; } main();
<html>
<head>
<title>Count of a given type</title>
</head>
<body>
<h4>Count of the given objects</h4>
<b>Count Query:</b> <#if query??>${query}<#else>-</#if><br/>
<hr/>
<#if siteCount?is_hash_ex>
<table border="1">
<tr>
<th align="center">Site Short Name</th>
<th align="center">Count</th>
</tr>
<#assign keys = siteCount ?keys>
<#list keys as key>
<tr>
<td align="center">${key}</td>
<td align="center">${siteCount [key]}</td>
</tr>
</#list>
</table>
</#if>
</body>
</html>
11-25-2019 12:04 PM
Thank you for the revert.
I was able to count records in a datalist with this approach(Java backed code).
I also wanted to calculate total size of the datalist in terms of MB/GB(based on amount of records present). What are the possible methods which will return this result. Also, for document library how can I caculate the total number of files and folder count alongwith total size of documentlibrary present using java code. (required for a timer job)
Explore our Alfresco products with the links below. Use labels to filter content by product module.