use of io.gravitee.repository.analytics.query.groupby.GroupByResponse 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);
}
}
Aggregations