]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Jan 2014 07:27:11 +0000 (08:27 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Jan 2014 07:27:11 +0000 (08:27 +0100)
sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java

index caa6c7c2eacb0412f53a5c69d907f0836eb6fec8..083b888a1cf72ac28f16a60317dc33f9e30bd3f9 100644 (file)
@@ -66,7 +66,7 @@ public class QualityProfileDao implements ServerComponent {
     }
   }
 
-  public void delete(Integer id) {
+  public void delete(int id) {
     SqlSession session = mybatis.openSession();
     try {
       session.getMapper(QualityProfileMapper.class).delete(id);
@@ -94,7 +94,7 @@ public class QualityProfileDao implements ServerComponent {
     }
   }
 
-  public List<QualityProfileDto> selectByProject(Long projectId, String propKeyPrefix) {
+  public List<QualityProfileDto> selectByProject(long projectId, String propKeyPrefix) {
     SqlSession session = mybatis.openSession();
     try {
       return session.getMapper(QualityProfileMapper.class).selectByProject(projectId, propKeyPrefix);
@@ -113,12 +113,12 @@ public class QualityProfileDao implements ServerComponent {
   }
 
   @CheckForNull
-  public QualityProfileDto selectById(Integer id, SqlSession session) {
+  public QualityProfileDto selectById(int id, SqlSession session) {
     return session.getMapper(QualityProfileMapper.class).selectById(id);
   }
 
   @CheckForNull
-  public QualityProfileDto selectById(Integer id) {
+  public QualityProfileDto selectById(int id) {
     SqlSession session = mybatis.openSession();
     try {
       return selectById(id, session);
@@ -128,12 +128,12 @@ public class QualityProfileDao implements ServerComponent {
   }
 
   @CheckForNull
-  public QualityProfileDto selectParent(Integer childId, SqlSession session) {
+  public QualityProfileDto selectParent(int childId, SqlSession session) {
     return session.getMapper(QualityProfileMapper.class).selectParent(childId);
   }
 
   @CheckForNull
-  public QualityProfileDto selectParent(Integer childId) {
+  public QualityProfileDto selectParent(int childId) {
     SqlSession session = mybatis.openSession();
     try {
       return selectParent(childId, session);
index bd99a6a99cab33e73608863f2fc360ccdea8b8f4..99124fedc79a66051e25d23a0b6329697261d02b 100644 (file)
@@ -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;
   }
 
index b86e4370194dbdc39d23ee8e25116816e7096ced..6230ce16f94c6485d612bac77d52f0e4b3013a6c 100644 (file)
@@ -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;
index c4c21831d7857351e44017b6e9753bc0e56256f3..7e5f73f54defb4828a2b077043a3a4c00c2af7ab 100644 (file)
 
 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.");
     }
   }
 }