diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-16 12:13:34 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-16 12:13:45 +0200 |
commit | ae9e693c2d82c2fa450b29d8c3656d260aac9894 (patch) | |
tree | 3add4d783852e410fee063c2b7e821a9a0963ab4 /sonar-core | |
parent | 69291bdd13e1d9fa27410fe6ef9ec567e69efb62 (diff) | |
download | sonarqube-ae9e693c2d82c2fa450b29d8c3656d260aac9894.tar.gz sonarqube-ae9e693c2d82c2fa450b29d8c3656d260aac9894.zip |
SONAR-4287 Fix issue when loading action plan form
Diffstat (limited to 'sonar-core')
4 files changed, 80 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 79e5d1b13c0..2b6b04a7122 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 @@ -25,6 +25,8 @@ import org.sonar.api.component.Component; import org.sonar.core.component.ComponentDto; import org.sonar.core.persistence.MyBatis; +import javax.annotation.CheckForNull; + import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -152,6 +154,26 @@ public class ResourceDao { } } + @CheckForNull + public ResourceDto getRootProjectByComponentKey(String componentKey) { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(ResourceMapper.class).selectRootProjectByComponentKey(componentKey); + } finally { + MyBatis.closeQuietly(session); + } + } + + @CheckForNull + public ResourceDto getRootProjectByComponentId(Long componentId) { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(ResourceMapper.class).selectRootProjectByComponentId(componentId); + } finally { + MyBatis.closeQuietly(session); + } + } + public 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 13093cce06c..7e500ac589a 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 @@ -55,6 +55,17 @@ public interface ResourceMapper { */ List<ResourceDto> selectResourcesById(@Param("ids") List <List<Integer>> ids); + /** + * @since 3.6 + */ + ResourceDto selectRootProjectByComponentKey(@Param("componentKey") String componentKey); + + /** + * @since 3.6 + */ + ResourceDto selectRootProjectByComponentId(@Param("componentId") Long componentId); + + void insert(ResourceDto resource); void update(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 ded87d52b8f..1b1270b7dbe 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 @@ -101,6 +101,25 @@ select * from projects where scope='PRJ' and root_id=#{id} </select> + <select id="selectRootProjectByComponentKey" parameterType="string" resultMap="resourceResultMap"> + select rootProject.* + from projects p, snapshots s, projects rootProject + <where> + and p.kee=#{componentKey} + and s.project_id=p.id + and rootProject.id=s.root_project_id + </where> + </select> + + <select id="selectRootProjectByComponentId" parameterType="long" resultMap="resourceResultMap"> + select rootProject.* + from snapshots s, projects rootProject + <where> + and s.project_id=#{componentId} + and rootProject.id=s.root_project_id + </where> + </select> + <insert id="insert" parameterType="Resource" useGeneratedKeys="true" keyProperty="id"> insert into projects (name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, enabled, created_at) 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 961467b4177..1c5eb3bf23a 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 @@ -160,6 +160,34 @@ public class ResourceDaoTest extends AbstractDaoTestCase { } @Test + public void should_find_root_project_by_component_key() { + setupData("fixture"); + + ResourceDto resource = dao.getRootProjectByComponentKey("org.struts:struts:org.struts.RequestContext"); + assertThat(resource.getName()).isEqualTo("Struts"); + + resource = dao.getRootProjectByComponentKey("org.struts:struts:org.struts"); + assertThat(resource.getName()).isEqualTo("Struts"); + + resource = dao.getRootProjectByComponentKey("org.struts:struts-core"); + assertThat(resource.getName()).isEqualTo("Struts"); + } + + @Test + public void should_find_root_project_by_component_Id() { + setupData("fixture"); + + ResourceDto resource = dao.getRootProjectByComponentId(4l); + assertThat(resource.getName()).isEqualTo("Struts"); + + resource = dao.getRootProjectByComponentId(3l); + assertThat(resource.getName()).isEqualTo("Struts"); + + resource = dao.getRootProjectByComponentId(2l); + assertThat(resource.getName()).isEqualTo("Struts"); + } + + @Test public void should_update() { setupData("update"); |