Search in sources :

Example 86 with IssueDto

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

the class WebIssueStorage method doInsert.

private IssueDto doInsert(DbSession session, long now, DefaultIssue issue) {
    ComponentDto component = component(session, issue);
    ComponentDto project = project(session, issue);
    String ruleUuid = getRuleUuid(issue).orElseThrow(() -> new IllegalStateException("Rule not found: " + issue.ruleKey()));
    IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleUuid, now);
    getDbClient().issueDao().insert(session, dto);
    return dto;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto)

Example 87 with IssueDto

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

the class WebIssueStorage method insert.

/**
 * @return the keys of the inserted issues
 */
private Collection<IssueDto> insert(DbSession session, Iterable<DefaultIssue> issuesToInsert, long now) {
    List<IssueDto> inserted = newArrayList();
    int count = 0;
    IssueChangeMapper issueChangeMapper = session.getMapper(IssueChangeMapper.class);
    for (DefaultIssue issue : issuesToInsert) {
        IssueDto issueDto = doInsert(session, now, issue);
        inserted.add(issueDto);
        insertChanges(issueChangeMapper, issue, uuidFactory);
        if (count > BatchSession.MAX_BATCH_SIZE) {
            session.commit();
            count = 0;
        }
        count++;
    }
    session.commit();
    return inserted;
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Example 88 with IssueDto

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

the class WebIssueStorage method doUpdate.

private IssueDto doUpdate(DbSession session, long now, DefaultIssue issue) {
    IssueDto dto = IssueDto.toDtoForUpdate(issue, now);
    getDbClient().issueDao().update(session, dto);
    // Rule id does not exist in DefaultIssue
    getRuleUuid(issue).ifPresent(dto::setRuleUuid);
    return dto;
}
Also used : IssueDto(org.sonar.db.issue.IssueDto)

Example 89 with IssueDto

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

the class IssuesActionTest method return_issues_by_project_and_branch.

@Test
public void return_issues_by_project_and_branch() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    addPermissionTo(project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
    ComponentDto file = db.components().insertComponent(newFileDto(branch));
    IssueDto issueOnFile = db.issues().insert(rule, branch, file, i -> i.setType(randomRuleTypeExceptHotspot()));
    IssueDto issueOnBranch = db.issues().insert(rule, branch, branch, i -> i.setType(randomRuleTypeExceptHotspot()));
    assertResult(project.getKey(), "my_branch", tuple(issueOnFile.getKey(), branch.getKey()), tuple(issueOnBranch.getKey(), branch.getKey()));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 90 with IssueDto

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

the class IssuesActionTest method test_fields_with_non_null_values.

@Test
public void test_fields_with_non_null_values() throws Exception {
    UserDto user = db.users().insertUser(u -> u.setLogin("simon").setName("Simon").setEmail("simon@email.com"));
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module, null));
    IssueDto issue = db.issues().insert(rule, project, file, i -> i.setSeverity("BLOCKER").setStatus("OPEN").setType(BUG).setManualSeverity(true).setResolution("FIXED").setMessage("the message").setLine(10).setChecksum("ABC").setAssigneeUuid(user.getUuid()));
    addPermissionTo(project);
    ServerIssue serverIssue = call(project.getKey());
    assertThat(serverIssue.getKey()).isEqualTo(issue.getKey());
    assertThat(serverIssue.getModuleKey()).isEqualTo(module.getKey());
    assertThat(serverIssue.getRuleRepository()).isEqualTo(rule.getRepositoryKey());
    assertThat(serverIssue.getRuleKey()).isEqualTo(rule.getRuleKey());
    assertThat(serverIssue.getStatus()).isEqualTo("OPEN");
    assertThat(serverIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(serverIssue.getType()).isEqualTo(BUG.name());
    assertThat(serverIssue.getManualSeverity()).isTrue();
    assertThat(serverIssue.getPath()).isEqualTo(file.path());
    assertThat(serverIssue.getLine()).isEqualTo(issue.getLine());
    assertThat(serverIssue.getMsg()).isEqualTo(issue.getMessage());
    assertThat(serverIssue.getResolution()).isEqualTo(issue.getResolution());
    assertThat(serverIssue.getChecksum()).isEqualTo(issue.getChecksum());
    assertThat(serverIssue.getAssigneeLogin()).isEqualTo(user.getLogin());
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) ServerIssue(org.sonar.scanner.protocol.input.ScannerInput.ServerIssue) 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