From 6e2ed638eeb353c4048575e9ba16c968455d3142 Mon Sep 17 00:00:00 2001 From: Léo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com> Date: Fri, 22 Apr 2022 14:13:59 +0200 Subject: SONAR-16302 adapt RuleDto, RuleDefinitionDto and introduce RuleSectionDescriptionDto to prepare for multiple section support --- .../java/org/sonar/server/rule/CachingRuleFinder.java | 15 +++------------ .../java/org/sonar/server/rule/CachingRuleFinderTest.java | 3 ++- 2 files changed, 5 insertions(+), 13 deletions(-) (limited to 'server/sonar-webserver-api') diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java index 17199eb9ce1..43f6fdb03c6 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java @@ -41,9 +41,7 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDefinitionDto; -import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; -import org.sonar.markdown.Markdown; import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableMap; @@ -147,8 +145,6 @@ public class CachingRuleFinder implements ServerRuleFinder { private static Rule toRule(RuleDefinitionDto ruleDefinition, List params) { String severity = ruleDefinition.getSeverityString(); - String description = ruleDefinition.getDescription(); - RuleDto.Format descriptionFormat = ruleDefinition.getDescriptionFormat(); Rule apiRule = new Rule(); apiRule @@ -163,14 +159,9 @@ public class CachingRuleFinder implements ServerRuleFinder { .setSeverity(severity != null ? RulePriority.valueOf(severity) : null) .setStatus(ruleDefinition.getStatus().name()) .setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()])) - .setTags(new String[0]); - if (description != null && descriptionFormat != null) { - if (RuleDto.Format.HTML.equals(descriptionFormat)) { - apiRule.setDescription(description); - } else { - apiRule.setDescription(Markdown.convertToHtml(description)); - } - } + .setTags(new String[0]) + .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDefinition)); + List apiParams = new ArrayList<>(); for (RuleParamDto param : params) { diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java index 0d37e1221fe..cd2c2235981 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java @@ -46,6 +46,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection; public class CachingRuleFinderTest { @org.junit.Rule @@ -422,7 +423,7 @@ public class CachingRuleFinderTest { assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString()); assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().toArray(new String[0])); assertThat(rule.getTags()).isEmpty(); - assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription()); + assertThat(rule.getDescription()).isEqualTo(createDefaultRuleDescriptionSection(randomAlphabetic(5)).getDescription()); assertThat(rule.getParams()).hasSize(1); org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next(); -- cgit v1.2.3