aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-06-26 16:57:38 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-06-26 16:57:38 +0200
commit11e082fab82637141908cef3801eb95ef8d13ba4 (patch)
tree18bfedbeb3c6229cb7ee91c196458446211bc6fa
parent568ac968c81d2e5b29fbb427c40637fdde207f6c (diff)
downloadsonarqube-11e082fab82637141908cef3801eb95ef8d13ba4.tar.gz
sonarqube-11e082fab82637141908cef3801eb95ef8d13ba4.zip
Use MetricJsonWriter in the metrics/search WS
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/metric/ws/SearchAction.java36
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java5
2 files changed, 3 insertions, 38 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/SearchAction.java
index 75248f3eef6..21485fc738a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/SearchAction.java
@@ -115,40 +115,6 @@ public class SearchAction implements MetricsWsAction {
}
public static void writeMetrics(JsonWriter json, List<MetricDto> metrics, Set<String> desiredFields) {
- json.name("metrics");
- json.beginArray();
- for (MetricDto metric : metrics) {
- json.beginObject();
- json.prop(FIELD_ID, String.valueOf(metric.getId()));
- json.prop(FIELD_KEY, metric.getKey());
- writeIfDesired(json, FIELD_TYPE, metric.getValueType(), desiredFields);
- writeIfDesired(json, FIELD_NAME, metric.getShortName(), desiredFields);
- writeIfDesired(json, FIELD_DESCRIPTION, metric.getDescription(), desiredFields);
- writeIfDesired(json, FIELD_DOMAIN, metric.getDomain(), desiredFields);
- writeIfDesired(json, FIELD_DIRECTION, metric.getDirection(), desiredFields);
- writeIfDesired(json, FIELD_QUALITATIVE, metric.isQualitative(), desiredFields);
- writeIfDesired(json, FIELD_HIDDEN, metric.isHidden(), desiredFields);
- writeIfDesired(json, FIELD_CUSTOM, metric.isUserManaged(), desiredFields);
- json.endObject();
- }
- json.endArray();
- }
-
- private static void writeIfDesired(JsonWriter json, String field, String value, Set<String> desiredFields) {
- if (desiredFields.contains(field)) {
- json.prop(field, value);
- }
- }
-
- private static void writeIfDesired(JsonWriter json, String field, int value, Set<String> desiredFields) {
- if (desiredFields.contains(field)) {
- json.prop(field, value);
- }
- }
-
- private static void writeIfDesired(JsonWriter json, String field, boolean value, Set<String> desiredFields) {
- if (desiredFields.contains(field)) {
- json.prop(field, value);
- }
+ MetricJsonWriter.write(json, metrics, desiredFields);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
index 5f433b649f9..c2206fc99cc 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
@@ -126,10 +126,9 @@ public class SearchActionTest {
String result = newRequest().setParam(Param.FIELDS, "name").execute().outputAsString();
- assertThat(result).contains("id", "key", "name")
+ assertThat(result).contains("id", "key", "name", "type")
.doesNotContain("domain")
- .doesNotContain("description")
- .doesNotContain("type");
+ .doesNotContain("description");
}
private void insertNewNonCustomMetric(String... ids) {