From f78d1f81f737dca1d9db173cbab9160db9cb9e6f Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Tue, 6 Sep 2016 22:04:05 +0000 Subject: [PATCH] Merged 5.2.N (5.2.1) to HEAD (5.2) 130176 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1) 129787 gjames: SEARCH-114: No default paging. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130327 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/search/SearchApiWebscript.java | 2 +- .../org/alfresco/rest/api/search/impl/ResultMapper.java | 5 ++++- .../org/alfresco/rest/api/search/impl/SearchMapper.java | 4 +++- .../org/alfresco/rest/api/search/ResultMapperTests.java | 7 ++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java b/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java index 59b13f89e7..f7ecdccf88 100644 --- a/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java +++ b/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java @@ -88,7 +88,7 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class); //Parse the parameter - Params.RecognizedParams recognizedParams = new Params.RecognizedParams(null, searchQuery.getPaging(), null, null, null, null, null, null, false); + Params.RecognizedParams recognizedParams = new Params.RecognizedParams(null, null, null, null, null, null, null, null, false); Params params = Params.valueOf(null, recognizedParams, searchQuery, webScriptRequest); //Turn the params into the Java SearchParameters object diff --git a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java index 8790ad9385..2ef6c9c7dc 100644 --- a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java @@ -31,6 +31,7 @@ import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.api.search.model.SearchEntry; +import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Params; @@ -73,6 +74,7 @@ public class ResultMapper */ public CollectionWithPagingInfo toCollectionWithPagingInfo(Params params, ResultSet results) { + SearchQuery searchQuery = (SearchQuery) params.getPassedIn(); Long totalItems = results.getNumberFound(); List noderesults = new ArrayList(); @@ -86,7 +88,8 @@ public class ResultMapper ); Integer total = Integer.valueOf(totalItems.intValue()); - return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, noderesults.size() + params.getPaging().getSkipCount() < total, total); + int skip = searchQuery.getPaging()==null?0:searchQuery.getPaging().getSkipCount(); + return CollectionWithPagingInfo.asPaged(searchQuery.getPaging(), noderesults, noderesults.size() + skip < total, total); } } diff --git a/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java b/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java index 5ae873fa14..489e23f288 100644 --- a/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java @@ -34,6 +34,7 @@ import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Params; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.LimitBy; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.rest.api.model.Node; @@ -64,7 +65,7 @@ public class SearchMapper ParameterCheck.mandatory("query", searchQuery.getQuery()); SearchParameters sp = new SearchParameters(); - fromQuery(sp, searchQuery.getQuery()); + fromQuery(sp, searchQuery.getQuery()); fromPaging(sp, searchQuery.getPaging()); //Hardcode workspace store @@ -106,6 +107,7 @@ public class SearchMapper { if (paging != null) { + sp.setLimitBy(LimitBy.FINAL_SIZE); sp.setMaxItems(paging.getMaxItems()); sp.setSkipCount(paging.getSkipCount()); } diff --git a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java index 0fad98d3fc..fee5491613 100644 --- a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java +++ b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java @@ -111,7 +111,7 @@ public class ResultMapperTests @Test public void testNoResults() throws Exception { - CollectionWithPagingInfo collection = mapper.toCollectionWithPagingInfo(mockParams(),new EmptyResultSet()); + CollectionWithPagingInfo collection = mapper.toCollectionWithPagingInfo(mockParams(new SearchQuery()),new EmptyResultSet()); assertNotNull(collection); assertFalse(collection.hasMoreItems()); assertTrue(collection.getTotalItems() < 1); @@ -121,7 +121,7 @@ public class ResultMapperTests public void testToCollectionWithPagingInfo() throws Exception { ResultSet results = mockResultset(); - CollectionWithPagingInfo collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(),results); + CollectionWithPagingInfo collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(new SearchQuery()),results); assertNotNull(collectionWithPage); Long found = results.getNumberFound(); assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue()); @@ -142,10 +142,11 @@ public class ResultMapperTests return results; } - private Params mockParams() + private Params mockParams(SearchQuery searchQuery) { Params params = mock(Params.class); when(params.getInclude()).thenReturn(new ArrayList()); + when(params.getPassedIn()).thenReturn(searchQuery); return params; }