Search in sources :

Example 1 with SearchSQLQuery

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

the class SearchSQLApiWebscriptTests method testSearchQueryParamsTimezone.

@Test
public void testSearchQueryParamsTimezone() throws Exception {
    String query = "select SITE from alfresco";
    SearchSQLQuery searchQuery = new SearchSQLQuery(query, "solr", emptyList(), 1000, false, "Israel", emptyList());
    SearchParameters sparams = webscript.buildSearchParameters(searchQuery);
    assertNotNull(sparams);
    assertEquals(query, sparams.getQuery());
    assertEquals(false, sparams.isIncludeMetadata());
    assertEquals(Collections.EMPTY_LIST, sparams.getLocales());
    assertEquals("solr", sparams.getExtraParameters().get("format"));
    assertEquals("Israel", sparams.getTimezone());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) Test(org.junit.Test)

Example 2 with SearchSQLQuery

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

the class SearchSQLApiWebscriptTests method testSearchQueryParamsFormatNull.

@Test
public void testSearchQueryParamsFormatNull() throws Exception {
    String query = "select SITE from alfresco";
    SearchSQLQuery searchQuery = new SearchSQLQuery(query, "", emptyList(), 1000, false, "", emptyList());
    SearchParameters sparams = webscript.buildSearchParameters(searchQuery);
    assertNotNull(sparams);
    assertEquals(query, sparams.getQuery());
    assertEquals(false, sparams.isIncludeMetadata());
    assertEquals(Collections.EMPTY_LIST, sparams.getLocales());
    assertEquals(null, sparams.getExtraParameters().get("format"));
    assertEquals(null, sparams.getTimezone());
    searchQuery = new SearchSQLQuery(query, null, emptyList(), 1000, true, "", emptyList());
    sparams = webscript.buildSearchParameters(searchQuery);
    assertNotNull(sparams);
    assertEquals(query, sparams.getQuery());
    assertEquals(true, sparams.isIncludeMetadata());
    assertEquals(Collections.EMPTY_LIST, sparams.getLocales());
    assertEquals(null, sparams.getExtraParameters().get("format"));
    assertEquals(null, sparams.getTimezone());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) Test(org.junit.Test)

Example 3 with SearchSQLQuery

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

the class SearchSQLApiWebscriptTests method testSearchQueryParams.

@Test
public void testSearchQueryParams() throws Exception {
    String query = "select SITE from alfresco";
    SearchSQLQuery searchQuery = new SearchSQLQuery(query, "solr", emptyList(), 1000, false, "", emptyList());
    SearchParameters sparams = webscript.buildSearchParameters(searchQuery);
    assertNotNull(sparams);
    assertEquals(query, sparams.getQuery());
    assertEquals(false, sparams.isIncludeMetadata());
    assertEquals(Collections.EMPTY_LIST, sparams.getLocales());
    assertEquals("solr", sparams.getExtraParameters().get("format"));
    assertEquals(null, sparams.getTimezone());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) Test(org.junit.Test)

Example 4 with SearchSQLQuery

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

the class SearchSQLParseTest method testSQLDeserializeQuery.

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

Example 5 with SearchSQLQuery

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

the class SearchSQLApiWebscript method execute.

@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse res) throws IOException {
    try {
        // Turn JSON into a Java object representation
        SearchSQLQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchSQLQuery.class);
        SearchParameters sparams = buildSearchParameters(searchQuery);
        ResultSet results = searchService.query(sparams);
        FilteringResultSet frs = (FilteringResultSet) results;
        SolrSQLJSONResultSet ssjr = (SolrSQLJSONResultSet) frs.getUnFilteredResultSet();
        // When solr format is requested pass the solr output directly.
        if (searchQuery.getFormat().equalsIgnoreCase("solr")) {
            res.getWriter().write(ssjr.getSolrResponse());
        } else {
            CollectionWithPagingInfo<TupleList> nodes = resultMapper.toCollectionWithPagingInfo(ssjr.getDocs(), searchQuery);
            renderJsonResponse(res, nodes, assistant.getJsonHelper());
        }
        setResponse(res, DEFAULT_SUCCESS);
    } catch (Exception exception) {
        if (exception instanceof LuceneQueryParserException) {
            renderException(exception, res, assistant);
        } else {
            renderException(new WebScriptException(400, exception.getMessage()), res, assistant);
        }
    }
}
Also used : FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) TupleList(org.alfresco.rest.api.search.model.TupleList) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SolrSQLJSONResultSet(org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) ResultSet(org.alfresco.service.cmr.search.ResultSet) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) SolrSQLJSONResultSet(org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

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