aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-es/src/main
diff options
context:
space:
mode:
authorDejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-08-14 12:03:22 +0200
committersonartech <sonartech@sonarsource.com>2024-08-26 20:03:06 +0000
commitfc0739fd4eaf7a467de77773be76ddbb5f8040ef (patch)
tree466d0bc4725038ae206318d8e89ff4fb4bcb8b2d /server/sonar-webserver-es/src/main
parent9324868e5ad6264744afd9f5a5ea7555ab2de65b (diff)
downloadsonarqube-fc0739fd4eaf7a467de77773be76ddbb5f8040ef.tar.gz
sonarqube-fc0739fd4eaf7a467de77773be76ddbb5f8040ef.zip
SONAR-22727 index software qualitiy measure to project measures
Co-authored-by: Léo Geoffroy <leo.geoffroy@sonarsource.com>
Diffstat (limited to 'server/sonar-webserver-es/src/main')
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java49
1 files changed, 39 insertions, 10 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
index 5e33203b4bd..9d6344f96e2 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
@@ -21,6 +21,7 @@ package org.sonar.server.measure.index;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -103,6 +104,14 @@ import static org.sonar.api.measures.CoreMetrics.SECURITY_HOTSPOTS_REVIEWED_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_REVIEW_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_RATING_KEY;
+import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY;
import static org.sonar.server.es.EsUtils.escapeSpecialRegexChars;
import static org.sonar.server.es.EsUtils.termsToMap;
import static org.sonar.server.es.IndexType.FIELD_INDEX_TYPE;
@@ -154,6 +163,8 @@ public class ProjectMeasuresIndex {
NEW_DUPLICATED_LINES_DENSITY(new RangeWithNoDataMeasureFacet(NEW_DUPLICATED_LINES_DENSITY_KEY, DUPLICATIONS_THRESHOLDS)),
COVERAGE(new RangeWithNoDataMeasureFacet(COVERAGE_KEY, COVERAGE_THRESHOLDS)),
NEW_COVERAGE(new RangeWithNoDataMeasureFacet(NEW_COVERAGE_KEY, COVERAGE_THRESHOLDS)),
+
+ //RuleType ratings
SQALE_RATING(new RatingMeasureFacet(SQALE_RATING_KEY)),
NEW_MAINTAINABILITY_RATING(new RatingMeasureFacet(NEW_MAINTAINABILITY_RATING_KEY)),
RELIABILITY_RATING(new RatingMeasureFacet(RELIABILITY_RATING_KEY)),
@@ -162,6 +173,17 @@ public class ProjectMeasuresIndex {
NEW_SECURITY_RATING(new RatingMeasureFacet(NEW_SECURITY_RATING_KEY)),
SECURITY_REVIEW_RATING(new RatingMeasureFacet(SECURITY_REVIEW_RATING_KEY)),
NEW_SECURITY_REVIEW_RATING(new RatingMeasureFacet(NEW_SECURITY_REVIEW_RATING_KEY)),
+
+ //Software quality ratings
+ SOFTWARE_QUALITY_MAINTAINABILITY_RATING(new RatingMeasureFacet(SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, 4)),
+ NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING(new RatingMeasureFacet(NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, 4)),
+ SOFTWARE_QUALITY_RELIABILITY_RATING(new RatingMeasureFacet(SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, 4)),
+ NEW_SOFTWARE_QUALITY_RELIABILITY_RATING(new RatingMeasureFacet(NEW_SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, 4)),
+ SOFTWARE_QUALITY_SECURITY_RATING(new RatingMeasureFacet(SOFTWARE_QUALITY_SECURITY_RATING_KEY, 4)),
+ NEW_SOFTWARE_QUALITY_SECURITY_RATING(new RatingMeasureFacet(NEW_SOFTWARE_QUALITY_SECURITY_RATING_KEY, 4)),
+ SOFTWARE_QUALITY_SECURITY_REVIEW_RATING(new RatingMeasureFacet(SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, 4)),
+ NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING(new RatingMeasureFacet(NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, 4)),
+
SECURITY_HOTSPOTS_REVIEWED(new RangeMeasureFacet(SECURITY_HOTSPOTS_REVIEWED_KEY, SECURITY_REVIEW_RATING_THRESHOLDS)),
NEW_SECURITY_HOTSPOTS_REVIEWED(new RangeMeasureFacet(NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, SECURITY_REVIEW_RATING_THRESHOLDS)),
ALERT_STATUS(new MeasureFacet(ALERT_STATUS_KEY, ProjectMeasuresIndex::buildAlertStatusFacet)),
@@ -566,14 +588,20 @@ public class ProjectMeasuresIndex {
private static class RatingMeasureFacet extends MeasureFacet {
private RatingMeasureFacet(String metricKey) {
- super(metricKey, new MetricRatingFacetBuilder(metricKey));
+ super(metricKey, new MetricRatingFacetBuilder(metricKey, 5));
+ }
+
+ private RatingMeasureFacet(String metricKey, int maxRating) {
+ super(metricKey, new MetricRatingFacetBuilder(metricKey, maxRating));
}
private static class MetricRatingFacetBuilder implements FacetBuilder {
private final String metricKey;
+ private final int maxRating;
- private MetricRatingFacetBuilder(String metricKey) {
+ private MetricRatingFacetBuilder(String metricKey, int maxRating) {
this.metricKey = metricKey;
+ this.maxRating = maxRating;
}
@Override
@@ -581,19 +609,20 @@ public class ProjectMeasuresIndex {
return topAggregationHelper.buildTopAggregation(
facet.getName(), facet.getTopAggregationDef(),
NO_EXTRA_FILTER,
- t -> t.subAggregation(createMeasureRatingFacet(metricKey)));
+ t -> t.subAggregation(createMeasureRatingFacet(metricKey, maxRating)));
}
- private static AbstractAggregationBuilder<?> createMeasureRatingFacet(String metricKey) {
+ private static AbstractAggregationBuilder<?> createMeasureRatingFacet(String metricKey, int maxRating) {
+ List<KeyedFilter> filter = new ArrayList<>();
+ for (int i = 1; i <= maxRating; i++) {
+ filter.add(new KeyedFilter(String.valueOf(i), termQuery(FIELD_MEASURES_MEASURE_VALUE, Double.valueOf(i))));
+ }
+
return AggregationBuilders.nested("nested_" + metricKey, FIELD_MEASURES)
.subAggregation(
AggregationBuilders.filter("filter_" + metricKey, termsQuery(FIELD_MEASURES_MEASURE_KEY, metricKey))
- .subAggregation(filters(metricKey,
- new KeyedFilter("1", termQuery(FIELD_MEASURES_MEASURE_VALUE, 1D)),
- new KeyedFilter("2", termQuery(FIELD_MEASURES_MEASURE_VALUE, 2D)),
- new KeyedFilter("3", termQuery(FIELD_MEASURES_MEASURE_VALUE, 3D)),
- new KeyedFilter("4", termQuery(FIELD_MEASURES_MEASURE_VALUE, 4D)),
- new KeyedFilter("5", termQuery(FIELD_MEASURES_MEASURE_VALUE, 5D)))));
+ .subAggregation(filters(metricKey, filter.toArray(new KeyedFilter[0])
+ )));
}
}
}