use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter in project sonarqube by SonarSource.
the class IssueIndex method processSecurityReportCategorySearchResults.
private static SecurityStandardCategoryStatistics processSecurityReportCategorySearchResults(HasAggregations categoryBucket, String categoryName, @Nullable List<SecurityStandardCategoryStatistics> children) {
List<? extends Terms.Bucket> severityBuckets = ((ParsedStringTerms) ((ParsedFilter) categoryBucket.getAggregations().get(AGG_VULNERABILITIES)).getAggregations().get(AGG_SEVERITIES)).getBuckets();
long vulnerabilities = severityBuckets.stream().mapToLong(b -> ((ParsedValueCount) b.getAggregations().get(AGG_COUNT)).getValue()).sum();
// Worst severity having at least one issue
OptionalInt severityRating = severityBuckets.stream().filter(b -> ((ParsedValueCount) b.getAggregations().get(AGG_COUNT)).getValue() != 0).mapToInt(b -> Severity.ALL.indexOf(b.getKeyAsString()) + 1).max();
long toReviewSecurityHotspots = ((ParsedValueCount) ((ParsedFilter) categoryBucket.getAggregations().get(AGG_TO_REVIEW_SECURITY_HOTSPOTS)).getAggregations().get(AGG_COUNT)).getValue();
long reviewedSecurityHotspots = ((ParsedValueCount) ((ParsedFilter) categoryBucket.getAggregations().get(AGG_REVIEWED_SECURITY_HOTSPOTS)).getAggregations().get(AGG_COUNT)).getValue();
Optional<Double> percent = computePercent(toReviewSecurityHotspots, reviewedSecurityHotspots);
Integer securityReviewRating = computeRating(percent.orElse(null)).getIndex();
return new SecurityStandardCategoryStatistics(categoryName, vulnerabilities, severityRating, toReviewSecurityHotspots, reviewedSecurityHotspots, securityReviewRating, children);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter in project sonarqube by SonarSource.
the class IssueIndex method searchProjectStatistics.
public List<ProjectStatistics> searchProjectStatistics(List<String> projectUuids, List<Long> froms, @Nullable String assigneeUuid) {
checkState(projectUuids.size() == froms.size(), "Expected same size for projectUuids (had size %s) and froms (had size %s)", projectUuids.size(), froms.size());
if (projectUuids.isEmpty()) {
return Collections.emptyList();
}
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(boolQuery().mustNot(existsQuery(FIELD_ISSUE_RESOLUTION)).filter(termQuery(FIELD_ISSUE_ASSIGNEE_UUID, assigneeUuid)).mustNot(termQuery(FIELD_ISSUE_TYPE, SECURITY_HOTSPOT.name()))).size(0);
IntStream.range(0, projectUuids.size()).forEach(i -> {
String projectUuid = projectUuids.get(i);
long from = froms.get(i);
sourceBuilder.aggregation(AggregationBuilders.filter(projectUuid, boolQuery().filter(termQuery(FIELD_ISSUE_PROJECT_UUID, projectUuid)).filter(rangeQuery(FIELD_ISSUE_FUNC_CREATED_AT).gte(epochMillisToEpochSeconds(from)))).subAggregation(AggregationBuilders.terms("branchUuid").field(FIELD_ISSUE_BRANCH_UUID).subAggregation(AggregationBuilders.count(AGG_COUNT).field(FIELD_ISSUE_KEY)).subAggregation(AggregationBuilders.max("maxFuncCreatedAt").field(FIELD_ISSUE_FUNC_CREATED_AT))));
});
SearchRequest requestBuilder = EsClient.prepareSearch(TYPE_ISSUE.getMainType());
requestBuilder.source(sourceBuilder);
SearchResponse response = client.search(requestBuilder);
return response.getAggregations().asList().stream().map(x -> (ParsedFilter) x).flatMap(projectBucket -> ((ParsedStringTerms) projectBucket.getAggregations().get("branchUuid")).getBuckets().stream().flatMap(branchBucket -> {
long count = ((ParsedValueCount) branchBucket.getAggregations().get(AGG_COUNT)).getValue();
if (count < 1L) {
return Stream.empty();
}
long lastIssueDate = (long) ((ParsedMax) branchBucket.getAggregations().get("maxFuncCreatedAt")).getValue();
return Stream.of(new ProjectStatistics(branchBucket.getKeyAsString(), count, lastIssueDate));
})).collect(MoreCollectors.toList(projectUuids.size()));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter in project sonarqube by SonarSource.
the class IssueIndex method processSecurityReportSearchResults.
private List<SecurityStandardCategoryStatistics> processSecurityReportSearchResults(SearchSourceBuilder sourceBuilder, boolean includeCwe) {
SearchRequest request = EsClient.prepareSearch(TYPE_ISSUE.getMainType()).source(sourceBuilder);
SearchResponse response = client.search(request);
return response.getAggregations().asList().stream().map(c -> processSecurityReportIssueSearchResults((ParsedFilter) c, includeCwe)).collect(MoreCollectors.toList());
}
Aggregations