use of io.gravitee.rest.api.management.rest.resource.param.Range in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentAnalyticsResource method executeGroupBy.
private Analytics executeGroupBy(AnalyticsParam analyticsParam, String extraFilter) {
GroupByQuery query = new GroupByQuery();
query.setFrom(analyticsParam.getFrom());
query.setTo(analyticsParam.getTo());
query.setInterval(analyticsParam.getInterval());
query.setQuery(analyticsParam.getQuery());
query.setField(analyticsParam.getField());
if (analyticsParam.getOrder() != null) {
final 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);
}
addExtraFilter(query, extraFilter);
switch(analyticsParam.getField()) {
case STATE_FIELD:
{
return getTopHitsAnalytics(api -> api.getState().name());
}
case LIFECYCLE_STATE_FIELD:
{
return getTopHitsAnalytics(api -> api.getLifecycleState().name());
}
default:
return analyticsService.execute(query);
}
}
Aggregations