use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class SetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.getParam(PARAM_PROJECT).emptyAsNull().or(() -> null);
String branchKey = request.getParam(PARAM_BRANCH).emptyAsNull().or(() -> null);
if (projectKey == null && branchKey != null) {
throw new IllegalArgumentException("If branch key is specified, project key needs to be specified too");
}
try (DbSession dbSession = dbClient.openSession(false)) {
String typeStr = request.mandatoryParam(PARAM_TYPE);
String valueStr = request.getParam(PARAM_VALUE).emptyAsNull().or(() -> null);
boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
NewCodePeriodType type = validateType(typeStr, projectKey == null, branchKey != null || isCommunityEdition);
NewCodePeriodDto dto = new NewCodePeriodDto();
dto.setType(type);
ProjectDto project = null;
BranchDto branch = null;
if (projectKey != null) {
project = getProject(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.ADMIN, project);
if (branchKey != null) {
branch = getBranch(dbSession, project, branchKey);
dto.setBranchUuid(branch.getUuid());
} else if (isCommunityEdition) {
// in CE set main branch value instead of project value
branch = getMainBranch(dbSession, project);
dto.setBranchUuid(branch.getUuid());
}
dto.setProjectUuid(project.getUuid());
} else {
userSession.checkIsSystemAdministrator();
}
setValue(dbSession, dto, type, project, branch, valueStr);
newCodePeriodDao.upsert(dbSession, dto);
dbSession.commit();
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class UnsetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.getParam(PARAM_PROJECT).emptyAsNull().or(() -> null);
String branchKey = request.getParam(PARAM_BRANCH).emptyAsNull().or(() -> null);
if (projectKey == null && branchKey != null) {
throw new IllegalArgumentException("If branch key is specified, project key needs to be specified too");
}
try (DbSession dbSession = dbClient.openSession(false)) {
String projectUuid = null;
String branchUuid = null;
// in CE set main branch value instead of project value
boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
if (projectKey != null) {
ProjectDto project = getProject(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.ADMIN, project);
projectUuid = project.getUuid();
if (branchKey != null) {
branchUuid = getBranch(dbSession, project, branchKey).getUuid();
} else if (isCommunityEdition) {
branchUuid = getMainBranch(dbSession, project).getUuid();
}
} else {
userSession.checkIsSystemAdministrator();
}
newCodePeriodDao.delete(dbSession, projectUuid, branchUuid);
if (isCommunityEdition && projectUuid != null) {
// also delete project default in case it was somehow set (downgrade from another edition, for example)
newCodePeriodDao.delete(dbSession, projectUuid, null);
}
dbSession.commit();
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class NewCodePeriodDaoTest method select_branches_referencing.
@Test
public void select_branches_referencing() {
ProjectDto project = db.components().insertPrivateProjectDto();
BranchDto mainBranch = db.getDbClient().branchDao().selectByUuid(dbSession, project.getUuid()).get();
BranchDto branch1 = db.components().insertProjectBranch(project);
BranchDto branch2 = db.components().insertProjectBranch(project);
BranchDto branch3 = db.components().insertProjectBranch(project);
insert("1", project.getUuid(), null, REFERENCE_BRANCH, mainBranch.getKey());
insert("2", project.getUuid(), branch1.getUuid(), REFERENCE_BRANCH, mainBranch.getKey());
insert("3", project.getUuid(), branch2.getUuid(), NUMBER_OF_DAYS, "5");
insert("4", project.getUuid(), project.getUuid(), PREVIOUS_VERSION, null);
db.commit();
assertThat(underTest.selectBranchesReferencing(dbSession, project.getUuid(), mainBranch.getKey())).containsOnly(branch1.getUuid(), branch3.getUuid());
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_rows_in_user_dismissed_messages_when_deleting_project.
@Test
public void delete_rows_in_user_dismissed_messages_when_deleting_project() {
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectDto anotherProject = db.components().insertPrivateProjectDto();
UserDismissedMessageDto msg1 = db.users().insertUserDismissedMessage(user1, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
UserDismissedMessageDto msg2 = db.users().insertUserDismissedMessage(user2, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
UserDismissedMessageDto msg3 = db.users().insertUserDismissedMessage(user1, anotherProject, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
assertThat(uuidsIn("user_dismissed_messages")).containsOnly(msg1.getUuid(), msg2.getUuid(), msg3.getUuid());
underTest.deleteProject(dbSession, project.getUuid(), project.getQualifier(), project.getName(), project.getKey());
dbSession.commit();
assertThat(uuidsIn("user_dismissed_messages")).containsOnly(msg3.getUuid());
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class UserDaoTest method clean_users_homepage_when_deleting_project.
@Test
public void clean_users_homepage_when_deleting_project() {
UserDto userUnderTest = newUserDto().setHomepageType("PROJECT").setHomepageParameter("dummy-project-UUID");
underTest.insert(session, userUnderTest);
UserDto untouchedUser = newUserDto().setHomepageType("PROJECT").setHomepageParameter("not-so-dummy-project-UUID");
underTest.insert(session, untouchedUser);
session.commit();
underTest.cleanHomepage(session, new ProjectDto().setUuid("dummy-project-UUID"));
UserDto userWithAHomepageReloaded = underTest.selectByUuid(session, userUnderTest.getUuid());
assertThat(userWithAHomepageReloaded.getUpdatedAt()).isEqualTo(NOW);
assertThat(userWithAHomepageReloaded.getHomepageType()).isNull();
assertThat(userWithAHomepageReloaded.getHomepageParameter()).isNull();
UserDto untouchedUserReloaded = underTest.selectByUuid(session, untouchedUser.getUuid());
assertThat(untouchedUserReloaded.getUpdatedAt()).isEqualTo(untouchedUser.getUpdatedAt());
assertThat(untouchedUserReloaded.getHomepageType()).isEqualTo(untouchedUser.getHomepageType());
assertThat(untouchedUserReloaded.getHomepageParameter()).isEqualTo(untouchedUser.getHomepageParameter());
}
Aggregations