Search in sources :

Example 1 with GroupByQuery

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);
    }
}
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)

Example 2 with GroupByQuery

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);
}
Also used : GroupByQuery(io.gravitee.management.model.analytics.query.GroupByQuery) Range(io.gravitee.management.rest.resource.param.Range)

Example 3 with GroupByQuery

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);
}
Also used : GroupByQuery(io.gravitee.management.model.analytics.query.GroupByQuery) Range(io.gravitee.management.rest.resource.param.Range)

Aggregations

GroupByQuery (io.gravitee.management.model.analytics.query.GroupByQuery)3 Range (io.gravitee.management.rest.resource.param.Range)2 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