]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16413 fix quality profile copy inconsistency
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Fri, 20 May 2022 08:18:02 +0000 (10:18 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 20 May 2022 20:02:46 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java

index 99f173b86258d2fb3277e835e0fd1cc1acd484c9..ffa21ec4388c4a88c1a1d18d7896d3d3f7ba7ae1 100644 (file)
@@ -95,7 +95,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
       importedRule.setRepository(ruleKey.repository());
       importedRule.setKey(ruleKey.rule());
       importedRule.setSeverity(exportRuleDto.getSeverityString());
-      if (importedRule.isCustomRule()) {
+      if (exportRuleDto.isCustomRule()) {
         importedRule.setTemplate(exportRuleDto.getTemplateRuleKey().rule());
         importedRule.setDescription(exportRuleDto.getDescriptionOrThrow());
       }
@@ -138,13 +138,13 @@ public class QProfileBackuperImpl implements QProfileBackuper {
 
     List<ImportedRule> importedRules = qProfile.getRules();
 
-    Map<RuleKey, RuleDto> ruleDefinitionsByKey = getImportedRulesDefinitions(dbSession, importedRules);
-    checkIfRulesFromExternalEngines(ruleDefinitionsByKey.values());
+    Map<RuleKey, RuleDto> ruleKeyToDto = getImportedRulesDtos(dbSession, importedRules);
+    checkIfRulesFromExternalEngines(ruleKeyToDto.values());
 
-    Map<RuleKey, RuleDto> customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleDefinitionsByKey);
-    ruleDefinitionsByKey.putAll(customRulesDefinitions);
+    Map<RuleKey, RuleDto> customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleKeyToDto);
+    ruleKeyToDto.putAll(customRulesDefinitions);
 
-    List<RuleActivation> ruleActivations = toRuleActivations(importedRules, ruleDefinitionsByKey);
+    List<RuleActivation> ruleActivations = toRuleActivations(importedRules, ruleKeyToDto);
 
     BulkChangeResult changes = profileReset.reset(dbSession, targetProfile, ruleActivations);
     return new QProfileRestoreSummary(targetProfile, changes);
@@ -154,15 +154,15 @@ public class QProfileBackuperImpl implements QProfileBackuper {
    * Returns map of rule definition for an imported rule key.
    * The imported rule key may refer to a deprecated rule key, in which case the the RuleDto will correspond to a different key (the new key).
    */
-  private Map<RuleKey, RuleDto> getImportedRulesDefinitions(DbSession dbSession, List<ImportedRule> rules) {
+  private Map<RuleKey, RuleDto> getImportedRulesDtos(DbSession dbSession, List<ImportedRule> rules) {
     Set<RuleKey> ruleKeys = rules.stream()
       .map(ImportedRule::getRuleKey)
       .collect(toSet());
-    Map<RuleKey, RuleDto> rulesDefinitions = db.ruleDao().selectByKeys(dbSession, ruleKeys).stream()
+    Map<RuleKey, RuleDto> ruleDtos = db.ruleDao().selectByKeys(dbSession, ruleKeys).stream()
       .collect(Collectors.toMap(RuleDto::getKey, identity()));
 
     Set<RuleKey> unrecognizedRuleKeys = ruleKeys.stream()
-      .filter(r -> !rulesDefinitions.containsKey(r))
+      .filter(r -> !ruleDtos.containsKey(r))
       .collect(toSet());
 
     if (!unrecognizedRuleKeys.isEmpty()) {
@@ -177,11 +177,11 @@ public class QProfileBackuperImpl implements QProfileBackuper {
       for (RuleDto rule : rulesBasedOnDeprecatedKeys) {
         DeprecatedRuleKeyDto deprecatedRuleKey = deprecatedRuleKeysByUuid.get(rule.getUuid());
         RuleKey oldRuleKey = RuleKey.of(deprecatedRuleKey.getOldRepositoryKey(), deprecatedRuleKey.getOldRuleKey());
-        rulesDefinitions.put(oldRuleKey, rule);
+        ruleDtos.put(oldRuleKey, rule);
       }
     }
 
-    return rulesDefinitions;
+    return ruleDtos;
   }
 
   private static void checkIfRulesFromExternalEngines(Collection<RuleDto> ruleDefinitions) {