use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class MovedIssueVisitorTest method onIssue_update_component_and_module_fields_to_component_and_flag_issue_has_changed.
@Test
public void onIssue_update_component_and_module_fields_to_component_and_flag_issue_has_changed() {
MovedFilesRepository.OriginalFile originalFile = new MovedFilesRepository.OriginalFile(6451, "original uuid", "original key");
DefaultIssue issue = mockIssue(originalFile.getUuid());
when(movedFilesRepository.getOriginalFile(FILE)).thenReturn(Optional.of(originalFile));
underTest.onIssue(FILE, issue);
verify(issue).setComponentUuid(FILE.getUuid());
verify(issue).setComponentKey(FILE.getKey());
verify(issue).setModuleUuid(null);
verify(issue).setModuleUuidPath(null);
verify(issue).setChanged(true);
ArgumentCaptor<IssueChangeContext> issueChangeContextCaptor = ArgumentCaptor.forClass(IssueChangeContext.class);
verify(issue).setFieldChange(issueChangeContextCaptor.capture(), eq("file"), eq(originalFile.getUuid()), eq(FILE.getUuid()));
assertThat(issueChangeContextCaptor.getValue().date()).isEqualTo(new Date(ANALYSIS_DATE));
assertThat(issueChangeContextCaptor.getValue().login()).isNull();
assertThat(issueChangeContextCaptor.getValue().scan()).isFalse();
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification.
@Test
public void verify_notification() throws Exception {
RuleDto rule = ruleDbTester.insertRule(newRuleDto());
ComponentDto project = componentDbTester.insertProject();
ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
DefaultIssue issue = issueDbTester.insertIssue(newDto(rule, file, project)).setSeverity(MAJOR).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssue(dbTester.getSession(), issue, context, "increase severity");
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key());
assertThat(issueChangeNotification.getFieldValue("old.severity")).isEqualTo(MAJOR);
assertThat(issueChangeNotification.getFieldValue("new.severity")).isEqualTo(BLOCKER);
assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.key());
assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName());
assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.key());
assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name());
assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName());
assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo("john");
assertThat(issueChangeNotification.getFieldValue("comment")).isEqualTo("increase severity");
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class IssueService method assign.
public void assign(String issueKey, @Nullable String assignee) {
userSession.checkLoggedIn();
DbSession session = dbClient.openSession(false);
try {
DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
User user = null;
if (!Strings.isNullOrEmpty(assignee)) {
user = userFinder.findByLogin(assignee);
checkRequest(user != null, "Unknown user: %s", assignee);
}
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
if (issueFieldsSetter.assign(issue, user, context)) {
issueUpdater.saveIssue(session, issue, context, null);
}
} finally {
session.close();
}
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class IssueService method setTags.
public Collection<String> setTags(String issueKey, Collection<String> tags) {
userSession.checkLoggedIn();
DbSession session = dbClient.openSession(false);
try {
DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
if (issueFieldsSetter.setTags(issue, tags, context)) {
issueUpdater.saveIssue(session, issue, context, null);
}
return issue.tags();
} finally {
session.close();
}
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class BulkChangeAction method executeBulkChange.
private BulkChangeResult executeBulkChange(DbSession dbSession, Request request) {
BulkChangeData bulkChangeData = new BulkChangeData(dbSession, request);
BulkChangeResult result = new BulkChangeResult(bulkChangeData.issues.size());
IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
List<DefaultIssue> items = bulkChangeData.issues.stream().filter(bulkChange(issueChangeContext, bulkChangeData, result)).collect(MoreCollectors.toList());
issueStorage.save(dbSession, items);
refreshLiveMeasures(dbSession, bulkChangeData, result);
Set<String> assigneeUuids = items.stream().map(DefaultIssue::assignee).filter(Objects::nonNull).collect(Collectors.toSet());
Map<String, UserDto> userDtoByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, u -> u));
String authorUuid = requireNonNull(userSession.getUuid(), "User uuid cannot be null");
UserDto author = dbClient.userDao().selectByUuid(dbSession, authorUuid);
checkState(author != null, "User with uuid '%s' does not exist");
sendNotification(items, bulkChangeData, userDtoByUuid, author);
return result;
}
Aggregations