]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7135 WS api/measures/component_tree parameterized periods in a measure
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 15 Jan 2016 10:55:27 +0000 (11:55 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 15 Jan 2016 11:02:55 +0000 (12:02 +0100)
server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
sonar-ws/src/main/protobuf/ws-measures.proto

index bd40552062441ed67750e78805aee43d311483e5..a4070fe6bda94203ce0ec13e5c582aec70c4779b 100644 (file)
@@ -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();
index 46d75e0884a8629480b3cebd661fece86c5f1363..9c22d862ac9533e2a5545bd45471e158631bf5f0 100644 (file)
     "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": []
       }
     ]
   },
       "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": []
         }
       ]
     },
       "measures": [
         {
           "metric": "new_violations",
-          "variationValueP1": "0",
-          "variationValueP2": "0",
-          "variationValueP3": "0"
+          "periods": [
+            {
+              "index": 1,
+              "value": "0"
+            },
+            {
+              "index": 2,
+              "value": "0"
+            },
+            {
+              "index": 3,
+              "value": "0"
+            }
+          ]
         }
       ]
     },
       "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"
+            }
+          ]
         }
       ]
     }
index 48a80deb61b0ee735e997894af98c810b3bc90cd..18d4694a9e62bd49925bc9e56a29169dc63d2371 100644 (file)
@@ -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);
 
index e0ebbe0740b1c497fdf710c19e3d2244ece2ea1c..b666b72f79af075b7d77e49ecf972ae7e009ee52 100644 (file)
@@ -161,8 +161,6 @@ public class ComponentTreeActionTest {
     List<WsMeasures.Measure> 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");
   }
 
index c462231c9b7836ae7f52ee3fdfc3e48d7df28f1a..6292b94c36e0b2b743bcb74e77319aff4642eea9 100644 (file)
@@ -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;
   }
index 395484609a23b6a3d41db95ec6f50261e90d97c1..5217936392c5b4408b841bbb58a386fe42a7fccd 100644 (file)
@@ -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;
 }