cancel
Showing results for 
Search instead for 
Did you mean: 

Listing the repo

sledwich
Champ in-the-making
Champ in-the-making
I have originally posted this
I am new to alfresco and tried everywhere to find out how to iterate through the repository using the soap interface but so far can only see the Query interface which is not really an iterative process.


I just want to iterate the tree to put all the contents in the repository into a java tree.

Can anybody point me in the right direction thanks.
to the prog env. which is the wrong place I think (sorry for that)

I need to put the entire contents of the SpacesStore into a java tree and I am using soap. So far I have managed to find

        Reference reference = new Reference(STORE, null, "/app:company_home/*[@cm:name=\"" + spaceName + "\"]");
       
        Predicate predicate = new Predicate(new Reference[]{reference}, null, null);

        Node[] nodes = repositoryService.get(predicate);
       
        Query query = new Query(
                Constants.QUERY_LANG_LUCENE,
                "+PARENT:\"workspace://SpacesStore/"+ nodes[0].getReference().getUuid() + "\"");
       
        // Execute the query
        QueryResult queryResult = repositoryService.query(STORE, query, false);
       
        // Display the results
        ResultSet resultSet = queryResult.getResultSet();
        ResultSetRow[] rows = resultSet.getRows();
       
        if (rows != null)
        {
            // Get the infomation from the result set
            for(ResultSetRow row : rows)
            {
                String nodeId = row.getNode().getId();
//                ContentResult contentResult = new ContentResult(nodeId);
               
                for (NamedValue namedValue : row.getColumns())
                {
                   System.out.println(namedValue.getName()+"  :  "+namedValue.getValue());
                 if(namedValue.getName().endsWith(Constants.PROP_NAME) == true )
                 {
                       TreeItem item = new TreeItem( treeMailMerge, SWT.NONE );
                       item.setText(namedValue.getValue());
   
                 }
                        }
           }
        }
   }

This code will list me the contents of a particular folder which I can iteratively work through but When I change the folder name to * it does not work it reports an exception saying the line
Node[] nodes = repositoryService.get(predicate);
only supports a single reference. I am stuck and ANY help would be really appreciated. Thanks in advance.
1 REPLY 1

sledwich
Champ in-the-making
Champ in-the-making
OK - managed to get pretty much what I want to do so here it is. If it helps somebody else not go through the struggle I did to get to this point then thats good.


   void loadStore(String spaceName, RepositoryServiceSoapBindingStub repositoryService) throws RepositoryFault, RemoteException
   {
      Query query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/{http://www.alfresco.org/model/application/1.0}company_home/*\"");

//      Execute the query
      QueryResult queryResult = repositoryService.query(STORE, query, false);

//      Load the results
      ResultSet resultSet = queryResult.getResultSet();
      ResultSetRow[] rows = resultSet.getRows();
      if (rows == null)
      {
         System.out.println("No query results found.");
      }
      else
      {
         System.out.println("Results from query:");
          TreeItem item = new TreeItem( this.treeMailMerge, SWT.NONE );
          item.setText("root");
         outputResultSet(repositoryService, rows, item);
      }
   }
   
   
    public void outputResultSet(RepositoryServiceSoapBindingStub repositoryService, ResultSetRow[] rows, TreeItem parentTreeItem) throws RepositoryFault, RemoteException
    {
        if (rows != null)
        {
            for (ResultSetRow row :rows)
            {
                for( NamedValue namedValue: row.getColumns())
                {

                   if(namedValue.getName().endsWith(Constants.PROP_NAME) == true )
                   {
                      
                      //LOAD THE RESULT INTO AN SWT TREE
                      TreeItem item = new TreeItem( parentTreeItem, SWT.NONE );
                      item.setText(namedValue.getValue());
                      
                     // Get the id of the first result
                     Reference reference = new Reference(STORE, row.getNode().getId(), null);

                     // Get the parent(s) of the first result
                     QueryResult childQueryResult = repositoryService.queryChildren(reference);

                     // Get the child of the this node
                     ResultSet childResultSet = childQueryResult.getResultSet();
                     ResultSetRow[] childRows = childResultSet.getRows();
                     if (childRows != null)
                        outputResultSet(repositoryService, childRows, item);
                   }
                }
            }
        }
    }