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();
}
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();
}
}
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);
}
}
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();
}
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);
}
Aggregations