Search in sources :

Example 6 with Search

use of io.arlas.server.core.model.request.Search in project ARLAS-server by gisaia.

the class GeoSearchRESTService method geosearchPost.

@Timed
@Path("{collection}/_geosearch")
@POST
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "GeoSearch", produces = UTF8JSON, notes = Documentation.GEOSEARCH_OPERATION, consumes = UTF8JSON, response = FeatureCollection.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = FeatureCollection.class, responseContainer = "FeatureCollection"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response geosearchPost(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
Search search, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws NotFoundException, ArlasException {
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException(collection);
    }
    String includes = search.projection != null ? search.projection.includes : null;
    String excludes = search.projection != null ? search.projection.excludes : null;
    CheckParams.checkReturnedGeometries(collectionReference, includes, excludes, search.returned_geometries);
    Search searchHeader = new Search();
    searchHeader.filter = ParamsParser.getFilter(partitionFilter);
    exploreService.setValidGeoFilters(collectionReference, search);
    exploreService.setValidGeoFilters(collectionReference, searchHeader);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
    search.projection = ParamsParser.enrichIncludes(search.projection, search.returned_geometries);
    MixedRequest request = new MixedRequest();
    request.basicRequest = search;
    request.headerRequest = searchHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    FeatureCollection fc = exploreService.getFeatures(request, collectionReference, (search.form != null && search.form.flat));
    return cache(Response.ok(fc), maxagecache);
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) FeatureCollection(org.geojson.FeatureCollection) Search(io.arlas.server.core.model.request.Search) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with Search

use of io.arlas.server.core.model.request.Search in project ARLAS-server by gisaia.

the class GeoSearchRESTService method geosearch.

private Response geosearch(CollectionReference collectionReference, Filter filter, String partitionFilter, Optional<String> columnFilter, Boolean flat, String include, String exclude, IntParam size, IntParam from, String sort, String after, String before, Integer maxagecache, String returned_geometries, boolean asShapeFile) throws ArlasException {
    CheckParams.checkReturnedGeometries(collectionReference, include, exclude, returned_geometries);
    Search search = new Search();
    search.filter = filter;
    search.page = ParamsParser.getPage(size, from, sort, after, before);
    search.projection = ParamsParser.getProjection(include, exclude);
    search.returned_geometries = returned_geometries;
    exploreService.setValidGeoFilters(collectionReference, search);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
    search.projection = ParamsParser.enrichIncludes(search.projection, returned_geometries);
    Search searchHeader = new Search();
    searchHeader.filter = ParamsParser.getFilter(partitionFilter);
    MixedRequest request = new MixedRequest();
    request.basicRequest = search;
    exploreService.setValidGeoFilters(collectionReference, searchHeader);
    request.headerRequest = searchHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    FeatureCollection fc = exploreService.getFeatures(request, collectionReference, (flat != null && flat));
    if (asShapeFile) {
        File result = toShapefile(fc);
        try {
            return Response.ok(result).header("Content-Disposition", "attachment; filename=" + result.getName()).build();
        } finally {
            try {
                FileUtils.forceDeleteOnExit(result);
            } catch (IOException e) {
            }
        }
    } else {
        return cache(Response.ok(fc), maxagecache);
    }
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) FeatureCollection(org.geojson.FeatureCollection) Search(io.arlas.server.core.model.request.Search) IOException(java.io.IOException) File(java.io.File)

Example 8 with Search

use of io.arlas.server.core.model.request.Search in project ARLAS-server by gisaia.

the class GeoSearchRESTService method shapesearchPost.

@Timed
@Path("{collection}/_shapesearch")
@POST
@Produces(ZIPFILE)
@Consumes(UTF8JSON)
@ApiOperation(value = "ShapeSearch", produces = ZIPFILE, notes = Documentation.SHAPESEARCH_OPERATION, consumes = UTF8JSON)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response shapesearchPost(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
Search search, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws NotFoundException, ArlasException {
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException(collection);
    }
    String includes = search.projection != null ? search.projection.includes : null;
    String excludes = search.projection != null ? search.projection.excludes : null;
    CheckParams.checkReturnedGeometries(collectionReference, includes, excludes, search.returned_geometries);
    Search searchHeader = new Search();
    searchHeader.filter = ParamsParser.getFilter(partitionFilter);
    exploreService.setValidGeoFilters(collectionReference, search);
    exploreService.setValidGeoFilters(collectionReference, searchHeader);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
    search.projection = ParamsParser.enrichIncludes(search.projection, search.returned_geometries);
    MixedRequest request = new MixedRequest();
    request.basicRequest = search;
    request.headerRequest = searchHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    FeatureCollection fc = exploreService.getFeatures(request, collectionReference, true);
    File result = toShapefile(fc);
    try {
        return Response.ok(result).header("Content-Disposition", "attachment; filename=" + result.getName()).build();
    } finally {
        try {
            FileUtils.forceDeleteOnExit(result);
        } catch (IOException e) {
        }
    }
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) FeatureCollection(org.geojson.FeatureCollection) Search(io.arlas.server.core.model.request.Search) IOException(java.io.IOException) File(java.io.File) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 9 with Search

use of io.arlas.server.core.model.request.Search in project ARLAS-server by gisaia.

the class SearchRESTService method searchPost.

@Timed
@Path("{collection}/_search")
@POST
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Search", produces = UTF8JSON, notes = Documentation.SEARCH_OPERATION, consumes = UTF8JSON, response = Hits.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = Hits.class, responseContainer = "ArlasHits"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response searchPost(@Context UriInfo uriInfo, // --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
Search search, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws NotFoundException, ArlasException {
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException(collection);
    }
    String includes = search.projection != null ? search.projection.includes : null;
    String excludes = search.projection != null ? search.projection.excludes : null;
    Search searchHeader = new Search();
    searchHeader.filter = ParamsParser.getFilter(partitionFilter);
    exploreService.setValidGeoFilters(collectionReference, search);
    exploreService.setValidGeoFilters(collectionReference, searchHeader);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
    CheckParams.checkReturnedGeometries(collectionReference, includes, excludes, search.returned_geometries);
    search.projection = ParamsParser.enrichIncludes(search.projection, search.returned_geometries);
    MixedRequest request = new MixedRequest();
    request.basicRequest = search;
    request.headerRequest = searchHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    Hits hits = exploreService.search(request, collectionReference, (search.form != null && Boolean.TRUE.equals(search.form.flat)), uriInfo, "POST");
    return cache(Response.ok(hits), maxagecache);
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) Hits(io.arlas.server.core.model.response.Hits) Search(io.arlas.server.core.model.request.Search) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with Search

use of io.arlas.server.core.model.request.Search in project ARLAS-server by gisaia.

the class AbstractPaginatedTest method testPOSTLinkSearchAfter.

@Test
public void testPOSTLinkSearchAfter() throws Exception {
    /**
     * Test sort without md.id field ==> link.next is null
     */
    search.page.sort = "params.startdate";
    RequestSpecification requestWithoutIdInSort = givenFilterableRequestBody();
    requestWithoutIdInSort.param("sort", search.page.sort).when().get(getUrlPath("geodata")).then().statusCode(200).body("links.next", nullValue()).body("links.self", notNullValue());
    /**
     * Test sort with md.id field  ==> link.next is not null
     *  The following request will allow us to apply `after` parameter for the next requests
     */
    search.page.sort = "params.startdate,id";
    search.page.size = 3;
    RequestSpecification requestWithIdInSort = givenFilterableRequestBody();
    ExtractableResponse firstResponse = requestWithIdInSort.body(handlePostRequest(search)).when().post(getUrlPath("geodata")).then().body("links.next", notNullValue()).body("links.self", notNullValue()).extract();
    String id_0 = firstResponse.path("hits[0].data.id");
    Integer date_0 = firstResponse.path("hits[0].data.params.startdate");
    String id_1 = firstResponse.path("hits[1].data.id");
    String id_2 = firstResponse.path("hits[2].data.id");
    /**
     * Second request will use 'after' param starting from id_0 with a size = 1 ==> the first hit id will be id_1
     */
    search.page.sort = "params.startdate,id";
    search.page.size = 1;
    search.page.after = date_0.toString().concat(",").concat(id_0);
    RequestSpecification secondRequest = givenFilterableRequestBody();
    ExtractableResponse secondResponse = secondRequest.body(handlePostRequest(search)).when().post(getUrlPath("geodata")).then().body("hits[0].data.id", equalTo(id_1)).extract();
    /**
     * Third request will use 'after' param using links.next of the second response (with a size = 1) ==> the first hit id will be id_2
     */
    HashMap data = secondResponse.path("links.next.body");
    String href = secondResponse.path("links.next.href");
    ObjectMapper objectMapper = new ObjectMapper();
    Search searchFromLink = objectMapper.convertValue(data, Search.class);
    ExtractableResponse thirdResponse = givenFilterableRequestBody().body(handlePostRequest(searchFromLink)).when().post(href).then().body("hits[0].data.id", equalTo(id_2)).body("links.next", notNullValue()).body("links.self", notNullValue()).statusCode(200).extract();
    /**
     * This request will use 'before' param using links.previous of the third response (with a size = 1) ==> the first hit id will be id_1
     */
    HashMap thirdBodyPrevious = thirdResponse.path("links.previous.body");
    String thirdResponsePreviousHref = thirdResponse.path("links.previous.href");
    Search searchPreviousFromLink = objectMapper.convertValue(thirdBodyPrevious, Search.class);
    givenFilterableRequestBody().body(handlePostRequest(searchPreviousFromLink)).when().post(thirdResponsePreviousHref).then().body("hits[0].data.id", equalTo(id_1)).body("links.next", notNullValue()).body("links.self", notNullValue()).statusCode(200).extract();
    /**
     * We go now to the last page by applying a size = 595. 'link.next' should be null
     */
    HashMap lastRequestBody = thirdResponse.path("links.next.body");
    String lastHref = thirdResponse.path("links.next.href");
    Search lastSearchFromLink = objectMapper.convertValue(lastRequestBody, Search.class);
    lastSearchFromLink.page.size = 595;
    givenFilterableRequestBody().body(handlePostRequest(lastSearchFromLink)).when().post(lastHref).then().body("nbhits", lessThan(lastSearchFromLink.page.size)).body("links.next", nullValue()).body("links.self", notNullValue()).statusCode(200);
}
Also used : HashMap(java.util.HashMap) ExtractableResponse(io.restassured.response.ExtractableResponse) Search(io.arlas.server.core.model.request.Search) RequestSpecification(io.restassured.specification.RequestSpecification) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Search (io.arlas.server.core.model.request.Search)10 MixedRequest (io.arlas.server.core.model.request.MixedRequest)7 CollectionReference (io.arlas.server.core.model.CollectionReference)6 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 FeatureCollection (org.geojson.FeatureCollection)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArlasException (io.arlas.server.core.exceptions.ArlasException)2 Hits (io.arlas.server.core.model.response.Hits)2 ExploreService (io.arlas.server.core.services.ExploreService)2 io.arlas.server.core.utils (io.arlas.server.core.utils)2 IntParam (io.dropwizard.jersey.params.IntParam)2 ExtractableResponse (io.restassured.response.ExtractableResponse)2 RequestSpecification (io.restassured.specification.RequestSpecification)2 File (java.io.File)2 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 Response (javax.ws.rs.core.Response)2