Search in sources :

Example 1 with CountQuery

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

the class ApplicationAnalyticsResourceTest method shouldGetCountAnalytics.

@Test
public void shouldGetCountAnalytics() {
    final Response response = target(APPLICATION).path("analytics").queryParam("from", 0).queryParam("to", 100).queryParam("interval", 10_000).queryParam("query", APPLICATION).queryParam("type", "COUNT").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<CountQuery> queryCaptor = ArgumentCaptor.forClass(CountQuery.class);
    Mockito.verify(analyticsService).execute(queryCaptor.capture());
    final CountQuery query = queryCaptor.getValue();
    assertEquals(0, query.getFrom());
    assertEquals(100, query.getTo());
    assertEquals(10_000, query.getInterval());
    assertEquals(APPLICATION, query.getQuery());
    assertEquals(ANALYTICS_ROOT_FIELD, query.getRootField());
    assertEquals(APPLICATION, query.getRootIdentifier());
}
Also used : Response(javax.ws.rs.core.Response) CountQuery(io.gravitee.rest.api.model.analytics.query.CountQuery) Test(org.junit.Test)

Example 2 with CountQuery

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

the class EnvironmentAnalyticsResource method executeCount.

private Analytics executeCount(AnalyticsParam analyticsParam, String extraFilter) {
    CountQuery query = new CountQuery();
    query.setFrom(analyticsParam.getFrom());
    query.setTo(analyticsParam.getTo());
    query.setInterval(analyticsParam.getInterval());
    query.setQuery(analyticsParam.getQuery());
    addExtraFilter(query, extraFilter);
    switch(analyticsParam.getField()) {
        case API_FIELD:
            if (isAdmin()) {
                return buildCountStat(apiService.search(new ApiQuery()).size());
            } else {
                return buildCountStat(apiService.findByUser(getAuthenticatedUser(), new ApiQuery(), false).size());
            }
        case APPLICATION_FIELD:
            if (isAdmin()) {
                return buildCountStat(applicationService.findAll().size());
            } else {
                return buildCountStat(applicationService.findByUser(getAuthenticatedUser()).size());
            }
        default:
            return analyticsService.execute(query);
    }
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) CountQuery(io.gravitee.rest.api.model.analytics.query.CountQuery)

Aggregations

CountQuery (io.gravitee.rest.api.model.analytics.query.CountQuery)2 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1