AnsweredAssumed Answered

Opencmis extension paging problem

Question asked by mirko79 on Mar 16, 2012
Latest reply on Nov 20, 2013 by mohcinew
Hi,
i'm having problems using pagination with opencmis extension : if the last page contains only one results the "currentPage.getHasMoreItems()" on second-last page returns false and i lose one result.
For example if i set MaxItemPerPage to 10 and there are 21 results, the last is not retrieved.

I have installed Alfresco community 4.0.d (alfresco-community-4.0.d-installer-win-x64.exe)

Creation of session in client:

                        SessionFactory factory = SessionFactoryImpl.newInstance();
         Map<String, String> parameter = new HashMap<String, String>();
   
         // user credentials
         parameter.put(SessionParameter.USER, configurationUtils.getCmisUserLogin());
         parameter.put(SessionParameter.PASSWORD, configurationUtils.getCmisUserPassword());
              // ATOMPUB binding
         parameter.put(SessionParameter.ATOMPUB_URL, configurationUtils.getCmisBindingUrl());
         parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
         parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

                       List<Repository> repositories = factory.getRepositories(parameter);
                       this.session = repositories.get(0).createSession();
         

Query with pagination to cmis:


                Session session = cmisClient.getSession();
      OperationContext operationContext = new OperationContextImpl();
      operationContext.setMaxItemsPerPage(10);

      String queryString = "select d.*,w.* "
            + "from cmis:document as d join adp:my_aspect as w on d.cmis:objectId = w.cmis:objectId "
            + "where w.adp:stato = 'DA INVIARE'";
      
      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) {
            String objectId = "";
            PropertyData<?> propData = qResult.getPropertyById("cmis:objectId"); // Atom Pub binding
            if (propData != null) {
               objectId = (String) propData.getFirstValue();
            } else {
               //TODO: decidere se fare o meno
               objectId = qResult.getPropertyValueByQueryName("d.cmis:objectId"); // Web Services binding
            }
            CmisObject obj = session.getObject(session.createObjectId(objectId));
            count++;
            _log.info("CMIS obj id: [" + obj.getId() + "], name:["+ obj.getName() + "], adp:status: ["+obj.getPropertyValue("adp:stato")+"]");
         }
         pageNumber++;
           if (!currentPage.getHasMoreItems())
               finished = true;
      }

thanks

Outcomes