private List<MetricDto> searchMetrics(DbSession dbSession, ComponentTreeWsRequest request) { List<String> metricKeys = requireNonNull(request.getMetricKeys()); List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, metricKeys); if (metrics.size() < metricKeys.size()) { List<String> foundMetricKeys = Lists.transform(metrics, MetricDtoFunctions.toKey()); Set<String> missingMetricKeys = Sets.difference(new LinkedHashSet<>(metricKeys), new LinkedHashSet<>(foundMetricKeys)); throw new NotFoundException( format( "The following metric keys are not found: %s", Joiner.on(", ").join(missingMetricKeys))); } return metrics; }