Search in sources :

Example 1 with HistogramAnalytics

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();
}
Also used : Response(javax.ws.rs.core.Response) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) Test(org.junit.Test)

Example 2 with HistogramAnalytics

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();
}
Also used : Response(javax.ws.rs.core.Response) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) Test(org.junit.Test)

Example 3 with HistogramAnalytics

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();
}
Also used : TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) Analytics(io.gravitee.rest.api.model.analytics.Analytics) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with HistogramAnalytics

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;
}
Also used : Timestamp(io.gravitee.rest.api.model.analytics.Timestamp) FieldBucket(io.gravitee.repository.healthcheck.query.FieldBucket) Bucket(io.gravitee.repository.healthcheck.query.Bucket) HistogramAnalytics(io.gravitee.rest.api.model.analytics.HistogramAnalytics)

Aggregations

HistogramAnalytics (io.gravitee.rest.api.model.analytics.HistogramAnalytics)4 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 Bucket (io.gravitee.repository.healthcheck.query.Bucket)1 FieldBucket (io.gravitee.repository.healthcheck.query.FieldBucket)1 Analytics (io.gravitee.rest.api.model.analytics.Analytics)1 Timestamp (io.gravitee.rest.api.model.analytics.Timestamp)1 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)1 StatsAnalytics (io.gravitee.rest.api.model.analytics.query.StatsAnalytics)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1