aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi
diff options
context:
space:
mode:
authorDejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-03-08 09:44:33 +0100
committersonartech <sonartech@sonarsource.com>2024-03-08 20:02:34 +0000
commite64df27ae07319d522cb2c486c1031674ae91b23 (patch)
treead07cbf7c927c1d8e2ee86154d5905ef87549511 /server/sonar-webserver-webapi
parentc0dae13e030edba13bf325e852ad858a8c44b0c0 (diff)
downloadsonarqube-e64df27ae07319d522cb2c486c1031674ae91b23.tar.gz
sonarqube-e64df27ae07319d522cb2c486c1031674ae91b23.zip
SONAR-21770 Add new accepted values for the 'metricKeys'
'maintainability_issues', 'reliability_issues', 'security_issues'
Diffstat (limited to 'server/sonar-webserver-webapi')
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java134
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java38
2 files changed, 119 insertions, 53 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
index 25db2bb768b..00535396b66 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
@@ -22,8 +22,8 @@ package org.sonar.server.measure.ws;
import com.google.common.base.Joiner;
import java.util.List;
import java.util.stream.IntStream;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.ResourceTypeTree;
import org.sonar.api.resources.ResourceTypes;
@@ -59,7 +59,11 @@ import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
+import static org.sonar.api.measures.CoreMetrics.MAINTAINABILITY_ISSUES_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY;
+import static org.sonar.api.measures.CoreMetrics.RELIABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.SECURITY_ISSUES_KEY;
+import static org.sonar.api.measures.Metric.ValueType.DATA;
import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
import static org.sonar.api.measures.Metric.ValueType.FLOAT;
import static org.sonar.api.measures.Metric.ValueType.INT;
@@ -97,11 +101,11 @@ import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.Measures.Component;
import static org.sonarqube.ws.Measures.Measure;
-public class ComponentTreeActionIT {
- @Rule
- public UserSessionRule userSession = UserSessionRule.standalone().logIn();
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+class ComponentTreeActionIT {
+ @RegisterExtension
+ private final UserSessionRule userSession = UserSessionRule.standalone().logIn();
+ @RegisterExtension
+ private final DbTester db = DbTester.create(System2.INSTANCE);
private final I18nRule i18n = new I18nRule();
@@ -120,7 +124,7 @@ public class ComponentTreeActionIT {
i18n, resourceTypes));
@Test
- public void json_example() {
+ void json_example() {
ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT")
.setName("My Project"));
ComponentDto mainBranch = projectData.getMainBranchComponent();
@@ -185,7 +189,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void shouldReturnRenamedMetric() {
+ void shouldReturnRenamedMetric() {
ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT")
.setName("My Project"));
addProjectPermission(projectData);
@@ -210,7 +214,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void empty_response() {
+ void empty_response() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -227,7 +231,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void load_measures_and_periods() {
+ void load_measures_and_periods() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession,
newAnalysis(mainBranch)
@@ -261,7 +265,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void load_measures_with_best_value() {
+ void load_measures_with_best_value() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
userSession.anonymous().addProjectPermission(USER, mainBranch);
@@ -307,7 +311,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void return_is_best_value_on_leak_measures() {
+ void return_is_best_value_on_leak_measures() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
userSession.anonymous().addProjectPermission(USER, mainBranch);
@@ -349,7 +353,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void use_best_value_for_rating() {
+ void use_best_value_for_rating() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
userSession.anonymous().addProjectPermission(USER, mainBranch);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch)
@@ -383,7 +387,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void load_measures_multi_sort_with_metric_key_and_paginated() {
+ void load_measures_multi_sort_with_metric_key_and_paginated() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -427,7 +431,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void sort_by_metric_value() {
+ void sort_by_metric_value() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -455,7 +459,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void remove_components_without_measure_on_the_metric_sort() {
+ void remove_components_without_measure_on_the_metric_sort() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -490,7 +494,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void sort_by_metric_period() {
+ void sort_by_metric_period() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -517,7 +521,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void remove_components_without_measure_on_the_metric_period_sort() {
+ void remove_components_without_measure_on_the_metric_period_sort() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -548,7 +552,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void load_measures_when_no_leave_qualifier() {
+ void load_measures_when_no_leave_qualifier() {
resourceTypes.setLeavesQualifiers();
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
@@ -568,7 +572,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void branch() {
+ void branch() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -594,7 +598,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void dont_show_branch_if_main_branch() {
+ void dont_show_branch_if_main_branch() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -612,7 +616,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void show_branch_on_empty_response_if_not_main_branch() {
+ void show_branch_on_empty_response_if_not_main_branch() {
ComponentDto mainProjectBranch = db.components().insertPrivateProject().getMainBranchComponent();
userSession.addProjectPermission(USER, mainProjectBranch);
ComponentDto branch = db.components().insertProjectBranch(mainProjectBranch, b -> b.setKey("develop"));
@@ -632,7 +636,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void pull_request() {
+ void pull_request() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -657,7 +661,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void metric_without_a_domain() {
+ void metric_without_a_domain() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -680,7 +684,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void project_reference_from_portfolio() {
+ void project_reference_from_portfolio() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -702,7 +706,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void portfolio_local_reference_in_portfolio() {
+ void portfolio_local_reference_in_portfolio() {
ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("VIEW1-UUID")
.setKey("Apache-Projects").setName("Apache Projects"));
userSession.registerPortfolios(view);
@@ -725,7 +729,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void application_local_reference_in_portfolio() {
+ void application_local_reference_in_portfolio() {
ComponentDto apache_projects = ComponentTesting.newPortfolio("VIEW1-UUID")
.setKey("Apache-Projects").setName("Apache Projects").setPrivate(true);
userSession.addProjectPermission(USER, apache_projects);
@@ -749,7 +753,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void project_branch_reference_from_application_branch() {
+ void project_branch_reference_from_application_branch() {
MetricDto ncloc = insertNclocMetric();
ProjectData applicationData = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key"));
ComponentDto application = applicationData.getMainBranchComponent();
@@ -784,7 +788,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_metric_keys_parameter_is_empty() {
+ void fail_when_metric_keys_parameter_is_empty() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
@@ -799,7 +803,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_a_metric_is_not_found() {
+ void fail_when_a_metric_is_not_found() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -817,7 +821,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_using_DISTRIB_metrics() {
+ void fail_when_using_DISTRIB_metrics() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -837,14 +841,14 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_using_DATA_metrics() {
+ void fail_when_using_unsupported_DATA_metrics() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
db.components().insertSnapshot(mainBranch);
- dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data1").setValueType(DISTRIB.name()));
- dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data2").setValueType(DISTRIB.name()));
+ dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data1").setValueType(DATA.name()));
+ dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data2").setValueType(DATA.name()));
db.commit();
assertThatThrownBy(() -> {
@@ -858,7 +862,37 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_setting_more_than_15_metric_keys() {
+ void execute_whenUsingSupportedDATAMetrics_shouldReturnMetrics() {
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(mainBranch));
+ MetricDto dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(SECURITY_ISSUES_KEY));
+ db.measures().insertLiveMeasure(mainBranch, dataMetric, c -> c.setData(SECURITY_ISSUES_KEY + "_data"));
+ dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(MAINTAINABILITY_ISSUES_KEY));
+ db.measures().insertLiveMeasure(mainBranch, dataMetric, c -> c.setData(MAINTAINABILITY_ISSUES_KEY + "_data"));
+ dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(RELIABILITY_ISSUES_KEY));
+ db.measures().insertLiveMeasure(mainBranch, dataMetric, c -> c.setData(RELIABILITY_ISSUES_KEY + "_data"));
+
+ ComponentTreeWsResponse response = ws.newRequest()
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
+ .setParam(PARAM_METRIC_KEYS, format("%s,%s,%s", SECURITY_ISSUES_KEY, MAINTAINABILITY_ISSUES_KEY, RELIABILITY_ISSUES_KEY))
+ .setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
+ .executeProtobuf(ComponentTreeWsResponse.class);
+
+ assertThat(response.getMetrics().getMetricsList()).size().isEqualTo(3);
+
+ List<Measure> dataMeasures = response.getBaseComponent().getMeasuresList();
+
+ assertThat(dataMeasures)
+ .extracting(Measure::getMetric, Measure::getValue)
+ .containsExactlyInAnyOrder(tuple(SECURITY_ISSUES_KEY, SECURITY_ISSUES_KEY + "_data"),
+ tuple(MAINTAINABILITY_ISSUES_KEY, MAINTAINABILITY_ISSUES_KEY + "_data"),
+ tuple(RELIABILITY_ISSUES_KEY, RELIABILITY_ISSUES_KEY + "_data"));
+ }
+
+ @Test
+ void fail_when_setting_more_than_15_metric_keys() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
List<String> metrics = IntStream.range(0, 20)
@@ -877,7 +911,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_search_query_have_less_than_3_characters() {
+ void fail_when_search_query_have_less_than_3_characters() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
insertNclocMetric();
@@ -895,7 +929,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_insufficient_privileges() {
+ void fail_when_insufficient_privileges() {
userSession.logIn();
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
@@ -908,7 +942,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_app_with_insufficient_privileges_for_projects() {
+ void fail_when_app_with_insufficient_privileges_for_projects() {
userSession.logIn();
ComponentDto app = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
@@ -930,7 +964,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_sort_by_metric_and_no_metric_sort_provided() {
+ void fail_when_sort_by_metric_and_no_metric_sort_provided() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
@@ -947,7 +981,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_sort_by_metric_and_not_in_the_list_of_metric_keys() {
+ void fail_when_sort_by_metric_and_not_in_the_list_of_metric_keys() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
@@ -964,7 +998,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_sort_by_metric_period_and_no_metric_period_sort_provided() {
+ void fail_when_sort_by_metric_period_and_no_metric_period_sort_provided() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
@@ -982,7 +1016,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_paging_parameter_is_too_big() {
+ void fail_when_paging_parameter_is_too_big() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
insertNclocMetric();
@@ -999,7 +1033,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_with_measures_only_and_no_metric_sort() {
+ void fail_when_with_measures_only_and_no_metric_sort() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
insertNclocMetric();
@@ -1016,7 +1050,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_component_does_not_exist() {
+ void fail_when_component_does_not_exist() {
insertNclocMetric();
assertThatThrownBy(() -> {
@@ -1030,7 +1064,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_when_component_is_removed() {
+ void fail_when_component_is_removed() {
ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
db.components().insertSnapshot(mainBranch);
ComponentDto file = db.components().insertComponent(newFileDto(mainBranch).setKey("file-key").setEnabled(false));
@@ -1048,7 +1082,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void fail_if_branch_does_not_exist() {
+ void fail_if_branch_does_not_exist() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
@@ -1067,7 +1101,7 @@ public class ComponentTreeActionIT {
}
@Test
- public void doHandle_whenPassingUnexpectedQualifier_shouldThrowException() {
+ void doHandle_whenPassingUnexpectedQualifier_shouldThrowException() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
addProjectPermission(projectData);
@@ -1091,6 +1125,10 @@ public class ComponentTreeActionIT {
.setOptimizedBestValue(false);
}
+ private static MetricDto newDataMetricDto(String key) {
+ return newMetricDto().setValueType(DATA.name()).setKey(key);
+ }
+
private MetricDto insertNewViolationsMetric() {
MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDto()
.setKey("new_violations")
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
index a888f34e9ae..3749ec2ab0b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
@@ -37,6 +37,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
@@ -77,6 +78,9 @@ import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Optional.ofNullable;
+import static org.sonar.api.measures.CoreMetrics.MAINTAINABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.RELIABILITY_ISSUES_KEY;
+import static org.sonar.api.measures.CoreMetrics.SECURITY_ISSUES_KEY;
import static org.sonar.api.measures.Metric.ValueType.DATA;
import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
import static org.sonar.api.utils.Paging.offset;
@@ -149,7 +153,6 @@ public class ComponentTreeAction implements MeasuresWsAction {
static final String ALL_METRIC_SORT_FILTER = "all";
static final String WITH_MEASURES_ONLY_METRIC_SORT_FILTER = "withMeasuresOnly";
static final Set<String> METRIC_SORT_FILTERS = ImmutableSortedSet.of(ALL_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER);
- static final Set<String> FORBIDDEN_METRIC_TYPES = Set.of(DISTRIB.name(), DATA.name());
private static final int MAX_METRIC_KEYS = 15;
private static final String COMMA_JOIN_SEPARATOR = ", ";
private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = Set.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
@@ -181,10 +184,10 @@ public class ComponentTreeAction implements MeasuresWsAction {
.setHandler(this)
.addPagingParams(100, MAX_SIZE)
.setChangelog(
+ new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'maintainability_issues', 'reliability_issues', 'security_issues'"),
new Change("10.4", String.format("The metrics %s are now deprecated in the response " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
- new Change("10.4", "Added new accepted values for the 'metricKeys' param: 'maintainability_issues', 'reliability_issues', 'security_issues'"),
new Change("10.4", "The metrics 'open_issues', 'reopened_issues' and 'confirmed_issues' are now deprecated in the response. Consume 'violations' instead."),
new Change("10.4", "The use of 'open_issues', 'reopened_issues' and 'confirmed_issues' values in 'metricKeys' param are now deprecated. Use 'violations' instead."),
new Change("10.4", "The metric 'wont_fix_issues' is now deprecated in the response. Consume 'accepted_issues' instead."),
@@ -258,7 +261,10 @@ public class ComponentTreeAction implements MeasuresWsAction {
.setPossibleValues(METRIC_SORT_FILTERS);
createMetricKeysParameter(action)
- .setDescription("Comma-separated list of metric keys. Types %s are not allowed.", String.join(COMMA_JOIN_SEPARATOR, FORBIDDEN_METRIC_TYPES))
+ .setDescription("Comma-separated list of metric keys. Types %s are not allowed. For type %s only %s metrics are supported",
+ String.join(COMMA_JOIN_SEPARATOR, UnsupportedMetrics.FORBIDDEN_METRIC_TYPES),
+ DATA.name(),
+ String.join(COMMA_JOIN_SEPARATOR, UnsupportedMetrics.PARTIALLY_SUPPORTED_METRICS.get(DATA.name())))
.setMaxValuesAllowed(MAX_METRIC_KEYS);
createAdditionalFieldsParameter(action);
createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes));
@@ -290,7 +296,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
request,
data,
Paging.forPageIndex(
- request.getPage())
+ request.getPage())
.withPageSize(request.getPageSize())
.andTotal(data.getComponentCount()),
request.getMetricKeys());
@@ -516,7 +522,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
throw new NotFoundException(format("The following metric keys are not found: %s", String.join(COMMA_JOIN_SEPARATOR, missingMetricKeys)));
}
String forbiddenMetrics = metrics.stream()
- .filter(metric -> ComponentTreeAction.FORBIDDEN_METRIC_TYPES.contains(metric.getValueType()))
+ .filter(UnsupportedMetrics.INSTANCE)
.map(MetricDto::getKey)
.sorted()
.collect(Collectors.joining(COMMA_JOIN_SEPARATOR));
@@ -668,4 +674,26 @@ public class ComponentTreeAction implements MeasuresWsAction {
return new MetricDtoWithBestValue(input);
}
}
+
+ private enum UnsupportedMetrics implements Predicate<MetricDto> {
+ INSTANCE;
+
+ static final Set<String> FORBIDDEN_METRIC_TYPES = Set.of(DISTRIB.name());
+ static final Map<String, Set<String>> PARTIALLY_SUPPORTED_METRICS= Map. of(
+ DATA.name(), Set.of(SECURITY_ISSUES_KEY, MAINTAINABILITY_ISSUES_KEY, RELIABILITY_ISSUES_KEY));
+
+ @Override
+ public boolean test(@Nonnull MetricDto input) {
+ if (FORBIDDEN_METRIC_TYPES.contains(input.getValueType())) {
+ return true;
+ }
+ Set<String> partialSupport = PARTIALLY_SUPPORTED_METRICS.get(input.getValueType());
+ if (partialSupport == null) {
+ return false;
+ } else {
+ return !partialSupport.contains(input.getKey());
+ }
+ }
+ }
+
}