aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-03 17:37:34 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-03 17:37:34 +0100
commit31af09b42f8aafb2a56522e8670b574603cd9eee (patch)
tree8ad623c3a6a658b4cb45a755367ad24adf995747 /sonar-core
parent68e772f2ce0b97b4c2cdb7f5d16c4bb6202b02d6 (diff)
downloadsonarqube-31af09b42f8aafb2a56522e8670b574603cd9eee.tar.gz
sonarqube-31af09b42f8aafb2a56522e8670b574603cd9eee.zip
SONAR-2094 Do not delete ACTIVE_RULES rows when rules are disabled
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java51
-rw-r--r--sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java51
-rw-r--r--sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml19
-rw-r--r--sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile.xml13
-rw-r--r--sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldSynchronizeRuleOfActiveRule.xml13
5 files changed, 0 insertions, 147 deletions
diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java
index 8cb5151c7f5..b90e8afe852 100644
--- a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java
+++ b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java
@@ -57,60 +57,9 @@ public class RulesDao extends BaseDao {
return getSession().getSingleResult(Rule.class, "key", ruleKey, "pluginName", repositoryKey, "enabled", true);
}
- public Long countRules(List<String> plugins) {
- return (Long) getSession().createQuery(
- "SELECT COUNT(r) FROM Rule r WHERE r.pluginName IN (:pluginNames) AND r.enabled=true").
- setParameter("pluginNames", plugins).
- getSingleResult();
- }
-
- public List<RuleParam> getRuleParams() {
- return getSession().getResults(RuleParam.class);
- }
public RuleParam getRuleParam(Rule rule, String paramKey) {
return getSession().getSingleResult(RuleParam.class, "rule", rule, "key", paramKey);
}
- public void addActiveRulesToProfile(List<ActiveRule> activeRules, int profileId, String pluginKey) {
- RulesProfile rulesProfile = getProfileById(profileId);
- for (ActiveRule activeRule : activeRules) {
- synchronizeRuleOfActiveRule(activeRule, pluginKey);
- activeRule.setRulesProfile(rulesProfile);
- getSession().save(activeRule);
- }
- }
-
- public List<RuleFailureModel> getViolations(Snapshot snapshot) {
- return getSession().getResults(RuleFailureModel.class, "snapshotId", snapshot.getId());
- }
-
- public void synchronizeRuleOfActiveRule(ActiveRule activeRule, String pluginKey) {
- Rule rule = activeRule.getRule();
- Rule ruleFromDataBase = getRuleByKey(pluginKey, rule.getKey());
- activeRule.setRule(ruleFromDataBase);
- List<RuleParam> ruleParamsFromDataBase = getRuleParams();
- for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
- boolean found = false;
- Iterator<RuleParam> iterator = ruleParamsFromDataBase.iterator();
- while (iterator.hasNext() && !found) {
- RuleParam ruleParamFromDataBase = iterator.next();
- if (isRuleParamEqual(activeRuleParam.getRuleParam(), ruleParamFromDataBase, rule.getKey(), pluginKey)) {
- activeRuleParam.setRuleParam(ruleParamFromDataBase);
- found = true;
- }
- }
- }
- }
-
- public boolean isRuleParamEqual(RuleParam ruleParam, RuleParam ruleParamFromDatabase, String ruleKey, String pluginKey) {
- return ruleParam.getKey().equals(ruleParamFromDatabase.getKey()) &&
- ruleKey.equals(ruleParamFromDatabase.getRule().getKey()) &&
- ruleParamFromDatabase.getRule().getPluginName().equals(pluginKey);
- }
-
- public RulesProfile getProfileById(int profileId) {
- return getSession().getEntityManager().getReference(RulesProfile.class, profileId);
- }
-
}
diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java
index 4656c20bb1b..7d1b0e97a64 100644
--- a/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java
@@ -65,55 +65,4 @@ public class RulesDaoTest extends AbstractDbUnitTestCase {
assertThat(rule2, nullValue());
}
- @Test
- public void shouldGetRuleParams() {
- setupData("shouldGetRuleParams");
-
- List<RuleParam> ruleParams = rulesDao.getRuleParams();
-
- assertThat(ruleParams.size(), is(3));
- }
-
- @Test
- public void shouldSynchronizeRuleOfActiveRule() {
- setupData("shouldSynchronizeRuleOfActiveRule");
- Rule rule = new Rule(null, "other key", (String) null, null, null);
- RuleParam ruleParam = new RuleParam(null, "rule1_param1", null, null);
- rule.setParams(Arrays.asList(ruleParam));
- ActiveRule activeRule = new ActiveRule(null, rule, null);
- ActiveRuleParam activeRuleParam = new ActiveRuleParam(activeRule, ruleParam, null);
- activeRule.setActiveRuleParams(Arrays.asList(activeRuleParam));
-
- rulesDao.synchronizeRuleOfActiveRule(activeRule, "plugin");
-
- assertThat(activeRule.getRule().getId(), notNullValue());
- assertThat(activeRule.getActiveRuleParams().size(), is(1));
- }
-
- @Test
- public void shouldGetRulesProfileById() {
- RulesProfile rulesProfile = new RulesProfile("profil", "java", true, true);
- getSession().save(rulesProfile);
-
- RulesProfile rulesProfileExpected = rulesDao.getProfileById(rulesProfile.getId());
-
- assertThat(rulesProfileExpected, is(rulesProfile));
- }
-
- @Test
- public void shouldAddActiveRulesToProfile() {
- setupData("shouldAddActiveRulesToProfile");
-
- Rule rule = new Rule("rule1", "key1", "config1", null, null);
- RuleParam ruleParam = new RuleParam(null, "param1", null, null);
- rule.setParams(Arrays.asList(ruleParam));
-
- ActiveRule activeRule = new ActiveRule(null, rule, RulePriority.MAJOR);
- ActiveRuleParam activeRuleParam = new ActiveRuleParam(activeRule, ruleParam, "20");
- activeRule.setActiveRuleParams(Arrays.asList(activeRuleParam));
- rulesDao.addActiveRulesToProfile(Arrays.asList(activeRule), 1, "plugin");
-
- checkTables("shouldAddActiveRulesToProfile", "rules", "active_rules", "rules_profiles");
- }
-
}
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml
deleted file mode 100644
index cecf13ba8e1..00000000000
--- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<dataset>
-
- <rules_profiles id="1" parent_name="[null]" provided="true" name="profile" default_profile="1" language="java" enabled="true"/>
-
- <rules_categories id="1" name="category one" description="[null]"/>
-
- <rules id="1" name="rule1" description="desc" plugin_config_key="config1"
- plugin_rule_key="key1" plugin_name="plugin" priority="1" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
-
- <rules_parameters id="1" rule_id="1" name="param1" description="foo" param_type="r"/>
-
- <!-- Active rule created -->
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
-
- <!-- Active rule param created -->
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>
-
-
-</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile.xml
deleted file mode 100644
index 0851c7441a0..00000000000
--- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
- <rules_profiles id="1" provided="true" name="profile" default_profile="1" language="java" enabled="true"/>
-
- <rules_categories id="1" name="category one" description="[null]"/>
-
- <rules id="1" name="rule1" description="desc" plugin_config_key="config1"
- plugin_rule_key="key1" plugin_name="plugin" priority="1" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
-
- <rules_parameters id="1" rule_id="1" name="param1" description="foo" param_type="r"/>
-
-
-</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldSynchronizeRuleOfActiveRule.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldSynchronizeRuleOfActiveRule.xml
deleted file mode 100644
index 94227fff982..00000000000
--- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldSynchronizeRuleOfActiveRule.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
- <rules_categories id="1" name="category one" description="[null]"/>
-
- <rules id="1" name="other rule" description="desc" plugin_config_key="other config"
- plugin_rule_key="other key" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
- <rules id="2" name="rule" description="desc" plugin_config_key="config"
- plugin_rule_key="key" plugin_name="other plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
-
- <rules_parameters id="1" rule_id="1" name="rule1_param1" description="rule1_desc1" param_type="r" />
- <rules_parameters id="2" rule_id="2" name="rule2_param1" description="rule2_desc1" param_type="r" />
-
-</dataset> \ No newline at end of file