use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class AnalysisStatusAction method doHandle.
private void doHandle(Request request, Response response, String projectKey, @Nullable String branchKey, @Nullable String pullRequestKey) {
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.USER, project);
BranchDto branch = componentFinder.getBranchOrPullRequest(dbSession, project, branchKey, pullRequestKey);
AnalysisStatusWsResponse.Builder responseBuilder = AnalysisStatusWsResponse.newBuilder();
CeActivityDto lastActivity = dbClient.ceActivityDao().selectLastByComponentUuidAndTaskType(dbSession, branch.getUuid(), CeTaskTypes.REPORT).orElse(null);
responseBuilder.setComponent(formatComponent(dbSession, project, lastActivity, branchKey, pullRequestKey));
writeProtobuf(responseBuilder.build(), request, response);
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ListAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto projectOrApp = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(projectOrApp);
Collection<BranchDto> branches = dbClient.branchDao().selectByProject(dbSession, projectOrApp).stream().filter(b -> b.getBranchType() == BRANCH).collect(toList());
List<String> branchUuids = branches.stream().map(BranchDto::getUuid).collect(toList());
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricKeys(dbSession, branchUuids, singletonList(ALERT_STATUS_KEY)).stream().collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream().collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt())));
ProjectBranches.ListWsResponse.Builder protobufResponse = ProjectBranches.ListWsResponse.newBuilder();
branches.forEach(b -> addBranch(protobufResponse, b, qualityGateMeasuresByComponentUuids.get(b.getUuid()), analysisDateByBranchUuid.get(b.getUuid())));
WsUtils.writeProtobuf(protobufResponse.build(), request, response);
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class RenameAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String projectKey = request.mandatoryParam(PARAM_PROJECT);
String newBranchName = request.mandatoryParam(PARAM_NAME);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(project);
Optional<BranchDto> existingBranch = dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), newBranchName);
checkArgument(!existingBranch.filter(b -> !b.isMain()).isPresent(), "Impossible to update branch name: a branch with name \"%s\" already exists in the project.", newBranchName);
dbClient.branchDao().updateMainBranchName(dbSession, project.getUuid(), newBranchName);
dbSession.commit();
response.noContent();
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class TokenRenewAction method doHandle.
private void 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.ADMIN, projectDto);
String newGeneratedToken = tokenGenerator.generate();
dbClient.projectBadgeTokenDao().upsert(dbSession, newGeneratedToken, projectDto, userSession.getUuid(), userSession.getLogin());
dbSession.commit();
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class DeleteAction 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);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(project);
BranchDto branch = checkFoundWithOptional(dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), branchKey), "Branch '%s' not found for project '%s'", branchKey, projectKey);
if (branch.isMain()) {
throw new IllegalArgumentException("Only non-main branches can be deleted");
}
componentCleanerService.deleteBranch(dbSession, branch);
projectLifeCycleListeners.onProjectBranchesDeleted(singleton(from(project)));
response.noContent();
}
}
Aggregations