mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -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
|
||||
|
@@ -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<Node> toCollectionWithPagingInfo(Params params, ResultSet results)
|
||||
{
|
||||
SearchQuery searchQuery = (SearchQuery) params.getPassedIn();
|
||||
Long totalItems = results.getNumberFound();
|
||||
List<Node> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -106,6 +107,7 @@ public class SearchMapper
|
||||
{
|
||||
if (paging != null)
|
||||
{
|
||||
sp.setLimitBy(LimitBy.FINAL_SIZE);
|
||||
sp.setMaxItems(paging.getMaxItems());
|
||||
sp.setSkipCount(paging.getSkipCount());
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ public class ResultMapperTests
|
||||
@Test
|
||||
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);
|
||||
assertFalse(collection.hasMoreItems());
|
||||
assertTrue(collection.getTotalItems() < 1);
|
||||
@@ -121,7 +121,7 @@ public class ResultMapperTests
|
||||
public void testToCollectionWithPagingInfo() throws Exception
|
||||
{
|
||||
ResultSet results = mockResultset();
|
||||
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(),results);
|
||||
CollectionWithPagingInfo<Node> 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<String>());
|
||||
when(params.getPassedIn()).thenReturn(searchQuery);
|
||||
return params;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user