diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-05-29 15:43:39 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.com> | 2017-06-14 15:43:12 +0200 |
commit | 71987dfa5a6c563b3d8acf86592517a61ade3bc7 (patch) | |
tree | 5ab45e464265a5347ab105e5f8bbb2035712061a /server/sonar-db-dao | |
parent | 0fb3084e6c609fb9b94cb67ed7c7ac884502aea3 (diff) | |
download | sonarqube-71987dfa5a6c563b3d8acf86592517a61ade3bc7.tar.gz sonarqube-71987dfa5a6c563b3d8acf86592517a61ade3bc7.zip |
SONAR-9304 drop use of rules_profiles.is_default
Diffstat (limited to 'server/sonar-db-dao')
21 files changed, 171 insertions, 197 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index b65f4ba9968..d55857343c3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -97,7 +97,7 @@ import org.sonar.db.qualityprofile.ActiveRuleMapper; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.DefaultQProfileMapper; import org.sonar.db.qualityprofile.QProfileChangeMapper; -import org.sonar.db.qualityprofile.QualityProfileDto; +import org.sonar.db.qualityprofile.RulesProfileDto; import org.sonar.db.qualityprofile.QualityProfileMapper; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMapper; @@ -166,7 +166,7 @@ public class MyBatis implements Startable { confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class); confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class); confBuilder.loadAlias("QualityGate", QualityGateDto.class); - confBuilder.loadAlias("QualityProfile", QualityProfileDto.class); + confBuilder.loadAlias("RulesProfile", RulesProfileDto.class); confBuilder.loadAlias("RequirementMigration", RequirementMigrationDto.class); confBuilder.loadAlias("Resource", ResourceDto.class); confBuilder.loadAlias("RuleParam", RuleParamDto.class); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java index 0f5010156b3..ff3719a8810 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java @@ -142,7 +142,7 @@ public class ActiveRuleDto { return this; } - public static ActiveRuleDto createFor(QualityProfileDto profileDto, RuleDefinitionDto ruleDto) { + public static ActiveRuleDto createFor(RulesProfileDto profileDto, RuleDefinitionDto ruleDto) { requireNonNull(profileDto.getId(), "Profile is not persisted"); requireNonNull(ruleDto.getId(), "Rule is not persisted"); ActiveRuleDto dto = new ActiveRuleDto(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java index 53145402965..e97e7803665 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java @@ -52,7 +52,7 @@ public class DefaultQProfileDto { return this; } - public static DefaultQProfileDto from(QualityProfileDto profile) { + public static DefaultQProfileDto from(RulesProfileDto profile) { return new DefaultQProfileDto() .setOrganizationUuid(profile.getOrganizationUuid()) .setLanguage(profile.getLanguage()) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index 0d0b9421a8e..6d0f8a45065 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -49,35 +49,35 @@ public class QualityProfileDao implements Dao { } @CheckForNull - public QualityProfileDto selectByKey(DbSession session, String key) { + public RulesProfileDto selectByKey(DbSession session, String key) { return mapper(session).selectByKey(key); } - public QualityProfileDto selectOrFailByKey(DbSession session, String key) { - QualityProfileDto dto = selectByKey(session, key); + public RulesProfileDto selectOrFailByKey(DbSession session, String key) { + RulesProfileDto dto = selectByKey(session, key); if (dto == null) { throw new RowNotFoundException("Quality profile not found: " + key); } return dto; } - public List<QualityProfileDto> selectByKeys(DbSession session, List<String> keys) { + public List<RulesProfileDto> selectByKeys(DbSession session, List<String> keys) { return executeLargeInputs(keys, mapper(session)::selectByKeys); } - public List<QualityProfileDto> selectAll(DbSession session, OrganizationDto organization) { + public List<RulesProfileDto> selectAll(DbSession session, OrganizationDto organization) { return mapper(session).selectAll(organization.getUuid()); } - public void insert(DbSession session, QualityProfileDto profile, QualityProfileDto... otherProfiles) { + public void insert(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) { QualityProfileMapper mapper = mapper(session); doInsert(mapper, profile); - for (QualityProfileDto other : otherProfiles) { + for (RulesProfileDto other : otherProfiles) { doInsert(mapper, other); } } - private void doInsert(QualityProfileMapper mapper, QualityProfileDto profile) { + private void doInsert(QualityProfileMapper mapper, RulesProfileDto profile) { Preconditions.checkArgument(profile.getId() == null, "Quality profile is already persisted (got id %d)", profile.getId()); Date now = new Date(system.now()); profile.setCreatedAt(now); @@ -85,52 +85,52 @@ public class QualityProfileDao implements Dao { mapper.insert(profile); } - public void update(DbSession session, QualityProfileDto profile, QualityProfileDto... otherProfiles) { + public void update(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) { QualityProfileMapper mapper = mapper(session); doUpdate(mapper, profile); - for (QualityProfileDto otherProfile : otherProfiles) { + for (RulesProfileDto otherProfile : otherProfiles) { doUpdate(mapper, otherProfile); } } - private void doUpdate(QualityProfileMapper mapper, QualityProfileDto profile) { + private void doUpdate(QualityProfileMapper mapper, RulesProfileDto profile) { Preconditions.checkArgument(profile.getId() != null, "Quality profile is not persisted"); profile.setUpdatedAt(new Date(system.now())); mapper.update(profile); } - public List<QualityProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languageKeys) { + public List<RulesProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languageKeys) { return executeLargeInputs(languageKeys, chunk -> mapper(session).selectDefaultProfiles(organization.getUuid(), chunk)); } @CheckForNull - public QualityProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) { + public RulesProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) { return mapper(session).selectDefaultProfile(organization.getUuid(), language); } @CheckForNull - public QualityProfileDto selectByProjectAndLanguage(DbSession session, String projectKey, String language) { + public RulesProfileDto selectByProjectAndLanguage(DbSession session, String projectKey, String language) { return mapper(session).selectByProjectAndLanguage(projectKey, language); } - public List<QualityProfileDto> selectByProjectAndLanguages(DbSession session, OrganizationDto organization, ComponentDto project, Collection<String> languageKeys) { + public List<RulesProfileDto> selectByProjectAndLanguages(DbSession session, OrganizationDto organization, ComponentDto project, Collection<String> languageKeys) { return executeLargeInputs(languageKeys, input -> mapper(session).selectByProjectAndLanguages(organization.getUuid(), project.getKey(), input)); } - public List<QualityProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) { + public List<RulesProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) { return mapper(dbSession).selectByLanguage(organization.getUuid(), language); } - public List<QualityProfileDto> selectChildren(DbSession session, String key) { + public List<RulesProfileDto> selectChildren(DbSession session, String key) { return mapper(session).selectChildren(key); } /** * All descendants, in the top-down order. */ - public List<QualityProfileDto> selectDescendants(DbSession session, String key) { - List<QualityProfileDto> descendants = Lists.newArrayList(); - for (QualityProfileDto child : selectChildren(session, key)) { + public List<RulesProfileDto> selectDescendants(DbSession session, String key) { + List<RulesProfileDto> descendants = Lists.newArrayList(); + for (RulesProfileDto child : selectChildren(session, key)) { descendants.add(child); descendants.addAll(selectDescendants(session, child.getKey())); } @@ -138,11 +138,11 @@ public class QualityProfileDao implements Dao { } @CheckForNull - public QualityProfileDto selectByNameAndLanguage(OrganizationDto organization, String name, String language, DbSession session) { + public RulesProfileDto selectByNameAndLanguage(OrganizationDto organization, String name, String language, DbSession session) { return mapper(session).selectByNameAndLanguage(organization.getUuid(), name, language); } - public List<QualityProfileDto> selectByNameAndLanguages(OrganizationDto organization, String name, Collection<String> languageKeys, DbSession session) { + public List<RulesProfileDto> selectByNameAndLanguages(OrganizationDto organization, String name, Collection<String> languageKeys, DbSession session) { return executeLargeInputs(languageKeys, input -> mapper(session).selectByNameAndLanguages(organization.getUuid(), name, input)); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java index d7aed6dd103..10bf85d14de 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java @@ -28,43 +28,43 @@ import org.sonar.db.KeyLongValue; public interface QualityProfileMapper { - void insert(QualityProfileDto dto); + void insert(RulesProfileDto dto); - void update(QualityProfileDto dto); + void update(RulesProfileDto dto); void deleteByKeys(@Param("profileKeys") Collection<String> profileKeys); - List<QualityProfileDto> selectAll(@Param("organizationUuid") String organizationUuid); + List<RulesProfileDto> selectAll(@Param("organizationUuid") String organizationUuid); @CheckForNull - QualityProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language); + RulesProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language); - List<QualityProfileDto> selectDefaultProfiles(@Param("organizationUuid") String organizationUuid, @Param("languages") List<String> languages); + List<RulesProfileDto> selectDefaultProfiles(@Param("organizationUuid") String organizationUuid, @Param("languages") List<String> languages); @CheckForNull - QualityProfileDto selectByNameAndLanguage(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("language") String language); + RulesProfileDto selectByNameAndLanguage(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("language") String language); - List<QualityProfileDto> selectByNameAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("languages") List<String> languages); + List<RulesProfileDto> selectByNameAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("languages") List<String> languages); @CheckForNull - QualityProfileDto selectByKey(String key); + RulesProfileDto selectByKey(String key); - List<QualityProfileDto> selectByLanguage(@Param("organizationUuid") String organizationUuid, @Param("language") String language); + List<RulesProfileDto> selectByLanguage(@Param("organizationUuid") String organizationUuid, @Param("language") String language); - List<QualityProfileDto> selectByKeys(@Param("keys") List<String> keys); + List<RulesProfileDto> selectByKeys(@Param("keys") List<String> keys); // INHERITANCE - List<QualityProfileDto> selectChildren(String key); + List<RulesProfileDto> selectChildren(String key); // PROJECTS List<KeyLongValue> countProjectsByProfileKey(@Param("organizationUuid") String organizationUuid); - QualityProfileDto selectByProjectAndLanguage(@Param("projectKey") String projectKey, @Param("language") String language); + RulesProfileDto selectByProjectAndLanguage(@Param("projectKey") String projectKey, @Param("language") String language); - List<QualityProfileDto> selectByProjectAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("projectKey") String projectKey, - @Param("languages") List<String> input); + List<RulesProfileDto> selectByProjectAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("projectKey") String projectKey, + @Param("languages") List<String> input); void insertProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileKey") String profileKey); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java index 372ee468f0d..cc8ad2fd1b5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java @@ -29,7 +29,7 @@ import org.sonar.db.organization.OrganizationDto; /** * Represents the table "rules_profiles" */ -public class QualityProfileDto extends Dto<String> { +public class RulesProfileDto extends Dto<String> { private Integer id; /** @@ -45,14 +45,13 @@ public class QualityProfileDto extends Dto<String> { private String rulesUpdatedAt; private Long lastUsed; private Long userUpdatedAt; - private boolean isDefault; private boolean isBuiltIn; public String getOrganizationUuid() { return organizationUuid; } - public QualityProfileDto setOrganizationUuid(String organizationUuid) { + public RulesProfileDto setOrganizationUuid(String organizationUuid) { this.organizationUuid = organizationUuid; return this; } @@ -62,7 +61,7 @@ public class QualityProfileDto extends Dto<String> { return kee; } - public QualityProfileDto setKey(String s) { + public RulesProfileDto setKey(String s) { return setKee(s); } @@ -70,7 +69,7 @@ public class QualityProfileDto extends Dto<String> { return kee; } - public QualityProfileDto setKee(String s) { + public RulesProfileDto setKee(String s) { this.kee = s; return this; } @@ -79,7 +78,7 @@ public class QualityProfileDto extends Dto<String> { return id; } - public QualityProfileDto setId(Integer id) { + public RulesProfileDto setId(Integer id) { this.id = id; return this; } @@ -88,7 +87,7 @@ public class QualityProfileDto extends Dto<String> { return name; } - public QualityProfileDto setName(String name) { + public RulesProfileDto setName(String name) { this.name = name; return this; } @@ -97,7 +96,7 @@ public class QualityProfileDto extends Dto<String> { return language; } - public QualityProfileDto setLanguage(String language) { + public RulesProfileDto setLanguage(String language) { this.language = language; return this; } @@ -107,7 +106,7 @@ public class QualityProfileDto extends Dto<String> { return parentKee; } - public QualityProfileDto setParentKee(@Nullable String s) { + public RulesProfileDto setParentKee(@Nullable String s) { this.parentKee = s; return this; } @@ -116,12 +115,12 @@ public class QualityProfileDto extends Dto<String> { return rulesUpdatedAt; } - public QualityProfileDto setRulesUpdatedAt(String s) { + public RulesProfileDto setRulesUpdatedAt(String s) { this.rulesUpdatedAt = s; return this; } - public QualityProfileDto setRulesUpdatedAtAsDate(Date d) { + public RulesProfileDto setRulesUpdatedAtAsDate(Date d) { this.rulesUpdatedAt = UtcDateUtils.formatDateTime(d); return this; } @@ -131,7 +130,7 @@ public class QualityProfileDto extends Dto<String> { return lastUsed; } - public QualityProfileDto setLastUsed(@Nullable Long lastUsed) { + public RulesProfileDto setLastUsed(@Nullable Long lastUsed) { this.lastUsed = lastUsed; return this; } @@ -141,30 +140,21 @@ public class QualityProfileDto extends Dto<String> { return userUpdatedAt; } - public QualityProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) { + public RulesProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) { this.userUpdatedAt = userUpdatedAt; return this; } - public boolean isDefault() { - return isDefault; - } - - public QualityProfileDto setDefault(boolean isDefault) { - this.isDefault = isDefault; - return this; - } - public boolean isBuiltIn() { return isBuiltIn; } - public QualityProfileDto setIsBuiltIn(boolean b) { + public RulesProfileDto setIsBuiltIn(boolean b) { this.isBuiltIn = b; return this; } - public static QualityProfileDto createFor(String key) { - return new QualityProfileDto().setKee(key); + public static RulesProfileDto createFor(String key) { + return new RulesProfileDto().setKee(key); } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index 45219cde771..9eb7b487da8 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -10,7 +10,6 @@ p.name as name, p.language as language, p.parent_kee as parentKee, - p.is_default as isDefault, p.created_at as createdAt, p.updated_at as updatedAt, p.rules_updated_at as rulesUpdatedAt, @@ -19,15 +18,14 @@ p.is_built_in as isBuiltIn </sql> - <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> - INSERT INTO rules_profiles (organization_uuid, kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used, user_updated_at, is_built_in) + <insert id="insert" parameterType="RulesProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + INSERT INTO rules_profiles (organization_uuid, kee, parent_kee, name, language, created_at, updated_at, rules_updated_at, last_used, user_updated_at, is_built_in) VALUES ( #{organizationUuid, jdbcType=VARCHAR}, #{kee, jdbcType=VARCHAR}, #{parentKee, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{language, jdbcType=VARCHAR}, - #{isDefault, jdbcType=BOOLEAN}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}, #{rulesUpdatedAt, jdbcType=VARCHAR}, @@ -37,11 +35,10 @@ ) </insert> - <update id="update" parameterType="QualityProfile"> + <update id="update" parameterType="RulesProfile"> UPDATE rules_profiles SET name=#{name, jdbcType=VARCHAR}, language=#{language, jdbcType=VARCHAR}, - is_default=#{isDefault, jdbcType=BOOLEAN}, parent_kee=#{parentKee, jdbcType=VARCHAR}, updated_at=#{updatedAt, jdbcType=TIMESTAMP}, rules_updated_at=#{rulesUpdatedAt, jdbcType=VARCHAR}, @@ -57,7 +54,7 @@ <foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">#{profileKey, jdbcType=VARCHAR}</foreach> </update> - <select id="selectAll" parameterType="map" resultType="QualityProfile"> + <select id="selectAll" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -65,7 +62,7 @@ ORDER BY p.name, p.language </select> - <select id="selectByNameAndLanguage" parameterType="map" resultType="QualityProfile"> + <select id="selectByNameAndLanguage" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -76,7 +73,7 @@ </if> </select> - <select id="selectByNameAndLanguages" parameterType="map" resultType="QualityProfile"> + <select id="selectByNameAndLanguages" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -85,14 +82,14 @@ AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} </select> - <select id="selectByKey" parameterType="string" resultType="QualityProfile"> + <select id="selectByKey" parameterType="string" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p WHERE p.kee=#{id} </select> - <select id="selectByKeys" parameterType="string" resultType="QualityProfile"> + <select id="selectByKeys" parameterType="string" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -102,7 +99,7 @@ </foreach> </select> - <select id="selectByLanguage" parameterType="String" resultType="QualityProfile"> + <select id="selectByLanguage" parameterType="String" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -111,7 +108,7 @@ ORDER BY p.name </select> - <select id="selectChildren" parameterType="string" resultType="QualityProfile"> + <select id="selectChildren" parameterType="string" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -119,22 +116,24 @@ ORDER BY p.name </select> - <select id="selectDefaultProfile" parameterType="map" resultType="QualityProfile"> + <select id="selectDefaultProfile" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p - WHERE p.is_default=${_true} - AND p.language=#{language, jdbcType=VARCHAR} - AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} + INNER JOIN default_qprofiles dp on p.kee=dp.qprofile_uuid + WHERE + dp.language=#{language, jdbcType=VARCHAR} + AND dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} </select> - <select id="selectDefaultProfiles" parameterType="map" resultType="QualityProfile"> + <select id="selectDefaultProfiles" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p - WHERE p.is_default=${_true} - AND p.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach> - AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} + INNER JOIN default_qprofiles dp on p.kee=dp.qprofile_uuid + WHERE + dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach> + AND dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} </select> <select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto"> @@ -181,7 +180,7 @@ group by pp.profile_key </select> - <select id="selectByProjectAndLanguage" parameterType="map" resultType="QualityProfile"> + <select id="selectByProjectAndLanguage" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p @@ -190,7 +189,7 @@ WHERE p.language=#{language} </select> - <select id="selectByProjectAndLanguages" parameterType="map" resultType="QualityProfile"> + <select id="selectByProjectAndLanguages" parameterType="map" resultType="RulesProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java index 31c968c6846..30d00d121e2 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java @@ -41,7 +41,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.dialect.Dialect; import org.sonar.db.dialect.Oracle; -import org.sonar.db.qualityprofile.QualityProfileDto; +import org.sonar.db.qualityprofile.RulesProfileDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupTesting; import org.sonar.db.user.UserDto; @@ -877,7 +877,7 @@ public class OrganizationDaoTest { public void selectWithoutQualityProfile_returns_() { OrganizationDto orgWithoutAnyProfiles = dbTester.organizations().insert(); OrganizationDto orgWithProfiles = dbTester.organizations().insert(); - QualityProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles); + RulesProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles); assertThat(underTest.selectWithoutQualityProfile(dbSession, "js", "foo")) .extracting(OrganizationDto::getUuid).containsExactlyInAnyOrder(orgWithoutAnyProfiles.getUuid(), orgWithProfiles.getUuid()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index e6b26bae698..bb08d8d48ee 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -63,8 +63,8 @@ public class ActiveRuleDaoTest { private OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - private QualityProfileDto profile1 = QualityProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1"); - private QualityProfileDto profile2 = QualityProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2"); + private RulesProfileDto profile1 = RulesProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1"); + private RulesProfileDto profile2 = RulesProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2"); private RuleDefinitionDto rule1 = RuleTesting.newRule(RuleTesting.XOO_X1); private RuleDefinitionDto rule2 = RuleTesting.newRule(RuleTesting.XOO_X2); @@ -334,7 +334,7 @@ public class ActiveRuleDaoTest { assertThat(dbTester.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1); } - private static ActiveRuleDto newRow(QualityProfileDto profile, RuleDefinitionDto rule) { + private static ActiveRuleDto newRow(RulesProfileDto profile, RuleDefinitionDto rule) { return createFor(profile, rule).setSeverity(BLOCKER); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java index 3d48cb407c7..f5800f52589 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java @@ -42,7 +42,7 @@ public class DefaultQProfileDaoTest { @Test public void insertOrUpdate_inserts_row_when_does_not_exist() { OrganizationDto org = dbTester.organizations().insert(); - QualityProfileDto profile = dbTester.qualityProfiles().insert(org); + RulesProfileDto profile = dbTester.qualityProfiles().insert(org); DefaultQProfileDto dto = DefaultQProfileDto.from(profile); underTest.insertOrUpdate(dbSession, dto); @@ -94,8 +94,8 @@ public class DefaultQProfileDaoTest { @Test public void selectExistingQProfileUuids_filters_defaults() { OrganizationDto org = dbTester.organizations().insert(); - QualityProfileDto profile1 = dbTester.qualityProfiles().insert(org); - QualityProfileDto profile2 = dbTester.qualityProfiles().insert(org); + RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org); + RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org); dbTester.qualityProfiles().markAsDefault(profile1); List<String> profileUuids = asList(profile1.getKee(), profile2.getKee(), "other"); @@ -106,8 +106,8 @@ public class DefaultQProfileDaoTest { @Test public void isDefault_returns_true_if_profile_is_marked_as_default() { OrganizationDto org = dbTester.organizations().insert(); - QualityProfileDto profile1 = dbTester.qualityProfiles().insert(org); - QualityProfileDto profile2 = dbTester.qualityProfiles().insert(org); + RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org); + RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org); dbTester.qualityProfiles().markAsDefault(profile1); assertThat(underTest.isDefault(dbSession, org.getUuid(), profile1.getKee())).isTrue(); @@ -115,7 +115,7 @@ public class DefaultQProfileDaoTest { assertThat(underTest.isDefault(dbSession, org.getUuid(), "does_not_exist")).isFalse(); } - private void assertThatIsDefault(OrganizationDto org, QualityProfileDto profile) { + private void assertThatIsDefault(OrganizationDto org, RulesProfileDto profile) { assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org, profile.getLanguage())).hasValue(profile.getKee()); assertThat(underTest.isDefault(dbSession, org.getUuid(), profile.getKee())).isTrue(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index 30f0dffd516..f67b323e5a2 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -75,7 +75,7 @@ public class QualityProfileDaoTest { public void insert() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - QualityProfileDto dto = QualityProfileDto.createFor("abcde") + RulesProfileDto dto = RulesProfileDto.createFor("abcde") .setOrganizationUuid(organization.getUuid()) .setName("ABCDE") .setLanguage("xoo") @@ -91,13 +91,12 @@ public class QualityProfileDaoTest { public void update() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - QualityProfileDto dto = QualityProfileDto.createFor("key") + RulesProfileDto dto = RulesProfileDto.createFor("key") .setId(1) .setOrganizationUuid(organization.getUuid()) .setName("New Name") .setLanguage("js") .setParentKee("fghij") - .setDefault(false) .setIsBuiltIn(false); underTest.update(dbSession, dto); @@ -108,9 +107,9 @@ public class QualityProfileDaoTest { @Test public void test_deleteByKeys() { - QualityProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); - QualityProfileDto p2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); - QualityProfileDto p3 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto p2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto p3 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); underTest.deleteByKeys(dbSession, asList(p1.getKey(), p3.getKey(), "does_not_exist")); @@ -121,7 +120,7 @@ public class QualityProfileDaoTest { @Test public void deleteByKeys_does_nothing_if_empty_keys() { - QualityProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); underTest.deleteByKeys(dbSession, Collections.emptyList()); @@ -130,7 +129,7 @@ public class QualityProfileDaoTest { @Test public void deleteProjectAssociationsByProfileKeys_does_nothing_if_empty_keys() { - QualityProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); ComponentDto project1 = dbTester.components().insertPrivateProject(); dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1); @@ -141,8 +140,8 @@ public class QualityProfileDaoTest { @Test public void deleteProjectAssociationsByProfileKeys_deletes_rows_from_table_project_profiles() { - QualityProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); - QualityProfileDto profile2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); + RulesProfileDto profile2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization()); ComponentDto project1 = dbTester.components().insertPrivateProject(); ComponentDto project2 = dbTester.components().insertPrivateProject(); ComponentDto project3 = dbTester.components().insertPrivateProject(); @@ -162,18 +161,18 @@ public class QualityProfileDaoTest { public void find_all() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - List<QualityProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization); + List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization); assertThat(dtos).hasSize(2); - QualityProfileDto dto1 = dtos.get(0); + RulesProfileDto dto1 = dtos.get(0); assertThat(dto1.getId()).isEqualTo(1); assertThat(dto1.getName()).isEqualTo("Sonar Way"); assertThat(dto1.getLanguage()).isEqualTo("java"); assertThat(dto1.getParentKee()).isNull(); assertThat(dto1.isBuiltIn()).isTrue(); - QualityProfileDto dto2 = dtos.get(1); + RulesProfileDto dto2 = dtos.get(1); assertThat(dto2.getId()).isEqualTo(2); assertThat(dto2.getName()).isEqualTo("Sonar Way"); assertThat(dto2.getLanguage()).isEqualTo("js"); @@ -185,7 +184,7 @@ public class QualityProfileDaoTest { public void find_all_is_sorted_by_profile_name() { dbTester.prepareDbUnit(getClass(), "select_all_is_sorted_by_profile_name.xml"); - List<QualityProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization); + List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization); assertThat(dtos).hasSize(3); assertThat(dtos.get(0).getName()).isEqualTo("First"); @@ -197,7 +196,7 @@ public class QualityProfileDaoTest { public void get_default_profile() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - QualityProfileDto java = underTest.selectDefaultProfile(dbTester.getSession(), organization, "java"); + RulesProfileDto java = underTest.selectDefaultProfile(dbTester.getSession(), organization, "java"); assertThat(java).isNotNull(); assertThat(java.getKey()).isEqualTo("java_sonar_way"); @@ -209,7 +208,7 @@ public class QualityProfileDaoTest { public void get_default_profiles() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - List<QualityProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("java")); + List<RulesProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("java")); assertThat(java).extracting("key").containsOnly("java_sonar_way"); assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("js"))).isEmpty(); @@ -221,7 +220,7 @@ public class QualityProfileDaoTest { public void get_by_name_and_language() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - QualityProfileDto dto = underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession()); + RulesProfileDto dto = underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession()); assertThat(dto.getId()).isEqualTo(1); assertThat(dto.getName()).isEqualTo("Sonar Way"); assertThat(dto.getLanguage()).isEqualTo("java"); @@ -235,9 +234,9 @@ public class QualityProfileDaoTest { public void get_by_name_and_languages() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - List<QualityProfileDto> dtos = underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("java"), dbTester.getSession()); + List<RulesProfileDto> dtos = underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("java"), dbTester.getSession()); assertThat(dtos).hasSize(1); - QualityProfileDto dto = dtos.iterator().next(); + RulesProfileDto dto = dtos.iterator().next(); assertThat(dto.getId()).isEqualTo(1); assertThat(dto.getName()).isEqualTo("Sonar Way"); assertThat(dto.getLanguage()).isEqualTo("java"); @@ -249,13 +248,13 @@ public class QualityProfileDaoTest { @Test public void should_find_by_language() { - QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto() + RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto() .setOrganizationUuid(organization.getUuid()); underTest.insert(dbSession, profile); - List<QualityProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage()); + List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage()); assertThat(results).hasSize(1); - QualityProfileDto result = results.get(0); + RulesProfileDto result = results.get(0); assertThat(result.getId()).isEqualTo(profile.getId()); assertThat(result.getName()).isEqualTo(profile.getName()); @@ -266,21 +265,21 @@ public class QualityProfileDaoTest { @Test public void should_not_find_by_language_in_wrong_organization() { - QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto() + RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto() .setOrganizationUuid(organization.getUuid()); underTest.insert(dbSession, profile); - List<QualityProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage()); + List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage()); assertThat(results).isEmpty(); } @Test public void should_not_find_by_language_with_wrong_language() { - QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto() + RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto() .setOrganizationUuid(organization.getUuid()); underTest.insert(dbSession, profile); - List<QualityProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language"); + List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language"); assertThat(results).isEmpty(); } @@ -288,17 +287,17 @@ public class QualityProfileDaoTest { public void find_children() { dbTester.prepareDbUnit(getClass(), "inheritance.xml"); - List<QualityProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent"); + List<RulesProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent"); assertThat(dtos).hasSize(2); - QualityProfileDto dto1 = dtos.get(0); + RulesProfileDto dto1 = dtos.get(0); assertThat(dto1.getId()).isEqualTo(1); assertThat(dto1.getName()).isEqualTo("Child1"); assertThat(dto1.getLanguage()).isEqualTo("java"); assertThat(dto1.getParentKee()).isEqualTo("java_parent"); - QualityProfileDto dto2 = dtos.get(1); + RulesProfileDto dto2 = dtos.get(1); assertThat(dto2.getId()).isEqualTo(2); assertThat(dto2.getName()).isEqualTo("Child2"); assertThat(dto2.getLanguage()).isEqualTo("java"); @@ -307,15 +306,15 @@ public class QualityProfileDaoTest { @Test public void countProjectsByProfileKey() { - QualityProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization); - QualityProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization); + RulesProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization); + RulesProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization); ComponentDto project1 = dbTester.components().insertPrivateProject(organization); ComponentDto project2 = dbTester.components().insertPrivateProject(organization); dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profileWithProjects); dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profileWithProjects); OrganizationDto otherOrg = dbTester.organizations().insert(); - QualityProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg); + RulesProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg); ComponentDto projectInOtherOrg = dbTester.components().insertPrivateProject(otherOrg); dbTester.qualityProfiles().associateProjectWithQualityProfile(projectInOtherOrg, profileInOtherOrg); @@ -327,7 +326,7 @@ public class QualityProfileDaoTest { public void select_by_project_key_and_language() { dbTester.prepareDbUnit(getClass(), "projects.xml"); - QualityProfileDto dto = underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "java"); + RulesProfileDto dto = underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "java"); assertThat(dto.getId()).isEqualTo(1); assertThat(underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "unkown")).isNull(); @@ -341,7 +340,7 @@ public class QualityProfileDaoTest { OrganizationDto organization = dbTester.organizations().insert(OrganizationTesting.newOrganizationDto().setUuid("org1")); ComponentDto project = dbTester.getDbClient().componentDao().selectOrFailByKey(dbTester.getSession(), "org.codehaus.sonar:sonar"); ComponentDto unknownProject = dbTester.components().insertPrivateProject(organization, p -> p.setKey("unknown")); - List<QualityProfileDto> dto = underTest.selectByProjectAndLanguages(dbTester.getSession(), organization, project, singletonList("java")); + List<RulesProfileDto> dto = underTest.selectByProjectAndLanguages(dbTester.getSession(), organization, project, singletonList("java")); assertThat(dto).extracting("id").containsOnly(1); assertThat(underTest.selectByProjectAndLanguages(dbTester.getSession(), organization, project, singletonList("unkown"))).isEmpty(); @@ -358,7 +357,7 @@ public class QualityProfileDaoTest { assertThat(underTest.selectByKey(dbSession, "qp-key-42")).isNull(); assertThat(underTest.selectByKeys(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42"))) .hasSize(2) - .extracting(QualityProfileDto::getKey).containsOnlyOnce("qp-key-1", "qp-key-3"); + .extracting(RulesProfileDto::getKey).containsOnlyOnce("qp-key-1", "qp-key-3"); assertThat(underTest.selectByKeys(dbSession, emptyList())).isEmpty(); } @@ -370,12 +369,12 @@ public class QualityProfileDaoTest { OrganizationDto organization2 = dbTester.organizations().insert(); ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid())); - QualityProfileDto profile1 = newQualityProfileDto(); + RulesProfileDto profile1 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile1); qualityProfileDb.associateProjectWithQualityProfile(project1, profile1); qualityProfileDb.associateProjectWithQualityProfile(project2, profile1); - QualityProfileDto profile2 = newQualityProfileDto(); + RulesProfileDto profile2 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile2); qualityProfileDb.associateProjectWithQualityProfile(project3, profile2); @@ -397,11 +396,11 @@ public class QualityProfileDaoTest { OrganizationDto organization2 = dbTester.organizations().insert(); ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid())); - QualityProfileDto profile1 = newQualityProfileDto(); + RulesProfileDto profile1 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile1); qualityProfileDb.associateProjectWithQualityProfile(project1, profile1); - QualityProfileDto profile2 = newQualityProfileDto(); + RulesProfileDto profile2 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile2); qualityProfileDb.associateProjectWithQualityProfile(project2, profile2); @@ -423,11 +422,11 @@ public class QualityProfileDaoTest { OrganizationDto organization2 = dbTester.organizations().insert(); ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid())); - QualityProfileDto profile1 = newQualityProfileDto(); + RulesProfileDto profile1 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile1); qualityProfileDb.associateProjectWithQualityProfile(project1, profile1); - QualityProfileDto profile2 = newQualityProfileDto(); + RulesProfileDto profile2 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile2); qualityProfileDb.associateProjectWithQualityProfile(project2, profile2); @@ -445,9 +444,9 @@ public class QualityProfileDaoTest { @Test public void update_project_profile_association() { ComponentDto project = dbTester.components().insertPrivateProject(); - QualityProfileDto profile1Language1 = insertQualityProfileDto("profile1", "Profile 1", "xoo"); - QualityProfileDto profile2Language2 = insertQualityProfileDto("profile2", "Profile 2", "xoo2"); - QualityProfileDto profile3Language1 = insertQualityProfileDto("profile3", "Profile 3", "xoo"); + RulesProfileDto profile1Language1 = insertQualityProfileDto("profile1", "Profile 1", "xoo"); + RulesProfileDto profile2Language2 = insertQualityProfileDto("profile2", "Profile 2", "xoo2"); + RulesProfileDto profile3Language1 = insertQualityProfileDto("profile3", "Profile 3", "xoo"); qualityProfileDb.associateProjectWithQualityProfile(project, profile1Language1, profile2Language2); underTest.updateProjectProfileAssociation(project.uuid(), profile3Language1.getKey(), profile1Language1.getKey(), dbSession); @@ -461,11 +460,11 @@ public class QualityProfileDaoTest { OrganizationDto org1 = dbTester.organizations().insert(); OrganizationDto org2 = dbTester.organizations().insert(); OrganizationDto org3 = dbTester.organizations().insert(); - QualityProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo")); - QualityProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo")); - QualityProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo")); - QualityProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo")); - QualityProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar")); + RulesProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo")); + RulesProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo")); + RulesProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo")); + RulesProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo")); + RulesProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar")); Collection<String> keys = underTest.selectOutdatedProfiles(dbSession, "java", "foo"); @@ -481,9 +480,9 @@ public class QualityProfileDaoTest { public void renameAndCommit_updates_name_of_specified_profiles() { OrganizationDto org1 = dbTester.organizations().insert(); OrganizationDto org2 = dbTester.organizations().insert(); - QualityProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p->p.setName("foo")); - QualityProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p->p.setName("foo")); - QualityProfileDto bar = dbTester.qualityProfiles().insert(org1, p->p.setName("bar")); + RulesProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p->p.setName("foo")); + RulesProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p->p.setName("foo")); + RulesProfileDto bar = dbTester.qualityProfiles().insert(org1, p->p.setName("bar")); underTest.renameAndCommit(dbSession, asList(fooInOrg1.getKee(), fooInOrg2.getKee()), "foo (copy)"); @@ -495,15 +494,15 @@ public class QualityProfileDaoTest { @Test public void renameAndCommit_does_nothing_if_empty_keys() { OrganizationDto org = dbTester.organizations().insert(); - QualityProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo")); + RulesProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo")); underTest.renameAndCommit(dbSession, Collections.emptyList(), "foo (copy)"); assertThat(underTest.selectOrFailByKey(dbSession, profile.getKey()).getName()).isEqualTo("foo"); } - private QualityProfileDto insertQualityProfileDto(String key, String name, String language) { - QualityProfileDto dto = QualityProfileDto.createFor(key) + private RulesProfileDto insertQualityProfileDto(String key, String name, String language) { + RulesProfileDto dto = RulesProfileDto.createFor(key) .setOrganizationUuid(organization.getUuid()) .setName(name) .setLanguage(language); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java index 42240eba66a..9c9b359e290 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java @@ -22,7 +22,6 @@ package org.sonar.db.qualityprofile; import java.util.Arrays; import java.util.Optional; import java.util.function.Consumer; -import org.apache.commons.lang.math.RandomUtils; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -44,7 +43,7 @@ public class QualityProfileDbTester { this.dbSession = dbTester.getSession(); } - public Optional<QualityProfileDto> selectByKey(String key) { + public Optional<RulesProfileDto> selectByKey(String key) { return Optional.ofNullable(dbClient.qualityProfileDao().selectByKey(dbSession, key)); } @@ -52,10 +51,8 @@ public class QualityProfileDbTester { * Create a profile with random field values on the specified organization. */ @SafeVarargs - public final QualityProfileDto insert(OrganizationDto organization, Consumer<QualityProfileDto>... consumers) { - QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto() - // default is not randomized yet in QualityProfileTesting - .setDefault(RandomUtils.nextBoolean()) + public final RulesProfileDto insert(OrganizationDto organization, Consumer<RulesProfileDto>... consumers) { + RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto() .setOrganizationUuid(organization.getUuid()); Arrays.stream(consumers).forEach(c -> c.accept(profile)); @@ -64,34 +61,34 @@ public class QualityProfileDbTester { return profile; } - public void insertQualityProfiles(QualityProfileDto qualityProfile, QualityProfileDto... qualityProfiles) { + public void insertQualityProfiles(RulesProfileDto qualityProfile, RulesProfileDto... qualityProfiles) { dbClient.qualityProfileDao().insert(dbSession, qualityProfile, qualityProfiles); dbSession.commit(); } - public QualityProfileDto insertQualityProfile(QualityProfileDto qualityProfile) { + public RulesProfileDto insertQualityProfile(RulesProfileDto qualityProfile) { dbClient.qualityProfileDao().insert(dbSession, qualityProfile); dbSession.commit(); return qualityProfile; } - public void insertProjectWithQualityProfileAssociations(ComponentDto project, QualityProfileDto... qualityProfiles) { + public void insertProjectWithQualityProfileAssociations(ComponentDto project, RulesProfileDto... qualityProfiles) { dbClient.componentDao().insert(dbSession, project); - for (QualityProfileDto qualityProfile : qualityProfiles) { + for (RulesProfileDto qualityProfile : qualityProfiles) { dbClient.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession); } dbSession.commit(); } - public void associateProjectWithQualityProfile(ComponentDto project, QualityProfileDto... qualityProfiles) { - for (QualityProfileDto qualityProfile : qualityProfiles) { + public void associateProjectWithQualityProfile(ComponentDto project, RulesProfileDto... qualityProfiles) { + for (RulesProfileDto qualityProfile : qualityProfiles) { dbClient.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession); } dbSession.commit(); } @SafeVarargs - public final ActiveRuleDto activateRule(QualityProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto>... consumers) { + public final ActiveRuleDto activateRule(RulesProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto>... consumers) { ActiveRuleDto activeRule = createFor(profile, rule).setSeverity(MAJOR); for (Consumer<ActiveRuleDto> consumer : consumers) { consumer.accept(activeRule); @@ -101,12 +98,15 @@ public class QualityProfileDbTester { return activeRule; } - public void markAsDefault(QualityProfileDto profile) { - DefaultQProfileDto dto = new DefaultQProfileDto() - .setOrganizationUuid(profile.getOrganizationUuid()) - .setLanguage(profile.getLanguage()) - .setQProfileUuid(profile.getKee()); - dbClient.defaultQProfileDao().insertOrUpdate(dbSession, dto); + public void markAsDefault(RulesProfileDto... profiles) { + for (RulesProfileDto profile : profiles) { + DefaultQProfileDto dto = new DefaultQProfileDto() + .setOrganizationUuid(profile.getOrganizationUuid()) + .setLanguage(profile.getLanguage()) + .setQProfileUuid(profile.getKee()); + dbClient.defaultQProfileDao().insertOrUpdate(dbSession, dto); + } + dbSession.commit(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java index 20538cc463f..5a1e7638dcf 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java @@ -30,9 +30,9 @@ import static org.apache.commons.lang.math.RandomUtils.nextLong; public class QualityProfileTesting { - public static QualityProfileDto newQualityProfileDto() { + public static RulesProfileDto newQualityProfileDto() { String uuid = Uuids.createFast(); - QualityProfileDto dto = QualityProfileDto.createFor(uuid) + RulesProfileDto dto = RulesProfileDto.createFor(uuid) .setOrganizationUuid(randomAlphanumeric(40)) .setName(uuid) .setLanguage(randomAlphanumeric(20)) diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml index 7bd904cf663..691735eb14d 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml @@ -7,7 +7,6 @@ parent_kee="[null]" kee="js_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml index 877fe21aacc..8f063f02d18 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml @@ -6,7 +6,6 @@ organization_uuid="org-123" parent_kee="java_parent" kee="java_child1" - is_default="[false]" is_built_in="[false]" rules_updated_at="[null]" created_at="[null]" @@ -18,7 +17,6 @@ organization_uuid="org-123" parent_kee="java_parent" kee="java_child2" - is_default="[false]" is_built_in="[false]" rules_updated_at="[null]" created_at="[null]" @@ -30,7 +28,6 @@ organization_uuid="org-123" parent_kee="[null]" kee="java_parent" - is_default="[false]" is_built_in="[false]" rules_updated_at="[null]" created_at="[null]" @@ -45,7 +42,6 @@ parent_kee="js_parent" kee="js_child1" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -57,7 +53,6 @@ parent_kee="js_parent" kee="js_child2" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -69,7 +64,6 @@ parent_kee="[null]" kee="js_parent" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml index c052ce63284..1e4b2849681 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml @@ -7,7 +7,6 @@ parent_kee="[null]" kee="java_sonar_way" is_built_in="[true]" - is_default="[true]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" @@ -21,7 +20,6 @@ parent_kee="[null]" kee="js_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" @@ -35,7 +33,6 @@ parent_kee="[null]" kee="abcde" is_built_in="[true]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml index 61841606e51..2b1a2bf6aa8 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml @@ -7,7 +7,6 @@ parent_kee="[null]" kee="java_sonar_way" is_built_in="[false]" - is_default="[true]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -18,7 +17,6 @@ parent_kee="[null]" kee="js_sonar_way" is_built_in="[false]" - is_default="[true]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml index af11713dc4d..42c8a4f64ab 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml @@ -7,7 +7,6 @@ parent_kee="[null]" kee="js_third" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -19,7 +18,6 @@ parent_kee="[null]" kee="js_first" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -31,7 +29,6 @@ parent_kee="[null]" kee="js_second" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml index 0411f9f6a60..3d5814908ca 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml @@ -7,7 +7,6 @@ parent_kee="[null]" kee="java_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -19,7 +18,6 @@ parent_kee="[null]" kee="js_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> @@ -31,7 +29,6 @@ parent_kee="[null]" kee="java_sonar_way2" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml index bd3c86accd7..7872802c029 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml @@ -7,7 +7,6 @@ parent_kee="[null]" kee="java_sonar_way" is_built_in="[true]" - is_default="[true]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" @@ -21,11 +20,18 @@ parent_kee="[null]" kee="js_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/> + <default_qprofiles + organization_uuid="QualityProfileDaoTest-ORG" + language="java" + qprofile_uuid="java_sonar_way" + created_at="1000" + updated_at="2000" + /> + </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml index 7bff78801ee..d37e24c2e62 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml @@ -7,7 +7,6 @@ parent_kee="fghij" kee="java_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" @@ -21,7 +20,6 @@ parent_kee="[null]" kee="js_sonar_way" is_built_in="[false]" - is_default="[false]" rules_updated_at="[null]" created_at="[null]" updated_at="[null]" |