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;
@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));
}
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;
@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");
@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");
.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) {
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);
+ }
}
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;
@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();
}
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());
@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
.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));
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);
i18n.put("qualifier." + Qualifiers.VIEW, "View");
assertThatThrownBy(() -> {
- logInAsProjectAdministrator(view);
+ logInAsPortfolioAdministrator(db.components().getPortfolioDto(view));
callForProjectSettingByKey("my.key", "My Value", view.getKey());
})
.isInstanceOf(BadRequestException.class)
@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);
}
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
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)
.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")));
@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();
.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) {
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();
}
}
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;
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(
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)
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) {