From aab6ac481446f5373f662b7c75dc88897d99864d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 17 Jul 2013 18:26:31 +0200 Subject: SONAR-4419 when searching for projects, the technical projects should not be returned --- .../main/java/org/sonar/core/resource/ResourceDao.java | 17 +++++++++++++++++ .../java/org/sonar/core/resource/ResourceMapper.java | 4 ++++ .../org/sonar/core/resource/ResourceMapper.xml | 12 ++++++++++++ .../java/org/sonar/core/resource/ResourceDaoTest.java | 12 ++++++++++++ .../core/resource/ResourceDaoTest/technical-project.xml | 9 +++++++++ 5 files changed, 54 insertions(+) create mode 100644 sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml (limited to 'sonar-core/src') 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 b6a5e8c113f..18bb0ec788c 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 @@ -201,6 +201,23 @@ public class ResourceDao { } } + public List selectComponentsByQualifiers(Collection qualifiers) { + if (qualifiers.isEmpty()) { + return Collections.emptyList(); + } + SqlSession session = mybatis.openSession(); + try { + List resourceDtos = session.getMapper(ResourceMapper.class).selectComponentsByQualifiers(qualifiers); + List components = newArrayList(); + for (ResourceDto resourceDto : resourceDtos) { + components.add(toComponent(resourceDto)); + } + return components; + } finally { + MyBatis.closeQuietly(session); + } + } + public static ComponentDto toComponent(ResourceDto resourceDto){ return new ComponentDto() .setKey(resourceDto.getKey()) 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 2632a0d1929..c8a811080fb 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 @@ -74,6 +74,10 @@ public interface ResourceMapper { List selectAuthorizedChildrenComponentIds(@Param("componentRootKeys") Collection componentRootKeys, @Param("userId") @Nullable Integer userId, @Param("role") String role); + /** + * @since 3.7 + */ + List selectComponentsByQualifiers(@Param("qualifiers") Collection qualifier); void insert(ResourceDto resource); 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 16c5c68f3ba..3d0319a0e04 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 @@ -120,6 +120,18 @@ + + 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 1855d41a178..11a7edcd71e 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 @@ -308,4 +308,16 @@ public class ResourceDaoTest extends AbstractDaoTestCase { assertThat(dao.findByKey("org.struts:struts:org.struts.RequestContext")).isNotNull(); assertThat(dao.findByKey("unknown")).isNull(); } + + @Test + public void should_select_components_by_qualifiers(){ + setupData("fixture", "technical-project"); + + List components = dao.selectComponentsByQualifiers(newArrayList("TRK")); + assertThat(components).hasSize(1); + assertThat(components.get(0).key()).isEqualTo("org.struts:struts"); + + assertThat(dao.selectComponentsByQualifiers(newArrayList("unknown"))).isEmpty(); + assertThat(dao.selectComponentsByQualifiers(Collections.emptyList())).isEmpty(); + } } diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml new file mode 100644 index 00000000000..ba8298a2ae9 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml @@ -0,0 +1,9 @@ + + + + + + + -- cgit v1.2.3