]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Fixed overridden RemFn param in WS
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 25 Jul 2014 07:20:38 +0000 (09:20 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 25 Jul 2014 07:20:38 +0000 (09:20 +0200)
sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java
sonar-server/src/main/java/org/sonar/server/search/ws/BaseMapping.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java

index ecb1f2233a3bc742b3b98f005796c6a33b23ad55..5f68223b13662a848275ca27d68359a844a5a168 100644 (file)
@@ -109,23 +109,44 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> {
   private void mapDebtFields() {
     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(),
       RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field()));
     map("debtSubChar", new IndexStringMapper("debtSubChar", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(),
       RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field()));
+
     map("debtCharName", new CharacteristicNameMapper());
     map("debtSubCharName", new SubCharacteristicNameMapper());
-    map("debtRemFn", new IndexStringMapper("debtRemFnType", RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field(),
-      RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_TYPE.field()));
-    map("debtRemFn", new IndexStringMapper("debtRemFnCoeff", RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field(),
-      RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_COEFFICIENT.field()));
-    map("debtRemFn", new IndexStringMapper("debtRemFnOffset", RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field(),
-      RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_OFFSET.field()));
+
     map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnType", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_TYPE.field()));
     map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnCoeff", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_COEFFICIENT.field()));
     map("defaultDebtRemFn", new IndexStringMapper("defaultDebtRemFnOffset", RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_OFFSET.field()));
     map("effortToFixDescription", RuleNormalizer.RuleField.FIX_DESCRIPTION.field());
     map("debtOverloaded", new OverriddenMapper());
+
+    map("debtRemFn", new EffectiveDebtRemFn("debtRemFnType", RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field(),
+      RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_TYPE.field()));
+    map("debtRemFn", new EffectiveDebtRemFn("debtRemFnCoeff", RuleNormalizer.RuleField.DEBT_FUNCTION_COEFFICIENT.field(),
+      RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_COEFFICIENT.field()));
+    map("debtRemFn", new EffectiveDebtRemFn("debtRemFnOffset", RuleNormalizer.RuleField.DEBT_FUNCTION_OFFSET.field(),
+      RuleNormalizer.RuleField.DEFAULT_DEBT_FUNCTION_OFFSET.field()));
+  }
+
+  public static class EffectiveDebtRemFn extends IndexStringMapper<RuleDoc,RuleMappingContext> {
+
+    public EffectiveDebtRemFn(String key, String indexKey, String defaultIndexKey) {
+      super(key, indexKey, defaultIndexKey);
+    }
+
+    @Override
+    public void write(JsonWriter json, RuleDoc doc, RuleMappingContext context) {
+      if(doc.debtOverloaded()){
+        Object val = doc.getNullableField(indexFields[0]);
+        json.prop(key, val != null ? val.toString() : null);
+      } else {
+        super.write(json,doc,context);
+      }
+    }
   }
 
   private void mapParamFields() {
index 69a73937c6a64957c194dd2c5868f846648c54ab..8a4096a47a8a9e8757db53fd28003f6bbcc7edce 100644 (file)
@@ -133,7 +133,7 @@ public abstract class BaseMapping<DOC extends BaseDoc, CTX> implements ServerCom
    * String field
    */
   public static class IndexStringMapper<DOC extends BaseDoc, CTX> extends IndexMapper<DOC,CTX> {
-    private final String key;
+    protected final String key;
 
     public IndexStringMapper(String key, String indexKey, String defaultIndexKey) {
       super(indexKey, defaultIndexKey);
index 43e1c2fc12718e8db77b8cb4ca05cc9b83a7bc28..11776ed9107acd8a98d3f8c6a6fe8f8b8f05af61 100644 (file)
@@ -220,7 +220,6 @@ public class RulesWebServiceMediumTest {
   }
 
   @Test
-  @Ignore("To be fixed")
   public void search_debt_rules_with_default_linear_offset_and_overridden_constant_debt() throws Exception {
     insertDebtCharacteristics(session);
 
@@ -245,7 +244,6 @@ public class RulesWebServiceMediumTest {
   }
 
   @Test
-  @Ignore("To be fixed")
   public void search_debt_rules_with_default_linear_offset_and_overridden_linear_debt() throws Exception {
     insertDebtCharacteristics(session);