aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-07-17 18:26:31 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-07-17 18:26:31 +0200
commitaab6ac481446f5373f662b7c75dc88897d99864d (patch)
treeba2a0a80abf68c9d4979e6592cb25ca9359a789a /sonar-core/src
parent20cac9a061e03e3d6fbaee936b46609c2f3f5569 (diff)
downloadsonarqube-aab6ac481446f5373f662b7c75dc88897d99864d.tar.gz
sonarqube-aab6ac481446f5373f662b7c75dc88897d99864d.zip
SONAR-4419 when searching for projects, the technical projects should not be returned
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java17
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml12
-rw-r--r--sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java12
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml9
5 files changed, 54 insertions, 0 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 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<Component> selectComponentsByQualifiers(Collection<String> qualifiers) {
+ if (qualifiers.isEmpty()) {
+ return Collections.emptyList();
+ }
+ SqlSession session = mybatis.openSession();
+ try {
+ List<ResourceDto> resourceDtos = session.getMapper(ResourceMapper.class).selectComponentsByQualifiers(qualifiers);
+ List<Component> 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<Integer> selectAuthorizedChildrenComponentIds(@Param("componentRootKeys") Collection<String> componentRootKeys,
@Param("userId") @Nullable Integer userId, @Param("role") String role);
+ /**
+ * @since 3.7
+ */
+ List<ResourceDto> selectComponentsByQualifiers(@Param("qualifiers") Collection<String> 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 @@
</where>
</select>
+ <select id="selectComponentsByQualifiers" parameterType="map" resultMap="resourceResultMap">
+ select * from projects p
+ <where>
+ <if test="qualifiers != null and qualifiers.size() > 0">
+ and p.qualifier in
+ <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator="," close=")">#{qualifier}</foreach>
+ </if>
+ and p.enabled=${_true}
+ and p.copy_resource_id is null
+ </where>
+ </select>
+
<select id="selectAuthorizedChildrenComponentIds" parameterType="map" resultType="int">
<include refid="selectAuthorizedChildrenComponentIdsQuery" />
</select>
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<Component> 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.<String>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 @@
+<dataset>
+
+ <!-- technical project -->
+ <projects id="5" root_id="[null]" scope="PRJ" qualifier="TRK" kee="COPYorg.struts:struts" name="Struts"
+ description="the description" long_name="Apache Struts"
+ enabled="[true]" language="java" copy_resource_id="1" person_id="[null]"/>
+
+
+</dataset>