From: Aurelien Poscia Date: Fri, 20 May 2022 08:18:02 +0000 (+0200) Subject: SONAR-16413 fix quality profile copy inconsistency X-Git-Tag: 9.5.0.56709~124 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7e0bd442a7d8ee660d3f1e069ecb0d01dc24e5d3;p=sonarqube.git SONAR-16413 fix quality profile copy inconsistency --- diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java index 99f173b8625..ffa21ec4388 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java @@ -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 importedRules = qProfile.getRules(); - Map ruleDefinitionsByKey = getImportedRulesDefinitions(dbSession, importedRules); - checkIfRulesFromExternalEngines(ruleDefinitionsByKey.values()); + Map ruleKeyToDto = getImportedRulesDtos(dbSession, importedRules); + checkIfRulesFromExternalEngines(ruleKeyToDto.values()); - Map customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleDefinitionsByKey); - ruleDefinitionsByKey.putAll(customRulesDefinitions); + Map customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleKeyToDto); + ruleKeyToDto.putAll(customRulesDefinitions); - List ruleActivations = toRuleActivations(importedRules, ruleDefinitionsByKey); + List 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 getImportedRulesDefinitions(DbSession dbSession, List rules) { + private Map getImportedRulesDtos(DbSession dbSession, List rules) { Set ruleKeys = rules.stream() .map(ImportedRule::getRuleKey) .collect(toSet()); - Map rulesDefinitions = db.ruleDao().selectByKeys(dbSession, ruleKeys).stream() + Map ruleDtos = db.ruleDao().selectByKeys(dbSession, ruleKeys).stream() .collect(Collectors.toMap(RuleDto::getKey, identity())); Set 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 ruleDefinitions) {