cancel
Showing results for 
Search instead for 
Did you mean: 

Pagination CMIS query results

agz
Champ on-the-rise
Champ on-the-rise
Hi all,
I'm working with Alfresco Community 4.0.e through CMIS.

In a Java class I have a query that find all documents in a specified folder:


SELECT *
FROM cmis:document
WHERE IN_FOLDER('workspace://SpacesStore/d588e663-7dc4-48b2-be8e-b6044584f769')


this query give mi 28 results and I want to have pagination every 25 results.
In my Java class I have:

ItemIterable<QueryResult> risultati = <SOMETHING>.getSession(Security.connectedUser()).query(query,false);

At this point I try to have pagination of my results but I have tried in different ways but with no result.

I introduced in the code the OperationContext because I have tried this approach <a>http://forums.alfresco.com/forum/developer-discussions/alfresco-api/opencmis-extension-paging-proble...</a>
<em>(the code below is extracted from above topic and adapted)</em>

Session session = cmisClient.getSession();
      OperationContext operationContext = new OperationContextImpl();
      operationContext.setMaxItemsPerPage(25);
      String queryString = <MYQUERY>;
      ItemIterable<QueryResult> results = session.query(queryString, false,operationContext);
      
                int pageNumber = 0;
      boolean finished = false;
      int count = 0;
      while (!finished) {
         ItemIterable<QueryResult> currentPage = results.skipTo(count).getPage();
         for (QueryResult qResult : currentPage) {
                        <SOME LOGIC>   
         count++;
         }
         pageNumber++;
           if (!currentPage.getHasMoreItems())
               finished = true;
      }


but in
ItemIterable<QueryResult> currentPage = results.skipTo(count).getPage();
after first 25 results I have a CmisRuntimeException because currentaPage have no data

…but where are 3 records after 25???

Thanks in advance.
3 REPLIES 3

goebel
Champ on-the-rise
Champ on-the-rise
Hi

Today it ran into the same Problem. After losing lot of time in debugging an googling, I managed to get it working but I still do not know if it's the right way (or solution)

How do you create you session ? Do you use an url like "http://alfrescoServer:8080/alfresco/s/cmis" ? I had exactly the same problem you had when I was using such an URL to create my session. After changing it to "http://alfrescoServer:8080/alfresco/cmisatom", the same code worked for me. (Which is according to alfresco help the 'alfresco open cmis extension')
In all the cmis documention on alfresco wiki and examples, I only found the alfresco/s/cmis url. So I am still a little concerned if I should use the cmisatom extension

Let me hear if that fixed your problem too.

Georges Goebel

chayiadp
Champ in-the-making
Champ in-the-making
I solve the problem. i know the post is old but it's possible it helps someone
Sorry for my english


   OperationContext tmpOperationContext = new OperationContextImpl();
      int numRowsPage = 2;
      tmpOperationContext.setMaxItemsPerPage(numRowsPage);
      String tmpQuery = "SELECT " + PropertyIds.NAME + " FROM cmis:document";
      ItemIterable<QueryResult> tmpResults = aSession.query(tmpQuery, true, tmpOperationContext);
      
      int count= 0;
      
      while(tmpResults.skipTo(count*numRowsPage).getHasMoreItems()){
         ItemIterable<QueryResult> tmpPage = tmpResults.skipTo(count*numRowsPage).getPage();
         count++;
         for(QueryResult tmpRegistro: tmpPage) {
            System.out.println(tmpRegistro.getPropertyById(PropertyIds.NAME).getFirstValue());
         }
      }

chayiadp
Champ in-the-making
Champ in-the-making
I solve the problem. i know the post is old but it's possible it helps someone
Sorry for my english


   OperationContext tmpOperationContext = new OperationContextImpl();
      int numRowsPage = 2;
      tmpOperationContext.setMaxItemsPerPage(numRowsPage);
      String tmpQuery = "SELECT " + PropertyIds.NAME + " FROM cmis:document";
      ItemIterable<QueryResult> tmpResults = aSession.query(tmpQuery, true, tmpOperationContext);
      
      int count= 0;
      
      while(tmpResults.skipTo(count*numRowsPage).getHasMoreItems()){
         ItemIterable<QueryResult> tmpPage = tmpResults.skipTo(count*numRowsPage).getPage();
         count++;
         for(QueryResult tmpRegistro: tmpPage) {
            System.out.println(tmpRegistro.getPropertyById(PropertyIds.NAME).getFirstValue());
         }
      }