Search in sources :

Example 1 with Hit

use of io.arlas.server.core.model.response.Hit 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)1 Documentation (io.arlas.server.core.app.Documentation)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 NotFoundException (io.arlas.server.core.exceptions.NotFoundException)1 CollectionReference (io.arlas.server.core.model.CollectionReference)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 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 javax.ws.rs (javax.ws.rs)1 Response (javax.ws.rs.core.Response)1