diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/queries.post.atomfeed.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/queries.post.atomfeed.ftl
index ec0636c43c..da3f4f2be4 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/cmis/queries.post.atomfeed.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/queries.post.atomfeed.ftl
@@ -18,7 +18,7 @@
[@pagingLib.opensearch cursor/]
[@pagingLib.cmis cursor/]
-[#assign rs = cmisresultset(resultset)]
+[#assign rs = cmisresultset(resultset, cursor)]
[#list rs.rows as row]
[@entryLib.row row=row renditionfilter=renditionFilter includeallowableactions=includeAllowableActions includerelationships=includeRelationships/]
[/#list]
diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/query.get.atomfeed.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/query.get.atomfeed.ftl
index e2b1588582..b4c64fbfd9 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/cmis/query.get.atomfeed.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/query.get.atomfeed.ftl
@@ -18,7 +18,7 @@
[@pagingLib.opensearch cursor/]
[@pagingLib.cmis cursor/]
-[#assign rs = cmisresultset(resultset)]
+[#assign rs = cmisresultset(resultset, cursor)]
[#list rs.rows as row]
[@entryLib.row row=row includeallowableactions=includeAllowableActions includerelationships=includeRelationships/]
[/#list]
diff --git a/config/alfresco/templates/webscripts/org/alfresco/paging.lib.atom.ftl b/config/alfresco/templates/webscripts/org/alfresco/paging.lib.atom.ftl
index da30114721..56afaa4118 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/paging.lib.atom.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/paging.lib.atom.ftl
@@ -63,11 +63,7 @@
[#macro opensearch cursor]
[#-- NOTE: this macro requires the definition of xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" in --]
[#-- the enclosing document --]
-[#-- don't display totalResults if totalPages is < 0 (CMIS) and pageSize is > 0 --]
-[#-- because in this case we don't know the total number of results --]
-[#if (cursor.totalPages != -1 && cursor.pageSize > 0)]
- ${cursor.totalRows?c}
-[/#if]
+${cursor.totalRows?c}
${cursor.startRow?c}
${cursor.pageSize?c}
[/#macro]
@@ -75,11 +71,7 @@
[#macro cmis cursor]
[#-- NOTE: this macro requires the definition of xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" in --]
[#-- the enclosing document --]
-[#-- don't display totalResults if totalPages is < 0 (CMIS) and pageSize is > 0 --]
-[#-- because in this case we don't know the total number of results --]
-[#if (cursor.totalPages != -1 && cursor.pageSize > 0)]
- ${cursor.totalRows?c}
-[/#if]
+${cursor.totalRows?c}
[/#macro]
[#macro changelinks changeLog]
diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISResultSetMethod.java b/source/java/org/alfresco/repo/cmis/rest/CMISResultSetMethod.java
index a3df241117..36c1f79cb3 100644
--- a/source/java/org/alfresco/repo/cmis/rest/CMISResultSetMethod.java
+++ b/source/java/org/alfresco/repo/cmis/rest/CMISResultSetMethod.java
@@ -22,6 +22,7 @@ import java.util.List;
import org.alfresco.cmis.CMISResultSet;
import org.alfresco.repo.web.scripts.RepositoryImageResolver;
+import org.alfresco.repo.web.util.paging.Cursor;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
@@ -60,7 +61,7 @@ public final class CMISResultSetMethod implements TemplateMethodModelEx
{
CMISTemplateResultSet resultSet = null;
- if (args.size() == 1)
+ if (args.size() > 0)
{
Object arg0 = args.get(0);
if (arg0 instanceof BeanModel)
@@ -71,7 +72,20 @@ public final class CMISResultSetMethod implements TemplateMethodModelEx
{
if (wrapped instanceof CMISResultSet)
{
- resultSet = new CMISTemplateResultSet((CMISResultSet)wrapped, serviceRegistry, imageResolver);
+ Cursor cursor = null;
+ if (args.size() == 2)
+ {
+ Object arg1 = args.get(1);
+ if (arg1 instanceof BeanModel)
+ {
+ Object wrapped1 = ((BeanModel)arg1).getWrappedObject();
+ if (wrapped1 != null && wrapped1 instanceof Cursor)
+ {
+ cursor = (Cursor)wrapped1;
+ }
+ }
+ }
+ resultSet = new CMISTemplateResultSet((CMISResultSet)wrapped, cursor, serviceRegistry, imageResolver);
}
}
}
diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISScript.java b/source/java/org/alfresco/repo/cmis/rest/CMISScript.java
index c5cd8a7da1..0aabb06d41 100644
--- a/source/java/org/alfresco/repo/cmis/rest/CMISScript.java
+++ b/source/java/org/alfresco/repo/cmis/rest/CMISScript.java
@@ -649,9 +649,8 @@ public class CMISScript extends BaseScopableProcessorExtension
CMISQueryOptions options = new CMISQueryOptions(statement, cmisService.getDefaultRootStoreRef());
options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
options.setSkipCount(unknownRows.getStartRow());
- options.setMaxItems(unknownRows.getPageSize());
CMISResultSet resultSet = cmisQueryService.query(options);
- Cursor cursor = paging.createCursor(unknownRows.getStartRow() + resultSet.getLength() + (resultSet.hasMore() ? 1 : 0) , page);
+ Cursor cursor = paging.createCursor(unknownRows.getStartRow() + resultSet.getLength(), page);
return paging.createPagedResult(resultSet, cursor);
}
diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISTemplateResultSet.java b/source/java/org/alfresco/repo/cmis/rest/CMISTemplateResultSet.java
index 0c8cfa5b80..1dbba79754 100644
--- a/source/java/org/alfresco/repo/cmis/rest/CMISTemplateResultSet.java
+++ b/source/java/org/alfresco/repo/cmis/rest/CMISTemplateResultSet.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
import org.alfresco.cmis.CMISPropertyDefinition;
import org.alfresco.cmis.CMISResultSet;
@@ -31,6 +32,7 @@ import org.alfresco.cmis.CMISResultSetColumn;
import org.alfresco.cmis.CMISResultSetMetaData;
import org.alfresco.cmis.CMISResultSetRow;
import org.alfresco.repo.template.TemplateNode;
+import org.alfresco.repo.web.util.paging.Cursor;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
@@ -51,6 +53,7 @@ public class CMISTemplateResultSet implements Serializable
private static final long serialVersionUID = 2245418238171563934L;
private CMISResultSet resultSet;
+ private Cursor cursor;
private ServiceRegistry serviceRegistry;
private TemplateImageResolver imageResolver;
@@ -61,9 +64,10 @@ public class CMISTemplateResultSet implements Serializable
* @param serviceRegistry
* @param imageResolver
*/
- public CMISTemplateResultSet(CMISResultSet resultSet, ServiceRegistry serviceRegistry, TemplateImageResolver imageResolver)
+ public CMISTemplateResultSet(CMISResultSet resultSet, Cursor cursor, ServiceRegistry serviceRegistry, TemplateImageResolver imageResolver)
{
this.resultSet = resultSet;
+ this.cursor = cursor;
this.serviceRegistry = serviceRegistry;
this.imageResolver = imageResolver;
}
@@ -119,6 +123,7 @@ public class CMISTemplateResultSet implements Serializable
public class TemplateIterator implements Iterator
{
private Iterator iter;
+ private int idx = 0;
/**
* Construct
@@ -135,7 +140,7 @@ public class CMISTemplateResultSet implements Serializable
*/
public boolean hasNext()
{
- return iter.hasNext();
+ return (cursor == null || idx < cursor.getRowCount()) && iter.hasNext();
}
/* (non-Javadoc)
@@ -143,7 +148,18 @@ public class CMISTemplateResultSet implements Serializable
*/
public TemplateRow next()
{
- return new TemplateRow(iter.next());
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ try
+ {
+ return new TemplateRow(iter.next());
+ }
+ finally
+ {
+ idx++;
+ }
}
/* (non-Javadoc)
diff --git a/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java
index b4194bbdb9..f2e1508bf8 100644
--- a/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java
+++ b/source/java/org/alfresco/repo/cmis/ws/DMDiscoveryServicePort.java
@@ -76,15 +76,13 @@ public class DMDiscoveryServicePort extends DMAbstractServicePort implements Dis
// TODO: includeRelationships, includeRenditions
CMISQueryOptions options = new CMISQueryOptions(parameters.getStatement(), cmisService.getDefaultRootStoreRef());
+ int skipCount = 0;
if (parameters.getSkipCount() != null && parameters.getSkipCount().getValue() != null)
{
- options.setSkipCount(parameters.getSkipCount().getValue().intValue());
+ skipCount = parameters.getSkipCount().getValue().intValue();
+ options.setSkipCount(skipCount);
}
- if (parameters.getMaxItems() != null && parameters.getMaxItems().getValue() != null)
- {
- options.setMaxItems(parameters.getMaxItems().getValue().intValue());
- }
boolean includeAllowableActions = ((null != parameters.getIncludeAllowableActions()) && (null != parameters.getIncludeAllowableActions().getValue())) ? (parameters
.getIncludeAllowableActions().getValue()) : (false);
String renditionFilter = (null != parameters.getRenditionFilter()) ? (parameters.getRenditionFilter().getValue()) : null;
@@ -103,9 +101,21 @@ public class DMDiscoveryServicePort extends DMAbstractServicePort implements Dis
EnumIncludeRelationships cmisDirection = (null != parameters.getIncludeRelationships()) ? (parameters.getIncludeRelationships().getValue()) : (null);
CMISRelationshipDirectionEnum includeRelationships = INCLUDE_RELATIONSHIPS_ENUM_MAPPING.get(cmisDirection);
+ int maxItems = -1;
+ if (parameters.getMaxItems() != null && parameters.getMaxItems().getValue() != null)
+ {
+ maxItems = parameters.getMaxItems().getValue().intValue();
+ }
+
// for each row...
+ int idx = 0;
for (CMISResultSetRow row : resultSet)
{
+ if (maxItems != -1 && idx == maxItems)
+ {
+ break;
+ }
+
CmisPropertiesType properties = new CmisPropertiesType();
Map values = row.getValues();
@@ -150,8 +160,9 @@ public class DMDiscoveryServicePort extends DMAbstractServicePort implements Dis
}
}
response.getObjects().getObjects().add(object);
+ idx++;
}
- response.getObjects().setNumItems(BigInteger.valueOf(response.getObjects().getObjects().size()));
+ response.getObjects().setNumItems(BigInteger.valueOf(skipCount + resultSet.getLength()));
response.getObjects().setHasMoreItems(resultSet.hasMore());
return response;
}