aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorOrlovAlexander <alexander.orlov@sonarsource.com>2024-11-05 16:48:04 +0100
committersonartech <sonartech@sonarsource.com>2024-11-11 20:02:43 +0000
commit2659be50a7dee7cc410106fe861b0385340889b0 (patch)
treeb74a5261feaf6e2e6c94199db29b28834a5b95f2 /server/sonar-db-dao
parent191245551be3efdd1f2e9dbb6128cd3f252b951c (diff)
downloadsonarqube-2659be50a7dee7cc410106fe861b0385340889b0.tar.gz
sonarqube-2659be50a7dee7cc410106fe861b0385340889b0.zip
SONAR-23363 Database Migration for manual_severity flag
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java65
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/ImpactDto.java22
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml8
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl3
4 files changed, 78 insertions, 20 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java
index ef3a44abbb1..15758d0f49b 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java
@@ -20,7 +20,6 @@
package org.sonar.db.issue;
import java.security.SecureRandom;
-import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -184,10 +183,10 @@ class IssueDaoIT {
assertThat(issue.getEffectiveCleanCodeAttribute()).isEqualTo(RULE.getCleanCodeAttribute());
assertThat(issue.parseLocations()).isNull();
assertThat(issue.getImpacts())
- .extracting(ImpactDto::getSeverity, ImpactDto::getSoftwareQuality)
+ .extracting(ImpactDto::getSeverity, ImpactDto::getSoftwareQuality, ImpactDto::isManualSeverity)
.containsExactlyInAnyOrder(
- tuple(MEDIUM, RELIABILITY),
- tuple(LOW, SECURITY));
+ tuple(MEDIUM, RELIABILITY, false),
+ tuple(LOW, SECURITY, false));
assertThat(issue.getRuleDefaultImpacts())
.extracting(ImpactDto::getSeverity, ImpactDto::getSoftwareQuality)
.containsExactlyInAnyOrder(tuple(HIGH, MAINTAINABILITY));
@@ -238,7 +237,7 @@ class IssueDaoIT {
}
@Test
- void scrollIndexationIssues_shouldReturnDto() throws SQLException {
+ void scrollIndexationIssues_shouldReturnDto() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
RuleDto rule = db.rules().insert(r -> r.setRepositoryKey("java").setLanguage("java")
.replaceAllDefaultImpacts(List.of(new ImpactDto()
@@ -251,7 +250,7 @@ class IssueDaoIT {
ComponentDto branchA = db.components().insertProjectBranch(project, b -> b.setKey("branchA"));
ComponentDto fileA = db.components().insertComponent(newFileDto(branchA));
- IntStream.range(0, 100).forEach(i -> insertBranchIssue(branchA, fileA, rule, "A" + i, STATUS_OPEN, 1_340_000_000_000L));
+ IntStream.range(0, 100).forEach(i -> insertBranchIssueWithManualSeverity(branchA, fileA, rule, "A" + i, STATUS_OPEN, 1_340_000_000_000L));
Cursor<IndexedIssueDto> issues = underTest.scrollIssuesForIndexation(db.getSession(), null, null);
@@ -260,14 +259,15 @@ class IssueDaoIT {
while (iterator.hasNext()) {
IndexedIssueDto next = iterator.next();
assertThat(next.getRuleDefaultImpacts()).hasSize(2)
- .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity)
+ .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity, ImpactDto::isManualSeverity)
.containsExactlyInAnyOrder(
- tuple(RELIABILITY, LOW),
- tuple(MAINTAINABILITY, MEDIUM));
+ tuple(RELIABILITY, LOW, false),
+ tuple(MAINTAINABILITY, MEDIUM, false));
assertThat(next.getImpacts())
- .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity)
+ .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity, ImpactDto::isManualSeverity)
.containsExactlyInAnyOrder(
- tuple(MAINTAINABILITY, HIGH));
+ tuple(MAINTAINABILITY, HIGH, true),
+ tuple(RELIABILITY, LOW, false));
issueCount++;
}
assertThat(issueCount).isEqualTo(100);
@@ -792,10 +792,12 @@ class IssueDaoIT {
void insert_shouldInsertBatchIssuesWithImpacts() {
ImpactDto impact1 = new ImpactDto()
.setSoftwareQuality(MAINTAINABILITY)
- .setSeverity(HIGH);
+ .setSeverity(HIGH)
+ .setManualSeverity(false);
ImpactDto impact2 = new ImpactDto()
.setSoftwareQuality(SECURITY)
- .setSeverity(LOW);
+ .setSeverity(LOW)
+ .setManualSeverity(true);
IssueDto issue1 = createIssueWithKey(ISSUE_KEY1)
.addImpact(impact1)
.addImpact(impact2);
@@ -840,7 +842,8 @@ class IssueDaoIT {
.setSeverity(HIGH);
ImpactDto impact2 = new ImpactDto()
.setSoftwareQuality(SECURITY)
- .setSeverity(LOW);
+ .setSeverity(LOW)
+ .setManualSeverity(true);
IssueDto issue1 = createIssueWithKey(ISSUE_KEY1)
.addImpact(impact1)
.addImpact(impact2);
@@ -1098,6 +1101,20 @@ class IssueDaoIT {
.containsExactlyInAnyOrder(tuple(RELIABILITY, MEDIUM), tuple(SECURITY, LOW));
}
+ @Test
+ void insertIssueImpacts_should_insert_all_values() {
+ IssueDto issueDto = createIssueWithKey(ISSUE_KEY1);
+ ImpactDto impactDto1 = new ImpactDto(MAINTAINABILITY, MEDIUM, true);
+ ImpactDto impactDto2 = new ImpactDto(RELIABILITY, HIGH, false);
+ issueDto.addImpact(impactDto1);
+ issueDto.addImpact(impactDto2);
+ underTest.insert(db.getSession(), issueDto);
+
+ assertThat(underTest.selectOrFailByKey(db.getSession(), ISSUE_KEY1).getImpacts()).extracting(ImpactDto::getSoftwareQuality,
+ ImpactDto::getSeverity, ImpactDto::isManualSeverity)
+ .containsExactlyInAnyOrder(tuple(MAINTAINABILITY, MEDIUM, true), tuple(RELIABILITY, HIGH, false));
+ }
+
private static IssueDto createIssueWithKey(String issueKey) {
return createIssueWithKey(issueKey, PROJECT_UUID, FILE_UUID);
}
@@ -1178,6 +1195,26 @@ class IssueDaoIT {
.setMessageFormattings(MESSAGE_FORMATTING));
}
+ private void insertBranchIssueWithManualSeverity(ComponentDto branch, ComponentDto file, RuleDto rule, String id, String status,
+ Long updateAt) {
+ db.issues().insert(rule, branch, file, i -> i.setKee("issue" + id)
+ .setStatus(status)
+ .setResolution(null)
+ .setUpdatedAt(updateAt)
+ .setType(randomRuleTypeExceptHotspot())
+ .setMessage("message")
+ .setMessageFormattings(MESSAGE_FORMATTING)
+ .replaceAllImpacts(List.of(
+ new ImpactDto()
+ .setSoftwareQuality(MAINTAINABILITY)
+ .setSeverity(HIGH)
+ .setManualSeverity(true),
+ new ImpactDto()
+ .setSoftwareQuality(RELIABILITY)
+ .setSeverity(LOW)
+ .setManualSeverity(false))));
+ }
+
private void insertBranchIssue(ComponentDto branch, ComponentDto file, RuleDto rule, String id, String status, Long updateAt) {
insertBranchIssue(branch, file, rule, id, status, null, updateAt);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ImpactDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ImpactDto.java
index 4cf2ec95e1a..389c549649b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ImpactDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ImpactDto.java
@@ -27,14 +27,20 @@ import org.sonar.api.issue.impact.SoftwareQuality;
public class ImpactDto implements Serializable {
private SoftwareQuality softwareQuality;
private Severity severity;
+ private boolean manualSeverity;
public ImpactDto() {
// nothing to do
}
- public ImpactDto(SoftwareQuality softwareQuality, Severity severity) {
+ public ImpactDto(SoftwareQuality softwareQuality, Severity severity, boolean manualSeverity) {
this.softwareQuality = softwareQuality;
this.severity = severity;
+ this.manualSeverity = manualSeverity;
+ }
+
+ public ImpactDto(SoftwareQuality softwareQuality, Severity severity) {
+ this(softwareQuality, severity, false);
}
public SoftwareQuality getSoftwareQuality() {
@@ -55,6 +61,15 @@ public class ImpactDto implements Serializable {
return this;
}
+ public boolean isManualSeverity() {
+ return manualSeverity;
+ }
+
+ public ImpactDto setManualSeverity(boolean manualSeverity) {
+ this.manualSeverity = manualSeverity;
+ return this;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -67,12 +82,13 @@ public class ImpactDto implements Serializable {
ImpactDto impactDto = (ImpactDto) o;
return Objects.equals(softwareQuality, impactDto.softwareQuality)
- && Objects.equals(severity, impactDto.severity);
+ && Objects.equals(severity, impactDto.severity)
+ && Objects.equals(manualSeverity, impactDto.manualSeverity);
}
@Override
public int hashCode() {
- return Objects.hash(softwareQuality, severity);
+ return Objects.hash(softwareQuality, severity, manualSeverity);
}
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
index 0dbe81a387c..1515c039681 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
@@ -119,6 +119,7 @@
<sql id="issueImpactsColumns">
ii.software_quality as "ii_softwareQuality",
ii.severity as "ii_severity",
+ ii.manual_severity as "ii_manualSeverity",
</sql>
<sql id="ruleDefaultImpactsColumns">
@@ -137,6 +138,7 @@
javaType="java.util.Set" ofType="Impact">
<result property="softwareQuality" column="ii_softwareQuality"/>
<result property="severity" column="ii_severity"/>
+ <result property="manualSeverity" column="ii_manualSeverity"/>
</collection>
<collection property="ruleDefaultImpacts" column="rdi_softwareQuality" notNullColumn="rdi_softwareQuality"
javaType="java.util.Set" ofType="Impact">
@@ -185,11 +187,12 @@
</insert>
<insert id="insertIssueImpact" parameterType="map" useGeneratedKeys="false">
- INSERT INTO issues_impacts (issue_key, software_quality, severity)
+ INSERT INTO issues_impacts (issue_key, software_quality, severity, manual_severity)
VALUES (
#{issueKey,jdbcType=VARCHAR},
#{dto.softwareQuality,jdbcType=VARCHAR},
- #{dto.severity,jdbcType=VARCHAR})
+ #{dto.severity,jdbcType=VARCHAR},
+ #{dto.manualSeverity,jdbcType=BOOLEAN})
</insert>
<delete id="deleteAsNewCodeOnReferenceBranch" parameterType="String">
@@ -343,6 +346,7 @@
javaType="java.util.Set" ofType="Impact">
<result property="softwareQuality" column="ii_softwareQuality"/>
<result property="severity" column="ii_severity"/>
+ <result property="manualSeverity" column="ii_manualSeverity"/>
</collection>
<collection property="ruleDefaultImpacts" column="rdi_softwareQuality" notNullColumn="rdi_softwareQuality"
javaType="java.util.Set" ofType="Impact">
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 272b1c156a1..b6a46b9bc40 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -511,7 +511,8 @@ ALTER TABLE "ISSUES_FIXED" ADD CONSTRAINT "PK_ISSUES_FIXED" PRIMARY KEY("PULL_RE
CREATE TABLE "ISSUES_IMPACTS"(
"ISSUE_KEY" CHARACTER VARYING(40) NOT NULL,
"SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
- "SEVERITY" CHARACTER VARYING(40) NOT NULL
+ "SEVERITY" CHARACTER VARYING(40) NOT NULL,
+ "MANUAL_SEVERITY" BOOLEAN DEFAULT FALSE NOT NULL
);
ALTER TABLE "ISSUES_IMPACTS" ADD CONSTRAINT "PK_ISSUES_IMPACTS" PRIMARY KEY("ISSUE_KEY", "SOFTWARE_QUALITY");
CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_ISS_KEY_SOF_QUAL" ON "ISSUES_IMPACTS"("ISSUE_KEY" NULLS FIRST, "SOFTWARE_QUALITY" NULLS FIRST);