diff options
author | Jacek Poreda <jacek.poreda@sonarsource.com> | 2023-08-10 10:33:25 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-18 20:02:49 +0000 |
commit | 177da8d8b082ad4688524d8f3ecea9bee624d09b (patch) | |
tree | 0923e3ac529b086de0f9d42c0e8f3129e5c6e079 /server/sonar-webserver-es | |
parent | 2b456da715b2650a1519a4d273119b01388396df (diff) | |
download | sonarqube-177da8d8b082ad4688524d8f3ecea9bee624d09b.tar.gz sonarqube-177da8d8b082ad4688524d8f3ecea9bee624d09b.zip |
SONAR-20021 Update Issues web apis with Clean Code Taxonomy
Diffstat (limited to 'server/sonar-webserver-es')
4 files changed, 30 insertions, 25 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java index a8991a87577..f6336ef6eda 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -111,6 +111,7 @@ import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termsQuery; import static org.elasticsearch.search.aggregations.AggregationBuilders.filters; +import static org.elasticsearch.search.aggregations.AggregationBuilders.reverseNested; import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; import static org.sonar.api.rules.RuleType.VULNERABILITY; import static org.sonar.server.es.EsUtils.escapeSpecialRegexChars; @@ -128,6 +129,8 @@ import static org.sonar.server.issue.index.IssueIndex.Facet.CREATED_AT; import static org.sonar.server.issue.index.IssueIndex.Facet.CWE; import static org.sonar.server.issue.index.IssueIndex.Facet.DIRECTORIES; import static org.sonar.server.issue.index.IssueIndex.Facet.FILES; +import static org.sonar.server.issue.index.IssueIndex.Facet.IMPACT_SEVERITY; +import static org.sonar.server.issue.index.IssueIndex.Facet.IMPACT_SOFTWARE_QUALITY; import static org.sonar.server.issue.index.IssueIndex.Facet.LANGUAGES; import static org.sonar.server.issue.index.IssueIndex.Facet.OWASP_ASVS_40; import static org.sonar.server.issue.index.IssueIndex.Facet.OWASP_TOP_10; @@ -140,8 +143,6 @@ import static org.sonar.server.issue.index.IssueIndex.Facet.RULES; import static org.sonar.server.issue.index.IssueIndex.Facet.SANS_TOP_25; import static org.sonar.server.issue.index.IssueIndex.Facet.SCOPES; import static org.sonar.server.issue.index.IssueIndex.Facet.SEVERITIES; -import static org.sonar.server.issue.index.IssueIndex.Facet.IMPACT_SOFTWARE_QUALITY; -import static org.sonar.server.issue.index.IssueIndex.Facet.IMPACT_SEVERITY; import static org.sonar.server.issue.index.IssueIndex.Facet.SONARSOURCE_SECURITY; import static org.sonar.server.issue.index.IssueIndex.Facet.STATUSES; import static org.sonar.server.issue.index.IssueIndex.Facet.TAGS; @@ -159,6 +160,9 @@ import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_FILE import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_FUNC_CLOSED_AT; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_FUNC_UPDATED_AT; +import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPACTS; +import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPACT_SEVERITY; +import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPACT_SOFTWARE_QUALITY; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IS_MAIN_BRANCH; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_KEY; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_LANGUAGE; @@ -176,9 +180,6 @@ import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SANS import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SCOPE; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SEVERITY; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SEVERITY_VALUE; -import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPACTS; -import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPACT_SOFTWARE_QUALITY; -import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPACT_SEVERITY; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SQ_SECURITY_CATEGORY; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_STATUS; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_TAGS; @@ -199,6 +200,8 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AT; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CWE; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DIRECTORIES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IMPACT_SEVERITIES; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IMPACT_SOFTWARE_QUALITIES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_LANGUAGES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_ASVS_40; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_TOP_10; @@ -210,8 +213,6 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SANS_TOP_25; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SCOPES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SEVERITIES; -import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SOFTWARE_QUALITIES; -import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SOFTWARE_QUALITIES_SEVERTIIES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SONARSOURCE_SECURITY; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_STATUSES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_TAGS; @@ -255,8 +256,8 @@ public class IssueIndex { public enum Facet { SEVERITIES(PARAM_SEVERITIES, FIELD_ISSUE_SEVERITY, STICKY, Severity.ALL.size()), - IMPACT_SOFTWARE_QUALITY(PARAM_SOFTWARE_QUALITIES, FIELD_ISSUE_IMPACT_SOFTWARE_QUALITY, STICKY, SoftwareQuality.values().length), - IMPACT_SEVERITY(PARAM_SOFTWARE_QUALITIES_SEVERTIIES, FIELD_ISSUE_IMPACT_SEVERITY, STICKY, + IMPACT_SOFTWARE_QUALITY(PARAM_IMPACT_SOFTWARE_QUALITIES, FIELD_ISSUE_IMPACT_SOFTWARE_QUALITY, STICKY, SoftwareQuality.values().length), + IMPACT_SEVERITY(PARAM_IMPACT_SEVERITIES, FIELD_ISSUE_IMPACT_SEVERITY, STICKY, org.sonar.api.issue.impact.Severity.values().length), CLEAN_CODE_ATTRIBUTE_CATEGORY(PARAM_CLEAN_CODE_ATTRIBUTE_CATEGORIES, FIELD_ISSUE_CLEAN_CODE_ATTRIBUTE_CATEGORY, STICKY, CleanCodeAttributeCategory.values().length), STATUSES(PARAM_STATUSES, FIELD_ISSUE_STATUS, STICKY, Issue.STATUSES.size()), @@ -900,7 +901,7 @@ public class IssueIndex { } private static void addImpactSoftwareQualityFacetIfNeeded(SearchOptions options, IssueQuery query, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) { - if (!options.getFacets().contains(PARAM_SOFTWARE_QUALITIES)) { + if (!options.getFacets().contains(PARAM_IMPACT_SOFTWARE_QUALITIES)) { return; } @@ -924,7 +925,7 @@ public class IssueIndex { } private static void addImpactSeverityFacetIfNeeded(SearchOptions options, IssueQuery query, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) { - if (!options.getFacets().contains(PARAM_SOFTWARE_QUALITIES_SEVERTIIES)) { + if (!options.getFacets().contains(PARAM_IMPACT_SEVERITIES)) { return; } @@ -942,8 +943,9 @@ public class IssueIndex { IMPACT_SEVERITY.getName(), IMPACT_SEVERITY.getTopAggregationDef(), NO_EXTRA_FILTER, t -> t.subAggregation(AggregationBuilders.nested("nested_" + IMPACT_SEVERITY.getName(), FIELD_ISSUE_IMPACTS) - .subAggregation(filters(IMPACT_SEVERITY.getName(), - keyedFilters)))); + .subAggregation(filters(IMPACT_SEVERITY.getName(), keyedFilters) + // we want to count the number of issues for each severity, so we need to reverse the nested aggregation + .subAggregation(reverseNested("reverse_nested_" + IMPACT_SOFTWARE_QUALITY.getName()))))); esRequest.aggregation(aggregation); } diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java index 11cd3614c1f..33eefc1e188 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java @@ -101,7 +101,7 @@ public class IssueQuery { private final Boolean newCodeOnReference; private final Collection<String> newCodeOnReferenceByProjectUuids; private final Collection<String> codeVariants; - private Collection<String> cleanCodeAttributesCategories; + private final Collection<String> cleanCodeAttributesCategories; private IssueQuery(Builder builder) { this.issueKeys = defaultCollection(builder.issueKeys); diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index fb2ce21a14a..5386e7c302c 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -122,6 +122,9 @@ public class IssueQueryFactory { IssueQuery.Builder builder = IssueQuery.builder() .issueKeys(request.getIssues()) .severities(request.getSeverities()) + .cleanCodeAttributesCategories(request.getCleanCodeAttributesCategories()) + .impactSoftwareQualities(request.getImpactSoftwareQualities()) + .impactSeverities(request.getImpactSeverities()) .statuses(request.getStatuses()) .resolutions(request.getResolutions()) .resolved(request.getResolved()) diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java index cc9ede60838..1171923de97 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java @@ -671,7 +671,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon { } @Test - public void search_shouldReturnSoftwareQualityFacet() { + public void search_shouldReturnImpactSoftwareQualitiesFacet() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project); @@ -686,14 +686,14 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon { newDoc("I4", project.uuid(), file).setImpacts(Map.of( MAINTAINABILITY, org.sonar.api.issue.impact.Severity.LOW))); - assertThatFacetHasOnly(IssueQuery.builder(), "softwareQualities", + assertThatFacetHasOnly(IssueQuery.builder(), "impactSoftwareQualities", entry("MAINTAINABILITY", 3L), entry("RELIABILITY", 2L), entry("SECURITY", 0L)); } @Test - public void search_whenFilteredOnSeverity_shouldReturnSoftwareQualityFacet() { + public void search_whenFilteredOnSeverity_shouldReturnImpactSoftwareQualitiesFacet() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project); @@ -710,31 +710,31 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon { MAINTAINABILITY, org.sonar.api.issue.impact.Severity.LOW))); assertThatFacetHasOnly(IssueQuery.builder().impactSoftwareQualities(Set.of(MAINTAINABILITY.name())).impactSeverities(Set.of(org.sonar.api.issue.impact.Severity.LOW.name())), - "softwareQualities", + "impactSoftwareQualities", entry("MAINTAINABILITY", 2L), entry("RELIABILITY", 0L), entry("SECURITY", 0L)); - assertThatFacetHasOnly(IssueQuery.builder().impactSeverities(Set.of(Severity.MEDIUM.name())), "softwareQualities", + assertThatFacetHasOnly(IssueQuery.builder().impactSeverities(Set.of(Severity.MEDIUM.name())), "impactSoftwareQualities", entry("MAINTAINABILITY", 0L), entry("RELIABILITY", 1L), entry("SECURITY", 0L)); - assertThatFacetHasOnly(IssueQuery.builder().impactSeverities(Set.of(org.sonar.api.issue.impact.Severity.HIGH.name())), "softwareQualities", + assertThatFacetHasOnly(IssueQuery.builder().impactSeverities(Set.of(org.sonar.api.issue.impact.Severity.HIGH.name())), "impactSoftwareQualities", entry("MAINTAINABILITY", 1L), entry("RELIABILITY", 1L), entry("SECURITY", 0L)); assertThatFacetHasOnly(IssueQuery.builder() .tags(singletonList("my-tag")) - .impactSeverities(Set.of(org.sonar.api.issue.impact.Severity.HIGH.name())), "softwareQualities", + .impactSeverities(Set.of(org.sonar.api.issue.impact.Severity.HIGH.name())), "impactSoftwareQualities", entry("MAINTAINABILITY", 1L), entry("RELIABILITY", 0L), entry("SECURITY", 0L)); } @Test - public void search_shouldReturnSoftwareQualitySeverityFacet() { + public void search_shouldReturnImpactSeverityFacet() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project); @@ -749,14 +749,14 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon { newDoc("I4", project.uuid(), file).setImpacts(Map.of( MAINTAINABILITY, org.sonar.api.issue.impact.Severity.LOW))); - assertThatFacetHasOnly(IssueQuery.builder(), "softwareQualitiesSeverities", + assertThatFacetHasOnly(IssueQuery.builder(), "impactSeverities", entry("HIGH", 2L), entry("MEDIUM", 1L), entry("LOW", 2L)); } @Test - public void search_whenFilteredOnSoftwareQuality_shouldReturnSoftwareQualitySeverityFacet() { + public void search_whenFilteredOnSoftwareQuality_shouldReturnImpactSeverityFacet() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project); @@ -771,7 +771,7 @@ public class IssueIndexFacetsTest extends IssueIndexTestCommon { newDoc("I4", project.uuid(), file).setImpacts(Map.of( MAINTAINABILITY, org.sonar.api.issue.impact.Severity.LOW))); - assertThatFacetHasOnly(IssueQuery.builder().impactSoftwareQualities(Set.of(MAINTAINABILITY.name())), "softwareQualitiesSeverities", + assertThatFacetHasOnly(IssueQuery.builder().impactSoftwareQualities(Set.of(MAINTAINABILITY.name())), "impactSeverities", entry("HIGH", 1L), entry("MEDIUM", 0L), entry("LOW", 2L)); |