summaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-07 17:04:47 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-07 17:04:47 +0100
commitff2f7c88ae07aa885e8fc35ac8d185ccfd27ebb1 (patch)
treed046a3e728eeb04420c8f8a8c9f07b81b5b48cb6 /sonar-core/src
parentcba6dcf8b735ca9da345538c8308318c040ec899 (diff)
downloadsonarqube-ff2f7c88ae07aa885e8fc35ac8d185ccfd27ebb1.tar.gz
sonarqube-ff2f7c88ae07aa885e8fc35ac8d185ccfd27ebb1.zip
SONAR-4923 profiles page now uses Java face (expect for alerts)
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java61
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java22
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml68
-rw-r--r--sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java113
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/inheritance.xml23
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/parent.xml9
6 files changed, 208 insertions, 88 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
index f8a313b7aed..646d3edf2d9 100644
--- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
@@ -36,6 +36,40 @@ public class QualityProfileDao implements ServerComponent {
this.mybatis = mybatis;
}
+ public void insert(QualityProfileDto dto, SqlSession session) {
+ session.getMapper(QualityProfileMapper.class).insert(dto);
+ }
+
+ public void insert(QualityProfileDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ insert(dto, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void update(QualityProfileDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ session.getMapper(QualityProfileMapper.class).update(dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void delete(Integer id) {
+ SqlSession session = mybatis.openSession();
+ try {
+ session.getMapper(QualityProfileMapper.class).delete(id);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
public List<QualityProfileDto> selectAll() {
SqlSession session = mybatis.openSession();
try {
@@ -81,53 +115,46 @@ public class QualityProfileDao implements ServerComponent {
}
}
- public QualityProfileDto selectByNameAndLanguage(String name, String language) {
+ public List<QualityProfileDto> selectChildren(String name, String language) {
SqlSession session = mybatis.openSession();
try {
- return session.getMapper(QualityProfileMapper.class).selectByNameAndLanguage(StringUtils.upperCase(name), language);
+ return session.getMapper(QualityProfileMapper.class).selectChildren(StringUtils.upperCase(name), language);
} finally {
MyBatis.closeQuietly(session);
}
}
- public List<ComponentDto> selectProjects(String propertyKey, String propertyValue) {
+ public int countChildren(String name, String language) {
SqlSession session = mybatis.openSession();
try {
- return session.getMapper(QualityProfileMapper.class).selectProjects(propertyKey, propertyValue);
+ return session.getMapper(QualityProfileMapper.class).countChildren(StringUtils.upperCase(name), language);
} finally {
MyBatis.closeQuietly(session);
}
}
- public void insert(QualityProfileDto dto, SqlSession session) {
- session.getMapper(QualityProfileMapper.class).insert(dto);
- }
-
- public void insert(QualityProfileDto dto) {
+ public QualityProfileDto selectByNameAndLanguage(String name, String language) {
SqlSession session = mybatis.openSession();
try {
- insert(dto, session);
- session.commit();
+ return session.getMapper(QualityProfileMapper.class).selectByNameAndLanguage(StringUtils.upperCase(name), language);
} finally {
MyBatis.closeQuietly(session);
}
}
- public void update(QualityProfileDto dto) {
+ public List<ComponentDto> selectProjects(String propertyKey, String propertyValue) {
SqlSession session = mybatis.openSession();
try {
- session.getMapper(QualityProfileMapper.class).update(dto);
- session.commit();
+ return session.getMapper(QualityProfileMapper.class).selectProjects(propertyKey, propertyValue);
} finally {
MyBatis.closeQuietly(session);
}
}
- public void delete(Integer id) {
+ public int countProjects(String propertyKey, String propertyValue) {
SqlSession session = mybatis.openSession();
try {
- session.getMapper(QualityProfileMapper.class).delete(id);
- session.commit();
+ return session.getMapper(QualityProfileMapper.class).countProjects(propertyKey, propertyValue);
} finally {
MyBatis.closeQuietly(session);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
index f101e1036be..089e6b5d8bd 100644
--- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
@@ -29,6 +29,12 @@ import java.util.List;
public interface QualityProfileMapper {
+ void insert(QualityProfileDto dto);
+
+ void update(QualityProfileDto dto);
+
+ void delete(Integer id);
+
List<QualityProfileDto> selectAll();
@CheckForNull
@@ -40,17 +46,23 @@ public interface QualityProfileMapper {
@CheckForNull
QualityProfileDto selectById(@Param("id") Integer id);
+
+ // INHERITANCE
+
@CheckForNull
QualityProfileDto selectParent(@Param("childId") Integer childId);
- List<ComponentDto> selectProjects(@Param("value") String propertyValue, @Param("key") String propertyKey);
+ List<QualityProfileDto> selectChildren(@Param("name") String name, @Param("language") String language);
- List<QualityProfileDto> selectByProject(@Param("projectId") Long projectId, @Param("key") String propertyKeyPrefix);
+ int countChildren(@Param("name") String name, @Param("language") String language);
- void insert(QualityProfileDto dto);
+ // PROJECTS
- void update(QualityProfileDto dto);
+ List<ComponentDto> selectProjects(@Param("value") String propertyValue, @Param("key") String propertyKey);
+
+ int countProjects(@Param("value") String propertyValue, @Param("key") String propertyKey);
+
+ List<QualityProfileDto> selectByProject(@Param("projectId") Long projectId, @Param("key") String propertyKeyPrefix);
- void delete(Integer id);
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml
index 12943752f23..3fdf3073ce1 100644
--- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml
@@ -12,6 +12,25 @@
p.used_profile as used
</sql>
+ <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO rules_profiles (name, language, parent_name, version, used_profile)
+ VALUES (#{name}, #{language}, #{parent}, #{version}, #{used})
+ </insert>
+
+ <update id="update" parameterType="QualityProfile">
+ UPDATE rules_profiles SET
+ name=#{name},
+ language=#{language},
+ parent_name=#{parent},
+ version=#{version},
+ used_profile=#{used}
+ WHERE id=#{id}
+ </update>
+
+ <update id="delete" parameterType="Integer">
+ DELETE FROM rules_profiles WHERE id=#{id}
+ </update>
+
<select id="selectAll" parameterType="map" resultType="QualityProfile">
SELECT <include refid="profilesColumns"/>
FROM rules_profiles p
@@ -41,6 +60,25 @@
INNER JOIN rules_profiles child ON child.parent_name=p.name and child.language=p.language and child.id=#{childId}
</select>
+ <select id="selectChildren" parameterType="map" resultType="QualityProfile">
+ SELECT <include refid="profilesColumns"/>
+ FROM rules_profiles p
+ <where>
+ AND UPPER(p.parent_name)=#{name}
+ AND p.language=#{language}
+ </where>
+ ORDER BY p.name
+ </select>
+
+ <select id="countChildren" parameterType="map" resultType="Integer">
+ SELECT count(p.id)
+ FROM rules_profiles p
+ <where>
+ AND UPPER(p.parent_name)=#{name}
+ AND p.language=#{language}
+ </where>
+ </select>
+
<select id="selectDefaultProfile" parameterType="Integer" resultType="QualityProfile">
SELECT <include refid="profilesColumns"/>
FROM rules_profiles p
@@ -63,6 +101,17 @@
</where>
</select>
+ <select id="countProjects" parameterType="Integer" resultType="Integer">
+ SELECT count(projects.id)
+ FROM projects projects
+ LEFT JOIN properties ON properties.resource_id = projects.id
+ <where>
+ AND properties.resource_id IS NOT NULL
+ AND properties.prop_key=#{key}
+ AND properties.text_value LIKE #{value}
+ </where>
+ </select>
+
<select id="selectByProject" parameterType="map" resultType="QualityProfile">
SELECT DISTINCT <include refid="profilesColumns"/>
FROM rules_profiles p
@@ -71,24 +120,5 @@
AND prop.text_value LIKE p.name
</select>
- <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO rules_profiles (name, language, parent_name, version, used_profile)
- VALUES (#{name}, #{language}, #{parent}, #{version}, #{used})
- </insert>
-
- <update id="update" parameterType="QualityProfile">
- UPDATE rules_profiles SET
- name=#{name},
- language=#{language},
- parent_name=#{parent},
- version=#{version},
- used_profile=#{used}
- WHERE id=#{id}
- </update>
-
- <update id="delete" parameterType="Integer">
- DELETE FROM rules_profiles WHERE id=#{id}
- </update>
-
</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java
index ba0d7e3d7e1..f35bb8765bc 100644
--- a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java
@@ -37,6 +37,49 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase {
dao = new QualityProfileDao(getMyBatis());
}
+
+ @Test
+ public void insert() {
+ setupData("shared");
+
+ QualityProfileDto dto = new QualityProfileDto()
+ .setName("Sonar Way with Findbugs")
+ .setLanguage("xoo")
+ .setParent("Sonar Way")
+ .setVersion(2)
+ .setUsed(true);
+
+ dao.insert(dto);
+
+ checkTables("insert", "rules_profiles");
+ }
+
+ @Test
+ public void update() {
+ setupData("shared");
+
+ QualityProfileDto dto = new QualityProfileDto()
+ .setId(1)
+ .setName("New Sonar Way with Findbugs")
+ .setLanguage("js")
+ .setParent("New Sonar Way")
+ .setVersion(3)
+ .setUsed(false);
+
+ dao.update(dto);
+
+ checkTables("update", "rules_profiles");
+ }
+
+ @Test
+ public void delete() {
+ setupData("shared");
+
+ dao.delete(1);
+
+ checkTables("delete", "rules_profiles");
+ }
+
@Test
public void select_all() {
setupData("shared");
@@ -115,66 +158,60 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase {
@Test
public void select_parent() {
- setupData("parent");
+ setupData("inheritance");
QualityProfileDto dto = dao.selectParent(1);
- assertThat(dto.getId()).isEqualTo(2);
+ assertThat(dto.getId()).isEqualTo(3);
}
@Test
- public void select_projects() {
- setupData("projects");
+ public void select_children() {
+ setupData("inheritance");
- assertThat(dao.selectProjects("Sonar Way", "sonar.profile.java")).hasSize(2);
- }
+ List<QualityProfileDto> dtos = dao.selectChildren("Parent", "java");
- @Test
- public void select_by_project() {
- setupData("projects");
+ assertThat(dtos).hasSize(2);
- assertThat(dao.selectByProject(1L, "sonar.profile.%")).hasSize(2);
+ QualityProfileDto dto1 = dtos.get(0);
+ assertThat(dto1.getId()).isEqualTo(1);
+ assertThat(dto1.getName()).isEqualTo("Child1");
+ assertThat(dto1.getLanguage()).isEqualTo("java");
+ assertThat(dto1.getParent()).isEqualTo("Parent");
+
+ QualityProfileDto dto2 = dtos.get(1);
+ assertThat(dto2.getId()).isEqualTo(2);
+ assertThat(dto2.getName()).isEqualTo("Child2");
+ assertThat(dto2.getLanguage()).isEqualTo("java");
+ assertThat(dto2.getParent()).isEqualTo("Parent");
}
@Test
- public void insert() {
- setupData("shared");
+ public void count_children() {
+ setupData("inheritance");
- QualityProfileDto dto = new QualityProfileDto()
- .setName("Sonar Way with Findbugs")
- .setLanguage("xoo")
- .setParent("Sonar Way")
- .setVersion(2)
- .setUsed(true);
-
- dao.insert(dto);
-
- checkTables("insert", "rules_profiles");
+ assertThat(dao.countChildren("Parent", "java")).isEqualTo(2);
}
@Test
- public void update() {
- setupData("shared");
+ public void select_projects() {
+ setupData("projects");
- QualityProfileDto dto = new QualityProfileDto()
- .setId(1)
- .setName("New Sonar Way with Findbugs")
- .setLanguage("js")
- .setParent("New Sonar Way")
- .setVersion(3)
- .setUsed(false);
+ assertThat(dao.selectProjects("Sonar Way", "sonar.profile.java")).hasSize(2);
+ }
- dao.update(dto);
+ @Test
+ public void count_projects() {
+ setupData("projects");
- checkTables("update", "rules_profiles");
+ assertThat(dao.countProjects("Sonar Way", "sonar.profile.java")).isEqualTo(2);
}
@Test
- public void delete() {
- setupData("shared");
-
- dao.delete(1);
+ public void select_by_project() {
+ setupData("projects");
- checkTables("delete", "rules_profiles");
+ assertThat(dao.selectByProject(1L, "sonar.profile.%")).hasSize(2);
}
+
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/inheritance.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/inheritance.xml
new file mode 100644
index 00000000000..b74e6a003f2
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/inheritance.xml
@@ -0,0 +1,23 @@
+<dataset>
+
+ <rules_profiles id="1" name="Child1" language="java" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="2" name="Child2" language="java" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="3" name="Parent" language="java" parent_name="[null]" version="1"
+ used_profile="[false]"/>
+
+ <!-- Same profile for another language -->
+
+ <rules_profiles id="4" name="Child1" language="js" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="5" name="Child2" language="js" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="6" name="Parent" language="js" parent_name="[null]" version="1"
+ used_profile="[false]"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/parent.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/parent.xml
deleted file mode 100644
index 2c978506b6d..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/parent.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-
- <rules_profiles id="1" name="Child" language="java" parent_name="Parent" version="1"
- used_profile="[false]"/>
-
- <rules_profiles id="2" name="Parent" language="java" parent_name="[null]" version="1"
- used_profile="[false]"/>
-
-</dataset>