diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-28 17:54:26 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-28 18:00:14 +0200 |
commit | f61b4f4b92e27fbc98f590833245d22d875881e2 (patch) | |
tree | 473b26d46a288edb17d566a84563a6371691b131 /sonar-core/src/main | |
parent | 45bf17cf349fdbd120f8b4a915200dbe4c0a1909 (diff) | |
download | sonarqube-f61b4f4b92e27fbc98f590833245d22d875881e2.tar.gz sonarqube-f61b4f4b92e27fbc98f590833245d22d875881e2.zip |
SONAR-4449 Issue display should not fail on deleted action plan
Diffstat (limited to 'sonar-core/src/main')
4 files changed, 86 insertions, 17 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java index 7b93ecfb41f..1fa8b6d024c 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java @@ -73,20 +73,20 @@ public class IssueDao implements BatchComponent, ServerComponent { } @VisibleForTesting - List<IssueDto> selectIssues(IssueQuery query, @Nullable Integer userId, Integer maxResult) { + List<IssueDto> selectIssueIds(IssueQuery query, @Nullable Integer userId, Integer maxResult) { SqlSession session = mybatis.openSession(); try { - return selectIssues(query, userId, maxResult, session); + return selectIssueIds(query, userId, maxResult, session); } finally { MyBatis.closeQuietly(session); } } @VisibleForTesting - List<IssueDto> selectIssues(IssueQuery query) { + List<IssueDto> selectIssueIds(IssueQuery query) { SqlSession session = mybatis.openSession(); try { - return selectIssues(query, null, Integer.MAX_VALUE, session); + return selectIssueIds(query, null, Integer.MAX_VALUE, session); } finally { MyBatis.closeQuietly(session); } @@ -95,13 +95,31 @@ public class IssueDao implements BatchComponent, ServerComponent { /** * The returned IssueDto list contains only the issue id and the sort column */ + public List<IssueDto> selectIssueIds(IssueQuery query, @Nullable Integer userId, SqlSession session){ + return selectIssueIds(query, userId, query.maxResults(), session); + } + + private List<IssueDto> selectIssueIds(IssueQuery query, @Nullable Integer userId, Integer maxResults, SqlSession session){ + IssueMapper mapper = session.getMapper(IssueMapper.class); + return mapper.selectIssues(query, query.componentRoots(), userId, query.requiredRole(), maxResults, true); + } + + public List<IssueDto> selectIssues(IssueQuery query) { + SqlSession session = mybatis.openSession(); + try { + return selectIssues(query, null, Integer.MAX_VALUE, session); + } finally { + MyBatis.closeQuietly(session); + } + } + public List<IssueDto> selectIssues(IssueQuery query, @Nullable Integer userId, SqlSession session){ return selectIssues(query, userId, query.maxResults(), session); } - private List<IssueDto> selectIssues(IssueQuery query, @Nullable Integer userId, Integer maxResults, SqlSession session){ + public List<IssueDto> selectIssues(IssueQuery query, @Nullable Integer userId, Integer maxResults, SqlSession session){ IssueMapper mapper = session.getMapper(IssueMapper.class); - return mapper.selectIssues(query, query.componentRoots(), userId, query.requiredRole(), maxResults); + return mapper.selectIssues(query, query.componentRoots(), userId, query.requiredRole(), maxResults, false); } @VisibleForTesting diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java index 42c9b091340..d8ea5863a07 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java @@ -33,8 +33,13 @@ public interface IssueMapper { List<IssueDto> selectNonClosedIssuesByModule(int rootComponentId); + /** + * Return a paginated list of authorized issue ids for a user. + * If the role is null, then the authorisation check is disabled. + */ List<IssueDto> selectIssues(@Param("query") IssueQuery query, @Param("componentRootKeys") Collection<String> componentRootKeys, - @Nullable @Param("userId") Integer userId, @Param("role") String role, @Param("maxResults") Integer maxResult); + @Nullable @Param("userId") Integer userId, @Nullable @Param("role") String role, + @Param("maxResults") Integer maxResult, @Param("returnOnlyIdAndSortColumns") boolean returnOnlyIdAndSortColumns); void insert(IssueDto issue); diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 505f9ce267e..61ef848f10f 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -186,30 +186,75 @@ </select> <select id="selectIssues" parameterType="map" resultType="Issue" fetchSize="100000"> - select i.id - <include refid="sortColumn"/> + select + <choose> + <when test="returnOnlyIdAndSortColumns == true"> + i.id + <include refid="sortColumn"/> + from issues i + </when> + <otherwise> + <include refid="issueColumns"/> + from issues i + inner join rules r on r.id=i.rule_id + inner join projects p on p.id=i.component_id + inner join projects root on root.id=i.root_component_id + </otherwise> + </choose> <include refid="selectQueryConditions"/> - limit #{maxResults} + <if test="maxResults != null"> + limit #{maxResults} + </if> </select> <!-- SQL Server --> <select id="selectIssues" parameterType="map" resultType="Issue" fetchSize="100000" databaseId="mssql"> - select top (#{maxResults}) i.id - <include refid="sortColumn"/> + select + <if test="maxResults != null"> + top (#{maxResults}) + </if> + <choose> + <when test="returnOnlyIdAndSortColumns == true"> + i.id + <include refid="sortColumn"/> + from issues i + </when> + <otherwise> + <include refid="issueColumns"/> + from issues i + inner join rules r on r.id=i.rule_id + inner join projects p on p.id=i.component_id + inner join projects root on root.id=i.root_component_id + </otherwise> + </choose> <include refid="selectQueryConditions"/> </select> <!-- Oracle --> <select id="selectIssues" parameterType="map" resultType="Issue" fetchSize="100000" databaseId="oracle"> - select * from (select i.id - <include refid="sortColumn"/> + select * from (select + <choose> + <when test="returnOnlyIdAndSortColumns == true"> + i.id + <include refid="sortColumn"/> + </when> + <otherwise> + <include refid="issueColumns"/> + from issues i + inner join rules r on r.id=i.rule_id + inner join projects p on p.id=i.component_id + inner join projects root on root.id=i.root_component_id + </otherwise> + </choose> <include refid="selectQueryConditions"/> - ) where rownum <= #{maxResults} + ) + <if test="maxResults != null"> + where rownum <= #{maxResults} + </if> </select> <sql id="selectQueryConditions"> - from issues i - <if test="componentRootKeys.size() == 0"> + <if test="componentRootKeys.size() == 0 and role != null"> inner join (<include refid="org.sonar.core.user.AuthorizationMapper.selectAuthorizedRootProjectsIdsQuery" />) authorizedProjects on authorizedProjects.root_project_id=i.root_component_id </if> <if test="componentRootKeys.size() > 0"> diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueStatsMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueStatsMapper.xml index beab090bafd..accae5e1b88 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueStatsMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueStatsMapper.xml @@ -9,6 +9,7 @@ <if test="'ASSIGNEE'.equals(column)"> i.assignee </if> + from issues i <include refid="org.sonar.core.issue.db.IssueMapper.selectQueryConditions"/> </select> |