diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-18 16:22:09 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-18 16:22:21 +0200 |
commit | fa2fcc0312a3c22a03e1c28bdd42ab4e45249c45 (patch) | |
tree | 6f84fca2da2a698cab5aee4f0a4b61e33ab98175 /sonar-core/src/main | |
parent | 85143f236cb74df69d55214b3d62a8c7f2398c7f (diff) | |
download | sonarqube-fa2fcc0312a3c22a03e1c28bdd42ab4e45249c45.tar.gz sonarqube-fa2fcc0312a3c22a03e1c28bdd42ab4e45249c45.zip |
SONAR-4393 Manage favourite issue filters
Diffstat (limited to 'sonar-core/src/main')
10 files changed, 266 insertions, 7 deletions
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 679b02e7915..d74fafd02ae 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 @@ -31,7 +31,7 @@ import javax.annotation.Nullable; import java.util.List; /** - * @since 3.6 + * @since 3.7 */ public class IssueFilterDao implements BatchComponent, ServerComponent { @@ -56,7 +56,6 @@ public class IssueFilterDao implements BatchComponent, ServerComponent { 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); @@ -66,13 +65,21 @@ public class IssueFilterDao implements BatchComponent, ServerComponent { public List<IssueFilterDto> selectByUser(String user) { SqlSession session = mybatis.openSession(); try { - session.getMapper(IssueFilterMapper.class); return getMapper(session).selectByUser(user); } finally { MyBatis.closeQuietly(session); } } + public List<IssueFilterDto> selectByUserWithOnlyFavoriteFilters(String user) { + SqlSession session = mybatis.openSession(); + try { + return getMapper(session).selectByUserWithOnlyFavoriteFilters(user); + } finally { + MyBatis.closeQuietly(session); + } + } + public void insert(IssueFilterDto filter) { SqlSession session = mybatis.openSession(); try { 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 9fe5c1e6291..ac366e66a1f 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 @@ -26,7 +26,7 @@ import javax.annotation.Nullable; import java.util.Date; /** - * @since 3.6 + * @since 3.7 */ public class IssueFilterDto { @@ -61,7 +61,7 @@ public class IssueFilterDto { return userLogin; } - public IssueFilterDto setUserLogin(@Nullable String userLogin) { + public IssueFilterDto setUserLogin(String userLogin) { this.userLogin = userLogin; return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteDao.java new file mode 100644 index 00000000000..2f692c1b967 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteDao.java @@ -0,0 +1,80 @@ +/* + * 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; + +/** + * @since 3.7 + */ +public class IssueFilterFavouriteDao implements BatchComponent, ServerComponent { + + private final MyBatis mybatis; + + public IssueFilterFavouriteDao(MyBatis mybatis) { + this.mybatis = mybatis; + } + + public IssueFilterFavouriteDto selectById(Long id) { + SqlSession session = mybatis.openSession(); + try { + return getMapper(session).selectById(id); + } finally { + MyBatis.closeQuietly(session); + } + } + + public IssueFilterFavouriteDto selectByUserAndIssueFilterId(String user, Long issueFilterId) { + SqlSession session = mybatis.openSession(); + try { + return getMapper(session).selectByIssueFilterId(user, issueFilterId); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void insert(IssueFilterFavouriteDto filter) { + SqlSession session = mybatis.openSession(); + try { + getMapper(session).insert(filter); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void delete(Long id) { + SqlSession session = mybatis.openSession(); + try { + getMapper(session).delete(id); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + private IssueFilterFavouriteMapper getMapper(SqlSession session) { + return session.getMapper(IssueFilterFavouriteMapper.class); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteDto.java new file mode 100644 index 00000000000..b59dcbf4e4b --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteDto.java @@ -0,0 +1,70 @@ +/* + * 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 java.util.Date; + +/** + * @since 3.7 + */ +public class IssueFilterFavouriteDto { + + private Long id; + private String userLogin; + private Long issueFilterId; + private Date createdAt; + + public Long getId() { + return id; + } + + public IssueFilterFavouriteDto setId(Long id) { + this.id = id; + return this; + } + + public String getUserLogin() { + return userLogin; + } + + public IssueFilterFavouriteDto setUserLogin(String userLogin) { + this.userLogin = userLogin; + return this; + } + + public Long getIssueFilterId() { + return issueFilterId; + } + + public IssueFilterFavouriteDto setIssueFilterId(Long issueFilterId) { + this.issueFilterId = issueFilterId; + return this; + } + + public Date getCreatedAt() { + return createdAt; + } + + public IssueFilterFavouriteDto setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteMapper.java new file mode 100644 index 00000000000..03986f82118 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterFavouriteMapper.java @@ -0,0 +1,40 @@ +/* + * 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.annotations.Param; + +import javax.annotation.CheckForNull; + +/** + * @since 3.7 + */ +public interface IssueFilterFavouriteMapper { + + @CheckForNull + IssueFilterFavouriteDto selectById(Long id); + + @CheckForNull + IssueFilterFavouriteDto selectByIssueFilterId(@Param("userLogin") String userLogin, @Param("issueFilterId") Long issueFilterId); + + void insert(IssueFilterFavouriteDto filterFavourite); + + void delete(Long id); +} 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 86f10e01c7b..f07316f07a1 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 @@ -27,7 +27,7 @@ import javax.annotation.Nullable; import java.util.List; /** - * @since 3.6 + * @since 3.7 */ public interface IssueFilterMapper { @@ -39,6 +39,8 @@ public interface IssueFilterMapper { List<IssueFilterDto> selectByUser(String user); + List<IssueFilterDto> selectByUserWithOnlyFavoriteFilters(String user); + void insert(IssueFilterDto filter); void update(IssueFilterDto filter); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java index db936c44976..6cbb0c6e736 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java @@ -60,6 +60,7 @@ public final class DaoUtils { IssueStatsDao.class, IssueChangeDao.class, IssueFilterDao.class, + IssueFilterFavouriteDao.class, LoadedTemplateDao.class, MeasureFilterDao.class, PropertiesDao.class, diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 90b83920742..59959a44502 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -116,6 +116,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "Issue", IssueDto.class); loadAlias(conf, "IssueChange", IssueChangeDto.class); loadAlias(conf, "IssueFilter", IssueFilterDto.class); + loadAlias(conf, "IssueFilterFavourite", IssueFilterFavouriteDto.class); loadAlias(conf, "SnapshotData", SnapshotDataDto.class); loadAlias(conf, "ActionPlanIssue", ActionPlanDto.class); loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class); @@ -127,7 +128,7 @@ public class MyBatis implements BatchComponent, ServerComponent { Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class, DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class, - IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, + IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.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, diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml new file mode 100644 index 00000000000..3c8d2db4718 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml @@ -0,0 +1,49 @@ +<?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.IssueFilterFavouriteMapper"> + + <sql id="issueFilterFavouriteColumns"> + filter_favourites.id as id, + filter_favourites.user_login as userLogin, + filter_favourites.issue_filter_id as issueFilterId, + filter_favourites.created_at as createdAt + </sql> + + <select id="selectById" parameterType="long" resultType="issueFilterFavourite"> + select <include refid="issueFilterFavouriteColumns"/> + from issue_filter_favourites filter_favourites + <where> + filter_favourites.id=#{id} + </where> + </select> + + <select id="selectByIssueFilterId" parameterType="long" resultType="issueFilterFavourite"> + select <include refid="issueFilterFavouriteColumns"/> + from issue_filter_favourites filter_favourites + <where> + filter_favourites.issue_filter_id=#{issueFilterId} + and filter_favourites.user_login=#{userLogin} + </where> + </select> + + <insert id="insert" parameterType="issueFilterFavourite" useGeneratedKeys="true" keyProperty="id"> + INSERT INTO issue_filter_favourites (user_login, issue_filter_id, created_at) + VALUES (#{userLogin}, #{issueFilterId}, current_timestamp) + </insert> + + <!-- Oracle --> + <insert id="insert" databaseId="oracle" parameterType="issueFilterFavourite" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + <selectKey order="BEFORE" resultType="Long" keyProperty="id"> + select issue_filter_favourites_seq.NEXTVAL from DUAL + </selectKey> + INSERT INTO issue_filter_favourites (id, user_login, issue_filter_id, created_at) + VALUES (#{id},#{userLogin}, #{issueFilterId}, current_timestamp) + </insert> + + <delete id="delete" parameterType="int"> + delete from issue_filter_favourites where id=#{id} + </delete> + +</mapper> 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 291f90db47f..2d62e89af3d 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 @@ -43,6 +43,15 @@ </where> </select> + <select id="selectByUserWithOnlyFavoriteFilters" parameterType="String" resultType="IssueFilter"> + select <include refid="issueFilterColumns"/> + from issue_filters filters + inner join issue_filter_favourites fav on fav.issue_filter_id = filters.id + <where> + fav.user_login=#{user} + </where> + </select> + <insert id="insert" parameterType="IssueFilter" useGeneratedKeys="true" keyProperty="id"> INSERT INTO issue_filters (name, user_login, shared, description, data, created_at, updated_at) VALUES (#{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) |