use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class AddCommentAction method handle.
@Override
public void handle(Request request, Response response) {
userSession.checkLoggedIn();
AddCommentRequest wsRequest = toWsRequest(request);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto issueDto = issueFinder.getByKey(dbSession, wsRequest.getIssue());
IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
DefaultIssue defaultIssue = issueDto.toDefaultIssue();
issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context);
SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, false);
responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response);
}
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class AddCommentAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
hotspotWsSupport.checkLoggedIn();
String hotspotKey = request.mandatoryParam(PARAM_HOTSPOT_KEY);
String comment = request.mandatoryParam(PARAM_COMMENT);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
hotspotWsSupport.loadAndCheckProject(dbSession, hotspot, UserRole.USER);
DefaultIssue defaultIssue = hotspot.toDefaultIssue();
IssueChangeContext context = hotspotWsSupport.newIssueChangeContext();
issueFieldsSetter.addComment(defaultIssue, comment, context);
issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, false);
response.noContent();
}
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class ChangeStatusActionTest method success_to_change_hostpot_to_review_into_reviewed_status.
@Test
@UseDataProvider("reviewedResolutionsAndExpectedTransitionKey")
public void success_to_change_hostpot_to_review_into_reviewed_status(String resolution, String expectedTransitionKey, boolean transitionDone) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.logIn().registerComponents(project).addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(STATUS_TO_REVIEW).setResolution(null));
when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone);
newRequest(hotspot, STATUS_REVIEWED, resolution, NO_COMMENT).execute().assertNoContent();
IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(now), userSessionRule.getUuid());
ArgumentCaptor<DefaultIssue> defaultIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
verify(transitionService).checkTransitionPermission(eq(expectedTransitionKey), defaultIssueCaptor.capture());
verify(transitionService).doTransition(defaultIssueCaptor.capture(), eq(issueChangeContext), eq(expectedTransitionKey));
if (transitionDone) {
verify(issueUpdater).saveIssueAndPreloadSearchResponseData(any(DbSession.class), defaultIssueCaptor.capture(), eq(issueChangeContext), eq(true));
// because it is mutated by FieldSetter and IssueUpdater, the same object must be passed to all methods
verifyAllSame3Objects(defaultIssueCaptor.getAllValues());
verifyNoInteractions(issueFieldsSetter);
} else {
verifyNoInteractions(issueUpdater, issueFieldsSetter);
}
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class IssueUpdaterTest method saveIssue_populates_specified_SearchResponseData_with_no_rule_but_with_project_and_component_if_rule_is_removed.
@Test
public void saveIssue_populates_specified_SearchResponseData_with_no_rule_but_with_project_and_component_if_rule_is_removed() {
RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED));
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = db.issues().insertIssue(rule, project, file);
DefaultIssue issue = issueDto.setSeverity(MAJOR).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
assertThat(preloadedSearchResponseData.getIssues()).hasSize(1);
assertThat(preloadedSearchResponseData.getIssues().iterator().next()).isNotSameAs(issueDto);
assertThat(preloadedSearchResponseData.getRules()).isNullOrEmpty();
assertThat(preloadedSearchResponseData.getComponents()).extracting(ComponentDto::uuid).containsOnly(project.uuid(), file.uuid());
}
use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.
the class IssueUpdaterTest method saveIssue_populates_specified_SearchResponseData_with_rule_project_and_component_retrieved_from_DB.
@Test
public void saveIssue_populates_specified_SearchResponseData_with_rule_project_and_component_retrieved_from_DB() {
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = db.issues().insertIssue(rule, project, file);
DefaultIssue issue = issueDto.setSeverity(MAJOR).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, true);
assertThat(preloadedSearchResponseData.getIssues()).hasSize(1);
assertThat(preloadedSearchResponseData.getIssues().iterator().next()).isNotSameAs(issueDto);
assertThat(preloadedSearchResponseData.getRules()).extracting(RuleDefinitionDto::getKey).containsOnly(rule.getKey());
assertThat(preloadedSearchResponseData.getComponents()).extracting(ComponentDto::uuid).containsOnly(project.uuid(), file.uuid());
assertThat(issueChangePostProcessor.calledComponents()).containsExactlyInAnyOrder(file);
}
Aggregations