private String ruleField;
private String ruleProfileUuid;
private String securityStandards;
+ private boolean isExternal;
public ActiveRuleDto() {
// nothing to do here
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");
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);
}
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 {
List<String> selectQProfileUuidsByProjectUuid(@Param("projectUuid") String projectUuid);
+ List<QProfileDto> selectQProfilesByProjectUuid(@Param("projectUuid") String projectUuid);
+
void insertProjectProfileAssociation(
@Param("uuid") String uuid,
@Param("projectUuid") String projectUuid,
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">
</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,
ActiveRuleDto activeRule = createFor(profile1, rule1)
.setSeverity(BLOCKER)
.setInheritance(INHERITED)
+ .setIsExternal(false)
.setCreatedAt(1000L)
.setUpdatedAt(2000L);
underTest.insert(dbSession, activeRule);
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);
}
.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();