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)
129819 gjames: SEARCH-113: The Json representation is immutable. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130179 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,18 +26,27 @@
|
|||||||
|
|
||||||
package org.alfresco.rest.api.search.model;
|
package org.alfresco.rest.api.search.model;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonCreator;
|
||||||
|
import org.codehaus.jackson.annotate.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POJO class representing the query element of the JSON body
|
* POJO class representing the query element of the JSON body
|
||||||
**/
|
**/
|
||||||
public class Query
|
public class Query
|
||||||
{
|
{
|
||||||
|
|
||||||
String language;
|
private final String language;
|
||||||
String query;
|
private final String query;
|
||||||
String userQuery;
|
private final String userQuery;
|
||||||
|
|
||||||
public Query()
|
@JsonCreator
|
||||||
|
public Query(@JsonProperty("language") String language,
|
||||||
|
@JsonProperty("query") String query,
|
||||||
|
@JsonProperty("userQuery") String userQuery)
|
||||||
{
|
{
|
||||||
|
this.language = language;
|
||||||
|
this.query = query;
|
||||||
|
this.userQuery = userQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLanguage()
|
public String getLanguage()
|
||||||
@@ -45,28 +54,14 @@ public class Query
|
|||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLanguage(String language)
|
|
||||||
{
|
|
||||||
this.language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQuery()
|
public String getQuery()
|
||||||
{
|
{
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQuery(String query)
|
|
||||||
{
|
|
||||||
this.query = query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserQuery()
|
public String getUserQuery()
|
||||||
{
|
{
|
||||||
return userQuery;
|
return userQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserQuery(String userQuery)
|
|
||||||
{
|
|
||||||
this.userQuery = userQuery;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
package org.alfresco.rest.api.search.model;
|
package org.alfresco.rest.api.search.model;
|
||||||
|
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
|
import org.codehaus.jackson.annotate.JsonCreator;
|
||||||
|
import org.codehaus.jackson.annotate.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POJO class representing the JSON body for a search request
|
* POJO class representing the JSON body for a search request
|
||||||
@@ -35,11 +37,17 @@ import org.alfresco.rest.framework.resource.parameters.Paging;
|
|||||||
*/
|
*/
|
||||||
public class SearchQuery
|
public class SearchQuery
|
||||||
{
|
{
|
||||||
Query query;
|
private final Query query;
|
||||||
Paging paging;
|
private final Paging paging;
|
||||||
|
|
||||||
public SearchQuery()
|
public static final SearchQuery EMPTY = new SearchQuery(null, null);
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public SearchQuery(@JsonProperty("query") Query query,
|
||||||
|
@JsonProperty("paging") Paging paging)
|
||||||
{
|
{
|
||||||
|
this.query = query;
|
||||||
|
this.paging = paging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery()
|
public Query getQuery()
|
||||||
@@ -47,18 +55,8 @@ public class SearchQuery
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQuery(Query query)
|
|
||||||
{
|
|
||||||
this.query = query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Paging getPaging()
|
public Paging getPaging()
|
||||||
{
|
{
|
||||||
return paging;
|
return paging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPaging(Paging paging)
|
|
||||||
{
|
|
||||||
this.paging = paging;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ public class ResultMapperTests
|
|||||||
@Test
|
@Test
|
||||||
public void testNoResults() throws Exception
|
public void testNoResults() throws Exception
|
||||||
{
|
{
|
||||||
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(mockParams(new SearchQuery()),new EmptyResultSet());
|
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(mockParams(SearchQuery.EMPTY),new EmptyResultSet());
|
||||||
assertNotNull(collection);
|
assertNotNull(collection);
|
||||||
assertFalse(collection.hasMoreItems());
|
assertFalse(collection.hasMoreItems());
|
||||||
assertTrue(collection.getTotalItems() < 1);
|
assertTrue(collection.getTotalItems() < 1);
|
||||||
@@ -121,7 +121,7 @@ public class ResultMapperTests
|
|||||||
public void testToCollectionWithPagingInfo() throws Exception
|
public void testToCollectionWithPagingInfo() throws Exception
|
||||||
{
|
{
|
||||||
ResultSet results = mockResultset();
|
ResultSet results = mockResultset();
|
||||||
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(new SearchQuery()),results);
|
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(SearchQuery.EMPTY),results);
|
||||||
assertNotNull(collectionWithPage);
|
assertNotNull(collectionWithPage);
|
||||||
Long found = results.getNumberFound();
|
Long found = results.getNumberFound();
|
||||||
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
|
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
|
||||||
|
@@ -55,7 +55,7 @@ public class SearchMapperTests
|
|||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testMandatory() throws Exception
|
public void testMandatory() throws Exception
|
||||||
{
|
{
|
||||||
SearchParameters searchParameters = searchMapper.toSearchParameters(new SearchQuery());
|
SearchParameters searchParameters = searchMapper.toSearchParameters(SearchQuery.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -75,15 +75,14 @@ public class SearchMapperTests
|
|||||||
SearchParameters searchParameters = new SearchParameters();
|
SearchParameters searchParameters = new SearchParameters();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
searchMapper.fromQuery(searchParameters, new Query());
|
searchMapper.fromQuery(searchParameters, new Query(null,null, null));
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException iae)
|
} catch (IllegalArgumentException iae)
|
||||||
{
|
{
|
||||||
assertTrue(iae.getLocalizedMessage().contains("query is a mandatory parameter"));
|
assertTrue(iae.getLocalizedMessage().contains("query is a mandatory parameter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Query q = new Query();
|
Query q = new Query(null,"hello", null);
|
||||||
q.setQuery("hello");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -94,7 +93,7 @@ public class SearchMapperTests
|
|||||||
assertTrue(iae.getLocalizedMessage().contains("language is a mandatory parameter"));
|
assertTrue(iae.getLocalizedMessage().contains("language is a mandatory parameter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
q.setLanguage("world");
|
q = new Query("world", "hello", null);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -106,21 +105,21 @@ public class SearchMapperTests
|
|||||||
//world is not a valid language type
|
//world is not a valid language type
|
||||||
}
|
}
|
||||||
|
|
||||||
q.setLanguage("afts");
|
q = new Query("afts", "hello", null);
|
||||||
searchMapper.fromQuery(searchParameters, q);
|
searchMapper.fromQuery(searchParameters, q);
|
||||||
assertEquals(LANGUAGE_FTS_ALFRESCO, searchParameters.getLanguage());
|
assertEquals(LANGUAGE_FTS_ALFRESCO, searchParameters.getLanguage());
|
||||||
|
|
||||||
q.setLanguage("cMiS");
|
q = new Query("cMiS", "hello", null);
|
||||||
searchMapper.fromQuery(searchParameters, q);
|
searchMapper.fromQuery(searchParameters, q);
|
||||||
assertEquals(LANGUAGE_CMIS_ALFRESCO, searchParameters.getLanguage());
|
assertEquals(LANGUAGE_CMIS_ALFRESCO, searchParameters.getLanguage());
|
||||||
|
|
||||||
q.setLanguage("LuCENE");
|
q = new Query("LuCENE", "hello", null);
|
||||||
searchMapper.fromQuery(searchParameters, q);
|
searchMapper.fromQuery(searchParameters, q);
|
||||||
assertEquals(LANGUAGE_LUCENE, searchParameters.getLanguage());
|
assertEquals(LANGUAGE_LUCENE, searchParameters.getLanguage());
|
||||||
|
|
||||||
assertEquals("hello", searchParameters.getQuery());
|
assertEquals("hello", searchParameters.getQuery());
|
||||||
|
|
||||||
q.setUserQuery("Heload");
|
q = new Query("LuCENE", "hello", "Heload");
|
||||||
searchMapper.fromQuery(searchParameters, q);
|
searchMapper.fromQuery(searchParameters, q);
|
||||||
assertEquals("Heload", searchParameters.getSearchTerm());
|
assertEquals("Heload", searchParameters.getSearchTerm());
|
||||||
}
|
}
|
||||||
@@ -139,11 +138,8 @@ public class SearchMapperTests
|
|||||||
|
|
||||||
private SearchQuery minimalQuery()
|
private SearchQuery minimalQuery()
|
||||||
{
|
{
|
||||||
SearchQuery sq = new SearchQuery();
|
Query query = new Query("cmis", "foo", "");
|
||||||
Query query = new Query();
|
SearchQuery sq = new SearchQuery(query,null);
|
||||||
sq.setQuery(query);
|
|
||||||
query.setQuery("foo");
|
|
||||||
query.setLanguage("cmis");
|
|
||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user