aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-05-13 13:35:10 +0200
committersonartech <sonartech@sonarsource.com>2020-05-26 20:05:32 +0000
commit21dacef212465e85aff5cec8803536f5f76a5192 (patch)
treeaebb036a938ecdf2034d190ecc375842e7ad062c /server/sonar-webserver-webapi
parent4fc4a5853354a00e80f1e27556385e4338b57cd0 (diff)
downloadsonarqube-21dacef212465e85aff5cec8803536f5f76a5192.tar.gz
sonarqube-21dacef212465e85aff5cec8803536f5f76a5192.zip
SONAR-13291 index components with qualifier ['APP', 'TRK', 'VW', 'SVW'] only in Component ES index
Diffstat (limited to 'server/sonar-webserver-webapi')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json17
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json10
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java46
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java18
6 files changed, 39 insertions, 62 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
index 4d81269850c..54fdab08141 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
@@ -89,8 +89,10 @@ public class SearchAction implements ComponentsWsAction {
.setDescription("Search for components")
.addPagingParams(100, MAX_LIMIT)
.setChangelog(
- new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)),
- new Change("8.0", "Field 'id' from response has been removed"))
+ new Change("8.4", String.format("The use of 'DIR','FIL','UTS' as values for parameter '%s' is no longer supported", PARAM_QUALIFIERS)),
+ new Change("8.0", "Field 'id' from response has been removed"),
+ new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS))
+ )
.setResponseExample(getClass().getResource("search-components-example.json"))
.setHandler(this);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
index 0adc826a924..f570389fc21 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
@@ -119,6 +119,7 @@ public class SuggestionsAction implements ComponentsWsAction {
.setHandler(this)
.setResponseExample(Resources.getResource(this.getClass(), "suggestions-example.json"))
.setChangelog(
+ new Change("8.4", String.format("The use of 'DIR', 'FIL','UTS' as values for parameter '%s' is no longer supported", PARAM_MORE)),
new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE)));
action.createParam(PARAM_QUERY)
@@ -259,6 +260,9 @@ public class SuggestionsAction implements ComponentsWsAction {
Set<String> availableQualifiers = resourceTypes.getAll().stream()
.map(ResourceType::getQualifier)
.filter(q -> !q.equals(Qualifiers.MODULE))
+ .filter(q -> !q.equals(Qualifiers.DIRECTORY))
+ .filter(q -> !q.equals(Qualifiers.FILE))
+ .filter(q -> !q.equals(Qualifiers.UNIT_TEST_FILE))
.collect(MoreCollectors.toSet());
if (more == null) {
return stream(SuggestionCategory.values())
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json
index 0eb71aa1f14..641a8c7152d 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json
@@ -2,26 +2,11 @@
"paging": {
"pageIndex": 1,
"pageSize": 100,
- "total": 3
+ "total": 1
},
"components": [
{
"organization": "my-org-1",
- "key": "directory-key",
- "qualifier": "DIR",
- "name": "Directory Name",
- "project": "project-key"
- },
- {
- "organization": "my-org-1",
- "key": "file-key",
- "qualifier": "FIL",
- "name": "File Name",
- "language": "java",
- "project": "project-key"
- },
- {
- "organization": "my-org-1",
"key": "project-key",
"qualifier": "TRK",
"name": "Project Name",
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json
index 48a24e137b7..18e95da7cda 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json
@@ -38,16 +38,6 @@
}
],
"more": 0
- },
- {
- "q": "FIL",
- "items": [],
- "more": 0
- },
- {
- "q": "UTS",
- "items": [],
- "more": 0
}
],
"organizations": [
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
index c8a9f8664d9..8692d26d4b3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
@@ -120,8 +120,9 @@ public class SearchActionTest {
assertThat(action.changelog())
.extracting(Change::getVersion, Change::getDescription)
.containsExactlyInAnyOrder(
- tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"),
- tuple("8.0", "Field 'id' from response has been removed"));
+ tuple("8.4", "The use of 'DIR','FIL','UTS' as values for parameter 'qualifiers' is no longer supported"),
+ tuple("8.0", "Field 'id' from response has been removed"),
+ tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"));
assertThat(action.responseExampleAsString()).isNotEmpty();
assertThat(action.params()).hasSize(6);
@@ -155,7 +156,7 @@ public class SearchActionTest {
}
@Test
- public void search_for_files() {
+ public void returns_empty_result_when_search_for_files() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
ComponentDto file1 = newFileDto(project).setDbKey("file1");
ComponentDto file2 = newFileDto(project).setDbKey("file2");
@@ -164,7 +165,7 @@ public class SearchActionTest {
SearchWsResponse response = call(new SearchRequest().setQuery(file1.getDbKey()).setQualifiers(singletonList(FILE)));
- assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(file1.getDbKey());
+ assertThat(response.getComponentsList()).isEmpty();
}
@Test
@@ -194,40 +195,35 @@ public class SearchActionTest {
}
@Test
- public void return_only_components_from_projects_on_which_user_has_browse_permission() {
+ public void return_only_projects_on_which_user_has_browse_permission() {
ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto file1 = newFileDto(project1).setDbKey("file1");
- ComponentDto file2 = newFileDto(project1).setDbKey("file2");
ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto file3 = newFileDto(project2).setDbKey("file3");
- db.components().insertComponents(project1, file1, file2, project2, file3);
+ ComponentDto portfolio = ComponentTesting.newView(db.getDefaultOrganization());
+
+ db.components().insertComponents(project1, project2, portfolio);
setBrowsePermissionOnUserAndIndex(project1);
- SearchWsResponse response = call(new SearchRequest().setQualifiers(singletonList(FILE)));
+ SearchWsResponse response = call(new SearchRequest().setQualifiers(singletonList(PROJECT)));
assertThat(response.getComponentsList()).extracting(Component::getKey)
- .containsExactlyInAnyOrder(file1.getDbKey(), file2.getDbKey());
- assertThat(response.getPaging().getTotal()).isEqualTo(2);
+ .containsExactlyInAnyOrder(project1.getDbKey());
+ assertThat(response.getPaging().getTotal()).isEqualTo(1);
}
@Test
public void return_project_key() {
ComponentDto project = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization());
ComponentDto module = ComponentTesting.newModuleDto(project);
- ComponentDto file1 = newFileDto(module).setDbKey("file1");
- ComponentDto file2 = newFileDto(module).setDbKey("file2");
- ComponentDto file3 = newFileDto(project).setDbKey("file3");
- db.components().insertComponents(project, module, file1, file2, file3);
+ ComponentDto dir1 = newDirectory(module, "dir1").setDbKey("dir1");
+ ComponentDto dir2 = newDirectory(module, "dir2").setDbKey("dir2");
+ ComponentDto dir3 = newDirectory(project, "dir3").setDbKey("dir3");
+ db.components().insertComponents(project, module, dir1, dir2, dir3);
setBrowsePermissionOnUserAndIndex(project);
- SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, MODULE, FILE)));
+ SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, MODULE, DIRECTORY)));
assertThat(response.getComponentsList()).extracting(Component::getKey, Component::getProject)
- .containsOnly(tuple(project.getDbKey(), project.getDbKey()),
- tuple(module.getDbKey(), project.getDbKey()),
- tuple(file1.getDbKey(), project.getDbKey()),
- tuple(file2.getDbKey(), project.getDbKey()),
- tuple(file3.getDbKey(), project.getDbKey()));
+ .containsOnly(tuple(project.getDbKey(), project.getDbKey()));
}
@Test
@@ -265,14 +261,14 @@ public class SearchActionTest {
ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setName("Project Name").setDbKey("project-key");
ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setDbKey("module-key");
ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setDbKey("directory-key").setName("Directory Name");
- db.components().insertComponents(project, module, directory,
- newFileDto(module, directory, "file-uuid").setDbKey("file-key").setLanguage("java").setName("File Name"));
+ ComponentDto view = newView(organizationDto);
+ db.components().insertComponents(project, module, directory, view);
setBrowsePermissionOnUserAndIndex(project);
String response = ws.newRequest()
.setMediaType(MediaTypes.JSON)
.setParam(PARAM_ORGANIZATION, organizationDto.getKey())
- .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, DIRECTORY, FILE))
+ .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, DIRECTORY))
.execute().getInput();
assertJson(response).isSimilarTo(ws.getDef().responseExampleAsString());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
index 8f1238b4d5d..cef814630e8 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
@@ -69,6 +69,7 @@ import static org.sonar.api.resources.Qualifiers.FILE;
import static org.sonar.api.resources.Qualifiers.MODULE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.SUBVIEW;
+import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
@@ -120,6 +121,7 @@ public class SuggestionsActionTest {
PARAM_QUERY,
PARAM_RECENTLY_BROWSED);
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
+ tuple("8.4", "The use of 'DIR', 'FIL','UTS' as values for parameter 'more' is no longer supported"),
tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated"));
WebService.Param recentlyBrowsed = action.param(PARAM_RECENTLY_BROWSED);
@@ -346,13 +348,13 @@ public class SuggestionsActionTest {
assertThat(response.getResultsList())
.extracting(Category::getQ, Category::getItemsCount)
- .containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1), tuple("FIL", 0), tuple("UTS", 0))
- .doesNotContain(tuple("BRC", 0));
+ .containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1))
+ .doesNotContain(tuple("BRC", 0), tuple("FIL", 0), tuple("UTS", 0));
}
@Test
public void suggestions_should_filter_allowed_qualifiers() {
- resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE);
+ resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE, UNIT_TEST_FILE);
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
componentIndexer.indexOnAnalysis(project.projectUuid());
userSessionRule.addProjectPermission(USER, project);
@@ -364,7 +366,7 @@ public class SuggestionsActionTest {
assertThat(response.getResultsList())
.extracting(Category::getQ)
- .containsExactlyInAnyOrder(PROJECT, FILE).doesNotContain(MODULE);
+ .containsExactlyInAnyOrder(PROJECT).doesNotContain(MODULE, FILE, UNIT_TEST_FILE);
}
@Test
@@ -577,7 +579,7 @@ public class SuggestionsActionTest {
assertThat(response.getResultsList())
.extracting(Category::getQ, Category::getItemsCount)
- .containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1), tuple("FIL", 0), tuple("UTS", 0));
+ .containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1));
}
@Test
@@ -590,7 +592,7 @@ public class SuggestionsActionTest {
ComponentDto project = db.components().insertPrivateProject(organization, p -> p.setName(query));
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query));
- ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(Qualifiers.UNIT_TEST_FILE));
+ ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE));
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
authorizationIndexerTester.allowOnlyAnyone(view);
@@ -607,9 +609,7 @@ public class SuggestionsActionTest {
tuple(SuggestionCategory.APP.getName(), false),
tuple(SuggestionCategory.VIEW.getName(), false),
tuple(SuggestionCategory.SUBVIEW.getName(), false),
- tuple(SuggestionCategory.PROJECT.getName(), false),
- tuple(SuggestionCategory.FILE.getName(), true),
- tuple(SuggestionCategory.UNIT_TEST_FILE.getName(), true));
+ tuple(SuggestionCategory.PROJECT.getName(), false));
}
@Test