Search in sources :

Example 1 with Analytics

use of io.gravitee.rest.api.model.analytics.Analytics in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAnalyticsResource method getApplicationAnalyticsHits.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get application analytics", notes = "User must have the APPLICATION_ANALYTICS[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Application analytics"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_ANALYTICS, acls = RolePermissionAction.READ) })
public Response getApplicationAnalyticsHits(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    switch(analyticsParam.getTypeParam().getValue()) {
        case DATE_HISTO:
            analytics = executeDateHisto(application, analyticsParam);
            break;
        case GROUP_BY:
            analytics = executeGroupBy(application, analyticsParam);
            break;
        case COUNT:
            analytics = executeCount(application, analyticsParam);
            break;
        case STATS:
            analytics = executeStats(application, analyticsParam);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.rest.api.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 2 with Analytics

use of io.gravitee.rest.api.model.analytics.Analytics 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)

Example 3 with Analytics

use of io.gravitee.rest.api.model.analytics.Analytics in project gravitee-management-rest-api by gravitee-io.

the class ApiAnalyticsResource method getApiAnalyticsHits.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get API analytics", notes = "User must have the API_ANALYTICS[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "API analytics"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_ANALYTICS, acls = RolePermissionAction.READ) })
public Response getApiAnalyticsHits(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    switch(analyticsParam.getType()) {
        case DATE_HISTO:
            analytics = executeDateHisto(api, analyticsParam);
            break;
        case GROUP_BY:
            analytics = executeGroupBy(api, analyticsParam);
            break;
        case COUNT:
            analytics = executeCount(api, analyticsParam);
            break;
        case STATS:
            analytics = executeStats(api, analyticsParam);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.rest.api.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 4 with Analytics

use of io.gravitee.rest.api.model.analytics.Analytics in project gravitee-management-rest-api by gravitee-io.

the class PlatformAnalyticsResource method getPlatformAnalytics.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get platform analytics", notes = "User must have the MANAGEMENT_PLATFORM[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Platform analytics"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = ENVIRONMENT_PLATFORM, acls = READ) })
public Response getPlatformAnalytics(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    // add filter by Apis or Applications
    String extraFilter = null;
    if (!isAdmin()) {
        String fieldName;
        List<String> ids;
        if ("application".equals(analyticsParam.getField())) {
            fieldName = "application";
            ids = applicationService.findByUser(getAuthenticatedUser()).stream().filter(app -> permissionService.hasPermission(APPLICATION_ANALYTICS, app.getId(), READ)).map(ApplicationListItem::getId).collect(Collectors.toList());
        } else {
            fieldName = "api";
            ids = apiService.findByUser(getAuthenticatedUser(), null, false).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.toList());
        }
        if (ids.isEmpty()) {
            return Response.noContent().build();
        }
        extraFilter = getExtraFilter(fieldName, ids);
    }
    if (analyticsParam.getQuery() != null) {
        analyticsParam.setQuery(analyticsParam.getQuery().replaceAll("\\?", "1"));
    }
    switch(analyticsParam.getTypeParam().getValue()) {
        case DATE_HISTO:
            analytics = executeDateHisto(analyticsParam, extraFilter);
            break;
        case GROUP_BY:
            analytics = executeGroupBy(analyticsParam, extraFilter);
            break;
        case COUNT:
            analytics = executeCount(analyticsParam, extraFilter);
            break;
        case STATS:
            analytics = executeStats(analyticsParam, extraFilter);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) ApiService(io.gravitee.rest.api.service.ApiService) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) Aggregation(io.gravitee.rest.api.management.rest.resource.param.Aggregation) Map(java.util.Map) PermissionService(io.gravitee.rest.api.service.PermissionService) Analytics(io.gravitee.rest.api.model.analytics.Analytics) Api(io.swagger.annotations.Api) io.gravitee.rest.api.model.analytics.query(io.gravitee.rest.api.model.analytics.query) 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) Collectors(java.util.stream.Collectors) BeanParam(javax.ws.rs.BeanParam) Permission(io.gravitee.rest.api.management.rest.security.Permission) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Response(javax.ws.rs.core.Response) 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) AnalyticsService(io.gravitee.rest.api.service.AnalyticsService) Permissions(io.gravitee.rest.api.management.rest.security.Permissions) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Analytics(io.gravitee.rest.api.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.rest.api.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with Analytics

use of io.gravitee.rest.api.model.analytics.Analytics in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResource method getPlatformAnalytics.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get environment analytics")
@ApiResponses({ @ApiResponse(code = 200, message = "Environment analytics"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getPlatformAnalytics(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    // add filter by Apis or Applications
    String extraFilter = null;
    if (!isAdmin()) {
        String fieldName;
        List<String> ids;
        if (APPLICATION_FIELD.equals(analyticsParam.getField())) {
            fieldName = APPLICATION_FIELD;
            ids = applicationService.findByUser(getAuthenticatedUser()).stream().map(ApplicationListItem::getId).filter(appId -> permissionService.hasPermission(APPLICATION_ANALYTICS, appId, READ)).collect(Collectors.toList());
        } else {
            fieldName = API_FIELD;
            ids = apiService.findByUser(getAuthenticatedUser(), null, false).stream().map(ApiEntity::getId).filter(apiId -> permissionService.hasPermission(API_ANALYTICS, apiId, READ)).collect(Collectors.toList());
        }
        extraFilter = getExtraFilter(fieldName, ids);
    }
    if (analyticsParam.getQuery() != null) {
        analyticsParam.setQuery(analyticsParam.getQuery().replaceAll("\\?", "1"));
    }
    switch(analyticsParam.getTypeParam().getValue()) {
        case DATE_HISTO:
            analytics = !isAdmin() && extraFilter == null ? new HistogramAnalytics() : executeDateHisto(analyticsParam, extraFilter);
            break;
        case GROUP_BY:
            analytics = !isAdmin() && extraFilter == null ? new TopHitsAnalytics() : executeGroupBy(analyticsParam, extraFilter);
            break;
        case COUNT:
            analytics = !isAdmin() && extraFilter == null ? new StatsAnalytics() : executeCount(analyticsParam, extraFilter);
            break;
        case STATS:
            analytics = !isAdmin() && extraFilter == null ? new StatsAnalytics() : executeStats(analyticsParam, extraFilter);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) Analytics(io.gravitee.rest.api.model.analytics.Analytics) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Analytics (io.gravitee.rest.api.model.analytics.Analytics)5 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 MediaType (io.gravitee.common.http.MediaType)2 Aggregation (io.gravitee.rest.api.management.rest.resource.param.Aggregation)2 AnalyticsParam (io.gravitee.rest.api.management.rest.resource.param.AnalyticsParam)2 Range (io.gravitee.rest.api.management.rest.resource.param.Range)2 HistogramAnalytics (io.gravitee.rest.api.model.analytics.HistogramAnalytics)2 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)2 StatsAnalytics (io.gravitee.rest.api.model.analytics.query.StatsAnalytics)2 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)2 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)2 READ (io.gravitee.rest.api.model.permissions.RolePermissionAction.READ)2 AnalyticsService (io.gravitee.rest.api.service.AnalyticsService)2 ApiService (io.gravitee.rest.api.service.ApiService)2 ApplicationService (io.gravitee.rest.api.service.ApplicationService)2 PermissionService (io.gravitee.rest.api.service.PermissionService)2