Search in sources :

Example 1 with NotFoundException

use of io.arlas.server.core.exceptions.NotFoundException in project ARLAS-server by gisaia.

the class StacCollectionsRESTService method getFeature.

@Timed
@Path("/collections/{collectionId}/items/{featureId}")
@GET
@Produces({ "application/geo+json", MediaType.APPLICATION_JSON })
@ApiOperation(value = "Fetch a single feature", notes = "Fetch the feature with id `featureId` in the feature collection with id `collectionId`.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Fetch the feature with id `featureId` in the feature collection with id `collectionId`.", response = Item.class, responseContainer = "Item"), @ApiResponse(code = 404, message = "The requested URI was not found.", response = Error.class), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class) })
public Response getFeature(@Context UriInfo uriInfo, @ApiParam(name = "collectionId", value = "Local identifier of a collection", required = true) @PathParam(value = "collectionId") String collectionId, @ApiParam(name = "featureId", value = "Local identifier of a feature", required = true) @PathParam(value = "featureId") String featureId, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter) throws ArlasException {
    CollectionReference collectionReference = collectionReferenceService.getCollectionReference(collectionId);
    StacFeatureCollection features = getStacFeatureCollection(collectionReference, partitionFilter, columnFilter, null, java.util.Collections.singletonList(getIdFilter(featureId, collectionReference)), uriInfo, "GET", true);
    if (features.getFeatures().size() == 1) {
        Item response = getItem(features.getFeatures().get(0), collectionReference, uriInfo);
        return cache(Response.ok(response), 0);
    } else {
        throw new NotFoundException("Item not found");
    }
}
Also used : 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)

Example 2 with NotFoundException

use of io.arlas.server.core.exceptions.NotFoundException in project ARLAS-server by gisaia.

the class ElasticTool method getCollectionReferenceFromES.

public static CollectionReference getCollectionReferenceFromES(ElasticClient client, String index, ObjectReader reader, String ref) throws ArlasException {
    CollectionReference collection = new CollectionReference(ref);
    // Exclude old include_fields for support old collection
    String[] includes = Strings.EMPTY_ARRAY;
    String[] excludes = new String[] { "include_fields" };
    String source = client.getHit(index, ref, includes, excludes);
    if (source != null) {
        try {
            collection.params = reader.readValue(source);
        } catch (IOException e) {
            throw new InternalServerErrorException("Can not fetch collection " + ref, e);
        }
    } else {
        throw new NotFoundException("Collection " + ref + " not found.");
    }
    return collection;
}
Also used : InternalServerErrorException(io.arlas.server.core.exceptions.InternalServerErrorException) NotFoundException(io.arlas.server.core.exceptions.NotFoundException) IOException(java.io.IOException) CollectionReference(io.arlas.server.core.model.CollectionReference)

Example 3 with NotFoundException

use of io.arlas.server.core.exceptions.NotFoundException 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

NotFoundException (io.arlas.server.core.exceptions.NotFoundException)3 CollectionReference (io.arlas.server.core.model.CollectionReference)3 Timed (com.codahale.metrics.annotation.Timed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Documentation (io.arlas.server.core.app.Documentation)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 InternalServerErrorException (io.arlas.server.core.exceptions.InternalServerErrorException)1 Error (io.arlas.server.core.model.response.Error)1 Hit (io.arlas.server.core.model.response.Hit)1 ExploreService (io.arlas.server.core.services.ExploreService)1 ColumnFilterUtil (io.arlas.server.core.utils.ColumnFilterUtil)1 ExploreRESTServices (io.arlas.server.rest.explore.ExploreRESTServices)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 javax.ws.rs (javax.ws.rs)1