From 6de09db43d0b7255226ee5ac074ee83468ae4700 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 23 Jun 2014 12:41:03 +0200 Subject: [PATCH] SONAR-5407 - fixed missing defaultChars in ES --- .../server/rule/index/RuleNormalizer.java | 24 ++++++++++++------- .../org/sonar/server/rule/ws/RuleMapping.java | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) 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 0c6ec3c77d1..2e3bba794b7 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 @@ -99,8 +99,8 @@ public class RuleNormalizer extends BaseNormalizer { 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 { 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 { 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; 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 65bf05ce14e..1466dd92ddf 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 @@ -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())); -- 2.39.5