]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7400 Replace ActiveRuleDao#selectByRule by selectByRuleId 971/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 May 2016 09:21:08 +0000 (11:21 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 May 2016 10:08:18 +0000 (12:08 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java
server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java

index 6c2b8422e0184391fafdcaf20a0daf3c740018cb..4e1bc6ae9bdfc32bb7cb6af3b0f229a2a6837015 100644 (file)
@@ -335,7 +335,7 @@ public class RuleActivator {
    */
   public List<ActiveRuleChange> deactivate(DbSession dbSession, RuleDto ruleDto) {
     List<ActiveRuleChange> changes = Lists.newArrayList();
-    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRule(dbSession, ruleDto);
+    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRuleId(dbSession, ruleDto.getId());
     for (ActiveRuleDto activeRule : activeRules) {
       changes.addAll(deactivate(dbSession, activeRule.getKey(), true));
     }
index 36ad359472e6d9b9e6e2f223b654677106f77db9..dd8cd06cc9d0ee2e7bd4777f13101e0d95007ca9 100644 (file)
@@ -290,7 +290,7 @@ public class RegisterRules implements Startable {
     for (RuleParamDto paramDto : paramDtos) {
       RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
       if (paramDef == null) {
-        dbClient.activeRuleDao().deleteParamsByRuleParam(session, rule, paramDto.getName());
+        dbClient.activeRuleDao().deleteParamsByRuleParam(session, rule.getId(), paramDto.getName());
         dbClient.ruleDao().deleteRuleParam(session, paramDto.getId());
       } else {
         if (mergeParam(paramDto, paramDef)) {
@@ -312,7 +312,7 @@ public class RegisterRules implements Startable {
         dbClient.ruleDao().insertRuleParam(session, rule, paramDto);
         if (!StringUtils.isEmpty(param.defaultValue())) {
           // Propagate the default value to existing active rule parameters
-          for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRule(session, rule)) {
+          for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleId(session, rule.getId())) {
             ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
             dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
           }
index a031895eadf7e928f34eb91085d629ff213142dd..fd0ef2727a9a81c6b6483f955b051842fa26c173 100644 (file)
@@ -252,7 +252,7 @@ public class RuleUpdater {
   }
 
   private Multimap<ActiveRuleDto, ActiveRuleParamDto> getActiveRuleParamsByActiveRule(DbSession dbSession, RuleDto customRule) {
-    List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRule(dbSession, customRule);
+    List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, customRule.getId());
     Map<Integer, ActiveRuleDto> activeRuleById = from(activeRuleDtos).uniqueIndex(ActiveRuleDtoToId.INSTANCE);
     List<Integer> activeRuleIds = from(activeRuleDtos)
       .transform(ActiveRuleDtoToId.INSTANCE)
index e8c26af0b450bdf1cde7f60aa83636470f4bfa2f..1a2a3122825e2112a779520a020f85e85a3ddc6f 100644 (file)
@@ -143,7 +143,7 @@ public class ActiveRuleCompleter {
   }
 
   void completeShow(DbSession dbSession, RuleDto rule, ShowResponse.Builder response) {
-    List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRule(dbSession, rule);
+    List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, rule.getId());
     Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
     for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
       activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey());
index 5a59174436993343588b5bebb5f50b334deed7fe..36bd0c012f21b595caa635a49ad0e5f2bc7f45f3 100644 (file)
@@ -375,7 +375,7 @@ public class QProfilesWsMediumTest {
     session.commit();
 
     // 2. Assert ActiveRule with MINOR severity
-    assertThat(tester.get(ActiveRuleDao.class).selectByRule(session, rule0).get(0).getSeverityString()).isEqualTo("MINOR");
+    assertThat(tester.get(ActiveRuleDao.class).selectByRuleId(session, rule0.getId()).get(0).getSeverityString()).isEqualTo("MINOR");
     assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery()
       .setQProfileKey(profile.getKey())
       .setKey(rule0.getKey().toString())
index 07bf2d770d638a7f76aa14490adfb1ae11ec5c8b..a80c442315145cdb492dab72fc326dd3c946e257 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.db.Dao;
 import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.RowNotFoundException;
-import org.sonar.db.rule.RuleDto;
 
 public class ActiveRuleDao implements Dao {
 
@@ -59,9 +58,8 @@ public class ActiveRuleDao implements Dao {
     return DatabaseUtils.executeLargeInputs(keys, new KeyToDto(mapper(dbSession)));
   }
 
-  public List<ActiveRuleDto> selectByRule(DbSession dbSession, RuleDto rule) {
-    Preconditions.checkNotNull(rule.getId(), RULE_IS_NOT_PERSISTED);
-    return mapper(dbSession).selectByRuleId(rule.getId());
+  public List<ActiveRuleDto> selectByRuleId(DbSession dbSession, int ruleId) {
+    return mapper(dbSession).selectByRuleId(ruleId);
   }
 
   public List<ActiveRuleDto> selectByRuleIds(DbSession dbSession, List<Integer> ids) {
@@ -168,8 +166,8 @@ public class ActiveRuleDao implements Dao {
     }
   }
 
-  public void deleteParamsByRuleParam(DbSession dbSession, RuleDto rule, String paramKey) {
-    List<ActiveRuleDto> activeRules = selectByRule(dbSession, rule);
+  public void deleteParamsByRuleParam(DbSession dbSession, int ruleId, String paramKey) {
+    List<ActiveRuleDto> activeRules = selectByRuleId(dbSession, ruleId);
     for (ActiveRuleDto activeRule : activeRules) {
       for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
         if (activeParam.getKey().equals(paramKey)) {
index 9567f8ecaa96577323104b9910c9e0720d98eacb..a7b09360e8c402ae1ff3d8117bf579eb1585a472 100644 (file)
@@ -153,8 +153,8 @@ public class ActiveRuleDaoTest {
     underTest.insert(dbTester.getSession(), activeRule2);
     dbSession.commit();
 
-    assertThat(underTest.selectByRule(dbSession, rule1)).extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey());
-    assertThat(underTest.selectByRule(dbSession, rule3)).isEmpty();
+    assertThat(underTest.selectByRuleId(dbSession, rule1.getId())).extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey());
+    assertThat(underTest.selectByRuleId(dbSession, rule3.getId())).isEmpty();
   }
 
   @Test
@@ -512,7 +512,7 @@ public class ActiveRuleDaoTest {
 
     dbSession.commit();
 
-    underTest.deleteParamsByRuleParam(dbSession, rule1, rule1Param1.getName());
+    underTest.deleteParamsByRuleParam(dbSession, rule1.getId(), rule1Param1.getName());
     dbSession.commit();
 
     assertThat(underTest.selectParamByKeyAndName(activeRule1.getKey(), activeRuleParam1.getKey(), dbSession)).isNull();
@@ -533,6 +533,6 @@ public class ActiveRuleDaoTest {
 
     dbSession.commit();
 
-    underTest.deleteParamsByRuleParam(dbSession, rule1, "unknown");
+    underTest.deleteParamsByRuleParam(dbSession, rule1.getId(), "unknown");
   }
 }