use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class IssueIteratorFactoryTest method extract_file_path.
@Test
public void extract_file_path() {
RuleDefinitionDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml"));
ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java"));
IssueDto projectIssue = dbTester.issues().insert(rule, project, project);
IssueDto fileInSubDirIssue = dbTester.issues().insert(rule, project, fileInSubDir);
IssueDto fileInRootDirIssue = dbTester.issues().insert(rule, project, fileInRootDir);
IssueDto moduleIssue = dbTester.issues().insert(rule, project, module);
Map<String, IssueDoc> issuesByKey = issuesByKey();
assertThat(issuesByKey).hasSize(4);
assertThat(issuesByKey.get(fileInSubDirIssue.getKey()).filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issuesByKey.get(fileInRootDirIssue.getKey()).filePath()).isEqualTo("pom.xml");
assertThat(issuesByKey.get(moduleIssue.getKey()).filePath()).isNull();
assertThat(issuesByKey.get(projectIssue.getKey()).filePath()).isNull();
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class IssueIteratorFactoryTest method iterator_over_one_issue.
@Test
public void iterator_over_one_issue() {
RuleDefinitionDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project).setPath("src/main/java/Action.java"));
IssueDto expected = dbTester.issues().insert(rule, project, file, t -> t.setResolution("FIXED").setStatus("RESOLVED").setSeverity("BLOCKER").setManualSeverity(false).setAssigneeUuid("uuid-of-guy1").setAuthorLogin("guy2").setChecksum("FFFFF").setGap(2D).setEffort(10L).setMessage(null).setLine(444).setRuleUuid(rule.getUuid()).setTags(List.of("tag1", "tag2", "tag3")).setCreatedAt(1400000000000L).setUpdatedAt(1400000000000L).setIssueCreationDate(new Date(1115848800000L)).setIssueUpdateDate(new Date(1356994800000L)).setIssueCloseDate(null).setType(2));
Map<String, IssueDoc> issuesByKey = issuesByKey();
assertThat(issuesByKey).hasSize(1);
IssueDoc issue = issuesByKey.get(expected.getKey());
assertThat(issue.key()).isEqualTo(expected.getKey());
assertThat(issue.resolution()).isEqualTo("FIXED");
assertThat(issue.status()).isEqualTo("RESOLVED");
assertThat(issue.severity()).isEqualTo("BLOCKER");
assertThat(issue.assigneeUuid()).isEqualTo("uuid-of-guy1");
assertThat(issue.authorLogin()).isEqualTo("guy2");
assertThat(issue.line()).isEqualTo(444);
assertThat(issue.ruleUuid()).isEqualTo(rule.getUuid());
assertThat(issue.componentUuid()).isEqualTo(file.uuid());
assertThat(issue.projectUuid()).isEqualTo(file.projectUuid());
assertThat(issue.moduleUuid()).isEqualTo(file.projectUuid());
assertThat(issue.modulePath()).isEqualTo(file.moduleUuidPath());
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isPositive();
assertThat(issue.type().getDbConstant()).isEqualTo(2);
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class IssuesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = loadComponent(dbSession, request);
userSession.checkComponentPermission(USER, component);
Map<String, String> keysByUUid = keysByUUid(dbSession, component);
ScannerInput.ServerIssue.Builder responseBuilder = ScannerInput.ServerIssue.newBuilder();
response.stream().setMediaType(MediaTypes.PROTOBUF);
OutputStream output = response.stream().output();
List<IssueDto> issueDtos = new ArrayList<>();
switch(component.scope()) {
case Scopes.PROJECT:
issueDtos.addAll(dbClient.issueDao().selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(dbSession, component));
break;
case Scopes.FILE:
issueDtos.addAll(dbClient.issueDao().selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(dbSession, component.uuid()));
break;
default:
// only projects, modules and files are supported. Other types of components are not allowed.
throw new IllegalArgumentException(format("Component of scope '%s' is not allowed", component.scope()));
}
List<String> usersUuids = issueDtos.stream().filter(issue -> issue.getAssigneeUuid() != null).map(IssueDto::getAssigneeUuid).collect(toList());
Map<String, String> userLoginsByUserUuids = dbClient.userDao().selectByUuids(dbSession, usersUuids).stream().collect(toMap(UserDto::getUuid, UserDto::getLogin));
issueDtos.forEach(issue -> {
issue.setAssigneeUuid(userLoginsByUserUuids.get(issue.getAssigneeUuid()));
handleIssue(issue, responseBuilder, keysByUUid, output);
});
}
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class AssignAction method assign.
private SearchResponseData assign(String issueKey, @Nullable String login) {
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto issueDto = issueFinder.getByKey(dbSession, issueKey);
DefaultIssue issue = issueDto.toDefaultIssue();
UserDto user = getUser(dbSession, login);
IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
if (issueFieldsSetter.assign(issue, user, context)) {
return issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, issue, context, false);
}
return new SearchResponseData(issueDto);
}
}
use of org.sonar.db.issue.IssueDto 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;
}
Aggregations