Search in sources :

Example 1 with CqlQueryResponse

use of org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse in project ddf by codice.

the class QueryApplication method init.

@Override
public void init() {
    post("/cql", APPLICATION_JSON, (req, res) -> {
        CqlRequest cqlRequest = mapper.readValue(req.body(), CqlRequest.class);
        CqlQueryResponse cqlQueryResponse = executeCqlQuery(cqlRequest);
        String result = mapper.toJson(cqlQueryResponse);
        return result;
    });
    after("/cql", (req, res) -> {
        res.type(APPLICATION_JSON);
        res.header("Content-Encoding", "gzip");
    });
    exception(UnsupportedQueryException.class, (e, request, response) -> {
        response.status(400);
        response.body("Unsupported query request.");
        LOGGER.error("Query endpoint failed", e);
    });
    exception(Exception.class, (e, request, response) -> {
        response.status(500);
        response.body("Error while processing query request.");
        LOGGER.error("Query endpoint failed", e);
    });
    enableRouteOverview();
}
Also used : CqlRequest(org.codice.ddf.catalog.ui.query.cql.CqlRequest) CqlQueryResponse(org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse)

Example 2 with CqlQueryResponse

use of org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse in project ddf by codice.

the class QueryApplication method executeCqlQuery.

private CqlQueryResponse executeCqlQuery(CqlRequest cqlRequest) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    QueryRequest request = cqlRequest.createQueryRequest(catalogFramework.getId(), filterBuilder);
    Stopwatch stopwatch = Stopwatch.createStarted();
    QueryResponse response = catalogFramework.query(request);
    stopwatch.stop();
    return new CqlQueryResponse(cqlRequest.getId(), request, response, cqlRequest.getSource(), stopwatch.elapsed(TimeUnit.MILLISECONDS), cqlRequest.isNormalize(), filterAdapter, actionRegistry);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CqlQueryResponse(org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Stopwatch(com.google.common.base.Stopwatch) CqlQueryResponse(org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse)

Aggregations

CqlQueryResponse (org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse)2 Stopwatch (com.google.common.base.Stopwatch)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 CqlRequest (org.codice.ddf.catalog.ui.query.cql.CqlRequest)1