]> source.dussan.org Git - sonarqube.git/commitdiff
Do not show the debt (sub)characteristic of a rule when it has been overloaded as... 168/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 24 Mar 2015 10:45:21 +0000 (11:45 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 24 Mar 2015 10:45:21 +0000 (11:45 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_rule_with_overridden_disable_debt.json

index edb54625e5e2a1660cbaa78d0b483351def7ab58..77cf01ec5a2494c0f6b5c86366e460fe398d3605 100644 (file)
@@ -106,8 +106,8 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> {
     map("defaultDebtChar", new IndexStringMapper("defaultDebtChar", RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field()));
     map("defaultDebtSubChar", new IndexStringMapper("defaultDebtSubChar", RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field()));
 
-    map("debtChar", new IndexStringMapper("debtChar", RuleNormalizer.RuleField.CHARACTERISTIC.field()));
-    map("debtSubChar", new IndexStringMapper("debtSubChar", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
+    map("debtChar", new CharacteristicMapper());
+    map("debtSubChar", new SubCharacteristicMapper());
 
     map("debtCharName", new CharacteristicNameMapper());
     map("debtSubCharName", new SubCharacteristicNameMapper());
@@ -198,6 +198,34 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> {
     return context == null || context.getFieldsToReturn().contains("debtSubCharName");
   }
 
+  private static class CharacteristicMapper extends IndexMapper<RuleDoc, RuleMappingContext> {
+    private CharacteristicMapper() {
+      super(RuleNormalizer.RuleField.CHARACTERISTIC.field());
+    }
+
+    @Override
+    public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) {
+      String debtCharacteristicKey = rule.debtCharacteristicKey();
+      if (debtCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtCharacteristicKey)) {
+        json.prop("debtChar", debtCharacteristicKey);
+      }
+    }
+  }
+
+  private static class SubCharacteristicMapper extends IndexMapper<RuleDoc, RuleMappingContext> {
+    private SubCharacteristicMapper() {
+      super(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field());
+    }
+
+    @Override
+    public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) {
+      String debtSubCharacteristicKey = rule.debtSubCharacteristicKey();
+      if (debtSubCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtSubCharacteristicKey)) {
+        json.prop("debtSubChar", debtSubCharacteristicKey);
+      }
+    }
+  }
+
   private static class CharacteristicNameMapper extends IndexMapper<RuleDoc, RuleMappingContext> {
     private CharacteristicNameMapper() {
       super(RuleNormalizer.RuleField.CHARACTERISTIC.field());
@@ -237,7 +265,7 @@ class RuleMappingContext {
   private final Map<String, String> debtCharacteristicNamesByKey = Maps.newHashMap();
 
   @CheckForNull
-  public String debtCharacteristicName(String key) {
+  public String debtCharacteristicName(@Nullable String key) {
     return debtCharacteristicNamesByKey.get(key);
   }
 
index e4b2495aac351fa7c2291a4c0efdd40be5249c0f..10bb82b9b8a07a6c9b2bd6d2a80aa192c896cfbf 100644 (file)
@@ -7,8 +7,6 @@
     "severity": "MINOR",
     "status": "BETA",
     "isTemplate": false,
-    "debtChar": "NONE",
-    "debtSubChar": "NONE",
     "debtOverloaded": true,
     "lang": "xoo"
   }