mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
130307 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1) 130151 gjames: SEARCH-124: Implementing "limits" search api param git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130379 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -32,6 +32,7 @@ import org.alfresco.rest.api.search.model.FacetField;
|
|||||||
import org.alfresco.rest.api.search.model.FacetFields;
|
import org.alfresco.rest.api.search.model.FacetFields;
|
||||||
import org.alfresco.rest.api.search.model.FacetQuery;
|
import org.alfresco.rest.api.search.model.FacetQuery;
|
||||||
import org.alfresco.rest.api.search.model.FilterQuery;
|
import org.alfresco.rest.api.search.model.FilterQuery;
|
||||||
|
import org.alfresco.rest.api.search.model.Limits;
|
||||||
import org.alfresco.rest.api.search.model.Query;
|
import org.alfresco.rest.api.search.model.Query;
|
||||||
import org.alfresco.rest.api.search.model.Scope;
|
import org.alfresco.rest.api.search.model.Scope;
|
||||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||||
@@ -112,6 +113,7 @@ public class SearchMapper
|
|||||||
fromFacetFields(sp, searchQuery.getFacetFields());
|
fromFacetFields(sp, searchQuery.getFacetFields());
|
||||||
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
||||||
fromScope(sp, searchQuery.getScope());
|
fromScope(sp, searchQuery.getScope());
|
||||||
|
fromLimits(sp, searchQuery.getLimits());
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
@@ -429,4 +431,29 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchParameters from the Limits object
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param paging Paging
|
||||||
|
*/
|
||||||
|
public void fromLimits(SearchParameters sp, Limits limits)
|
||||||
|
{
|
||||||
|
if (limits != null)
|
||||||
|
{
|
||||||
|
if (limits.getPermissionEvaluationCount() != null)
|
||||||
|
{
|
||||||
|
sp.setMaxItems(-1);
|
||||||
|
sp.setLimitBy(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS);
|
||||||
|
sp.setMaxPermissionChecks(limits.getPermissionEvaluationCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (limits.getPermissionEvaluationTime() != null)
|
||||||
|
{
|
||||||
|
sp.setMaxItems(-1);
|
||||||
|
sp.setLimitBy(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS);
|
||||||
|
sp.setMaxPermissionCheckTimeMillis(limits.getPermissionEvaluationTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
58
source/java/org/alfresco/rest/api/search/model/Limits.java
Normal file
58
source/java/org/alfresco/rest/api/search/model/Limits.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.rest.api.search.model;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonCreator;
|
||||||
|
import org.codehaus.jackson.annotate.JsonProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POJO class representing the query Limits
|
||||||
|
**/
|
||||||
|
public class Limits
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Integer permissionEvaluationTime;
|
||||||
|
private final Integer permissionEvaluationCount;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public Limits(@JsonProperty("permissionEvaluationTime") Integer permissionEvaluationTime,
|
||||||
|
@JsonProperty("permissionEvaluationCount") Integer permissionEvaluationCount)
|
||||||
|
{
|
||||||
|
this.permissionEvaluationTime = permissionEvaluationTime;
|
||||||
|
this.permissionEvaluationCount = permissionEvaluationCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPermissionEvaluationTime()
|
||||||
|
{
|
||||||
|
return permissionEvaluationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPermissionEvaluationCount()
|
||||||
|
{
|
||||||
|
return permissionEvaluationCount;
|
||||||
|
}
|
||||||
|
}
|
@@ -51,8 +51,9 @@ public class SearchQuery
|
|||||||
private final FacetFields facetFields;
|
private final FacetFields facetFields;
|
||||||
private final Spelling spellcheck;
|
private final Spelling spellcheck;
|
||||||
private final Scope scope;
|
private final Scope scope;
|
||||||
|
private final Limits limits;
|
||||||
|
|
||||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null, null, null, null);
|
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null,null, null, null, null);
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public SearchQuery(@JsonProperty("query") Query query,
|
public SearchQuery(@JsonProperty("query") Query query,
|
||||||
@@ -65,7 +66,8 @@ public class SearchQuery
|
|||||||
@JsonProperty("facetFields") FacetFields facetFields,
|
@JsonProperty("facetFields") FacetFields facetFields,
|
||||||
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
|
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
|
||||||
@JsonProperty("spellcheck") Spelling spellcheck,
|
@JsonProperty("spellcheck") Spelling spellcheck,
|
||||||
@JsonProperty("scope") Scope scope)
|
@JsonProperty("scope") Scope scope,
|
||||||
|
@JsonProperty("limits")Limits limits)
|
||||||
{
|
{
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.paging = paging;
|
this.paging = paging;
|
||||||
@@ -78,6 +80,7 @@ public class SearchQuery
|
|||||||
this.spellcheck = spellcheck;
|
this.spellcheck = spellcheck;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.facetFields = facetFields;
|
this.facetFields = facetFields;
|
||||||
|
this.limits = limits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery()
|
public Query getQuery()
|
||||||
@@ -132,4 +135,9 @@ public class SearchQuery
|
|||||||
{
|
{
|
||||||
return facetFields;
|
return facetFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Limits getLimits()
|
||||||
|
{
|
||||||
|
return limits;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ import org.alfresco.rest.api.search.model.FacetField;
|
|||||||
import org.alfresco.rest.api.search.model.FacetFields;
|
import org.alfresco.rest.api.search.model.FacetFields;
|
||||||
import org.alfresco.rest.api.search.model.FacetQuery;
|
import org.alfresco.rest.api.search.model.FacetQuery;
|
||||||
import org.alfresco.rest.api.search.model.FilterQuery;
|
import org.alfresco.rest.api.search.model.FilterQuery;
|
||||||
|
import org.alfresco.rest.api.search.model.Limits;
|
||||||
import org.alfresco.rest.api.search.model.Query;
|
import org.alfresco.rest.api.search.model.Query;
|
||||||
import org.alfresco.rest.api.search.model.Scope;
|
import org.alfresco.rest.api.search.model.Scope;
|
||||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||||
@@ -474,10 +475,40 @@ public class SearchMapperTests
|
|||||||
assertEquals("ENUM" ,ff.getMethod().toString());
|
assertEquals("ENUM" ,ff.getMethod().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromLimits() throws Exception
|
||||||
|
{
|
||||||
|
SearchParameters searchParameters = new SearchParameters();
|
||||||
|
searchMapper.setDefaults(searchParameters);
|
||||||
|
|
||||||
|
//Doesn't error
|
||||||
|
searchMapper.fromLimits(searchParameters, null);
|
||||||
|
assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
|
||||||
|
assertEquals(100, searchParameters.getMaxItems());
|
||||||
|
|
||||||
|
searchMapper.fromLimits(searchParameters, new Limits(null, null));
|
||||||
|
assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
|
||||||
|
assertEquals(100, searchParameters.getMaxItems());
|
||||||
|
|
||||||
|
searchMapper.fromLimits(searchParameters, new Limits(null, 34));
|
||||||
|
assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
|
||||||
|
assertEquals(34, searchParameters.getMaxPermissionChecks());
|
||||||
|
assertEquals(-1, searchParameters.getMaxItems());
|
||||||
|
assertEquals(-1, searchParameters.getMaxPermissionCheckTimeMillis());
|
||||||
|
|
||||||
|
searchParameters = new SearchParameters();
|
||||||
|
searchMapper.setDefaults(searchParameters);
|
||||||
|
searchMapper.fromLimits(searchParameters, new Limits(1000, null));
|
||||||
|
assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
|
||||||
|
assertEquals(1000, searchParameters.getMaxPermissionCheckTimeMillis());
|
||||||
|
assertEquals(-1, searchParameters.getMaxItems());
|
||||||
|
assertEquals(-1, searchParameters.getMaxPermissionChecks());
|
||||||
|
}
|
||||||
|
|
||||||
private SearchQuery minimalQuery()
|
private SearchQuery minimalQuery()
|
||||||
{
|
{
|
||||||
Query query = new Query("cmis", "foo", "");
|
Query query = new Query("cmis", "foo", "");
|
||||||
SearchQuery sq = new SearchQuery(query,null, null, null, null, null, null, null, null, null, null);
|
SearchQuery sq = new SearchQuery(query,null, null, null, null, null, null, null, null, null, null, null);
|
||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,9 +104,10 @@ public class SearchQuerySerializerTests
|
|||||||
assertEquals("mylabel", ff.getLabel());
|
assertEquals("mylabel", ff.getLabel());
|
||||||
assertEquals("FC", ff.getMethod());
|
assertEquals("FC", ff.getMethod());
|
||||||
assertEquals(Integer.valueOf(5), ff.getMincount());
|
assertEquals(Integer.valueOf(5), ff.getMincount());
|
||||||
|
assertEquals(2000, searchQuery.getLimits().getPermissionEvaluationCount().intValue());
|
||||||
|
assertEquals(5000, searchQuery.getLimits().getPermissionEvaluationTime().intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeContext() throws IOException
|
public void testSerializeContext() throws IOException
|
||||||
{
|
{
|
||||||
|
@@ -63,6 +63,7 @@ public class SerializerTestHelper implements RequestReader
|
|||||||
+ "\"facetFields\": {\"facets\": [{\"field\": \"cm:creator\",\"prefix\": \"myquery2\",\"sort\": \"COUNT\",\"missing\": \"false\"}, {\"field\": \"modifier\",\"label\": \"mylabel\",\"method\": \"FC\",\"mincount\": \"5\"}]},"
|
+ "\"facetFields\": {\"facets\": [{\"field\": \"cm:creator\",\"prefix\": \"myquery2\",\"sort\": \"COUNT\",\"missing\": \"false\"}, {\"field\": \"modifier\",\"label\": \"mylabel\",\"method\": \"FC\",\"mincount\": \"5\"}]},"
|
||||||
+ "\"facetQueries\": [{\"query\": \"facquery\",\"label\": \"facnoused\"}],"
|
+ "\"facetQueries\": [{\"query\": \"facquery\",\"label\": \"facnoused\"}],"
|
||||||
+ "\"spellcheck\": {\"query\": \"alfrezco\"},"
|
+ "\"spellcheck\": {\"query\": \"alfrezco\"},"
|
||||||
|
+ "\"limits\": {\"permissionEvaluationCount\": \"2000\",\"permissionEvaluationTime\": \"5000\"},"
|
||||||
+ "\"scope\": { \"stores\": [\"workspace://SpacesStore\"]},"
|
+ "\"scope\": { \"stores\": [\"workspace://SpacesStore\"]},"
|
||||||
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user