use of io.gravitee.rest.api.management.rest.resource.param.AnalyticsParam 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.management.rest.resource.param.AnalyticsParam 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();
}
Aggregations