}
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()) {
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)) {
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;
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;
}
@CheckForNull
- public Map<Long, String> getReferenceComponentUuidsById() {
- return referenceComponentUuidsById;
+ public Map<Long, ComponentDto> getReferenceComponentsById() {
+ return referenceComponentsById;
}
@CheckForNull
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;
return this;
}
- public Builder setReferenceComponentUuidsById(Map<Long, String> referenceComponentsById) {
- this.referenceComponentUuidsById = referenceComponentsById;
+ public Builder setReferenceComponentsById(Map<Long, ComponentDto> referenceComponentsById) {
+ this.referenceComponentsById = referenceComponentsById;
return this;
}
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)
.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())
}
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;
@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);
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