aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-01-20 12:23:09 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-01-20 12:44:43 +0100
commit49632b19154fa95cf68802645defa16027ab6de4 (patch)
tree0dbc9fc7cb0dec55d5828d111cbaa8ece4a65d4e
parent35468c07da8166677e4155a87a912e2352ef241a (diff)
downloadsonarqube-49632b19154fa95cf68802645defa16027ab6de4.tar.gz
sonarqube-49632b19154fa95cf68802645defa16027ab6de4.zip
SONAR-7129 WS api/components/tree return refKey
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java58
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java3
-rw-r--r--sonar-ws/src/main/protobuf/ws-components.proto17
-rw-r--r--sonar-ws/src/main/protobuf/ws-measures.proto19
-rw-r--r--sonar-ws/src/main/protobuf/ws-qualitygates.proto2
5 files changed, 51 insertions, 48 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
index 5fc9911c3b6..0855467bc91 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
@@ -173,7 +173,7 @@ public class TreeAction implements ComponentsWsAction {
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));
@@ -182,7 +182,7 @@ public class TreeAction implements ComponentsWsAction {
}
}
- 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())
@@ -192,9 +192,9 @@ public class TreeAction implements ComponentsWsAction {
}
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;
@@ -209,8 +209,8 @@ public class TreeAction implements ComponentsWsAction {
}
}
- 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())
@@ -218,44 +218,46 @@ public class TreeAction implements ComponentsWsAction {
.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());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
index cc5821ce126..2fe4f1d7669 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
@@ -243,7 +243,7 @@ public class TreeActionTest {
public void direct_children_of_a_view() throws IOException {
ComponentDto view = newView("view-uuid");
SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view);
- ComponentDto project = newProjectDto("project-uuid-1").setName("project-name");
+ ComponentDto project = newProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot);
componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot);
@@ -260,6 +260,7 @@ public class TreeActionTest {
assertThat(response.getComponentsList()).extracting("id").containsExactly("project-uuid-1-copy", "sub-view-uuid");
assertThat(response.getComponentsList()).extracting("refId").containsExactly("project-uuid-1", "");
+ assertThat(response.getComponentsList()).extracting("refKey").containsExactly("project-key-1", "");
}
@Test
diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto
index 9ff36b851a5..128ade44c99 100644
--- a/sonar-ws/src/main/protobuf/ws-components.proto
+++ b/sonar-ws/src/main/protobuf/ws-components.proto
@@ -48,12 +48,13 @@ message ShowWsResponse {
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 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;
}
diff --git a/sonar-ws/src/main/protobuf/ws-measures.proto b/sonar-ws/src/main/protobuf/ws-measures.proto
index 5960ea78943..6014576568f 100644
--- a/sonar-ws/src/main/protobuf/ws-measures.proto
+++ b/sonar-ws/src/main/protobuf/ws-measures.proto
@@ -37,15 +37,16 @@ message ComponentTreeWsResponse {
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 {
diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
index f4669419d86..57e867e767d 100644
--- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto
+++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
@@ -20,8 +20,6 @@ syntax = "proto2";
package sonarqube.ws.qualitygate;
-import "ws-commons.proto";
-
option java_package = "org.sonarqube.ws";
option java_outer_classname = "WsQualityGates";
option optimize_for = SPEED;