Search in sources :

Example 1 with ComputationResponse

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

the class ComputeRESTService method compute.

@Timed
@Path("{collection}/_compute")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Compute", produces = UTF8JSON, notes = Documentation.COMPUTE_OPERATION, consumes = UTF8JSON, response = ComputationResponse.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = ComputationResponse.class, responseContainer = "ArlasComputation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response compute(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
@ApiParam(name = "field", value = Documentation.COMPUTE_FIELD, required = true) @QueryParam(value = "field") String field, @ApiParam(name = "metric", value = Documentation.COMPUTE_METRIC, required = true) @QueryParam(value = "metric") String metric, // --------------------------------------------------------
@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 = "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 ArlasException {
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException(collection);
    }
    ComputationRequest computationRequest = new ComputationRequest();
    computationRequest.filter = ParamsParser.getFilter(collectionReference, f, q, dateformat);
    computationRequest.field = field;
    computationRequest.metric = ComputationEnum.fromValue(metric);
    exploreService.setValidGeoFilters(collectionReference, computationRequest);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, computationRequest);
    ComputationRequest computationRequestHeader = new ComputationRequest();
    computationRequestHeader.filter = ParamsParser.getFilter(partitionFilter);
    exploreService.setValidGeoFilters(collectionReference, computationRequestHeader);
    MixedRequest request = new MixedRequest();
    request.basicRequest = computationRequest;
    request.headerRequest = computationRequestHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    ComputationResponse computationResponse = exploreService.compute(request, collectionReference);
    return cache(Response.ok(computationResponse), maxagecache);
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) ComputationRequest(io.arlas.server.core.model.request.ComputationRequest) CollectionReference(io.arlas.server.core.model.CollectionReference) ComputationResponse(io.arlas.server.core.model.response.ComputationResponse) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ComputationResponse

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

the class ComputeRESTService method computePost.

@Timed
@Path("{collection}/_compute")
@POST
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Compute", produces = UTF8JSON, notes = Documentation.COMPUTE_OPERATION, consumes = UTF8JSON, response = ComputationResponse.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = ComputationResponse.class, responseContainer = "ArlasComputation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response computePost(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
ComputationRequest computationRequest, @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);
    }
    ComputationRequest computationRequestHeader = new ComputationRequest();
    computationRequestHeader.filter = ParamsParser.getFilter(partitionFilter);
    MixedRequest request = new MixedRequest();
    exploreService.setValidGeoFilters(collectionReference, computationRequest);
    exploreService.setValidGeoFilters(collectionReference, computationRequestHeader);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, computationRequest);
    request.basicRequest = computationRequest;
    request.headerRequest = computationRequestHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    ComputationResponse computationResponse = exploreService.compute(request, collectionReference);
    return cache(Response.ok(computationResponse), maxagecache);
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) ComputationRequest(io.arlas.server.core.model.request.ComputationRequest) CollectionReference(io.arlas.server.core.model.CollectionReference) ComputationResponse(io.arlas.server.core.model.response.ComputationResponse) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)2 CollectionReference (io.arlas.server.core.model.CollectionReference)2 ComputationRequest (io.arlas.server.core.model.request.ComputationRequest)2 MixedRequest (io.arlas.server.core.model.request.MixedRequest)2 ComputationResponse (io.arlas.server.core.model.response.ComputationResponse)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2