Search in sources :

Example 1 with RemoteQueryParseException

use of org.apache.jackrabbit.oak.remote.RemoteQueryParseException in project jackrabbit-oak by apache.

the class ContentRemoteSession method search.

@Override
public RemoteResults search(RemoteRevision revision, String query, String language, long offset, long limit) throws RemoteQueryParseException {
    ContentRemoteRevision contentRemoteRevision = null;
    if (revision instanceof ContentRemoteRevision) {
        contentRemoteRevision = (ContentRemoteRevision) revision;
    }
    if (contentRemoteRevision == null) {
        throw new IllegalArgumentException("invalid revision");
    }
    Root root = contentRemoteRevision.getRoot();
    if (query == null) {
        throw new IllegalArgumentException("query not provided");
    }
    if (language == null) {
        throw new IllegalArgumentException("language not provided");
    }
    if (!root.getQueryEngine().getSupportedQueryLanguages().contains(language)) {
        throw new IllegalArgumentException("language not supported");
    }
    if (offset < 0) {
        throw new IllegalArgumentException("invalid offset");
    }
    if (limit < 0) {
        throw new IllegalArgumentException("invalid limit");
    }
    Result results;
    try {
        results = root.getQueryEngine().executeQuery(query, language, limit, offset, new HashMap<String, PropertyValue>(), new HashMap<String, String>());
    } catch (ParseException e) {
        throw new RemoteQueryParseException("invalid query", e);
    }
    return new ContentRemoteResults(contentRemoteBinaries, results);
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) PathUtils.denotesRoot(org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot) HashMap(java.util.HashMap) RemoteQueryParseException(org.apache.jackrabbit.oak.remote.RemoteQueryParseException) ParseException(java.text.ParseException) RemoteQueryParseException(org.apache.jackrabbit.oak.remote.RemoteQueryParseException) Result(org.apache.jackrabbit.oak.api.Result)

Example 2 with RemoteQueryParseException

use of org.apache.jackrabbit.oak.remote.RemoteQueryParseException in project jackrabbit-oak by apache.

the class SearchRevisionHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    RemoteSession session = (RemoteSession) request.getAttribute("session");
    if (session == null) {
        sendInternalServerError(response, "session not found");
        return;
    }
    RemoteRevision revision = readRevision(request, session);
    if (revision == null) {
        sendGone(response, "unable to read the revision");
        return;
    }
    String query = readQuery(request);
    if (query == null) {
        sendBadRequest(response, "query not specified");
        return;
    }
    String language = readLanguage(request);
    if (language == null) {
        sendBadRequest(response, "language not specified");
        return;
    }
    Long offset = readOffset(request);
    if (offset == null) {
        sendBadRequest(response, "offset not specified");
        return;
    }
    Long limit = readLimit(request);
    if (limit == null) {
        sendBadRequest(response, "limit not specified");
        return;
    }
    RemoteResults results;
    try {
        results = session.search(revision, query, language, offset, limit);
    } catch (RemoteQueryParseException e) {
        sendBadRequest(response, "malformed query");
        return;
    }
    response.setStatus(HttpServletResponse.SC_OK);
    response.setHeader("Oak-Revision", revision.asString());
    response.setContentType("application/json");
    ServletOutputStream stream = response.getOutputStream();
    JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
    renderResponse(generator, results);
    generator.flush();
    stream.close();
}
Also used : RemoteResults(org.apache.jackrabbit.oak.remote.RemoteResults) ServletOutputStream(javax.servlet.ServletOutputStream) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteQueryParseException(org.apache.jackrabbit.oak.remote.RemoteQueryParseException) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision)

Aggregations

RemoteQueryParseException (org.apache.jackrabbit.oak.remote.RemoteQueryParseException)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Result (org.apache.jackrabbit.oak.api.Result)1 Root (org.apache.jackrabbit.oak.api.Root)1 PathUtils.denotesRoot (org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot)1 RemoteResults (org.apache.jackrabbit.oak.remote.RemoteResults)1 RemoteRevision (org.apache.jackrabbit.oak.remote.RemoteRevision)1 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)1