]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5407 - fixed missing defaultChars in ES
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 23 Jun 2014 10:41:03 +0000 (12:41 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 23 Jun 2014 10:41:27 +0000 (12:41 +0200)
sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java
sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java

index 0c6ec3c77d16008702d51da7f6535e42bda47220..2e3bba794b74d73b0bbff7ed4d48ebb4136b3722 100644 (file)
@@ -99,8 +99,8 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
     public static final IndexField DEBT_FUNCTION_TYPE = add(IndexField.Type.STRING, "debtRemFnType");
     public static final IndexField DEBT_FUNCTION_COEFFICIENT = add(IndexField.Type.STRING, "debtRemFnCoefficient");
     public static final IndexField DEBT_FUNCTION_OFFSET = add(IndexField.Type.STRING, "debtRemFnOffset");
-    public static final IndexField DEFAULT_CHARACTERISTIC = add(IndexField.Type.STRING, "_debtChar");
-    public static final IndexField DEFAULT_SUB_CHARACTERISTIC = add(IndexField.Type.STRING, "_debtSubChar");
+    public static final IndexField DEFAULT_CHARACTERISTIC = add(IndexField.Type.STRING, "defaultDebtChar");
+    public static final IndexField DEFAULT_SUB_CHARACTERISTIC = add(IndexField.Type.STRING, "defaultDebtSubChar");
     public static final IndexField CHARACTERISTIC = add(IndexField.Type.STRING, "debtChar");
     public static final IndexField SUB_CHARACTERISTIC = add(IndexField.Type.STRING, "debtSubChar");
     public static final IndexField NOTE = add(IndexField.Type.TEXT, "markdownNote");
@@ -204,7 +204,9 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
       if (rule.getDefaultSubCharacteristicId() != null) {
         characteristic = db.debtCharacteristicDao().selectById(rule.getDefaultSubCharacteristicId(), session);
         defaultCharacteristic = characteristic;
-        update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), defaultCharacteristic.getKey());
+        if (defaultCharacteristic != null) {
+          update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), defaultCharacteristic.getKey());
+        }
       }
       if (rule.getSubCharacteristicId() != null) {
         characteristic = db.debtCharacteristicDao().selectById(rule.getSubCharacteristicId(), session);
@@ -215,17 +217,21 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
           CharacteristicDto parentCharacteristic =
             db.debtCharacteristicDao().selectById(characteristic.getParentId(), session);
           update.put(RuleField.CHARACTERISTIC.field(), parentCharacteristic.getKey());
-          if (characteristic.getId() == defaultCharacteristic.getId()) {
-            update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), parentCharacteristic.getKey());
-          } else {
-            update.put(RuleField.DEFAULT_CHARACTERISTIC.field(),
-              db.debtCharacteristicDao().selectById(defaultCharacteristic.getParentId(), session)
-                .getKey());
+          if (defaultCharacteristic != null) {
+            if (characteristic.getId() == defaultCharacteristic.getId()) {
+              update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), parentCharacteristic.getKey());
+            } else {
+              update.put(RuleField.DEFAULT_CHARACTERISTIC.field(),
+                db.debtCharacteristicDao().selectById(defaultCharacteristic.getParentId(), session)
+                  .getKey());
+            }
           }
         }
       } else {
         update.put(RuleField.CHARACTERISTIC.field(), null);
         update.put(RuleField.SUB_CHARACTERISTIC.field(), null);
+        update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), null);
+        update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), null);
       }
 
       String dType = null, dCoefficient = null, dOffset = null;
index 65bf05ce14e2b41b431827703ecb704c65198c65..1466dd92ddf9cfa1d783e4469c0c3f9c5ae46417 100644 (file)
@@ -48,8 +48,8 @@ public class RuleMapping extends BaseMapping {
     addIndexStringField("templateKey", RuleNormalizer.RuleField.TEMPLATE_KEY.field());
     addIndexArrayField("tags", RuleNormalizer.RuleField.TAGS.field());
     addIndexArrayField("sysTags", RuleNormalizer.RuleField.SYSTEM_TAGS.field());
-    addIndexStringField("defaultDebtChar", RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field());
-    addIndexStringField("defaultDebtSubChar", RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field());
+    addField("defaultDebtChar", new IndexStringField("debtChar", RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field()));
+    addField("defaultDebtChar", new IndexStringField("debtSubChar", RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field()));
     addField("debtChar", new IndexStringField("debtChar", RuleNormalizer.RuleField.CHARACTERISTIC.field()));
     addField("debtChar", new IndexStringField("debtSubChar", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
     addField("debtRemFn", new IndexStringField("debtRemFnType", RuleNormalizer.RuleField.DEBT_FUNCTION_TYPE.field()));