From f81126bff713a48d5794bd5775e4aa5ebc2dfa0c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 15 Apr 2014 11:36:01 +0200 Subject: [PATCH] Fix quality flaw --- .../sonar/server/debt/DebtModelBackup.java | 68 ++++++++++--------- 1 file 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 ruleDtos, List rules, List 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) */ -- 2.39.5