diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-01-15 08:27:11 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-01-15 08:27:11 +0100 |
commit | bb22ca234e9c08da5ee9cff94d32db983322bdac (patch) | |
tree | 4ceba2727e01ba733e51e47877a37490ea9a4e69 /sonar-server | |
parent | eec173a9c939e0620ccbfd72ed00cb3286777cd7 (diff) | |
download | sonarqube-bb22ca234e9c08da5ee9cff94d32db983322bdac.tar.gz sonarqube-bb22ca234e9c08da5ee9cff94d32db983322bdac.zip |
Fix quality flaws
Diffstat (limited to 'sonar-server')
3 files changed, 26 insertions, 17 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java index bd99a6a99ca..99124fedc79 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java @@ -39,7 +39,6 @@ import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleParamDto; import org.sonar.server.configuration.ProfilesManager; import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.rule.RuleRegistry; import org.sonar.server.user.UserSession; @@ -149,7 +148,7 @@ public class QProfileActiveRuleOperations implements ServerComponent { validatePermission(userSession); SqlSession session = myBatis.openSession(); try { - ActiveRuleDto activeRule = findActiveRule(profileId, ruleId, session); + ActiveRuleDto activeRule = findActiveRuleNotNull(profileId, ruleId, session); return deactivateRule(activeRule, userSession, session); } finally { MyBatis.closeQuietly(session); @@ -458,11 +457,15 @@ public class QProfileActiveRuleOperations implements ServerComponent { return activeRuleDao.selectByProfileAndRule(profileId, ruleId, session); } + private ActiveRuleDto findActiveRuleNotNull(int profileId, int ruleId, SqlSession session) { + ActiveRuleDto activeRule = findActiveRule(profileId, ruleId, session); + QProfileValidations.checkActiveRuleIsNotNull(activeRule); + return activeRule; + } + private ActiveRuleDto findActiveRuleNotNull(int activeRuleId, SqlSession session) { ActiveRuleDto activeRule = activeRuleDao.selectById(activeRuleId, session); - if (activeRule == null) { - throw new NotFoundException("This active rule does not exists."); - } + QProfileValidations.checkActiveRuleIsNotNull(activeRule); return activeRule; } diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java index b86e4370194..6230ce16f94 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java @@ -81,10 +81,11 @@ public class QProfileLookup implements ServerComponent { @CheckForNull public QProfile parent(QProfile profile) { - if (profile.parent() != null) { - QualityProfileDto parent = findQualityProfile(profile.parent(), profile.language()); - if (parent != null) { - return QProfile.from(parent); + String parent = profile.parent(); + if (parent != null) { + QualityProfileDto parentDto = findQualityProfile(parent, profile.language()); + if (parentDto != null) { + return QProfile.from(parentDto); } } return null; diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java index c4c21831d78..7e5f73f54de 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java @@ -20,33 +20,38 @@ package org.sonar.server.qualityprofile; +import org.sonar.core.qualityprofile.db.ActiveRuleDto; import org.sonar.core.qualityprofile.db.QualityProfileDto; import org.sonar.core.rule.RuleDto; import org.sonar.server.exceptions.NotFoundException; +import javax.annotation.Nullable; + public class QProfileValidations { - public static void checkProfileIsNotNull(QProfile profile) { + private static final String QUALITY_PROFILE_DOES_NOT_EXISTS_MESSAGE = "This quality profile does not exists."; + + public static void checkProfileIsNotNull(@Nullable QProfile profile) { if (profile == null) { - throw new NotFoundException("This quality profile does not exists."); + throw new NotFoundException(QUALITY_PROFILE_DOES_NOT_EXISTS_MESSAGE); } } - public static void checkProfileIsNotNull(QualityProfileDto profile) { + public static void checkProfileIsNotNull(@Nullable QualityProfileDto profile) { if (profile == null) { - throw new NotFoundException("This quality profile does not exists."); + throw new NotFoundException(QUALITY_PROFILE_DOES_NOT_EXISTS_MESSAGE); } } - public static void checkRuleIsNotNull(QProfileRule rule) { + public static void checkRuleIsNotNull(@Nullable RuleDto rule) { if (rule == null) { throw new NotFoundException("This rule does not exists."); } } - public static void checkRuleIsNotNull(RuleDto rule) { - if (rule == null) { - throw new NotFoundException("This rule does not exists."); + public static void checkActiveRuleIsNotNull(@Nullable ActiveRuleDto activeRule) { + if (activeRule == null) { + throw new NotFoundException("This active rule does not exists."); } } } |