From 3fc57d40a6f3b3e896b7417c714ac028f3e38710 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 3 Apr 2014 09:33:04 +0200 Subject: [PATCH] Move hasCharacteristic() method from RuleDto to RulesProvider --- .../java/org/sonar/batch/rule/RulesProvider.java | 12 +++++++++++- .../src/main/java/org/sonar/core/rule/RuleDto.java | 4 ---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java index 821cdbe4b3d..1cbf9b1aa5b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java @@ -79,7 +79,7 @@ public class RulesProvider extends ProviderAdapter { .setStatus(RuleStatus.valueOf(ruleDto.getStatus())); // TODO should we set metadata ? - if (ruleDto.hasCharacteristic()) { + if (hasCharacteristic(ruleDto)) { newRule.setDebtCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key()); newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations)); } @@ -121,4 +121,14 @@ public class RulesProvider extends ProviderAdapter { offset != null ? durations.decode(offset) : null); } + /** + * Return true is the characteristic has not been overridden and a default characteristic is existing or + * if the characteristic has been overridden but is not disabled + */ + private boolean hasCharacteristic(RuleDto ruleDto){ + Integer subCharacteristicId = ruleDto.getSubCharacteristicId(); + return (subCharacteristicId == null && ruleDto.getDefaultSubCharacteristicId() != null) || + (subCharacteristicId != null && !RuleDto.DISABLED_CHARACTERISTIC_ID.equals(subCharacteristicId)); + } + } diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java index 7ce85241430..8bb8f4e38b5 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java @@ -315,10 +315,6 @@ public final class RuleDto { return this; } - public boolean hasCharacteristic(){ - return (subCharacteristicId != null && !RuleDto.DISABLED_CHARACTERISTIC_ID.equals(subCharacteristicId)) || (subCharacteristicId == null && defaultSubCharacteristicId != null); - } - @Override public boolean equals(Object obj) { if (!(obj instanceof RuleDto)) { -- 2.39.5