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/BRANCHES/DEV/5.2.N/root@130176 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-06 14:18:33 +00:00
parent faeb31dabe
commit 43bf3e848c
4 changed files with 12 additions and 6 deletions

View File

@@ -88,7 +88,7 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP
SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class); SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class);
//Parse the parameter //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); Params params = Params.valueOf(null, recognizedParams, searchQuery, webScriptRequest);
//Turn the params into the Java SearchParameters object //Turn the params into the Java SearchParameters object

View File

@@ -31,6 +31,7 @@ import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.search.model.SearchEntry; 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.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Paging;
import org.alfresco.rest.framework.resource.parameters.Params; import org.alfresco.rest.framework.resource.parameters.Params;
@@ -73,6 +74,7 @@ public class ResultMapper
*/ */
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, ResultSet results) public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, ResultSet results)
{ {
SearchQuery searchQuery = (SearchQuery) params.getPassedIn();
Long totalItems = results.getNumberFound(); Long totalItems = results.getNumberFound();
List<Node> noderesults = new ArrayList(); List<Node> noderesults = new ArrayList();
@@ -86,7 +88,8 @@ public class ResultMapper
); );
Integer total = Integer.valueOf(totalItems.intValue()); 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);
} }
} }

View File

@@ -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.Paging;
import org.alfresco.rest.framework.resource.parameters.Params; import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.service.cmr.repository.StoreRef; 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.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.Node;
@@ -106,6 +107,7 @@ public class SearchMapper
{ {
if (paging != null) if (paging != null)
{ {
sp.setLimitBy(LimitBy.FINAL_SIZE);
sp.setMaxItems(paging.getMaxItems()); sp.setMaxItems(paging.getMaxItems());
sp.setSkipCount(paging.getSkipCount()); sp.setSkipCount(paging.getSkipCount());
} }

View File

@@ -111,7 +111,7 @@ public class ResultMapperTests
@Test @Test
public void testNoResults() throws Exception public void testNoResults() throws Exception
{ {
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(mockParams(),new EmptyResultSet()); CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(mockParams(new SearchQuery()),new EmptyResultSet());
assertNotNull(collection); assertNotNull(collection);
assertFalse(collection.hasMoreItems()); assertFalse(collection.hasMoreItems());
assertTrue(collection.getTotalItems() < 1); assertTrue(collection.getTotalItems() < 1);
@@ -121,7 +121,7 @@ public class ResultMapperTests
public void testToCollectionWithPagingInfo() throws Exception public void testToCollectionWithPagingInfo() throws Exception
{ {
ResultSet results = mockResultset(); ResultSet results = mockResultset();
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(),results); CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(new SearchQuery()),results);
assertNotNull(collectionWithPage); assertNotNull(collectionWithPage);
Long found = results.getNumberFound(); Long found = results.getNumberFound();
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue()); assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
@@ -142,10 +142,11 @@ public class ResultMapperTests
return results; return results;
} }
private Params mockParams() private Params mockParams(SearchQuery searchQuery)
{ {
Params params = mock(Params.class); Params params = mock(Params.class);
when(params.getInclude()).thenReturn(new ArrayList<String>()); when(params.getInclude()).thenReturn(new ArrayList<String>());
when(params.getPassedIn()).thenReturn(searchQuery);
return params; return params;
} }