]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Jan 2014 09:57:56 +0000 (10:57 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Jan 2014 09:58:05 +0000 (10:58 +0100)
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java

index ffd9a248f9c1dff19085df5d3a6570fd69766981..e18c9f9c5d8a87626cfeb7d37c9e93eea200f2e3 100644 (file)
@@ -98,7 +98,7 @@ public class ProfilesBackup {
   public void importXml(SonarConfig sonarConfig) {
     if (sonarConfig.getProfiles() != null && !sonarConfig.getProfiles().isEmpty()) {
       LoggerFactory.getLogger(getClass()).info("Delete profiles");
-      ProfilesManager profilesManager = new ProfilesManager(session, null, dryRunCache);
+      ProfilesManager profilesManager = new ProfilesManager(session, dryRunCache);
       profilesManager.deleteAllProfiles();
 
       RulesDao rulesDao = new RulesDao(session);
index ec346d02146e89c4d3569b2e8a308200213b68e0..358871b25fb83208250e1c95fab251e149235985 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.core.preview.PreviewCache;
 import org.sonar.jpa.dao.BaseDao;
 import org.sonar.jpa.dao.RulesDao;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 import java.util.List;
@@ -44,6 +45,11 @@ public class ProfilesManager extends BaseDao {
     this.dryRunCache = dryRunCache;
   }
 
+  public ProfilesManager(DatabaseSession session, PreviewCache dryRunCache) {
+    super(session);
+    this.dryRunCache = dryRunCache;
+  }
+
   public int copyProfile(int profileId, String newProfileName) {
     RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId);
     RulesProfile toImport = (RulesProfile) profile.clone();
@@ -137,7 +143,7 @@ public class ProfilesManager extends BaseDao {
   /**
    * Rule param was changed
    */
-  public RuleInheritanceActions ruleParamChanged(int profileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) {
+  public RuleInheritanceActions ruleParamChanged(int profileId, int activeRuleId, String paramKey, @Nullable String oldValue, @Nullable String newValue, String userName) {
     ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId);
     RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
 
@@ -391,12 +397,14 @@ public class ProfilesManager extends BaseDao {
     getSession().removeWithoutFlush(activeRule);
   }
 
-  RulesProfile getProfile(String language, String name) {
+  @CheckForNull
+  RulesProfile getProfile(String language, @Nullable String name) {
     return getSession().getSingleResult(RulesProfile.class,
       "language", language,
       "name", name);
   }
 
+  @CheckForNull
   RulesProfile getParentProfile(RulesProfile profile) {
     if (profile.getParentName() == null) {
       return null;
index f35dfc24f850d69b645b430f8d64900832c0fb36..7c2a42d1adb8c405e44de65dc8db80bc5d239e8a 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ibatis.session.SqlSession;
 import org.elasticsearch.common.base.Predicate;
 import org.elasticsearch.common.collect.Iterables;
 import org.sonar.api.ServerComponent;
-import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.rules.RulePriority;
+import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.api.utils.System2;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.MyBatis;
@@ -118,7 +118,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
       activeRuleDao.insert(activeRuleParam, session);
     }
     session.commit();
-    ProfilesManager.RuleInheritanceActions actions = profilesManager.activated(profileId, activeRule.getId(), userSession.name());
+    ProfilesManager.RuleInheritanceActions actions = profilesManager.activated(profileId, activeRule.getId(), getLoggedName(userSession));
     reindexInheritanceResult(actions, session);
     return activeRule;
   }
@@ -159,7 +159,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
 
   private boolean deactivateRule(ActiveRuleDto activeRule, UserSession userSession, SqlSession session) {
     if (activeRule.getInheritance() == null) {
-      ProfilesManager.RuleInheritanceActions actions = profilesManager.deactivated(activeRule.getProfileId(), activeRule.getId(), userSession.name());
+      ProfilesManager.RuleInheritanceActions actions = profilesManager.deactivated(activeRule.getProfileId(), activeRule.getId(), getLoggedName(userSession));
 
       activeRuleDao.deleteParameters(activeRule.getId(), session);
       activeRuleDao.delete(activeRule.getId(), session);
@@ -219,7 +219,8 @@ public class QProfileActiveRuleOperations implements ServerComponent {
     activeRuleDao.insert(activeRuleParam, session);
     session.commit();
 
-    ProfilesManager.RuleInheritanceActions actions = profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), key, null, value, userSession.name());
+    ProfilesManager.RuleInheritanceActions actions = profilesManager.ruleParamChanged(
+      activeRule.getProfileId(), activeRule.getId(), key, null, value, getLoggedName(userSession));
     reindexInheritanceResult(actions, session);
   }
 
@@ -310,7 +311,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
       } else {
         activeRuleDao.deleteParameter(param.getId(), session);
         session.commit();
-        actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), key, param.getValue(), null, userSession.name()));
+        actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), key, param.getValue(), null, getLoggedName(userSession)));
       }
       paramKeys.add(key);
     }
@@ -321,7 +322,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
         activeRuleDao.insert(activeRuleParam, session);
         session.commit();
         newParams.add(activeRuleParam);
-        actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), parentParam.getKey(), null, parentParam.getValue(), userSession.name()));
+        actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), parentParam.getKey(), null, parentParam.getValue(), getLoggedName(userSession)));
       }
     }
     return newParams;
@@ -336,7 +337,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
       activeRuleDao.update(activeRule, session);
       session.commit();
       actions.add(profilesManager.ruleSeverityChanged(activeRule.getProfileId(), activeRule.getId(),
-        RulePriority.valueOf(getSeverityFromOrdinal(oldSeverity)), RulePriority.valueOf(getSeverityFromOrdinal(newSeverity)), userSession.name()));
+        RulePriority.valueOf(getSeverityFromOrdinal(oldSeverity)), RulePriority.valueOf(getSeverityFromOrdinal(newSeverity)), getLoggedName(userSession)));
     }
   }
 
@@ -382,7 +383,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
     ProfilesManager.RuleInheritanceActions actions = new ProfilesManager.RuleInheritanceActions();
     for (ActiveRuleParamDto activeRuleParam : params) {
       actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), activeRuleParam.getKey(), activeRuleParam.getValue(),
-        null, userSession.name()));
+        null, getLoggedName(userSession)));
     }
     reindexInheritanceResult(actions, session);
   }
@@ -390,7 +391,7 @@ public class QProfileActiveRuleOperations implements ServerComponent {
   private void notifySeverityChanged(ActiveRuleDto activeRule, String newSeverity, String oldSeverity, SqlSession session, UserSession userSession) {
     ProfilesManager.RuleInheritanceActions actions = profilesManager.ruleSeverityChanged(activeRule.getProfileId(), activeRule.getId(),
       RulePriority.valueOf(oldSeverity), RulePriority.valueOf(newSeverity),
-      userSession.name());
+      getLoggedName(userSession));
     reindexInheritanceResult(actions, session);
   }