aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/main/java/org/sonar/db/issue
diff options
context:
space:
mode:
authorantoine.vinot <antoine.vinot@sonarsource.com>2023-09-12 16:59:23 +0200
committersonartech <sonartech@sonarsource.com>2023-09-21 20:02:44 +0000
commitabc6475f07561c76b346b2bea7b757a48c7cf9b6 (patch)
treed6aab64e78888e83a8699cb8fb501330fb478d41 /server/sonar-db-dao/src/main/java/org/sonar/db/issue
parentf4dfa7536a815153fb8a04081e96180e33ba2638 (diff)
downloadsonarqube-abc6475f07561c76b346b2bea7b757a48c7cf9b6.tar.gz
sonarqube-abc6475f07561c76b346b2bea7b757a48c7cf9b6.zip
SONAR-20424 - Store rules impact within issue
Diffstat (limited to 'server/sonar-db-dao/src/main/java/org/sonar/db/issue')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
index e6811c758f4..d933e0b45fd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
@@ -26,9 +26,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.Serializable;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
@@ -53,6 +51,7 @@ import org.sonar.db.rule.RuleDto;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
+import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.sonar.api.utils.DateUtils.dateToLong;
import static org.sonar.api.utils.DateUtils.longToDate;
@@ -840,10 +839,12 @@ public final class IssueDto implements Serializable {
* @return Unmodifiable Map of impacts
*/
public Map<SoftwareQuality, Severity> getEffectiveImpacts() {
- EnumMap<SoftwareQuality, Severity> effectiveImpacts = new EnumMap<>(SoftwareQuality.class);
- ruleDefaultImpacts.forEach(impact -> effectiveImpacts.put(impact.getSoftwareQuality(), impact.getSeverity()));
- impacts.forEach(impact -> effectiveImpacts.put(impact.getSoftwareQuality(), impact.getSeverity()));
- return Collections.unmodifiableMap(effectiveImpacts);
+ return impacts.isEmpty() ? toImpactMap(ruleDefaultImpacts) : toImpactMap(impacts);
+ }
+
+ private static Map<SoftwareQuality, Severity> toImpactMap(Collection<ImpactDto> impacts) {
+ return impacts.stream()
+ .collect(toUnmodifiableMap(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity));
}
@Override