From af8cbb165e10a9bcd5ccef57ec7813645bfaf5d4 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 1 Feb 2011 22:08:15 +0100 Subject: SONAR-2094 Add the column RULES_PROFILES.ENABLED --- .../main/java/org/sonar/jpa/dao/ProfilesDao.java | 28 +++------------------- .../java/org/sonar/jpa/entity/SchemaMigration.java | 2 +- .../java/org/sonar/jpa/dao/ProfilesDaoTest.java | 14 ++--------- .../jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml | 6 ++--- .../shouldAddActiveRulesToProfile-result.xml | 2 +- .../RulesDaoTest/shouldAddActiveRulesToProfile.xml | 2 +- ...tiveRuleParametersFromARuleParameter-result.xml | 4 ++-- ...eleteActiveRuleParametersFromARuleParameter.xml | 4 ++-- .../shouldDeleteActiveRules-result.xml | 4 ++-- .../dao/RulesDaoTest/shouldDeleteActiveRules.xml | 4 ++-- .../jpa/dao/RulesDaoTest/shouldGetActiveRules.xml | 4 ++-- 11 files changed, 21 insertions(+), 53 deletions(-) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java index 65944ab720b..ba1eb21cf80 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java @@ -23,44 +23,22 @@ import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.profiles.RulesProfile; -import java.util.List; - public class ProfilesDao extends BaseDao { public ProfilesDao(DatabaseSession session) { super(session); } - public List getActiveProfiles() { - return getSession().getResults(RulesProfile.class, "defaultProfile", true); - } - public RulesProfile getActiveProfile(String languageKey, String projectResourceKey) { ResourceModel projectResource = getSession().getSingleResult(ResourceModel.class, "key", projectResourceKey, "scope", ResourceModel.SCOPE_PROJECT); - if (projectResource != null && projectResource.getRulesProfile() != null) { + if (projectResource != null && projectResource.getRulesProfile() != null && projectResource.getRulesProfile().isEnabled()) { return projectResource.getRulesProfile(); } - return getSession().getSingleResult(RulesProfile.class, "defaultProfile", true, "language", languageKey); - } - - public List getProfiles(String languageKey) { - return getSession().getResults(RulesProfile.class, "language", languageKey); - } - - public List getProfiles() { - return getSession().getResults(RulesProfile.class); - } - - public List getProvidedProfiles() { - return getSession().getResults(RulesProfile.class, "provided", true); + return getSession().getSingleResult(RulesProfile.class, "defaultProfile", true, "language", languageKey, "enabled", true); } public RulesProfile getProfile(String languageKey, String profileName) { - return getSession().getSingleResult(RulesProfile.class, "language", languageKey, "name", profileName); - } - - public RulesProfile getProfileById(int profileId) { - return getSession().getEntityManager().getReference(RulesProfile.class, profileId); + return getSession().getSingleResult(RulesProfile.class, "language", languageKey, "name", profileName, "enabled", true); } } diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index a80961ba4ce..921cbcab6d3 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -31,7 +31,7 @@ import javax.persistence.*; public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 170; + public static final int LAST_VERSION = 180; public final static String TABLE_NAME = "schema_migrations"; diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java index 796435c5dab..0b821d51dc2 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java @@ -25,10 +25,8 @@ import org.sonar.api.database.model.ResourceModel; import org.sonar.api.profiles.RulesProfile; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class ProfilesDaoTest extends AbstractDbUnitTestCase { @@ -39,14 +37,6 @@ public class ProfilesDaoTest extends AbstractDbUnitTestCase { profilesDao = new ProfilesDao(getSession()); } - @Test - public void shouldGetProfiles() { - setupData("shouldGetProfiles"); - - List profiles = profilesDao.getProfiles("java"); - - assertThat(profiles.size(), is(2)); - } @Test public void testGetActiveProfile() { diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml index f1e87d6dcb5..3325d8baf74 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml @@ -1,7 +1,7 @@ - - - + + + \ No newline at end of file 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 index cd31402ceb1..cecf13ba8e1 100644 --- 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 @@ -1,6 +1,6 @@ - + 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 index 19b124c737d..0851c7441a0 100644 --- 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 @@ -1,6 +1,6 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml index 5f86b049240..be6be226a56 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml @@ -8,8 +8,8 @@ - - + + diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml index f2d17bc78be..f19937676d1 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml @@ -8,8 +8,8 @@ - - + + diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml index 736de8e2412..94757dbf118 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml @@ -2,8 +2,8 @@ - - + + diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml index 89f2fecf7cf..de59da7e6e7 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml @@ -2,8 +2,8 @@ - - + + diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml index 736de8e2412..94757dbf118 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml @@ -2,8 +2,8 @@ - - + + -- cgit v1.2.3