Search in sources :

Example 6 with SearchSQLQuery

use of org.alfresco.rest.api.search.model.SearchSQLQuery in project alfresco-remote-api by Alfresco.

the class SearchSQLParseTest method testSQLDeserializeSelectQuery.

@Test
public void testSQLDeserializeSelectQuery() throws IOException {
    String query = "{\"stmt\": \"select SITE from alfresco\"}";
    SearchSQLQuery searchQuery = parse(query);
    assertEquals("select SITE from alfresco", searchQuery.getStmt());
}
Also used : SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) Test(org.junit.Test)

Example 7 with SearchSQLQuery

use of org.alfresco.rest.api.search.model.SearchSQLQuery in project alfresco-remote-api by Alfresco.

the class ResultMapperTests method testSqlResponse.

@Test
public void testSqlResponse() throws IOException, JSONException {
    JSONObject response = new JSONObject("{\"docs\":[{\"SITE\":\"_REPOSITORY_\"},{\"SITE\":\"surf-config\"},{\"SITE\":\"swsdp\"},{\"EOF\":true,\"RESPONSE_TIME\":96}]}");
    JSONArray docs = response.getJSONArray("docs");
    SearchSQLQuery query = new SearchSQLQuery("select SITE from alfresco group by SITE", null, null, 100, false, null, null);
    CollectionWithPagingInfo<TupleList> info = mapper.toCollectionWithPagingInfo(docs, query);
    assertEquals(100, info.getPaging().getMaxItems());
    assertEquals(0, info.getPaging().getSkipCount());
    assertEquals(false, info.getCollection().isEmpty());
    assertEquals(3, info.getCollection().size());
    info = mapper.toCollectionWithPagingInfo(new JSONArray(), query);
    assertEquals(100, info.getPaging().getMaxItems());
    assertEquals(0, info.getPaging().getSkipCount());
    assertEquals(true, info.getCollection().isEmpty());
    assertEquals(0, info.getCollection().size());
    try {
        mapper.toCollectionWithPagingInfo(null, query);
    } catch (Exception e) {
        assertNotNull(e);
        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());
    }
}
Also used : TupleList(org.alfresco.rest.api.search.model.TupleList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) JSONException(org.json.JSONException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SearchSQLQuery (org.alfresco.rest.api.search.model.SearchSQLQuery)7 Test (org.junit.Test)6 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)4 IOException (java.io.IOException)2 TupleList (org.alfresco.rest.api.search.model.TupleList)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 LuceneQueryParserException (org.alfresco.repo.search.impl.lucene.LuceneQueryParserException)1 SolrSQLJSONResultSet (org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet)1 FilteringResultSet (org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1