From 77f34d207b904879912fc912fbbcaa7b6b4e965c Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 3 Feb 2020 15:12:00 +0100 Subject: [PATCH] SONAR-12961 add facets for: security_hotspots_reviewed, security_review_rating --- .../ProjectMeasuresIndexerIterator.java | 2 + .../index/ProjectMeasuresIndexTest.java | 43 ++++++++++++++++++- .../measure/index/ProjectMeasuresIndex.java | 8 ++++ .../ws/SearchProjectsActionTest.java | 5 ++- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java index a67aa5854b9..3c814651ab9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java @@ -59,6 +59,8 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator=30% and <50% + newDoc(SECURITY_HOTSPOTS_REVIEWED, 30), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 49), + // 4 docs with >=50% and <70% + newDoc(SECURITY_HOTSPOTS_REVIEWED, 50), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 60), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 61), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 69), + // 2 docs with >=70% and <80% + newDoc(SECURITY_HOTSPOTS_REVIEWED, 70), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 79), + // 5 docs with duplication>= 80% + newDoc(SECURITY_HOTSPOTS_REVIEWED, 80), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 90), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 93), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 99), + newDoc(SECURITY_HOTSPOTS_REVIEWED, 100)); + + Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_HOTSPOTS_REVIEWED)).getFacets(); + assertThat(facets.get(SECURITY_HOTSPOTS_REVIEWED)).containsExactly( + entry("*-30.0", 3L), + entry("30.0-50.0", 2L), + entry("50.0-70.0", 4L), + entry("70.0-80.0", 2L), + entry("80.0-*", 5L)); + } + @Test public void filter_on_quality_gate_status() { index( 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 79f5f9db187..8e8d6791e5f 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 @@ -84,7 +84,9 @@ import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY; +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.server.es.EsUtils.escapeSpecialRegexChars; import static org.sonar.server.es.EsUtils.termsToMap; @@ -122,12 +124,15 @@ public class ProjectMeasuresIndex { NEW_RELIABILITY_RATING_KEY, SECURITY_RATING_KEY, NEW_SECURITY_RATING_KEY, + SECURITY_REVIEW_RATING_KEY, + SECURITY_HOTSPOTS_REVIEWED_KEY, ALERT_STATUS_KEY, FILTER_LANGUAGES, FILTER_TAGS); private static final Double[] LINES_THRESHOLDS = new Double[] {1_000d, 10_000d, 100_000d, 500_000d}; private static final Double[] COVERAGE_THRESHOLDS = new Double[] {30d, 50d, 70d, 80d}; + private static final Double[] SECURITY_REVIEW_RATING_THRESHOLDS = new Double[] {30D, 50D, 70D, 80D}; private static final Double[] DUPLICATIONS_THRESHOLDS = new Double[] {3d, 5d, 10d, 20d}; private static final String FIELD_MEASURES_KEY = FIELD_MEASURES + "." + ProjectMeasuresIndexDefinition.FIELD_MEASURES_KEY; @@ -150,6 +155,9 @@ public class ProjectMeasuresIndex { .put(NEW_RELIABILITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, NEW_RELIABILITY_RATING_KEY, facetBuilder)) .put(SECURITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, SECURITY_RATING_KEY, facetBuilder)) .put(NEW_SECURITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, NEW_SECURITY_RATING_KEY, facetBuilder)) + .put(SECURITY_REVIEW_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, SECURITY_REVIEW_RATING_KEY, facetBuilder)) + .put(SECURITY_HOTSPOTS_REVIEWED_KEY, + (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, SECURITY_HOTSPOTS_REVIEWED_KEY, facetBuilder, SECURITY_REVIEW_RATING_THRESHOLDS)) .put(ALERT_STATUS_KEY, (esSearch, query, facetBuilder) -> esSearch.addAggregation(createStickyFacet(ALERT_STATUS_KEY, facetBuilder, createQualityGateFacet(query)))) .put(FILTER_LANGUAGES, ProjectMeasuresIndex::addLanguagesFacet) .put(FIELD_TAGS, ProjectMeasuresIndex::addTagsFacet) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 857ee247684..445850a4f51 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -170,6 +170,8 @@ public class SearchProjectsActionTest { "lines", "new_lines", "security_rating", + "security_review_rating", + "security_hotspots_reviewed", "new_reliability_rating", "new_coverage", "new_security_rating", @@ -192,7 +194,8 @@ public class SearchProjectsActionTest { Param facets = def.param("facets"); assertThat(facets.defaultValue()).isNull(); assertThat(facets.possibleValues()).containsOnly("ncloc", "duplicated_lines_density", "coverage", "sqale_rating", "reliability_rating", "security_rating", "alert_status", - "languages", "tags", "new_reliability_rating", "new_security_rating", "new_maintainability_rating", "new_coverage", "new_duplicated_lines_density", "new_lines"); + "languages", "tags", "new_reliability_rating", "new_security_rating", "new_maintainability_rating", "new_coverage", "new_duplicated_lines_density", "new_lines", + "security_review_rating", "security_hotspots_reviewed"); } @Test -- 2.39.5