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)
130185 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1) 129838 gjames: SEARCH-117: Implementing templates git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130336 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,6 +29,7 @@ package org.alfresco.rest.api.search.impl;
|
|||||||
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;
|
||||||
|
import org.alfresco.rest.api.search.model.Template;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
@@ -84,6 +85,7 @@ public class SearchMapper
|
|||||||
fromQuery(sp, searchQuery.getQuery());
|
fromQuery(sp, searchQuery.getQuery());
|
||||||
fromPaging(sp, searchQuery.getPaging());
|
fromPaging(sp, searchQuery.getPaging());
|
||||||
fromSort(sp, searchQuery.getSort());
|
fromSort(sp, searchQuery.getSort());
|
||||||
|
fromTemplate(sp, searchQuery.getTemplates());
|
||||||
validateInclude(searchQuery.getInclude());
|
validateInclude(searchQuery.getInclude());
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
@@ -157,6 +159,17 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fromTemplate(SearchParameters sp, List<Template> templates)
|
||||||
|
{
|
||||||
|
if (templates != null && !templates.isEmpty())
|
||||||
|
{
|
||||||
|
for (Template aTemplate:templates)
|
||||||
|
{
|
||||||
|
sp.addQueryTemplate(aTemplate.getName(), aTemplate.getTemplate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void validateInclude(List<String> includes)
|
public void validateInclude(List<String> includes)
|
||||||
{
|
{
|
||||||
if (includes != null && !includes.isEmpty())
|
if (includes != null && !includes.isEmpty())
|
||||||
|
@@ -43,19 +43,22 @@ public class SearchQuery
|
|||||||
private final Paging paging;
|
private final Paging paging;
|
||||||
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;
|
||||||
|
|
||||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null);
|
public static final SearchQuery EMPTY = new SearchQuery(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)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery()
|
public Query getQuery()
|
||||||
@@ -76,4 +79,8 @@ public class SearchQuery
|
|||||||
{
|
{
|
||||||
return sort;
|
return sort;
|
||||||
}
|
}
|
||||||
|
public List<Template> getTemplates()
|
||||||
|
{
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
56
source/java/org/alfresco/rest/api/search/model/Template.java
Normal file
56
source/java/org/alfresco/rest/api/search/model/Template.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*-
|
||||||
|
* #%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 Template
|
||||||
|
*/
|
||||||
|
public class Template
|
||||||
|
{
|
||||||
|
private final String name;
|
||||||
|
private final String template;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public Template(@JsonProperty("name") String name,
|
||||||
|
@JsonProperty("template") String template)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.template = template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTemplate()
|
||||||
|
{
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
}
|
@@ -37,6 +37,7 @@ import org.alfresco.rest.api.search.impl.SearchMapper;
|
|||||||
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;
|
||||||
|
import org.alfresco.rest.api.search.model.Template;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
@@ -182,6 +183,21 @@ public class SearchMapperTests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromTemplate() throws Exception
|
||||||
|
{
|
||||||
|
SearchParameters searchParameters = new SearchParameters();
|
||||||
|
//Doesn't error
|
||||||
|
searchMapper.fromTemplate(searchParameters, null);
|
||||||
|
|
||||||
|
searchMapper.fromTemplate(searchParameters, Arrays.asList(new Template("hedge", "hog"), new Template("king", "kong"), new Template("bish", "bash")));
|
||||||
|
assertEquals(3 ,searchParameters.getQueryTemplates().size());
|
||||||
|
assertEquals("hog" ,searchParameters.getQueryTemplates().get("hedge"));
|
||||||
|
assertEquals("kong" ,searchParameters.getQueryTemplates().get("king"));
|
||||||
|
assertEquals("bash" ,searchParameters.getQueryTemplates().get("bish"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateInclude() throws Exception
|
public void validateInclude() throws Exception
|
||||||
{
|
{
|
||||||
@@ -216,7 +232,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);
|
SearchQuery sq = new SearchQuery(query,null, null, null, null);
|
||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,8 @@ public class SearchQuerySerializerTests
|
|||||||
assertEquals(2, searchQuery.getInclude().size());
|
assertEquals(2, searchQuery.getInclude().size());
|
||||||
assertTrue(searchQuery.getInclude().contains("aspectNames"));
|
assertTrue(searchQuery.getInclude().contains("aspectNames"));
|
||||||
assertTrue(searchQuery.getInclude().contains("properties"));
|
assertTrue(searchQuery.getInclude().contains("properties"));
|
||||||
|
assertEquals(1, searchQuery.getSort().size());
|
||||||
|
assertEquals(2, searchQuery.getTemplates().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,8 @@ public class SerializerTestHelper implements RequestReader
|
|||||||
|
|
||||||
public static final String JSON = "{ \"query\": {\"query\": \"g*\",\"userQuery\": \"great\",\"language\": \"afts\"}, "
|
public static final String JSON = "{ \"query\": {\"query\": \"g*\",\"userQuery\": \"great\",\"language\": \"afts\"}, "
|
||||||
+ "\"paging\": {\"maxItems\": \"99\",\"skipCount\": \"4\"},"
|
+ "\"paging\": {\"maxItems\": \"99\",\"skipCount\": \"4\"},"
|
||||||
+ "\"sort\": {\"type\": \"FIELD\",\"field\": \"king\",\"ascending\": \"true\"},"
|
+ "\"sort\": {\"type\": \"FIELD\",\"field\": \"cm:title\",\"ascending\": \"true\"},"
|
||||||
|
+ "\"templates\": [{\"name\": \"mytemp\",\"template\": \"ATEMP\"}, {\"name\": \"yourtemp\",\"template\": \"%cm:content\"}],"
|
||||||
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
||||||
|
|
||||||
public SerializerTestHelper()
|
public SerializerTestHelper()
|
||||||
|
Reference in New Issue
Block a user