use of io.gravitee.repository.analytics.AnalyticsException in project gravitee-management-rest-api by gravitee-io.
the class AnalyticsServiceImpl method execute.
@Override
public TopHitsAnalytics execute(GroupByQuery query) {
try {
GroupByQueryBuilder queryBuilder = QueryBuilders.groupBy().query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root(query.getRootField(), query.getRootIdentifier()).field(query.getField());
if (query.getGroups() != null) {
query.getGroups().forEach(queryBuilder::range);
}
if (query.getOrder() != null) {
GroupByQuery.Order order = query.getOrder();
queryBuilder.sort(SortBuilder.on(order.getField(), order.isOrder() ? Order.ASC : Order.DESC, (order.getType() == null) ? SortType.AVG : SortType.valueOf(order.getType().toUpperCase())));
}
GroupByResponse response = analyticsRepository.query(queryBuilder.build());
return convert(response);
} catch (AnalyticsException ae) {
logger.error("Unable to calculate analytics: ", ae);
throw new TechnicalManagementException("Unable to calculate analytics", ae);
}
}
use of io.gravitee.repository.analytics.AnalyticsException in project gravitee-management-rest-api by gravitee-io.
the class AnalyticsServiceImpl method execute.
@Override
public HistogramAnalytics execute(DateHistogramQuery query) {
try {
DateHistogramQueryBuilder queryBuilder = QueryBuilders.dateHistogram().query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root(query.getRootField(), query.getRootIdentifier());
if (query.getAggregations() != null) {
query.getAggregations().stream().forEach(aggregation -> queryBuilder.aggregation(AggregationType.valueOf(aggregation.type().name()), aggregation.field()));
}
DateHistogramResponse response = analyticsRepository.query(queryBuilder.build());
return convert(response);
} catch (AnalyticsException ae) {
logger.error("Unable to calculate analytics: ", ae);
throw new TechnicalManagementException("Unable to calculate analytics", ae);
}
}
use of io.gravitee.repository.analytics.AnalyticsException 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);
}
}
use of io.gravitee.repository.analytics.AnalyticsException 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);
}
}
Aggregations