From b005183fd67521cbb16182fbe4ef9094f92a3c83 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 23 Jun 2014 09:35:55 +0200 Subject: [PATCH] SONAR-5406 - Added effortToFix to Rule domain object and WS Json response. --- sonar-server/src/main/java/org/sonar/server/rule/Rule.java | 3 ++- .../src/main/java/org/sonar/server/rule/index/RuleDoc.java | 7 ++++++- .../java/org/sonar/server/rule/index/RuleNormalizer.java | 2 ++ .../main/java/org/sonar/server/rule/ws/RuleMapping.java | 1 + .../java/org/sonar/server/rule/RuleBackendMediumTest.java | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/rule/Rule.java b/sonar-server/src/main/java/org/sonar/server/rule/Rule.java index 74b785903ad..93a238bc12c 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/Rule.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/Rule.java @@ -24,7 +24,6 @@ import org.sonar.api.rule.RuleStatus; import org.sonar.api.server.debt.DebtRemediationFunction; import javax.annotation.CheckForNull; - import java.util.Date; import java.util.List; @@ -41,6 +40,8 @@ public interface Rule { String htmlDescription(); + String effortToFixDescription(); + /** * Default severity when activated on a Quality profile * diff --git a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java index 3d3d7b30186..d5f88efdc78 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java @@ -33,7 +33,6 @@ import org.sonar.server.search.IndexUtils; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -92,6 +91,12 @@ public class RuleDoc extends BaseDoc implements Rule { return getNullableField(RuleNormalizer.RuleField.HTML_DESCRIPTION.field()); } + @Override + @CheckForNull + public String effortToFixDescription() { + return getNullableField(RuleNormalizer.RuleField.FIX_DESCRIPTION.field()); + } + @Override @CheckForNull public String severity() { diff --git a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java index 07d3a37c669..d1a3b6fd525 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java @@ -89,6 +89,7 @@ public class RuleNormalizer extends BaseNormalizer { public static final IndexField HTML_DESCRIPTION = addSearchable(IndexField.Type.TEXT, "htmlDesc"); public static final IndexField SEVERITY = add(IndexField.Type.STRING, "severity"); public static final IndexField STATUS = add(IndexField.Type.STRING, "status"); + public static final IndexField FIX_DESCRIPTION = add(IndexField.Type.STRING, "effortToFix"); public static final IndexField LANGUAGE = add(IndexField.Type.STRING, "lang"); public static final IndexField TAGS = add(IndexField.Type.STRING, "tags"); public static final IndexField SYSTEM_TAGS = add(IndexField.Type.STRING, "sysTags"); @@ -174,6 +175,7 @@ public class RuleNormalizer extends BaseNormalizer { update.put(RuleField.CREATED_AT.field(), rule.getCreatedAt()); update.put(RuleField.UPDATED_AT.field(), rule.getUpdatedAt()); update.put(RuleField.HTML_DESCRIPTION.field(), rule.getDescription()); + update.put(RuleField.FIX_DESCRIPTION.field(), rule.getEffortToFixDescription()); update.put(RuleField.SEVERITY.field(), rule.getSeverityString()); update.put(RuleField.STATUS.field(), rule.getStatus().name()); update.put(RuleField.LANGUAGE.field(), rule.getLanguage()); diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java index 265730b321c..4c7585a6d4b 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java @@ -53,6 +53,7 @@ public class RuleMapping extends BaseMapping { addField("debtRemFn", new IndexStringField("debtRemFnType", RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field())); addField("debtRemFn", new IndexStringField("debtRemFnCoeff", RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field())); addField("debtRemFn", new IndexStringField("debtRemFnOffset", RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field())); + addIndexStringField("effortToFixDescription", RuleNormalizer.RuleField.FIX_DESCRIPTION.field()); addIndexStringField("mdNote", RuleNormalizer.RuleField.NOTE.field()); addField("htmlNote", new HtmlNoteField(macroInterpreter)); addIndexStringField("noteLogin", RuleNormalizer.RuleField.NOTE_LOGIN.field()); diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java index 522741cdf4a..f5709040c7f 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java @@ -106,6 +106,7 @@ public class RuleBackendMediumTest { assertThat(hit.isTemplate()).isFalse(); assertThat(hit.tags()).containsOnly("tag1", "tag2"); assertThat(hit.systemTags()).containsOnly("systag1", "systag2"); + assertThat(hit.effortToFixDescription()).isEqualTo(persistedDto.getEffortToFixDescription()); } @Test -- 2.39.5