From 6895f3582df8ae0b30bbc16b6a00e67ff4a1acac Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 23 May 2022 17:24:26 +0200 Subject: [PATCH] SONAR-16316 Add resolution and comments --- .../org/sonar/db/report/IssueFindingDto.java | 6 ++++++ .../sonar/db/report/RegulatoryReportMapper.xml | 17 +++++++++++++++-- .../db/report/RegulatoryReportDaoTest.java | 7 +++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/IssueFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/IssueFindingDto.java index b1fdfe9f761..6881a90177c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/report/IssueFindingDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/IssueFindingDto.java @@ -19,6 +19,7 @@ */ package org.sonar.db.report; +import java.util.List; import java.util.Set; import javax.annotation.CheckForNull; import org.sonar.api.rules.RuleType; @@ -40,6 +41,7 @@ public class IssueFindingDto { private String securityStandards; private boolean isNewCodeReferenceIssue; private long creationDate; + private List comments; public String getStatus() { return status; @@ -105,4 +107,8 @@ public class IssueFindingDto { public long getCreationDate() { return creationDate; } + + public List getComments() { + return comments; + } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml index c598bcc587c..50111cac536 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml @@ -3,6 +3,13 @@ + + + + + + + m.description as description, qgc.operator as operator, @@ -43,6 +50,7 @@ r.security_standards as securityStandards, r.name as ruleName, i.issue_creation_date as creationDate, + @@ -64,14 +72,19 @@ where oqp.uuid=#{qualityProfileUuid,jdbcType=VARCHAR} - select - + , + ic.change_data, + ic.issue_change_creation_date from issues i inner join rules r on r.uuid=i.rule_uuid inner join components p on p.uuid=i.component_uuid + left join issue_changes ic on ic.issue_key = i.kee left join new_code_reference_issues n on i.kee = n.issue_key where i.project_uuid=#{branchUuid,jdbcType=VARCHAR} + and (ic.change_type = 'comment' or ic.change_type is null) and i.status !='CLOSED' + order by i.kee, ic.issue_change_creation_date diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java index fba4390d17a..e2e96733c50 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java @@ -28,10 +28,12 @@ import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; +import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbTester; import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; +import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.project.ProjectDto; @@ -165,6 +167,10 @@ public class RegulatoryReportDaoTest { IssueDto issue2 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("CONFIRMED").setResolution(null)); IssueDto issue3 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("RESOLVED").setResolution(RESOLUTION_WONT_FIX)); + // comments + db.issues().insertChange(issue1, ic -> ic.setChangeData("c2").setIssueChangeCreationDate(2000L).setChangeType("comment")); + db.issues().insertChange(issue1, ic -> ic.setChangeData("c1").setIssueChangeCreationDate(1000L).setChangeType("comment")); + // not returned IssueDto issue4 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("CLOSED").setResolution(null)); ComponentDto otherProject = db.components().insertPrivateProject(); @@ -187,5 +193,6 @@ public class RegulatoryReportDaoTest { assertThat(issue.getType().getDbConstant()).isEqualTo(issue1.getType()); assertThat(issue.getSecurityStandards()).isEqualTo(rule.getSecurityStandards()); assertThat(issue.isManualSeverity()).isEqualTo(issue1.isManualSeverity()); + assertThat(issue.getComments()).containsExactly("c1", "c2"); } } -- 2.39.5