aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java24
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java20
-rw-r--r--sonar-ws/src/main/protobuf/ws-components.proto11
3 files changed, 31 insertions, 24 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
index f554345758a..b88c983d00a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
@@ -39,10 +39,10 @@ import org.sonar.server.component.index.ComponentHitsPerQualifier;
import org.sonar.server.component.index.ComponentIndex;
import org.sonar.server.component.index.ComponentIndexQuery;
import org.sonar.server.es.textsearch.ComponentTextSearchFeature;
-import org.sonarqube.ws.WsComponents.Component;
import org.sonarqube.ws.WsComponents.SuggestionsWsResponse;
import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Category;
import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Project;
+import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Suggestion;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Arrays.stream;
@@ -160,36 +160,36 @@ public class SuggestionsAction implements ComponentsWsAction {
.collect(MoreCollectors.uniqueIndex(ComponentDto::uuid));
}
builder
- .addAllSuggestions(toCategoryResponses(componentsPerQualifiers, componentsByUuids, organizationsByUuids, projectsByUuids))
- .addAllOrganizations(toOrganizationResponses(organizationsByUuids))
- .addAllProjects(toProjectResponses(projectsByUuids));
+ .addAllSuggestions(toCategories(componentsPerQualifiers, componentsByUuids, organizationsByUuids, projectsByUuids))
+ .addAllOrganizations(toOrganizations(organizationsByUuids))
+ .addAllProjects(toProjects(projectsByUuids));
}
ofNullable(warning).ifPresent(builder::setWarning);
return builder.build();
}
- private static List<Category> toCategoryResponses(List<ComponentHitsPerQualifier> componentsPerQualifiers, Map<String, ComponentDto> componentsByUuids,
+ private static List<Category> toCategories(List<ComponentHitsPerQualifier> componentsPerQualifiers, Map<String, ComponentDto> componentsByUuids,
Map<String, OrganizationDto> organizationByUuids, Map<String, ComponentDto> projectsByUuids) {
return componentsPerQualifiers.stream().map(qualifier -> {
- List<Component> results = qualifier.getComponentUuids().stream()
+ List<Suggestion> suggestions = qualifier.getComponentUuids().stream()
.map(componentsByUuids::get)
- .map(dto -> dtoToComponent(dto, organizationByUuids, projectsByUuids))
+ .map(dto -> toSuggestion(dto, organizationByUuids, projectsByUuids))
.collect(toList());
return Category.newBuilder()
.setCategory(qualifier.getQualifier())
.setMore(qualifier.getNumberOfFurtherResults())
- .addAllItems(results)
+ .addAllSuggestions(suggestions)
.build();
}).collect(toList());
}
- private static Component dtoToComponent(ComponentDto result, Map<String, OrganizationDto> organizationByUuid, Map<String, ComponentDto> projectsByUuids) {
+ private static Suggestion toSuggestion(ComponentDto result, Map<String, OrganizationDto> organizationByUuid, Map<String, ComponentDto> projectsByUuids) {
String organizationKey = organizationByUuid.get(result.getOrganizationUuid()).getKey();
checkState(organizationKey != null, "Organization with uuid '%s' not found", result.getOrganizationUuid());
String projectKey = ofNullable(result.projectUuid()).map(projectsByUuids::get).map(ComponentDto::getKey).orElse("");
- return Component.newBuilder()
+ return Suggestion.newBuilder()
.setOrganization(organizationKey)
.setProject(projectKey)
.setKey(result.getKey())
@@ -197,7 +197,7 @@ public class SuggestionsAction implements ComponentsWsAction {
.build();
}
- private static List<Organization> toOrganizationResponses(Map<String, OrganizationDto> organizationByUuids) {
+ private static List<Organization> toOrganizations(Map<String, OrganizationDto> organizationByUuids) {
return organizationByUuids.values().stream()
.map(o -> Organization.newBuilder()
.setKey(o.getKey())
@@ -206,7 +206,7 @@ public class SuggestionsAction implements ComponentsWsAction {
.collect(Collectors.toList());
}
- private static List<Project> toProjectResponses(Map<String, ComponentDto> projectsByUuids) {
+ private static List<Project> toProjects(Map<String, ComponentDto> projectsByUuids) {
return projectsByUuids.values().stream()
.map(p -> Project.newBuilder()
.setKey(p.key())
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
index 533c94a4a41..b249bb62486 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
@@ -43,9 +43,9 @@ import org.sonar.server.permission.index.PermissionIndexerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
-import org.sonarqube.ws.WsComponents.Component;
import org.sonarqube.ws.WsComponents.SuggestionsWsResponse;
import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Project;
+import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Suggestion;
import static java.util.Optional.ofNullable;
import static java.util.stream.IntStream.range;
@@ -111,14 +111,14 @@ public class SuggestionsActionTest {
// assert match in qualifier "TRK"
assertThat(response.getSuggestionsList())
- .filteredOn(q -> q.getItemsCount() > 0)
+ .filteredOn(q -> q.getSuggestionsCount() > 0)
.extracting(Category::getCategory)
.containsExactly(Qualifiers.PROJECT);
// assert correct id to be found
assertThat(response.getSuggestionsList())
- .flatExtracting(Category::getItemsList)
- .extracting(Component::getKey, Component::getOrganization)
+ .flatExtracting(Category::getSuggestionsList)
+ .extracting(Suggestion::getKey, Suggestion::getOrganization)
.containsExactly(tuple(project.getKey(), organization.getKey()));
}
@@ -134,7 +134,7 @@ public class SuggestionsActionTest {
.setParam(PARAM_QUERY, "S o")
.executeProtobuf(SuggestionsWsResponse.class);
- assertThat(response.getSuggestionsList()).filteredOn(q -> q.getItemsCount() > 0).isEmpty();
+ assertThat(response.getSuggestionsList()).filteredOn(q -> q.getSuggestionsCount() > 0).isEmpty();
assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING);
}
@@ -187,8 +187,8 @@ public class SuggestionsActionTest {
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getSuggestionsList())
- .flatExtracting(Category::getItemsList)
- .extracting(Component::getProject)
+ .flatExtracting(Category::getSuggestionsList)
+ .extracting(Suggestion::getProject)
.containsOnly(project.key());
assertThat(response.getProjectsList())
@@ -236,18 +236,18 @@ public class SuggestionsActionTest {
// assert match in qualifier "TRK"
assertThat(response.getSuggestionsList())
- .filteredOn(q -> q.getItemsCount() > 0)
+ .filteredOn(q -> q.getSuggestionsCount() > 0)
.extracting(Category::getCategory)
.containsExactly(Qualifiers.PROJECT);
// include limited number of results in the response
assertThat(response.getSuggestionsList())
- .flatExtracting(Category::getItemsList)
+ .flatExtracting(Category::getSuggestionsList)
.hasSize(Math.min(results, numberOfProjects));
// indicate, that there are more results
assertThat(response.getSuggestionsList())
- .filteredOn(q -> q.getItemsCount() > 0)
+ .filteredOn(q -> q.getSuggestionsCount() > 0)
.extracting(Category::getMore)
.containsExactly(numberOfMoreResults);
}
diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto
index cd480edc5a0..638d7193592 100644
--- a/sonar-ws/src/main/protobuf/ws-components.proto
+++ b/sonar-ws/src/main/protobuf/ws-components.proto
@@ -55,10 +55,18 @@ message SuggestionsWsResponse {
message Category {
optional string category = 1;
- repeated Component items = 2;
+ repeated Suggestion suggestions = 2;
optional int64 more = 3;
}
+ message Suggestion {
+ optional string key = 1;
+ optional string name = 2;
+ optional string match = 3;
+ optional string organization = 4;
+ optional string project = 5;
+ }
+
message Organization {
optional string key = 1;
optional string name = 2;
@@ -83,7 +91,6 @@ message Component {
optional string key = 2;
optional string refId = 3;
optional string refKey = 4;
- optional string project = 15;
optional string projectId = 5;
optional string name = 6;
optional string description = 7;