Search in sources :

Example 6 with IssueDto

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

the class SearchResponseFormat method formatIssues.

private List<Issues.Issue> formatIssues(Set<SearchAdditionalField> fields, SearchResponseData data) {
    List<Issues.Issue> result = new ArrayList<>();
    Issues.Issue.Builder issueBuilder = Issues.Issue.newBuilder();
    for (IssueDto dto : data.getIssues()) {
        issueBuilder.clear();
        formatIssue(issueBuilder, dto, data);
        if (fields.contains(SearchAdditionalField.ACTIONS)) {
            formatIssueActions(data, issueBuilder, dto);
        }
        if (fields.contains(SearchAdditionalField.TRANSITIONS)) {
            formatIssueTransitions(data, issueBuilder, dto);
        }
        if (fields.contains(SearchAdditionalField.COMMENTS)) {
            formatIssueComments(data, issueBuilder, dto);
        }
        result.add(issueBuilder.build());
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) IssueDto(org.sonar.db.issue.IssueDto)

Example 7 with IssueDto

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

the class SearchResponseLoader method loadActionsAndTransitions.

private void loadActionsAndTransitions(Collector collector, SearchResponseData result) {
    if (collector.contains(ACTIONS) || collector.contains(TRANSITIONS)) {
        for (IssueDto dto : result.getIssues()) {
            // so that IssueDto can be used.
            if (collector.contains(ACTIONS)) {
                result.addActions(dto.getKey(), actionService.listAvailableActions(dto));
            }
            if (collector.contains(TRANSITIONS)) {
                // TODO workflow and action engines must not depend on org.sonar.api.issue.Issue but on a generic interface
                DefaultIssue issue = dto.toDefaultIssue();
                result.addTransitions(issue.key(), transitionService.listTransitions(issue));
            }
        }
    }
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 8 with IssueDto

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

the class IntegrateIssuesVisitorTest method addBaseIssue.

private void addBaseIssue(RuleKey ruleKey) {
    ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY);
    ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, file);
    RuleDto ruleDto = RuleTesting.newDto(ruleKey);
    dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), ruleDto);
    ruleRepositoryRule.add(ruleKey);
    IssueDto issue = IssueTesting.newDto(ruleDto, file, project).setKee("ISSUE").setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR);
    dbTester.getDbClient().issueDao().insert(dbTester.getSession(), issue);
    dbTester.getSession().commit();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto)

Example 9 with IssueDto

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

the class UpdateConflictResolverTest method should_keep_changes_made_by_user.

@Test
public void should_keep_changes_made_by_user() {
    DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setRuleKey(RuleKey.of("squid", "AvoidCycles")).setComponentKey("struts:org.apache.struts.Action").setNew(false);
    // Before starting scan
    issue.setAssignee(null);
    issue.setCreationDate(DateUtils.parseDate("2012-01-01"));
    issue.setUpdateDate(DateUtils.parseDate("2012-02-02"));
    // Changed by scan
    issue.setLine(200);
    issue.setSeverity(Severity.BLOCKER);
    issue.setManualSeverity(false);
    issue.setAuthorLogin("simon");
    issue.setChecksum("CHECKSUM-ABCDE");
    issue.setResolution(null);
    issue.setStatus(Issue.STATUS_REOPENED);
    // Issue as seen and changed by end-user
    IssueDto dbIssue = new IssueDto().setKee("ABCDE").setRuleId(10).setRuleKey("squid", "AvoidCycles").setComponentUuid("100").setComponentKey("struts:org.apache.struts.Action").setLine(10).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_RESOLVED).setAssignee("arthur").setSeverity(Severity.MAJOR).setManualSeverity(false);
    new UpdateConflictResolver().mergeFields(dbIssue, issue);
    assertThat(issue.key()).isEqualTo("ABCDE");
    assertThat(issue.componentKey()).isEqualTo("struts:org.apache.struts.Action");
    // Scan wins on :
    assertThat(issue.line()).isEqualTo(200);
    assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
    assertThat(issue.manualSeverity()).isFalse();
    // User wins on :
    assertThat(issue.assignee()).isEqualTo("arthur");
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.status()).isEqualTo(Issue.STATUS_RESOLVED);
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 10 with IssueDto

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

the class PersistIssuesStepTest method insert_new_issue.

@Test
public void insert_new_issue() {
    RuleDto rule = RuleTesting.newDto(RuleKey.of("xoo", "S01"));
    dbClient.ruleDao().insert(session, rule);
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    dbClient.componentDao().insert(session, project);
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    dbClient.componentDao().insert(session, file);
    session.commit();
    issueCache.newAppender().append(new DefaultIssue().setKey("ISSUE").setType(RuleType.CODE_SMELL).setRuleKey(rule.getKey()).setComponentUuid(file.uuid()).setProjectUuid(project.uuid()).setSeverity(Severity.BLOCKER).setStatus(Issue.STATUS_OPEN).setNew(true).setType(RuleType.BUG)).close();
    step.execute();
    IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE");
    assertThat(result.getKey()).isEqualTo("ISSUE");
    assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
    assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
    assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
    assertThat(result.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(result.getStatus()).isEqualTo(Issue.STATUS_OPEN);
    assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

IssueDto (org.sonar.db.issue.IssueDto)134 Test (org.junit.Test)117 ComponentDto (org.sonar.db.component.ComponentDto)48 RuleDto (org.sonar.db.rule.RuleDto)28 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)19 UserDto (org.sonar.db.user.UserDto)18 WsTester (org.sonar.server.ws.WsTester)18 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)15 FieldDiffs (org.sonar.core.issue.FieldDiffs)14 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)14 ChangelogWsResponse (org.sonarqube.ws.Issues.ChangelogWsResponse)12 TestResponse (org.sonar.server.ws.TestResponse)9 Request (org.sonar.api.server.ws.Request)8 Response (org.sonar.api.server.ws.Response)8 DefaultIssue (org.sonar.core.issue.DefaultIssue)8 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)8 TestRequest (org.sonar.server.ws.TestRequest)8 Date (java.util.Date)6 DbSession (org.sonar.db.DbSession)5 IssueDao (org.sonar.db.issue.IssueDao)4