default:
throw new IllegalStateException("Unknown component tree strategy");
}
- Map<Long, String> referenceComponentUuidsById = searchReferenceComponentUuidsById(dbSession, components);
+ Map<Long, ComponentDto> referenceComponentUuidsById = searchReferenceComponentUuidsById(dbSession, components);
return buildResponse(baseComponent, components, referenceComponentUuidsById,
Paging.forPageIndex(query.getPage()).withPageSize(query.getPageSize()).andTotal(total));
}
}
- private Map<Long, String> searchReferenceComponentUuidsById(DbSession dbSession, List<ComponentDtoWithSnapshotId> components) {
+ private Map<Long, ComponentDto> searchReferenceComponentUuidsById(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;
}
}
- private static TreeWsResponse buildResponse(ComponentDto baseComponent, List<ComponentDtoWithSnapshotId> components, Map<Long, String> referenceComponentUuidsById,
- Paging paging) {
+ private static TreeWsResponse buildResponse(ComponentDto baseComponent, List<ComponentDtoWithSnapshotId> components, Map<Long, ComponentDto> referenceComponentsById,
+ Paging paging) {
TreeWsResponse.Builder response = TreeWsResponse.newBuilder();
response.getPagingBuilder()
.setPageIndex(paging.pageIndex())
.setTotal(paging.total())
.build();
- response.setBaseComponent(componentDtoToWsComponent(baseComponent, referenceComponentUuidsById));
+ response.setBaseComponent(componentDtoToWsComponent(baseComponent, referenceComponentsById));
for (ComponentDto dto : components) {
- response.addComponents(componentDtoToWsComponent(dto, referenceComponentUuidsById));
+ response.addComponents(componentDtoToWsComponent(dto, referenceComponentsById));
}
return response.build();
}
- private static WsComponents.Component.Builder componentDtoToWsComponent(ComponentDto dto, Map<Long, String> referenceComponentUuidsById) {
- WsComponents.Component.Builder wsComponent = WsComponents.Component.newBuilder()
- .setId(dto.uuid())
- .setKey(dto.key())
- .setName(dto.name())
- .setQualifier(dto.qualifier());
- if (dto.path() != null) {
- wsComponent.setPath(dto.path());
- }
- if (dto.description() != null) {
- wsComponent.setDescription(dto.description());
- }
- if (!referenceComponentUuidsById.isEmpty() && referenceComponentUuidsById.get(dto.getCopyResourceId()) != null) {
- wsComponent.setRefId(referenceComponentUuidsById.get(dto.getCopyResourceId()));
- }
-
- return wsComponent;
- }
-
private static TreeWsResponse emptyResponse(ComponentDto baseComponent, TreeWsRequest request) {
TreeWsResponse.Builder response = TreeWsResponse.newBuilder();
response.getPagingBuilder()
.setTotal(0)
.setPageIndex(request.getPage())
.setPageSize(request.getPageSize());
- response.setBaseComponent(componentDtoToWsComponent(baseComponent, Collections.<Long, String>emptyMap()));
+ response.setBaseComponent(componentDtoToWsComponent(baseComponent, Collections.<Long, ComponentDto>emptyMap()));
return response.build();
}
+ private static WsComponents.Component.Builder componentDtoToWsComponent(ComponentDto component, Map<Long, ComponentDto> referenceComponentsById) {
+ WsComponents.Component.Builder wsComponent = WsComponents.Component.newBuilder()
+ .setId(component.uuid())
+ .setKey(component.key())
+ .setName(component.name())
+ .setQualifier(component.qualifier());
+ if (component.path() != null) {
+ wsComponent.setPath(component.path());
+ }
+ if (component.description() != null) {
+ wsComponent.setDescription(component.description());
+ }
+ ComponentDto referenceComponent = referenceComponentsById.get(component.getCopyResourceId());
+ if (!referenceComponentsById.isEmpty() && referenceComponent != null) {
+ wsComponent.setRefId(referenceComponent.uuid());
+ wsComponent.setRefKey(referenceComponent.key());
+ }
+
+ return wsComponent;
+ }
+
private ComponentTreeQuery toComponentTreeQuery(TreeWsRequest request, SnapshotDto baseSnapshot) {
List<String> childrenQualifiers = childrenQualifiers(request, baseSnapshot.getQualifier());
message Component {
optional string id = 1;
- optional string refId = 2;
- optional string key = 3;
- optional string projectId = 4;
- optional string name = 5;
- optional string description = 6;
- optional string qualifier = 7;
- optional string path = 8;
- optional string language = 9;
- optional Measures measures = 10;
+ optional string key = 2;
+ optional string refId = 3;
+ optional string refKey = 4;
+ optional string projectId = 5;
+ optional string name = 6;
+ optional string description = 7;
+ optional string qualifier = 8;
+ optional string path = 9;
+ optional string language = 10;
+ optional Measures measures = 11;
}
message Period {