Search in sources :

Example 36 with ProjectDto

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();
    }
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentFinder(org.sonar.server.component.ComponentFinder) NewCodePeriodDao(org.sonar.db.newcodeperiod.NewCodePeriodDao) NewCodePeriodParser(org.sonar.db.newcodeperiod.NewCodePeriodParser) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) WebService(org.sonar.api.server.ws.WebService) Locale(java.util.Locale) Response(org.sonar.api.server.ws.Response) NUMBER_OF_DAYS(org.sonar.db.newcodeperiod.NewCodePeriodType.NUMBER_OF_DAYS) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) EditionProvider(org.sonar.core.platform.EditionProvider) EnumSet(java.util.EnumSet) Nullable(javax.annotation.Nullable) PREVIOUS_VERSION(org.sonar.db.newcodeperiod.NewCodePeriodType.PREVIOUS_VERSION) REFERENCE_BRANCH(org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Set(java.util.Set) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) DbClient(org.sonar.db.DbClient) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) UserRole(org.sonar.api.web.UserRole) SPECIFIC_ANALYSIS(org.sonar.db.newcodeperiod.NewCodePeriodType.SPECIFIC_ANALYSIS) ProjectDto(org.sonar.db.project.ProjectDto) Preconditions(com.google.common.base.Preconditions) UserSession(org.sonar.server.user.UserSession) SnapshotDto(org.sonar.db.component.SnapshotDto) ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) BranchDto(org.sonar.db.component.BranchDto) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType)

Example 37 with ProjectDto

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();
    }
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentFinder(org.sonar.server.component.ComponentFinder) NewCodePeriodDao(org.sonar.db.newcodeperiod.NewCodePeriodDao) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) DbSession(org.sonar.db.DbSession) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) UserRole(org.sonar.api.web.UserRole) WebService(org.sonar.api.server.ws.WebService) Response(org.sonar.api.server.ws.Response) ProjectDto(org.sonar.db.project.ProjectDto) UserSession(org.sonar.server.user.UserSession) EditionProvider(org.sonar.core.platform.EditionProvider) ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession)

Example 38 with ProjectDto

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());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) Test(org.junit.Test)

Example 39 with ProjectDto

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());
}
Also used : PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto) Test(org.junit.Test)

Example 40 with ProjectDto

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());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10