]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7135 WS api/measures/component_tree refKey in the response
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 20 Jan 2016 11:38:33 +0000 (12:38 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 20 Jan 2016 11:44:43 +0000 (12:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java

index 5734963a43d120420b2830230fea3142e7b39685..319148d89ea4f3bf237af459513f22294ac9acd4 100644 (file)
@@ -33,11 +33,13 @@ class ComponentDtoToWsComponent {
   }
 
   static WsMeasures.Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, MeasureDto> measuresByMetric,
-    Map<Long, String> referenceComponentUuidsById) {
+    Map<Long, ComponentDto> referenceComponentsById) {
     WsMeasures.Component.Builder wsComponent = componentDtoToWsComponent(component);
 
-    if (!referenceComponentUuidsById.isEmpty() && referenceComponentUuidsById.get(component.getCopyResourceId()) != null) {
-      wsComponent.setRefId(referenceComponentUuidsById.get(component.getCopyResourceId()));
+    ComponentDto referenceComponent = referenceComponentsById.get(component.getCopyResourceId());
+    if (!referenceComponentsById.isEmpty() && referenceComponent != null) {
+      wsComponent.setRefId(referenceComponent.uuid());
+      wsComponent.setRefKey(referenceComponent.key());
     }
 
     for (Map.Entry<MetricDto, MeasureDto> entry : measuresByMetric.entrySet()) {
index 8d4d970807ffae58443fd53b7b78805d475155d0..ca904c0576566bba205a0fb5e2b6500df362b44f 100644 (file)
@@ -194,13 +194,13 @@ public class ComponentTreeAction implements MeasuresWsAction {
       componentDtoToWsComponent(
         data.getBaseComponent(),
         data.getMeasuresByComponentUuidAndMetric().row(data.getBaseComponent().uuid()),
-        data.getReferenceComponentUuidsById()));
+        data.getReferenceComponentsById()));
 
     for (ComponentDto componentDto : data.getComponents()) {
       response.addComponents(componentDtoToWsComponent(
         componentDto,
         data.getMeasuresByComponentUuidAndMetric().row(componentDto.uuid()),
-        data.getReferenceComponentUuidsById()));
+        data.getReferenceComponentsById()));
     }
 
     if (areMetricsInResponse(request)) {
index 79d6fb116ca2066f2884cb4a15b36b56acb18602..7c4505c61bf3a1faaf5b1d65fe5a43ff75c9e221 100644 (file)
@@ -35,7 +35,7 @@ class ComponentTreeData {
   private final ComponentDto baseComponent;
   private final List<ComponentDtoWithSnapshotId> components;
   private final int componentCount;
-  private final Map<Long, String> referenceComponentUuidsById;
+  private final Map<Long, ComponentDto> referenceComponentsById;
   private final List<MetricDto> metrics;
   private final List<WsMeasures.Period> periods;
   private final Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric;
@@ -44,7 +44,7 @@ class ComponentTreeData {
     this.baseComponent = builder.baseComponent;
     this.components = builder.componentsFromDb;
     this.componentCount = builder.componentCount;
-    this.referenceComponentUuidsById = builder.referenceComponentUuidsById;
+    this.referenceComponentsById = builder.referenceComponentsById;
     this.metrics = builder.metrics;
     this.measuresByComponentUuidAndMetric = builder.measuresByComponentUuidAndMetric;
     this.periods = builder.periods;
@@ -65,8 +65,8 @@ class ComponentTreeData {
   }
 
   @CheckForNull
-  public Map<Long, String> getReferenceComponentUuidsById() {
-    return referenceComponentUuidsById;
+  public Map<Long, ComponentDto> getReferenceComponentsById() {
+    return referenceComponentsById;
   }
 
   @CheckForNull
@@ -91,7 +91,7 @@ class ComponentTreeData {
   static class Builder {
     private ComponentDto baseComponent;
     private List<ComponentDtoWithSnapshotId> componentsFromDb;
-    private Map<Long, String> referenceComponentUuidsById;
+    private Map<Long, ComponentDto> referenceComponentsById;
     private int componentCount;
     private List<MetricDto> metrics;
     private List<WsMeasures.Period> periods;
@@ -131,8 +131,8 @@ class ComponentTreeData {
       return this;
     }
 
-    public Builder setReferenceComponentUuidsById(Map<Long, String> referenceComponentsById) {
-      this.referenceComponentUuidsById = referenceComponentsById;
+    public Builder setReferenceComponentsById(Map<Long, ComponentDto> referenceComponentsById) {
+      this.referenceComponentsById = referenceComponentsById;
       return this;
     }
 
index 16154108dfa3415e8903cc0d6b44de4512c4a29b..e73cb8cc1a5848e1dbd8f300a375316559067cb8 100644 (file)
@@ -111,7 +111,7 @@ public class ComponentTreeDataLoader {
 
       components = sortComponents(components, wsRequest, metrics, measuresByComponentUuidAndMetric);
       components = paginateComponents(components, componentCount, wsRequest);
-      Map<Long, String> referenceComponentUuidsById = searchReferenceComponentUuidsById(dbSession, components);
+      Map<Long, ComponentDto> referenceComponentsById = searchReferenceComponentsById(dbSession, components);
 
       return ComponentTreeData.builder()
         .setBaseComponent(baseComponent)
@@ -120,14 +120,14 @@ public class ComponentTreeDataLoader {
         .setMeasuresByComponentUuidAndMetric(measuresByComponentUuidAndMetric)
         .setMetrics(metrics)
         .setPeriods(periods)
-        .setReferenceComponentUuidsById(referenceComponentUuidsById)
+        .setReferenceComponentsById(referenceComponentsById)
         .build();
     } finally {
       dbClient.closeSession(dbSession);
     }
   }
 
-  private Map<Long, String> searchReferenceComponentUuidsById(DbSession dbSession, List<ComponentDtoWithSnapshotId> components) {
+  private Map<Long, ComponentDto> searchReferenceComponentsById(DbSession dbSession, List<ComponentDtoWithSnapshotId> components) {
     List<Long> referenceComponentIds = from(components)
       .transform(ComponentDtoWithSnapshotIdToCopyResourceIdFunction.INSTANCE)
       .filter(Predicates.<Long>notNull())
@@ -137,9 +137,9 @@ public class ComponentTreeDataLoader {
     }
 
     List<ComponentDto> referenceComponents = dbClient.componentDao().selectByIds(dbSession, referenceComponentIds);
-    Map<Long, String> referenceComponentUuidsById = new HashMap<>();
+    Map<Long, ComponentDto> referenceComponentUuidsById = new HashMap<>();
     for (ComponentDto referenceComponent : referenceComponents) {
-      referenceComponentUuidsById.put(referenceComponent.getId(), referenceComponent.uuid());
+      referenceComponentUuidsById.put(referenceComponent.getId(), referenceComponent);
     }
 
     return referenceComponentUuidsById;
index 51ffab6228cd7aad3f93be8c9d6b73aa74824c01..f8d35db0e7cb5ea268dd9d89fae0ed54e7b2bdea 100644 (file)
@@ -270,7 +270,7 @@ public class ComponentTreeActionTest {
   @Test
   public void load_developer_descendants() {
     ComponentDto developer = newDeveloper("developer").setUuid("developer-uuid");
-    ComponentDto project = newProjectDto("project-uuid");
+    ComponentDto project = newProjectDto("project-uuid").setKey("project-key");
     SnapshotDto developerSnapshot = componentDb.insertDeveloperAndSnapshot(developer);
     componentDb.insertProjectAndSnapshot(project);
     componentDb.insertComponentAndSnapshot(newDevProjectCopy("project-uuid-copy", project, developer), developerSnapshot);
@@ -284,6 +284,7 @@ public class ComponentTreeActionTest {
     WsMeasures.Component projectCopy = response.getComponents(0);
     assertThat(projectCopy.getId()).isEqualTo("project-uuid-copy");
     assertThat(projectCopy.getRefId()).isEqualTo("project-uuid");
+    assertThat(projectCopy.getRefKey()).isEqualTo("project-key");
   }
 
   @Test