]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16316 Minor refactoring on quality profile findings writer
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>
Fri, 3 Jun 2022 11:06:36 +0000 (13:06 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 3 Jun 2022 20:03:04 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java

index c867aa778ddf012ff12459705716492cd51c2d7d..f96e21bad3ae85e5a5ae19de8d5cbd64bc9fb337 100644 (file)
@@ -50,6 +50,7 @@ public class ActiveRuleDto {
   private String ruleField;
   private String ruleProfileUuid;
   private String securityStandards;
+  private boolean isExternal;
 
   public ActiveRuleDto() {
     // nothing to do here
@@ -160,6 +161,15 @@ public class ActiveRuleDto {
     return this;
   }
 
+  public boolean isExternal() {
+    return this.isExternal;
+  }
+
+  public ActiveRuleDto setIsExternal(boolean isExternal) {
+    this.isExternal = isExternal;
+    return this;
+  }
+
   public static ActiveRuleDto createFor(QProfileDto profile, RuleDto ruleDto) {
     requireNonNull(profile.getRulesProfileUuid(), "Profile is not persisted");
     requireNonNull(ruleDto.getUuid(), "Rule is not persisted");
index 2948705b2a910b5516f75f452fce3f5ae06b7cc0..7d2d4c1838b9aa82bc36c030873b57f90eb2061b 100644 (file)
@@ -171,6 +171,10 @@ public class QualityProfileDao implements Dao {
     return mapper(dbSession).selectQProfileUuidsByProjectUuid(projectUuid);
   }
 
+  public List<QProfileDto> selectQProfilesByProjectUuid(DbSession dbSession, String projectUuid) {
+    return mapper(dbSession).selectQProfilesByProjectUuid(projectUuid);
+  }
+
   public List<QProfileDto> selectByLanguage(DbSession dbSession, String language) {
     return mapper(dbSession).selectByLanguage(language);
   }
index cf5e8480f94c0b2cc90621744417ad541b31b48f..27fc6f28def8627844788ee5afa6b73754f91be7 100644 (file)
@@ -24,7 +24,6 @@ import java.util.Date;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.ResultHandler;
 import org.sonar.db.KeyLongValue;
 
 public interface QualityProfileMapper {
@@ -94,6 +93,8 @@ public interface QualityProfileMapper {
 
   List<String> selectQProfileUuidsByProjectUuid(@Param("projectUuid") String projectUuid);
 
+  List<QProfileDto> selectQProfilesByProjectUuid(@Param("projectUuid") String projectUuid);
+
   void insertProjectProfileAssociation(
     @Param("uuid") String uuid,
     @Param("projectUuid") String projectUuid,
index 8d05ec5155bd9560a9b2335143c8c11dde4cebe0..84a298f7dccabecb0586047564896f06cef24675 100644 (file)
@@ -28,7 +28,8 @@
     rp.uuid as "ruleProfileUuid",
     a.created_at as "createdAt",
     a.updated_at as "updatedAt",
-    oqp.uuid as "orgProfileUuid"
+    oqp.uuid as "orgProfileUuid",
+    r.is_external as "isExternal"
   </sql>
 
   <sql id="activeRuleKeyJoin">
index db706ae4d65b09e4cbad56ff3a09721fee176cfc..fb610cac517939462d4ae419e8efefad924d92c7 100644 (file)
     </where>
   </select>
 
+  <select id="selectQProfilesByProjectUuid" parameterType="String" resultType="org.sonar.db.qualityprofile.QProfileDto">
+    select
+    <include refid="qProfileColumns"/>
+    from org_qprofiles oqp
+      inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
+      inner join project_qprofiles pqp on pqp.profile_key = oqp.uuid
+    where
+      pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
+  </select>
+
   <insert id="insertProjectProfileAssociation" useGeneratedKeys="false">
     insert into project_qprofiles (
       uuid,
index 9a83f626dcaa14ee6566558d0cc928a95d270ddc..30781d2d34d26990e89cb745893382397f822724 100644 (file)
@@ -259,6 +259,7 @@ public class ActiveRuleDaoTest {
     ActiveRuleDto activeRule = createFor(profile1, rule1)
       .setSeverity(BLOCKER)
       .setInheritance(INHERITED)
+      .setIsExternal(false)
       .setCreatedAt(1000L)
       .setUpdatedAt(2000L);
     underTest.insert(dbSession, activeRule);
@@ -271,6 +272,7 @@ public class ActiveRuleDaoTest {
     assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
     assertThat(result.getSeverityString()).isEqualTo(BLOCKER);
     assertThat(result.getInheritance()).isEqualTo(INHERITED);
+    assertThat(result.isExternal()).isFalse();
     assertThat(result.getCreatedAt()).isEqualTo(1000L);
     assertThat(result.getUpdatedAt()).isEqualTo(2000L);
   }
index 2ea5e44292cc041a18b54147bcc45b979cc44e6d..f2a77a607e9da8cc731cd7bab7f73e0f29fcc4c7 100644 (file)
@@ -693,6 +693,27 @@ public class QualityProfileDaoTest {
       .isEmpty();
   }
 
+  @Test
+  public void test_selectQProfilesByProjectUuid() {
+    ProjectDto project1 = db.components().insertPublicProjectDto();
+    ProjectDto project2 = db.components().insertPublicProjectDto();
+    ProjectDto project3 = db.components().insertPublicProjectDto();
+    QProfileDto javaProfile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
+    QProfileDto jsProfile = db.qualityProfiles().insert(p -> p.setLanguage("js"));
+    QProfileDto cProfile = db.qualityProfiles().insert(p -> p.setLanguage("c"));
+    db.qualityProfiles().associateWithProject(project1, javaProfile, cProfile);
+    db.qualityProfiles().associateWithProject(project2, jsProfile);
+
+    assertThat(underTest.selectQProfilesByProjectUuid(dbSession, project1.getUuid()))
+      .containsExactly(javaProfile, cProfile);
+
+    assertThat(underTest.selectQProfilesByProjectUuid(dbSession, project2.getUuid()))
+      .containsExactly(jsProfile);
+
+    assertThat(underTest.selectQProfilesByProjectUuid(dbSession, project3.getUuid()))
+      .isEmpty();
+  }
+
   @Test
   public void test_updateProjectProfileAssociation() {
     ProjectDto project = db.components().insertPrivateProjectDto();