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)
130187 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1) 129890 gjames: SEARCH-116: Implementing defaults git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130338 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
package org.alfresco.rest.api.search.impl;
|
package org.alfresco.rest.api.search.impl;
|
||||||
|
|
||||||
|
import org.alfresco.rest.api.search.model.Default;
|
||||||
import org.alfresco.rest.api.search.model.Query;
|
import org.alfresco.rest.api.search.model.Query;
|
||||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||||
import org.alfresco.rest.api.search.model.SortDef;
|
import org.alfresco.rest.api.search.model.SortDef;
|
||||||
@@ -40,6 +41,7 @@ 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;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters.Operator;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
@@ -73,7 +75,7 @@ public class SearchMapper
|
|||||||
/**
|
/**
|
||||||
* Turn the params into the Java SearchParameters object
|
* Turn the params into the Java SearchParameters object
|
||||||
* @param params
|
* @param params
|
||||||
* @return
|
* @return SearchParameters
|
||||||
*/
|
*/
|
||||||
public SearchParameters toSearchParameters(SearchQuery searchQuery)
|
public SearchParameters toSearchParameters(SearchQuery searchQuery)
|
||||||
{
|
{
|
||||||
@@ -87,6 +89,7 @@ public class SearchMapper
|
|||||||
fromSort(sp, searchQuery.getSort());
|
fromSort(sp, searchQuery.getSort());
|
||||||
fromTemplate(sp, searchQuery.getTemplates());
|
fromTemplate(sp, searchQuery.getTemplates());
|
||||||
validateInclude(searchQuery.getInclude());
|
validateInclude(searchQuery.getInclude());
|
||||||
|
fromDefault(sp, searchQuery.getDefaults());
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
@@ -102,9 +105,9 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* SearchParameters from the Query object
|
||||||
* @param sp
|
* @param sp SearchParameters
|
||||||
* @param q
|
* @param q Query
|
||||||
*/
|
*/
|
||||||
public void fromQuery(SearchParameters sp, Query q)
|
public void fromQuery(SearchParameters sp, Query q)
|
||||||
{
|
{
|
||||||
@@ -130,6 +133,11 @@ public class SearchMapper
|
|||||||
sp.setSearchTerm(q.getUserQuery());
|
sp.setSearchTerm(q.getUserQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchParameters from the Paging object
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param paging Paging
|
||||||
|
*/
|
||||||
public void fromPaging(SearchParameters sp, Paging paging)
|
public void fromPaging(SearchParameters sp, Paging paging)
|
||||||
{
|
{
|
||||||
if (paging != null)
|
if (paging != null)
|
||||||
@@ -140,6 +148,11 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchParameters from List<SortDef>
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param sort List<SortDef>
|
||||||
|
*/
|
||||||
public void fromSort(SearchParameters sp, List<SortDef> sort)
|
public void fromSort(SearchParameters sp, List<SortDef> sort)
|
||||||
{
|
{
|
||||||
if (sort != null && !sort.isEmpty())
|
if (sort != null && !sort.isEmpty())
|
||||||
@@ -159,6 +172,11 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchParameters from List<Template>
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param templates List<Template>
|
||||||
|
*/
|
||||||
public void fromTemplate(SearchParameters sp, List<Template> templates)
|
public void fromTemplate(SearchParameters sp, List<Template> templates)
|
||||||
{
|
{
|
||||||
if (templates != null && !templates.isEmpty())
|
if (templates != null && !templates.isEmpty())
|
||||||
@@ -170,6 +188,42 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchParameters from Default object
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param defaults Default
|
||||||
|
*/
|
||||||
|
public void fromDefault(SearchParameters sp, Default defaults)
|
||||||
|
{
|
||||||
|
if (defaults != null)
|
||||||
|
{
|
||||||
|
List<String> txtAttribs = defaults.getTextAttributes();
|
||||||
|
if (txtAttribs!= null && !txtAttribs.isEmpty())
|
||||||
|
{
|
||||||
|
for (String attrib:txtAttribs)
|
||||||
|
{
|
||||||
|
sp.addTextAttribute(attrib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaults.getDefaultFTSOperator() != null)
|
||||||
|
{
|
||||||
|
sp.setDefaultFTSOperator(Operator.valueOf(defaults.getDefaultFTSOperator().toUpperCase()));
|
||||||
|
}
|
||||||
|
if (defaults.getDefaultFTSFieldOperator() != null)
|
||||||
|
{
|
||||||
|
sp.setDefaultFTSFieldConnective(Operator.valueOf(defaults.getDefaultFTSFieldOperator().toUpperCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
sp.setNamespace(defaults.getNamespace());
|
||||||
|
sp.setDefaultFieldName(defaults.getDefaultFieldName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the List<String> includes
|
||||||
|
* @param includes List<String>
|
||||||
|
*/
|
||||||
public void validateInclude(List<String> includes)
|
public void validateInclude(List<String> includes)
|
||||||
{
|
{
|
||||||
if (includes != null && !includes.isEmpty())
|
if (includes != null && !includes.isEmpty())
|
||||||
|
82
source/java/org/alfresco/rest/api/search/model/Default.java
Normal file
82
source/java/org/alfresco/rest/api/search/model/Default.java
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*-
|
||||||
|
* #%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;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POJO class representing the search Defaults
|
||||||
|
*/
|
||||||
|
public class Default
|
||||||
|
{
|
||||||
|
private final List<String> textAttributes;
|
||||||
|
private final String defaultFTSOperator;
|
||||||
|
private final String defaultFTSFieldOperator;
|
||||||
|
private final String namespace;
|
||||||
|
private final String defaultFieldName;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public Default(@JsonProperty("textAttributes") List<String> textAttributes,
|
||||||
|
@JsonProperty("defaultFTSOperator") String defaultFTSOperator,
|
||||||
|
@JsonProperty("defaultFTSFieldOperator") String defaultFTSFieldOperator,
|
||||||
|
@JsonProperty("namespace") String namespace,
|
||||||
|
@JsonProperty("defaultFieldName") String defaultFieldName)
|
||||||
|
{
|
||||||
|
this.textAttributes = textAttributes;
|
||||||
|
this.defaultFTSOperator = defaultFTSOperator;
|
||||||
|
this.defaultFTSFieldOperator = defaultFTSFieldOperator;
|
||||||
|
this.namespace = namespace;
|
||||||
|
this.defaultFieldName = defaultFieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTextAttributes()
|
||||||
|
{
|
||||||
|
return textAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultFTSOperator()
|
||||||
|
{
|
||||||
|
return defaultFTSOperator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultFTSFieldOperator()
|
||||||
|
{
|
||||||
|
return defaultFTSFieldOperator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNamespace()
|
||||||
|
{
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultFieldName()
|
||||||
|
{
|
||||||
|
return defaultFieldName;
|
||||||
|
}
|
||||||
|
}
|
@@ -44,21 +44,24 @@ public class SearchQuery
|
|||||||
private final List<String> include;
|
private final List<String> include;
|
||||||
private final List<SortDef> sort;
|
private final List<SortDef> sort;
|
||||||
private final List<Template> templates;
|
private final List<Template> templates;
|
||||||
|
private final Default defaults;
|
||||||
|
|
||||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null);
|
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null);
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public SearchQuery(@JsonProperty("query") Query query,
|
public SearchQuery(@JsonProperty("query") Query query,
|
||||||
@JsonProperty("paging") Paging paging,
|
@JsonProperty("paging") Paging paging,
|
||||||
@JsonProperty("include") List<String> include,
|
@JsonProperty("include") List<String> include,
|
||||||
@JsonProperty("sort") List<SortDef> sort,
|
@JsonProperty("sort") List<SortDef> sort,
|
||||||
@JsonProperty("templates") List<Template> templates)
|
@JsonProperty("templates") List<Template> templates,
|
||||||
|
@JsonProperty("defaults") Default defaults)
|
||||||
{
|
{
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.paging = paging;
|
this.paging = paging;
|
||||||
this.include = include;
|
this.include = include;
|
||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
this.templates = templates;
|
this.templates = templates;
|
||||||
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery()
|
public Query getQuery()
|
||||||
@@ -83,4 +86,9 @@ public class SearchQuery
|
|||||||
{
|
{
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Default getDefaults()
|
||||||
|
{
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESC
|
|||||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import org.alfresco.rest.api.search.impl.SearchMapper;
|
import org.alfresco.rest.api.search.impl.SearchMapper;
|
||||||
|
import org.alfresco.rest.api.search.model.Default;
|
||||||
import org.alfresco.rest.api.search.model.Query;
|
import org.alfresco.rest.api.search.model.Query;
|
||||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||||
import org.alfresco.rest.api.search.model.SortDef;
|
import org.alfresco.rest.api.search.model.SortDef;
|
||||||
@@ -198,6 +199,42 @@ public class SearchMapperTests
|
|||||||
assertEquals("bash" ,searchParameters.getQueryTemplates().get("bish"));
|
assertEquals("bash" ,searchParameters.getQueryTemplates().get("bish"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromDefaults() throws Exception
|
||||||
|
{
|
||||||
|
SearchParameters searchParameters = new SearchParameters();
|
||||||
|
//Doesn't error
|
||||||
|
searchMapper.fromDefault(searchParameters, null);
|
||||||
|
searchMapper.fromDefault(searchParameters, new Default(null,null,null,null,null));
|
||||||
|
|
||||||
|
searchMapper.fromDefault(searchParameters, new Default(null,"AND",null,null,null));
|
||||||
|
assertEquals("AND", searchParameters.getDefaultFTSOperator().toString());
|
||||||
|
|
||||||
|
searchMapper.fromDefault(searchParameters, new Default(null, null, "or", null,null));
|
||||||
|
assertEquals("OR", searchParameters.getDefaultFTSFieldOperator().toString());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
searchMapper.fromDefault(searchParameters, new Default(null, null, "ELSE", null,null));
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException iae)
|
||||||
|
{
|
||||||
|
//ELSE is illegal
|
||||||
|
assertNotNull(iae);
|
||||||
|
}
|
||||||
|
|
||||||
|
searchMapper.fromDefault(searchParameters, new Default(null, null, null, "nspa","dfn"));
|
||||||
|
assertEquals("nspa", searchParameters.getNamespace());
|
||||||
|
assertEquals("dfn", searchParameters.getDefaultFieldName());
|
||||||
|
|
||||||
|
assertEquals(0 , searchParameters.getTextAttributes().size());
|
||||||
|
searchMapper.fromDefault(searchParameters, new Default(Arrays.asList("sausage", "mash"), null, null, null,null));
|
||||||
|
assertEquals(2 , searchParameters.getTextAttributes().size());
|
||||||
|
assertTrue(searchParameters.getTextAttributes().contains("sausage"));
|
||||||
|
assertTrue(searchParameters.getTextAttributes().contains("mash"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateInclude() throws Exception
|
public void validateInclude() throws Exception
|
||||||
{
|
{
|
||||||
@@ -232,7 +269,7 @@ public class SearchMapperTests
|
|||||||
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);
|
SearchQuery sq = new SearchQuery(query,null, null, null, null, null);
|
||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import org.alfresco.rest.api.model.Comment;
|
import org.alfresco.rest.api.model.Comment;
|
||||||
|
import org.alfresco.rest.api.search.model.Default;
|
||||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||||
import org.alfresco.rest.framework.jacksonextensions.RestJsonModule;
|
import org.alfresco.rest.framework.jacksonextensions.RestJsonModule;
|
||||||
@@ -74,6 +75,13 @@ public class SearchQuerySerializerTests
|
|||||||
assertTrue(searchQuery.getInclude().contains("properties"));
|
assertTrue(searchQuery.getInclude().contains("properties"));
|
||||||
assertEquals(1, searchQuery.getSort().size());
|
assertEquals(1, searchQuery.getSort().size());
|
||||||
assertEquals(2, searchQuery.getTemplates().size());
|
assertEquals(2, searchQuery.getTemplates().size());
|
||||||
|
Default defaults = searchQuery.getDefaults();
|
||||||
|
assertEquals("namesp", defaults.getNamespace());
|
||||||
|
assertEquals("myfield", defaults.getDefaultFieldName());
|
||||||
|
assertEquals("AND", defaults.getDefaultFTSOperator());
|
||||||
|
assertEquals(2, defaults.getTextAttributes().size());
|
||||||
|
assertTrue(defaults.getTextAttributes().contains("roy"));
|
||||||
|
assertTrue(defaults.getTextAttributes().contains("king"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,7 @@ public class SerializerTestHelper implements RequestReader
|
|||||||
+ "\"paging\": {\"maxItems\": \"99\",\"skipCount\": \"4\"},"
|
+ "\"paging\": {\"maxItems\": \"99\",\"skipCount\": \"4\"},"
|
||||||
+ "\"sort\": {\"type\": \"FIELD\",\"field\": \"cm:title\",\"ascending\": \"true\"},"
|
+ "\"sort\": {\"type\": \"FIELD\",\"field\": \"cm:title\",\"ascending\": \"true\"},"
|
||||||
+ "\"templates\": [{\"name\": \"mytemp\",\"template\": \"ATEMP\"}, {\"name\": \"yourtemp\",\"template\": \"%cm:content\"}],"
|
+ "\"templates\": [{\"name\": \"mytemp\",\"template\": \"ATEMP\"}, {\"name\": \"yourtemp\",\"template\": \"%cm:content\"}],"
|
||||||
|
+ "\"defaults\": {\"namespace\": \"namesp\",\"defaultFieldName\": \"myfield\",\"defaultFTSOperator\": \"AND\", \"textAttributes\": [\"roy\", \"king\"]},"
|
||||||
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
||||||
|
|
||||||
public SerializerTestHelper()
|
public SerializerTestHelper()
|
||||||
|
Reference in New Issue
Block a user