Search in sources :

Example 1 with ComputationRequest

use of io.arlas.server.core.model.request.ComputationRequest 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 ComputationRequest

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

the class StacRESTService method getSpatialExtent.

protected ExtentSpatial getSpatialExtent(CollectionReference collectionReference) throws ArlasException {
    ComputationRequest computationRequest = new ComputationRequest();
    computationRequest.field = collectionReference.params.centroidPath;
    computationRequest.metric = ComputationEnum.GEOBBOX;
    exploreService.setValidGeoFilters(collectionReference, computationRequest);
    MixedRequest request = new MixedRequest();
    request.basicRequest = computationRequest;
    request.headerRequest = new ComputationRequest();
    return new ExtentSpatial().bbox(getBbox((Polygon) exploreService.compute(request, collectionReference).geometry));
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) ComputationRequest(io.arlas.server.core.model.request.ComputationRequest) Polygon(org.geojson.Polygon)

Example 3 with ComputationRequest

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

the class StacRESTService method getTemporalExtent.

protected ExtentTemporal getTemporalExtent(CollectionReference collectionReference) throws ArlasException {
    ComputationRequest computationRequest = new ComputationRequest();
    computationRequest.field = collectionReference.params.timestampPath;
    computationRequest.metric = ComputationEnum.MIN;
    MixedRequest request = new MixedRequest();
    request.basicRequest = computationRequest;
    request.headerRequest = new ComputationRequest();
    Double minTime = exploreService.compute(request, collectionReference).value;
    computationRequest.metric = ComputationEnum.MAX;
    Double maxTime = exploreService.compute(request, collectionReference).value;
    if (minTime != null && maxTime != null) {
        return new ExtentTemporal().interval(Collections.singletonList(Arrays.asList(ITU.formatUtc(OffsetDateTime.ofInstant(Instant.ofEpochMilli(minTime.longValue()), ZoneOffset.UTC)), ITU.formatUtc(OffsetDateTime.ofInstant(Instant.ofEpochMilli(maxTime.longValue()), ZoneOffset.UTC)))));
    } else {
        return null;
    }
}
Also used : MixedRequest(io.arlas.server.core.model.request.MixedRequest) ComputationRequest(io.arlas.server.core.model.request.ComputationRequest)

Example 4 with ComputationRequest

use of io.arlas.server.core.model.request.ComputationRequest 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

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