<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>
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"
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>
// 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
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.");