Search in sources :

Example 6 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class SetSeverityAction method setType.

private void setType(DbSession session, String issueKey, String severity) {
    DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
    userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
    if (issueFieldsSetter.setManualSeverity(issue, severity, context)) {
        issueUpdater.saveIssue(session, issue, context, null);
    }
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 7 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class SetTypeAction method setType.

private void setType(DbSession session, String issueKey, RuleType ruleType) {
    DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
    userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
    if (issueFieldsSetter.setType(issue, ruleType, context)) {
        issueUpdater.saveIssue(session, issue, context, null);
    }
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 8 with IssueChangeContext

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();
    }
}
Also used : DbSession(org.sonar.db.DbSession) User(org.sonar.api.user.User) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 9 with IssueChangeContext

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();
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 10 with IssueChangeContext

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();
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) MovedFilesRepository(org.sonar.server.computation.task.projectanalysis.filemove.MovedFilesRepository) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)11 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)11 DefaultIssue (org.sonar.core.issue.DefaultIssue)10 Test (org.junit.Test)5 DbSession (org.sonar.db.DbSession)3 ComponentDto (org.sonar.db.component.ComponentDto)2 IssueDto (org.sonar.db.issue.IssueDto)2 RuleDto (org.sonar.db.rule.RuleDto)2 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)2 User (org.sonar.api.user.User)1 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)1 MovedFilesRepository (org.sonar.server.computation.task.projectanalysis.filemove.MovedFilesRepository)1 IssueChangeNotification (org.sonar.server.issue.notification.IssueChangeNotification)1 AddCommentRequest (org.sonarqube.ws.client.issue.AddCommentRequest)1