]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Fix issue on SQL to retrieve root project
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 5 Jun 2013 11:04:15 +0000 (13:04 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 5 Jun 2013 11:04:15 +0000 (13:04 +0200)
sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml
sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
sonar-server/src/test/java/org/sonar/server/issue/IssueServiceTest.java

index 41de56b693121058d03b042b0f1dfc4885286941..0b6d58823bb0c90d43e9e0abd9d68bf7e1704e3d 100644 (file)
 
   <select id="selectRootProjectByComponentKey" parameterType="string" resultMap="resourceResultMap">
     select rootProject.*
-    from projects p, snapshots s, projects rootProject
+    from projects p
+    inner join snapshots s on s.project_id=p.id and s.islast=${_true}
+    inner join projects rootProject on rootProject.id=s.root_project_id
     <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
+    from snapshots s
+    inner join projects rootProject on rootProject.id=s.root_project_id
     <where>
       and s.project_id=#{componentId}
-      and rootProject.id=s.root_project_id
+      and s.islast=${_true}
     </where>
   </select>
 
index 6445d143ed7b3e11481058e6ce8d3ac645eb0935..0c72a978001470c1abe525e8b843e2e8bfb91894 100644 (file)
                period5_mode="[null]" period5_param="[null]" period5_date="[null]"
                depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
                version="[null]" path=""/>
+  <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="[false]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" build_date="2008-12-01 13:58:00.00"
+             version="[null]" path=""/>
 
   <!-- project -->
   <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
@@ -58,4 +67,6 @@
                period5_mode="[null]" period5_param="[null]" period5_date="[null]"
                depth="[null]" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
                version="[null]" path="1.2.3."/>
+
+
 </dataset>
index f6a9e846b0a740e7ca1e0f14cfd8bcb314873c51..14ade9f87e4203c0bef404e7e61c16f15b6f2e79 100644 (file)
@@ -203,14 +203,14 @@ public class IssueService implements ServerComponent {
       // must be logged
       throw new IllegalStateException("User is not logged in");
     }
-    if (!authorizationDao.isAuthorizedComponentId(findProject(issue.componentKey()).getId(), userSession.userId(), requiredRole)) {
+    if (!authorizationDao.isAuthorizedComponentId(findRootProject(issue.componentKey()).getId(), userSession.userId(), requiredRole)) {
       // TODO throw unauthorized
       throw new IllegalStateException("User does not have the required role");
     }
   }
 
   @VisibleForTesting
-  ResourceDto findProject(String componentKey) {
+  ResourceDto findRootProject(String componentKey) {
     ResourceDto resourceDto = resourceDao.getRootProjectByComponentKey(componentKey);
     if (resourceDto == null) {
       // TODO throw 404
index 584c217ad069940cceef9edaee03b399870dac11..bfeec5cbfc1950b09d3fc1419c8d9f514d698f96 100644 (file)
@@ -411,14 +411,14 @@ public class IssueServiceTest {
   public void should_find_project() {
     ResourceDto project = new ResourceDto().setKey("org.sonar.Sample").setId(1l);
     when(resourceDao.getRootProjectByComponentKey(anyString())).thenReturn(project);
-    assertThat(issueService.findProject("org.sonar.Sample")).isEqualTo(project);
+    assertThat(issueService.findRootProject("org.sonar.Sample")).isEqualTo(project);
   }
 
   @Test
   public void should_fail_to_find_project() {
     when(resourceDao.getRootProjectByComponentKey(anyString())).thenReturn(null);
     try {
-      issueService.findProject("org.sonar.Sample");
+      issueService.findRootProject("org.sonar.Sample");
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Component 'org.sonar.Sample' does not exists.");