Search in sources :

Example 1 with APPLICATION_ANALYTICS

use of io.gravitee.management.model.permissions.RolePermission.APPLICATION_ANALYTICS in project gravitee-management-rest-api by gravitee-io.

the class PlatformAnalyticsResource method platformAnalytics.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = MANAGEMENT_PLATFORM, acls = READ) })
public Response platformAnalytics(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    // add filter by Apis or Applications
    String extraFilter = null;
    if (!isAdmin()) {
        if ("api".equals(analyticsParam.getField())) {
            extraFilter = getExtraFilter(analyticsParam.getField(), apiService.findByUser(getAuthenticatedUser()).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.toList()));
        } else if ("application".equals(analyticsParam.getField())) {
            extraFilter = getExtraFilter(analyticsParam.getField(), applicationService.findByUser(getAuthenticatedUser()).stream().filter(app -> permissionService.hasPermission(APPLICATION_ANALYTICS, app.getId(), READ)).map(ApplicationEntity::getId).collect(Collectors.toList()));
        }
    }
    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;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.management.model.analytics.Analytics) io.gravitee.management.model.analytics.query(io.gravitee.management.model.analytics.query) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiEntity(io.gravitee.management.model.ApiEntity) ApiService(io.gravitee.management.service.ApiService) RolePermission(io.gravitee.management.model.permissions.RolePermission) Aggregation(io.gravitee.management.rest.resource.param.Aggregation) AnalyticsService(io.gravitee.management.service.AnalyticsService) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Function(java.util.function.Function) Inject(javax.inject.Inject) Map(java.util.Map) Api(io.swagger.annotations.Api) Permission(io.gravitee.management.rest.security.Permission) AnalyticsParam(io.gravitee.management.rest.resource.param.AnalyticsParam) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) API_ANALYTICS(io.gravitee.management.model.permissions.RolePermission.API_ANALYTICS) MANAGEMENT_PLATFORM(io.gravitee.management.model.permissions.RolePermission.MANAGEMENT_PLATFORM) Range(io.gravitee.management.rest.resource.param.Range) Permissions(io.gravitee.management.rest.security.Permissions) PermissionService(io.gravitee.management.service.PermissionService) Collectors(java.util.stream.Collectors) ApplicationService(io.gravitee.management.service.ApplicationService) BeanParam(javax.ws.rs.BeanParam) READ(io.gravitee.management.model.permissions.RolePermissionAction.READ) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Response(javax.ws.rs.core.Response) APPLICATION_ANALYTICS(io.gravitee.management.model.permissions.RolePermission.APPLICATION_ANALYTICS) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Analytics(io.gravitee.management.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Permissions(io.gravitee.management.rest.security.Permissions)

Aggregations

MediaType (io.gravitee.common.http.MediaType)1 ApiEntity (io.gravitee.management.model.ApiEntity)1 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)1 Analytics (io.gravitee.management.model.analytics.Analytics)1 io.gravitee.management.model.analytics.query (io.gravitee.management.model.analytics.query)1 RolePermission (io.gravitee.management.model.permissions.RolePermission)1 API_ANALYTICS (io.gravitee.management.model.permissions.RolePermission.API_ANALYTICS)1 APPLICATION_ANALYTICS (io.gravitee.management.model.permissions.RolePermission.APPLICATION_ANALYTICS)1 MANAGEMENT_PLATFORM (io.gravitee.management.model.permissions.RolePermission.MANAGEMENT_PLATFORM)1 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)1 READ (io.gravitee.management.model.permissions.RolePermissionAction.READ)1 Aggregation (io.gravitee.management.rest.resource.param.Aggregation)1 AnalyticsParam (io.gravitee.management.rest.resource.param.AnalyticsParam)1 Range (io.gravitee.management.rest.resource.param.Range)1 Permission (io.gravitee.management.rest.security.Permission)1 Permissions (io.gravitee.management.rest.security.Permissions)1 AnalyticsService (io.gravitee.management.service.AnalyticsService)1 ApiService (io.gravitee.management.service.ApiService)1 ApplicationService (io.gravitee.management.service.ApplicationService)1 PermissionService (io.gravitee.management.service.PermissionService)1