Search in sources :

Example 71 with DefaultIssue

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

the class BaseIssuesLoader method loadForComponentUuid.

public List<DefaultIssue> loadForComponentUuid(String componentUuid) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<DefaultIssue> result = new ArrayList<>();
        dbSession.getMapper(IssueMapper.class).selectNonClosedByComponentUuid(componentUuid, resultContext -> {
            DefaultIssue issue = ((IssueDto) resultContext.getResultObject()).toDefaultIssue();
            if (!isActive(issue.ruleKey()) || ruleRepository.getByKey(issue.ruleKey()).getStatus() == RuleStatus.REMOVED) {
                issue.setOnDisabledRule(true);
                issue.setBeingClosed(true);
            }
            issue.setSelectedAt(System.currentTimeMillis());
            result.add(issue);
        });
        return result;
    }
}
Also used : DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList) IssueMapper(org.sonar.db.issue.IssueMapper) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 72 with DefaultIssue

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

the class IntegrateIssuesVisitor method fillNewOpenIssues.

private void fillNewOpenIssues(Component component, Tracking<DefaultIssue, DefaultIssue> tracking, DiskCache<DefaultIssue>.DiskAppender<DefaultIssue> cacheAppender) {
    for (DefaultIssue issue : tracking.getUnmatchedRaws()) {
        issueLifecycle.initNewOpenIssue(issue);
        process(component, issue, cacheAppender);
    }
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 73 with DefaultIssue

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

the class PersistIssuesStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(true);
        CloseableIterator<DefaultIssue> issues = issueCache.traverse()) {
        IssueMapper mapper = dbSession.getMapper(IssueMapper.class);
        IssueChangeMapper changeMapper = dbSession.getMapper(IssueChangeMapper.class);
        while (issues.hasNext()) {
            DefaultIssue issue = issues.next();
            boolean saved = persistIssueIfRequired(mapper, issue);
            if (saved) {
                insertChanges(changeMapper, issue);
            }
        }
        dbSession.flushStatements();
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueMapper(org.sonar.db.issue.IssueMapper) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Example 74 with DefaultIssue

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

the class SendIssueNotificationsStep method doExecute.

private void doExecute(Component project) {
    NewIssuesStatistics newIssuesStats = new NewIssuesStatistics();
    CloseableIterator<DefaultIssue> issues = issueCache.traverse();
    try {
        processIssues(newIssuesStats, issues, project);
    } finally {
        issues.close();
    }
    if (newIssuesStats.hasIssues()) {
        long analysisDate = analysisMetadataHolder.getAnalysisDate();
        sendNewIssuesNotification(newIssuesStats, project, analysisDate);
        sendNewIssuesNotificationToAssignees(newIssuesStats, project, analysisDate);
    }
}
Also used : NewIssuesStatistics(org.sonar.server.issue.notification.NewIssuesStatistics) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 75 with DefaultIssue

use of org.sonar.core.issue.DefaultIssue 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.getLogin());
        DefaultIssue defaultIssue = issueDto.toDefaultIssue();
        issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context);
        issueUpdater.saveIssue(dbSession, defaultIssue, context, wsRequest.getText());
        responseWriter.write(defaultIssue.key(), request, response);
    }
}
Also used : AddCommentRequest(org.sonarqube.ws.client.issue.AddCommentRequest) DbSession(org.sonar.db.DbSession) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Aggregations

DefaultIssue (org.sonar.core.issue.DefaultIssue)140 Test (org.junit.Test)120 Date (java.util.Date)27 ActiveRule (org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule)15 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)14 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)8 IssueDto (org.sonar.db.issue.IssueDto)8 DbSession (org.sonar.db.DbSession)6 ComponentDto (org.sonar.db.component.ComponentDto)5 Issue (org.sonar.api.issue.Issue)4 FieldDiffs (org.sonar.core.issue.FieldDiffs)4 ArrayList (java.util.ArrayList)3 RuleKey (org.sonar.api.rule.RuleKey)3 User (org.sonar.api.user.User)3 IssueChangeMapper (org.sonar.db.issue.IssueChangeMapper)3 IssueMapper (org.sonar.db.issue.IssueMapper)3 RuleDto (org.sonar.db.rule.RuleDto)3 IssueChangeNotification (org.sonar.server.issue.notification.IssueChangeNotification)3 DefaultUser (org.sonar.core.user.DefaultUser)2 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)2