Search in sources :

Example 1 with IssueChangeDto

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

the class NewEffortAggregator method beforeComponent.

@Override
public void beforeComponent(Component component) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<IssueChangeDto> changes = dbClient.issueChangeDao().selectChangelogOfNonClosedIssuesByComponent(dbSession, component.getUuid());
        for (IssueChangeDto change : changes) {
            changesByIssueUuid.put(change.getIssueKey(), change);
        }
    }
    counter = new NewEffortCounter(calculator);
    counterByComponentRef.put(component.getReportAttributes().getRef(), counter);
    for (Component child : component.getChildren()) {
        NewEffortCounter childSum = counterByComponentRef.remove(child.getReportAttributes().getRef());
        if (childSum != null) {
            counter.add(childSum);
        }
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) DbSession(org.sonar.db.DbSession) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 2 with IssueChangeDto

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

the class SearchResponseLoader method loadComments.

private void loadComments(Collector collector, DbSession dbSession, SearchResponseData result) {
    if (collector.contains(COMMENTS)) {
        List<IssueChangeDto> comments = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, collector.getIssueKeys(), IssueChangeDto.TYPE_COMMENT);
        result.setComments(comments);
        for (IssueChangeDto comment : comments) {
            collector.add(USERS, comment.getUserLogin());
            if (canEditOrDelete(comment)) {
                result.addUpdatableComment(comment.getKey());
            }
        }
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto)

Example 3 with IssueChangeDto

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

the class NewEffortCalculatorTest method guess_initial_debt_when_first_change_is_after_period.

@Test
public void guess_initial_debt_when_first_change_is_after_period() {
    // creation: 1d
    // after period: increased to 2d, then to 5d
    // -> new debt is 5d - 1d = 4d
    issue.setEffort(FIVE_DAYS).setCreationDate(new Date(PERIOD_DATE - 10000));
    List<IssueChangeDto> changelog = Arrays.asList(newDebtChangelog(ONE_DAY.toMinutes(), TWO_DAYS.toMinutes(), PERIOD_DATE + 20000), newDebtChangelog(TWO_DAYS.toMinutes(), FIVE_DAYS.toMinutes(), PERIOD_DATE + 30000));
    long newDebt = underTest.calculate(issue, changelog, PERIOD);
    assertThat(newDebt).isEqualTo(FIVE_DAYS.toMinutes() - ONE_DAY.toMinutes());
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) Date(java.util.Date) Test(org.junit.Test)

Example 4 with IssueChangeDto

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

the class SearchActionMediumTest method issue_with_comment_hidden.

@Test
public void issue_with_comment_hidden() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com"));
    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
    db.issueDao().insert(session, issue);
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCD").setChangeData("*My comment*").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("john").setCreatedAt(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCE").setChangeData("Another comment").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("fabrice").setCreatedAt(DateUtils.parseDateTime("2014-09-10T19:10:03+0000").getTime()));
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    userSessionRule.logIn("john");
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(PARAM_HIDE_COMMENTS, "true").execute();
    result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
    assertThat(result.outputAsString()).doesNotContain("fabrice");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) WsTester(org.sonar.server.ws.WsTester) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueChangeDao(org.sonar.db.issue.IssueChangeDao) Test(org.junit.Test)

Example 5 with IssueChangeDto

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

the class SearchActionMediumTest method issue_with_comments.

@Test
public void issue_with_comments() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("john").setName("John"));
    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
    db.issueDao().insert(session, issue);
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCD").setChangeData("*My comment*").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("john").setCreatedAt(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCE").setChangeData("Another comment").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("fabrice").setCreatedAt(DateUtils.parseDateTime("2014-09-10T12:00:00+0000").getTime()));
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    userSessionRule.logIn("john");
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam("additionalFields", "comments,users").execute();
    result.assertJson(this.getClass(), "issue_with_comments.json");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) WsTester(org.sonar.server.ws.WsTester) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueChangeDao(org.sonar.db.issue.IssueChangeDao) Test(org.junit.Test)

Aggregations

IssueChangeDto (org.sonar.db.issue.IssueChangeDto)23 Test (org.junit.Test)18 IssueDto (org.sonar.db.issue.IssueDto)15 Request (org.sonar.api.server.ws.Request)5 Response (org.sonar.api.server.ws.Response)5 TestRequest (org.sonar.server.ws.TestRequest)5 TestResponse (org.sonar.server.ws.TestResponse)5 Date (java.util.Date)4 IssueComment (org.sonar.api.issue.IssueComment)2 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)2 FieldDiffs (org.sonar.core.issue.FieldDiffs)2 ComponentDto (org.sonar.db.component.ComponentDto)2 IssueChangeDao (org.sonar.db.issue.IssueChangeDao)2 UserDto (org.sonar.db.user.UserDto)2 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)2 WsTester (org.sonar.server.ws.WsTester)2 DbSession (org.sonar.db.DbSession)1 Component (org.sonar.server.computation.task.projectanalysis.component.Component)1 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)1