cancel
Showing results for 
Search instead for 
Did you mean: 

BUG: CMIS paging query getTotalNumItems() is wrong

ddelapasse
Champ in-the-making
Champ in-the-making
Easily illustrated bug, the getTotalNumItems() returns ONLY the results returned up to the current page.  I saw a link that said the issue was fixed in Enterprise…has anyone fixed (or know how to fix) Community 4.2.f?  If so, could you please share the fix?  I believe this is the same issue:  https://issues.alfresco.com/jira/browse/MNT-2839 (marked fixed in Enterprise).

import org.apache.chemistry.opencmis.commons.*
import org.apache.chemistry.opencmis.commons.data.*
import org.apache.chemistry.opencmis.commons.enums.*
import org.apache.chemistry.opencmis.client.api.*

String cql = "SELECT cmis:name FROM cmis:folder"

int maxItemsPerPage = 10;
OperationContext context = session.createOperationContext();
context.setIncludeAcls(false);
context.setIncludePolicies(false);
context.setMaxItemsPerPage(maxItemsPerPage);

int reqPageNum = 0;
ItemIterable<QueryResult> results = session.query(cql, false, context).skipTo(reqPageNum * maxItemsPerPage).getPage(maxItemsPerPage);
long total = results.getTotalNumItems();
println("==========  total: "+total);  // will be WRONG and return 10

reqPageNum = 1;
results = session.query(cql, false, context).skipTo(reqPageNum * maxItemsPerPage).getPage(maxItemsPerPage);
total = results.getTotalNumItems();
println("==========  total: "+total);  // will be WRONG and return 20

1 REPLY 1

afaust
Legendary Innovator
Legendary Innovator
Hello,

this isn't a simple fix that you can just apply/backport to a single line of code. In order to solve this, internal result set interfaces had to be changed to expose previously internal information (as stated in the comment of Andrew Hind). You should find the fix included in Alfresco 5.0 Community.
The essential change is in this line: https://github.com/Alfresco/community-edition/blob/24ae86da33534a90fc10a693f48bc45556fd9d9d/projects...
But in 4.2.f you'd need to change a bit to actually be able to call getNumberFound.

Regards
Axel