cancel
Showing results for 
Search instead for 
Did you mean: 

Space size

fedemori
Champ in-the-making
Champ in-the-making
Hi,
how I can calculate the size of an Alfresco Share Site or a Space?

Thanks Federico
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator
You probably need to create some java utility class which could get sitename iterate though it's all documents of document library and calculate total size occupied.
This is really a very useful usecase but I am not able to recollect any out of box feature though which this can be achieved.Can anybody else share their thoughts on that?

jpotts
World-Class Innovator
World-Class Innovator
It would be quite easy to do with a script that leverages OpenCMIS (Java) or cmislib (Python).

For example, here is a Groovy script from the CMIS & Apache Chemistry in Action book that dumps the descendants of a folder:
https://github.com/fmui/ApacheChemistryInAction/blob/master/chapter2/listing2.2.getDescendants.groov...

You could easily modify that to compute a running total of the value of each child's "cmis:contentStreamLength" property.

Jeff

fedemori
Champ in-the-making
Champ in-the-making
Thanks jpotts, I created a tool that recovers recursive CMIS:contentStreamLength from all contents of a folder

mitpatoliya
Star Collaborator
Star Collaborator
Great Job Federico,
It would be really helpful to other members if you could share your tool.

fedemori
Champ in-the-making
Champ in-the-making
this is my testcode

public void getDimension() throws Exception{
      String parentFolder = "documentLibrary";
      String site = "workspace://SpacesStore/48299b30-d909-41e4-b7c7-73a504d5161d";
      Session session = CmisUtil.createCmisSession(ALFRESCO_USER, ALFRESCO_PWD, ALFRESCO_CMIS_URL);
      RepositoryCapabilities caps =
        session.getRepositoryInfo().getCapabilities();
      
      Folder folder = CmisUtil.getFolderInSite(session, parentFolder, site);

      if (!caps.isGetDescendantsSupported()) {
         throw new Exception("\n Warning: getDescendants " +
                  "not supported in this repository");
      } else {
         System.out.println("\ngetDescendants " +
                  "is supported on this repository.");

         
          for (Tree<FileableCmisObject> t : folder.getDescendants(-1)) {
              printTree(t , "");
          }
          System.out.println("\nSize of " +
               folder.getName() + ": " + size);
      } 

   }
private static void printTree(Tree<FileableCmisObject> tree,
             String tab) throws Exception {
         long value = 0;
         for(Property<?> property : tree.getItem().getProperties()){
            String queryName = property.getQueryName();
              if (queryName.equalsIgnoreCase("cmis:contentStreamLength")){
                 Object obj = property.getFirstValue();
               BigInteger bi = (BigInteger) obj;
               value = bi.longValue();
               size = size + value;
               break;}
         }
         System.out.println("Size of " +
               tree.getItem().getName() + ": " + value);
            
         
          for (Tree<FileableCmisObject> t:  tree.getChildren()) {
              printTree(t, tab + "  ");
          }
   }

Thank you for all, but when I try to run your code I got the error:

2 compilation errors:

Apparent variable 'size' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'size' but left out brackets in a place not allowed by the grammar.
at line: 77, column: 21

Apparent variable 'size' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'size' but left out brackets in a place not allowed by the grammar.
at line: 77, column: 28

can you explain to me what that mean