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

130181 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1)
      129821 gjames: SEARCH-150: Implementing include in the JSON body


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130332 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-09-06 22:04:51 +00:00
parent 7e95472e8c
commit e8e0209f8c
4 changed files with 81 additions and 5 deletions

View File

@@ -42,8 +42,18 @@ import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.lang.NotImplementedException;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLINK;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PROPERTIES;
import static org.alfresco.service.cmr.search.SearchService.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Maps from a json request and a solr SearchParameters object.
*
@@ -51,6 +61,9 @@ import static org.alfresco.service.cmr.search.SearchService.*;
*/
public class SearchMapper
{
public static final List<String> PERMITTED_INCLUDES
= Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES);
/**
* Turn the params into the Java SearchParameters object
@@ -64,6 +77,7 @@ public class SearchMapper
SearchParameters sp = new SearchParameters();
fromQuery(sp, searchQuery.getQuery());
fromPaging(sp, searchQuery.getPaging());
validateInclude(searchQuery.getInclude());
//Hardcode workspace store
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
@@ -109,4 +123,20 @@ public class SearchMapper
sp.setSkipCount(paging.getSkipCount());
}
}
public void validateInclude(List<String> includes)
{
if (includes != null && !includes.isEmpty())
{
for (String inc:includes)
{
if (!PERMITTED_INCLUDES.contains(inc))
{
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
new Object[] { inc });
}
}
}
}
}

View File

@@ -30,6 +30,8 @@ import org.alfresco.rest.framework.resource.parameters.Paging;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List;
/**
* POJO class representing the JSON body for a search request
*
@@ -39,15 +41,18 @@ public class SearchQuery
{
private final Query query;
private final Paging paging;
private final List<String> include;
public static final SearchQuery EMPTY = new SearchQuery(null, null);
public static final SearchQuery EMPTY = new SearchQuery(null, null, null);
@JsonCreator
public SearchQuery(@JsonProperty("query") Query query,
@JsonProperty("paging") Paging paging)
@JsonProperty("paging") Paging paging,
@JsonProperty("include") List<String> include)
{
this.query = query;
this.paging = paging;
this.include = include;
}
public Query getQuery()
@@ -59,4 +64,9 @@ public class SearchQuery
{
return paging;
}
public List<String> getInclude()
{
return include;
}
}