use of org.sonar.api.rule.Severity 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);
}
Aggregations