]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaw
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 15 Apr 2014 09:36:01 +0000 (11:36 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 15 Apr 2014 09:36:01 +0000 (11:36 +0200)
sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java

index e0931dd8dda57452382343a2054f19ee945537ed..ff4957a9f4b7bec225b23a72f54ad089164f11ab 100644 (file)
@@ -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)
    */