Search in sources :

Example 1 with Range

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);
    }
}
Also used : APPLICATION_ANALYTICS(io.gravitee.rest.api.model.permissions.RolePermission.APPLICATION_ANALYTICS) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) API_ANALYTICS(io.gravitee.rest.api.model.permissions.RolePermission.API_ANALYTICS) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) ApiService(io.gravitee.rest.api.service.ApiService) DateHistogramQuery(io.gravitee.rest.api.model.analytics.query.DateHistogramQuery) GroupByQuery(io.gravitee.rest.api.model.analytics.query.GroupByQuery) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) Aggregation(io.gravitee.rest.api.management.rest.resource.param.Aggregation) AggregationType(io.gravitee.rest.api.model.analytics.query.AggregationType) Map(java.util.Map) PermissionService(io.gravitee.rest.api.service.PermissionService) Analytics(io.gravitee.rest.api.model.analytics.Analytics) Api(io.swagger.annotations.Api) AbstractQuery(io.gravitee.rest.api.model.analytics.query.AbstractQuery) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) READ(io.gravitee.rest.api.model.permissions.RolePermissionAction.READ) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Set(java.util.Set) CountQuery(io.gravitee.rest.api.model.analytics.query.CountQuery) Collectors(java.util.stream.Collectors) BeanParam(javax.ws.rs.BeanParam) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Response(javax.ws.rs.core.Response) StatsQuery(io.gravitee.rest.api.model.analytics.query.StatsQuery) ApiResponse(io.swagger.annotations.ApiResponse) AnalyticsParam(io.gravitee.rest.api.management.rest.resource.param.AnalyticsParam) ApplicationService(io.gravitee.rest.api.service.ApplicationService) Range(io.gravitee.rest.api.management.rest.resource.param.Range) TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) AnalyticsService(io.gravitee.rest.api.service.AnalyticsService) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) NotNull(org.jetbrains.annotations.NotNull) GroupByQuery(io.gravitee.rest.api.model.analytics.query.GroupByQuery) Range(io.gravitee.rest.api.management.rest.resource.param.Range)

Aggregations

MediaType (io.gravitee.common.http.MediaType)1 Aggregation (io.gravitee.rest.api.management.rest.resource.param.Aggregation)1 AnalyticsParam (io.gravitee.rest.api.management.rest.resource.param.AnalyticsParam)1 Range (io.gravitee.rest.api.management.rest.resource.param.Range)1 Analytics (io.gravitee.rest.api.model.analytics.Analytics)1 HistogramAnalytics (io.gravitee.rest.api.model.analytics.HistogramAnalytics)1 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)1 AbstractQuery (io.gravitee.rest.api.model.analytics.query.AbstractQuery)1 AggregationType (io.gravitee.rest.api.model.analytics.query.AggregationType)1 CountQuery (io.gravitee.rest.api.model.analytics.query.CountQuery)1 DateHistogramQuery (io.gravitee.rest.api.model.analytics.query.DateHistogramQuery)1 GroupByQuery (io.gravitee.rest.api.model.analytics.query.GroupByQuery)1 StatsAnalytics (io.gravitee.rest.api.model.analytics.query.StatsAnalytics)1 StatsQuery (io.gravitee.rest.api.model.analytics.query.StatsQuery)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)1 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)1 API_ANALYTICS (io.gravitee.rest.api.model.permissions.RolePermission.API_ANALYTICS)1 APPLICATION_ANALYTICS (io.gravitee.rest.api.model.permissions.RolePermission.APPLICATION_ANALYTICS)1 READ (io.gravitee.rest.api.model.permissions.RolePermissionAction.READ)1