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