Search-577: code review updates

This commit is contained in:
Michael
2018-03-07 22:25:33 +00:00
parent 6ccbbbe307
commit 01ba02c115
5 changed files with 36 additions and 18 deletions

View File

@@ -90,7 +90,7 @@ public class SearchSQLApiWebscript extends AbstractWebScript implements Recogniz
} }
else else
{ {
CollectionWithPagingInfo<TupleList> nodes = resultMapper.toCollectionWithPagingInfo(ssjr.getDocs()); CollectionWithPagingInfo<TupleList> nodes = resultMapper.toCollectionWithPagingInfo(ssjr.getDocs(), searchQuery);
renderJsonResponse(res, nodes, assistant.getJsonHelper()); renderJsonResponse(res, nodes, assistant.getJsonHelper());
} }
setResponse(res, DEFAULT_SUCCESS); setResponse(res, DEFAULT_SUCCESS);

View File

@@ -71,6 +71,7 @@ import org.alfresco.rest.api.search.model.FacetQuery;
import org.alfresco.rest.api.search.model.HighlightEntry; import org.alfresco.rest.api.search.model.HighlightEntry;
import org.alfresco.rest.api.search.model.SearchEntry; import org.alfresco.rest.api.search.model.SearchEntry;
import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.api.search.model.SearchSQLQuery;
import org.alfresco.rest.api.search.model.TupleEntry; import org.alfresco.rest.api.search.model.TupleEntry;
import org.alfresco.rest.api.search.model.TupleList; import org.alfresco.rest.api.search.model.TupleList;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
@@ -641,12 +642,16 @@ public class ResultMapper
return null; return null;
} }
public CollectionWithPagingInfo<TupleList> toCollectionWithPagingInfo(JSONArray docs) throws JSONException public CollectionWithPagingInfo<TupleList> toCollectionWithPagingInfo(JSONArray docs, SearchSQLQuery searchQuery) throws JSONException
{ {
if(docs == null) if(docs == null )
{ {
throw new RuntimeException("Solr response is required instead of JSONArray docs was null" ); throw new RuntimeException("Solr response is required instead of JSONArray docs was null" );
} }
if(searchQuery == null )
{
throw new RuntimeException("SearchSQLQuery is required" );
}
List<TupleList> entries = new ArrayList<TupleList>(); List<TupleList> entries = new ArrayList<TupleList>();
for(int i = 0; i < docs.length() -1; i++) for(int i = 0; i < docs.length() -1; i++)
{ {
@@ -665,7 +670,7 @@ public class ResultMapper
}); });
entries.add(new TupleList(row)); entries.add(new TupleList(row));
} }
Paging paging = Paging.valueOf(0, 1000); Paging paging = Paging.valueOf(0, searchQuery.getItemLimit());
return CollectionWithPagingInfo.asPaged(paging, entries); return CollectionWithPagingInfo.asPaged(paging, entries);
} }
} }

View File

@@ -38,17 +38,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class SearchSQLQuery public class SearchSQLQuery
{ {
private final String stmt; private final String stmt;
private Integer paging; private Integer itemLimit;
private final String format; private final String format;
private List<String> locales; private List<String> locales;
public SearchSQLQuery(@JsonProperty("stmt") String stmt, public SearchSQLQuery(@JsonProperty("stmt") String stmt,
@JsonProperty("format") String format, @JsonProperty("format") String format,
@JsonProperty("locales") List<String> locales) @JsonProperty("locales") List<String> locales,
@JsonProperty("limit") Integer itemLimit)
{ {
this.stmt = stmt; this.stmt = stmt;
this.format = format != null ? format : "default"; this.format = format != null ? format : "default";
this.locales = locales != null ? locales : Collections.EMPTY_LIST; this.locales = locales != null ? locales : Collections.emptyList();
this.itemLimit = itemLimit == null || itemLimit < 1 ? new Integer(1000) : itemLimit;
} }
public String getStmt() public String getStmt()
@@ -56,9 +58,9 @@ public class SearchSQLQuery
return stmt; return stmt;
} }
public Integer getPaging() public Integer getItemLimit()
{ {
return paging; return itemLimit;
} }
public String getFormat() public String getFormat()

View File

@@ -79,6 +79,7 @@ import org.alfresco.rest.api.search.impl.SearchMapper;
import org.alfresco.rest.api.search.impl.StoreMapper; import org.alfresco.rest.api.search.impl.StoreMapper;
import org.alfresco.rest.api.search.model.HighlightEntry; import org.alfresco.rest.api.search.model.HighlightEntry;
import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.api.search.model.SearchSQLQuery;
import org.alfresco.rest.api.search.model.TupleList; import org.alfresco.rest.api.search.model.TupleList;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
@@ -852,24 +853,34 @@ public class ResultMapperTests
{ {
JSONObject response = new JSONObject("{\"docs\":[{\"SITE\":\"_REPOSITORY_\"},{\"SITE\":\"surf-config\"},{\"SITE\":\"swsdp\"},{\"EOF\":true,\"RESPONSE_TIME\":96}]}"); JSONObject response = new JSONObject("{\"docs\":[{\"SITE\":\"_REPOSITORY_\"},{\"SITE\":\"surf-config\"},{\"SITE\":\"swsdp\"},{\"EOF\":true,\"RESPONSE_TIME\":96}]}");
JSONArray docs = response.getJSONArray("docs"); JSONArray docs = response.getJSONArray("docs");
CollectionWithPagingInfo<TupleList> info = mapper.toCollectionWithPagingInfo(docs); SearchSQLQuery query = new SearchSQLQuery("select SITE from alfresco group by SITE", null, null, 100);
assertEquals(1000, info.getPaging().getMaxItems()); CollectionWithPagingInfo<TupleList> info = mapper.toCollectionWithPagingInfo(docs, query);
assertEquals(100, info.getPaging().getMaxItems());
assertEquals(0, info.getPaging().getSkipCount()); assertEquals(0, info.getPaging().getSkipCount());
assertEquals(false, info.getCollection().isEmpty()); assertEquals(false, info.getCollection().isEmpty());
assertEquals(3, info.getCollection().size()); assertEquals(3, info.getCollection().size());
info = mapper.toCollectionWithPagingInfo(new JSONArray()); info = mapper.toCollectionWithPagingInfo(new JSONArray(), query);
assertEquals(1000, info.getPaging().getMaxItems()); assertEquals(100, info.getPaging().getMaxItems());
assertEquals(0, info.getPaging().getSkipCount()); assertEquals(0, info.getPaging().getSkipCount());
assertEquals(true, info.getCollection().isEmpty()); assertEquals(true, info.getCollection().isEmpty());
assertEquals(0, info.getCollection().size()); assertEquals(0, info.getCollection().size());
try try
{ {
mapper.toCollectionWithPagingInfo(null); mapper.toCollectionWithPagingInfo(null, query);
} }
catch (Exception e) catch (Exception e)
{ {
assertNotNull(e); assertNotNull(e);
assertEquals("Solr response is required instead of docs:null", e.getMessage()); assertEquals("Solr response is required instead of JSONArray docs was null", e.getMessage());
}
try
{
mapper.toCollectionWithPagingInfo(docs, null);
}
catch (Exception e)
{
assertNotNull(e);
assertEquals("SearchSQLQuery is required", e.getMessage());
} }
} }
} }

View File

@@ -47,7 +47,7 @@ public class SearchSQLApiWebscriptTests
public void testSearchQueryParams() throws Exception public void testSearchQueryParams() throws Exception
{ {
String query = "select SITE from alfresco"; String query = "select SITE from alfresco";
SearchSQLQuery searchQuery = new SearchSQLQuery(query, "solr", Collections.EMPTY_LIST); SearchSQLQuery searchQuery = new SearchSQLQuery(query, "solr", Collections.emptyList(), 1000);
SearchParameters sparams = webscript.buildSearchParameters(searchQuery); SearchParameters sparams = webscript.buildSearchParameters(searchQuery);
assertNotNull(sparams); assertNotNull(sparams);
@@ -57,7 +57,7 @@ public class SearchSQLApiWebscriptTests
@Test @Test
public void testSearchQueryNullStmt() throws Exception public void testSearchQueryNullStmt() throws Exception
{ {
SearchSQLQuery searchQuery = new SearchSQLQuery(null, "solr", Collections.EMPTY_LIST); SearchSQLQuery searchQuery = new SearchSQLQuery(null, "solr", Collections.emptyList(), null);
try try
{ {
webscript.buildSearchParameters(searchQuery); webscript.buildSearchParameters(searchQuery);
@@ -70,7 +70,7 @@ public class SearchSQLApiWebscriptTests
@Test @Test
public void testSearchSQLQueryAgainstNonInsight() throws Exception public void testSearchSQLQueryAgainstNonInsight() throws Exception
{ {
SearchSQLQuery searchQuery = new SearchSQLQuery(null, "solr", Collections.EMPTY_LIST); SearchSQLQuery searchQuery = new SearchSQLQuery(null, "solr", Collections.emptyList(), 1000);
try try
{ {
webscript.buildSearchParameters(searchQuery); webscript.buildSearchParameters(searchQuery);