aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-06-01 10:45:30 +0200
committersonartech <sonartech@sonarsource.com>2022-06-01 20:03:02 +0000
commit2b8d594f9c5f4dda90e315b6438849ec883628d8 (patch)
treec84293d555f37617123cfbf8d81a571b2d757d84 /server/sonar-db-dao
parent1e83af8df638591b47e672462421ebfc50dc5c6d (diff)
downloadsonarqube-2b8d594f9c5f4dda90e315b6438849ec883628d8.tar.gz
sonarqube-2b8d594f9c5f4dda90e315b6438849ec883628d8.zip
SONAR-16316 Improvements on quality gate findings CSV file
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java52
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java33
3 files changed, 28 insertions, 67 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java
index 20829ac2df4..2272cd8cc8c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java
@@ -19,23 +19,14 @@
*/
package org.sonar.db.qualitygate;
-import javax.annotation.CheckForNull;
-
public class QualityGateFindingDto {
public static final String RATING_VALUE_TYPE = "RATING";
public static final String PERCENT_VALUE_TYPE = "PERCENT";
- public static final String NEW_CODE_METRIC_PREFIX = "new_";
private String description = null;
private String operator = null;
- private String kee = null;
- private Boolean isEnabled = null;
private String valueType = null;
- private Double bestValue = null;
- private Double worstValue = null;
- private Boolean optimizedBestValue = null;
private String errorThreshold = null;
- private Integer decimalScale = null;
public String getDescription() {
return description;
@@ -49,53 +40,34 @@ public class QualityGateFindingDto {
return PercentageType.valueOf(getOperator()).getDescription();
}
- public Boolean isNewCodeMetric() {
- return kee.startsWith(NEW_CODE_METRIC_PREFIX);
- }
-
- public boolean isEnabled() {
- return isEnabled;
- }
-
- public String getValueType() {
- return valueType;
- }
-
- @CheckForNull
- public Double getBestValue() {
- return bestValue;
- }
-
- @CheckForNull
- public Double getWorstValue() {
- return worstValue;
- }
-
public String getErrorThreshold() {
if (isRating(getValueType())) {
return RatingValue.valueOf(Integer.parseInt(errorThreshold));
}
- return errorThreshold;
- }
-
- public boolean isOptimizedBestValue() {
- return optimizedBestValue;
- }
+ if (isPercentage(getValueType())) {
+ return errorThreshold + "%";
+ }
- @CheckForNull
- public Integer getDecimalScale() {
- return decimalScale;
+ return errorThreshold;
}
private String getOperator() {
return operator;
}
+ private String getValueType() {
+ return valueType;
+ }
+
private static boolean isRating(String metricType) {
return RATING_VALUE_TYPE.equals(metricType);
}
+ private static boolean isPercentage(String metricType) {
+ return PERCENT_VALUE_TYPE.equals(metricType);
+ }
+
public enum RatingType {
LT("Is Better Than"),
GT("Is Worse Than"),
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
index 2488f9adcfb..0771e2eaddf 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
@@ -7,16 +7,10 @@
</sql>
<sql id="qualityGateFindingColumns">
- m.description as description,
+ m.short_name as description,
qgc.operator as operator,
- m.name as kee,
- m.enabled as isEnabled,
m.val_type as valueType,
- m.best_value as bestValue,
- m.worst_value as worstValue,
- m.optimized_best_value as optimizedBestValue,
- qgc.value_error as errorThreshold,
- m.decimal_scale as decimalScale
+ qgc.value_error as errorThreshold
</sql>
<insert id="insertQualityGate" parameterType="QualityGate" useGeneratedKeys="false">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
index a5d9a085c1c..24e8c1530ae 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
@@ -38,8 +38,7 @@ import org.sonar.db.project.ProjectDto;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.AssertionsForClassTypes.within;
-import static org.sonar.db.qualitygate.QualityGateFindingDto.NEW_CODE_METRIC_PREFIX;
+import static org.sonar.db.qualitygate.QualityGateFindingDto.PERCENT_VALUE_TYPE;
import static org.sonar.db.qualitygate.QualityGateFindingDto.RATING_VALUE_TYPE;
public class QualityGateDaoTest {
@@ -133,13 +132,13 @@ public class QualityGateDaoTest {
QualityGateDto gate = db.qualityGates().insertQualityGate();
db.qualityGates().setDefaultQualityGate(gate);
- MetricDto metric1 = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.PERCENT.name()).setDescription("metric 1 description").setDecimalScale(0));
+ MetricDto metric1 = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.PERCENT.name()).setShortName("metric 1"));
QualityGateConditionDto condition1 = db.qualityGates().addCondition(gate, metric1, c -> c.setErrorThreshold("13"));
- MetricDto metric2 = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.RATING.name()).setDescription("metric 2 description").setDecimalScale(1));
+ MetricDto metric2 = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.RATING.name()).setShortName("metric 2"));
QualityGateConditionDto condition2 = db.qualityGates().addCondition(gate, metric2, c -> c.setErrorThreshold("1"));
- MetricDto metric3 = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.INT.name()).setDescription("metric 3 description").setDecimalScale(0));
+ MetricDto metric3 = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.INT.name()).setShortName("metric 3"));
QualityGateConditionDto condition3 = db.qualityGates().addCondition(gate, metric3, c -> c.setErrorThreshold("0"));
db.qualityGates().associateProjectToQualityGate(project, gate);
@@ -150,17 +149,16 @@ public class QualityGateDaoTest {
// check fields
assertThat(findings).hasSize(3);
- assertThat(findings.stream().map(f -> f.getDescription()).collect(Collectors.toSet())).containsExactlyInAnyOrder(metric1.getDescription(), metric2.getDescription(), metric3.getDescription());
+ assertThat(findings.stream().map(QualityGateFindingDto::getDescription).collect(Collectors.toSet())).containsExactlyInAnyOrder(metric1.getShortName(), metric2.getShortName(), metric3.getShortName());
- QualityGateFindingDto finding1 = findings.stream().filter(f -> f.getDescription().equals(metric1.getDescription())).findFirst().get();
+ QualityGateFindingDto finding1 = findings.stream().filter(f -> f.getDescription().equals(metric1.getShortName())).findFirst().get();
validateQualityGateFindingFields(finding1, metric1, condition1);
- QualityGateFindingDto finding2 = findings.stream().filter(f -> f.getDescription().equals(metric2.getDescription())).findFirst().get();
+ QualityGateFindingDto finding2 = findings.stream().filter(f -> f.getDescription().equals(metric2.getShortName())).findFirst().get();
validateQualityGateFindingFields(finding2, metric2, condition2);
- QualityGateFindingDto finding3 = findings.stream().filter(f -> f.getDescription().equals(metric3.getDescription())).findFirst().get();
+ QualityGateFindingDto finding3 = findings.stream().filter(f -> f.getDescription().equals(metric3.getShortName())).findFirst().get();
validateQualityGateFindingFields(finding3, metric3, condition3);
-
}
@Test
@@ -255,19 +253,16 @@ public class QualityGateDaoTest {
return QualityGateFindingDto.RatingValue.valueOf(Integer.parseInt(errorThreshold));
}
+ if (PERCENT_VALUE_TYPE.equals(valueType)) {
+ return errorThreshold + "%";
+ }
+
return errorThreshold;
}
private void validateQualityGateFindingFields(QualityGateFindingDto finding, MetricDto metric, QualityGateConditionDto condition) {
- assertThat(finding.getDescription()).isEqualTo(metric.getDescription());
- assertThat(finding.getOperatorDescription()).isEqualTo( getOperatorDescription(condition.getOperator(), metric.getValueType()));
+ assertThat(finding.getDescription()).isEqualTo(metric.getShortName());
+ assertThat(finding.getOperatorDescription()).isEqualTo(getOperatorDescription(condition.getOperator(), metric.getValueType()));
assertThat(finding.getErrorThreshold()).isEqualTo(getErrorThreshold(condition.getErrorThreshold(), metric.getValueType()));
- assertThat(finding.getValueType()).isEqualTo(metric.getValueType());
- assertThat(finding.isNewCodeMetric()).isEqualTo(metric.getKey().startsWith(NEW_CODE_METRIC_PREFIX));
- assertThat(finding.isEnabled()).isEqualTo(metric.isEnabled());
- assertThat(finding.getBestValue()).isEqualTo(metric.getBestValue(), within(0.00001));
- assertThat(finding.getWorstValue()).isEqualTo(metric.getWorstValue(), within(0.00001));
- assertThat(finding.isOptimizedBestValue()).isEqualTo(metric.isOptimizedBestValue());
- assertThat(finding.getDecimalScale()).isEqualTo(metric.getDecimalScale());
}
}