]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7135 WS api/measures/component_tree baseComponent has measures
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 14 Jan 2016 17:48:30 +0000 (18:48 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 14 Jan 2016 17:53:45 +0000 (18:53 +0100)
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.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/measure/ws/ComponentTreeActionTest.java

index e13cc234ffca5f3c91a272d698359eaf4a4e72ad..77d88aca13199e144ce23e4292c6e029ea5e3e23 100644 (file)
@@ -173,7 +173,11 @@ public class ComponentTreeAction implements MeasuresWsAction {
       .setTotal(paging.total())
       .build();
 
-    response.setBaseComponent(componentDtoToWsComponent(data.getBaseComponent()));
+    response.setBaseComponent(
+      componentDtoToWsComponent(
+        data.getBaseComponent(),
+        data.getMeasuresByComponentUuidAndMetric().row(data.getBaseComponent().uuid()),
+        data.getReferenceComponentUuidsById()));
 
     for (ComponentDto componentDto : data.getComponents()) {
       response.addComponents(componentDtoToWsComponent(
index 176db2a75b9eb3dbe4c0de6ee7770983b952b3e9..e05441ac0ab93cadbd07a5dac6aa12a2234f73f8 100644 (file)
@@ -106,7 +106,8 @@ public class ComponentTreeDataLoader {
       int componentCount = componentDtosAndTotal.total;
       List<MetricDto> metrics = searchMetrics(dbSession, wsRequest);
       List<WsMeasures.Period> periods = periodsFromSnapshot(baseSnapshot);
-      Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, components, metrics, periods);
+      Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, baseSnapshot, components, metrics,
+        periods);
 
       components = sortComponents(components, wsRequest, metrics, measuresByComponentUuidAndMetric);
       components = paginateComponents(components, componentCount, wsRequest);
@@ -174,9 +175,14 @@ public class ComponentTreeDataLoader {
     return metrics;
   }
 
-  private Table<String, MetricDto, MeasureDto> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, List<ComponentDtoWithSnapshotId> components, List<MetricDto> metrics,
+  private Table<String, MetricDto, MeasureDto> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, SnapshotDto baseSnapshot,
+    List<ComponentDtoWithSnapshotId> components, List<MetricDto> metrics,
     List<WsMeasures.Period> periods) {
-    Map<Long, ComponentDtoWithSnapshotId> componentsBySnapshotId = Maps.uniqueIndex(components, ComponentDtoWithSnapshotIdToSnapshotIdFunction.INSTANCE);
+    Map<Long, ComponentDto> componentsBySnapshotId = new HashMap<>();
+    componentsBySnapshotId.put(baseSnapshot.getId(), baseComponent);
+    for (ComponentDtoWithSnapshotId component : components) {
+      componentsBySnapshotId.put(component.getSnapshotId(), component);
+    }
 
     Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDtoFunctions.toId());
     List<MeasureDto> measureDtos = dbClient.measureDao().selectBySnapshotIdsAndMetricIds(dbSession,
index 1db85e0e61d7230497dbe958257e06f9dc1f6292..46d75e0884a8629480b3cebd661fece86c5f1363 100644 (file)
@@ -8,7 +8,23 @@
     "id": "project-id",
     "key": "MY_PROJECT",
     "name": "My Project",
-    "qualifier": "TRK"
+    "qualifier": "TRK",
+    "measures": [
+      {
+        "metric": "new_violations",
+        "variationValueP1": "255",
+        "variationValueP2": "0",
+        "variationValueP3": "255"
+      },
+      {
+        "metric": "ncloc",
+        "value": "1984"
+      },
+      {
+        "metric": "complexity",
+        "value": "42"
+      }
+    ]
   },
   "components": [
     {
@@ -43,7 +59,6 @@
       "measures": [
         {
           "metric": "new_violations",
-          "value": "0",
           "variationValueP1": "0",
           "variationValueP2": "0",
           "variationValueP3": "0"
index a89f3e8a78ba7ccedb04450e3fd6e9cc2dd3c657..e0ebbe0740b1c497fdf710c19e3d2244ece2ea1c 100644 (file)
@@ -405,7 +405,9 @@ public class ComponentTreeActionTest {
         .setValue(12.0d),
       newMeasureDto(complexity, directorySnapshot.getId())
         .setValue(35.0d)
-        .setVariation(2, 0.0d));
+        .setVariation(2, 0.0d),
+      newMeasureDto(complexity, projectSnapshot.getId())
+        .setValue(42.0d));
 
     MetricDto ncloc = insertNclocMetric();
     dbClient.measureDao().insert(dbSession,
@@ -413,7 +415,9 @@ public class ComponentTreeActionTest {
         .setValue(114.0d),
       newMeasureDto(ncloc, directorySnapshot.getId())
         .setValue(217.0d)
-        .setVariation(2, 0.0d));
+        .setVariation(2, 0.0d),
+      newMeasureDto(ncloc, projectSnapshot.getId())
+        .setValue(1984.0d));
 
     MetricDto newViolations = insertNewViolationsMetric();
     dbClient.measureDao().insert(dbSession,
@@ -422,14 +426,17 @@ public class ComponentTreeActionTest {
         .setVariation(2, 0.0d)
         .setVariation(3, 25.0d),
       newMeasureDto(newViolations, file2Snapshot.getId())
-        .setValue(0.0d)
         .setVariation(1, 0.0d)
         .setVariation(2, 0.0d)
         .setVariation(3, 0.0d),
       newMeasureDto(newViolations, directorySnapshot.getId())
         .setVariation(1, 25.0d)
         .setVariation(2, 0.0d)
-        .setVariation(3, 25.0d));
+        .setVariation(3, 25.0d),
+      newMeasureDto(newViolations, projectSnapshot.getId())
+        .setVariation(1, 255.0d)
+        .setVariation(2, 0.0d)
+        .setVariation(3, 255.0d));
 
     db.commit();
   }