]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20896 Adjust Gitlab vulnerabilities with new Clean Code Taxonomy
authorAlain Kermis <alain.kermis@sonarsource.com>
Thu, 26 Oct 2023 15:35:20 +0000 (17:35 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 30 Oct 2023 20:04:03 +0000 (20:04 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueListQuery.java
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml

index f65f56f6129becc889381f62ea9736c85a838f99..d1f9ba2bb4466a0771eb7e2ec19bef399584e4f5 100644 (file)
@@ -874,6 +874,19 @@ public class IssueDaoIT {
     assertThat(results.stream().toList()).containsExactlyInAnyOrderElementsOf(expectedKeys);
   }
 
+  @Test
+  public void selectIssueKeysByQuery_whenFilteredWithSoftwareQualities_shouldGetThoseIssuesOnly() {
+    prepareTables(); // One of the issues has software quality impact: SECURITY
+
+    List<String> results = underTest.selectIssueKeysByQuery(
+      db.getSession(),
+      newIssueListQueryBuilder().project(PROJECT_KEY).softwareQualities(List.of("SECURITY")).build(),
+      Pagination.forPage(1).andSize(10));
+
+    List<String> expectedKeys = List.of("I1");
+    assertThat(results.stream().toList()).containsExactlyInAnyOrderElementsOf(expectedKeys);
+  }
+
   @Test
   public void updateIfBeforeSelectedDate_whenCalledWithBeforeSelectDate_shouldUpdateImpacts() {
     prepareTables();
index 217f047ab6c1bdb8835a43b3bbb71fe6e03802cb..185692e70e836a36e10057df4e8ddb733c6d7c62 100644 (file)
@@ -38,6 +38,7 @@ public class IssueListQuery {
   private final Collection<Integer> types;
   private final Collection<String> statuses;
   private final Collection<String> resolutions;
+  private final Collection<String> softwareQualities;
 
   private IssueListQuery(IssueListQueryBuilder issueListQueryBuilder) {
     this.project = issueListQueryBuilder.project;
@@ -56,6 +57,9 @@ public class IssueListQuery {
     this.resolutions = ofNullable(issueListQueryBuilder.resolutions)
       .map(Collections::unmodifiableCollection)
       .orElse(emptyList());
+    this.softwareQualities = ofNullable(issueListQueryBuilder.softwareQualities)
+      .map(Collections::unmodifiableCollection)
+      .orElse(emptyList());
   }
 
   public String getProject() {
@@ -98,6 +102,10 @@ public class IssueListQuery {
     return resolutions;
   }
 
+  public Collection<String> getSoftwareQualities() {
+    return softwareQualities;
+  }
+
   public static final class IssueListQueryBuilder {
     private String project;
     private String branch;
@@ -109,6 +117,7 @@ public class IssueListQuery {
     private Collection<Integer> types;
     private Collection<String> statuses;
     private Collection<String> resolutions;
+    private Collection<String> softwareQualities;
 
     private IssueListQueryBuilder() {
     }
@@ -167,6 +176,11 @@ public class IssueListQuery {
       return this;
     }
 
+    public IssueListQueryBuilder softwareQualities(Collection<String> softwareQualities) {
+      this.softwareQualities = softwareQualities;
+      return this;
+    }
+
     public IssueListQuery build() {
       return new IssueListQuery(this);
     }
index 5332d6877218d277adb7ef3cde33c022d6a82a6f..9e042bc90f794eb4cd7d93a11287ce939e994080 100644 (file)
     inner join components root on root.uuid=i.project_uuid
     inner join project_branches pb on pb.uuid=i.project_uuid
     left join new_code_reference_issues n on i.kee = n.issue_key
+    <if test="query.softwareQualities.size() > 0">
+      left join issues_impacts im on i.kee = im.issue_key
+    </if>
     <where>
       <if test="query.project != null">
         root.kee = #{query.project,jdbcType=VARCHAR}
           #{type,jdbcType=VARCHAR}
         </foreach>
       </if>
+      <if test="query.softwareQualities.size() > 0">
+        AND im.software_quality IN
+        <foreach collection="query.softwareQualities" open="(" close=")" item="type" separator=",">
+          #{type,jdbcType=VARCHAR}
+        </foreach>
+      </if>
       <if test="query.statuses.size() > 0">
         AND i.status IN
         <foreach collection="query.statuses" open="(" close=")" item="status" separator=",">