Search in sources :

Example 66 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class ShowAction method loadUsers.

private Users loadUsers(DbSession dbSession, IssueDto hotspot) {
    UserDto assignee = ofNullable(hotspot.getAssigneeUuid()).map(uuid -> dbClient.userDao().selectByUuid(dbSession, uuid)).orElse(null);
    UserDto author = ofNullable(hotspot.getAuthorLogin()).map(login -> {
        if (assignee != null && assignee.getLogin().equals(login)) {
            return assignee;
        }
        return dbClient.userDao().selectByLogin(dbSession, login);
    }).orElse(null);
    return new Users(assignee, author);
}
Also used : IssueChangeWSSupport(org.sonar.server.issue.IssueChangeWSSupport) ShowWsResponse(org.sonarqube.ws.Hotspots.ShowWsResponse) SecurityStandards(org.sonar.server.security.SecurityStandards) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) Function(java.util.function.Function) DbSession(org.sonar.db.DbSession) HashSet(java.util.HashSet) Request(org.sonar.api.server.ws.Request) Uuids(org.sonar.core.util.Uuids) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Sets.difference(com.google.common.collect.Sets.difference) DbIssues(org.sonar.db.protobuf.DbIssues) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) WebService(org.sonar.api.server.ws.WebService) Locations(org.sonar.db.protobuf.DbIssues.Locations) Collections.singleton(java.util.Collections.singleton) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) Load(org.sonar.server.issue.IssueChangeWSSupport.Load) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableSet.copyOf(com.google.common.collect.ImmutableSet.copyOf) Hotspots(org.sonarqube.ws.Hotspots) Optional.ofNullable(java.util.Optional.ofNullable) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Common(org.sonarqube.ws.Common) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) ComponentDto(org.sonar.db.component.ComponentDto) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) Stream(java.util.stream.Stream) UserRole(org.sonar.api.web.UserRole) UserResponseFormatter(org.sonar.server.issue.ws.UserResponseFormatter) RuleKey(org.sonar.api.rule.RuleKey) Optional(java.util.Optional) HotspotRuleDescription(org.sonar.server.rule.HotspotRuleDescription) CheckForNull(javax.annotation.CheckForNull) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) UserDto(org.sonar.db.user.UserDto)

Example 67 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String hotspotKey = request.mandatoryParam(PARAM_HOTSPOT_KEY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
        Components components = loadComponents(dbSession, hotspot);
        Users users = loadUsers(dbSession, hotspot);
        RuleDefinitionDto rule = loadRule(dbSession, hotspot);
        ShowWsResponse.Builder responseBuilder = ShowWsResponse.newBuilder();
        formatHotspot(responseBuilder, hotspot, users);
        formatComponents(components, responseBuilder);
        formatRule(responseBuilder, rule);
        formatTextRange(responseBuilder, hotspot);
        formatFlows(dbSession, responseBuilder, hotspot);
        FormattingContext formattingContext = formatChangeLogAndComments(dbSession, hotspot, users, components, responseBuilder);
        formatUsers(responseBuilder, users, formattingContext);
        writeProtobuf(responseBuilder.build(), request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) ShowWsResponse(org.sonarqube.ws.Hotspots.ShowWsResponse) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto)

Example 68 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class ChangeStatusAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    hotspotWsSupport.checkLoggedIn();
    String hotspotKey = request.mandatoryParam(PARAM_HOTSPOT_KEY);
    String newStatus = request.mandatoryParam(PARAM_STATUS);
    String newResolution = resolutionParam(request, newStatus);
    try (DbSession dbSession = dbClient.openSession(false)) {
        IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
        hotspotWsSupport.loadAndCheckProject(dbSession, hotspot, UserRole.SECURITYHOTSPOT_ADMIN);
        if (needStatusUpdate(hotspot, newStatus, newResolution)) {
            String transitionKey = toTransitionKey(newStatus, newResolution);
            doTransition(dbSession, hotspot, transitionKey, trimToNull(request.param(PARAM_COMMENT)));
        }
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueDto(org.sonar.db.issue.IssueDto)

Example 69 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class ExportIssuesChangelogStepTest method insertIssue.

private void insertIssue(String projectUuid, String uuid, String status) {
    IssueDto dto = new IssueDto().setKee(uuid).setProjectUuid(projectUuid).setStatus(status);
    dbClient.issueDao().insert(dbSession, dto);
    dbSession.commit();
}
Also used : IssueDto(org.sonar.db.issue.IssueDto)

Example 70 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class PersistIssuesStepTest method close_issue.

@Test
public void close_issue() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = db.rules().insert();
    IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setCreatedAt(NOW - 1_000_000_000L).setUpdatedAt(NOW - 1_000_000_000L));
    DiskCache.CacheAppender issueCacheAppender = protoIssueCache.newAppender();
    issueCacheAppender.append(issue.toDefaultIssue().setStatus(STATUS_CLOSED).setResolution(RESOLUTION_FIXED).setSelectedAt(NOW).setNew(false).setChanged(true)).close();
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get();
    assertThat(issueReloaded.getStatus()).isEqualTo(STATUS_CLOSED);
    assertThat(issueReloaded.getResolution()).isEqualTo(RESOLUTION_FIXED);
    assertThat(context.getStatistics().getAll()).contains(entry("inserts", "0"), entry("updates", "1"), entry("merged", "0"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) DiskCache(org.sonar.ce.task.projectanalysis.util.cache.DiskCache) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Aggregations

IssueDto (org.sonar.db.issue.IssueDto)478 Test (org.junit.Test)425 ComponentDto (org.sonar.db.component.ComponentDto)324 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)213 UserDto (org.sonar.db.user.UserDto)136 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)77 TestRequest (org.sonar.server.ws.TestRequest)66 Date (java.util.Date)60 Hotspots (org.sonarqube.ws.Hotspots)57 DefaultIssue (org.sonar.core.issue.DefaultIssue)55 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)53 NotFoundException (org.sonar.server.exceptions.NotFoundException)51 DbClient (org.sonar.db.DbClient)50 List (java.util.List)49 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)49 Rule (org.junit.Rule)49 System2 (org.sonar.api.utils.System2)49 DbTester (org.sonar.db.DbTester)49 RuleDto (org.sonar.db.rule.RuleDto)49 IntStream (java.util.stream.IntStream)48