Search in sources :

Example 1 with GroupByQueryBuilder

use of io.gravitee.repository.analytics.query.groupby.GroupByQueryBuilder in project gravitee-management-rest-api by gravitee-io.

the class AnalyticsServiceImpl method execute.

@Override
public TopHitsAnalytics execute(GroupByQuery query) {
    try {
        GroupByQueryBuilder queryBuilder = QueryBuilders.groupBy().query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root(query.getRootField(), query.getRootIdentifier()).field(query.getField());
        if (query.getGroups() != null) {
            query.getGroups().forEach(queryBuilder::range);
        }
        if (query.getOrder() != null) {
            GroupByQuery.Order order = query.getOrder();
            queryBuilder.sort(SortBuilder.on(order.getField(), order.isOrder() ? Order.ASC : Order.DESC, (order.getType() == null) ? SortType.AVG : SortType.valueOf(order.getType().toUpperCase())));
        }
        GroupByResponse 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 : GroupByQuery(io.gravitee.management.model.analytics.query.GroupByQuery) GroupByResponse(io.gravitee.repository.analytics.query.groupby.GroupByResponse) GroupByQueryBuilder(io.gravitee.repository.analytics.query.groupby.GroupByQueryBuilder) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException)

Aggregations

GroupByQuery (io.gravitee.management.model.analytics.query.GroupByQuery)1 AnalyticsException (io.gravitee.repository.analytics.AnalyticsException)1 GroupByQueryBuilder (io.gravitee.repository.analytics.query.groupby.GroupByQueryBuilder)1 GroupByResponse (io.gravitee.repository.analytics.query.groupby.GroupByResponse)1