Search in sources :

Example 1 with Error

use of io.arlas.server.core.model.response.Error in project ARLAS-server by gisaia.

the class TileRESTService method tiledgeosearch.

@Timed
@Path("{collection}/_tile/{z}/{x}/{y}.png")
@GET
@Produces({ TileRESTService.PRODUCES_PNG })
@Consumes(UTF8JSON)
@ApiOperation(value = "Tiled GeoSearch", produces = TileRESTService.PRODUCES_PNG, notes = Documentation.TILED_GEOSEARCH_OPERATION, consumes = UTF8JSON, response = FeatureCollection.class)
@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 tiledgeosearch(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, @ApiParam(name = "x", value = "x", required = true) @PathParam(value = "x") Integer x, @ApiParam(name = "y", value = "y", required = true) @PathParam(value = "y") Integer y, @ApiParam(name = "z", value = "z", required = true) @PathParam(value = "z") Integer z, // --------------------------------------------------------
@ApiParam(name = "f", value = Documentation.FILTER_PARAM_F, allowMultiple = true) @QueryParam(value = "f") List<String> f, @ApiParam(name = "q", value = Documentation.FILTER_PARAM_Q, allowMultiple = true) @QueryParam(value = "q") List<String> q, @ApiParam(name = "dateformat", value = Documentation.FILTER_DATE_FORMAT) @QueryParam(value = "dateformat") String dateformat, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, @ApiParam(name = "size", value = Documentation.PAGE_PARAM_SIZE, defaultValue = "10", allowableValues = "range[1, infinity]", type = "integer") @DefaultValue("10") @QueryParam(value = "size") IntParam size, @ApiParam(name = "from", value = Documentation.PAGE_PARAM_FROM, defaultValue = "0", allowableValues = "range[0, infinity]", type = "integer") @DefaultValue("0") @QueryParam(value = "from") IntParam from, @ApiParam(name = "sort", value = Documentation.PAGE_PARAM_SORT, allowMultiple = true) @QueryParam(value = "sort") String sort, @ApiParam(name = "after", value = Documentation.PAGE_PARAM_AFTER) @QueryParam(value = "after") String after, @ApiParam(name = "before", value = Documentation.PAGE_PARAM_BEFORE) @QueryParam(value = "before") String before, // --------------------------------------------------------
@ApiParam(name = "sampling", value = TileDocumentation.TILE_SAMPLING, defaultValue = "10") @QueryParam(value = "sampling") Integer sampling, @ApiParam(name = "coverage", value = TileDocumentation.TILE_COVERAGE, defaultValue = "70") @QueryParam(value = "coverage") Integer coverage, // --------------------------------------------------------
@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);
    }
    if (collectionReference.params.rasterTileURL == null) {
        throw new NotFoundException(collectionReference.collectionName + " has no URL defined for fetching the tiles.");
    }
    if (StringUtil.isNullOrEmpty(collectionReference.params.rasterTileURL.url)) {
        throw new NotFoundException(collectionReference.collectionName + " has no URL defined for fetching the tiles.");
    }
    if (z < collectionReference.params.rasterTileURL.minZ || z > collectionReference.params.rasterTileURL.maxZ) {
        LOGGER.info("Request level out of [" + collectionReference.params.rasterTileURL.minZ + "-" + collectionReference.params.rasterTileURL.maxZ + "]");
        return Response.noContent().build();
    }
    BoundingBox bbox = GeoTileUtil.getBoundingBox(new Tile(x, y, z));
    Search search = new Search();
    search.filter = ParamsParser.getFilter(collectionReference, f, q, dateformat);
    search.page = ParamsParser.getPage(size, from, sort, after, before);
    search.projection = ParamsParser.getProjection(collectionReference.params.rasterTileURL.idPath + "," + collectionReference.params.geometryPath, null);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
    Search searchHeader = new Search();
    searchHeader.filter = ParamsParser.getFilter(partitionFilter);
    MixedRequest request = new MixedRequest();
    request.basicRequest = search;
    request.headerRequest = searchHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    Queue<TileProvider<RasterTile>> providers = findCandidateTiles(collectionReference, request).stream().filter(match -> match._2().map(// if geo is available, does it intersect the bbox?
    polygon -> (!collectionReference.params.rasterTileURL.checkGeometry) || polygon.intersects(GeoTileUtil.toPolygon(bbox))).orElse(// otherwise, let's keep that match, we'll see later if it paints something
    Boolean.TRUE)).map(match -> new URLBasedRasterTileProvider(new RasterTileURL(collectionReference.params.rasterTileURL.url.replace("{id}", Optional.ofNullable(match._1()).orElse("")), collectionReference.params.rasterTileURL.minZ, collectionReference.params.rasterTileURL.maxZ, collectionReference.params.rasterTileURL.checkGeometry), collectionReference.params.rasterTileWidth, collectionReference.params.rasterTileHeight)).collect(Collectors.toCollection(LinkedList::new));
    if (providers.size() == 0) {
        return Response.noContent().build();
    }
    Try<Optional<RasterTile>, ArlasException> stacked = new RasterTileStacker().stack(providers).sampling(Optional.ofNullable(sampling).orElse(10)).upTo(new RasterTileStacker.Percentage(Optional.ofNullable(coverage).orElse(10))).on(new Tile(x, y, z));
    stacked.onFail(failure -> LOGGER.error("Failed to fetch a tile", failure));
    return stacked.map(otile -> otile.map(tile -> Try.withCatch(() -> {
        // lets write the image to the response's output
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        ImageIO.write(tile.getImg(), "png", out);
        return cache(Response.ok(out.toByteArray()), maxagecache);
    }, IOException.class).onFail(e -> Response.serverError().entity(e.getMessage()).build()).orElse(// Can't write the tile => No content
    Response.noContent().build())).orElse(// No tile => No content
    Response.noContent().build())).orElse(// No tile => No content
    Response.noContent().build());
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) MixedRequest(io.arlas.server.core.model.request.MixedRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ApiOperation(io.swagger.annotations.ApiOperation) ArlasException(io.arlas.server.core.exceptions.ArlasException) ExploreService(io.arlas.server.core.services.ExploreService) FeatureCollection(org.geojson.FeatureCollection) RasterTileURL(io.arlas.server.core.model.RasterTileURL) IntParam(io.dropwizard.jersey.params.IntParam) io.arlas.server.core.utils(io.arlas.server.core.utils) ImageIO(javax.imageio.ImageIO) LinkedList(java.util.LinkedList) Search(io.arlas.server.core.model.request.Search) CollectionReference(io.arlas.server.core.model.CollectionReference) Documentation(io.arlas.server.core.app.Documentation) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Timed(com.codahale.metrics.annotation.Timed) ExploreRESTServices(io.arlas.server.rest.explore.ExploreRESTServices) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ParseException(org.locationtech.jts.io.ParseException) ApiResponse(io.swagger.annotations.ApiResponse) Try(cyclops.control.Try) Geometry(org.locationtech.jts.geom.Geometry) Optional(java.util.Optional) Queue(java.util.Queue) Error(io.arlas.server.core.model.response.Error) ArlasException(io.arlas.server.core.exceptions.ArlasException) Optional(java.util.Optional) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CollectionReference(io.arlas.server.core.model.CollectionReference) RasterTileURL(io.arlas.server.core.model.RasterTileURL) MixedRequest(io.arlas.server.core.model.request.MixedRequest) Search(io.arlas.server.core.model.request.Search) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with Error

use of io.arlas.server.core.model.response.Error in project ARLAS-server by gisaia.

the class StacCollectionsRESTService method getCollections.

@Timed
@Path("/collections")
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "The feature collections in the dataset", notes = "A body of Feature Collections that belong or are used together with additional links.\n" + "Request may not return the full set of metadata per Feature Collection.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "The feature collections shared by this API.\n" + "The dataset is organized as one or more feature collections.\n" + "This resource provides information about and access to the collections.\n" + "The response contains the list of collections.\n" + "For each collection, a link to the items in the collection (path `/collections/{collectionId}/items`, " + "link relation `items`) as well as key information about the collection.\n" + "This information includes:\n" + "  * A local identifier for the collection that is unique for the dataset;\n" + "  * A list of coordinate reference systems (CRS) in which geometries may be returned by the server. " + "The first CRS is the default coordinate reference system (the default is always WGS 84 with axis order longitude/latitude);\n" + "  * An optional title and description for the collection;\n" + "  * An optional extent that can be used to provide an indication of the spatial and temporal " + "extent of the collection - typically derived from the data;\n" + "  * An optional indicator about the type of the items in the collection (the default value, " + "if the indicator is not provided, is 'feature').", response = CollectionList.class, responseContainer = "CollectionList"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class) })
public Response getCollections(@Context UriInfo uriInfo, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter) throws ArlasException {
    // TODO what do we put in there?
    List<StacLink> links = new ArrayList<>();
    links.add(getSelfLink(uriInfo));
    List<Collection> collectionList = new ArrayList<>();
    for (CollectionReference c : collectionReferenceService.getAllCollectionReferences(columnFilter).stream().filter(c -> !c.collectionName.equals("metacollection")).collect(Collectors.toList())) {
        collectionList.add(getCollection(c, uriInfo));
    }
    return cache(Response.ok(new CollectionList().collections(collectionList).links(links)), 0);
}
Also used : ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) ArlasException(io.arlas.server.core.exceptions.ArlasException) ExploreService(io.arlas.server.core.services.ExploreService) IntParam(io.dropwizard.jersey.params.IntParam) Max(javax.validation.constraints.Max) Schema(io.swagger.v3.oas.annotations.media.Schema) CollectionReference(io.arlas.server.core.model.CollectionReference) Context(javax.ws.rs.core.Context) CollectionReferenceService(io.arlas.server.core.services.CollectionReferenceService) Documentation(io.arlas.server.core.app.Documentation) NotFoundException(io.arlas.server.core.exceptions.NotFoundException) Explode(io.swagger.v3.oas.annotations.enums.Explode) io.arlas.server.stac.model(io.arlas.server.stac.model) Collectors(java.util.stream.Collectors) Parameter(io.swagger.v3.oas.annotations.Parameter) ParameterStyle(io.swagger.v3.oas.annotations.enums.ParameterStyle) Timed(com.codahale.metrics.annotation.Timed) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) STACConfiguration(io.arlas.server.core.app.STACConfiguration) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) Error(io.arlas.server.core.model.response.Error) ArrayList(java.util.ArrayList) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Error

use of io.arlas.server.core.model.response.Error in project ARLAS-server by gisaia.

the class RawRESTService method getArlasHit.

@Timed
@Path("{collection}/{identifier}")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Get an Arlas document", produces = UTF8JSON, notes = "Returns a raw indexed document.", consumes = UTF8JSON, response = Hit.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = Hit.class), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class), @ApiResponse(code = 404, message = "Not Found Error.", response = Error.class) })
public Response getArlasHit(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, @ApiParam(name = "identifier", value = "identifier", required = true) @PathParam(value = "identifier") String identifier, // --------------------------------------------------------
@ApiParam(name = "pretty", value = "Pretty print", defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, @ApiParam(name = "flat", value = Documentation.FORM_FLAT, defaultValue = "false") @QueryParam(value = "flat") Boolean flat, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws ArlasException {
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException("Collection " + collection + " not found.");
    }
    ColumnFilterUtil.assertCollectionsAllowed(columnFilter, Collections.singletonList(collectionReference));
    String[] includes = ColumnFilterUtil.cleanColumnFilter(columnFilter).map(cf -> cf + "," + String.join(",", ColumnFilterUtil.getCollectionMandatoryPaths(collectionReference))).map(i -> i.split(",")).orElse(null);
    Map<String, Object> source = exploreService.getRawDoc(collectionReference, identifier, includes);
    if (source == null || source.isEmpty()) {
        throw new NotFoundException("Document " + identifier + " not found.");
    }
    Hit hit = new Hit(collectionReference, source, Boolean.TRUE.equals(flat), false);
    return cache(Response.ok(hit), maxagecache);
}
Also used : CollectionReference(io.arlas.server.core.model.CollectionReference) Documentation(io.arlas.server.core.app.Documentation) NotFoundException(io.arlas.server.core.exceptions.NotFoundException) Hit(io.arlas.server.core.model.response.Hit) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Timed(com.codahale.metrics.annotation.Timed) ExploreRESTServices(io.arlas.server.rest.explore.ExploreRESTServices) ApiOperation(io.swagger.annotations.ApiOperation) ArlasException(io.arlas.server.core.exceptions.ArlasException) ExploreService(io.arlas.server.core.services.ExploreService) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) Map(java.util.Map) Optional(java.util.Optional) ColumnFilterUtil(io.arlas.server.core.utils.ColumnFilterUtil) Error(io.arlas.server.core.model.response.Error) Collections(java.util.Collections) Hit(io.arlas.server.core.model.response.Hit) NotFoundException(io.arlas.server.core.exceptions.NotFoundException) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)3 Documentation (io.arlas.server.core.app.Documentation)3 ArlasException (io.arlas.server.core.exceptions.ArlasException)3 CollectionReference (io.arlas.server.core.model.CollectionReference)3 Error (io.arlas.server.core.model.response.Error)3 ExploreService (io.arlas.server.core.services.ExploreService)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Optional (java.util.Optional)3 javax.ws.rs (javax.ws.rs)3 Response (javax.ws.rs.core.Response)3 NotFoundException (io.arlas.server.core.exceptions.NotFoundException)2 ExploreRESTServices (io.arlas.server.rest.explore.ExploreRESTServices)2 IntParam (io.dropwizard.jersey.params.IntParam)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Try (cyclops.control.Try)1