Search in sources :

Example 1 with DateHistogramResponse

use of io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse in project gravitee-management-rest-api by gravitee-io.

the class AnalyticsServiceImpl method execute.

@Override
public HistogramAnalytics execute(DateHistogramQuery query) {
    try {
        DateHistogramQueryBuilder queryBuilder = QueryBuilders.dateHistogram().query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root(query.getRootField(), query.getRootIdentifier());
        if (query.getAggregations() != null) {
            query.getAggregations().stream().forEach(aggregation -> queryBuilder.aggregation(AggregationType.valueOf(aggregation.type().name()), aggregation.field()));
        }
        DateHistogramResponse response = analyticsRepository.query(queryBuilder.build());
        return convert(response);
    } catch (AnalyticsException ae) {
        logger.error("Unable to calculate analytics: ", ae);
        throw new TechnicalManagementException("Unable to calculate analytics", ae);
    }
}
Also used : AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) DateHistogramResponse(io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse)

Aggregations

AnalyticsException (io.gravitee.repository.analytics.AnalyticsException)1 DateHistogramResponse (io.gravitee.repository.analytics.query.response.histogram.DateHistogramResponse)1