From 061165a76b9efa2956c23188e50d114d6cda3e02 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 15 Jan 2016 11:55:27 +0100 Subject: [PATCH] SONAR-7135 WS api/measures/component_tree parameterized periods in a measure --- .../measure/ws/MeasureDtoToWsMeasure.java | 27 ++--- .../measure/ws/component_tree-example.json | 110 +++++++++++++----- .../server/component/ws/SearchActionTest.java | 2 +- .../measure/ws/ComponentTreeActionTest.java | 2 - .../db/component/ComponentTreeQuery.java | 6 +- sonar-ws/src/main/protobuf/ws-measures.proto | 11 +- 6 files changed, 103 insertions(+), 55 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java index bd405520624..a4070fe6bda 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java @@ -23,8 +23,8 @@ import org.sonar.db.measure.MeasureDto; import org.sonar.db.metric.MetricDto; import org.sonarqube.ws.WsMeasures; -import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue; import static org.sonar.server.measure.ws.MeasureValueFormatter.formatMeasureValue; +import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue; class MeasureDtoToWsMeasure { @@ -37,23 +37,18 @@ class MeasureDtoToWsMeasure { measure.setMetric(metricDto.getKey()); // a measure value can be null, new_violations metric for example if (measureDto.getValue() != null - || measureDto.getData()!=null) { + || measureDto.getData() != null) { measure.setValue(formatMeasureValue(measureDto, metricDto)); } - if (measureDto.getVariation(1) != null) { - measure.setVariationValueP1(formatNumericalValue(measureDto.getVariation(1), metricDto)); - } - if (measureDto.getVariation(2) != null) { - measure.setVariationValueP2(formatNumericalValue(measureDto.getVariation(2), metricDto)); - } - if (measureDto.getVariation(3) != null) { - measure.setVariationValueP3(formatNumericalValue(measureDto.getVariation(3), metricDto)); - } - if (measureDto.getVariation(4) != null) { - measure.setVariationValueP4(formatNumericalValue(measureDto.getVariation(4), metricDto)); - } - if (measureDto.getVariation(5) != null) { - measure.setVariationValueP5(formatNumericalValue(measureDto.getVariation(5), metricDto)); + + WsMeasures.PeriodValue.Builder periodBuilder = WsMeasures.PeriodValue.newBuilder(); + for (int i = 1; i <= 5; i++) { + if (measureDto.getVariation(i) != null) { + measure.addPeriods(periodBuilder + .clear() + .setIndex(i) + .setValue(formatNumericalValue(measureDto.getVariation(i), metricDto))); + } } return measure.build(); diff --git a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json index 46d75e0884a..9c22d862ac9 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json @@ -12,17 +12,30 @@ "measures": [ { "metric": "new_violations", - "variationValueP1": "255", - "variationValueP2": "0", - "variationValueP3": "255" + "periods": [ + { + "index": 1, + "value": "255" + }, + { + "index": 2, + "value": "0" + }, + { + "index": 3, + "value": "255" + } + ] }, { - "metric": "ncloc", - "value": "1984" + "metric": "complexity", + "value": "42", + "periods": [] }, { - "metric": "complexity", - "value": "42" + "metric": "ncloc", + "value": "1984", + "periods": [] } ] }, @@ -36,17 +49,30 @@ "measures": [ { "metric": "new_violations", - "variationValueP1": "25", - "variationValueP2": "0", - "variationValueP3": "25" + "periods": [ + { + "index": 1, + "value": "25" + }, + { + "index": 2, + "value": "0" + }, + { + "index": 3, + "value": "25" + } + ] }, { - "metric": "ncloc", - "value": "114" + "metric": "complexity", + "value": "12", + "periods": [] }, { - "metric": "complexity", - "value": "12" + "metric": "ncloc", + "value": "114", + "periods": [] } ] }, @@ -59,9 +85,20 @@ "measures": [ { "metric": "new_violations", - "variationValueP1": "0", - "variationValueP2": "0", - "variationValueP3": "0" + "periods": [ + { + "index": 1, + "value": "0" + }, + { + "index": 2, + "value": "0" + }, + { + "index": 3, + "value": "0" + } + ] } ] }, @@ -72,21 +109,42 @@ "qualifier": "DIR", "path": "src/main/java/com/sonarsource/markdown/impl", "measures": [ - { - "metric": "ncloc", - "value": "217", - "variationValueP2": "0" - }, { "metric": "new_violations", - "variationValueP1": "25", - "variationValueP2": "0", - "variationValueP3": "25" + "periods": [ + { + "index": 1, + "value": "25" + }, + { + "index": 2, + "value": "0" + }, + { + "index": 3, + "value": "25" + } + ] }, { "metric": "complexity", "value": "35", - "variationValueP2": "0" + "periods": [ + { + "index": 2, + "value": "0" + } + ] + }, + { + "metric": "ncloc", + "value": "217", + "periods": [ + { + "index": 2, + "value": "0" + } + ] } ] } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 48a80deb61b..18d4694a9e6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -141,7 +141,7 @@ public class SearchActionTest { db.commit(); InputStream responseStream = newRequest(Qualifiers.PROJECT) - .setParam(Param.TEXT_QUERY, "project-_%") + .setParam(Param.TEXT_QUERY, "project-_%-key") .execute().getInputStream(); SearchWsResponse response = SearchWsResponse.parseFrom(responseStream); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index e0ebbe0740b..b666b72f79a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -161,8 +161,6 @@ public class ComponentTreeActionTest { List fileMeasures = response.getComponentsList().get(1).getMeasures().getMeasuresList(); assertThat(fileMeasures).extracting("metric").containsOnly("ncloc", "coverage"); assertThat(fileMeasures).extracting("value").containsOnly("5", "15.5"); - assertThat(fileMeasures).extracting("variationValueP1").containsOnly("", "4"); - assertThat(fileMeasures).extracting("variationValueP3").containsOnly("", "2.0"); assertThat(response.getPeriods().getPeriodsList()).extracting("mode").containsOnly("last_version", "last_analysis"); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java index c462231c9b7..6292b94c36e 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java @@ -63,6 +63,7 @@ public class ComponentTreeQuery { return qualifiers; } + @CheckForNull public String getNameOrKeyQuery() { return nameOrKeyQuery; } @@ -72,11 +73,6 @@ public class ComponentTreeQuery { return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, AFTER).toLowerCase(); } - @CheckForNull - public String getNameOrKeyQueryToSqlForProjectKey() { - return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, AFTER); - } - public Integer getPage() { return page; } diff --git a/sonar-ws/src/main/protobuf/ws-measures.proto b/sonar-ws/src/main/protobuf/ws-measures.proto index 395484609a2..5217936392c 100644 --- a/sonar-ws/src/main/protobuf/ws-measures.proto +++ b/sonar-ws/src/main/protobuf/ws-measures.proto @@ -70,9 +70,10 @@ message Measures { message Measure { optional string metric = 1; optional string value = 2; - optional string variationValueP1 = 3; - optional string variationValueP2 = 4; - optional string variationValueP3 = 5; - optional string variationValueP4 = 6; - optional string variationValueP5 = 7; + repeated PeriodValue periods = 3; +} + +message PeriodValue { + optional int32 index = 1; + optional string value = 2; } -- 2.39.5