]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4383 Add IssueFilters db creation script and DAO
authorJulien Lancelot <julien.lancelot@gmail.com>
Tue, 11 Jun 2013 08:27:42 +0000 (10:27 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Tue, 11 Jun 2013 08:27:42 +0000 (10:27 +0200)
22 files changed:
sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDao.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/test/java/org/sonar/core/issue/db/IssueFilterDaoTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterDaoTest.java
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/shared.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_delete-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_insert-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_select_by_user.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_update-result.xml [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/410_create_issue_filters.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/411_create_issue_filter_favourites.rb [new file with mode: 0644]

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
new file mode 100644 (file)
index 0000000..37d9790
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * 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.db;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+import org.sonar.core.persistence.MyBatis;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+/**
+ * @since 3.6
+ */
+public class IssueFilterDao implements BatchComponent, ServerComponent {
+
+  private final MyBatis mybatis;
+
+  public IssueFilterDao(MyBatis mybatis) {
+    this.mybatis = mybatis;
+  }
+
+  @CheckForNull
+  public IssueFilterDto selectById(Integer id) {
+    SqlSession session = mybatis.openSession();
+    try {
+      session.getMapper(IssueFilterMapper.class);
+      return getMapper(session).selectById(id);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public List<IssueFilterDto> selectByUser(Integer userId) {
+    SqlSession session = mybatis.openSession();
+    try {
+      session.getMapper(IssueFilterMapper.class);
+      return getMapper(session).selectByUser(userId);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void insert(IssueFilterDto filter) {
+    SqlSession session = mybatis.openSession();
+    try {
+      getMapper(session).insert(filter);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void update(IssueFilterDto filter) {
+    SqlSession session = mybatis.openSession();
+    try {
+      getMapper(session).update(filter);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void delete(Integer id) {
+    SqlSession session = mybatis.openSession();
+    try {
+      getMapper(session).delete(id);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  private IssueFilterMapper getMapper(SqlSession session) {
+    return session.getMapper(IssueFilterMapper.class);
+  }
+}
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
new file mode 100644 (file)
index 0000000..1e4c59c
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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.db;
+
+import javax.annotation.Nullable;
+
+import java.util.Date;
+
+/**
+ * @since 3.6
+ */
+public class IssueFilterDto {
+
+  private Long id;
+  private String name;
+  private Long userId;
+  private Boolean shared;
+  private String description;
+  private String data;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public IssueFilterDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public IssueFilterDto setName(String name) {
+    this.name = name;
+    return this;
+  }
+
+  public Long getUserId() {
+    return userId;
+  }
+
+  public IssueFilterDto setUserId(@Nullable Long userId) {
+    this.userId = userId;
+    return this;
+  }
+
+  public Boolean isShared() {
+    return shared;
+  }
+
+  public IssueFilterDto setShared(@Nullable Boolean shared) {
+    this.shared = shared;
+    return this;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public IssueFilterDto setDescription(@Nullable String description) {
+    this.description = description;
+    return this;
+  }
+
+  public String getData() {
+    return data;
+  }
+
+  public IssueFilterDto setData(String data) {
+    this.data = data;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public IssueFilterDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public IssueFilterDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
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
new file mode 100644 (file)
index 0000000..9bf819d
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.db;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+/**
+ * @since 3.6
+ */
+public interface IssueFilterMapper {
+
+  @CheckForNull
+  IssueFilterDto selectById(Integer id);
+
+  List<IssueFilterDto> selectByUser(Integer userId);
+
+  void insert(IssueFilterDto filter);
+
+  void update(IssueFilterDto filter);
+
+  void delete(Integer id);
+}
index 33fa7b7708aea8c7bd7a63899dee5a5de933cb60..db936c44976219597c52565cc4b8c554285bd2f4 100644 (file)
@@ -59,6 +59,7 @@ public final class DaoUtils {
       IssueDao.class,
       IssueStatsDao.class,
       IssueChangeDao.class,
+      IssueFilterDao.class,
       LoadedTemplateDao.class,
       MeasureFilterDao.class,
       PropertiesDao.class,
index 4d684fc9e74bf1987941e75c9f8a41f69854293c..d981d4275361b6e9dbf7561d377af5bf80d8f63f 100644 (file)
@@ -62,6 +62,8 @@ public final class DatabaseUtils {
     "group_roles",
     "issues",
     "issue_changes",
+    "issue_filters",
+    "issue_filter_favourites",
     "loaded_templates",
     "manual_measures",
     "measure_data",
index e70f13887bd1dc131f242ebf2319ab82cc0b6941..f060ae68e5985d4b1986d5dfc35b1c7d211812e6 100644 (file)
@@ -32,7 +32,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 403;
+  public static final int LAST_VERSION = 411;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 41d9eb9200a83bcca27e019d792a5e4ee4178cbf..90b83920742cfb667cd07b726a5d778d08698466 100644 (file)
@@ -115,22 +115,24 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadAlias(conf, "MeasureData", MeasureData.class);
     loadAlias(conf, "Issue", IssueDto.class);
     loadAlias(conf, "IssueChange", IssueChangeDto.class);
+    loadAlias(conf, "IssueFilter", IssueFilterDto.class);
     loadAlias(conf, "SnapshotData", SnapshotDataDto.class);
     loadAlias(conf, "ActionPlanIssue", ActionPlanDto.class);
     loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class);
 
+    // AuthorizationMapper has to be loaded before IssueMapper because this last one used it
+    loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
+    // ResourceMapper has to be loaded before IssueMapper because this last one used it
+    loadMapper(conf, ResourceMapper.class);
+
     Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
       DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class,
-      IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class,
+      IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, IssueFilterMapper.class,
       LoadedTemplateMapper.class, MeasureFilterMapper.class, PropertiesMapper.class, PurgeMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class,
       ResourceSnapshotMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class,
       SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, MeasureMapper.class, SnapshotDataMapper.class,
       SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class
     };
-    // AuthorizationMapper has to be loaded before IssueMapper because this last one used it
-    loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
-    // ResourceMapper has to be loaded before IssueMapper because this last one used it
-    loadMapper(conf, ResourceMapper.class);
     loadMappers(conf, mappers);
     configureLogback(mappers);
 
index 83cd957bd93330a64997e546d2e30dd9b53836e7..0d1c57ee13621a7e2e059439fc2c1292047fe88a 100644 (file)
@@ -1,25 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
-<!--
-  ~ 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.
-  -->
-
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd">
 
 <mapper namespace="org.sonar.core.issue.db.IssueChangeMapper">
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
new file mode 100644 (file)
index 0000000..d14bec6
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.issue.db.IssueFilterMapper">
+
+  <sql id="issueFilterColumns">
+    if.id,
+    if.name as name,
+    if.user_id as userId,
+    if.shared as shared,
+    if.description as description,
+    if.data as data,
+    if.created_at as createdAt,
+    if.updated_at as updatedAt
+  </sql>
+
+  <select id="selectById" parameterType="int" resultType="IssueFilter">
+    select <include refid="issueFilterColumns"/>
+    from issue_filters if WHERE id=#{id}
+  </select>
+
+  <select id="selectByUser" parameterType="int" resultType="IssueFilter">
+    select <include refid="issueFilterColumns"/>
+    from issue_filters if WHERE user_id=#{userId}
+  </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>
+
+  <!-- Oracle -->
+  <insert id="insert" databaseId="oracle" parameterType="IssueFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+    <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>
+
+  <update id="update" parameterType="IssueFilter">
+    update issue_filters set
+    name=#{name},
+    user_id=#{userId},
+    shared=#{shared},
+    description=#{description},
+    data=#{data},
+    updated_at=current_timestamp
+    where id=#{id}
+  </update>
+
+  <delete id="delete" parameterType="int">
+    delete from issue_filters where id=#{id}
+  </delete>
+
+</mapper>
index 9f3acacff4775ae0ddec72da5c7286d6daabbbcb..aaef7a8f8323eda9507720f576573ce360341828 100644 (file)
@@ -166,6 +166,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('400');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('401');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('402');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('403');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('410');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('411');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 19ce838fa10ef85d5ecfdfc6179e2d0d7ceea5b2..2e65ee3b2d55be54de1ec72b4bade019a91871a0 100644 (file)
@@ -504,6 +504,24 @@ CREATE TABLE "ISSUE_CHANGES" (
   "UPDATED_AT" TIMESTAMP,
 );
 
+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,
+  "DESCRIPTION" VARCHAR(4000),
+  "DATA" CLOB(2147483647),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);
+
+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,
+  "ISSUE_FILTER_ID" INTEGER NOT NULL,
+  "CREATED_AT" TIMESTAMP
+);
+
 CREATE TABLE "SNAPSHOT_DATA" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "SNAPSHOT_ID" INTEGER,
@@ -638,4 +656,8 @@ CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES" ("KEE");
 
 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 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
new file mode 100644 (file)
index 0000000..8cc8ec0
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * 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.db;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueFilterDaoTest extends AbstractDaoTestCase {
+
+  IssueFilterDao dao;
+
+  @Before
+  public void createDao() {
+    dao = new IssueFilterDao(getMyBatis());
+  }
+
+  @Test
+  public void should_select_by_id() {
+    setupData("shared");
+
+    IssueFilterDto filter = dao.selectById(1);
+
+    assertThat(filter.getId()).isEqualTo(1L);
+    assertThat(filter.getName()).isEqualTo("Sonar Issues");
+    assertThat(filter.isShared()).isTrue();
+
+    assertThat(dao.selectById(123)).isNull();
+  }
+
+  @Test
+  public void should_select_by_user() {
+    setupData("should_select_by_user");
+
+    List<IssueFilterDto> results = dao.selectByUser(2);
+
+    assertThat(results).hasSize(2);
+  }
+
+  @Test
+  public void should_insert() {
+    setupData("shared");
+
+    IssueFilterDto filterDto = new IssueFilterDto();
+    filterDto.setName("Sonar Open issues");
+    filterDto.setUserId(2L);
+    filterDto.setShared(true);
+    filterDto.setDescription("All open issues on Sonar");
+    filterDto.setData("statuses=OPEN|componentRoots=org.codehaus.sonar");
+
+    dao.insert(filterDto);
+
+    checkTables("should_insert", new String[]{"created_at", "updated_at"}, "issue_filters");
+  }
+
+  @Test
+  public void should_update() {
+    setupData("shared");
+
+    IssueFilterDto filterDto = new IssueFilterDto();
+    filterDto.setId(2L);
+    filterDto.setName("Closed issues");
+    filterDto.setUserId(3L);
+    filterDto.setShared(false);
+    filterDto.setDescription("All closed issues");
+    filterDto.setData("statuses=CLOSED");
+
+    dao.update(filterDto);
+
+    checkTables("should_update", new String[]{"created_at", "updated_at"}, "issue_filters");
+  }
+
+  @Test
+  public void should_delete() {
+    setupData("shared");
+
+    dao.delete(1);
+
+    checkTables("should_delete", new String[]{"created_at", "updated_at"}, "issue_filters");
+  }
+}
index a62a8c5420ef6abc9723a7b69a5de1f4f774085c..04e3ffd3098c76073d8da65b3294e90e61c2a4c6 100644 (file)
@@ -43,7 +43,6 @@ public class MeasureFilterDaoTest extends AbstractDaoTestCase {
     assertThat(filter.getName()).isEqualTo("Projects");
   }
 
-
   @Test
   public void should_not_find_filter() {
     setupData("shared");
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
new file mode 100644 (file)
index 0000000..3dd5ac0
--- /dev/null
@@ -0,0 +1,23 @@
+<dataset>
+
+  <issue_filters
+      id="1"
+      name="Sonar Issues"
+      user_id="1"
+      shared="[true]"
+      description="All issues of Sonar"
+      data="componentRoots=org.codehaus.sonar"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+  <issue_filters
+      id="2"
+      name="Open issues"
+      user_id="2"
+      shared="[false]"
+      description="All open issues"
+      data="statuses=OPEN"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..b218f04
--- /dev/null
@@ -0,0 +1,13 @@
+<dataset>
+
+  <issue_filters
+      id="2"
+      name="Open issues"
+      user_id="2"
+      shared="[false]"
+      description="All open issues"
+      data="statuses=OPEN"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..dc7196e
--- /dev/null
@@ -0,0 +1,34 @@
+<dataset>
+
+  <issue_filters
+      id="1"
+      name="Sonar Issues"
+      user_id="1"
+      shared="[true]"
+      description="All issues of Sonar"
+      data="componentRoots=org.codehaus.sonar"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+  <issue_filters
+      id="2"
+      name="Open issues"
+      user_id="2"
+      shared="[false]"
+      description="All open issues"
+      data="statuses=OPEN"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+
+  <issue_filters
+      id="3"
+      name="Sonar Open issues"
+      user_id="2"
+      shared="[true]"
+      description="All open issues on Sonar"
+      data="statuses=OPEN|componentRoots=org.codehaus.sonar"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..fda801c
--- /dev/null
@@ -0,0 +1,33 @@
+<dataset>
+
+  <issue_filters
+      id="1"
+      name="Sonar Issues"
+      user_id="1"
+      shared="[true]"
+      description="All issues of Sonar"
+      data="componentRoots=org.codehaus.sonar"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+  <issue_filters
+      id="2"
+      name="Open issues"
+      user_id="2"
+      shared="[false]"
+      description="All open issues"
+      data="statuses=OPEN"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+  <issue_filters
+      id="3"
+      name="Sonar Open issues"
+      user_id="2"
+      shared="[true]"
+      description="All open issues on Sonar"
+      data="statuses=OPEN|componentRoots=org.codehaus.sonar"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+</dataset>
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
new file mode 100644 (file)
index 0000000..4b35add
--- /dev/null
@@ -0,0 +1,23 @@
+<dataset>
+
+  <issue_filters
+      id="1"
+      name="Sonar Issues"
+      user_id="1"
+      shared="[true]"
+      description="All issues of Sonar"
+      data="componentRoots=org.codehaus.sonar"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
+  <issue_filters
+      id="2"
+      name="Closed issues"
+      user_id="3"
+      shared="[false]"
+      description="All closed issues"
+      data="statuses=CLOSED"
+      created_at="2013-06-10"
+      updated_at="2013-06-11" />
+
+</dataset>
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java
new file mode 100644 (file)
index 0000000..d4364d2
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.server.issue;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.core.issue.db.IssueFilterDao;
+
+public class IssueFilterService implements ServerComponent {
+
+  private IssueFilterDao issueFilterDao;
+
+  public IssueFilterService(IssueFilterDao issueFilterDao) {
+    this.issueFilterDao = issueFilterDao;
+  }
+}
index 8a52b6f8124e1b1082070071f5bac2350d8557c7..1878f6de95c43cf6b0705a6024cc987bb03b2ab8 100644 (file)
@@ -273,6 +273,7 @@ public final class Platform {
     servicesContainer.addSingleton(IssueNotifications.class);
     servicesContainer.addSingleton(ActionService.class);
     servicesContainer.addSingleton(Actions.class);
+    servicesContainer.addSingleton(IssueFilterService.class);
 
     // rules
     servicesContainer.addSingleton(RubyRuleService.class);
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/410_create_issue_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/410_create_issue_filters.rb
new file mode 100644 (file)
index 0000000..ff63ed7
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# Sonar, entreprise quality control 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.
+#
+#
+# Sonar 3.6
+# See SONAR-4383
+#
+class CreateIssueFilters < ActiveRecord::Migration
+
+  def self.up
+    create_table 'issue_filters' do |t|
+      t.column 'name', :string, :null => false, :limit => 100
+      t.column 'user_id', :integer, :null => true
+      t.column 'shared', :boolean, :default => false, :null => false
+      t.column 'description', :string, :null => true, :limit => 4000
+      t.column 'data', :text, :null => true
+      t.timestamps
+    end
+    add_index 'issue_filters', 'name', :name => 'issue_filters_name'
+  end
+
+end
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/411_create_issue_filter_favourites.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/411_create_issue_filter_favourites.rb
new file mode 100644 (file)
index 0000000..322c19a
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# Sonar, entreprise quality control 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.
+#
+
+#
+# Sonar 3.6
+# See SONAR-4383
+#
+class CreateIssueFilterFavourites < ActiveRecord::Migration
+
+  def self.up
+    create_table 'issue_filter_favourites' do |t|
+      t.column 'user_id', :integer, :null => false
+      t.column 'issue_filter_id', :integer, :null => false
+      t.column 'created_at', :datetime
+    end
+    add_index 'issue_filter_favourites', 'user_id', :name => 'issue_filter_favs_userid'
+  end
+
+end
+