diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-06-30 17:29:16 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-07-03 20:03:13 +0000 |
commit | b819971ea23f4d63feed5147608a570f026d7906 (patch) | |
tree | 624dd2ea900cb034cb24d8eb9cc63ad5ef4f0e11 | |
parent | f16776129c779ddaed62114cbdda1d02fb26d9bf (diff) | |
download | sonarqube-b819971ea23f4d63feed5147608a570f026d7906.tar.gz sonarqube-b819971ea23f4d63feed5147608a570f026d7906.zip |
SONAR-19558 Refactored SetActionIT
9 files changed, 110 insertions, 83 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java index 106789c8fc2..0edde3eab48 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java @@ -43,7 +43,6 @@ import org.sonar.db.DbTester; import org.sonar.db.EmailSubscriberDto; import org.sonar.db.audit.AuditPersister; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ProjectData; import org.sonar.db.portfolio.PortfolioDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.user.UserDto; @@ -627,18 +626,18 @@ public class PropertiesDaoIT { @Test public void select_by_key_and_matching_value() { - ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent(); - ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent(); - db.properties().insertProperties(null, project1.getKey(), project1.name(), project1.qualifier(), newComponentPropertyDto("key", "value", project1)); - db.properties().insertProperties(null, project2.getKey(), project2.name(), project2.qualifier(), newComponentPropertyDto("key", "value", project2)); + ProjectDto project1 = db.components().insertPrivateProject().getProjectDto(); + ProjectDto project2 = db.components().insertPrivateProject().getProjectDto(); + db.properties().insertProperties(null, project1.getKey(), project1.getName(), project1.getQualifier(), newComponentPropertyDto("key", "value", project1)); + db.properties().insertProperties(null, project2.getKey(), project2.getName(), project2.getQualifier(), newComponentPropertyDto("key", "value", project2)); db.properties().insertProperties(null, null, null, null, newGlobalPropertyDto("key", "value")); - db.properties().insertProperties(null, project1.getKey(), project1.name(), project1.qualifier(), newComponentPropertyDto("another key", "value", project1)); + db.properties().insertProperties(null, project1.getKey(), project1.getName(), project1.getQualifier(), newComponentPropertyDto("another key", "value", project1)); assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value")) .extracting(PropertyDto::getValue, PropertyDto::getEntityUuid) .containsExactlyInAnyOrder( - tuple("value", project1.uuid()), - tuple("value", project2.uuid()), + tuple("value", project1.getUuid()), + tuple("value", project2.getUuid()), tuple("value", null)); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/PortfolioData.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/PortfolioData.java index a76d4ba6adc..c210e3fc9ee 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/PortfolioData.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/PortfolioData.java @@ -39,11 +39,11 @@ public class PortfolioData { return portfolioDto; } - public String portfolioUuid(){ + public String portfolioUuid() { return portfolioDto.getUuid(); } - public String rootComponentUuid(){ + public String rootComponentUuid() { return rootComponent.uuid(); } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java index 80392f266b0..dafacb3d5dd 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java @@ -52,7 +52,7 @@ public class ProjectData { return projectDto.getKey(); } - public String mainBranchUuid(){ + public String mainBranchUuid() { return mainBranchDto.getUuid(); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java index 738969cb8b1..f83902ef2ba 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java @@ -21,7 +21,6 @@ package org.sonar.db.property; import javax.annotation.Nullable; import org.apache.commons.lang.math.RandomUtils; -import org.sonar.db.component.ComponentDto; import org.sonar.db.entity.EntityDto; import org.sonar.db.user.UserDto; @@ -43,9 +42,9 @@ public class PropertyTesting { return newPropertyDto((String) null, null); } - public static PropertyDto newComponentPropertyDto(String key, String value, ComponentDto component) { - checkNotNull(component.uuid()); - return newPropertyDto(key, value, component.uuid(), null); + public static PropertyDto newComponentPropertyDto(String key, String value, EntityDto component) { + checkNotNull(component.getUuid()); + return newPropertyDto(key, value, component.getUuid(), null); } public static PropertyDto newComponentPropertyDto(EntityDto entity) { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java index 6f5061df6c7..63bb550608d 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/ActivityActionIT.java @@ -398,7 +398,7 @@ public class ActivityActionIT { ProjectData project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project.getProjectDto()); String branchName = "branch1"; - BranchDto branch = db.components().insertProjectBranch(project.getProjectDto(), b -> b.setBranchType(BRANCH).setKey(branchName)); + ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setBranchType(BRANCH).setKey(branchName)); SnapshotDto analysis = db.components().insertSnapshot(branch); CeActivityDto activity = insertActivity("T1", project.projectUuid(), project.mainBranchUuid(), SUCCESS, analysis); insertCharacteristic(activity, BRANCH_KEY, branchName); @@ -440,7 +440,7 @@ public class ActivityActionIT { ProjectData project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project.getProjectDto()); String pullRequestKey = RandomStringUtils.randomAlphanumeric(100); - BranchDto pullRequest = db.components().insertProjectBranch(project.getProjectDto(), b -> b.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey)); + ComponentDto pullRequest = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey)); SnapshotDto analysis = db.components().insertSnapshot(pullRequest); CeActivityDto activity = insertActivity("T1", project.projectUuid(), project.getMainBranchComponent().uuid(), SUCCESS, analysis); insertCharacteristic(activity, PULL_REQUEST, pullRequestKey); @@ -631,10 +631,10 @@ public class ActivityActionIT { return insertActivity(taskUuid, portfolio.portfolioUuid(), portfolio.rootComponentUuid(), status, db.components().insertSnapshot(portfolio.getPortfolioDto())); } - private CeActivityDto insertActivity(String taskUuid, String entityUuid, String rootCompomentUuid, Status status, @Nullable SnapshotDto analysis) { + private CeActivityDto insertActivity(String taskUuid, String entityUuid, String rootComponentUuid, Status status, @Nullable SnapshotDto analysis) { CeQueueDto queueDto = new CeQueueDto(); queueDto.setTaskType(CeTaskTypes.REPORT); - queueDto.setComponentUuid(rootCompomentUuid); + queueDto.setComponentUuid(rootComponentUuid); queueDto.setEntityUuid(entityUuid); queueDto.setUuid(taskUuid); queueDto.setCreatedAt(EXECUTED_AT); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateKeyActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateKeyActionIT.java index 31beb14a029..fd9624f43d7 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateKeyActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateKeyActionIT.java @@ -30,6 +30,8 @@ import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ProjectData; +import org.sonar.db.project.ProjectDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.ComponentService; import org.sonar.server.es.ProjectIndexers; @@ -61,21 +63,24 @@ public class UpdateKeyActionIT { @Test public void update_key_of_project_referenced_by_its_key() { - ComponentDto project = insertProject(); - userSessionRule.addProjectPermission(UserRole.ADMIN, project); + ProjectData project = insertProject(); + userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto()); - call(project.getKey(), ANOTHER_KEY); + call(project.projectKey(), ANOTHER_KEY); - assertThat(selectByKey(project.getKey())).isEmpty(); - assertThat(selectByKey(ANOTHER_KEY).get().uuid()).isEqualTo(project.uuid()); + assertThat(selectMainBranchByKey(project.projectKey())).isEmpty(); + assertThat(selectMainBranchByKey(ANOTHER_KEY).get().uuid()).isEqualTo(project.getMainBranchComponent().uuid()); + + assertThat(selectProjectByKey(project.projectKey())).isEmpty(); + assertThat(selectProjectByKey(ANOTHER_KEY).get().getUuid()).isEqualTo(project.getProjectDto().getUuid()); } @Test public void fail_if_not_authorized() { - ComponentDto project = insertProject(); - userSessionRule.addProjectPermission(UserRole.USER, project); + ProjectData project = insertProject(); + userSessionRule.addProjectPermission(UserRole.USER, project.getProjectDto()); - String projectKey = project.getKey(); + String projectKey = project.projectKey(); assertThatThrownBy(() -> call(projectKey, ANOTHER_KEY)) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); @@ -83,10 +88,10 @@ public class UpdateKeyActionIT { @Test public void fail_if_new_key_is_not_provided() { - ComponentDto project = insertProject(); - userSessionRule.addProjectPermission(UserRole.ADMIN, project); + ProjectData project = insertProject(); + userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto()); - String projectKey = project.getKey(); + String projectKey = project.projectKey(); assertThatThrownBy(() -> call(projectKey, null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("The 'to' parameter is missing"); @@ -119,8 +124,8 @@ public class UpdateKeyActionIT { .containsOnlyOnce("from", "to"); } - private ComponentDto insertProject() { - return db.components().insertPrivateProject().getMainBranchComponent(); + private ProjectData insertProject() { + return db.components().insertPrivateProject(); } private String call(@Nullable String key, @Nullable String newKey) { @@ -136,7 +141,11 @@ public class UpdateKeyActionIT { return request.execute().getInput(); } - private Optional<ComponentDto> selectByKey(String key) { + private Optional<ComponentDto> selectMainBranchByKey(String key) { return db.getDbClient().componentDao().selectByKey(db.getSession(), key); } + + private Optional<ProjectDto> selectProjectByKey(String key) { + return db.getDbClient().projectDao().selectProjectByKey(db.getSession(), key); + } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SetActionIT.java index e196bbe4d28..f022e088bab 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SetActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/SetActionIT.java @@ -46,7 +46,9 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; +import org.sonar.db.component.ProjectData; import org.sonar.db.portfolio.PortfolioDto; +import org.sonar.db.project.ProjectDto; import org.sonar.db.property.PropertyDbTester; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; @@ -143,13 +145,13 @@ public class SetActionIT { @Test public void persist_new_project_setting() { propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null, null); - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); logInAsProjectAdministrator(project); callForProjectSettingByKey("my.key", "my project value", project.getKey()); assertGlobalSetting("my.key", "my global value"); - assertComponentSetting("my.key", "my project value", project.uuid()); + assertComponentSetting("my.key", "my project value", project.getUuid()); assertThat(settingsChangeNotifier.wasCalled).isFalse(); } @@ -158,7 +160,7 @@ public class SetActionIT { propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null, null); ComponentDto portfolio = db.components().insertPrivatePortfolio(); ComponentDto subportfolio = db.components().insertSubportfolio(portfolio); - logInAsProjectAdministrator(portfolio); + logInAsPortfolioAdministrator(db.components().getPortfolioDto(portfolio)); callForProjectSettingByKey("my.key", "my project value", subportfolio.getKey()); @@ -169,27 +171,27 @@ public class SetActionIT { @Test public void persist_project_property_with_project_admin_permission() { - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); logInAsProjectAdministrator(project); callForProjectSettingByKey("my.key", "my value", project.getKey()); - assertComponentSetting("my.key", "my value", project.uuid()); + assertComponentSetting("my.key", "my value", project.getUuid()); } @Test public void update_existing_project_setting() { propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null, null); - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project), project.getKey(), - project.name(), null, null); - assertComponentSetting("my.key", "my project value", project.uuid()); + project.getName(), null, null); + assertComponentSetting("my.key", "my project value", project.getUuid()); logInAsProjectAdministrator(project); callForProjectSettingByKey("my.key", "my new project value", project.getKey()); - assertComponentSetting("my.key", "my new project value", project.uuid()); + assertComponentSetting("my.key", "my new project value", project.getUuid()); } @Test @@ -313,12 +315,12 @@ public class SetActionIT { .type(PropertyType.STRING) .build())) .build()); - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto("my.key", "1"), newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"), newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue")); - propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.getName(), project.getQualifier(), newComponentPropertyDto("my.key", "1", project), newComponentPropertyDto("my.key.1.firstField", "componentFirstValue", project), newComponentPropertyDto("my.key.1.firstField", "componentSecondValue", project)); @@ -330,11 +332,11 @@ public class SetActionIT { project.getKey()); assertThat(dbClient.propertiesDao().selectGlobalProperties(dbSession)).hasSize(3); - assertThat(dbClient.propertiesDao().selectEntityProperties(dbSession, project.uuid())).hasSize(5); + assertThat(dbClient.propertiesDao().selectEntityProperties(dbSession, project.getUuid())).hasSize(5); assertGlobalSetting("my.key", "1"); assertGlobalSetting("my.key.1.firstField", "oldFirstValue"); assertGlobalSetting("my.key.1.secondField", "oldSecondValue"); - String projectUuid = project.uuid(); + String projectUuid = project.getUuid(); assertComponentSetting("my.key", "1,2", projectUuid); assertComponentSetting("my.key.1.firstField", "firstValue", projectUuid); assertComponentSetting("my.key.1.secondField", "secondValue", projectUuid); @@ -794,7 +796,7 @@ public class SetActionIT { i18n.put("qualifier." + Qualifiers.VIEW, "View"); assertThatThrownBy(() -> { - logInAsProjectAdministrator(view); + logInAsPortfolioAdministrator(db.components().getPortfolioDto(view)); callForProjectSettingByKey("my.key", "My Value", view.getKey()); }) .isInstanceOf(BadRequestException.class) @@ -824,27 +826,27 @@ public class SetActionIT { @Test public void succeed_for_property_without_definition_when_set_on_project_component() { - ComponentDto project = randomPublicOrPrivateProject(); + ProjectDto project = randomPublicOrPrivateProject().getProjectDto(); succeedForPropertyWithoutDefinitionAndValidComponent(project); } @Test public void fail_for_property_without_definition_when_set_on_directory_component() { - ComponentDto project = randomPublicOrPrivateProject(); - ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project, "A/B")); - failForPropertyWithoutDefinitionOnUnsupportedComponent(project, directory); + ProjectData projectData = randomPublicOrPrivateProject(); + ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(projectData.getMainBranchComponent(), "A/B")); + failForPropertyWithoutDefinitionOnUnsupportedComponent(projectData.getProjectDto(), directory); } @Test public void fail_for_property_without_definition_when_set_on_file_component() { - ComponentDto project = randomPublicOrPrivateProject(); - ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); - failForPropertyWithoutDefinitionOnUnsupportedComponent(project, file); + ProjectData projectData = randomPublicOrPrivateProject(); + ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(projectData.getMainBranchComponent())); + failForPropertyWithoutDefinitionOnUnsupportedComponent(projectData.getProjectDto(), file); } @Test public void succeed_for_property_without_definition_when_set_on_view_component() { - ComponentDto view = db.components().insertPrivatePortfolio(); + PortfolioDto view = db.components().insertPrivatePortfolioDto(); succeedForPropertyWithoutDefinitionAndValidComponent(view); } @@ -852,7 +854,7 @@ public class SetActionIT { public void succeed_for_property_without_definition_when_set_on_subview_component() { ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubPortfolio(view)); - failForPropertyWithoutDefinitionOnUnsupportedComponent(view, subview); + failForPropertyWithoutDefinitionOnUnsupportedComponent(db.components().getPortfolioDto(view), subview); } @Test @@ -860,20 +862,37 @@ public class SetActionIT { ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto projectCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", db.components().insertPrivateProject().getMainBranchComponent(), view)); - failForPropertyWithoutDefinitionOnUnsupportedComponent(view, projectCopy); + failForPropertyWithoutDefinitionOnUnsupportedComponent(db.components().getPortfolioDto(view), projectCopy); + } + + private void succeedForPropertyWithoutDefinitionAndValidComponent(ProjectDto project) { + logInAsProjectAdministrator(project); + + callForProjectSettingByKey("my.key", "My Value", project.getKey()); + + assertComponentSetting("my.key", "My Value", project.getUuid()); } - private void succeedForPropertyWithoutDefinitionAndValidComponent(ComponentDto entity) { - logInAsProjectAdministrator(entity); + private void succeedForPropertyWithoutDefinitionAndValidComponent(PortfolioDto portfolioDto) { + logInAsPortfolioAdministrator(portfolioDto); - callForProjectSettingByKey("my.key", "My Value", entity.getKey()); + callForProjectSettingByKey("my.key", "My Value", portfolioDto.getKey()); - assertComponentSetting("my.key", "My Value", entity.uuid()); + assertComponentSetting("my.key", "My Value", portfolioDto.getUuid()); } - private void failForPropertyWithoutDefinitionOnUnsupportedComponent(ComponentDto root, ComponentDto component) { + private void failForPropertyWithoutDefinitionOnUnsupportedComponent(ProjectDto project, ComponentDto component) { i18n.put("qualifier." + component.qualifier(), "QualifierLabel"); - logInAsProjectAdministrator(root); + logInAsProjectAdministrator(project); + + assertThatThrownBy(() -> callForProjectSettingByKey("my.key", "My Value", component.getKey())) + .isInstanceOf(NotFoundException.class) + .hasMessage(String.format("Component key '%s' not found", component.getKey())); + } + + private void failForPropertyWithoutDefinitionOnUnsupportedComponent(PortfolioDto portfolio, ComponentDto component) { + i18n.put("qualifier." + component.qualifier(), "QualifierLabel"); + logInAsPortfolioAdministrator(portfolio); assertThatThrownBy(() -> callForProjectSettingByKey("my.key", "My Value", component.getKey())) .isInstanceOf(NotFoundException.class) @@ -1115,7 +1134,7 @@ public class SetActionIT { .fields(List.of(PropertyFieldDefinition.build("firstField").name("First Field").type(PropertyType.STRING).build())) .build()); i18n.put("qualifier." + Qualifiers.PROJECT, "Project"); - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); logInAsProjectAdministrator(project); List<String> values = List.of(GSON.toJson(Map.of("firstField", "firstValue"))); @@ -1137,7 +1156,7 @@ public class SetActionIT { @Test public void fail_when_setting_key_is_defined_in_sonar_properties() { - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); logInAsProjectAdministrator(project); String settingKey = ProcessProperties.Property.JDBC_URL.getKey(); @@ -1178,13 +1197,13 @@ public class SetActionIT { .containsExactly(tuple(key, value, userUuid)); } - private void assertComponentSetting(String key, String value, String componentUuid) { - PropertyDto result = dbClient.propertiesDao().selectProjectProperty(db.getSession(), componentUuid, key); + private void assertComponentSetting(String key, String value, String entityUuid) { + PropertyDto result = dbClient.propertiesDao().selectProjectProperty(db.getSession(), entityUuid, key); assertThat(result) .isNotNull() .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getEntityUuid) - .containsExactly(key, value, componentUuid); + .containsExactly(key, value, entityUuid); } private void callForGlobalSetting(@Nullable String key, @Nullable String value) { @@ -1249,11 +1268,11 @@ public class SetActionIT { userSession.logIn().addPortfolioPermission(UserRole.ADMIN, portfolio); } - private void logInAsProjectAdministrator(ComponentDto project) { + private void logInAsProjectAdministrator(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); } - private ComponentDto randomPublicOrPrivateProject() { - return new Random().nextBoolean() ? db.components().insertPrivateProject().getMainBranchComponent() : db.components().insertPublicProject().getMainBranchComponent(); + private ProjectData randomPublicOrPrivateProject() { + return new Random().nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject(); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java index 2dabe140c35..7792130d79b 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java @@ -79,7 +79,7 @@ public class IssueSnippetsActionIT { @Before public void setUp() { - project = db.components().insertPrivateProject("projectUuid", c->c.setKey("KEY_projectUuid").setName("NAME_projectUuid")); + project = db.components().insertPrivateProject("projectUuid", c -> c.setKey("KEY_projectUuid").setName("NAME_projectUuid")); mainBranchComponent = project.getMainBranchComponent(); HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java index 3a3c835f627..d5040db7d5b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java @@ -78,7 +78,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ActivityAction implements CeWsAction { private static final int MAX_PAGE_SIZE = 1000; - private static final String[] POSSIBLE_QUALIFIERS = new String[] {Qualifiers.PROJECT, Qualifiers.APP, Qualifiers.VIEW}; + private static final String[] POSSIBLE_QUALIFIERS = new String[]{Qualifiers.PROJECT, Qualifiers.APP, Qualifiers.VIEW}; private static final String INVALID_QUERY_PARAM_ERROR_MESSAGE = "%s and %s must not be set at the same time"; private final UserSession userSession; @@ -101,8 +101,8 @@ public class ActivityAction implements CeWsAction { public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("activity") .setDescription(format("Search for tasks.<br> " + - "Requires the system administration permission, " + - "or project administration permission if %s is set.", PARAM_COMPONENT)) + "Requires the system administration permission, " + + "or project administration permission if %s is set.", PARAM_COMPONENT)) .setResponseExample(getClass().getResource("activity-example.json")) .setHandler(this) .setChangelog( @@ -125,10 +125,10 @@ public class ActivityAction implements CeWsAction { action.createParam(TEXT_QUERY) .setDescription(format("Limit search to: <ul>" + - "<li>component names that contain the supplied string</li>" + - "<li>component keys that are exactly the same as the supplied string</li>" + - "<li>task ids that are exactly the same as the supplied string</li>" + - "</ul>")) + "<li>component names that contain the supplied string</li>" + + "<li>component keys that are exactly the same as the supplied string</li>" + + "<li>task ids that are exactly the same as the supplied string</li>" + + "</ul>")) .setExampleValue("Apache") .setSince("5.5"); action.createParam(PARAM_STATUS) @@ -287,19 +287,20 @@ public class ActivityAction implements CeWsAction { if (entity != null) { query.setEntityUuid(entity.getUuid()); } else if (componentQuery != null) { - query.setEntityUuids(loadComponents(dbSession, componentQuery).stream() - .map(ComponentDto::uuid) + query.setEntityUuids(loadEntities(dbSession, componentQuery).stream() + .map(EntityDto::getUuid) .collect(toList())); } return query; } - private List<ComponentDto> loadComponents(DbSession dbSession, String componentQuery) { + private List<EntityDto> loadEntities(DbSession dbSession, String componentQuery) { ComponentQuery componentDtoQuery = ComponentQuery.builder() .setNameOrKeyQuery(componentQuery) .setQualifiers(POSSIBLE_QUALIFIERS) .build(); - return dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS); + List<ComponentDto> componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS); + return dbClient.entityDao().selectByKeys(dbSession, componentDtos.stream().map(ComponentDto::getKey).collect(toSet())); } private Integer countQueuedTasks(DbSession dbSession, CeTaskQuery query) { |