Search in sources :

Example 61 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class SetAutomaticDeletionProtectionAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    String projectKey = request.mandatoryParam(PARAM_PROJECT);
    String branchKey = request.mandatoryParam(PARAM_BRANCH);
    boolean excludeFromPurge = request.mandatoryParamAsBoolean(PARAM_VALUE);
    try (DbSession dbSession = dbClient.openSession(false)) {
        ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
        checkPermission(project);
        BranchDto branch = dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), branchKey).orElseThrow(() -> new NotFoundException(format("Branch '%s' not found for project '%s'", branchKey, projectKey)));
        checkArgument(!branch.isMain() || excludeFromPurge, "Main branch of the project is always excluded from automatic deletion.");
        dbClient.branchDao().updateExcludeFromPurge(dbSession, branch.getUuid(), excludeFromPurge);
        dbSession.commit();
        response.noContent();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Example 62 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class ProjectBadgesSupport method getBranch.

BranchDto getBranch(DbSession dbSession, Request request) {
    try {
        String projectKey = request.mandatoryParam(PARAM_PROJECT);
        String branchName = request.param(PARAM_BRANCH);
        ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
        BranchDto branch;
        if (branchName == null) {
            branch = componentFinder.getMainBranch(dbSession, project);
        } else {
            branch = componentFinder.getBranchOrPullRequest(dbSession, project, branchName, null);
        }
        if (!branch.getBranchType().equals(BRANCH)) {
            throw generateInvalidProjectException();
        }
        return branch;
    } catch (NotFoundException e) {
        throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND);
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Example 63 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class TokenAction method doHandle.

private TokenWsResponse doHandle(Request request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        String projectKey = request.mandatoryParam(PROJECT_KEY_PARAM);
        ProjectDto projectDto = dbClient.projectDao().selectProjectByKey(dbSession, projectKey).orElseThrow(() -> new IllegalArgumentException("project not found"));
        userSession.checkProjectPermission(UserRole.USER, projectDto);
        ProjectBadgeTokenDto projectBadgeTokenDto = dbClient.projectBadgeTokenDao().selectTokenByProject(dbSession, projectDto);
        if (projectBadgeTokenDto == null) {
            projectBadgeTokenDto = dbClient.projectBadgeTokenDao().insert(dbSession, tokenGenerator.generate(), projectDto, userSession.getUuid(), userSession.getLogin());
            dbSession.commit();
        }
        return buildResponse(projectBadgeTokenDto);
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) ProjectBadgeTokenDto(org.sonar.db.project.ProjectBadgeTokenDto)

Example 64 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class SetBaselineAction method doHandle.

private void doHandle(Request request) {
    String projectKey = request.mandatoryParam(PARAM_PROJECT);
    String branchKey = trimToNull(request.param(PARAM_BRANCH));
    String analysisUuid = request.mandatoryParam(PARAM_ANALYSIS);
    try (DbSession dbSession = dbClient.openSession(false)) {
        ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
        BranchDto branch = loadBranch(dbSession, project, branchKey);
        SnapshotDto analysis = getAnalysis(dbSession, analysisUuid);
        checkRequest(project, branch, analysis, branchKey);
        dbClient.newCodePeriodDao().upsert(dbSession, new NewCodePeriodDto().setProjectUuid(project.getUuid()).setBranchUuid(branch.getUuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysisUuid));
        dbSession.commit();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 65 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class CreateEventAction method doHandle.

private CreateEventResponse doHandle(CreateEventRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        SnapshotDto analysis = getAnalysis(dbSession, request);
        ProjectDto project = getProjectOrApplication(dbSession, analysis);
        checkRequest(request, project);
        checkExistingDbEvents(dbSession, request, analysis);
        EventDto dbEvent = insertDbEvent(dbSession, request, analysis);
        return toCreateEventResponse(dbEvent);
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) SnapshotDto(org.sonar.db.component.SnapshotDto) EventDto(org.sonar.db.event.EventDto)

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