use of io.gravitee.rest.api.model.analytics.HistogramAnalytics in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentAnalyticsResourceTest method shouldGetEmptyHistoAnalyticsWhenNotAdminAndNoApp.
@Test
public void shouldGetEmptyHistoAnalyticsWhenNotAdminAndNoApp() {
when(applicationService.findByUser(any())).thenReturn(Collections.emptySet());
Response response = envTarget().queryParam("type", "date_histo").queryParam("field", "application").queryParam("interval", 1000).queryParam("to", 1000).request().get();
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
HistogramAnalytics analytics = response.readEntity(HistogramAnalytics.class);
assertThat(analytics.getValues()).isNull();
assertThat(analytics.getTimestamp()).isNull();
}
use of io.gravitee.rest.api.model.analytics.HistogramAnalytics in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentAnalyticsResourceTest method shouldGetEmptyHistoAnalyticsWhenNotAdminAndNoApi.
@Test
public void shouldGetEmptyHistoAnalyticsWhenNotAdminAndNoApi() {
when(apiService.findByUser(any(), eq(null), eq(false))).thenReturn(Collections.emptySet());
Response response = envTarget().queryParam("type", "date_histo").queryParam("field", "api").queryParam("interval", 1000).queryParam("to", 1000).request().get();
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
HistogramAnalytics analytics = response.readEntity(HistogramAnalytics.class);
assertThat(analytics.getValues()).isNull();
assertThat(analytics.getTimestamp()).isNull();
}
use of io.gravitee.rest.api.model.analytics.HistogramAnalytics 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();
}
use of io.gravitee.rest.api.model.analytics.HistogramAnalytics in project gravitee-management-rest-api by gravitee-io.
the class HealthCheckServiceImpl method convert.
private HistogramAnalytics convert(DateHistogramResponse histogramResponse) {
final HistogramAnalytics analytics = new HistogramAnalytics();
final List<Long> timestamps = histogramResponse.timestamps();
if (timestamps != null && timestamps.size() > 1) {
final long from = timestamps.get(0);
final long interval = timestamps.get(1) - from;
final long to = timestamps.get(timestamps.size() - 1);
analytics.setTimestamp(new Timestamp(from, to, interval));
List<io.gravitee.rest.api.model.analytics.Bucket> buckets = new ArrayList<>(histogramResponse.values().size());
for (io.gravitee.repository.analytics.query.response.histogram.Bucket bucket : histogramResponse.values()) {
io.gravitee.rest.api.model.analytics.Bucket analyticsBucket = convertBucket(histogramResponse.timestamps(), from, interval, bucket);
buckets.add(analyticsBucket);
}
analytics.setValues(buckets);
}
return analytics;
}
Aggregations