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);
}
}
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);
}
}
Aggregations