diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-17 18:36:38 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-17 18:36:38 +0200 |
commit | ec362118f5482b294fc657c00be6288142106428 (patch) | |
tree | 3aa0cb026d9cb7f517a78207a179bfb36404750f /sonar-core | |
parent | 32ec8599d050066e41e12acd4b554febd3920197 (diff) | |
download | sonarqube-ec362118f5482b294fc657c00be6288142106428.tar.gz sonarqube-ec362118f5482b294fc657c00be6288142106428.zip |
SONAR-4392 List and edit existing issues filter
Diffstat (limited to 'sonar-core')
6 files changed, 48 insertions, 7 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueFilter.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueFilter.java index 03ec5dac42b..db2b2b9fbf7 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueFilter.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueFilter.java @@ -25,8 +25,6 @@ import com.google.common.base.Splitter; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; -import javax.annotation.CheckForNull; - import java.util.Date; import java.util.Iterator; import java.util.List; @@ -63,7 +61,7 @@ public class DefaultIssueFilter { } public DefaultIssueFilter(Map<String, Object> mapData) { - this.data = mapAsdata(mapData); + setData(mapData); } public Long id() { @@ -84,7 +82,6 @@ public class DefaultIssueFilter { return this; } - @CheckForNull public String user() { return user; } @@ -139,6 +136,11 @@ public class DefaultIssueFilter { return this; } + public final DefaultIssueFilter setData(Map<String, Object> mapData) { + this.data = mapAsdata(mapData); + return this; + } + /** * Used by ui */ diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDao.java index 2ac8a80265c..679b02e7915 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDao.java @@ -26,6 +26,7 @@ import org.sonar.api.ServerComponent; import org.sonar.core.persistence.MyBatis; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.util.List; @@ -51,6 +52,17 @@ public class IssueFilterDao implements BatchComponent, ServerComponent { } } + @CheckForNull + public IssueFilterDto selectByNameAndUser(String name, String user, @Nullable Long existingId) { + SqlSession session = mybatis.openSession(); + try { + session.getMapper(IssueFilterMapper.class); + return getMapper(session).selectByNameAndUser(name, user, existingId); + } finally { + MyBatis.closeQuietly(session); + } + } + public List<IssueFilterDto> selectByUser(String user) { SqlSession session = mybatis.openSession(); try { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterMapper.java index c4e8520febb..86f10e01c7b 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterMapper.java @@ -19,7 +19,10 @@ */ package org.sonar.core.issue.db; +import org.apache.ibatis.annotations.Param; + import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.util.List; @@ -31,6 +34,9 @@ public interface IssueFilterMapper { @CheckForNull IssueFilterDto selectById(Long id); + @CheckForNull + IssueFilterDto selectByNameAndUser(@Param("name") String name, @Param("userLogin") String userLogin, @Nullable @Param("existingId") Long existingId); + List<IssueFilterDto> selectByUser(String user); void insert(IssueFilterDto filter); diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml index 8a5ed2fc971..291f90db47f 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml @@ -23,6 +23,18 @@ </where> </select> + <select id="selectByNameAndUser" parameterType="map" resultType="IssueFilter"> + select <include refid="issueFilterColumns"/> + from issue_filters filters + <where> + and filters.name=#{name} + and filters.user_login=#{userLogin} + <if test="existingId != null"> + and filters.id<>#{existingId} + </if> + </where> + </select> + <select id="selectByUser" parameterType="String" resultType="IssueFilter"> select <include refid="issueFilterColumns"/> from issue_filters filters @@ -48,7 +60,6 @@ <update id="update" parameterType="IssueFilter"> update issue_filters set name=#{name}, - user_login=#{userLogin}, shared=#{shared}, description=#{description}, data=#{data}, diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueFilterDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueFilterDaoTest.java index de841318b98..4f6b9001a0d 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueFilterDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueFilterDaoTest.java @@ -51,6 +51,17 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase { } @Test + public void should_select_by_name_and_user() { + setupData("shared"); + + IssueFilterDto filter = dao.selectByNameAndUser("Sonar Issues", "stephane", null); + assertThat(filter.getId()).isEqualTo(1L); + + filter = dao.selectByNameAndUser("Sonar Issues", "stephane", 1L); + assertThat(filter).isNull(); + } + + @Test public void should_select_by_user() { setupData("should_select_by_user"); @@ -84,7 +95,6 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase { IssueFilterDto filterDto = new IssueFilterDto(); filterDto.setId(2L); filterDto.setName("Closed issues"); - filterDto.setUserLogin("henry"); filterDto.setShared(false); filterDto.setDescription("All closed issues"); filterDto.setData("statuses=CLOSED"); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_update-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_update-result.xml index a3e7af9bda8..daf43474984 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_update-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_update-result.xml @@ -13,7 +13,7 @@ <issue_filters id="2" name="Closed issues" - user_login="henry" + user_login="michael" shared="[false]" description="All closed issues" data="statuses=CLOSED" |