]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16316 Include issues with 'diff' issue changes into csv result
authorJacek <jacek.poreda@sonarsource.com>
Tue, 31 May 2022 12:15:59 +0000 (14:15 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 1 Jun 2022 20:03:02 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java

index ea6b2bb051fadb5ceb5a431d29e46a855c35ee65..dc8be684288cff5e316f66c13a9b6a302945e2e7 100644 (file)
@@ -5,8 +5,27 @@
 <mapper namespace="org.sonar.db.report.RegulatoryReportMapper">
   <resultMap id="issueResultMap" type="org.sonar.db.report.IssueFindingDto" autoMapping="true">
     <id property="kee" column="kee"/>
-    <collection property="comments" ofType="string">
-      <result column="change_data"/>
+    <result property="severity" column="severity"/>
+    <result property="isManualSeverity" column="isManualSeverity"/>
+    <result property="message" column="message"/>
+    <result property="line" column="line"/>
+    <result property="status" column="status"/>
+    <result property="resolution" column="resolution"/>
+    <result property="fileName" column="fileName"/>
+    <result property="type" column="type"/>
+    <result property="ruleRepository" column="ruleRepository"/>
+    <result property="ruleKey" column="ruleKey"/>
+    <result property="securityStandards" column="securityStandards"/>
+    <result property="ruleName" column="ruleName"/>
+    <result property="creationDate" column="creationDate"/>
+    <result property="isNewCodeReferenceIssue" column="isNewCodeReferenceIssue"/>
+    <!--Usage of notNullColumn allows to skip creating objects which are not matching discriminator-->
+    <collection property="comments" ofType="string" notNullColumn="issue_change_kee">
+      <discriminator javaType="string" column="change_type" >
+        <case value="comment">
+          <result column="change_data"/>
+        </case>
+      </discriminator>
     </collection>
   </resultMap>
 
@@ -18,7 +37,6 @@
     i.line as line,
     i.status as status,
     i.resolution as resolution,
-    p.kee as componentKey,
     p.path as fileName,
     i.issue_type as type,
     r.plugin_name as ruleRepository,
     <include refid="org.sonar.db.issue.IssueMapper.isNewCodeReferenceIssue"/>
   </sql>
 
-  <select id="scrollIssues" parameterType="String" resultMap="issueResultMap" resultOrdered="true" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+  <select id="scrollIssues" parameterType="String" resultMap="issueResultMap" resultOrdered="true"
+    fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
     select
     <include refid="issueColumns"/>,
+    ic.kee as issue_change_kee,
     ic.change_data,
-    ic.issue_change_creation_date
+    ic.change_type
     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
   </select>
index e500e8bfa13854566a3f370195d73e0da2a2ff26..ca2d6391b50b5a57335cbb234edc4a8493078b70 100644 (file)
@@ -64,8 +64,11 @@ public class RegulatoryReportDaoTest {
     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"));
+    db.issues().insertChange(issue1, ic -> ic.setChangeData("c2").setIssueChangeCreationDate(2000L).setChangeType("comment"));
+    db.issues().insertChange(issue1, ic -> ic.setChangeData("c3").setIssueChangeCreationDate(3000L).setChangeType("diff").setKey(null));
+
+    db.issues().insertChange(issue2, ic -> ic.setChangeData("c4").setIssueChangeCreationDate(4000L).setChangeType("diff").setKey(null));
 
     // not returned
     IssueDto issue4 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("CLOSED").setResolution(null));
@@ -89,6 +92,10 @@ public class RegulatoryReportDaoTest {
     assertThat(issue.getType().getDbConstant()).isEqualTo(issue1.getType());
     assertThat(issue.getSecurityStandards()).isEqualTo(rule.getSecurityStandards());
     assertThat(issue.isManualSeverity()).isEqualTo(issue1.isManualSeverity());
+    assertThat(issue.getCreationDate()).isEqualTo(issue1.getIssueCreationTime());
+    assertThat(issue.isNewCodeReferenceIssue()).isEqualTo(issue1.isNewCodeReferenceIssue());
+    assertThat(issue.getResolution()).isEqualTo(issue1.getResolution());
+    assertThat(issue.getStatus()).isEqualTo(issue1.getStatus());
     assertThat(issue.getComments()).containsExactly("c1", "c2");
   }
 }