use of io.gravitee.management.model.analytics.query.GroupByQuery 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);
}
}
use of io.gravitee.management.model.analytics.query.GroupByQuery in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAnalyticsResource method executeGroupBy.
private Analytics executeGroupBy(String application, AnalyticsParam analyticsParam) {
GroupByQuery query = new GroupByQuery();
query.setFrom(analyticsParam.getFrom());
query.setTo(analyticsParam.getTo());
query.setInterval(analyticsParam.getInterval());
query.setQuery(analyticsParam.getQuery());
query.setField(analyticsParam.getField());
query.setRootField("application");
query.setRootIdentifier(application);
if (analyticsParam.getOrder() != null) {
GroupByQuery.Order order = new GroupByQuery.Order();
order.setField(analyticsParam.getOrder().getField());
order.setType(analyticsParam.getOrder().getType());
order.setOrder(analyticsParam.getOrder().isOrder());
query.setOrder(order);
}
List<Range> ranges = analyticsParam.getRanges();
if (ranges != null) {
Map<Double, Double> rangeMap = ranges.stream().collect(Collectors.toMap(Range::getFrom, Range::getTo));
query.setGroups(rangeMap);
}
return analyticsService.execute(query);
}
use of io.gravitee.management.model.analytics.query.GroupByQuery in project gravitee-management-rest-api by gravitee-io.
the class ApiAnalyticsResource method executeGroupBy.
private Analytics executeGroupBy(String api, AnalyticsParam analyticsParam) {
GroupByQuery query = new GroupByQuery();
query.setFrom(analyticsParam.getFrom());
query.setTo(analyticsParam.getTo());
query.setInterval(analyticsParam.getInterval());
query.setQuery(analyticsParam.getQuery());
query.setField(analyticsParam.getField());
query.setRootField("api");
query.setRootIdentifier(api);
if (analyticsParam.getOrder() != null) {
GroupByQuery.Order order = new GroupByQuery.Order();
order.setField(analyticsParam.getOrder().getField());
order.setType(analyticsParam.getOrder().getType());
order.setOrder(analyticsParam.getOrder().isOrder());
query.setOrder(order);
}
List<Range> ranges = analyticsParam.getRanges();
if (ranges != null) {
Map<Double, Double> rangeMap = ranges.stream().collect(Collectors.toMap(Range::getFrom, Range::getTo));
query.setGroups(rangeMap);
}
return analyticsService.execute(query);
}
Aggregations