You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@chemistry.apache.org by Mark Streit <mc...@gmail.com> on 2012/07/21 05:22:57 UTC

ItemIterable queryResult HAS items but getTotalNumItems() returns -1

Hello,

I am using the Java OpenCMIS 0.8.0 SNAPSHOT from about a month ago against
an Alfresco 4 instance and all has been working just fine.  I am using the
AtomPub binding.  However, today after adding a some documents and writing
a test case to check that the number of records returned > 0, I got a
failure because the method: *queryResult.getTotalNumItems()* is returning a
*-1* even though there are, in fact,  2 items in the
ItemIterable<QueryResult> collection returned.

We have added a custom type namespace "acme:" to test adding some custom
properties to the cmis:Document object.  This all works fine and the code
below works as long as the assertTrue() is not used because that returns
the -1 and reports the test failed.  Although the
assertNotNull(queryResult) is technically invalid because even with NO
records found, one will not get back a null, it was a simple bypass to
confirm that in fact 2 rows get reported and the information printed by the
System.out is correct.  I also confirmed through the Chemistry Workbench
running a Query, I DO get back 2 records as well.

The test code looks like this (some of it borrowed from the *GettingStarted
*application):  We've written our own wrapper facade called CMISServices to
make the required calls via the OpenCMIS API code..


   /**
    * Test method
    * @throws CMISServiceException
    */
   @Test
   public void testSearchRepositoryUsingEquals() throws
CMISServiceException {

      String query = "SELECT * FROM acme:doc WHERE
acme:attachmentOID='1122334400556677' AND acme:category='Technical'";

      ItemIterable<QueryResult> queryResult =
cmisServices.searchRepository(query);  // calls
cmisSession.query(queryString, false) since searchAllVersions is NOT
supported on this version of AF 4

      System.out.println("***results from query " + query);


      assertNotNull(queryResult);
      //assertTrue(queryResult.getTotalNumItems() > 0);

      if (queryResult != null) {
         int i = 1;
         for (QueryResult qr : queryResult) {

System.out.println("--------------------------------------------\n" + i + "
, "
                  +
qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue() + " , "
                  + qr.getPropertyByQueryName("cmis:name").getFirstValue()
+ " , "
                  +
qr.getPropertyByQueryName("cmis:createdBy").getFirstValue() + " , "
                  +
qr.getPropertyByQueryName("cmis:objectId").getFirstValue() + " , "
                  +
qr.getPropertyByQueryName("acme:attachmentOID").getFirstValue() + " , "
                  +
qr.getPropertyByQueryName("acme:attachmentType").getFirstValue() + " , "
                  +
qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue() + "
, "
                  +
qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue() + "
, "
                  +
qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue());
            i++;
         }
      }



   }


And here's what I get in the output (if I *don't rely on that
queryResult.getTotalNumItems()* method) ... there were 2 records as
expected.

***results from query SELECT * FROM acme:doc WHERE
acme:attachmentOID='1122334400556677' AND acme:category='Technical'
--------------------------------------------
1 , D:acme:doc , DMS_CMIS.pdf , admin ,
workspace://SpacesStore/92facd3f-7ff7-4dd4-ac51-6a71d1a46207;1.0 ,
1122334400556677 , Development, DMS_CMIS.pdf , application/pdf , 235549
--------------------------------------------
2 , D:acme:doc , EMC_Test.doc , admin ,
workspace://SpacesStore/3af1a42e-9e3e-42fb-af1e-81dce1395f44;1.0 ,
1122334400556677 , Development, EMC_Test.doc , application/msword , 99328

Is this something to open a JIRA record for or am I missing something?

Thanks

Re: ItemIterable queryResult HAS items but getTotalNumItems() returns -1

Posted by Florian Müller <fm...@apache.org>.
Hi Mark,

The total number of items is an optional return value. If the repository 
provides a value, OpenCMIS returns the number (>= 0). If the repository 
does not provide a value, OpenCMIS returns -1.

See also the CMIS specification [1] and the OpenCMIS JavaDoc [2].

Why the Alfresco server doesn't provide the total number is a question 
for Alfresco.


Florian


[1] 
http://docs.oasis-open.org/cmis/CMIS/v1.0/cs01/cmis-spec-v1.0.html#_Toc243905430
[2] 
http://chemistry.apache.org/java/0.7.0/maven/apidocs/org/apache/chemistry/opencmis/client/api/ItemIterable.html#getTotalNumItems()


> Hello,
>
> I am using the Java OpenCMIS 0.8.0 SNAPSHOT from about a month ago against
> an Alfresco 4 instance and all has been working just fine.  I am using the
> AtomPub binding.  However, today after adding a some documents and writing
> a test case to check that the number of records returned>  0, I got a
> failure because the method: *queryResult.getTotalNumItems()* is returning a
> *-1* even though there are, in fact,  2 items in the
> ItemIterable<QueryResult>  collection returned.
>
> We have added a custom type namespace "acme:" to test adding some custom
> properties to the cmis:Document object.  This all works fine and the code
> below works as long as the assertTrue() is not used because that returns
> the -1 and reports the test failed.  Although the
> assertNotNull(queryResult) is technically invalid because even with NO
> records found, one will not get back a null, it was a simple bypass to
> confirm that in fact 2 rows get reported and the information printed by the
> System.out is correct.  I also confirmed through the Chemistry Workbench
> running a Query, I DO get back 2 records as well.
>
> The test code looks like this (some of it borrowed from the *GettingStarted
> *application):  We've written our own wrapper facade called CMISServices to
> make the required calls via the OpenCMIS API code..
>
>
>     /**
>      * Test method
>      * @throws CMISServiceException
>      */
>     @Test
>     public void testSearchRepositoryUsingEquals() throws
> CMISServiceException {
>
>        String query = "SELECT * FROM acme:doc WHERE
> acme:attachmentOID='1122334400556677' AND acme:category='Technical'";
>
>        ItemIterable<QueryResult>  queryResult =
> cmisServices.searchRepository(query);  // calls
> cmisSession.query(queryString, false) since searchAllVersions is NOT
> supported on this version of AF 4
>
>        System.out.println("***results from query " + query);
>
>
>        assertNotNull(queryResult);
>        //assertTrue(queryResult.getTotalNumItems()>  0);
>
>        if (queryResult != null) {
>           int i = 1;
>           for (QueryResult qr : queryResult) {
>
> System.out.println("--------------------------------------------\n" + i + "
> , "
>                    +
> qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue() + " , "
>                    + qr.getPropertyByQueryName("cmis:name").getFirstValue()
> + " , "
>                    +
> qr.getPropertyByQueryName("cmis:createdBy").getFirstValue() + " , "
>                    +
> qr.getPropertyByQueryName("cmis:objectId").getFirstValue() + " , "
>                    +
> qr.getPropertyByQueryName("acme:attachmentOID").getFirstValue() + " , "
>                    +
> qr.getPropertyByQueryName("acme:attachmentType").getFirstValue() + " , "
>                    +
> qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue() + "
> , "
>                    +
> qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue() + "
> , "
>                    +
> qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue());
>              i++;
>           }
>        }
>
>
>
>     }
>
>
> And here's what I get in the output (if I *don't rely on that
> queryResult.getTotalNumItems()* method) ... there were 2 records as
> expected.
>
> ***results from query SELECT * FROM acme:doc WHERE
> acme:attachmentOID='1122334400556677' AND acme:category='Technical'
> --------------------------------------------
> 1 , D:acme:doc , DMS_CMIS.pdf , admin ,
> workspace://SpacesStore/92facd3f-7ff7-4dd4-ac51-6a71d1a46207;1.0 ,
> 1122334400556677 , Development, DMS_CMIS.pdf , application/pdf , 235549
> --------------------------------------------
> 2 , D:acme:doc , EMC_Test.doc , admin ,
> workspace://SpacesStore/3af1a42e-9e3e-42fb-af1e-81dce1395f44;1.0 ,
> 1122334400556677 , Development, EMC_Test.doc , application/msword , 99328
>
> Is this something to open a JIRA record for or am I missing something?
>
> Thanks
>