diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-20 12:38:33 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-20 12:44:43 +0100 |
commit | ec96c3e2c8e33bc40e519a7b9566cfb2e9338b52 (patch) | |
tree | caf1dbc859d5cf6d2a4f05dabcd92521872224a7 | |
parent | 49632b19154fa95cf68802645defa16027ab6de4 (diff) | |
download | sonarqube-ec96c3e2c8e33bc40e519a7b9566cfb2e9338b52.tar.gz sonarqube-ec96c3e2c8e33bc40e519a7b9566cfb2e9338b52.zip |
SONAR-7135 WS api/measures/component_tree refKey in the response
5 files changed, 21 insertions, 18 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java index 5734963a43d..319148d89ea 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java @@ -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()) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index 8d4d970807f..ca904c05765 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -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)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java index 79d6fb116ca..7c4505c61bf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java @@ -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; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java index 16154108dfa..e73cb8cc1a5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java @@ -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; 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 51ffab6228c..f8d35db0e7c 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 @@ -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 |