diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-01-30 17:05:49 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-02 16:21:28 +0100 |
commit | 639d4f6e33a4d6f645f9a091945bb4c743476d12 (patch) | |
tree | 8f1d8295b63e0f110543c5a750df1aa3073313a1 /sonar-core | |
parent | 22e6bbd3f1b318ef74c5c21ab43e7fa445418493 (diff) | |
download | sonarqube-639d4f6e33a4d6f645f9a091945bb4c743476d12.tar.gz sonarqube-639d4f6e33a4d6f645f9a091945bb4c743476d12.zip |
SONAR-6074 Add an ability to filter issues by view
Diffstat (limited to 'sonar-core')
12 files changed, 77 insertions, 41 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index 26de7532558..a0ac581d2fa 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -105,6 +105,16 @@ public class ResourceDao implements DaoComponent { } } + @CheckForNull + public ResourceDto getResource(String componentUuid) { + SqlSession session = mybatis.openSession(false); + try { + return session.getMapper(ResourceMapper.class).selectResourceByUuid(componentUuid); + } finally { + MyBatis.closeQuietly(session); + } + } + public ResourceDto getResource(long projectId, SqlSession session) { return session.getMapper(ResourceMapper.class).selectResource(projectId); } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java index 961e6bf3e9b..be3371b2c25 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java @@ -35,6 +35,8 @@ public interface ResourceMapper { ResourceDto selectResource(long id); + ResourceDto selectResourceByUuid(String uuid); + List<ResourceDto> selectDescendantProjects(long rootProjectId); /** diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index 9b29c8f5f70..0f995846731 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -97,6 +97,11 @@ where p.id=#{id} </select> + <select id="selectResourceByUuid" parameterType="String" resultMap="resourceResultMap"> + select * from projects p + where p.uuid=#{uuid} + </select> + <select id="selectSnapshot" parameterType="long" resultMap="snapshotResultMap"> select * from snapshots where id=#{id} </select> diff --git a/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml index 88549a4ab31..12e1e32da23 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/AuthorizationMapper.xml @@ -39,7 +39,7 @@ <when test="userId != null"> SELECT p.kee as root_project_kee FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL <where> and gr.role=#{role} and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId})) @@ -47,7 +47,7 @@ UNION SELECT p.kee as root_project_kee FROM user_roles ur - INNER JOIN projects p on p.id = ur.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = ur.resource_id AND p.module_uuid IS NULL <where> and ur.role=#{role} and ur.user_id = #{userId} @@ -56,7 +56,7 @@ <otherwise> SELECT p.kee as root_project_kee FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL <where> and gr.role=#{role} and gr.group_id is null @@ -70,7 +70,7 @@ <when test="userId != null"> SELECT p.uuid as root_project_uuid FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL <where> and gr.role=#{role} and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId})) @@ -78,7 +78,7 @@ UNION SELECT p.uuid as root_project_uuid FROM user_roles ur - INNER JOIN projects p on p.id = ur.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = ur.resource_id AND p.module_uuid IS NULL <where> and ur.role=#{role} and ur.user_id = #{userId} @@ -87,7 +87,7 @@ <otherwise> SELECT p.uuid as root_project_uuid FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL <where> and gr.role=#{role} and gr.group_id is null @@ -102,7 +102,7 @@ <when test="userId != null"> SELECT p.id as root_project_id FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL <where> and gr.role=#{role} and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId})) @@ -110,7 +110,7 @@ UNION SELECT p.id as root_project_id FROM user_roles ur - INNER JOIN projects p on p.id = ur.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = ur.resource_id AND p.module_uuid IS NULL <where> and ur.role=#{role} and ur.user_id = #{userId} @@ -119,7 +119,7 @@ <otherwise> SELECT p.id as root_project_id FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.scope = 'PRJ' AND p.qualifier = 'TRK' + INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL <where> and gr.role=#{role} and gr.group_id is null diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index 940d20690ac..e97cfa1d868 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -103,6 +103,25 @@ public class ResourceDaoTest extends AbstractDaoTestCase { } @Test + public void get_resource_by_uuid() { + setupData("fixture"); + + ResourceDto resource = dao.getResource("ABCD"); + + assertThat(resource.getUuid()).isEqualTo("ABCD"); + assertThat(resource.getProjectUuid()).isEqualTo("ABCD"); + assertThat(resource.getPath()).isNull(); + assertThat(resource.getName()).isEqualTo("Struts"); + assertThat(resource.getLongName()).isEqualTo("Apache Struts"); + assertThat(resource.getScope()).isEqualTo("PRJ"); + assertThat(resource.getDescription()).isEqualTo("the description"); + assertThat(resource.getLanguage()).isEqualTo("java"); + assertThat(resource.isEnabled()).isTrue(); + assertThat(resource.getAuthorizationUpdatedAt()).isNotNull(); + assertThat(resource.getCreatedAt()).isNotNull(); + } + + @Test public void get_resource_path_and_module_key() { setupData("fixture"); diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/anonymous_should_be_authorized.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/anonymous_should_be_authorized.xml index aaf6b56ff94..f5730087a21 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/anonymous_should_be_authorized.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/anonymous_should_be_authorized.xml @@ -5,10 +5,10 @@ <group_roles id="1" group_id="[null]" resource_id="300" role="user"/> <group_roles id="2" group_id="[null]" resource_id="400" role="user"/> - <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD"/> - <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE"/> - <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF" /> - <projects id="300" kee="pj-w-snapshot" uuid="EDFG"/> - <projects id="400" kee="pj-wo-snapshot" uuid="FGHI"/> + <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD" module_uuid="EDFG"/> + <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE" module_uuid="EDFG"/> + <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF" module_uuid="EDFG"/> + <projects id="300" kee="pj-w-snapshot" uuid="EDFG" module_uuid="[null]"/> + <projects id="400" kee="pj-wo-snapshot" uuid="FGHI" project_uuid="FGHI"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_be_authorized.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_be_authorized.xml index b500a05366a..7ffca0d6f5e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_be_authorized.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_be_authorized.xml @@ -7,10 +7,10 @@ <group_roles id="1" group_id="200" resource_id="300" role="user"/> <group_roles id="2" group_id="200" resource_id="400" role="user"/> - <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD"/> - <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE"/> - <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF"/> - <projects id="300" kee="pj-w-snapshot" uuid="DEFG"/> - <projects id="400" kee="pj-wo-snapshot" uuid="EFGH"/> + <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD" module_uuid="DEFG"/> + <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE" module_uuid="DEFG"/> + <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF" module_uuid="DEFG"/> + <projects id="300" kee="pj-w-snapshot" uuid="DEFG" module_uuid="[null]"/> + <projects id="400" kee="pj-wo-snapshot" uuid="EFGH" module_uuid="[null]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_have_global_authorization.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_have_global_authorization.xml index fe02d7bccbb..c5cd325ea5e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_have_global_authorization.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/group_should_have_global_authorization.xml @@ -6,10 +6,10 @@ <groups_users user_id="100" group_id="200"/> <group_roles id="1" group_id="200" resource_id="[null]" role="user"/> - <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD"/> - <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE"/> - <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF"/> - <projects id="300" kee="pj-w-snapshot" uuid="DEFG"/> - <projects id="400" kee="pj-wo-snapshot" uuid="EFGH"/> + <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD" module_uuid="DEFG"/> + <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE" module_uuid="DEFG"/> + <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF" module_uuid="DEFG"/> + <projects id="300" kee="pj-w-snapshot" uuid="DEFG" module_uuid="[null]"/> + <projects id="400" kee="pj-wo-snapshot" uuid="EFGH" module_uuid="[null]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml index eb7321ec20f..ed6f133f679 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml @@ -4,10 +4,10 @@ <groups_users user_id="100" group_id="200"/> <group_roles id="1" group_id="[null]" resource_id="300" role="user"/> - <projects id="300" uuid="ABCD" kee="pj-w-snapshot" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="301" uuid="BCDE" kee="pj-w-snapshot1" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="302" uuid="CDEF" kee="pj-w-snapshot2" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="300" uuid="ABCD" module_uuid="[null]" kee="pj-w-snapshot" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="301" uuid="BCDE" module_uuid="[null]" kee="pj-w-snapshot1" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="302" uuid="CDEF" module_uuid="[null]" kee="pj-w-snapshot2" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="303" uuid="DEFG" kee="pj-w-snapshot3" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="303" uuid="DEFG" module_uuid="[null]" kee="pj-w-snapshot3" scope="PRJ" qualifier="TRK" enabled="[true]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml index 05bca26378a..65b2ad7d372 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml @@ -6,10 +6,10 @@ <groups_users user_id="100" group_id="200"/> <group_roles id="1" group_id="200" resource_id="300" role="user"/> - <projects id="300" uuid="ABCD" kee="pj-w-snapshot" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="301" uuid="BCDE" kee="pj-w-snapshot1" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="302" uuid="CDEF" kee="pj-w-snapshot2" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="300" uuid="ABCD" module_uuid="[null]" kee="pj-w-snapshot" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="301" uuid="BCDE" module_uuid="[null]" kee="pj-w-snapshot1" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="302" uuid="CDEF" module_uuid="[null]" kee="pj-w-snapshot2" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="303" uuid="DEFG" kee="pj-w-snapshot3" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="303" uuid="DEFG" module_uuid="[null]" kee="pj-w-snapshot3" scope="PRJ" qualifier="TRK" enabled="[true]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml index 9ca62ae7ab8..706c9300fee 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml @@ -5,10 +5,10 @@ <groups_users user_id="100" group_id="200"/> <group_roles id="1" group_id="200" resource_id="999" role="user"/> - <projects id="300" uuid="ABCD" kee="pj-w-snapshot" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="301" uuid="BCDE" kee="pj-w-snapshot1" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="302" uuid="CDEF" kee="pj-w-snapshot2" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="300" uuid="ABCD" module_uuid="[null]" kee="pj-w-snapshot" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="301" uuid="BCDE" module_uuid="[null]" kee="pj-w-snapshot1" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="302" uuid="CDEF" module_uuid="[null]" kee="pj-w-snapshot2" scope="PRJ" qualifier="TRK" enabled="[true]"/> - <projects id="303" uuid="DEFG" kee="pj-w-snapshot3" scope="PRJ" qualifier="TRK" enabled="[true]"/> + <projects id="303" uuid="DEFG" module_uuid="[null]" kee="pj-w-snapshot3" scope="PRJ" qualifier="TRK" enabled="[true]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml index 07f8997740d..b6371a7e0b1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorizationDaoTest/user_should_be_authorized.xml @@ -6,9 +6,9 @@ <groups_users user_id="100" group_id="200"/> <group_roles id="1" group_id="200" resource_id="999" role="user"/> - <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD"/> - <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE"/> - <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF"/> - <projects id="300" kee="pj-w-snapshot" uuid="DEFG"/> - <projects id="400" kee="pj-wo-snapshot" uuid="EFGH"/> + <projects id="301" kee="pj-w-snapshot:package" root_id="300" uuid="ABCD" module_uuid="DEFG"/> + <projects id="302" kee="pj-w-snapshot:file" root_id="300" uuid="BCDE" module_uuid="DEFG"/> + <projects id="303" kee="pj-w-snapshot:other" root_id="300" uuid="CDEF" module_uuid="DEFG"/> + <projects id="300" kee="pj-w-snapshot" uuid="DEFG" module_uuid="[null]"/> + <projects id="400" kee="pj-wo-snapshot" uuid="EFGH" module_uuid="[null]"/> </dataset> |