Search in sources :

Example 1 with Analytics

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

the class ApiAnalyticsResource method hits.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Get API analytics")
@Permissions({ @Permission(value = RolePermission.API_ANALYTICS, acls = RolePermissionAction.READ) })
public Response hits(@PathParam("api") String api, @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;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.management.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions)

Example 2 with Analytics

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

Example 3 with Analytics

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

the class ApplicationAnalyticsResource method hits.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get Application analytics")
@Permissions({ @Permission(value = RolePermission.APPLICATION_ANALYTICS, acls = RolePermissionAction.READ) })
public Response hits(@PathParam("application") String application, @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;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.management.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions)

Aggregations

Analytics (io.gravitee.management.model.analytics.Analytics)3 Permissions (io.gravitee.management.rest.security.Permissions)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 ApiOperation (io.swagger.annotations.ApiOperation)2 MediaType (io.gravitee.common.http.MediaType)1 ApiEntity (io.gravitee.management.model.ApiEntity)1 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)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 AnalyticsService (io.gravitee.management.service.AnalyticsService)1