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