Search in sources :

Example 1 with TabularResponse

use of io.gravitee.repository.analytics.query.tabular.TabularResponse in project gravitee-management-rest-api by gravitee-io.

the class LogsServiceImpl method findByApplication.

@Override
public SearchLogResponse findByApplication(String application, LogQuery query) {
    try {
        TabularResponse response = logRepository.query(QueryBuilders.tabular().page(query.getPage()).size(query.getSize()).query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root("application", application).build());
        SearchLogResponse<ApplicationRequestItem> logResponse = new SearchLogResponse<>(response.getSize());
        // Transform repository logs
        logResponse.setLogs(response.getLogs().stream().map(this::toApplicationRequestItem).collect(Collectors.toList()));
        // Add metadata (only if they are results)
        if (response.getSize() > 0) {
            Map<String, Map<String, String>> metadata = new HashMap<>();
            logResponse.getLogs().forEach(logItem -> {
                String api = logItem.getApi();
                String plan = logItem.getPlan();
                if (api != null) {
                    metadata.computeIfAbsent(api, getAPIMetadata(api));
                }
                if (plan != null) {
                    metadata.computeIfAbsent(plan, getPlanMetadata(plan));
                }
            });
            logResponse.setMetadata(metadata);
        }
        return logResponse;
    } catch (AnalyticsException ae) {
        logger.error("Unable to retrieve logs: ", ae);
        throw new TechnicalManagementException("Unable to retrieve logs", ae);
    }
}
Also used : TabularResponse(io.gravitee.repository.analytics.query.tabular.TabularResponse) HashMap(java.util.HashMap) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) HashMap(java.util.HashMap) Map(java.util.Map) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 2 with TabularResponse

use of io.gravitee.repository.analytics.query.tabular.TabularResponse in project gravitee-management-rest-api by gravitee-io.

the class LogsServiceImpl method findByApi.

@Override
public SearchLogResponse findByApi(String api, LogQuery query) {
    try {
        TabularResponse response = logRepository.query(QueryBuilders.tabular().page(query.getPage()).size(query.getSize()).query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root("api", api).build());
        SearchLogResponse<ApiRequestItem> logResponse = new SearchLogResponse<>(response.getSize());
        // Transform repository logs
        logResponse.setLogs(response.getLogs().stream().map(this::toApiRequestItem).collect(Collectors.toList()));
        // Add metadata (only if they are results)
        if (response.getSize() > 0) {
            Map<String, Map<String, String>> metadata = new HashMap<>();
            logResponse.getLogs().forEach(logItem -> {
                String application = logItem.getApplication();
                String plan = logItem.getPlan();
                if (application != null) {
                    metadata.computeIfAbsent(application, getApplicationMetadata(application));
                }
                if (plan != null) {
                    metadata.computeIfAbsent(plan, getPlanMetadata(plan));
                }
            });
            logResponse.setMetadata(metadata);
        }
        return logResponse;
    } catch (AnalyticsException ae) {
        logger.error("Unable to retrieve logs: ", ae);
        throw new TechnicalManagementException("Unable to retrieve logs", ae);
    }
}
Also used : TabularResponse(io.gravitee.repository.analytics.query.tabular.TabularResponse) HashMap(java.util.HashMap) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) HashMap(java.util.HashMap) Map(java.util.Map) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)2 AnalyticsException (io.gravitee.repository.analytics.AnalyticsException)2 TabularResponse (io.gravitee.repository.analytics.query.tabular.TabularResponse)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2