Search in sources :

Example 21 with IssueChangeContext

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

the class DoTransitionAction method doTransition.

private SearchResponseData doTransition(DbSession session, IssueDto issueDto, String transitionKey) {
    DefaultIssue defaultIssue = issueDto.toDefaultIssue();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
    transitionService.checkTransitionPermission(transitionKey, defaultIssue);
    if (transitionService.doTransition(defaultIssue, context, transitionKey)) {
        return issueUpdater.saveIssueAndPreloadSearchResponseData(session, defaultIssue, context, true);
    }
    return new SearchResponseData(issueDto);
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 22 with IssueChangeContext

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

the class SetSeverityAction method setType.

private SearchResponseData setType(DbSession session, String issueKey, String severity) {
    IssueDto issueDto = issueFinder.getByKey(session, issueKey);
    DefaultIssue issue = issueDto.toDefaultIssue();
    userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid());
    if (issueFieldsSetter.setManualSeverity(issue, severity, context)) {
        return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, true);
    }
    return new SearchResponseData(issueDto);
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 23 with IssueChangeContext

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

the class SetTypeAction method setType.

private SearchResponseData setType(DbSession session, String issueKey, RuleType ruleType) {
    IssueDto issueDto = issueFinder.getByKey(session, issueKey);
    DefaultIssue issue = issueDto.toDefaultIssue();
    userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
    IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
    if (issueFieldsSetter.setType(issue, ruleType, context)) {
        return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, true);
    }
    return new SearchResponseData(issueDto);
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 24 with IssueChangeContext

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

the class ProjectTrackerBaseLazyInput method migrateIssuesToTheRoot.

private Collection<? extends DefaultIssue> migrateIssuesToTheRoot(List<DefaultIssue> issuesOnModule, String modulePath) {
    for (DefaultIssue i : issuesOnModule) {
        // changes the issue's component uuid, add a change and set issue as changed to enforce it is persisted to DB
        IssueChangeContext context = IssueChangeContext.createUser(new Date(analysisMetadataHolder.getAnalysisDate()), null);
        if (StringUtils.isNotBlank(modulePath)) {
            issueUpdater.setMessage(i, "[" + modulePath + "] " + i.getMessage(), context);
        }
        issueUpdater.setIssueMoved(i, component.getUuid(), context);
        // other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only
        i.setComponentKey(component.getKey());
        i.setModuleUuid(null);
        i.setModuleUuidPath(null);
    }
    return issuesOnModule;
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 25 with IssueChangeContext

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

the class AssignAction method assign.

private void assign(String hotspotKey, String login, @Nullable String comment) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        IssueDto hotspotDto = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
        checkIfHotspotToReview(hotspotDto);
        hotspotWsSupport.loadAndCheckProject(dbSession, hotspotDto, UserRole.USER);
        UserDto assignee = isNullOrEmpty(login) ? null : getAssignee(dbSession, login);
        IssueChangeContext context = hotspotWsSupport.newIssueChangeContext();
        DefaultIssue defaultIssue = hotspotDto.toDefaultIssue();
        if (comment != null) {
            issueFieldsSetter.addComment(defaultIssue, comment, context);
        }
        if (assignee != null) {
            checkAssigneeProjectPermission(dbSession, assignee, hotspotDto.getProjectUuid());
        }
        if (issueFieldsSetter.assign(defaultIssue, assignee, context)) {
            issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, false);
        }
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) UserDto(org.sonar.db.user.UserDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Aggregations

IssueChangeContext (org.sonar.core.issue.IssueChangeContext)34 DefaultIssue (org.sonar.core.issue.DefaultIssue)33 Date (java.util.Date)30 IssueDto (org.sonar.db.issue.IssueDto)23 Test (org.junit.Test)19 ComponentDto (org.sonar.db.component.ComponentDto)17 DbSession (org.sonar.db.DbSession)13 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)12 UserDto (org.sonar.db.user.UserDto)12 DbClient (org.sonar.db.DbClient)9 WebIssueStorage (org.sonar.server.issue.WebIssueStorage)9 IssuesChangesNotificationBuilder (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder)9 ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)9 UserChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange)9 IssuesChangesNotificationSerializer (org.sonar.server.issue.notification.IssuesChangesNotificationSerializer)9 NotificationManager (org.sonar.server.notification.NotificationManager)9 RuleStatus (org.sonar.api.rule.RuleStatus)8 BLOCKER (org.sonar.api.rule.Severity.BLOCKER)8 System2 (org.sonar.api.utils.System2)8 BranchType (org.sonar.db.component.BranchType)8