Search in sources :

Example 86 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class DeleteAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String analysisUuid = request.mandatoryParam(PARAM_ANALYSIS);
    try (DbSession dbSession = dbClient.openSession(false)) {
        SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, analysisUuid).orElseThrow(() -> analysisNotFoundException(analysisUuid));
        if (STATUS_UNPROCESSED.equals(analysis.getStatus())) {
            throw analysisNotFoundException(analysisUuid);
        }
        userSession.checkComponentUuidPermission(UserRole.ADMIN, analysis.getComponentUuid());
        checkArgument(!analysis.getLast(), "The last analysis '%s' cannot be deleted", analysisUuid);
        checkNotUsedInNewCodePeriod(dbSession, analysis);
        analysis.setStatus(STATUS_UNPROCESSED);
        dbClient.snapshotDao().update(dbSession, analysis);
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 87 with SnapshotDto

use of org.sonar.db.component.SnapshotDto 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 88 with SnapshotDto

use of org.sonar.db.component.SnapshotDto 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)

Example 89 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class DeleteEventAction method deleteEvent.

private void deleteEvent(DbSession dbSession, EventDto dbEvent) {
    if (VERSION.getLabel().equals(dbEvent.getCategory())) {
        SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, dbEvent.getAnalysisUuid()).orElseThrow(() -> new IllegalStateException(format("Analysis '%s' not found", dbEvent.getAnalysisUuid())));
        checkArgument(!analysis.getLast(), "Cannot delete the version event of last analysis");
        analysis.setProjectVersion(null);
        dbClient.snapshotDao().update(dbSession, analysis);
    }
    dbClient.eventDao().delete(dbSession, dbEvent.getUuid());
    dbSession.commit();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 90 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ProjectStatusAction method getSnapshotThenProject.

private ProjectAndSnapshot getSnapshotThenProject(DbSession dbSession, String analysisUuid) {
    SnapshotDto snapshotDto = getSnapshot(dbSession, analysisUuid);
    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, snapshotDto.getComponentUuid()).orElseThrow(() -> new IllegalStateException(String.format("Branch '%s' not found", snapshotDto.getUuid())));
    ProjectDto projectDto = dbClient.projectDao().selectByUuid(dbSession, branchDto.getProjectUuid()).orElseThrow(() -> new IllegalStateException(String.format("Project '%s' not found", branchDto.getProjectUuid())));
    return new ProjectAndSnapshot(projectDto, branchDto, snapshotDto);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) SnapshotDto(org.sonar.db.component.SnapshotDto)

Aggregations

SnapshotDto (org.sonar.db.component.SnapshotDto)326 Test (org.junit.Test)257 ComponentDto (org.sonar.db.component.ComponentDto)219 MetricDto (org.sonar.db.metric.MetricDto)54 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 EventDto (org.sonar.db.event.EventDto)30 ProjectDto (org.sonar.db.project.ProjectDto)27 DbSession (org.sonar.db.DbSession)26 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)21 BranchDto (org.sonar.db.component.BranchDto)20 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)20 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 DbClient (org.sonar.db.DbClient)14 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 List (java.util.List)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 UserRole (org.sonar.api.web.UserRole)13 DbTester (org.sonar.db.DbTester)13