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)
130287 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1) 130026 gjames: SEARCH-119: Implementing filter queries (without tags) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130359 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
package org.alfresco.rest.api.search.impl;
|
||||
|
||||
import org.alfresco.rest.api.search.model.Default;
|
||||
import org.alfresco.rest.api.search.model.FilterQuery;
|
||||
import org.alfresco.rest.api.search.model.Query;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.api.search.model.SortDef;
|
||||
@@ -90,6 +91,7 @@ public class SearchMapper
|
||||
fromTemplate(sp, searchQuery.getTemplates());
|
||||
validateInclude(searchQuery.getInclude());
|
||||
fromDefault(sp, searchQuery.getDefaults());
|
||||
fromFilterQuery(sp, searchQuery.getFilterQueries());
|
||||
|
||||
return sp;
|
||||
}
|
||||
@@ -238,4 +240,21 @@ public class SearchMapper
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** SearchParameters from List<FilterQuery>
|
||||
* @param sp
|
||||
* @param filterQueries
|
||||
*/
|
||||
public void fromFilterQuery(SearchParameters sp, List<FilterQuery> filterQueries)
|
||||
{
|
||||
if (filterQueries != null && !filterQueries.isEmpty())
|
||||
{
|
||||
for (FilterQuery fq:filterQueries)
|
||||
{
|
||||
sp.addFilterQuery(fq.getQuery());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,60 @@
|
||||
/*-
|
||||
* #%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 a FilterQuery
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class FilterQuery
|
||||
{
|
||||
private final String query;
|
||||
private final List<String> tags;
|
||||
|
||||
@JsonCreator
|
||||
public FilterQuery(@JsonProperty("query") String query, @JsonProperty("tags") List<String> tags)
|
||||
{
|
||||
this.query = query;
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public String getQuery()
|
||||
{
|
||||
return query;
|
||||
}
|
||||
|
||||
public List<String> getTags()
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
}
|
@@ -45,16 +45,18 @@ public class SearchQuery
|
||||
private final List<SortDef> sort;
|
||||
private final List<Template> templates;
|
||||
private final Default defaults;
|
||||
private final List<FilterQuery> filterQueries;
|
||||
|
||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null);
|
||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null);
|
||||
|
||||
@JsonCreator
|
||||
public SearchQuery(@JsonProperty("query") Query query,
|
||||
@JsonProperty("paging") Paging paging,
|
||||
@JsonProperty("include") List<String> include,
|
||||
@JsonProperty("sort") List<SortDef> sort,
|
||||
@JsonProperty("templates") List<Template> templates,
|
||||
@JsonProperty("defaults") Default defaults)
|
||||
@JsonProperty("paging") Paging paging,
|
||||
@JsonProperty("include") List<String> include,
|
||||
@JsonProperty("sort") List<SortDef> sort,
|
||||
@JsonProperty("templates") List<Template> templates,
|
||||
@JsonProperty("defaults") Default defaults,
|
||||
@JsonProperty("filterQueries") List<FilterQuery> filterQueries)
|
||||
{
|
||||
this.query = query;
|
||||
this.paging = paging;
|
||||
@@ -62,6 +64,7 @@ public class SearchQuery
|
||||
this.sort = sort;
|
||||
this.templates = templates;
|
||||
this.defaults = defaults;
|
||||
this.filterQueries = filterQueries;
|
||||
}
|
||||
|
||||
public Query getQuery()
|
||||
@@ -91,4 +94,9 @@ public class SearchQuery
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public List<FilterQuery> getFilterQueries()
|
||||
{
|
||||
return filterQueries;
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import org.alfresco.rest.api.search.impl.SearchMapper;
|
||||
import org.alfresco.rest.api.search.model.Default;
|
||||
import org.alfresco.rest.api.search.model.FilterQuery;
|
||||
import org.alfresco.rest.api.search.model.Query;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.api.search.model.SortDef;
|
||||
@@ -270,10 +271,25 @@ public class SearchMapperTests
|
||||
searchMapper.validateInclude(Arrays.asList("properties", "aspectNames"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromFilterQuery() throws Exception
|
||||
{
|
||||
SearchParameters searchParameters = new SearchParameters();
|
||||
//Doesn't error
|
||||
searchMapper.fromFilterQuery(searchParameters, null);
|
||||
|
||||
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("hedgehog", null), new FilterQuery("king", Arrays.asList("not", "used"))));
|
||||
assertEquals(2 ,searchParameters.getFilterQueries().size());
|
||||
assertEquals("hedgehog" ,searchParameters.getFilterQueries().get(0));
|
||||
assertEquals("king" ,searchParameters.getFilterQueries().get(1));
|
||||
|
||||
//tags aren't used at the moment
|
||||
}
|
||||
|
||||
private SearchQuery minimalQuery()
|
||||
{
|
||||
Query query = new Query("cmis", "foo", "");
|
||||
SearchQuery sq = new SearchQuery(query,null, null, null, null, null);
|
||||
SearchQuery sq = new SearchQuery(query,null, null, null, null, null, null);
|
||||
return sq;
|
||||
}
|
||||
}
|
||||
|
@@ -82,6 +82,10 @@ public class SearchQuerySerializerTests
|
||||
assertEquals(2, defaults.getTextAttributes().size());
|
||||
assertTrue(defaults.getTextAttributes().contains("roy"));
|
||||
assertTrue(defaults.getTextAttributes().contains("king"));
|
||||
assertEquals(2, searchQuery.getFilterQueries().size());
|
||||
assertEquals("myquery",searchQuery.getFilterQueries().get(0).getQuery());
|
||||
assertEquals(2, searchQuery.getFilterQueries().get(0).getTags().size());
|
||||
assertEquals("myquery2",searchQuery.getFilterQueries().get(1).getQuery());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -53,6 +53,7 @@ public class SerializerTestHelper implements RequestReader
|
||||
+ "\"sort\": {\"type\": \"FIELD\",\"field\": \"cm:title\",\"ascending\": \"true\"},"
|
||||
+ "\"templates\": [{\"name\": \"mytemp\",\"template\": \"ATEMP\"}, {\"name\": \"yourtemp\",\"template\": \"%cm:content\"}],"
|
||||
+ "\"defaults\": {\"namespace\": \"namesp\",\"defaultFieldName\": \"myfield\",\"defaultFTSOperator\": \"AND\", \"textAttributes\": [\"roy\", \"king\"]},"
|
||||
+ "\"filterQueries\": [{\"query\": \"myquery\",\"tags\": [\"tag1\", \"tag2\"]},{\"query\": \"myquery2\"}],"
|
||||
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
||||
|
||||
public SerializerTestHelper()
|
||||
|
Reference in New Issue
Block a user