use of org.sonar.db.component.BranchDto 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.component.BranchDto 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.component.BranchDto in project sonarqube by SonarSource.
the class BulkChangeAction method toNotification.
@CheckForNull
private ChangedIssue toNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, DefaultIssue issue) {
BranchDto branchDto = bulkChangeData.branchesByProjectUuid.get(issue.projectUuid());
if (!hasNotificationSupport(branchDto)) {
return null;
}
RuleDefinitionDto ruleDefinitionDto = bulkChangeData.rulesByKey.get(issue.ruleKey());
ComponentDto projectDto = bulkChangeData.projectsByUuid.get(issue.projectUuid());
if (ruleDefinitionDto == null || projectDto == null) {
return null;
}
Optional<UserDto> assignee = Optional.ofNullable(issue.assignee()).map(userDtoByUuid::get);
return new ChangedIssue.Builder(issue.key()).setNewStatus(issue.status()).setNewResolution(issue.resolution()).setAssignee(assignee.map(u -> new User(u.getUuid(), u.getLogin(), u.getName())).orElse(null)).setRule(new IssuesChangesNotificationBuilder.Rule(ruleDefinitionDto.getKey(), RuleType.valueOfNullable(ruleDefinitionDto.getType()), ruleDefinitionDto.getName())).setProject(new Project.Builder(projectDto.uuid()).setKey(projectDto.getKey()).setProjectName(projectDto.name()).setBranchName(branchDto.isMain() ? null : branchDto.getKey()).build()).build();
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class IssueUpdater method doSaveIssue.
private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, Optional<RuleDefinitionDto> rule, ComponentDto project, BranchDto branchDto) {
IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next();
if (// since this method is called after an update of the issue, date should never be null
issue.updateDate() == null || // name of rule is displayed in notification, rule must therefor be present
!rule.isPresent() || // notification are not supported on PRs
!hasNotificationSupport(branchDto)) {
return issueDto;
}
Optional<UserDto> assignee = Optional.ofNullable(issue.assignee()).map(assigneeUuid -> dbClient.userDao().selectByUuid(session, assigneeUuid));
UserDto author = Optional.ofNullable(context.userUuid()).map(authorUuid -> dbClient.userDao().selectByUuid(session, authorUuid)).orElseThrow(() -> new IllegalStateException("Can not find dto for change author " + context.userUuid()));
IssuesChangesNotificationBuilder notificationBuilder = new IssuesChangesNotificationBuilder(singleton(new ChangedIssue.Builder(issue.key()).setNewResolution(issue.resolution()).setNewStatus(issue.status()).setAssignee(assignee.map(assigneeDto -> new User(assigneeDto.getUuid(), assigneeDto.getLogin(), assigneeDto.getName())).orElse(null)).setRule(rule.map(r -> new Rule(r.getKey(), RuleType.valueOfNullable(r.getType()), r.getName())).get()).setProject(new Project.Builder(project.uuid()).setKey(project.getKey()).setProjectName(project.name()).setBranchName(branchDto.isMain() ? null : branchDto.getKey()).build()).build()), new UserChange(issue.updateDate().getTime(), new User(author.getUuid(), author.getLogin(), author.getName())));
notificationService.scheduleForSending(notificationSerializer.serialize(notificationBuilder));
return issueDto;
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class IssueUpdater method saveIssueAndPreloadSearchResponseData.
public SearchResponseData saveIssueAndPreloadSearchResponseData(DbSession dbSession, DefaultIssue issue, IssueChangeContext context, boolean refreshMeasures) {
Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey());
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid());
BranchDto branch = getBranch(dbSession, issue, issue.projectUuid());
ComponentDto component = getComponent(dbSession, issue, issue.componentUuid());
IssueDto issueDto = doSaveIssue(dbSession, issue, context, rule, project, branch);
SearchResponseData result = new SearchResponseData(issueDto);
rule.ifPresent(r -> result.addRules(singletonList(r)));
result.addComponents(singleton(project));
result.addComponents(singleton(component));
if (refreshMeasures) {
List<DefaultIssue> changedIssues = result.getIssues().stream().map(IssueDto::toDefaultIssue).collect(MoreCollectors.toList(result.getIssues().size()));
issueChangePostProcessor.process(dbSession, changedIssues, singleton(component));
}
return result;
}
Aggregations