diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-11 16:44:54 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-11 16:45:11 +0200 |
commit | 722a02188710fe1b15229e70dc7541a3caa033c5 (patch) | |
tree | 2efaf2dd1d22b4f9eecff93b93ced370a711152a /sonar-core/src | |
parent | eb6c7dca9332b5512a7877bd3d76e2a728687d45 (diff) | |
download | sonarqube-722a02188710fe1b15229e70dc7541a3caa033c5.tar.gz sonarqube-722a02188710fe1b15229e70dc7541a3caa033c5.zip |
SONAR-4383 Replace userId by user in FilterDto
Diffstat (limited to 'sonar-core/src')
12 files changed, 185 insertions, 40 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 new file mode 100644 index 00000000000..639dafbb62d --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueFilter.java @@ -0,0 +1,119 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.issue; + +import javax.annotation.CheckForNull; + +import java.util.Date; + +public class DefaultIssueFilter { + + public static String SEPARATOR = "|"; + public static String KEY_VALUE_SEPARATOR = "="; + public static String LIST_SEPARATOR = ","; + + private Long id; + private String name; + private String user; + private Boolean shared; + private String description; + private String data; + private Date createdAt; + private Date updatedAt; + + public DefaultIssueFilter() { + + } + + public Long id() { + return id; + } + + public DefaultIssueFilter setId(Long id) { + this.id = id; + return this; + } + + public String name() { + return name; + } + + public DefaultIssueFilter setName(String name) { + this.name = name; + return this; + } + + @CheckForNull + public String user() { + return user; + } + + public DefaultIssueFilter setUser(String user) { + this.user = user; + return this; + } + + public Boolean shared() { + return shared; + } + + public DefaultIssueFilter setShared(Boolean shared) { + this.shared = shared; + return this; + } + + public String description() { + return description; + } + + public DefaultIssueFilter setDescription(String description) { + this.description = description; + return this; + } + + public String data() { + return data; + } + + public DefaultIssueFilter setData(String data) { + this.data = data; + return this; + } + + public Date createdAt() { + return createdAt; + } + + public DefaultIssueFilter setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + + public Date updatedAt() { + return updatedAt; + } + + public DefaultIssueFilter setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + return this; + } + +} 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 37d9790a9e8..2ac8a80265c 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 @@ -41,7 +41,7 @@ public class IssueFilterDao implements BatchComponent, ServerComponent { } @CheckForNull - public IssueFilterDto selectById(Integer id) { + public IssueFilterDto selectById(Long id) { SqlSession session = mybatis.openSession(); try { session.getMapper(IssueFilterMapper.class); @@ -51,11 +51,11 @@ public class IssueFilterDao implements BatchComponent, ServerComponent { } } - public List<IssueFilterDto> selectByUser(Integer userId) { + public List<IssueFilterDto> selectByUser(String user) { SqlSession session = mybatis.openSession(); try { session.getMapper(IssueFilterMapper.class); - return getMapper(session).selectByUser(userId); + return getMapper(session).selectByUser(user); } finally { MyBatis.closeQuietly(session); } @@ -81,7 +81,7 @@ public class IssueFilterDao implements BatchComponent, ServerComponent { } } - public void delete(Integer id) { + public void delete(Long id) { SqlSession session = mybatis.openSession(); try { getMapper(session).delete(id); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDto.java index 1e4c59c4857..29093953dc9 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDto.java @@ -19,6 +19,8 @@ */ package org.sonar.core.issue.db; +import org.sonar.core.issue.DefaultIssueFilter; + import javax.annotation.Nullable; import java.util.Date; @@ -30,7 +32,7 @@ public class IssueFilterDto { private Long id; private String name; - private Long userId; + private String user; private Boolean shared; private String description; private String data; @@ -55,12 +57,12 @@ public class IssueFilterDto { return this; } - public Long getUserId() { - return userId; + public String getUser() { + return user; } - public IssueFilterDto setUserId(@Nullable Long userId) { - this.userId = userId; + public IssueFilterDto setUser(@Nullable String user) { + this.user = user; return this; } @@ -108,4 +110,28 @@ public class IssueFilterDto { this.updatedAt = updatedAt; return this; } + + public DefaultIssueFilter toIssueFilter() { + return new DefaultIssueFilter() + .setId(id) + .setName(name) + .setUser(user) + .setDescription(description) + .setShared(shared) + .setData(data) + .setCreatedAt(createdAt) + .setUpdatedAt(updatedAt); + } + + public static IssueFilterDto toIssueFilter(DefaultIssueFilter issueFilter) { + return new IssueFilterDto() + .setId(issueFilter.id()) + .setName(issueFilter.name()) + .setUser(issueFilter.user()) + .setDescription(issueFilter.description()) + .setShared(issueFilter.shared()) + .setData(issueFilter.data()) + .setCreatedAt(issueFilter.createdAt()) + .setUpdatedAt(issueFilter.updatedAt()); + } } 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 9bf819d11cd..c4e8520febb 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 @@ -29,13 +29,13 @@ import java.util.List; public interface IssueFilterMapper { @CheckForNull - IssueFilterDto selectById(Integer id); + IssueFilterDto selectById(Long id); - List<IssueFilterDto> selectByUser(Integer userId); + List<IssueFilterDto> selectByUser(String user); void insert(IssueFilterDto filter); void update(IssueFilterDto filter); - void delete(Integer id); + void delete(Long id); } 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 d14bec6f23c..c1a1090343a 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 @@ -7,7 +7,7 @@ <sql id="issueFilterColumns"> if.id, if.name as name, - if.user_id as userId, + if.user as user, if.shared as shared, if.description as description, if.data as data, @@ -20,14 +20,14 @@ from issue_filters if WHERE id=#{id} </select> - <select id="selectByUser" parameterType="int" resultType="IssueFilter"> + <select id="selectByUser" parameterType="String" resultType="IssueFilter"> select <include refid="issueFilterColumns"/> - from issue_filters if WHERE user_id=#{userId} + from issue_filters if WHERE user=#{user} </select> <insert id="insert" parameterType="IssueFilter" useGeneratedKeys="true" keyProperty="id"> - INSERT INTO issue_filters (name, user_id, shared, description, data, created_at, updated_at) - VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) + INSERT INTO issue_filters (name, user, shared, description, data, created_at, updated_at) + VALUES (#{name}, #{user}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) </insert> <!-- Oracle --> @@ -35,14 +35,14 @@ <selectKey order="BEFORE" resultType="Long" keyProperty="id"> select issue_filters_seq.NEXTVAL from DUAL </selectKey> - INSERT INTO issue_filters (id, name, user_id, shared, description, data, created_at, updated_at) - VALUES (#{id}, #{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) + INSERT INTO issue_filters (id, name, user, shared, description, data, created_at, updated_at) + VALUES (#{id}, #{name}, #{user}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) </insert> <update id="update" parameterType="IssueFilter"> update issue_filters set name=#{name}, - user_id=#{userId}, + user=#{user}, shared=#{shared}, description=#{description}, data=#{data}, diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 2e65ee3b2d5..2a7f1523100 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -508,7 +508,7 @@ CREATE TABLE "ISSUE_FILTERS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(100) NOT NULL, "SHARED" BOOLEAN NOT NULL DEFAULT FALSE, - "USER_ID" INTEGER, + "USER" VARCHAR(40), "DESCRIPTION" VARCHAR(4000), "DATA" CLOB(2147483647), "CREATED_AT" TIMESTAMP, @@ -517,7 +517,7 @@ CREATE TABLE "ISSUE_FILTERS" ( CREATE TABLE "ISSUE_FILTER_FAVOURITES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "USER_ID" INTEGER NOT NULL, + "USER" VARCHAR(40) NOT NULL, "ISSUE_FILTER_ID" INTEGER NOT NULL, "CREATED_AT" TIMESTAMP ); @@ -658,6 +658,6 @@ CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES" ("ISSUE_KEY"); CREATE INDEX "ISSUE_FILTERS_NAME" ON "ISSUE_FILTERS" ("NAME"); -CREATE INDEX "ISSUE_FILTER_FAVS_USERID" ON "ISSUE_FILTER_FAVOURITES" ("USER_ID"); +CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER"); CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN"); 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 8cc8ec08558..5d5f905716a 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 @@ -41,20 +41,20 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase { public void should_select_by_id() { setupData("shared"); - IssueFilterDto filter = dao.selectById(1); + IssueFilterDto filter = dao.selectById(1L); assertThat(filter.getId()).isEqualTo(1L); assertThat(filter.getName()).isEqualTo("Sonar Issues"); assertThat(filter.isShared()).isTrue(); - assertThat(dao.selectById(123)).isNull(); + assertThat(dao.selectById(123L)).isNull(); } @Test public void should_select_by_user() { setupData("should_select_by_user"); - List<IssueFilterDto> results = dao.selectByUser(2); + List<IssueFilterDto> results = dao.selectByUser("michael"); assertThat(results).hasSize(2); } @@ -65,7 +65,7 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase { IssueFilterDto filterDto = new IssueFilterDto(); filterDto.setName("Sonar Open issues"); - filterDto.setUserId(2L); + filterDto.setUser("michael"); filterDto.setShared(true); filterDto.setDescription("All open issues on Sonar"); filterDto.setData("statuses=OPEN|componentRoots=org.codehaus.sonar"); @@ -82,7 +82,7 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase { IssueFilterDto filterDto = new IssueFilterDto(); filterDto.setId(2L); filterDto.setName("Closed issues"); - filterDto.setUserId(3L); + filterDto.setUser("henry"); filterDto.setShared(false); filterDto.setDescription("All closed issues"); filterDto.setData("statuses=CLOSED"); @@ -96,7 +96,7 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase { public void should_delete() { setupData("shared"); - dao.delete(1); + dao.delete(1l); checkTables("should_delete", new String[]{"created_at", "updated_at"}, "issue_filters"); } diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/shared.xml index 3dd5ac09a05..9cc2014c435 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/shared.xml @@ -3,7 +3,7 @@ <issue_filters id="1" name="Sonar Issues" - user_id="1" + user="stephane" shared="[true]" description="All issues of Sonar" data="componentRoots=org.codehaus.sonar" @@ -13,7 +13,7 @@ <issue_filters id="2" name="Open issues" - user_id="2" + user="michael" shared="[false]" description="All open issues" data="statuses=OPEN" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_delete-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_delete-result.xml index b218f0457b2..d751cf7d2b7 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_delete-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_delete-result.xml @@ -3,7 +3,7 @@ <issue_filters id="2" name="Open issues" - user_id="2" + user="michael" shared="[false]" description="All open issues" data="statuses=OPEN" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_insert-result.xml index dc7196eafa8..ad5a2a52fa0 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_insert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_insert-result.xml @@ -3,7 +3,7 @@ <issue_filters id="1" name="Sonar Issues" - user_id="1" + user="stephane" shared="[true]" description="All issues of Sonar" data="componentRoots=org.codehaus.sonar" @@ -13,7 +13,7 @@ <issue_filters id="2" name="Open issues" - user_id="2" + user="michael" shared="[false]" description="All open issues" data="statuses=OPEN" @@ -24,7 +24,7 @@ <issue_filters id="3" name="Sonar Open issues" - user_id="2" + user="michael" shared="[true]" description="All open issues on Sonar" data="statuses=OPEN|componentRoots=org.codehaus.sonar" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_select_by_user.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_select_by_user.xml index fda801cd549..e79b57c103b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_select_by_user.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_select_by_user.xml @@ -3,7 +3,7 @@ <issue_filters id="1" name="Sonar Issues" - user_id="1" + user="stephane" shared="[true]" description="All issues of Sonar" data="componentRoots=org.codehaus.sonar" @@ -13,7 +13,7 @@ <issue_filters id="2" name="Open issues" - user_id="2" + user="michael" shared="[false]" description="All open issues" data="statuses=OPEN" @@ -23,7 +23,7 @@ <issue_filters id="3" name="Sonar Open issues" - user_id="2" + user="michael" shared="[true]" description="All open issues on Sonar" data="statuses=OPEN|componentRoots=org.codehaus.sonar" 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 4b35add7346..9a233882bc7 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 @@ -3,7 +3,7 @@ <issue_filters id="1" name="Sonar Issues" - user_id="1" + user="stephane" shared="[true]" description="All issues of Sonar" data="componentRoots=org.codehaus.sonar" @@ -13,7 +13,7 @@ <issue_filters id="2" name="Closed issues" - user_id="3" + user="henry" shared="[false]" description="All closed issues" data="statuses=CLOSED" |