Browse Source

SONAR-9073 reverted renaming of atts and values in suggestions api

tags/6.4-RC1
Daniel Schwarz 7 years ago
parent
commit
6100566c07

+ 9
- 11
server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionCategory.java View File

@@ -25,23 +25,21 @@ import org.sonar.api.resources.Qualifiers;
import static java.util.Arrays.stream;

public enum SuggestionCategory {
VIEW("views", Qualifiers.VIEW),
SUBVIEW("sub-views", Qualifiers.SUBVIEW),
PROJECT("projects", Qualifiers.PROJECT),
MODULE("modules", Qualifiers.MODULE),
FILE("files", Qualifiers.FILE),
UNIT_TEST_FILE("unit-test-files", Qualifiers.UNIT_TEST_FILE),;

private final String name;
VIEW(Qualifiers.VIEW),
SUBVIEW(Qualifiers.SUBVIEW),
PROJECT(Qualifiers.PROJECT),
MODULE(Qualifiers.MODULE),
FILE(Qualifiers.FILE),
UNIT_TEST_FILE(Qualifiers.UNIT_TEST_FILE),;

private final String qualifier;

SuggestionCategory(String name, String qualifier) {
this.name = name;
SuggestionCategory(String qualifier) {
this.qualifier = qualifier;
}

public String getName() {
return name;
return qualifier;
}

public String getQualifier() {

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java View File

@@ -194,7 +194,7 @@ public class SuggestionsAction implements ComponentsWsAction {
.collect(MoreCollectors.uniqueIndex(ComponentDto::uuid));
}
builder
.addAllSuggestions(toCategories(componentsPerQualifiers, recentlyBrowsedKeys, favoriteKeys, componentsByUuids, organizationsByUuids, projectsByUuids))
.addAllResults(toCategories(componentsPerQualifiers, recentlyBrowsedKeys, favoriteKeys, componentsByUuids, organizationsByUuids, projectsByUuids))
.addAllOrganizations(toOrganizations(organizationsByUuids))
.addAllProjects(toProjects(projectsByUuids));
}
@@ -211,9 +211,9 @@ public class SuggestionsAction implements ComponentsWsAction {
.collect(toList());

return Category.newBuilder()
.setCategory(qualifier.getQualifier())
.setQ(qualifier.getQualifier())
.setMore(qualifier.getNumberOfFurtherResults())
.addAllSuggestions(suggestions)
.addAllItems(suggestions)
.build();
}).collect(toList());
}

+ 19
- 19
server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java View File

@@ -124,14 +124,14 @@ public class SuggestionsActionTest {
.executeProtobuf(SuggestionsWsResponse.class);

// assert match in qualifier "TRK"
assertThat(response.getSuggestionsList())
.filteredOn(q -> q.getSuggestionsCount() > 0)
.extracting(Category::getCategory)
assertThat(response.getResultsList())
.filteredOn(q -> q.getItemsCount() > 0)
.extracting(Category::getQ)
.containsExactly(Qualifiers.PROJECT);

// assert correct id to be found
assertThat(response.getSuggestionsList())
.flatExtracting(Category::getSuggestionsList)
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getOrganization)
.containsExactly(tuple(project.getKey(), organization.getKey()));
}
@@ -148,7 +148,7 @@ public class SuggestionsActionTest {
.setParam(PARAM_QUERY, "S o")
.executeProtobuf(SuggestionsWsResponse.class);

assertThat(response.getSuggestionsList()).filteredOn(q -> q.getSuggestionsCount() > 0).isEmpty();
assertThat(response.getResultsList()).filteredOn(q -> q.getItemsCount() > 0).isEmpty();
assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING);
}

@@ -200,8 +200,8 @@ public class SuggestionsActionTest {
.setParam(PARAM_QUERY, "Module")
.executeProtobuf(SuggestionsWsResponse.class);

assertThat(response.getSuggestionsList())
.flatExtracting(Category::getSuggestionsList)
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getProject)
.containsOnly(project.key());

@@ -227,8 +227,8 @@ public class SuggestionsActionTest {
.setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getKey()).collect(joining(",")))
.executeProtobuf(SuggestionsWsResponse.class);

assertThat(response.getSuggestionsList())
.flatExtracting(Category::getSuggestionsList)
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getIsRecentlyBrowsed)
.containsExactly(true, false);
}
@@ -250,8 +250,8 @@ public class SuggestionsActionTest {
.setParam(PARAM_QUERY, "Module")
.executeProtobuf(SuggestionsWsResponse.class);

assertThat(response.getSuggestionsList())
.flatExtracting(Category::getSuggestionsList)
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getIsFavorite)
.containsExactly(tuple(favorite.getKey(), true), tuple(nonFavorite.getKey(), false));
}
@@ -294,19 +294,19 @@ public class SuggestionsActionTest {
.executeProtobuf(SuggestionsWsResponse.class);

// assert match in qualifier "TRK"
assertThat(response.getSuggestionsList())
.filteredOn(q -> q.getSuggestionsCount() > 0)
.extracting(Category::getCategory)
assertThat(response.getResultsList())
.filteredOn(q -> q.getItemsCount() > 0)
.extracting(Category::getQ)
.containsExactly(Qualifiers.PROJECT);

// include limited number of results in the response
assertThat(response.getSuggestionsList())
.flatExtracting(Category::getSuggestionsList)
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.hasSize(Math.min(results, numberOfProjects));

// indicate, that there are more results
assertThat(response.getSuggestionsList())
.filteredOn(q -> q.getSuggestionsCount() > 0)
assertThat(response.getResultsList())
.filteredOn(q -> q.getItemsCount() > 0)
.extracting(Category::getMore)
.containsExactly(numberOfMoreResults);
}

+ 3
- 3
sonar-ws/src/main/protobuf/ws-components.proto View File

@@ -48,14 +48,14 @@ message ShowWsResponse {

// WS api/components/suggestions
message SuggestionsWsResponse {
repeated Category suggestions = 1;
repeated Category results = 1;
optional string warning = 2;
repeated Organization organizations = 3;
repeated Project projects = 4;

message Category {
optional string category = 1;
repeated Suggestion suggestions = 2;
optional string q = 1;
repeated Suggestion items = 2;
optional int64 more = 3;
}


Loading…
Cancel
Save