AnsweredAssumed Answered

Tree traversal using Web Services is very slow

Question asked by amitoj on May 15, 2009
Or, I am doing it the wrong way.

Hi everyone,

I need to quickly query the Alfresco folder tree and create a corresponding JSON object. I have created a recursive Java method which queries its own children, but I am not sure if it's the correct way of doing it.

Its too slow and takes 3 - 4 seconds to traverse a tree with 3 folder levels and 150 nodes.

The code is


   public void justdoit(String parentfoldername, int level) throws Exception
   {
      ParentReference parent = new ParentReference(storeRef, null, parentfoldername, Constants.ASSOC_CONTAINS, null);
      QueryResult queryResult = repositoryService.queryChildren(parent);
      ResultSet resultSet = queryResult.getResultSet();
      ResultSetRow[] rows = resultSet.getRows();
       
      String name = null;
      String type = null;
      String path = null;
      
      String spacer = "";
      
      for (int i = 0 ; i < level ; i++)
      {
         spacer = spacer + "\t\t";
      }
      
      if (rows != null)
      {
         for(ResultSetRow row : rows)
         {
            for (NamedValue namedValue : row.getColumns())
            {
               if (namedValue.getName().endsWith("name"))
               {   
                  name = namedValue.getValue();
                  System.out.println(spacer + "name = "+ name);
               }

               if (namedValue.getName().endsWith("path"))
               {   
                  path = mapNamespace(namedValue.getValue());
                  //System.out.println(spacer + "path = "+ path);
               }
            }
      
            type = removeNamespace(row.getNode().getType());

            if (type.equals("folder"))
               justdoit(path, ++level);
         }
      }
   }


Any help will be very much appreciated.

Regards,

Amitoj.

Outcomes