Merged searchapi (5.2.1) to 5.2.N (5.2.1)

129780 gjames: SEARCH-114: Adding paging support


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130172 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-06 14:18:04 +00:00
parent 67c21ad600
commit fbebd84cd4
7 changed files with 47 additions and 4 deletions

View File

@@ -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, null, null, null, null, null, null, null, false);
Params.RecognizedParams recognizedParams = new Params.RecognizedParams(null, searchQuery.getPaging(), null, null, null, null, null, null, false);
Params params = Params.valueOf(null, recognizedParams, searchQuery, webScriptRequest);
//Turn the params into the Java SearchParameters object

View File

@@ -86,7 +86,7 @@ public class ResultMapper
);
Integer total = Integer.valueOf(totalItems.intValue());
return CollectionWithPagingInfo.asPaged(null, noderesults, noderesults.size() < total, total);
return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, noderesults.size() < total, total);
}
}

View File

@@ -31,6 +31,7 @@ import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
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.ResultSet;
@@ -64,6 +65,7 @@ public class SearchMapper
SearchParameters sp = new SearchParameters();
fromQuery(sp, searchQuery.getQuery());
fromPaging(sp, searchQuery.getPaging());
//Hardcode workspace store
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
@@ -99,4 +101,13 @@ public class SearchMapper
sp.setSearchTerm(q.getUserQuery());
}
public void fromPaging(SearchParameters sp, Paging paging)
{
if (paging != null)
{
sp.setMaxItems(paging.getMaxItems());
sp.setSkipCount(paging.getSkipCount());
}
}
}

View File

@@ -26,6 +26,8 @@
package org.alfresco.rest.api.search.model;
import org.alfresco.rest.framework.resource.parameters.Paging;
/**
* POJO class representing the JSON body for a search request
*
@@ -34,6 +36,7 @@ package org.alfresco.rest.api.search.model;
public class SearchQuery
{
Query query;
Paging paging;
public SearchQuery()
{
@@ -48,4 +51,14 @@ public class SearchQuery
{
this.query = query;
}
public Paging getPaging()
{
return paging;
}
public void setPaging(Paging paging)
{
this.paging = paging;
}
}

View File

@@ -26,6 +26,8 @@
package org.alfresco.rest.framework.resource.parameters;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
/**
* Represents paging of collections of resources. Set by the client request.<br/>
@@ -77,7 +79,8 @@ public class Paging
return this.maxItems;
}
public static Paging valueOf(int skipCount, int maxItems)
@JsonCreator
public static Paging valueOf(@JsonProperty("skipCount") int skipCount, @JsonProperty("maxItems") int maxItems)
{
return new Paging(skipCount,maxItems);
}

View File

@@ -36,6 +36,7 @@ import org.alfresco.rest.api.search.impl.SearchMapper;
import org.alfresco.rest.api.search.model.Query;
import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
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.SearchParameters;
@@ -127,6 +128,18 @@ public class SearchMapperTests
assertEquals("Heload", searchParameters.getSearchTerm());
}
@Test
public void fromPaging() throws Exception
{
SearchParameters searchParameters = new SearchParameters();
//Doesn't error
searchMapper.fromPaging(searchParameters, null);
Paging paging = Paging.DEFAULT;
searchMapper.fromPaging(searchParameters, paging);
assertEquals(searchParameters.getMaxItems(),paging.getMaxItems());
assertEquals(searchParameters.getSkipCount(),paging.getSkipCount());
}
private SearchQuery minimalQuery()
{
SearchQuery sq = new SearchQuery();

View File

@@ -63,12 +63,15 @@ public class SearchQuerySerializerTests implements RequestReader
@Test
public void testDeserializeQuery() throws IOException
{
String json = "{ \"query\": {\"query\": \"g*\",\"userQuery\": \"great\",\"language\": \"bob\"}}";
String json = "{ \"query\": {\"query\": \"g*\",\"userQuery\": \"great\",\"language\": \"bob\"}, "
+ "\"paging\": {\"maxItems\": \"99\",\"skipCount\": \"4\"}}";
SearchQuery searchQuery = extractFromJson(json);
assertEquals(SearchQuery.class, searchQuery.getClass());
assertEquals("bob", searchQuery.getQuery().getLanguage());
assertEquals("g*", searchQuery.getQuery().getQuery());
assertEquals("great", searchQuery.getQuery().getUserQuery());
assertEquals(99, searchQuery.getPaging().getMaxItems());
assertEquals(4, searchQuery.getPaging().getSkipCount());
}
private SearchQuery extractFromJson(String json) throws IOException