mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged searchapi (5.2.1) to 5.2.N (5.2.1)
130145 gjames: SEARCH-123: Implementing scope for queries git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130304 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,10 +26,12 @@
|
|||||||
|
|
||||||
package org.alfresco.rest.api.search.impl;
|
package org.alfresco.rest.api.search.impl;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.rest.api.search.model.Default;
|
import org.alfresco.rest.api.search.model.Default;
|
||||||
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.Query;
|
import org.alfresco.rest.api.search.model.Query;
|
||||||
|
import org.alfresco.rest.api.search.model.Scope;
|
||||||
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;
|
||||||
import org.alfresco.rest.api.search.model.Spelling;
|
import org.alfresco.rest.api.search.model.Spelling;
|
||||||
@@ -103,6 +105,7 @@ public class SearchMapper
|
|||||||
fromFilterQuery(sp, searchQuery.getFilterQueries());
|
fromFilterQuery(sp, searchQuery.getFilterQueries());
|
||||||
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
||||||
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
||||||
|
fromScope(sp, searchQuery.getScope());
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
@@ -111,7 +114,7 @@ public class SearchMapper
|
|||||||
* Sets the API defaults
|
* Sets the API defaults
|
||||||
* @param sp
|
* @param sp
|
||||||
*/
|
*/
|
||||||
protected void setDefaults(SearchParameters sp)
|
public void setDefaults(SearchParameters sp)
|
||||||
{
|
{
|
||||||
//Hardcode workspace store
|
//Hardcode workspace store
|
||||||
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
||||||
@@ -331,4 +334,34 @@ public class SearchMapper
|
|||||||
sp.setSpellCheck(true);
|
sp.setSpellCheck(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchParameters from Scope object
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param Scope scope
|
||||||
|
*/
|
||||||
|
public void fromScope(SearchParameters sp, Scope scope)
|
||||||
|
{
|
||||||
|
if (scope != null)
|
||||||
|
{
|
||||||
|
List<String> stores = scope.getStores();
|
||||||
|
if (stores!= null && !stores.isEmpty())
|
||||||
|
{
|
||||||
|
//First reset the stores then add them.
|
||||||
|
sp.getStores().clear();
|
||||||
|
for (String aStore:stores)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sp.addStore(new StoreRef(aStore));
|
||||||
|
}
|
||||||
|
catch (AlfrescoRuntimeException are)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
|
||||||
|
new Object[] { aStore });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
52
source/java/org/alfresco/rest/api/search/model/Scope.java
Normal file
52
source/java/org/alfresco/rest/api/search/model/Scope.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*-
|
||||||
|
* #%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 Scope
|
||||||
|
{
|
||||||
|
private final List<String> stores;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public Scope(@JsonProperty("stores") List<String> stores)
|
||||||
|
{
|
||||||
|
this.stores = stores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getStores()
|
||||||
|
{
|
||||||
|
return stores;
|
||||||
|
}
|
||||||
|
}
|
@@ -49,8 +49,9 @@ public class SearchQuery
|
|||||||
private final List<FilterQuery> filterQueries;
|
private final List<FilterQuery> filterQueries;
|
||||||
private final List<FacetQuery> facetQueries;
|
private final List<FacetQuery> facetQueries;
|
||||||
private final Spelling spellcheck;
|
private final Spelling spellcheck;
|
||||||
|
private final Scope scope;
|
||||||
|
|
||||||
public static final SearchQuery EMPTY = new SearchQuery(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);
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public SearchQuery(@JsonProperty("query") Query query,
|
public SearchQuery(@JsonProperty("query") Query query,
|
||||||
@@ -61,7 +62,8 @@ public class SearchQuery
|
|||||||
@JsonProperty("defaults") Default defaults,
|
@JsonProperty("defaults") Default defaults,
|
||||||
@JsonProperty("filterQueries") List<FilterQuery> filterQueries,
|
@JsonProperty("filterQueries") List<FilterQuery> filterQueries,
|
||||||
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
|
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
|
||||||
@JsonProperty("spellcheck") Spelling spellcheck)
|
@JsonProperty("spellcheck") Spelling spellcheck,
|
||||||
|
@JsonProperty("scope") Scope scope)
|
||||||
{
|
{
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.paging = paging;
|
this.paging = paging;
|
||||||
@@ -72,6 +74,7 @@ public class SearchQuery
|
|||||||
this.filterQueries = filterQueries;
|
this.filterQueries = filterQueries;
|
||||||
this.facetQueries = facetQueries;
|
this.facetQueries = facetQueries;
|
||||||
this.spellcheck = spellcheck;
|
this.spellcheck = spellcheck;
|
||||||
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery()
|
public Query getQuery()
|
||||||
@@ -116,4 +119,9 @@ public class SearchQuery
|
|||||||
{
|
{
|
||||||
return spellcheck;
|
return spellcheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Scope getScope()
|
||||||
|
{
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,8 @@ import static junit.framework.TestCase.assertEquals;
|
|||||||
import static junit.framework.TestCase.assertNotNull;
|
import static junit.framework.TestCase.assertNotNull;
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
import static junit.framework.TestCase.fail;
|
import static junit.framework.TestCase.fail;
|
||||||
|
import static org.alfresco.service.cmr.repository.StoreRef.PROTOCOL_DELETED;
|
||||||
|
import static org.alfresco.service.cmr.repository.StoreRef.PROTOCOL_TEST;
|
||||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_CMIS_ALFRESCO;
|
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_CMIS_ALFRESCO;
|
||||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESCO;
|
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESCO;
|
||||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
||||||
@@ -39,6 +41,7 @@ import org.alfresco.rest.api.search.model.Default;
|
|||||||
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.Query;
|
import org.alfresco.rest.api.search.model.Query;
|
||||||
|
import org.alfresco.rest.api.search.model.Scope;
|
||||||
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;
|
||||||
import org.alfresco.rest.api.search.model.Spelling;
|
import org.alfresco.rest.api.search.model.Spelling;
|
||||||
@@ -361,10 +364,43 @@ public class SearchMapperTests
|
|||||||
assertTrue(searchParameters.isSpellCheck());
|
assertTrue(searchParameters.isSpellCheck());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromScope() throws Exception
|
||||||
|
{
|
||||||
|
SearchParameters searchParameters = new SearchParameters();
|
||||||
|
searchMapper.setDefaults(searchParameters);
|
||||||
|
|
||||||
|
//Doesn't error, has default store
|
||||||
|
searchMapper.fromScope(searchParameters, null);
|
||||||
|
assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,searchParameters.getStores().get(0));
|
||||||
|
|
||||||
|
searchMapper.fromScope(searchParameters, new Scope(null));
|
||||||
|
assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,searchParameters.getStores().get(0));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList("nonsense")));
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch (InvalidArgumentException iae)
|
||||||
|
{
|
||||||
|
//Must be a valid store ref
|
||||||
|
assertNotNull(iae);
|
||||||
|
}
|
||||||
|
|
||||||
|
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(
|
||||||
|
new StoreRef(PROTOCOL_TEST, "SpacesStore").toString(),
|
||||||
|
new StoreRef(PROTOCOL_DELETED, "SpacesStore").toString())));
|
||||||
|
assertEquals(2 ,searchParameters.getStores().size());
|
||||||
|
assertEquals("test://SpacesStore",searchParameters.getStores().get(0).toString());
|
||||||
|
assertEquals("deleted://SpacesStore",searchParameters.getStores().get(1).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
SearchQuery sq = new SearchQuery(query,null, null, null, null, null, null, null, null, null);
|
||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -88,6 +88,9 @@ public class SearchQuerySerializerTests
|
|||||||
assertEquals("facquery",searchQuery.getFacetQueries().get(0).getQuery());
|
assertEquals("facquery",searchQuery.getFacetQueries().get(0).getQuery());
|
||||||
assertEquals("facnoused",searchQuery.getFacetQueries().get(0).getLabel());
|
assertEquals("facnoused",searchQuery.getFacetQueries().get(0).getLabel());
|
||||||
assertEquals("alfrezco", searchQuery.getSpellcheck().getQuery());
|
assertEquals("alfrezco", searchQuery.getSpellcheck().getQuery());
|
||||||
|
assertEquals(1, searchQuery.getScope().getStores().size());
|
||||||
|
assertEquals("test://SpacesStore", searchQuery.getScope().getStores().get(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -62,6 +62,7 @@ public class SerializerTestHelper implements RequestReader
|
|||||||
+ "\"filterQueries\": [{\"query\": \"myquery\",\"tags\": [\"tag1\", \"tag2\"]},{\"query\": \"myquery2\"}],"
|
+ "\"filterQueries\": [{\"query\": \"myquery\",\"tags\": [\"tag1\", \"tag2\"]},{\"query\": \"myquery2\"}],"
|
||||||
+ "\"facetQueries\": [{\"query\": \"facquery\",\"label\": \"facnoused\"}],"
|
+ "\"facetQueries\": [{\"query\": \"facquery\",\"label\": \"facnoused\"}],"
|
||||||
+ "\"spellcheck\": {\"query\": \"alfrezco\"},"
|
+ "\"spellcheck\": {\"query\": \"alfrezco\"},"
|
||||||
|
+ "\"scope\": { \"stores\": [\"test://SpacesStore\"]},"
|
||||||
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
||||||
|
|
||||||
public SerializerTestHelper()
|
public SerializerTestHelper()
|
||||||
|
Reference in New Issue
Block a user