Search in sources :

Example 6 with AggregationResponse

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

the class GeoAggregateRESTService method geotilegeoaggregate.

@Timed
@Path("{collection}/_geoaggregate/{z}/{x}/{y}")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "GeoAggregate on a geotile", produces = UTF8JSON, notes = Documentation.GEOTILE_GEOAGGREGATION_OPERATION, consumes = UTF8JSON, response = FeatureCollection.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = FeatureCollection.class, responseContainer = "FeatureCollection"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class), @ApiResponse(code = 501, message = "Not implemented functionality.", response = Error.class) })
public Response geotilegeoaggregate(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, @ApiParam(name = "z", value = "z", required = true) @PathParam(value = "z") Integer z, @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 = "agg", value = Documentation.GEOAGGREGATION_PARAM_AGG) @QueryParam(value = "agg") List<String> agg, // --------------------------------------------------------
@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(name = "flat", value = Documentation.FORM_FLAT, defaultValue = "false") @QueryParam(value = "flat") Boolean flat, // --------------------------------------------------------
@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 (agg == null || agg.size() == 0) {
        agg = Collections.singletonList("geotile:" + collectionReference.params.centroidPath + ":interval-" + (z + 3));
    }
    List<BoundingBox> bboxes = getBoundingBoxes(z, x, y, agg, collectionReference);
    List<CompletableFuture<AggregationResponse>> futureList = new ArrayList<>();
    AggregationTypeEnum aggType = null;
    for (BoundingBox b : bboxes) {
        Expression pwithinBbox = new Expression(collectionReference.params.centroidPath, OperatorEnum.within, b.getWest() + "," + b.getSouth() + "," + String.format(Locale.ROOT, "%.8f", b.getEast() - GEOHASH_EPSILON) + "," + String.format(Locale.ROOT, "%.8f", b.getNorth() - GEOHASH_EPSILON));
        MixedRequest request = getGeoaggregateRequest(collectionReference, ParamsParser.getFilter(collectionReference, f, q, dateformat, b, pwithinBbox), partitionFilter, columnFilter, agg);
        aggType = ((AggregationsRequest) request.basicRequest).aggregations.get(0).type;
        futureList.add(CompletableFuture.supplyAsync(() -> {
            try {
                return exploreService.aggregate(request, collectionReference, true, ((AggregationsRequest) request.basicRequest).aggregations, 0, System.nanoTime());
            } catch (ArlasException e) {
                throw new RuntimeException(e);
            }
        }));
    }
    List<AggregationResponse> aggResponses = futureList.stream().map(CompletableFuture::join).collect(Collectors.toList());
    return cache(Response.ok(toGeoJson(merge(aggResponses), aggType, Boolean.TRUE.equals(flat), Optional.of(z + "/" + x + "/" + y))), maxagecache);
}
Also used : ArlasException(io.arlas.server.core.exceptions.ArlasException) CollectionReference(io.arlas.server.core.model.CollectionReference) CompletableFuture(java.util.concurrent.CompletableFuture) AggregationResponse(io.arlas.server.core.model.response.AggregationResponse) AggregationTypeEnum(io.arlas.server.core.model.enumerations.AggregationTypeEnum) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with AggregationResponse

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

the class AggregateRESTService method flatten.

private AggregationResponse flatten(AggregationResponse aggregationResponse) {
    List<AggregationResponse> elements = aggregationResponse.elements;
    if (elements != null && elements.size() > 0) {
        for (AggregationResponse element : elements) {
            element.flattenedElements = new HashMap<>();
            exploreService.flat(element, new MapExplorer.ReduceArrayOnKey(ArlasServerConfiguration.FLATTEN_CHAR), s -> (!"elements".equals(s))).forEach((key, value) -> element.flattenedElements.put(key, value));
            element.elements = null;
            element.metrics = null;
        }
    }
    return aggregationResponse;
}
Also used : ParamsParser(io.arlas.server.core.utils.ParamsParser) CollectionReference(io.arlas.server.core.model.CollectionReference) MixedRequest(io.arlas.server.core.model.request.MixedRequest) Documentation(io.arlas.server.core.app.Documentation) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) TimeUnit(java.util.concurrent.TimeUnit) Timed(com.codahale.metrics.annotation.Timed) ExploreRESTServices(io.arlas.server.rest.explore.ExploreRESTServices) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) 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) MapExplorer(io.arlas.server.core.utils.MapExplorer) AggregationResponse(io.arlas.server.core.model.response.AggregationResponse) ApiResponse(io.swagger.annotations.ApiResponse) Optional(java.util.Optional) ArlasServerConfiguration(io.arlas.server.core.app.ArlasServerConfiguration) AggregationsRequest(io.arlas.server.core.model.request.AggregationsRequest) ColumnFilterUtil(io.arlas.server.core.utils.ColumnFilterUtil) Error(io.arlas.server.core.model.response.Error) AggregationResponse(io.arlas.server.core.model.response.AggregationResponse)

Example 8 with AggregationResponse

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

the class AggregateRESTService method aggregate.

@Timed
@Path("{collection}/_aggregate")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Aggregate", produces = UTF8JSON, notes = Documentation.AGGREGATION_OPERATION, consumes = UTF8JSON, response = AggregationResponse.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = AggregationResponse.class, responseContainer = "ArlasAggregation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response aggregate(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
@ApiParam(name = "agg", value = Documentation.AGGREGATION_PARAM_AGG, required = true) @QueryParam(value = "agg") List<String> agg, // --------------------------------------------------------
@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(name = "flat", value = Documentation.FORM_FLAT, defaultValue = "false") @QueryParam(value = "flat") Boolean flat, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws ArlasException {
    long startArlasTime = System.nanoTime();
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException(collection);
    }
    AggregationsRequest aggregationsRequest = new AggregationsRequest();
    aggregationsRequest.filter = ParamsParser.getFilter(collectionReference, f, q, dateformat);
    aggregationsRequest.aggregations = ParamsParser.getAggregations(collectionReference, agg);
    exploreService.setValidGeoFilters(collectionReference, aggregationsRequest);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, aggregationsRequest);
    AggregationsRequest aggregationsRequestHeader = new AggregationsRequest();
    aggregationsRequestHeader.filter = ParamsParser.getFilter(partitionFilter);
    MixedRequest request = new MixedRequest();
    request.basicRequest = aggregationsRequest;
    exploreService.setValidGeoFilters(collectionReference, aggregationsRequestHeader);
    request.headerRequest = aggregationsRequestHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    AggregationResponse aggregationResponse = getArlasAggregation(request, collectionReference, Boolean.TRUE.equals(flat));
    aggregationResponse.totalTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startArlasTime);
    return cache(Response.ok(aggregationResponse), maxagecache);
}
Also used : AggregationsRequest(io.arlas.server.core.model.request.AggregationsRequest) MixedRequest(io.arlas.server.core.model.request.MixedRequest) AggregationResponse(io.arlas.server.core.model.response.AggregationResponse) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

AggregationResponse (io.arlas.server.core.model.response.AggregationResponse)8 Timed (com.codahale.metrics.annotation.Timed)7 CollectionReference (io.arlas.server.core.model.CollectionReference)7 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 ArlasException (io.arlas.server.core.exceptions.ArlasException)5 AggregationTypeEnum (io.arlas.server.core.model.enumerations.AggregationTypeEnum)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 ArlasServerConfiguration (io.arlas.server.core.app.ArlasServerConfiguration)3 Documentation (io.arlas.server.core.app.Documentation)3 AggregationsRequest (io.arlas.server.core.model.request.AggregationsRequest)3 MixedRequest (io.arlas.server.core.model.request.MixedRequest)3 Error (io.arlas.server.core.model.response.Error)3 ExploreService (io.arlas.server.core.services.ExploreService)3 ExploreRESTServices (io.arlas.server.rest.explore.ExploreRESTServices)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 javax.ws.rs (javax.ws.rs)3 Response (javax.ws.rs.core.Response)3 FeatureCollection (org.geojson.FeatureCollection)3