aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-06-23 10:32:15 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-06-23 12:41:26 +0200
commit723f1a0bf7908a98b191c29c61e9f63e3f64c2e2 (patch)
tree9e834880d732b3037e87b89c72b5d1f27331f1dc
parentf7b49d348af4db850fcd882fc260323926bc8458 (diff)
downloadsonarqube-723f1a0bf7908a98b191c29c61e9f63e3f64c2e2.tar.gz
sonarqube-723f1a0bf7908a98b191c29c61e9f63e3f64c2e2.zip
SONAR-5407 - Added debtOverloaded() method to Rule domain object and defaultChar/SubChar
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/Rule.java8
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java18
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java19
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java10
5 files changed, 52 insertions, 5 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 93a238bc12c..d8a61eb9103 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
@@ -74,13 +74,21 @@ public interface Rule {
@CheckForNull
RuleParam param(final String key);
+ boolean debtOverloaded();
+
@CheckForNull
String debtCharacteristicKey();
@CheckForNull
+ String defaultDebtCharacteristicKey();
+
+ @CheckForNull
String debtSubCharacteristicKey();
@CheckForNull
+ String defaultDebtSubCharacteristicKey();
+
+ @CheckForNull
DebtRemediationFunction debtRemediationFunction();
Date createdAt();
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 d5f88efdc78..8b38025382a 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
@@ -182,6 +182,24 @@ public class RuleDoc extends BaseDoc implements Rule {
}
@Override
+ public boolean debtOverloaded() {
+ return !defaultDebtSubCharacteristicKey()
+ .equalsIgnoreCase(debtSubCharacteristicKey());
+ }
+
+ @Override
+ @CheckForNull
+ public String defaultDebtCharacteristicKey() {
+ return (String) getNullableField(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field());
+ }
+
+ @Override
+ @CheckForNull
+ public String defaultDebtSubCharacteristicKey() {
+ return (String) getNullableField(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field());
+ }
+
+ @Override
@CheckForNull
public String debtCharacteristicKey() {
return (String) getNullableField(RuleNormalizer.RuleField.CHARACTERISTIC.field());
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 d1a3b6fd525..0c6ec3c77d1 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,10 @@ 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 SUB_CHARACTERISTIC = add(IndexField.Type.STRING, "debtSubChar");
+ 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 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");
public static final IndexField NOTE_LOGIN = add(IndexField.Type.STRING, "noteLogin");
public static final IndexField NOTE_CREATED_AT = add(IndexField.Type.DATE, "noteCreatedAt");
@@ -198,8 +200,11 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
//TODO Legacy ID in DTO should be Key
CharacteristicDto characteristic = null;
+ CharacteristicDto defaultCharacteristic = null;
if (rule.getDefaultSubCharacteristicId() != null) {
characteristic = db.debtCharacteristicDao().selectById(rule.getDefaultSubCharacteristicId(), session);
+ defaultCharacteristic = characteristic;
+ update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), defaultCharacteristic.getKey());
}
if (rule.getSubCharacteristicId() != null) {
characteristic = db.debtCharacteristicDao().selectById(rule.getSubCharacteristicId(), session);
@@ -207,8 +212,16 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
if (characteristic != null && characteristic.getId() != -1) {
update.put(RuleField.SUB_CHARACTERISTIC.field(), characteristic.getKey());
if (characteristic.getParentId() != null) {
- update.put(RuleField.CHARACTERISTIC.field(),
- db.debtCharacteristicDao().selectById(characteristic.getParentId(), session).getKey());
+ 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());
+ }
}
} else {
update.put(RuleField.CHARACTERISTIC.field(), 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 4c7585a6d4b..65bf05ce14e 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,6 +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("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()));
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 f5709040c7f..3cc5438ba97 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
@@ -331,13 +331,19 @@ public class RuleBackendMediumTest {
ruleDto.setSubCharacteristicId(char21.getId());
dao.update(dbSession, ruleDto);
-
dbSession.commit();
- // 4. Get non-default chars from Rule
rule = index.getByKey(ruleKey);
+
+ // 4. Get non-default chars from Rule
assertThat(rule.debtCharacteristicKey()).isEqualTo(char2.getKey());
assertThat(rule.debtSubCharacteristicKey()).isEqualTo(char21.getKey());
+
+ // 5 Assert still get the default one
+ assertThat(rule.debtOverloaded()).isTrue();
+ assertThat(rule.defaultDebtCharacteristicKey()).isEqualTo(char1.getKey());
+ assertThat(rule.defaultDebtSubCharacteristicKey()).isEqualTo(char11.getKey());
+
}