aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-15 11:36:01 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-15 11:36:01 +0200
commitf81126bff713a48d5794bd5775e4aa5ebc2dfa0c (patch)
tree8d0f9d15824817bd1fb8820117c491ce48def61d /sonar-server
parent9e6bc9e42f5fbee6e39b5746a8fa8ad20609f201 (diff)
downloadsonarqube-f81126bff713a48d5794bd5775e4aa5ebc2dfa0c.tar.gz
sonarqube-f81126bff713a48d5794bd5775e4aa5ebc2dfa0c.zip
Fix quality flaw
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java68
1 files changed, 36 insertions, 32 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
index e0931dd8dda..ff4957a9f4b 100644
--- a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
+++ b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
@@ -162,38 +162,7 @@ public class DebtModelBackup implements ServerComponent {
rules.addAll(repoDef.rules());
}
- for (RuleDto rule : ruleDtos) {
- // Restore default debt definitions
-
- RulesDefinition.Rule ruleDef;
- if (rule.getParentId() != null) {
- RuleDto templateRule = rule(rule.getParentId(), ruleDtos);
- ruleDef = ruleDef(templateRule.getRepositoryKey(), templateRule.getRuleKey(), rules);
- } else {
- ruleDef = ruleDef(rule.getRepositoryKey(), rule.getRuleKey(), rules);
- }
-
- if (ruleDef != null) {
- String subCharacteristicKey = ruleDef.debtSubCharacteristic();
- CharacteristicDto subCharacteristicDto = characteristicByKey(subCharacteristicKey, allCharacteristicDtos, false);
- DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
- boolean hasDebtDefinition = subCharacteristicDto != null && remediationFunction != null;
-
- rule.setDefaultSubCharacteristicId(hasDebtDefinition ? subCharacteristicDto.getId() : null);
- rule.setDefaultRemediationFunction(hasDebtDefinition ? remediationFunction.type().name() : null);
- rule.setDefaultRemediationCoefficient(hasDebtDefinition ? remediationFunction.coefficient() : null);
- rule.setDefaultRemediationOffset(hasDebtDefinition ? remediationFunction.offset() : null);
- }
-
- // Reset overridden debt definitions
- rule.setSubCharacteristicId(null);
- rule.setRemediationFunction(null);
- rule.setRemediationCoefficient(null);
- rule.setRemediationOffset(null);
- rule.setUpdatedAt(updateDate);
- ruleDao.update(rule, session);
- }
- ruleRegistry.reindex(ruleDtos, session);
+ resetRules(ruleDtos, rules, allCharacteristicDtos, updateDate, session);
}
session.commit();
@@ -202,6 +171,41 @@ public class DebtModelBackup implements ServerComponent {
}
}
+ private void resetRules(List<RuleDto> ruleDtos, List<RulesDefinition.Rule> rules, List<CharacteristicDto> allCharacteristicDtos, Date updateDate, SqlSession session){
+ for (RuleDto rule : ruleDtos) {
+ // Restore default debt definitions
+
+ RulesDefinition.Rule ruleDef;
+ if (rule.getParentId() != null) {
+ RuleDto templateRule = rule(rule.getParentId(), ruleDtos);
+ ruleDef = ruleDef(templateRule.getRepositoryKey(), templateRule.getRuleKey(), rules);
+ } else {
+ ruleDef = ruleDef(rule.getRepositoryKey(), rule.getRuleKey(), rules);
+ }
+
+ if (ruleDef != null) {
+ String subCharacteristicKey = ruleDef.debtSubCharacteristic();
+ CharacteristicDto subCharacteristicDto = characteristicByKey(subCharacteristicKey, allCharacteristicDtos, false);
+ DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
+ boolean hasDebtDefinition = subCharacteristicDto != null && remediationFunction != null;
+
+ rule.setDefaultSubCharacteristicId(hasDebtDefinition ? subCharacteristicDto.getId() : null);
+ rule.setDefaultRemediationFunction(hasDebtDefinition ? remediationFunction.type().name() : null);
+ rule.setDefaultRemediationCoefficient(hasDebtDefinition ? remediationFunction.coefficient() : null);
+ rule.setDefaultRemediationOffset(hasDebtDefinition ? remediationFunction.offset() : null);
+ }
+
+ // Reset overridden debt definitions
+ rule.setSubCharacteristicId(null);
+ rule.setRemediationFunction(null);
+ rule.setRemediationCoefficient(null);
+ rule.setRemediationOffset(null);
+ rule.setUpdatedAt(updateDate);
+ ruleDao.update(rule, session);
+ }
+ ruleRegistry.reindex(ruleDtos, session);
+ }
+
/**
* Restore model from a given XML model (characteristics and rule debt are restored from XML)
*/