aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-05-31 10:59:33 +0200
committerEric Hartmann <hartmann.eric@gmail.com>2017-06-14 15:43:12 +0200
commit3e26c9b9b44ebabbc2c81e134c26799ce3f4bc3b (patch)
tree548b40695d3fb85cdcd42c889bb1ae470cbbbb14 /server
parentd4133c63eb8e7b6acc54195da3206f1b3a5f7689 (diff)
downloadsonarqube-3e26c9b9b44ebabbc2c81e134c26799ce3f4bc3b.tar.gz
sonarqube-3e26c9b9b44ebabbc2c81e134c26799ce3f4bc3b.zip
SONAR-9304 rename table qprofiles to org_qprofiles
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java6
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl7
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java (renamed from server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java)32
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java120
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java55
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml36
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml12
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml429
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java38
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java548
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java88
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java28
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml16
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml71
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml43
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml37
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml36
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml37
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml28
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java)27
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfiles.java)22
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java (renamed from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java)11
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java (renamed from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest.java)22
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql (renamed from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql)0
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql15
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql (renamed from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest/initial.sql)5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java34
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java32
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java23
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java20
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java38
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java32
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java70
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java107
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java44
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java21
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java42
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogLoaderTest.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java24
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java34
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java57
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java40
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java32
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java42
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java32
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java36
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RestoreActionTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java72
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java25
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/AppActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleQueryFactoryTest.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java6
139 files changed, 1746 insertions, 1728 deletions
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
index 7e23cf9dd70..c86a1b6a92c 100644
--- a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
+++ b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
@@ -68,19 +68,19 @@ public final class SqTables {
"notifications",
"organizations",
"organization_members",
+ "org_qprofiles",
"permission_templates",
"perm_templates_users",
"perm_templates_groups",
"perm_tpl_characteristics",
- "quality_gates",
- "quality_gate_conditions",
"projects",
"project_links",
"project_measures",
"project_qprofiles",
"properties",
"qprofile_changes",
- "qprofiles",
+ "quality_gates",
+ "quality_gate_conditions",
"rules",
"rules_metadata",
"rules_parameters",
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
index 21791997147..eda17e61f32 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -47,9 +47,7 @@ CREATE TABLE "RULES_PROFILES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
- "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"KEE" VARCHAR(255) NOT NULL,
- "PARENT_KEE" VARCHAR(255),
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
@@ -60,7 +58,7 @@ CREATE TABLE "RULES_PROFILES" (
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
-CREATE TABLE "QPROFILES" (
+CREATE TABLE "ORG_QPROFILES" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
@@ -68,7 +66,8 @@ CREATE TABLE "QPROFILES" (
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
-CREATE INDEX "QPROFILES_ORG_UUID" ON "QPROFILES" ("ORGANIZATION_UUID");
+CREATE INDEX "ORG_QPROFILES_ORG_UUID" ON "ORG_QPROFILES" ("ORGANIZATION_UUID");
+CREATE INDEX "ORG_QPROFILES_RP_UUID" ON "ORG_QPROFILES" ("RULES_PROFILE_UUID");
CREATE TABLE "DEFAULT_QPROFILES" (
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 d55857343c3..e99aec847ea 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,6 @@ 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.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileMapper;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleMapper;
@@ -166,7 +165,6 @@ public class MyBatis implements Startable {
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class);
confBuilder.loadAlias("QualityGate", QualityGateDto.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 ff3719a8810..415c17564ec 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(RulesProfileDto profileDto, RuleDefinitionDto ruleDto) {
+ public static ActiveRuleDto createFor(QProfileDto 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 e97e7803665..4474af22cf9 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(RulesProfileDto profile) {
+ public static DefaultQProfileDto from(QProfileDto profile) {
return new DefaultQProfileDto()
.setOrganizationUuid(profile.getOrganizationUuid())
.setLanguage(profile.getLanguage())
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java
index b98e7b24d29..783f1580563 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java
@@ -40,9 +40,7 @@ public class QProfileChangeDao implements Dao {
}
public void insert(DbSession dbSession, QProfileChangeDto dto) {
- checkState(dto.getKey() == null, "Key of QProfileChangeDto must be set by DAO only. Got %s.", dto.getKey());
checkState(dto.getCreatedAt() == 0L, "Date of QProfileChangeDto must be set by DAO only. Got %s.", dto.getCreatedAt());
-
dto.setKey(uuidFactory.create());
dto.setCreatedAt(system2.now());
mapper(dbSession).insert(dto);
@@ -52,13 +50,13 @@ public class QProfileChangeDao implements Dao {
return mapper(dbSession).selectByQuery(query);
}
- public int countForProfileKey(DbSession dbSession, String profileKey) {
- return mapper(dbSession).countForProfileKey(profileKey);
+ public int countForProfileUuid(DbSession dbSession, String profileUuid) {
+ return mapper(dbSession).countForProfileUuid(profileUuid);
}
- public void deleteByProfileKeys(DbSession dbSession, Collection<String> profileKeys) {
+ public void deleteByProfileKeys(DbSession dbSession, Collection<String> profileUuids) {
QProfileChangeMapper mapper = mapper(dbSession);
- DatabaseUtils.executeLargeUpdates(profileKeys, mapper::deleteByProfileKeys);
+ DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteByProfileUuids);
}
private static QProfileChangeMapper mapper(DbSession dbSession) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java
index 24d46605d9e..6d14638fcd2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java
@@ -29,7 +29,7 @@ public interface QProfileChangeMapper {
List<QProfileChangeDto> selectByQuery(@Param("query") QProfileChangeQuery query);
- int countForProfileKey(@Param("profileKey") String profileKey);
+ int countForProfileUuid(@Param("profileUuid") String profileUuid);
- void deleteByProfileKeys(@Param("profileKeys") Collection<String> profileKeys);
+ void deleteByProfileUuids(@Param("profileUuids") Collection<String> profileUuids);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java
index 8bbcbd88584..8de9d798c0f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java
@@ -28,18 +28,18 @@ import static java.util.Objects.requireNonNull;
public class QProfileChangeQuery {
- private final String profileKey;
+ private final String profileUuid;
private Long fromIncluded;
private Long toExcluded;
private int offset = 0;
private int limit = 100;
- public QProfileChangeQuery(String profileKey) {
- this.profileKey = requireNonNull(profileKey);
+ public QProfileChangeQuery(String profileUuid) {
+ this.profileUuid = requireNonNull(profileUuid);
}
- public String getProfileKey() {
- return profileKey;
+ public String getProfileUuid() {
+ return profileUuid;
}
@CheckForNull
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
index 0afffd0f7aa..92f47a6d3c0 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
@@ -26,9 +26,9 @@ import org.sonar.core.util.UtcDateUtils;
import org.sonar.db.organization.OrganizationDto;
/**
- * Represents the table "rules_profiles"
+ * Represents the join of "org_qprofiles" and "rules_profiles"
*/
-public class RulesProfileDto {
+public class QProfileDto {
private Integer id;
/**
@@ -50,12 +50,12 @@ public class RulesProfileDto {
return organizationUuid;
}
- public RulesProfileDto setOrganizationUuid(String organizationUuid) {
+ public QProfileDto setOrganizationUuid(String organizationUuid) {
this.organizationUuid = organizationUuid;
return this;
}
- public RulesProfileDto setKey(String s) {
+ public QProfileDto setKey(String s) {
return setKee(s);
}
@@ -63,7 +63,7 @@ public class RulesProfileDto {
return kee;
}
- public RulesProfileDto setKee(String s) {
+ public QProfileDto setKee(String s) {
this.kee = s;
return this;
}
@@ -72,7 +72,7 @@ public class RulesProfileDto {
return id;
}
- public RulesProfileDto setId(Integer id) {
+ public QProfileDto setId(Integer id) {
this.id = id;
return this;
}
@@ -81,7 +81,7 @@ public class RulesProfileDto {
return name;
}
- public RulesProfileDto setName(String name) {
+ public QProfileDto setName(String name) {
this.name = name;
return this;
}
@@ -90,7 +90,7 @@ public class RulesProfileDto {
return language;
}
- public RulesProfileDto setLanguage(String language) {
+ public QProfileDto setLanguage(String language) {
this.language = language;
return this;
}
@@ -100,7 +100,7 @@ public class RulesProfileDto {
return parentKee;
}
- public RulesProfileDto setParentKee(@Nullable String s) {
+ public QProfileDto setParentKee(@Nullable String s) {
this.parentKee = s;
return this;
}
@@ -109,12 +109,12 @@ public class RulesProfileDto {
return rulesUpdatedAt;
}
- public RulesProfileDto setRulesUpdatedAt(String s) {
+ public QProfileDto setRulesUpdatedAt(String s) {
this.rulesUpdatedAt = s;
return this;
}
- public RulesProfileDto setRulesUpdatedAtAsDate(Date d) {
+ public QProfileDto setRulesUpdatedAtAsDate(Date d) {
this.rulesUpdatedAt = UtcDateUtils.formatDateTime(d);
return this;
}
@@ -124,7 +124,7 @@ public class RulesProfileDto {
return lastUsed;
}
- public RulesProfileDto setLastUsed(@Nullable Long lastUsed) {
+ public QProfileDto setLastUsed(@Nullable Long lastUsed) {
this.lastUsed = lastUsed;
return this;
}
@@ -134,7 +134,7 @@ public class RulesProfileDto {
return userUpdatedAt;
}
- public RulesProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
+ public QProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
this.userUpdatedAt = userUpdatedAt;
return this;
}
@@ -143,12 +143,12 @@ public class RulesProfileDto {
return isBuiltIn;
}
- public RulesProfileDto setIsBuiltIn(boolean b) {
+ public QProfileDto setIsBuiltIn(boolean b) {
this.isBuiltIn = b;
return this;
}
- public static RulesProfileDto createFor(String key) {
- return new RulesProfileDto().setKee(key);
+ public static QProfileDto createFor(String key) {
+ return new QProfileDto().setKee(key);
}
}
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 7dd416bd086..e23cc4d980a 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
@@ -20,7 +20,7 @@
package org.sonar.db.qualityprofile;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -49,84 +49,87 @@ public class QualityProfileDao implements Dao {
}
@CheckForNull
- public RulesProfileDto selectByKey(DbSession session, String key) {
- return mapper(session).selectByKey(key);
+ public QProfileDto selectByUuid(DbSession session, String uuid) {
+ return mapper(session).selectByUuid(uuid);
}
- public RulesProfileDto selectOrFailByKey(DbSession session, String key) {
- RulesProfileDto dto = selectByKey(session, key);
+ public QProfileDto selectOrFailByUuid(DbSession session, String uuid) {
+ QProfileDto dto = selectByUuid(session, uuid);
if (dto == null) {
- throw new RowNotFoundException("Quality profile not found: " + key);
+ throw new RowNotFoundException("Quality profile not found: " + uuid);
}
return dto;
}
- public List<RulesProfileDto> selectByKeys(DbSession session, List<String> keys) {
- return executeLargeInputs(keys, mapper(session)::selectByKeys);
+ public List<QProfileDto> selectByUuids(DbSession session, List<String> uuids) {
+ return executeLargeInputs(uuids, mapper(session)::selectByUuids);
}
- public List<RulesProfileDto> selectAll(DbSession session, OrganizationDto organization) {
+ public List<QProfileDto> selectAll(DbSession session, OrganizationDto organization) {
return mapper(session).selectAll(organization.getUuid());
}
- public void insert(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) {
+ public void insert(DbSession session, QProfileDto profile, QProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(session);
doInsert(mapper, profile);
- for (RulesProfileDto other : otherProfiles) {
+ for (QProfileDto other : otherProfiles) {
doInsert(mapper, other);
}
}
- private void doInsert(QualityProfileMapper mapper, RulesProfileDto profile) {
+ private void doInsert(QualityProfileMapper mapper, QProfileDto profile) {
Preconditions.checkArgument(profile.getId() == null, "Quality profile is already persisted (got id %d)", profile.getId());
- mapper.insert(profile, new Date(system.now()));
+ long now = system.now();
+ mapper.insertRulesProfile(profile, new Date(now));
+ mapper.insertOrgQProfile(profile, now);
}
- public void update(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) {
+ public void update(DbSession session, QProfileDto profile, QProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(session);
- doUpdate(mapper, profile);
- for (RulesProfileDto otherProfile : otherProfiles) {
- doUpdate(mapper, otherProfile);
+ long now = system.now();
+ doUpdate(mapper, profile, now);
+ for (QProfileDto otherProfile : otherProfiles) {
+ doUpdate(mapper, otherProfile, now);
}
}
- private void doUpdate(QualityProfileMapper mapper, RulesProfileDto profile) {
- Preconditions.checkArgument(profile.getId() != null, "Quality profile is not persisted");
- mapper.update(profile, new Date(system.now()));
+ private void doUpdate(QualityProfileMapper mapper, QProfileDto profile, long now) {
+ mapper.updateRulesProfile(profile, new Date(now));
+ mapper.updateOrgQProfile(profile, now);
}
- public List<RulesProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languageKeys) {
- return mapper(session).selectDefaultProfiles(organization.getUuid(), languageKeys);
+ public List<QProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languages) {
+ return mapper(session).selectDefaultProfiles(organization.getUuid(), languages);
}
@CheckForNull
- public RulesProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) {
+ public QProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) {
return mapper(session).selectDefaultProfile(organization.getUuid(), language);
}
@CheckForNull
- public RulesProfileDto selectAssociatedToProjectAndLanguage(DbSession session, ComponentDto project, String language) {
+ public QProfileDto selectAssociatedToProjectAndLanguage(DbSession session, ComponentDto project, String language) {
return mapper(session).selectAssociatedToProjectUuidAndLanguage(project.getOrganizationUuid(), project.projectUuid(), language);
}
- public List<RulesProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession session, ComponentDto project, Collection<String> languages) {
+ public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession session, ComponentDto project, Collection<String> languages) {
return mapper(session).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), languages);
}
- public List<RulesProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
+ public List<QProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
return mapper(dbSession).selectByLanguage(organization.getUuid(), language);
}
- public List<RulesProfileDto> selectChildren(DbSession session, String key) {
- return mapper(session).selectChildren(key);
+ public List<QProfileDto> selectChildren(DbSession session, String uuid) {
+ return mapper(session).selectChildren(uuid);
}
/**
* All descendants, in the top-down order.
*/
- public List<RulesProfileDto> selectDescendants(DbSession session, String key) {
- List<RulesProfileDto> descendants = Lists.newArrayList();
- for (RulesProfileDto child : selectChildren(session, key)) {
+ public List<QProfileDto> selectDescendants(DbSession session, String uuid) {
+ List<QProfileDto> descendants = new ArrayList<>();
+ for (QProfileDto child : selectChildren(session, uuid)) {
descendants.add(child);
descendants.addAll(selectDescendants(session, child.getKee()));
}
@@ -134,63 +137,69 @@ public class QualityProfileDao implements Dao {
}
@CheckForNull
- public RulesProfileDto selectByNameAndLanguage(OrganizationDto organization, String name, String language, DbSession session) {
+ public QProfileDto selectByNameAndLanguage(DbSession session, OrganizationDto organization, String name, String language) {
return mapper(session).selectByNameAndLanguage(organization.getUuid(), name, language);
}
- public List<RulesProfileDto> selectByNameAndLanguages(OrganizationDto organization, String name, Collection<String> languageKeys, DbSession session) {
- return mapper(session).selectByNameAndLanguages(organization.getUuid(), name, languageKeys);
+ public List<QProfileDto> selectByNameAndLanguages(DbSession session, OrganizationDto organization, String name, Collection<String> languages) {
+ return mapper(session).selectByNameAndLanguages(organization.getUuid(), name, languages);
}
- public Map<String, Long> countProjectsByProfileKey(DbSession dbSession, OrganizationDto organization) {
- return KeyLongValue.toMap(mapper(dbSession).countProjectsByProfileKey(organization.getUuid()));
+ public Map<String, Long> countProjectsByProfileUuid(DbSession dbSession, OrganizationDto organization) {
+ return KeyLongValue.toMap(mapper(dbSession).countProjectsByProfileUuid(organization.getUuid()));
}
- public void insertProjectProfileAssociation(DbSession dbSession, ComponentDto project, RulesProfileDto profile) {
+ public void insertProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) {
mapper(dbSession).insertProjectProfileAssociation(project.uuid(), profile.getKee());
}
- public void deleteProjectProfileAssociation(DbSession dbSession, ComponentDto project, RulesProfileDto profile) {
+ public void deleteProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) {
mapper(dbSession).deleteProjectProfileAssociation(project.uuid(), profile.getKee());
}
- public void updateProjectProfileAssociation(DbSession dbSession, ComponentDto project, String newProfileKey, String oldProfileKey) {
- mapper(dbSession).updateProjectProfileAssociation(project.uuid(), newProfileKey, oldProfileKey);
+ public void updateProjectProfileAssociation(DbSession dbSession, ComponentDto project, String newProfileUuid, String oldProfileUuid) {
+ mapper(dbSession).updateProjectProfileAssociation(project.uuid(), newProfileUuid, oldProfileUuid);
}
- public void deleteProjectAssociationsByProfileKeys(DbSession dbSession, Collection<String> profileKeys) {
+ public void deleteProjectAssociationsByProfileUuids(DbSession dbSession, Collection<String> profileUuids) {
QualityProfileMapper mapper = mapper(dbSession);
- DatabaseUtils.executeLargeUpdates(profileKeys, mapper::deleteProjectAssociationByProfileKeys);
+ DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteProjectAssociationByProfileUuids);
}
- public List<ProjectQprofileAssociationDto> selectSelectedProjects(OrganizationDto organization, String profileKey, @Nullable String query, DbSession session) {
+ public List<ProjectQprofileAssociationDto> selectSelectedProjects(DbSession session, OrganizationDto organization, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
- return mapper(session).selectSelectedProjects(organization.getUuid(), profileKey, nameQuery);
+ return mapper(session).selectSelectedProjects(organization.getUuid(), profile.getKee(), nameQuery);
}
- public List<ProjectQprofileAssociationDto> selectDeselectedProjects(OrganizationDto organization, String profileKey, @Nullable String query, DbSession session) {
+ public List<ProjectQprofileAssociationDto> selectDeselectedProjects(DbSession session, OrganizationDto organization, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
- return mapper(session).selectDeselectedProjects(organization.getUuid(), profileKey, nameQuery);
+ return mapper(session).selectDeselectedProjects(organization.getUuid(), profile.getKee(), nameQuery);
}
- public List<ProjectQprofileAssociationDto> selectProjectAssociations(OrganizationDto organization, String profileKey, @Nullable String query, DbSession session) {
+ public List<ProjectQprofileAssociationDto> selectProjectAssociations(DbSession session, OrganizationDto organization, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
- return mapper(session).selectProjectAssociations(organization.getUuid(), profileKey, nameQuery);
+ return mapper(session).selectProjectAssociations(organization.getUuid(), profile.getKee(), nameQuery);
}
- public Collection<String> selectOutdatedProfiles(DbSession dbSession, String language, String name) {
- return mapper(dbSession).selectOutdatedProfiles(language, name);
+ public Collection<String> selectUuidsOfCustomRulesProfiles(DbSession dbSession, String language, String name) {
+ return mapper(dbSession).selectUuidsOfCustomQProfiles(language, name);
}
- public void renameAndCommit(DbSession dbSession, Collection<String> keys, String newName) {
+ public void renameRulesProfilesAndCommit(DbSession dbSession, Collection<String> rulesProfileUuids, String newName) {
QualityProfileMapper mapper = mapper(dbSession);
Date now = new Date(system.now());
- executeLargeUpdates(keys, partition -> {
- mapper.rename(newName, now, partition);
+ executeLargeUpdates(rulesProfileUuids, partition -> {
+ mapper.renameRulesProfiles(newName, now, partition);
dbSession.commit();
});
}
+ public void deleteByUuids(DbSession dbSession, Collection<String> profileUuids) {
+ QualityProfileMapper mapper = mapper(dbSession);
+ DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteOrgQProfilesByUuids);
+ DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteRulesProfilesByUuids);
+ }
+
private static String sqlQueryString(@Nullable String query) {
if (query == null) {
return "%";
@@ -201,9 +210,4 @@ public class QualityProfileDao implements Dao {
private static QualityProfileMapper mapper(DbSession session) {
return session.getMapper(QualityProfileMapper.class);
}
-
- public void deleteByKeys(DbSession dbSession, Collection<String> profileKeys) {
- QualityProfileMapper mapper = mapper(dbSession);
- DatabaseUtils.executeLargeUpdates(profileKeys, mapper::deleteByKeys);
- }
}
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 9a514215385..cf289bc2ce9 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,51 +28,62 @@ import org.sonar.db.KeyLongValue;
public interface QualityProfileMapper {
- void insert(@Param("dto") RulesProfileDto dto, @Param("now") Date now);
+ void insertOrgQProfile(@Param("dto") QProfileDto dto, @Param("now") long now);
- void update(@Param("dto") RulesProfileDto dto, @Param("now") Date now);
+ void insertRulesProfile(@Param("dto") QProfileDto dto, @Param("now") Date now);
- void deleteByKeys(@Param("profileKeys") Collection<String> profileKeys);
+ void updateRulesProfile(@Param("dto") QProfileDto dto, @Param("now") Date now);
- List<RulesProfileDto> selectAll(@Param("organizationUuid") String organizationUuid);
+ void updateOrgQProfile(@Param("dto") QProfileDto dto, @Param("now") long now);
+
+ void deleteRulesProfilesByUuids(@Param("uuids") Collection<String> uuids);
+
+ void deleteOrgQProfilesByUuids(@Param("uuids") Collection<String> uuids);
+
+ List<QProfileDto> selectAll(@Param("organizationUuid") String organizationUuid);
@CheckForNull
- RulesProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
+ QProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
- List<RulesProfileDto> selectDefaultProfiles(
+ List<QProfileDto> selectDefaultProfiles(
@Param("organizationUuid") String organizationUuid,
@Param("languages") Collection<String> languages);
@CheckForNull
- RulesProfileDto selectByNameAndLanguage(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("language") String language);
+ QProfileDto selectByNameAndLanguage(
+ @Param("organizationUuid") String organizationUuid,
+ @Param("name") String name,
+ @Param("language") String language);
- List<RulesProfileDto> selectByNameAndLanguages(
+ List<QProfileDto> selectByNameAndLanguages(
@Param("organizationUuid") String organizationUuid,
@Param("name") String name,
@Param("languages") Collection<String> languages);
@CheckForNull
- RulesProfileDto selectByKey(String key);
+ QProfileDto selectByUuid(String uuid);
- List<RulesProfileDto> selectByLanguage(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
+ List<QProfileDto> selectByUuids(@Param("uuids") Collection<String> uuids);
- List<RulesProfileDto> selectByKeys(@Param("keys") List<String> keys);
+ List<QProfileDto> selectByLanguage(
+ @Param("organizationUuid") String organizationUuid,
+ @Param("language") String language);
// INHERITANCE
- List<RulesProfileDto> selectChildren(String key);
+ List<QProfileDto> selectChildren(String uuid);
// PROJECTS
- List<KeyLongValue> countProjectsByProfileKey(@Param("organizationUuid") String organizationUuid);
+ List<KeyLongValue> countProjectsByProfileUuid(@Param("organizationUuid") String organizationUuid);
@CheckForNull
- RulesProfileDto selectAssociatedToProjectUuidAndLanguage(
+ QProfileDto selectAssociatedToProjectUuidAndLanguage(
@Param("organizationUuid") String organizationUuid,
@Param("projectUuid") String projectUuid,
@Param("language") String language);
- List<RulesProfileDto> selectAssociatedToProjectUuidAndLanguages(
+ List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(
@Param("organizationUuid") String organizationUuid,
@Param("projectUuid") String projectUuid,
@Param("languages") Collection<String> languages);
@@ -86,26 +97,26 @@ public interface QualityProfileMapper {
@Param("profileUuid") String profileUuid,
@Param("oldProfileUuid") String oldProfileUuid);
- void deleteProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileKey") String profileKey);
+ void deleteProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileUuid") String profileUuid);
- void deleteProjectAssociationByProfileKeys(@Param("profileKeys") Collection<String> profileKeys);
+ void deleteProjectAssociationByProfileUuids(@Param("profileUuids") Collection<String> profileUuids);
List<ProjectQprofileAssociationDto> selectSelectedProjects(
@Param("organizationUuid") String organizationUuid,
- @Param("profileKey") String profileKey,
+ @Param("profileUuid") String profileUuid,
@Param("nameQuery") String nameQuery);
List<ProjectQprofileAssociationDto> selectDeselectedProjects(
@Param("organizationUuid") String organizationUuid,
- @Param("profileKey") String profileKey,
+ @Param("profileUuid") String profileUuid,
@Param("nameQuery") String nameQuery);
List<ProjectQprofileAssociationDto> selectProjectAssociations(
@Param("organizationUuid") String organizationUuid,
- @Param("profileKey") String profileKey,
+ @Param("profileUuid") String profileUuid,
@Param("nameQuery") String nameQuery);
- List<String> selectOutdatedProfiles(@Param("language") String language, @Param("name") String name);
+ List<String> selectUuidsOfCustomQProfiles(@Param("language") String language, @Param("name") String name);
- void rename(@Param("newName") String newName, @Param("updatedAt") Date updatedAt, @Param("profileKeys") Collection<String> profileKeys);
+ void renameRulesProfiles(@Param("newName") String newName, @Param("updatedAt") Date updatedAt, @Param("uuids") Collection<String> uuids);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index feacf5db7a3..5d80727e51e 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -135,7 +135,8 @@
from organizations org
where not exists (
select 1 from rules_profiles p
- where p.organization_uuid = org.uuid
+ inner join org_qprofiles oqp on oqp.rules_profile_uuid = p.kee
+ where oqp.organization_uuid = org.uuid
and p.language = #{profileLanguage, jdbcType=VARCHAR}
and p.name = #{profileName, jdbcType=VARCHAR}
)
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
index 463c29de8ac..51d24aaf0f5 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
@@ -17,8 +17,9 @@
</sql>
<sql id="activeRuleKeyJoin">
- INNER JOIN rules_profiles qp ON qp.id=a.profile_id
- INNER JOIN rules r ON r.id = a.rule_id
+ inner join rules_profiles qp on qp.id=a.profile_id
+ inner join org_qprofiles oqp on oqp.rules_profile_uuid = qp.kee
+ inner join rules r on r.id = a.rule_id
</sql>
<insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
@@ -88,7 +89,7 @@
FROM active_rules a
<include refid="activeRuleKeyJoin"/>
WHERE a.rule_id=#{ruleId, jdbcType=BIGINT}
- AND qp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
+ AND oqp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
</select>
<select id="selectByRuleIdOfAllOrganizations" parameterType="Integer" resultType="ActiveRule">
@@ -109,7 +110,7 @@
<foreach collection="ruleIds" item="ruleId" separator="," open="(" close=")">
#{ruleId}
</foreach>
- AND qp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
+ AND oqp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
</select>
<!-- Parameters -->
@@ -191,34 +192,37 @@
</select>
<select id="countActiveRulesByProfileKey" resultType="KeyLongValue" parameterType="map">
- select p.kee as "key", count(ar.id) as "value"
+ select rp.kee as "key", count(ar.id) as "value"
from active_rules ar
- inner join rules_profiles p on p.id = ar.profile_id
+ inner join rules_profiles rp on rp.id = ar.profile_id
+ inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules r on r.id = ar.rule_id
- where p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ where oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and r.status != 'REMOVED'
- group by p.kee
+ group by rp.kee
</select>
<select id="countActiveRulesForRuleStatusByProfileKey" resultType="KeyLongValue" parameterType="map">
- select p.kee as "key", count(ar.id) as "value"
+ select rp.kee as "key", count(ar.id) as "value"
from active_rules ar
- inner join rules_profiles p on p.id = ar.profile_id
+ inner join rules_profiles rp on rp.id = ar.profile_id
+ inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules r on r.id = ar.rule_id
- where p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ where oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and r.status = #{ruleStatus, jdbcType=VARCHAR}
- group by p.kee
+ group by rp.kee
</select>
<select id="countActiveRulesForInheritanceByProfileKey" resultType="KeyLongValue" parameterType="map">
- select p.kee as "key", count(ar.id) as "value"
+ select rp.kee as "key", count(ar.id) as "value"
from active_rules ar
- inner join rules_profiles p on p.id = ar.profile_id
+ inner join rules_profiles rp on rp.id = ar.profile_id
+ inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules r on r.id = ar.rule_id
- where p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ where oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and ar.inheritance = #{inheritance, jdbcType=VARCHAR}
and r.status != 'REMOVED'
- group by p.kee
+ group by rp.kee
</select>
</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml
index 728614064df..ddd345a3f32 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml
@@ -22,9 +22,9 @@
)
</insert>
- <select id="countForProfileKey" resultType="int">
+ <select id="countForProfileUuid" resultType="int">
select count(kee) from qprofile_changes
- where qprofile_key = #{profileKey}
+ where qprofile_key = #{profileUuid, jdbcType=VARCHAR}
</select>
<select id="selectByQuery" resultType="org.sonar.db.qualityprofile.QProfileChangeDto">
@@ -61,7 +61,7 @@
<sql id="sqlSelectByQuery">
select <include refid="sqlColumns" />
from qprofile_changes
- where qprofile_key = #{query.profileKey}
+ where qprofile_key = #{query.profileUuid, jdbcType=VARCHAR}
<if test="query.fromIncluded != null">
and created_at &gt;= #{query.fromIncluded}
</if>
@@ -71,11 +71,11 @@
order by created_at desc
</sql>
- <delete id="deleteByProfileKeys" parameterType="String">
+ <delete id="deleteByProfileUuids" parameterType="String">
delete from qprofile_changes
where qprofile_key in
- <foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">
- #{profileKey, jdbcType=VARCHAR}
+ <foreach collection="profileUuids" open="(" close=")" item="profileUuid" separator=",">
+ #{profileUuid, jdbcType=VARCHAR}
</foreach>
</delete>
</mapper>
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 3eeb5f676ff..fdd6f3224b1 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
@@ -3,201 +3,226 @@
<mapper namespace="org.sonar.db.qualityprofile.QualityProfileMapper">
- <sql id="profilesColumns">
- p.id as id,
- p.organization_uuid as organizationUuid,
- p.kee as kee,
- p.name as name,
- p.language as language,
- p.parent_kee as parentKee,
- p.rules_updated_at as rulesUpdatedAt,
- p.last_used as lastUsed,
- p.user_updated_at as userUpdatedAt,
- p.is_built_in as isBuiltIn
+ <sql id="qProfileColumns">
+ oqp.uuid as kee,
+ oqp.organization_uuid as organizationUuid,
+ oqp.parent_uuid as parentKee,
+ rp.id as id,
+ rp.name as name,
+ rp.language as language,
+ rp.rules_updated_at as rulesUpdatedAt,
+ rp.last_used as lastUsed,
+ rp.user_updated_at as userUpdatedAt,
+ rp.is_built_in as isBuiltIn
</sql>
- <insert id="insert" parameterType="map" keyColumn="id" useGeneratedKeys="true" keyProperty="dto.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 (
- #{dto.organizationUuid, jdbcType=VARCHAR},
- #{dto.kee, jdbcType=VARCHAR},
- #{dto.parentKee, jdbcType=VARCHAR},
- #{dto.name, jdbcType=VARCHAR},
- #{dto.language, jdbcType=VARCHAR},
- #{now, jdbcType=TIMESTAMP},
- #{now, jdbcType=TIMESTAMP},
- #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
- #{dto.lastUsed, jdbcType=BIGINT},
- #{dto.userUpdatedAt, jdbcType=BIGINT},
- #{dto.isBuiltIn, jdbcType=BOOLEAN}
+ <insert id="insertRulesProfile" parameterType="map" keyColumn="id" useGeneratedKeys="true" keyProperty="dto.id">
+ insert into rules_profiles (
+ kee,
+ name,
+ language,
+ created_at,
+ updated_at,
+ rules_updated_at,
+ last_used,
+ user_updated_at,
+ is_built_in
+ ) values (
+ #{dto.kee, jdbcType=VARCHAR},
+ #{dto.name, jdbcType=VARCHAR},
+ #{dto.language, jdbcType=VARCHAR},
+ #{now, jdbcType=TIMESTAMP},
+ #{now, jdbcType=TIMESTAMP},
+ #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
+ #{dto.lastUsed, jdbcType=BIGINT},
+ #{dto.userUpdatedAt, jdbcType=BIGINT},
+ #{dto.isBuiltIn, jdbcType=BOOLEAN}
+ )
+ </insert>
+
+ <insert id="insertOrgQProfile" parameterType="map" useGeneratedKeys="false">
+ insert into org_qprofiles (
+ uuid,
+ organization_uuid,
+ rules_profile_uuid,
+ parent_uuid,
+ created_at,
+ updated_at
+ ) values (
+ #{dto.kee, jdbcType=VARCHAR},
+ #{dto.organizationUuid, jdbcType=VARCHAR},
+ #{dto.kee, jdbcType=VARCHAR},
+ #{dto.parentKee, jdbcType=VARCHAR},
+ #{now, jdbcType=BIGINT},
+ #{now, jdbcType=BIGINT}
)
</insert>
- <update id="update" parameterType="map">
- UPDATE rules_profiles SET
- name=#{dto.name, jdbcType=VARCHAR},
- language=#{dto.language, jdbcType=VARCHAR},
- parent_kee=#{dto.parentKee, jdbcType=VARCHAR},
- updated_at=#{now, jdbcType=TIMESTAMP},
- rules_updated_at=#{dto.rulesUpdatedAt, jdbcType=VARCHAR},
- last_used=#{dto.lastUsed, jdbcType=BIGINT},
- user_updated_at=#{dto.userUpdatedAt, jdbcType=BIGINT},
- is_built_in=#{dto.isBuiltIn, jdbcType=BOOLEAN}
- WHERE id=#{dto.id}
+ <update id="updateRulesProfile" parameterType="map">
+ update rules_profiles
+ set
+ name = #{dto.name, jdbcType=VARCHAR},
+ language = #{dto.language, jdbcType=VARCHAR},
+ updated_at = #{now, jdbcType=TIMESTAMP},
+ rules_updated_at = #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
+ last_used = #{dto.lastUsed, jdbcType=BIGINT},
+ user_updated_at = #{dto.userUpdatedAt, jdbcType=BIGINT},
+ is_built_in = #{dto.isBuiltIn, jdbcType=BOOLEAN}
+ where
+ kee = #{dto.kee, jdbcType=VARCHAR}
+ </update>
+
+ <update id="updateOrgQProfile" parameterType="map">
+ update org_qprofiles
+ set
+ parent_uuid = #{dto.parentKee, jdbcType=VARCHAR},
+ updated_at = #{now, jdbcType=BIGINT}
+ where
+ uuid = #{dto.kee, jdbcType=VARCHAR}
</update>
- <update id="deleteByKeys" parameterType="String">
+ <delete id="deleteRulesProfilesByUuids" parameterType="String">
delete from rules_profiles
where kee in
- <foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">#{profileKey, jdbcType=VARCHAR}</foreach>
- </update>
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
+ </delete>
- <select id="selectAll" parameterType="map" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- WHERE p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
- ORDER BY p.name, p.language
- </select>
-
- <select id="selectByNameAndLanguage" parameterType="map" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- WHERE p.name=#{name, jdbcType=VARCHAR}
- AND p.language=#{language, jdbcType=VARCHAR}
- <if test="organizationUuid != null">
- AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </if>
- </select>
-
- <select id="selectByNameAndLanguages" parameterType="map" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- WHERE p.name=#{name, jdbcType=VARCHAR}
- AND p.language IN <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
- AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <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="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- WHERE p.kee in
- <foreach collection="keys" open="(" close=")" item="key" separator=",">
- #{key}
- </foreach>
+ <delete id="deleteOrgQProfilesByUuids" parameterType="String">
+ delete from org_qprofiles
+ where uuid in
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
+ </delete>
+
+ <select id="selectAll" parameterType="map" 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.kee
+ where
+ oqp.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
+ order by rp.name, rp.language
</select>
- <select id="selectByLanguage" parameterType="String" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- WHERE p.language=#{language}
- AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- ORDER BY p.name
+ <select id="selectDefaultProfile" parameterType="map" 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.kee
+ inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
+ where
+ dp.language = #{language, jdbcType=VARCHAR}
+ and dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ and rp.language = dp.language
+ and oqp.organization_uuid = dp.organization_uuid
</select>
- <select id="selectChildren" parameterType="string" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- WHERE p.parent_kee=#{id}
- ORDER BY p.name
+ <select id="selectDefaultProfiles" parameterType="map" 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.kee
+ inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
+ where
+ dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
+ and dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ and rp.language = dp.language
+ and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
- <select id="selectDefaultProfile" parameterType="map" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- 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 id="selectByNameAndLanguage" parameterType="map" 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.kee
+ where
+ rp.name = #{name, jdbcType=VARCHAR}
+ and rp.language = #{language, jdbcType=VARCHAR}
+ and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ </select>
+
+ <select id="selectByNameAndLanguages" parameterType="map" 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.kee
+ where
+ rp.name = #{name, jdbcType=VARCHAR}
+ and rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
+ and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
- <select id="selectDefaultProfiles" parameterType="map" resultType="RulesProfile">
- SELECT
- <include refid="profilesColumns"/>
- FROM rules_profiles p
- 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 id="selectByUuid" 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.kee
+ where
+ oqp.uuid = #{uuid, jdbcType=VARCHAR}
</select>
- <select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
- FROM projects pj
- JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
- AND pp.profile_key = #{profileKey, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
- AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- ORDER BY pj.name ASC
+ <select id="selectByUuids" parameterType="map" 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.kee
+ where
+ oqp.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid}</foreach>
</select>
- <select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
- FROM projects pj
- LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
- AND pp.profile_key = #{profileKey, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
- AND pp.profile_key IS NULL
- AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- ORDER BY pj.name ASC
+ <select id="selectByLanguage" 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.kee
+ where
+ rp.language = #{language, jdbcType=VARCHAR}
+ and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
- <select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
- FROM projects pj
- LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
- AND pp.profile_key = #{profileKey, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
- AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- ORDER BY pj.name ASC
+ <select id="selectChildren" 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.kee
+ where
+ oqp.parent_uuid = #{uuid, jdbcType=VARCHAR}
+ ORDER BY rp.name
</select>
- <select id="countProjectsByProfileKey" resultType="KeyLongValue" parameterType="map">
- select pp.profile_key as "key", count(projects.id) as "value"
- from projects projects
- inner join project_qprofiles pp ON pp.project_uuid = projects.uuid
- inner join rules_profiles prof ON pp.profile_key = prof.kee
- where projects.enabled = ${_true}
- and prof.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- group by pp.profile_key
+ <select id="countProjectsByProfileUuid" resultType="KeyLongValue" parameterType="map">
+ select pqp.profile_key as "key", count(pj.uuid) as "value"
+ from projects pj
+ inner join project_qprofiles pqp on pqp.project_uuid = pj.uuid
+ inner join org_qprofiles oqp on oqp.uuid = pqp.profile_key
+ where
+ pj.enabled = ${_true}
+ and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ and oqp.organization_uuid = pj.organization_uuid
+ group by pqp.profile_key
</select>
- <select id="selectAssociatedToProjectUuidAndLanguage" parameterType="map" resultType="RulesProfile">
+ <select id="selectAssociatedToProjectUuidAndLanguage" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
- <include refid="profilesColumns"/>
- from rules_profiles p
- inner join project_qprofiles pp ON pp.profile_key = p.kee
+ <include refid="qProfileColumns"/>
+ from org_qprofiles oqp
+ inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
+ inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
where
- p.language = #{language, jdbcType=VARCHAR}
- and pp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ rp.language = #{language, jdbcType=VARCHAR}
+ and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
+ and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
- <select id="selectAssociatedToProjectUuidAndLanguages" parameterType="map" resultType="RulesProfile">
+ <select id="selectAssociatedToProjectUuidAndLanguages" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
- <include refid="profilesColumns"/>
- from rules_profiles p
- inner join project_qprofiles pq ON pq.profile_key = p.kee
+ <include refid="qProfileColumns"/>
+ from org_qprofiles oqp
+ inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
+ inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
where
- p.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
- and pq.project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
+ and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
+ and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
<insert id="insertProjectProfileAssociation" useGeneratedKeys="false">
@@ -213,40 +238,86 @@
<update id="updateProjectProfileAssociation">
update project_qprofiles
set
- profile_key = #{profileUuid, jdbcType=VARCHAR}
+ profile_key = #{profileUuid, jdbcType=VARCHAR}
where
- project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and profile_key = #{oldProfileUuid, jdbcType=VARCHAR}
+ project_uuid = #{projectUuid, jdbcType=VARCHAR}
+ and profile_key = #{oldProfileUuid, jdbcType=VARCHAR}
</update>
- <update id="deleteProjectProfileAssociation">
- DELETE FROM project_qprofiles
- WHERE project_uuid=#{projectUuid, jdbcType=VARCHAR} AND profile_key=#{profileKey, jdbcType=VARCHAR}
- </update>
+ <delete id="deleteProjectProfileAssociation">
+ delete from project_qprofiles
+ where
+ project_uuid = #{projectUuid, jdbcType=VARCHAR}
+ and profile_key=#{profileUuid, jdbcType=VARCHAR}
+ </delete>
- <update id="deleteProjectAssociationByProfileKeys" parameterType="String">
+ <delete id="deleteProjectAssociationByProfileUuids" parameterType="String">
delete from project_qprofiles
where profile_key in
- <foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">
- #{profileKey, jdbcType=VARCHAR}
+ <foreach collection="profileUuids" open="(" close=")" item="profileUuid" separator=",">
+ #{profileUuid, jdbcType=VARCHAR}
</foreach>
- </update>
+ </delete>
+
+ <select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
+ select
+ pp.id as id,
+ pj.id as projectId,
+ pj.uuid as projectUuid,
+ pj.kee as projectKey,
+ pj.name as projectName,
+ pp.profile_key as profileKey
+ from projects pj
+ inner join project_qprofiles pp ON pp.project_uuid = pj.uuid and pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
+ where
+ pj.scope = 'PRJ'
+ and pj.qualifier = 'TRK'
+ and upper(pj.name) like #{nameQuery, jdbcType=VARCHAR}
+ and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ order by pj.name ASC
+ </select>
- <select id="selectOutdatedProfiles" parameterType="map" resultType="string">
- select rp.kee
- from rules_profiles rp
- inner join organizations o on o.uuid = rp.organization_uuid
- where rp.language = #{language, jdbcType=VARCHAR}
+ <select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
+ SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
+ FROM projects pj
+ LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
+ AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
+ WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
+ AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
+ AND pp.profile_key IS NULL
+ AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ ORDER BY pj.name ASC
+ </select>
+
+ <select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
+ SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
+ FROM projects pj
+ LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
+ AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
+ WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
+ AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
+ AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ ORDER BY pj.name ASC
+ </select>
+
+ <select id="selectUuidsOfCustomQProfiles" parameterType="map" resultType="string">
+ select oqp.uuid
+ from org_qprofiles oqp
+ inner join organizations o on o.uuid = oqp.organization_uuid
+ inner join rules_profiles rp on rp.kee = oqp.rules_profile_uuid
+ where
+ rp.language = #{language, jdbcType=VARCHAR}
and rp.name = #{name, jdbcType=VARCHAR}
and rp.is_built_in = ${_false}
</select>
- <update id="rename" parameterType="map">
+ <update id="renameRulesProfiles" parameterType="map">
update rules_profiles
set
name = #{newName, jdbcType=VARCHAR},
updated_at = #{updatedAt, jdbcType=TIMESTAMP}
- where kee in <foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">#{profileKey, jdbcType=VARCHAR}</foreach>
+ where
+ kee in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</update>
</mapper>
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 30d00d121e2..242975bd404 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.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
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();
- RulesProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles);
+ QProfileDto 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 35530c4abd4..bf03320b40a 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 RulesProfileDto profile1 = RulesProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
- private RulesProfileDto profile2 = RulesProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2");
+ private QProfileDto profile1 = QProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
+ private QProfileDto profile2 = QProfileDto.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(RulesProfileDto profile, RuleDefinitionDto rule) {
+ private static ActiveRuleDto newRow(QProfileDto 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 f5800f52589..f317d828e08 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
@@ -20,6 +20,7 @@
package org.sonar.db.qualityprofile;
import java.util.List;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
@@ -42,7 +43,7 @@ public class DefaultQProfileDaoTest {
@Test
public void insertOrUpdate_inserts_row_when_does_not_exist() {
OrganizationDto org = dbTester.organizations().insert();
- RulesProfileDto profile = dbTester.qualityProfiles().insert(org);
+ QProfileDto profile = dbTester.qualityProfiles().insert(org);
DefaultQProfileDto dto = DefaultQProfileDto.from(profile);
underTest.insertOrUpdate(dbSession, dto);
@@ -69,7 +70,7 @@ public class DefaultQProfileDaoTest {
dbSession.commit();
assertThat(countRows()).isEqualTo(1);
- assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org, dto.getLanguage())).hasValue(newQProfileUuid);
+ assertThat(selectUuidOfDefaultProfile(org, dto.getLanguage())).hasValue(newQProfileUuid);
}
@Test
@@ -85,18 +86,18 @@ public class DefaultQProfileDaoTest {
dbSession.commit();
assertThat(countRows()).isEqualTo(2);
- assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org1, "java")).isEmpty();
- assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org1, "js")).hasValue("u2");
- assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org2, "java")).isEmpty();
- assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org2, "js")).hasValue("u4");
+ assertThat(selectUuidOfDefaultProfile(org1, "java")).isEmpty();
+ assertThat(selectUuidOfDefaultProfile(org1, "js")).hasValue("u2");
+ assertThat(selectUuidOfDefaultProfile(org2, "java")).isEmpty();
+ assertThat(selectUuidOfDefaultProfile(org2, "js")).hasValue("u4");
}
@Test
public void selectExistingQProfileUuids_filters_defaults() {
OrganizationDto org = dbTester.organizations().insert();
- RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org);
- RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org);
- dbTester.qualityProfiles().markAsDefault(profile1);
+ QProfileDto profile1 = dbTester.qualityProfiles().insert(org);
+ QProfileDto profile2 = dbTester.qualityProfiles().insert(org);
+ dbTester.qualityProfiles().setAsDefault(profile1);
List<String> profileUuids = asList(profile1.getKee(), profile2.getKee(), "other");
assertThat(underTest.selectExistingQProfileUuids(dbSession, org.getUuid(), profileUuids))
@@ -106,21 +107,30 @@ public class DefaultQProfileDaoTest {
@Test
public void isDefault_returns_true_if_profile_is_marked_as_default() {
OrganizationDto org = dbTester.organizations().insert();
- RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org);
- RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org);
- dbTester.qualityProfiles().markAsDefault(profile1);
+ QProfileDto profile1 = dbTester.qualityProfiles().insert(org);
+ QProfileDto profile2 = dbTester.qualityProfiles().insert(org);
+ dbTester.qualityProfiles().setAsDefault(profile1);
assertThat(underTest.isDefault(dbSession, org.getUuid(), profile1.getKee())).isTrue();
assertThat(underTest.isDefault(dbSession, org.getUuid(), profile2.getKee())).isFalse();
assertThat(underTest.isDefault(dbSession, org.getUuid(), "does_not_exist")).isFalse();
}
- private void assertThatIsDefault(OrganizationDto org, RulesProfileDto profile) {
- assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org, profile.getLanguage())).hasValue(profile.getKee());
+ private void assertThatIsDefault(OrganizationDto org, QProfileDto profile) {
+ assertThat(selectUuidOfDefaultProfile(org, profile.getLanguage())).hasValue(profile.getKee());
assertThat(underTest.isDefault(dbSession, org.getUuid(), profile.getKee())).isTrue();
}
private int countRows() {
return dbTester.countRowsOfTable("default_qprofiles");
}
+
+ private Optional<String> selectUuidOfDefaultProfile(OrganizationDto org, String language) {
+ return dbTester.select("select qprofile_uuid as \"profileUuid\" " +
+ " from default_qprofiles " +
+ " where organization_uuid='" + org.getUuid() + "' and language='" + language + "'")
+ .stream()
+ .findFirst()
+ .map(m -> (String) m.get("profileUuid"));
+ }
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java
index 6ecb82cebc4..be9bf0496de 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java
@@ -89,14 +89,6 @@ public class QProfileChangeDaoTest {
}
@Test
- public void insert_throws_ISE_if_key_is_already_set() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Key of QProfileChangeDto must be set by DAO only. Got C1.");
-
- underTest.insert(dbSession, new QProfileChangeDto().setKey("C1"));
- }
-
- @Test
public void insert_throws_ISE_if_date_is_already_set() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Date of QProfileChangeDto must be set by DAO only. Got 123.");
@@ -211,8 +203,8 @@ public class QProfileChangeDaoTest {
insertChange("P1", "ACTIVATED", null, null);// key: C1
insertChange("P1", "ACTIVATED", null, null);// key: C2
- assertThat(underTest.countForProfileKey(dbSession, "P1")).isEqualTo(2);
- assertThat(underTest.countForProfileKey(dbSession, "P2")).isEqualTo(0);
+ assertThat(underTest.countForProfileUuid(dbSession, "P1")).isEqualTo(2);
+ assertThat(underTest.countForProfileUuid(dbSession, "P2")).isEqualTo(0);
}
@Test
@@ -224,8 +216,8 @@ public class QProfileChangeDaoTest {
underTest.deleteByProfileKeys(dbSession, asList("P1"));
- assertThat(underTest.countForProfileKey(dbSession, "P1")).isEqualTo(0);
- assertThat(underTest.countForProfileKey(dbSession, "P2")).isEqualTo(1);
+ assertThat(underTest.countForProfileUuid(dbSession, "P1")).isEqualTo(0);
+ assertThat(underTest.countForProfileUuid(dbSession, "P2")).isEqualTo(1);
}
@Test
@@ -235,7 +227,7 @@ public class QProfileChangeDaoTest {
underTest.deleteByProfileKeys(dbSession, asList("does_not_exist"));
- assertThat(underTest.countForProfileKey(dbSession, "P1")).isEqualTo(1);
+ assertThat(underTest.countForProfileUuid(dbSession, "P1")).isEqualTo(1);
}
private void insertChange(String profileKey, String type, @Nullable String login, @Nullable String data) {
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 c6332f53d86..f2f2e8f9d56 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
@@ -19,10 +19,12 @@
*/
package org.sonar.db.qualityprofile;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.stream.IntStream;
import org.assertj.core.data.MapEntry;
import org.junit.After;
import org.junit.Before;
@@ -55,7 +57,6 @@ public class QualityProfileDaoTest {
public DbTester dbTester = DbTester.create(system);
private DbSession dbSession = dbTester.getSession();
- private QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(dbTester);
private QualityProfileDao underTest = dbTester.getDbClient().qualityProfileDao();
private OrganizationDto organization;
@@ -66,90 +67,109 @@ public class QualityProfileDaoTest {
}
@After
- public void tearDown() {
- // minor optimization, no need to commit pending operations
+ public void deleteData() {
dbSession.rollback();
}
@Test
- public void insert() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- RulesProfileDto dto = RulesProfileDto.createFor("abcde")
+ public void test_insert() {
+ QProfileDto dto = QProfileDto.createFor("theUuid")
.setOrganizationUuid(organization.getUuid())
- .setName("ABCDE")
- .setLanguage("xoo")
+ .setName("theName")
+ .setLanguage("theLang")
+ .setLastUsed(1_000L)
+ .setParentKee("theParentUuid")
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(true);
- underTest.insert(dbTester.getSession(), dto);
- dbTester.commit();
+ underTest.insert(dbSession, dto);
- dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
+ QProfileDto reloaded = underTest.selectByUuid(dbSession, dto.getKee());
+ assertThat(reloaded.getKee()).isEqualTo(dto.getKee());
+ assertThat(reloaded.getId()).isNotNull().isNotZero();
+ assertThat(reloaded.getLanguage()).isEqualTo(dto.getLanguage());
+ assertThat(reloaded.getName()).isEqualTo(dto.getName());
+ assertThat(reloaded.getLastUsed()).isEqualTo(dto.getLastUsed());
+ assertThat(reloaded.getRulesUpdatedAt()).isEqualTo(dto.getRulesUpdatedAt());
+ assertThat(reloaded.getParentKee()).isEqualTo(dto.getParentKee());
+ assertThat(reloaded.getOrganizationUuid()).isEqualTo(dto.getOrganizationUuid());
+ assertThat(reloaded.isBuiltIn()).isEqualTo(dto.isBuiltIn());
}
@Test
- public void update() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- RulesProfileDto dto = RulesProfileDto.createFor("key")
- .setId(1)
+ public void test_update() {
+ QProfileDto initial = QProfileDto.createFor("theUuid")
.setOrganizationUuid(organization.getUuid())
- .setName("New Name")
- .setLanguage("js")
- .setParentKee("fghij")
- .setIsBuiltIn(false);
-
- underTest.update(dbSession, dto);
- dbSession.commit();
-
- dbTester.assertDbUnit(getClass(), "update-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
+ .setName("theName")
+ .setLanguage("theLang")
+ .setLastUsed(1_000L)
+ .setParentKee("theParentUuid")
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(true);
+ underTest.insert(dbSession, initial);
+
+ QProfileDto update = QProfileDto.createFor(initial.getKee())
+ .setName("theNewName")
+ .setLanguage("theNewLang")
+ .setLastUsed(11_000L)
+ .setParentKee("theNewParentUuid")
+ .setUserUpdatedAt(12_000L)
+ .setRulesUpdatedAt("2017-06-01")
+ .setIsBuiltIn(false)
+
+ // field that cannot be changed
+ .setOrganizationUuid("theNewOrg");
+ underTest.update(dbSession, update);
+
+ QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee());
+ assertThat(reloaded.getKee()).isEqualTo(initial.getKee());
+ assertThat(reloaded.getOrganizationUuid()).isEqualTo(initial.getOrganizationUuid());
+
+ // updated fields
+ assertThat(reloaded.getLanguage()).isEqualTo(update.getLanguage());
+ assertThat(reloaded.getName()).isEqualTo(update.getName());
+ assertThat(reloaded.getLastUsed()).isEqualTo(update.getLastUsed());
+ assertThat(reloaded.getRulesUpdatedAt()).isEqualTo(update.getRulesUpdatedAt());
+ assertThat(reloaded.getParentKee()).isEqualTo(update.getParentKee());
+ assertThat(reloaded.isBuiltIn()).isEqualTo(update.isBuiltIn());
}
@Test
- public void test_deleteByKeys() {
- RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
- RulesProfileDto p2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
- RulesProfileDto p3 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
+ public void test_deleteByUuids() {
+ QProfileDto p1 = dbTester.qualityProfiles().insert(organization);
+ QProfileDto p2 = dbTester.qualityProfiles().insert(organization);
+ QProfileDto p3 = dbTester.qualityProfiles().insert(organization);
- underTest.deleteByKeys(dbSession, asList(p1.getKee(), p3.getKee(), "does_not_exist"));
+ underTest.deleteByUuids(dbSession, asList(p1.getKee(), p3.getKee(), "does_not_exist"));
- List<Map<String, Object>> keysInDb = dbTester.select(dbSession, "select kee as \"key\" from rules_profiles");
- assertThat(keysInDb).hasSize(1);
- assertThat(keysInDb.get(0).get("key")).isEqualTo(p2.getKee());
+ List<QProfileDto> profiles = underTest.selectAll(dbSession, organization);
+ assertThat(profiles).extracting(QProfileDto::getKee).containsExactly(p2.getKee());
}
@Test
- public void deleteByKeys_does_nothing_if_empty_keys() {
- RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
+ public void deleteByUuids_does_nothing_if_empty_uuids() {
+ dbTester.qualityProfiles().insert(organization);
- underTest.deleteByKeys(dbSession, Collections.emptyList());
+ underTest.deleteByUuids(dbSession, Collections.emptyList());
assertThat(dbTester.countRowsOfTable(dbSession, "rules_profiles")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable(dbSession, "org_qprofiles")).isEqualTo(1);
}
@Test
- public void deleteProjectAssociationsByProfileKeys_does_nothing_if_empty_keys() {
- RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
- ComponentDto project1 = dbTester.components().insertPrivateProject();
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);
-
- underTest.deleteProjectAssociationsByProfileKeys(dbSession, Collections.emptyList());
-
- assertThat(dbTester.countRowsOfTable(dbSession, "project_qprofiles")).isEqualTo(1);
- }
+ public void test_deleteProjectAssociationsByProfileUuids() {
+ QProfileDto profile1 = dbTester.qualityProfiles().insert(organization);
+ QProfileDto profile2 = dbTester.qualityProfiles().insert(organization);
+ ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project3 = dbTester.components().insertPrivateProject(organization);
+ dbTester.qualityProfiles().associateWithProject(project1, profile1);
+ dbTester.qualityProfiles().associateWithProject(project2, profile1);
+ dbTester.qualityProfiles().associateWithProject(project3, profile2);
- @Test
- public void deleteProjectAssociationsByProfileKeys_deletes_rows_from_table_project_profiles() {
- 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();
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profile1);
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project3, profile2);
-
- underTest.deleteProjectAssociationsByProfileKeys(dbSession, asList(profile1.getKee(), "does_not_exist"));
+ underTest.deleteProjectAssociationsByProfileUuids(dbSession, asList(profile1.getKee(), "does_not_exist"));
List<Map<String, Object>> rows = dbTester.select(dbSession, "select project_uuid as \"projectUuid\", profile_key as \"profileKey\" from project_qprofiles");
assertThat(rows).hasSize(1);
@@ -158,103 +178,148 @@ public class QualityProfileDaoTest {
}
@Test
- public void find_all() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
+ public void deleteProjectAssociationsByProfileUuids_does_nothing_if_empty_uuids() {
+ QProfileDto profile = dbTester.qualityProfiles().insert(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
+ dbTester.qualityProfiles().associateWithProject(project, profile);
- List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);
+ underTest.deleteProjectAssociationsByProfileUuids(dbSession, Collections.emptyList());
- assertThat(dtos).hasSize(2);
+ assertThat(dbTester.countRowsOfTable(dbSession, "project_qprofiles")).isEqualTo(1);
+ }
- 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();
-
- RulesProfileDto dto2 = dtos.get(1);
- assertThat(dto2.getId()).isEqualTo(2);
- assertThat(dto2.getName()).isEqualTo("Sonar Way");
- assertThat(dto2.getLanguage()).isEqualTo("js");
- assertThat(dto2.getParentKee()).isNull();
- assertThat(dto2.isBuiltIn()).isFalse();
+ @Test
+ public void test_selectAll() {
+ List<QProfileDto> sharedData = createSharedData();
+
+ List<QProfileDto> reloadeds = underTest.selectAll(dbSession, organization);
+
+ assertThat(reloadeds).hasSize(sharedData.size());
+
+ IntStream.range(1, reloadeds.size())
+ .forEach(
+ i -> {
+ QProfileDto reloaded = reloadeds.get(i - 1);
+ QProfileDto original = sharedData.get(i - 1);
+
+ assertThat(reloaded.getId()).isEqualTo(original.getId());
+ assertThat(reloaded.getName()).isEqualTo(original.getName());
+ assertThat(reloaded.getKee()).isEqualTo(original.getKee());
+ assertThat(reloaded.getOrganizationUuid()).isEqualTo(original.getOrganizationUuid());
+ assertThat(reloaded.getLanguage()).isEqualTo(original.getLanguage());
+ assertThat(reloaded.getParentKee()).isEqualTo(original.getParentKee());
+ assertThat(reloaded.getRulesUpdatedAt()).isEqualTo(original.getRulesUpdatedAt());
+ assertThat(reloaded.getLastUsed()).isEqualTo(original.getLastUsed());
+ assertThat(reloaded.getUserUpdatedAt()).isEqualTo(original.getUserUpdatedAt());
+ assertThat(reloaded.isBuiltIn()).isEqualTo(original.isBuiltIn());
+ }
+ );
}
@Test
public void find_all_is_sorted_by_profile_name() {
- dbTester.prepareDbUnit(getClass(), "select_all_is_sorted_by_profile_name.xml");
+ QProfileDto dto1 = QProfileDto.createFor("js_first")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("First")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, dto1);
+
+ QProfileDto dto2 = QProfileDto.createFor("js_second")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Second")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, dto2);
+
+ QProfileDto dto3 = QProfileDto.createFor("js_third")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Third")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, dto3);
- List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);
+ List<QProfileDto> dtos = underTest.selectAll(dbSession, organization);
assertThat(dtos).hasSize(3);
assertThat(dtos.get(0).getName()).isEqualTo("First");
assertThat(dtos.get(1).getName()).isEqualTo("Second");
assertThat(dtos.get(2).getName()).isEqualTo("Third");
+
+ underTest.deleteByUuids(dbSession, Arrays.asList("js_first", "js_second", "js_third"));
}
@Test
public void get_default_profile() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
+ List<QProfileDto> sharedData = createSharedData();
- RulesProfileDto java = underTest.selectDefaultProfile(dbTester.getSession(), organization, "java");
+ QProfileDto java = underTest.selectDefaultProfile(dbSession, organization, "java");
assertThat(java).isNotNull();
assertThat(java.getKee()).isEqualTo("java_sonar_way");
- assertThat(underTest.selectDefaultProfile(dbTester.getSession(), dbTester.organizations().insert(), "java")).isNull();
- assertThat(underTest.selectDefaultProfile(dbTester.getSession(), organization, "js")).isNull();
+ assertThat(underTest.selectDefaultProfile(dbSession, dbTester.organizations().insert(), "java")).isNull();
+ assertThat(underTest.selectDefaultProfile(dbSession, organization, "js")).isNull();
}
@Test
public void get_default_profiles() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
+ List<QProfileDto> sharedData = createSharedData();
- List<RulesProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("java"));
- assertThat(java).extracting(RulesProfileDto::getKee).containsOnly("java_sonar_way");
+ List<QProfileDto> java = underTest.selectDefaultProfiles(dbSession, organization, singletonList("java"));
+ assertThat(java).extracting(QProfileDto::getKee).containsOnly("java_sonar_way");
- assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("js"))).isEmpty();
- assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, of("java", "js"))).extracting(RulesProfileDto::getKee).containsOnly("java_sonar_way");
- assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, of("js", "java"))).extracting(RulesProfileDto::getKee).containsOnly("java_sonar_way");
+ assertThat(underTest.selectDefaultProfiles(dbSession, organization, singletonList("js"))).isEmpty();
+ assertThat(underTest.selectDefaultProfiles(dbSession, organization, of("java", "js"))).extracting(QProfileDto::getKee).containsOnly("java_sonar_way");
+ assertThat(underTest.selectDefaultProfiles(dbSession, organization, of("js", "java"))).extracting(QProfileDto::getKee).containsOnly("java_sonar_way");
}
@Test
public void get_by_name_and_language() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
+ List<QProfileDto> sharedData = createSharedData();
- RulesProfileDto dto = underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession());
- assertThat(dto.getId()).isEqualTo(1);
+ QProfileDto dto = underTest.selectByNameAndLanguage(dbSession, organization, "Sonar Way", "java");
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();
- assertThat(underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession())).isNotNull();
- assertThat(underTest.selectByNameAndLanguage(organization, "Sonar Way", "unknown", dbTester.getSession())).isNull();
+ assertThat(underTest.selectByNameAndLanguage(dbSession, organization, "Sonar Way", "java")).isNotNull();
+ assertThat(underTest.selectByNameAndLanguage(dbSession, organization, "Sonar Way", "unknown")).isNull();
}
@Test
public void get_by_name_and_languages() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
+ createSharedData();
- List<RulesProfileDto> dtos = underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("java"), dbTester.getSession());
+ List<QProfileDto> dtos = underTest.selectByNameAndLanguages(dbSession, organization, "Sonar Way", singletonList("java"));
assertThat(dtos).hasSize(1);
- RulesProfileDto dto = dtos.iterator().next();
- assertThat(dto.getId()).isEqualTo(1);
+ QProfileDto dto = dtos.iterator().next();
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();
- assertThat(underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("unknown"), dbTester.getSession())).isEmpty();
- assertThat(underTest.selectByNameAndLanguages(organization, "Sonar Way", of("java", "unknown"), dbTester.getSession())).extracting("id").containsOnly(1);
+ assertThat(underTest.selectByNameAndLanguages(dbSession, organization, "Sonar Way", singletonList("unknown"))).isEmpty();
+ assertThat(underTest.selectByNameAndLanguages(dbSession, organization, "Sonar Way", of("java", "unknown")))
+ .extracting(QProfileDto::getKee).containsOnly(dto.getKee());
}
@Test
public void should_find_by_language() {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);
- List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage());
+ List<QProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage());
assertThat(results).hasSize(1);
- RulesProfileDto result = results.get(0);
+ QProfileDto result = results.get(0);
assertThat(result.getId()).isEqualTo(profile.getId());
assertThat(result.getName()).isEqualTo(profile.getName());
@@ -265,60 +330,123 @@ public class QualityProfileDaoTest {
@Test
public void should_not_find_by_language_in_wrong_organization() {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);
- List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage());
+ List<QProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage());
assertThat(results).isEmpty();
}
@Test
public void should_not_find_by_language_with_wrong_language() {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);
- List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language");
+ List<QProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language");
assertThat(results).isEmpty();
}
+
@Test
public void find_children() {
- dbTester.prepareDbUnit(getClass(), "inheritance.xml");
+ QProfileDto original1 = QProfileDto.createFor("java_child1")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Child1")
+ .setLanguage("java")
+ .setLastUsed(1_000L)
+ .setParentKee("java_parent")
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, original1);
+
+ QProfileDto original2 = QProfileDto.createFor("java_child2")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Child2")
+ .setLanguage("java")
+ .setLastUsed(1_000L)
+ .setParentKee("java_parent")
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, original2);
+
+ QProfileDto original3 = QProfileDto.createFor("java_parent")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Parent")
+ .setLanguage("java")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, original3);
+
+ QProfileDto original4 = QProfileDto.createFor("js_child1")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Child1")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setParentKee("js_parent")
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, original4);
- List<RulesProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent");
+ QProfileDto original5 = QProfileDto.createFor("js_child2")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Child2")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setParentKee("js_parent")
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, original5);
+
+ QProfileDto original6 = QProfileDto.createFor("js_parent")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Parent")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(false);
+ underTest.insert(dbSession, original6);
+
+ List<QProfileDto> dtos = underTest.selectChildren(dbSession, "java_parent");
assertThat(dtos).hasSize(2);
- RulesProfileDto dto1 = dtos.get(0);
- assertThat(dto1.getId()).isEqualTo(1);
+ QProfileDto dto1 = dtos.get(0);
assertThat(dto1.getName()).isEqualTo("Child1");
assertThat(dto1.getLanguage()).isEqualTo("java");
assertThat(dto1.getParentKee()).isEqualTo("java_parent");
- RulesProfileDto dto2 = dtos.get(1);
- assertThat(dto2.getId()).isEqualTo(2);
+ QProfileDto dto2 = dtos.get(1);
assertThat(dto2.getName()).isEqualTo("Child2");
assertThat(dto2.getLanguage()).isEqualTo("java");
assertThat(dto2.getParentKee()).isEqualTo("java_parent");
+
+ underTest.deleteByUuids(dbSession, Arrays.asList("java_parent", "java_child1", "java_child2", "js_parent", "js_child1", "js_child2"));
}
@Test
public void countProjectsByProfileKey() {
- RulesProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
- RulesProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization);
+ QProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
+ QProfileDto 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);
+ dbTester.qualityProfiles().associateWithProject(project1, profileWithProjects);
+ dbTester.qualityProfiles().associateWithProject(project2, profileWithProjects);
OrganizationDto otherOrg = dbTester.organizations().insert();
- RulesProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
+ QProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
ComponentDto projectInOtherOrg = dbTester.components().insertPrivateProject(otherOrg);
- dbTester.qualityProfiles().associateProjectWithQualityProfile(projectInOtherOrg, profileInOtherOrg);
+ dbTester.qualityProfiles().associateWithProject(projectInOtherOrg, profileInOtherOrg);
- assertThat(underTest.countProjectsByProfileKey(dbTester.getSession(), organization)).containsOnly(
+ assertThat(underTest.countProjectsByProfileUuid(dbSession, organization)).containsOnly(
MapEntry.entry(profileWithProjects.getKee(), 2L));
}
@@ -327,17 +455,17 @@ public class QualityProfileDaoTest {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto project1 = dbTester.components().insertPublicProject(org);
ComponentDto project2 = dbTester.components().insertPublicProject(org);
- RulesProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
- RulesProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, javaProfile, jsProfile);
+ QProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
+ QProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
+ dbTester.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project1, "java").getKee())
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "java").getKee())
.isEqualTo(javaProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project1, "js").getKee())
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "js").getKee())
.isEqualTo(jsProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project1, "cobol"))
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "cobol"))
.isNull();
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project2, "java"))
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project2, "java"))
.isNull();
}
@@ -346,19 +474,19 @@ public class QualityProfileDaoTest {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto project1 = dbTester.components().insertPublicProject(org);
ComponentDto project2 = dbTester.components().insertPublicProject(org);
- RulesProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
- RulesProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, javaProfile, jsProfile);
+ QProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
+ QProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
+ dbTester.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);
- assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, singletonList("java")))
- .extracting(RulesProfileDto::getKee).containsOnly(javaProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, singletonList("unknown")))
+ assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, singletonList("java")))
+ .extracting(QProfileDto::getKee).containsOnly(javaProfile.getKee());
+ assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, singletonList("unknown")))
.isEmpty();
- assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, of("java", "unknown")))
- .extracting(RulesProfileDto::getKee).containsExactly(javaProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, of("java", "js")))
- .extracting(RulesProfileDto::getKee).containsExactlyInAnyOrder(javaProfile.getKee(), jsProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project2, singletonList("java")))
+ assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, of("java", "unknown")))
+ .extracting(QProfileDto::getKee).containsExactly(javaProfile.getKee());
+ assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, of("java", "js")))
+ .extracting(QProfileDto::getKee).containsExactlyInAnyOrder(javaProfile.getKee(), jsProfile.getKee());
+ assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project2, singletonList("java")))
.isEmpty();
}
@@ -366,10 +494,10 @@ public class QualityProfileDaoTest {
public void test_updateProjectProfileAssociation() {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto project = dbTester.components().insertPrivateProject(org);
- RulesProfileDto javaProfile1 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
- RulesProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
- RulesProfileDto javaProfile2 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
- qualityProfileDb.associateProjectWithQualityProfile(project, javaProfile1, jsProfile);
+ QProfileDto javaProfile1 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
+ QProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
+ QProfileDto javaProfile2 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
+ dbTester.qualityProfiles().associateWithProject(project, javaProfile1, jsProfile);
underTest.updateProjectProfileAssociation(dbSession, project, javaProfile2.getKee(), javaProfile1.getKee());
@@ -379,15 +507,15 @@ public class QualityProfileDaoTest {
@Test
public void selectByKeys() {
- qualityProfileDb.insertQualityProfiles(newQualityProfileDto().setKey("qp-key-1"), newQualityProfileDto().setKee("qp-key-2"), newQualityProfileDto().setKee("qp-key-3"));
+ dbTester.qualityProfiles().insert(newQualityProfileDto().setKey("qp-key-1"), newQualityProfileDto().setKee("qp-key-2"), newQualityProfileDto().setKee("qp-key-3"));
- assertThat(underTest.selectOrFailByKey(dbSession, "qp-key-1")).isNotNull();
- assertThat(underTest.selectByKey(dbSession, "qp-key-1")).isNotNull();
- assertThat(underTest.selectByKey(dbSession, "qp-key-42")).isNull();
- assertThat(underTest.selectByKeys(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
+ assertThat(underTest.selectOrFailByUuid(dbSession, "qp-key-1")).isNotNull();
+ assertThat(underTest.selectByUuid(dbSession, "qp-key-1")).isNotNull();
+ assertThat(underTest.selectByUuid(dbSession, "qp-key-42")).isNull();
+ assertThat(underTest.selectByUuids(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
.hasSize(2)
- .extracting(RulesProfileDto::getKee).containsOnlyOnce("qp-key-1", "qp-key-3");
- assertThat(underTest.selectByKeys(dbSession, emptyList())).isEmpty();
+ .extracting(QProfileDto::getKee).containsOnlyOnce("qp-key-1", "qp-key-3");
+ assertThat(underTest.selectByUuids(dbSession, emptyList())).isEmpty();
}
@Test
@@ -398,23 +526,24 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
- RulesProfileDto profile1 = newQualityProfileDto();
- qualityProfileDb.insertQualityProfiles(profile1);
- qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
- qualityProfileDb.associateProjectWithQualityProfile(project2, profile1);
+ QProfileDto profile1 = newQualityProfileDto();
+ dbTester.qualityProfiles().insert(profile1);
+ dbTester.qualityProfiles().associateWithProject(project1, profile1);
+ dbTester.qualityProfiles().associateWithProject(project2, profile1);
- RulesProfileDto profile2 = newQualityProfileDto();
- qualityProfileDb.insertQualityProfiles(profile2);
- qualityProfileDb.associateProjectWithQualityProfile(project3, profile2);
+ QProfileDto profile2 = newQualityProfileDto();
+ dbTester.qualityProfiles().insert(profile2);
+ dbTester.qualityProfiles().associateWithProject(project3, profile2);
+ QProfileDto profile3 = newQualityProfileDto();
- assertThat(underTest.selectSelectedProjects(organization, profile1.getKee(), null, dbSession))
+ assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, null))
.extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKee()),
tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), profile1.getKee()));
- assertThat(underTest.selectSelectedProjects(organization, profile1.getKee(), "ect1", dbSession)).hasSize(1);
- assertThat(underTest.selectSelectedProjects(organization, "unknown", null, dbSession)).isEmpty();
+ assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, "ect1")).hasSize(1);
+ assertThat(underTest.selectSelectedProjects(dbSession, organization, profile3, null)).isEmpty();
}
@Test
@@ -425,22 +554,23 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
- RulesProfileDto profile1 = newQualityProfileDto();
- qualityProfileDb.insertQualityProfiles(profile1);
- qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
+ QProfileDto profile1 = newQualityProfileDto();
+ dbTester.qualityProfiles().insert(profile1);
+ dbTester.qualityProfiles().associateWithProject(project1, profile1);
- RulesProfileDto profile2 = newQualityProfileDto();
- qualityProfileDb.insertQualityProfiles(profile2);
- qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);
+ QProfileDto profile2 = newQualityProfileDto();
+ dbTester.qualityProfiles().insert(profile2);
+ dbTester.qualityProfiles().associateWithProject(project2, profile2);
+ QProfileDto profile3 = newQualityProfileDto();
- assertThat(underTest.selectDeselectedProjects(organization, profile1.getKee(), null, dbSession))
+ assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, null))
.extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
.containsExactly(
tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null),
tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null));
- assertThat(underTest.selectDeselectedProjects(organization, profile1.getKee(), "ect2", dbSession)).hasSize(1);
- assertThat(underTest.selectDeselectedProjects(organization, "unknown", null, dbSession)).hasSize(3);
+ assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, "ect2")).hasSize(1);
+ assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile3, null)).hasSize(3);
}
@Test
@@ -451,23 +581,24 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
- RulesProfileDto profile1 = newQualityProfileDto();
- qualityProfileDb.insertQualityProfiles(profile1);
- qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
+ QProfileDto profile1 = newQualityProfileDto();
+ dbTester.qualityProfiles().insert(profile1);
+ dbTester.qualityProfiles().associateWithProject(project1, profile1);
- RulesProfileDto profile2 = newQualityProfileDto();
- qualityProfileDb.insertQualityProfiles(profile2);
- qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);
+ QProfileDto profile2 = newQualityProfileDto();
+ dbTester.qualityProfiles().insert(profile2);
+ dbTester.qualityProfiles().associateWithProject(project2, profile2);
+ QProfileDto profile3 = newQualityProfileDto();
- assertThat(underTest.selectProjectAssociations(organization, profile1.getKee(), null, dbSession))
+ assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, null))
.extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKee()),
tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null),
tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null));
- assertThat(underTest.selectProjectAssociations(organization, profile1.getKee(), "ect2", dbSession)).hasSize(1);
- assertThat(underTest.selectProjectAssociations(organization, "unknown", null, dbSession)).hasSize(3);
+ assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, "ect2")).hasSize(1);
+ assertThat(underTest.selectProjectAssociations(dbSession, organization, profile3, null)).hasSize(3);
}
@Test
@@ -475,54 +606,75 @@ public class QualityProfileDaoTest {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
OrganizationDto org3 = dbTester.organizations().insert();
- 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"));
+ QProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
+ QProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
+ QProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo"));
+ QProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
+ QProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));
- Collection<String> keys = underTest.selectOutdatedProfiles(dbSession, "java", "foo");
+ Collection<String> keys = underTest.selectUuidsOfCustomRulesProfiles(dbSession, "java", "foo");
assertThat(keys).containsExactlyInAnyOrder(outdatedProfile1.getKee(), outdatedProfile2.getKee());
}
@Test
public void selectOutdatedProfiles_returns_empty_list_if_no_match() {
- assertThat(underTest.selectOutdatedProfiles(dbSession, "java", "foo")).isEmpty();
+ assertThat(underTest.selectUuidsOfCustomRulesProfiles(dbSession, "java", "foo")).isEmpty();
}
@Test
public void renameAndCommit_updates_name_of_specified_profiles() {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
- 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"));
+ QProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setName("foo"));
+ QProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setName("foo"));
+ QProfileDto bar = dbTester.qualityProfiles().insert(org1, p -> p.setName("bar"));
- underTest.renameAndCommit(dbSession, asList(fooInOrg1.getKee(), fooInOrg2.getKee()), "foo (copy)");
+ underTest.renameRulesProfilesAndCommit(dbSession, asList(fooInOrg1.getKee(), fooInOrg2.getKee()), "foo (copy)");
- assertThat(underTest.selectOrFailByKey(dbSession, fooInOrg1.getKee()).getName()).isEqualTo("foo (copy)");
- assertThat(underTest.selectOrFailByKey(dbSession, fooInOrg2.getKee()).getName()).isEqualTo("foo (copy)");
- assertThat(underTest.selectOrFailByKey(dbSession, bar.getKee()).getName()).isEqualTo("bar");
+ assertThat(underTest.selectOrFailByUuid(dbSession, fooInOrg1.getKee()).getName()).isEqualTo("foo (copy)");
+ assertThat(underTest.selectOrFailByUuid(dbSession, fooInOrg2.getKee()).getName()).isEqualTo("foo (copy)");
+ assertThat(underTest.selectOrFailByUuid(dbSession, bar.getKee()).getName()).isEqualTo("bar");
}
@Test
public void renameAndCommit_does_nothing_if_empty_keys() {
OrganizationDto org = dbTester.organizations().insert();
- RulesProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo"));
+ QProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo"));
- underTest.renameAndCommit(dbSession, Collections.emptyList(), "foo (copy)");
+ underTest.renameRulesProfilesAndCommit(dbSession, Collections.emptyList(), "foo (copy)");
- assertThat(underTest.selectOrFailByKey(dbSession, profile.getKee()).getName()).isEqualTo("foo");
+ assertThat(underTest.selectOrFailByUuid(dbSession, profile.getKee()).getName()).isEqualTo("foo");
}
- private RulesProfileDto insertQualityProfileDto(String key, String name, String language) {
- RulesProfileDto dto = RulesProfileDto.createFor(key)
+ private List<QProfileDto> createSharedData() {
+ QProfileDto dto1 = QProfileDto.createFor("java_sonar_way")
.setOrganizationUuid(organization.getUuid())
- .setName(name)
- .setLanguage(language);
- underTest.insert(dbSession, dto);
- return dto;
+ .setName("Sonar Way")
+ .setLanguage("java")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(true);
+ underTest.insert(dbSession, dto1);
+
+ QProfileDto dto2 = QProfileDto.createFor("js_sonar_way")
+ .setOrganizationUuid(organization.getUuid())
+ .setName("Sonar Way")
+ .setLanguage("js")
+ .setLastUsed(1_000L)
+ .setUserUpdatedAt(2_000L)
+ .setRulesUpdatedAt("2017-05-31")
+ .setIsBuiltIn(true);
+ underTest.insert(dbSession, dto2);
+
+ DefaultQProfileDto defaultQProfileDto = new DefaultQProfileDto()
+ .setQProfileUuid(dto1.getKee())
+ .setLanguage(dto1.getLanguage())
+ .setOrganizationUuid(organization.getUuid());
+ dbTester.getDbClient().defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(dto1));
+
+ return Arrays.asList(dto1, dto2);
}
}
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 562f925b2ca..02c53fad43d 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,6 +22,7 @@ package org.sonar.db.qualityprofile;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;
+import org.sonar.api.rule.Severity;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -29,93 +30,82 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
-import static org.sonar.api.rule.Severity.MAJOR;
+import static org.apache.commons.lang.math.RandomUtils.nextInt;
+import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.sonar.db.qualityprofile.ActiveRuleDto.createFor;
public class QualityProfileDbTester {
- private final DbTester dbTester;
private final DbClient dbClient;
private final DbSession dbSession;
public QualityProfileDbTester(DbTester dbTester) {
- this.dbTester = dbTester;
this.dbClient = dbTester.getDbClient();
this.dbSession = dbTester.getSession();
}
- public Optional<RulesProfileDto> selectByKey(String key) {
- return Optional.ofNullable(dbClient.qualityProfileDao().selectByKey(dbSession, key));
+ public Optional<QProfileDto> selectByUuid(String uuid) {
+ return Optional.ofNullable(dbClient.qualityProfileDao().selectByUuid(dbSession, uuid));
}
/**
* Create a profile with random field values on the specified organization.
*/
- @SafeVarargs
- public final RulesProfileDto insert(OrganizationDto organization, Consumer<RulesProfileDto>... consumers) {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
+ public QProfileDto insert(OrganizationDto organization) {
+ return insert(organization, c -> {
+ });
+ }
+
+ /**
+ * Create a profile with random field values on the specified organization.
+ */
+ public QProfileDto insert(OrganizationDto organization, Consumer<QProfileDto> consumer) {
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
- Arrays.stream(consumers).forEach(c -> c.accept(profile));
+ consumer.accept(profile);
dbClient.qualityProfileDao().insert(dbSession, profile);
dbSession.commit();
return profile;
}
- public void insertQualityProfiles(RulesProfileDto qualityProfile, RulesProfileDto... qualityProfiles) {
- dbClient.qualityProfileDao().insert(dbSession, qualityProfile, qualityProfiles);
- dbSession.commit();
- }
-
- public RulesProfileDto insertQualityProfile(RulesProfileDto qualityProfile) {
- dbClient.qualityProfileDao().insert(dbSession, qualityProfile);
+ public QualityProfileDbTester insert(QProfileDto profile, QProfileDto... others) {
+ dbClient.qualityProfileDao().insert(dbSession, profile);
+ Arrays.stream(others).forEach(p -> dbClient.qualityProfileDao().insert(dbSession, p));
dbSession.commit();
- return qualityProfile;
+ return this;
}
- public void insertProjectWithQualityProfileAssociations(ComponentDto project, RulesProfileDto... qualityProfiles) {
- dbClient.componentDao().insert(dbSession, project);
- for (RulesProfileDto qualityProfile : qualityProfiles) {
- dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, qualityProfile);
+ public QualityProfileDbTester associateWithProject(ComponentDto project, QProfileDto profile, QProfileDto... otherProfiles) {
+ dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile);
+ for (QProfileDto p : otherProfiles) {
+ dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, p);
}
dbSession.commit();
+ return this;
}
- public void associateProjectWithQualityProfile(ComponentDto project, RulesProfileDto... qualityProfiles) {
- for (RulesProfileDto qualityProfile : qualityProfiles) {
- dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, qualityProfile);
- }
- dbSession.commit();
+ public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule) {
+ return activateRule(profile, rule, ar -> {
+ });
}
- @SafeVarargs
- 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);
- }
+ public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto> consumer) {
+ ActiveRuleDto activeRule = createFor(profile, rule)
+ .setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size())))
+ .setCreatedAt(nextLong())
+ .setUpdatedAt(nextLong());
+ consumer.accept(activeRule);
dbClient.activeRuleDao().insert(dbSession, activeRule);
dbSession.commit();
return activeRule;
}
- 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);
+ public QualityProfileDbTester setAsDefault(QProfileDto profile, QProfileDto... others) {
+ dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
+ for (QProfileDto other : others) {
+ dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(other));
}
-
dbSession.commit();
- }
-
- public Optional<String> selectUuidOfDefaultProfile(OrganizationDto org, String language) {
- return dbTester.select("select qprofile_uuid as \"profileUuid\" " +
- " from default_qprofiles " +
- " where organization_uuid='" + org.getUuid() + "' and language='" + language + "'")
- .stream()
- .findFirst()
- .map(m -> (String)m.get("profileUuid"));
+ return this;
}
}
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 3c1c9c1dec5..31625394af9 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
@@ -20,25 +20,32 @@
package org.sonar.db.qualityprofile;
import org.sonar.core.util.Uuids;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import static java.util.Arrays.stream;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang.math.RandomUtils.nextLong;
public class QualityProfileTesting {
- public static RulesProfileDto newQualityProfileDto() {
+ private QualityProfileTesting() {
+ // prevent instantiation
+ }
+
+ /**
+ * Create an instance of {@link QProfileDto} with random field values.
+ */
+ public static QProfileDto newQualityProfileDto() {
String uuid = Uuids.createFast();
- RulesProfileDto dto = RulesProfileDto.createFor(uuid)
+ return QProfileDto.createFor(uuid)
.setOrganizationUuid(randomAlphanumeric(40))
.setName(uuid)
.setLanguage(randomAlphanumeric(20))
.setLastUsed(nextLong());
- return dto;
}
+ /**
+ * Create an instance of {@link QProfileChangeDto} with random field values,
+ * except changeType which is always {@code "ACTIVATED"}.
+ */
public static QProfileChangeDto newQProfileChangeDto() {
return new QProfileChangeDto()
.setKey(randomAlphanumeric(40))
@@ -47,13 +54,4 @@ public class QualityProfileTesting {
.setChangeType("ACTIVATED")
.setLogin(randomAlphanumeric(10));
}
-
- public static void insert(DbTester dbTester, QProfileChangeDto... dtos) {
- // do not use QProfileChangeDao so that generated fields key and creation date
- // can be defined by tests
- DbSession dbSession = dbTester.getSession();
- QProfileChangeMapper mapper = dbSession.getMapper(QProfileChangeMapper.class);
- stream(dtos).forEach(mapper::insert);
- dbSession.commit();
- }
}
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
deleted file mode 100644
index 691735eb14d..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<dataset>
-
- <rules_profiles id="2"
- name="Sonar Way"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_sonar_way"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="123456789"
- user_updated_at="987654321"/>
-
-</dataset>
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
deleted file mode 100644
index 8f063f02d18..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<dataset>
-
- <rules_profiles id="1"
- name="Child1"
- language="java"
- organization_uuid="org-123"
- parent_kee="java_parent"
- kee="java_child1"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="2"
- name="Child2"
- language="java"
- organization_uuid="org-123"
- parent_kee="java_parent"
- kee="java_child2"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="3"
- name="Parent"
- language="java"
- organization_uuid="org-123"
- parent_kee="[null]"
- kee="java_parent"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <!-- Same profile for another language -->
-
- <rules_profiles id="4"
- name="Child1"
- language="js"
- organization_uuid="org-123"
- parent_kee="js_parent"
- kee="js_child1"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="5"
- name="Child2"
- language="js"
- organization_uuid="org-123"
- parent_kee="js_parent"
- kee="js_child2"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="6"
- name="Parent"
- language="js"
- organization_uuid="org-123"
- parent_kee="[null]"
- kee="js_parent"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
-</dataset>
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
deleted file mode 100644
index 1e4b2849681..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<dataset>
-
- <rules_profiles id="1"
- name="Sonar Way"
- language="java"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="java_sonar_way"
- is_built_in="[true]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="[null]"
- user_updated_at="[null]"/>
-
- <rules_profiles id="2"
- name="Sonar Way"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_sonar_way"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="123456789"
- user_updated_at="987654321"/>
-
- <rules_profiles id="3"
- name="ABCDE"
- language="xoo"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="abcde"
- is_built_in="[true]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="[null]"
- user_updated_at="[null]"/>
-
-
-</dataset>
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
deleted file mode 100644
index 42c8a4f64ab..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<dataset>
-
- <rules_profiles id="3"
- name="Third"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_third"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="1"
- name="First"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_first"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="2"
- name="Second"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_second"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
-
-</dataset>
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
deleted file mode 100644
index 3d5814908ca..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<dataset>
-
- <rules_profiles id="1"
- name="Sonar Way 1"
- language="java"
- organization_uuid="org-123"
- parent_kee="[null]"
- kee="java_sonar_way"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="2"
- name="Sonar Way"
- language="js"
- organization_uuid="org-123"
- parent_kee="[null]"
- kee="js_sonar_way"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
- <rules_profiles id="3"
- name="Sonar Way 2"
- language="java"
- organization_uuid="org-123"
- parent_kee="[null]"
- kee="java_sonar_way2"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"/>
-
-</dataset>
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
deleted file mode 100644
index 7872802c029..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<dataset>
-
- <rules_profiles id="1"
- name="Sonar Way"
- language="java"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="java_sonar_way"
- is_built_in="[true]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="[null]"
- user_updated_at="[null]"/>
-
- <rules_profiles id="2"
- name="Sonar Way"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_sonar_way"
- is_built_in="[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
deleted file mode 100644
index d37e24c2e62..00000000000
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<dataset>
-
- <rules_profiles id="1"
- name="New Name"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="fghij"
- kee="java_sonar_way"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="[null]"
- user_updated_at="[null]"/>
-
- <rules_profiles id="2"
- name="Sonar Way"
- language="js"
- organization_uuid="QualityProfileDaoTest-ORG"
- parent_kee="[null]"
- kee="js_sonar_way"
- is_built_in="[false]"
- rules_updated_at="[null]"
- created_at="[null]"
- updated_at="[null]"
- last_used="123456789"
- user_updated_at="987654321"/>
-</dataset>
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java
index 23d137c1142..787fa699238 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java
@@ -30,11 +30,11 @@ import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.new
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-public class CreateTableQProfiles extends DdlChange {
+public class CreateTableOrgQProfiles extends DdlChange {
- private static final String TABLE_NAME = "qprofiles";
+ private static final String TABLE_NAME = "org_qprofiles";
- public CreateTableQProfiles(Database db) {
+ public CreateTableOrgQProfiles(Database db) {
super(db);
}
@@ -46,21 +46,21 @@ public class CreateTableQProfiles extends DdlChange {
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
+ VarcharColumnDef rulesProfileUuid = newVarcharColumnDefBuilder()
+ .setColumnName("rules_profile_uuid")
+ .setLimit(UUID_SIZE)
+ .setIsNullable(false)
+ .setIgnoreOracleUnit(true)
+ .build();
context.execute(
new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newVarcharColumnDefBuilder()
.setColumnName("uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
- .setIgnoreOracleUnit(true)
.build())
.addColumn(organizationColumn)
- .addColumn(newVarcharColumnDefBuilder()
- .setColumnName("rules_profile_uuid")
- .setLimit(UUID_SIZE)
- .setIsNullable(false)
- .setIgnoreOracleUnit(true)
- .build())
+ .addColumn(rulesProfileUuid)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("parent_uuid")
.setLimit(UUID_SIZE)
@@ -83,5 +83,12 @@ public class CreateTableQProfiles extends DdlChange {
.setName("qprofiles_org_uuid")
.addColumn(organizationColumn)
.build());
+
+ context.execute(
+ new CreateIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName("qprofiles_rp_uuid")
+ .addColumn(rulesProfileUuid)
+ .build());
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
index a9956f20c78..abf295015e0 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
@@ -49,6 +49,7 @@ public class DbVersion65 implements DbVersion {
.add(1720, "Populate table default_qprofiles", PopulateTableDefaultQProfiles.class)
.add(1721, "Drop rules_profiles.is_default", DropIsDefaultColumnFromRulesProfiles.class)
.add(1722, "Create table qprofiles", CreateTableQProfiles.class)
- .add(1723, "Populate table qprofiles", PopulateQProfiles.class);
+ .add(1723, "Populate table qprofiles", PopulateQProfiles.class)
+ .add(1724, "Drop columns organization_uuid and parent_kee from rules_profiles", DropOrgUuidAndParentKeeFromRulesProfiles.class);
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java
new file mode 100644
index 00000000000..105c8fde6ab
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropOrgUuidAndParentKeeFromRulesProfiles extends DdlChange {
+
+ private static final String TABLE_NAME = "rules_profiles";
+
+ public DropOrgUuidAndParentKeeFromRulesProfiles(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "organization_uuid").build());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "parent_kee").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java
index a7505cd9d55..b8f35b3057a 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfiles.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java
@@ -26,11 +26,11 @@ import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
-public class PopulateQProfiles extends DataChange {
+public class PopulateOrgQProfiles extends DataChange {
private final System2 system2;
- public PopulateQProfiles(Database db, System2 system2) {
+ public PopulateOrgQProfiles(Database db, System2 system2) {
super(db);
this.system2 = system2;
}
@@ -41,15 +41,19 @@ public class PopulateQProfiles extends DataChange {
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select p.kee, p.organization_uuid, p.parent_kee from rules_profiles p " +
- "where not exists ( select qp.uuid from qprofiles qp where qp.uuid = p.kee and qp.organization_uuid = p.organization_uuid )");
- massUpdate.update("insert into qprofiles" +
+ "where not exists ( select qp.uuid from org_qprofiles qp where qp.uuid = p.kee and qp.organization_uuid = p.organization_uuid )");
+ massUpdate.update("insert into org_qprofiles" +
" (uuid, organization_uuid, rules_profile_uuid, parent_uuid, created_at, updated_at) values (?, ?, ?, ?, ?, ?)");
- massUpdate.rowPluralName("qprofiles");
+ massUpdate.rowPluralName("org_qprofiles");
massUpdate.execute((row, update) -> {
- update.setString(1, row.getString(1));
- update.setString(2, row.getString(2));
- update.setString(3, row.getString(1));
- update.setString(4, row.getString(3));
+ String uuid = row.getString(1);
+ String organizationUuid = row.getString(2);
+ String parentUuid = row.getString(3);
+
+ update.setString(1, uuid);
+ update.setString(2, organizationUuid);
+ update.setString(3, uuid);
+ update.setString(4, parentUuid);
update.setLong(5, now);
update.setLong(6, now);
return true;
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java
index 6ad59c3fdc5..d44d46715df 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java
@@ -29,16 +29,16 @@ import org.sonar.db.CoreDbTester;
import static org.assertj.core.api.Assertions.assertThat;
-public class CreateTableQProfilesTest {
+public class CreateTableOrgQProfilesTest {
- private static final String TABLE = "qprofiles";
+ private static final String TABLE = "org_qprofiles";
@Rule
- public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableQProfilesTest.class, "empty.sql");
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableOrgQProfilesTest.class, "empty.sql");
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private CreateTableQProfiles underTest = new CreateTableQProfiles(db.database());
+ private CreateTableOrgQProfiles underTest = new CreateTableOrgQProfiles(db.database());
@Test
public void creates_table_on_empty_db() throws SQLException {
@@ -47,12 +47,13 @@ public class CreateTableQProfilesTest {
assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0);
db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false);
- db.assertPrimaryKey(TABLE, "pk_qprofiles", "uuid");
+ db.assertPrimaryKey(TABLE, "pk_org_qprofiles", "uuid");
db.assertColumnDefinition(TABLE, "organization_uuid", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE, "rules_profile_uuid", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false);
db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false);
db.assertIndex(TABLE, "qprofiles_org_uuid", "organization_uuid");
+ db.assertIndex(TABLE, "qprofiles_rp_uuid", "rules_profile_uuid");
}
@Test
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
index a1f026d0fff..e9474738566 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
@@ -35,6 +35,6 @@ public class DbVersion65Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 24);
+ verifyMigrationCount(underTest, 25);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java
new file mode 100644
index 00000000000..f879628475b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropOrgUuidAndParentKeeFromRulesProfilesTest {
+
+ private static final String TABLE_NAME = "rules_profiles";
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropOrgUuidAndParentKeeFromRulesProfilesTest.class, "initial.sql");
+
+ private DropOrgUuidAndParentKeeFromRulesProfiles underTest = new DropOrgUuidAndParentKeeFromRulesProfiles(db.database());
+
+ @Test
+ public void columns_are_dropped() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist(TABLE_NAME, "organization_uuid");
+ db.assertColumnDoesNotExist(TABLE_NAME, "parent_kee");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java
index b4fb5dc578c..301fefc0e21 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java
@@ -35,16 +35,16 @@ import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
-public class PopulateQProfilesTest {
+public class PopulateOrgQProfilesTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public CoreDbTester db = CoreDbTester.createForSchema(PopulateQProfilesTest.class, "initial.sql");
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateOrgQProfilesTest.class, "initial.sql");
private System2 system2 = new AlwaysIncreasingSystem2();
- private PopulateQProfiles underTest = new PopulateQProfiles(db.database(), system2);
+ private PopulateOrgQProfiles underTest = new PopulateOrgQProfiles(db.database(), system2);
@Test
public void migration_is_reentrant() throws SQLException {
@@ -52,13 +52,13 @@ public class PopulateQProfilesTest {
insertRulesProfile("ORG_2", "js", "u2", "u1", true);
// org1 is already processed
- insertQProfile("u1", "ORG_1", "RPU1");
+ insertOrgQProfile("u1", "ORG_1", "RPU1");
underTest.execute();
assertThat(countRows()).isEqualTo(2);
- Map<String, Object> qprofile1 = selectQProfile("u1", "ORG_1");
- Map<String, Object> qprofile2 = selectQProfile("u2", "ORG_2");
+ Map<String, Object> qprofile1 = selectOrgQProfile("u1", "ORG_1");
+ Map<String, Object> qprofile2 = selectOrgQProfile("u2", "ORG_2");
assertThat(qprofile1.get("UUID")).isEqualTo("u1");
assertThat(qprofile1.get("ORGANIZATION_UUID")).isEqualTo("ORG_1");
@@ -86,7 +86,7 @@ public class PopulateQProfilesTest {
private int countRows() {
- return db.countRowsOfTable("qprofiles");
+ return db.countRowsOfTable("org_qprofiles");
}
private void insertRulesProfile(String orgUuid, String language, String uuid, String parentKee, boolean isDefault) {
@@ -100,8 +100,8 @@ public class PopulateQProfilesTest {
"IS_BUILT_IN", true);
}
- private void insertQProfile(String uuid, String orgUuid, String rulesProfileUuid) {
- db.executeInsert("QPROFILES",
+ private void insertOrgQProfile(String uuid, String orgUuid, String rulesProfileUuid) {
+ db.executeInsert("ORG_QPROFILES",
"ORGANIZATION_UUID", orgUuid,
"RULES_PROFILE_UUID", rulesProfileUuid,
"UUID", uuid,
@@ -110,7 +110,7 @@ public class PopulateQProfilesTest {
);
}
- private Map<String, Object> selectQProfile(String uuid, String orgUuid) {
- return db.selectFirst(format("select * from qprofiles where uuid='%s' and organization_uuid='%s'", uuid, orgUuid));
+ private Map<String, Object> selectOrgQProfile(String uuid, String orgUuid) {
+ return db.selectFirst(format("select * from org_qprofiles where uuid='%s' and organization_uuid='%s'", uuid, orgUuid));
}
}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql
index e69de29bb2d..e69de29bb2d 100644
--- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql
new file mode 100644
index 00000000000..7c1c1fedab0
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql
@@ -0,0 +1,15 @@
+CREATE TABLE "RULES_PROFILES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "NAME" VARCHAR(100) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(255) NOT NULL,
+ "PARENT_KEE" VARCHAR(255),
+ "RULES_UPDATED_AT" VARCHAR(100),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP,
+ "LAST_USED" BIGINT,
+ "USER_UPDATED_AT" BIGINT,
+ "IS_BUILT_IN" BOOLEAN NOT NULL
+);
+CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql
index df8bf1316ff..3d84b4a125f 100644
--- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest/initial.sql
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql
@@ -15,7 +15,7 @@ CREATE TABLE "RULES_PROFILES" (
);
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
-CREATE TABLE "QPROFILES" (
+CREATE TABLE "ORG_QPROFILES" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
@@ -23,4 +23,5 @@ CREATE TABLE "QPROFILES" (
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
-CREATE INDEX "QPROFILES_ORG_UUID" ON "QPROFILES" ("ORGANIZATION_UUID");
+CREATE INDEX "ORG_QPROFILES_ORG_UUID" ON "ORG_QPROFILES" ("ORGANIZATION_UUID");
+CREATE INDEX "ORG_QPROFILES_RP_UUID" ON "ORG_QPROFILES" ("RULES_PROFILE_UUID");
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
index b10b8745fb8..5898ef8b095 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
@@ -31,7 +31,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile;
import org.sonar.server.computation.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
@@ -107,10 +107,10 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
.map(QProfile::getKey)
.collect(toList(metadata.getQprofilesPerLanguage().size()));
try (DbSession dbSession = dbClient.openSession(false)) {
- List<RulesProfileDto> profiles = dbClient.qualityProfileDao().selectByKeys(dbSession, profileKeys);
+ List<QProfileDto> profiles = dbClient.qualityProfileDao().selectByUuids(dbSession, profileKeys);
String badKeys = profiles.stream()
.filter(p -> !p.getOrganizationUuid().equals(organization.getUuid()))
- .map(RulesProfileDto::getKee)
+ .map(QProfileDto::getKee)
.collect(MoreCollectors.join(Joiner.on(", ")));
if (!badKeys.isEmpty()) {
throw MessageException.of(format("Quality profiles with following keys don't exist in organization [%s]: %s", organization.getKey(), badKeys));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
index 968e6874896..97aa1f60f7c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
@@ -26,7 +26,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
@@ -68,7 +68,7 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
return;
}
- List<RulesProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
+ List<QProfileDto> dtos = dbClient.qualityProfileDao().selectByUuids(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
dtos.addAll(getAncestors(dbSession, dtos));
long analysisDate = analysisMetadataHolder.getAnalysisDate();
dtos.forEach(dto -> {
@@ -80,16 +80,16 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
}
}
- private List<RulesProfileDto> getAncestors(DbSession dbSession, List<RulesProfileDto> dtos) {
- List<RulesProfileDto> ancestors = new ArrayList<>();
+ private List<QProfileDto> getAncestors(DbSession dbSession, List<QProfileDto> dtos) {
+ List<QProfileDto> ancestors = new ArrayList<>();
dtos.forEach(dto -> incrementAncestors(dbSession, dto, ancestors));
return ancestors;
}
- private void incrementAncestors(DbSession session, RulesProfileDto profile, List<RulesProfileDto> ancestors) {
+ private void incrementAncestors(DbSession session, QProfileDto profile, List<QProfileDto> ancestors) {
String parentKey = profile.getParentKee();
if (parentKey != null) {
- RulesProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByKey(session, parentKey);
+ QProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByUuid(session, parentKey);
ancestors.add(parentDto);
incrementAncestors(session, parentDto, ancestors);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
index 5d11c6a0988..4b5d1cb9ae3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.organization.DefaultOrganization;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -134,9 +134,9 @@ public class DeleteAction implements OrganizationsWsAction {
}
private void deleteQualityProfiles(DbSession dbSession, OrganizationDto organization) {
- List<RulesProfileDto> profiles = dbClient.qualityProfileDao().selectAll(dbSession, organization);
+ List<QProfileDto> profiles = dbClient.qualityProfileDao().selectAll(dbSession, organization);
List<String> profileKeys = profiles.stream()
- .map(RulesProfileDto::getKee)
+ .map(QProfileDto::getKee)
.collect(MoreCollectors.toArrayList(profiles.size()));
qProfileFactory.deleteByKeys(dbSession, profileKeys);
dbSession.commit();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
index 532b81ed0eb..67d3b61a3a2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
@@ -47,7 +47,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.util.TypeValidations;
@@ -75,7 +75,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
initRuleRepository(batchSession);
Date now = new Date(system2.now());
- RulesProfileDto profileDto = insertQualityProfile(session, builtInQProfile, organization, now);
+ QProfileDto profileDto = insertQualityProfile(session, builtInQProfile, organization, now);
List<ActiveRuleChange> localChanges = builtInQProfile.getActiveRules()
.stream()
@@ -91,8 +91,8 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
}
}
- private RulesProfileDto insertQualityProfile(DbSession dbSession, BuiltInQProfile builtInQProfile, OrganizationDto organization, Date now) {
- RulesProfileDto profileDto = RulesProfileDto.createFor(uuidFactory.create())
+ private QProfileDto insertQualityProfile(DbSession dbSession, BuiltInQProfile builtInQProfile, OrganizationDto organization, Date now) {
+ QProfileDto profileDto = QProfileDto.createFor(uuidFactory.create())
.setName(builtInQProfile.getName())
.setOrganizationUuid(organization.getUuid())
.setLanguage(builtInQProfile.getLanguage())
@@ -105,7 +105,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
return profileDto;
}
- private ActiveRuleChange insertActiveRule(DbSession session, RulesProfileDto profileDto, org.sonar.api.rules.ActiveRule activeRule, long now) {
+ private ActiveRuleChange insertActiveRule(DbSession session, QProfileDto profileDto, org.sonar.api.rules.ActiveRule activeRule, long now) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
RuleDefinitionDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey)
.orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
index c641c53ed20..59feac2b206 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
@@ -24,14 +24,14 @@ import java.io.Writer;
import javax.annotation.Nullable;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
/**
* Backup and restore a Quality profile.
*/
public interface QProfileBackuper {
- void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter);
+ void backup(DbSession dbSession, QProfileDto profile, Writer backupWriter);
/**
* Restore backup on a profile in the specified organization. The parameter {@code overriddenProfileName}
@@ -43,5 +43,5 @@ public interface QProfileBackuper {
/**
* Restore backup on an existing profile.
*/
- QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile);
+ QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
index 69411175cd8..24e72bc5558 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
@@ -47,7 +47,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import static com.google.common.base.Preconditions.checkArgument;
@@ -82,13 +82,13 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}
@Override
- public void backup(DbSession dbSession, RulesProfileDto profileDto, Writer writer) {
+ public void backup(DbSession dbSession, QProfileDto profileDto, Writer writer) {
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKee());
activeRules.sort(BackupActiveRuleComparator.INSTANCE);
writeXml(dbSession, writer, profileDto, activeRules.iterator());
}
- private void writeXml(DbSession dbSession, Writer writer, RulesProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
+ private void writeXml(DbSession dbSession, Writer writer, QProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
XmlWriter xml = XmlWriter.of(writer).declaration();
xml.begin(ATTRIBUTE_PROFILE);
xml.prop(ATTRIBUTE_NAME, profile.getName());
@@ -126,7 +126,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}
@Override
- public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
+ public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile) {
return restore(dbSession, backup, nameInBackup -> {
checkArgument(profile.getLanguage().equals(nameInBackup.getLanguage()),
"Can't restore %s backup on %s profile with key [%s]. Languages are different.", nameInBackup.getLanguage(), profile.getLanguage(), profile.getKee());
@@ -134,7 +134,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
});
}
- private QProfileRestoreSummary restore(DbSession dbSession, Reader backup, Function<QProfileName, RulesProfileDto> profileLoader) {
+ private QProfileRestoreSummary restore(DbSession dbSession, Reader backup, Function<QProfileName, QProfileDto> profileLoader) {
try {
String profileLang = null;
String profileName = null;
@@ -161,7 +161,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}
QProfileName targetName = new QProfileName(profileLang, profileName);
- RulesProfileDto targetProfile = profileLoader.apply(targetName);
+ QProfileDto targetProfile = profileLoader.apply(targetName);
BulkChangeResult changes = profileReset.reset(dbSession, targetProfile, ruleActivations);
return new QProfileRestoreSummary(targetProfile, changes);
} catch (XMLStreamException e) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
index 3d316f432aa..8a995cbb048 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
@ServerSide
@ComputeEngineSide
@@ -48,7 +48,7 @@ public class QProfileComparison {
this.dbClient = dbClient;
}
- public QProfileComparisonResult compare(DbSession dbSession, RulesProfileDto left, RulesProfileDto right) {
+ public QProfileComparisonResult compare(DbSession dbSession, QProfileDto left, QProfileDto right) {
Map<RuleKey, ActiveRuleDto> leftActiveRulesByRuleKey = loadActiveRules(dbSession, left);
Map<RuleKey, ActiveRuleDto> rightActiveRulesByRuleKey = loadActiveRules(dbSession, right);
@@ -86,29 +86,29 @@ public class QProfileComparison {
}
}
- private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, RulesProfileDto profile) {
+ private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, QProfileDto profile) {
return Maps.uniqueIndex(dbClient.activeRuleDao().selectByProfileKey(session, profile.getKee()), ActiveRuleToRuleKey.INSTANCE);
}
public static class QProfileComparisonResult {
- private final RulesProfileDto left;
- private final RulesProfileDto right;
+ private final QProfileDto left;
+ private final QProfileDto right;
private final Map<RuleKey, ActiveRuleDto> inLeft = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDto> inRight = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDiff> modified = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDto> same = Maps.newHashMap();
- public QProfileComparisonResult(RulesProfileDto left, RulesProfileDto right) {
+ public QProfileComparisonResult(QProfileDto left, QProfileDto right) {
this.left = left;
this.right = right;
}
- public RulesProfileDto left() {
+ public QProfileDto left() {
return left;
}
- public RulesProfileDto right() {
+ public QProfileDto right() {
return right;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
index 8403b749d6f..b2fd1a69879 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
@@ -32,7 +32,7 @@ import org.sonar.api.utils.TempFolder;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -51,10 +51,10 @@ public class QProfileCopier {
this.temp = temp;
}
- public RulesProfileDto copyToName(DbSession dbSession, RulesProfileDto sourceProfile, String toName) {
+ public QProfileDto copyToName(DbSession dbSession, QProfileDto sourceProfile, String toName) {
OrganizationDto organization = db.organizationDao().selectByUuid(dbSession, sourceProfile.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException("Organization with UUID [" + sourceProfile.getOrganizationUuid() + "] does not exist"));
- RulesProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName);
+ QProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName);
File backupFile = temp.newFile();
try {
backup(dbSession, sourceProfile, backupFile);
@@ -65,10 +65,10 @@ public class QProfileCopier {
}
}
- private RulesProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, RulesProfileDto sourceProfile, String toName) {
+ private QProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, QProfileDto sourceProfile, String toName) {
QProfileName toProfileName = new QProfileName(sourceProfile.getLanguage(), toName);
verify(sourceProfile, toProfileName);
- RulesProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(organization, toProfileName.getName(), toProfileName.getLanguage(), dbSession);
+ QProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, toProfileName.getName(), toProfileName.getLanguage());
if (toProfile == null) {
toProfile = factory.checkAndCreateCustom(dbSession, organization, toProfileName);
toProfile.setParentKee(sourceProfile.getParentKee());
@@ -78,7 +78,7 @@ public class QProfileCopier {
return toProfile;
}
- private void verify(RulesProfileDto fromProfile, QProfileName toProfileName) {
+ private void verify(QProfileDto fromProfile, QProfileName toProfileName) {
if (!StringUtils.equals(fromProfile.getLanguage(), toProfileName.getLanguage())) {
throw new IllegalArgumentException(String.format(
"Source and target profiles do not have the same language: %s and %s",
@@ -90,7 +90,7 @@ public class QProfileCopier {
}
}
- private void backup(DbSession dbSession, RulesProfileDto profile, File backupFile) {
+ private void backup(DbSession dbSession, QProfileDto profile, File backupFile) {
try (Writer writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile), UTF_8)) {
backuper.backup(dbSession, profile, writer);
} catch (IOException e) {
@@ -98,7 +98,7 @@ public class QProfileCopier {
}
}
- private void restore(DbSession dbSession, File backupFile, RulesProfileDto profile) {
+ private void restore(DbSession dbSession, File backupFile, QProfileDto profile) {
try (Reader reader = new InputStreamReader(FileUtils.openInputStream(backupFile), UTF_8)) {
backuper.restore(dbSession, reader, profile);
} catch (IOException e) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
index 89f328d0a53..fc21a733039 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
@@ -44,7 +44,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
@@ -103,12 +103,12 @@ public class QProfileExporters {
return exporter.getMimeType();
}
- public void export(RulesProfileDto profile, String exporterKey, Writer writer) {
+ public void export(QProfileDto profile, String exporterKey, Writer writer) {
ProfileExporter exporter = findExporter(exporterKey);
exporter.exportProfile(wrap(profile), writer);
}
- private RulesProfile wrap(RulesProfileDto profile) {
+ private RulesProfile wrap(QProfileDto profile) {
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKee());
@@ -137,11 +137,11 @@ public class QProfileExporters {
throw new NotFoundException("Unknown quality profile exporter: " + exporterKey);
}
- public QProfileResult importXml(RulesProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) {
+ public QProfileResult importXml(QProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) {
return importXml(profileDto, importerKey, new InputStreamReader(xml, StandardCharsets.UTF_8), dbSession);
}
- private QProfileResult importXml(RulesProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
+ private QProfileResult importXml(QProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
QProfileResult result = new QProfileResult();
ValidationMessages messages = ValidationMessages.create();
ProfileImporter importer = getProfileImporter(importerKey);
@@ -152,7 +152,7 @@ public class QProfileExporters {
return result;
}
- private List<ActiveRuleChange> importProfile(RulesProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
+ private List<ActiveRuleChange> importProfile(QProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
List<ActiveRuleChange> changes = new ArrayList<>();
for (org.sonar.api.rules.ActiveRule activeRule : rulesProfile.getActiveRules()) {
changes.addAll(ruleActivator.activate(dbSession, toRuleActivation(activeRule), profileDto));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
index 0236aa15972..442dc90a98c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
@@ -30,7 +30,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
@@ -61,9 +61,9 @@ public class QProfileFactory {
return organization;
}
- RulesProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
+ QProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
requireNonNull(organization);
- RulesProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
+ QProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name.getName(), name.getLanguage());
if (profile == null) {
profile = doCreate(dbSession, organization, name, false, false);
} else {
@@ -78,9 +78,9 @@ public class QProfileFactory {
*
* @throws BadRequestException if a quality profile with the specified name already exists
*/
- public RulesProfileDto checkAndCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
+ public QProfileDto checkAndCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
requireNonNull(organization);
- RulesProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
+ QProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name.getName(), name.getLanguage());
checkRequest(dto == null, "Quality profile already exists: %s", name);
return doCreate(dbSession, organization, name, false, false);
}
@@ -90,16 +90,16 @@ public class QProfileFactory {
*
* A DB error will be thrown if the quality profile already exists.
*/
- public RulesProfileDto createBuiltIn(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault) {
+ public QProfileDto createBuiltIn(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault) {
return doCreate(dbSession, requireNonNull(organization), name, isDefault, true);
}
- private RulesProfileDto doCreate(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault, boolean isBuiltIn) {
+ private QProfileDto doCreate(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault, boolean isBuiltIn) {
if (StringUtils.isEmpty(name.getName())) {
throw BadRequestException.create("quality_profiles.profile_name_cant_be_blank");
}
Date now = new Date(system2.now());
- RulesProfileDto dto = RulesProfileDto.createFor(uuidFactory.create())
+ QProfileDto dto = QProfileDto.createFor(uuidFactory.create())
.setName(name.getName())
.setOrganizationUuid(organization.getUuid())
.setLanguage(name.getLanguage())
@@ -120,16 +120,16 @@ public class QProfileFactory {
* are deleted too. Deleting a parent profile does not delete descendants
* if their keys are not listed.
*/
- public void deleteByKeys(DbSession dbSession, Collection<String> profileKeys) {
- if (!profileKeys.isEmpty()) {
- db.qualityProfileDao().deleteProjectAssociationsByProfileKeys(dbSession, profileKeys);
- db.activeRuleDao().deleteParametersByProfileKeys(dbSession, profileKeys);
- db.activeRuleDao().deleteByProfileKeys(dbSession, profileKeys);
- db.qProfileChangeDao().deleteByProfileKeys(dbSession, profileKeys);
- db.defaultQProfileDao().deleteByQProfileUuids(dbSession, profileKeys);
- db.qualityProfileDao().deleteByKeys(dbSession, profileKeys);
+ public void deleteByKeys(DbSession dbSession, Collection<String> profileUuids) {
+ if (!profileUuids.isEmpty()) {
+ db.qualityProfileDao().deleteProjectAssociationsByProfileUuids(dbSession, profileUuids);
+ db.activeRuleDao().deleteParametersByProfileKeys(dbSession, profileUuids);
+ db.activeRuleDao().deleteByProfileKeys(dbSession, profileUuids);
+ db.qProfileChangeDao().deleteByProfileKeys(dbSession, profileUuids);
+ db.defaultQProfileDao().deleteByQProfileUuids(dbSession, profileUuids);
+ db.qualityProfileDao().deleteByUuids(dbSession, profileUuids);
dbSession.commit();
- activeRuleIndexer.deleteByProfileKeys(profileKeys);
+ activeRuleIndexer.deleteByProfileKeys(profileUuids);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
index db29f0ebe3c..77a7c5a6d0c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
@@ -19,12 +19,13 @@
*/
package org.sonar.server.qualityprofile;
+import java.util.Collection;
import java.util.List;
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import static com.google.common.collect.Lists.newArrayList;
@@ -37,23 +38,23 @@ public class QProfileLookup {
this.db = db;
}
- public List<RulesProfileDto> allProfiles(DbSession dbSession, OrganizationDto organization) {
+ public List<QProfileDto> allProfiles(DbSession dbSession, OrganizationDto organization) {
return db.qualityProfileDao().selectAll(dbSession, organization);
}
- public List<RulesProfileDto> profiles(DbSession dbSession, String language, OrganizationDto organization) {
+ public Collection<QProfileDto> profiles(DbSession dbSession, String language, OrganizationDto organization) {
return db.qualityProfileDao().selectByLanguage(dbSession, organization, language);
}
- public List<RulesProfileDto> ancestors(RulesProfileDto profile, DbSession session) {
- List<RulesProfileDto> ancestors = newArrayList();
+ public List<QProfileDto> ancestors(QProfileDto profile, DbSession session) {
+ List<QProfileDto> ancestors = newArrayList();
incrementAncestors(profile, ancestors, session);
return ancestors;
}
- private void incrementAncestors(RulesProfileDto profile, List<RulesProfileDto> ancestors, DbSession session) {
+ private void incrementAncestors(QProfileDto profile, List<QProfileDto> ancestors, DbSession session) {
if (profile.getParentKee() != null) {
- RulesProfileDto parentDto = db.qualityProfileDao().selectByKey(session, profile.getParentKee());
+ QProfileDto parentDto = db.qualityProfileDao().selectByUuid(session, profile.getParentKee());
if (parentDto == null) {
throw new IllegalStateException("Cannot find parent of profile : " + profile.getId());
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java
index 97d8ecea193..280cd87062f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java
@@ -21,12 +21,12 @@ package org.sonar.server.qualityprofile;
import java.util.Collection;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
public interface QProfileReset {
/**
* Reset the rules of the specified profile.
*/
- BulkChangeResult reset(DbSession dbSession, RulesProfileDto profile, Collection<RuleActivation> activations);
+ BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
index b4ae1d524cf..91cf16697c8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
@@ -30,7 +30,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
@@ -51,7 +51,7 @@ public class QProfileResetImpl implements QProfileReset {
}
@Override
- public BulkChangeResult reset(DbSession dbSession, RulesProfileDto profile, Collection<RuleActivation> activations) {
+ public BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations) {
requireNonNull(profile.getId(), "Quality profile must be persisted");
checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s'", profile.getKee());
BulkChangeResult result = new BulkChangeResult();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java
index b2d92b0a020..a78cd23a779 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java
@@ -19,20 +19,20 @@
*/
package org.sonar.server.qualityprofile;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import static java.util.Objects.requireNonNull;
public final class QProfileRestoreSummary {
- private final RulesProfileDto profile;
+ private final QProfileDto profile;
private final BulkChangeResult ruleChanges;
- public QProfileRestoreSummary(RulesProfileDto profile, BulkChangeResult ruleChanges) {
+ public QProfileRestoreSummary(QProfileDto profile, BulkChangeResult ruleChanges) {
this.profile = requireNonNull(profile);
this.ruleChanges = requireNonNull(ruleChanges);
}
- public RulesProfileDto getProfile() {
+ public QProfileDto getProfile() {
return profile;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
index bac92ad579d..39261221e64 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
@@ -21,14 +21,14 @@ package org.sonar.server.qualityprofile;
import java.util.ArrayList;
import java.util.List;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
public class QProfileResult {
private List<String> warnings;
private List<String> infos;
- private RulesProfileDto profile;
+ private QProfileDto profile;
private List<ActiveRuleChange> changes;
@@ -56,11 +56,11 @@ public class QProfileResult {
return this;
}
- public RulesProfileDto profile() {
+ public QProfileDto profile() {
return profile;
}
- public QProfileResult setProfile(RulesProfileDto profile) {
+ public QProfileResult setProfile(QProfileDto profile) {
this.profile = profile;
return this;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
index 544dd0385be..945fed7c534 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
@@ -104,12 +104,12 @@ public class RegisterQualityProfiles {
* built-in profile "Sonar way", which has probably different configuration.
*/
private void renameOutdatedProfiles(DbSession dbSession, BuiltInQProfile profile) {
- Collection<String> profileKeys = dbClient.qualityProfileDao().selectOutdatedProfiles(dbSession, profile.getLanguage(), profile.getName());
- if (profileKeys.isEmpty()) {
+ Collection<String> uuids = dbClient.qualityProfileDao().selectUuidsOfCustomRulesProfiles(dbSession, profile.getLanguage(), profile.getName());
+ if (uuids.isEmpty()) {
return;
}
String newName = profile.getName() + " (outdated copy)";
- LOGGER.info("Rename Quality profiles [{}/{}] to [{}] in {} organizations", profile.getLanguage(), profile.getName(), newName, profileKeys.size());
- dbClient.qualityProfileDao().renameAndCommit(dbSession, profileKeys, newName);
+ LOGGER.info("Rename Quality profiles [{}/{}] to [{}] in {} organizations", profile.getLanguage(), profile.getName(), newName, uuids.size());
+ dbClient.qualityProfileDao().renameRulesProfilesAndCommit(dbSession, uuids, newName);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
index 82b40aa1385..ae0c7c2fd69 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
@@ -38,7 +38,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -82,7 +82,7 @@ public class RuleActivator {
return doActivate(dbSession, activation, context);
}
- public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, RulesProfileDto profileDto) {
+ public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, QProfileDto profileDto) {
RuleActivatorContext context = contextFactory.create(profileDto, activation.getRuleKey(), dbSession);
return doActivate(dbSession, activation, context);
}
@@ -146,7 +146,7 @@ public class RuleActivator {
}
private void updateProfileDates(DbSession dbSession, RuleActivatorContext context) {
- RulesProfileDto profile = context.profile();
+ QProfileDto profile = context.profile();
profile.setRulesUpdatedAtAsDate(context.getInitDate());
if (userSession.isLoggedIn()) {
profile.setUserUpdatedAt(context.getInitDate().getTime());
@@ -224,20 +224,20 @@ public class RuleActivator {
return null;
}
- private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, RulesProfileDto rulesProfileDto) {
+ private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, QProfileDto qProfileDto) {
List<ActiveRuleChange> changes = Lists.newArrayList();
// get all inherited profiles
- String qualityProfileKey = rulesProfileDto.getKee();
- List<RulesProfileDto> children = getChildren(session, qualityProfileKey);
- for (RulesProfileDto child : children) {
+ String qualityProfileKey = qProfileDto.getKee();
+ List<QProfileDto> children = getChildren(session, qualityProfileKey);
+ for (QProfileDto child : children) {
RuleActivation childActivation = new RuleActivation(activation).setCascade(true);
changes.addAll(activate(session, childActivation, child));
}
return changes;
}
- protected List<RulesProfileDto> getChildren(DbSession session, String qualityProfileKey) {
+ protected List<QProfileDto> getChildren(DbSession session, String qualityProfileKey) {
return db.qualityProfileDao().selectChildren(session, qualityProfileKey);
}
@@ -370,9 +370,9 @@ public class RuleActivator {
persist(change, context, dbSession);
// get all inherited profiles
- List<RulesProfileDto> profiles = getChildren(dbSession, key.qProfile());
+ List<QProfileDto> profiles = getChildren(dbSession, key.qProfile());
- for (RulesProfileDto profile : profiles) {
+ for (QProfileDto profile : profiles) {
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKee(), key.ruleKey());
changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true, force));
}
@@ -457,14 +457,14 @@ public class RuleActivator {
}
public List<ActiveRuleChange> setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
- RulesProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
+ QProfileDto profile = db.qualityProfileDao().selectOrFailByUuid(dbSession, profileKey);
List<ActiveRuleChange> changes = new ArrayList<>();
if (parentKey == null) {
// unset if parent is defined, else nothing to do
changes.addAll(removeParent(dbSession, profile));
} else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
- RulesProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
+ QProfileDto parentProfile = db.qualityProfileDao().selectOrFailByUuid(dbSession, parentKey);
checkRequest(!isDescendant(dbSession, profile, parentProfile), "Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey);
changes.addAll(removeParent(dbSession, profile));
@@ -489,7 +489,7 @@ public class RuleActivator {
/**
* Does not commit
*/
- private List<ActiveRuleChange> removeParent(DbSession dbSession, RulesProfileDto profileDto) {
+ private List<ActiveRuleChange> removeParent(DbSession dbSession, QProfileDto profileDto) {
if (profileDto.getParentKee() != null) {
List<ActiveRuleChange> changes = new ArrayList<>();
profileDto.setParentKee(null);
@@ -509,15 +509,15 @@ public class RuleActivator {
return Collections.emptyList();
}
- boolean isDescendant(DbSession dbSession, RulesProfileDto childProfile, @Nullable RulesProfileDto parentProfile) {
- RulesProfileDto currentParent = parentProfile;
+ boolean isDescendant(DbSession dbSession, QProfileDto childProfile, @Nullable QProfileDto parentProfile) {
+ QProfileDto currentParent = parentProfile;
while (currentParent != null) {
if (childProfile.getName().equals(currentParent.getName())) {
return true;
}
String parentKey = currentParent.getParentKee();
if (parentKey != null) {
- currentParent = db.qualityProfileDao().selectByKey(dbSession, parentKey);
+ currentParent = db.qualityProfileDao().selectByUuid(dbSession, parentKey);
} else {
currentParent = null;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java
index bced651ea9c..4c26b20b50b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java
@@ -30,7 +30,7 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
@@ -41,7 +41,7 @@ class RuleActivatorContext {
private final Date initDate = new Date();
private RuleDefinitionDto rule;
private final Map<String, RuleParamDto> ruleParams = Maps.newHashMap();
- private RulesProfileDto profile;
+ private QProfileDto profile;
private ActiveRuleDto activeRule;
private ActiveRuleDto parentActiveRule;
private final Map<String, ActiveRuleParamDto> activeRuleParams = Maps.newHashMap();
@@ -83,11 +83,11 @@ class RuleActivatorContext {
return this;
}
- RulesProfileDto profile() {
+ QProfileDto profile() {
return profile;
}
- RuleActivatorContext setProfile(RulesProfileDto profile) {
+ RuleActivatorContext setProfile(QProfileDto profile) {
this.profile = profile;
return this;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
index 8b38d7ed5c0..2e280e1a00c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
@@ -29,7 +29,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
@@ -46,13 +46,13 @@ public class RuleActivatorContextFactory {
RuleActivatorContext create(String profileKey, RuleKey ruleKey, DbSession session) {
RuleActivatorContext context = new RuleActivatorContext();
- RulesProfileDto profile = getQualityProfileDto(session, profileKey);
+ QProfileDto profile = getQualityProfileDto(session, profileKey);
checkRequest(profile != null, "Quality profile not found: %s", profileKey);
context.setProfile(profile);
return create(ruleKey, session, context);
}
- RuleActivatorContext create(RulesProfileDto profile, RuleKey ruleKey, DbSession session) {
+ RuleActivatorContext create(QProfileDto profile, RuleKey ruleKey, DbSession session) {
return create(ruleKey, session, new RuleActivatorContext().setProfile(profile));
}
@@ -91,8 +91,8 @@ public class RuleActivatorContextFactory {
}
}
- RulesProfileDto getQualityProfileDto(DbSession session, String profileKey) {
- return db.qualityProfileDao().selectByKey(session, profileKey);
+ QProfileDto getQualityProfileDto(DbSession session, String profileKey) {
+ return db.qualityProfileDao().selectByUuid(session, profileKey);
}
Optional<RuleDefinitionDto> getRule(DbSession dbSession, RuleKey ruleKey) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
index bc84933d319..dac5a26ec57 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
@@ -27,10 +27,9 @@ import org.sonar.server.qualityprofile.ActiveRule;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ORGANIZATION_UUID;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ORGANIZATION_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY;
@@ -107,15 +106,6 @@ public class ActiveRuleDoc extends BaseDoc {
return this;
}
- long createdAt() {
- return (Long) getField(FIELD_ACTIVE_RULE_CREATED_AT);
- }
-
- public ActiveRuleDoc setCreatedAt(@Nullable Long l) {
- setField(FIELD_ACTIVE_RULE_CREATED_AT, l);
- return this;
- }
-
long updatedAt() {
return (Long) getField(FIELD_ACTIVE_RULE_UPDATED_AT);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
index ac003881fde..c4ef0eb089f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
@@ -37,21 +37,21 @@ import org.sonar.server.qualityprofile.ActiveRule;
public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc> {
private static final String[] FIELDS = {
- "a.failure_level",
- "a.inheritance",
+ "ar.failure_level",
+ "ar.inheritance",
"r.plugin_name",
"r.plugin_rule_key",
- "qp.organization_uuid",
- "qp.kee",
- "a.created_at",
- "a.updated_at"
+ "oqp.organization_uuid",
+ "oqp.uuid",
+ "ar.updated_at"
};
- private static final String SQL_ALL = "SELECT " + StringUtils.join(FIELDS, ",") + " FROM active_rules a " +
- "INNER JOIN rules_profiles qp ON qp.id=a.profile_id " +
- "INNER JOIN rules r ON r.id = a.rule_id";
+ private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from active_rules ar " +
+ " inner join rules_profiles rp on rp.id = ar.profile_id " +
+ " inner join org_qprofiles oqp on oqp.uuid = rp.kee " +
+ " inner join rules r on r.id = ar.rule_id ";
- private static final String SQL_AFTER_DATE = SQL_ALL + " WHERE a.updated_at>?";
+ private static final String SQL_AFTER_DATE = SQL_ALL + " where ar.updated_at>?";
private ActiveRuleResultSetIterator(PreparedStatement stmt) throws SQLException {
super(stmt);
@@ -86,8 +86,7 @@ public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc
doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
- doc.setCreatedAt(rs.getLong(7));
- doc.setUpdatedAt(rs.getLong(8));
+ doc.setUpdatedAt(rs.getLong(7));
return doc;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
index ae042d08121..494370f7cc2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
@@ -30,7 +30,7 @@ import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.ActiveRuleChange;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
@@ -107,7 +107,7 @@ public class ActivateRuleAction implements QProfileWsAction {
String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, profileKey);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java
index 0afa944d72d..431b262f3ff 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java
@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.rule.ws.RuleQueryFactory;
@@ -83,7 +83,7 @@ public class ActivateRulesAction implements QProfileWsAction {
userSession.checkLoggedIn();
BulkChangeResult result;
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, fromKey(qualityProfileKey));
+ QProfileDto profile = wsSupport.getProfile(dbSession, fromKey(qualityProfileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
result = ruleActivator.bulkActivate(ruleQueryFactory.createRuleQuery(dbSession, request), qualityProfileKey, request.param(SEVERITY));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java
index 953a4d1c63a..d0aef49c54e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.UserSession;
@@ -81,13 +81,13 @@ public class AddProjectAction implements QProfileWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = loadProject(dbSession, request);
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) {
throw new IllegalArgumentException("Project and Quality profile must have same organization");
}
- RulesProfileDto currentProfile = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage());
+ QProfileDto currentProfile = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage());
if (currentProfile == null) {
// project uses the default profile
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java
index 925d5a915b0..f1fa2df66a7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java
@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonarqube.ws.MediaTypes;
@@ -69,7 +69,7 @@ public class BackupAction implements QProfileWsAction {
try (OutputStreamWriter writer = new OutputStreamWriter(stream.output(), UTF_8);
DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
response.setHeader("Content-Disposition", String.format("attachment; filename=%s.xml", profile.getKee()));
backuper.backup(dbSession, profile, writer);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java
index 90781127d12..2e97b124011 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java
@@ -28,7 +28,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.user.UserSession;
@@ -85,7 +85,7 @@ public class ChangeParentAction implements QProfileWsAction {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
+ QProfileDto profile = wsSupport.getProfile(dbSession, reference);
String organizationUuid = profile.getOrganizationUuid();
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find organization with uuid '%s' of profile '%s'", organizationUuid, profile.getKee())));
@@ -100,7 +100,7 @@ public class ChangeParentAction implements QProfileWsAction {
String parentOrganizationKey = parentKey == null ? organization.getKey() : null;
String parentLanguage = parentKey == null ? request.param(PARAM_LANGUAGE) : null;
QProfileReference parentRef = QProfileReference.from(parentKey, parentOrganizationKey, parentLanguage, parentName);
- RulesProfileDto parent = wsSupport.getProfile(dbSession, parentRef);
+ QProfileDto parent = wsSupport.getProfile(dbSession, parentRef);
ruleActivator.setParent(dbSession, profile.getKee(), parent.getKee());
}
response.noContent();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
index 972c1d5e582..5d0877f0b6f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
@@ -32,7 +32,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QProfileChangeQuery;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
@@ -84,7 +84,7 @@ public class ChangelogAction implements QProfileWsAction {
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
+ QProfileDto profile = wsSupport.getProfile(dbSession, reference);
QProfileChangeQuery query = new QProfileChangeQuery(profile.getKee());
Date since = parseStartingDateOrDateTime(request.param(PARAM_SINCE));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java
index 2a0cf91dfb6..e04b6e121db 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java
@@ -58,7 +58,7 @@ public class ChangelogLoader {
.collect(MoreCollectors.toList(dtos.size()));
completeUserAndRuleNames(dbSession, changes);
- int total = dbClient.qProfileChangeDao().countForProfileKey(dbSession, query.getProfileKey());
+ int total = dbClient.qProfileChangeDao().countForProfileUuid(dbSession, query.getProfileUuid());
return new Changelog(total, changes);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java
index aa5dd97602f..6bd6685c4d0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java
@@ -39,7 +39,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleRepositoryDto;
import org.sonar.server.qualityprofile.QProfileComparison;
@@ -104,9 +104,9 @@ public class CompareAction implements QProfileWsAction {
String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto left = dbClient.qualityProfileDao().selectByKey(dbSession, leftKey);
+ QProfileDto left = dbClient.qualityProfileDao().selectByUuid(dbSession, leftKey);
checkArgument(left != null, "Could not find left profile '%s'", leftKey);
- RulesProfileDto right = dbClient.qualityProfileDao().selectByKey(dbSession, rightKey);
+ QProfileDto right = dbClient.qualityProfileDao().selectByUuid(dbSession, rightKey);
checkArgument(right != null, "Could not find right profile '%s'", rightKey);
checkArgument(Objects.equals(left.getOrganizationUuid(), right.getOrganizationUuid()),
@@ -148,7 +148,7 @@ public class CompareAction implements QProfileWsAction {
json.endObject().close();
}
- private void writeProfile(JsonWriter json, RulesProfileDto profile) {
+ private void writeProfile(JsonWriter json, QProfileDto profile) {
json.prop(ATTRIBUTE_KEY, profile.getKee())
.prop(ATTRIBUTE_NAME, profile.getName());
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java
index 03a6437866f..114f78c5a73 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java
@@ -29,7 +29,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileCopier;
import org.sonar.server.user.UserSession;
@@ -79,10 +79,10 @@ public class CopyAction implements QProfileWsAction {
String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto sourceProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
+ QProfileDto sourceProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, sourceProfile.getOrganizationUuid());
- RulesProfileDto copiedProfile = profileCopier.copyToName(dbSession, sourceProfile, newName);
+ QProfileDto copiedProfile = profileCopier.copyToName(dbSession, sourceProfile, newName);
boolean isDefault = dbClient.defaultQProfileDao().isDefault(dbSession, copiedProfile.getOrganizationUuid(), copiedProfile.getKee());
String languageKey = copiedProfile.getLanguage();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
index e0a165cef48..d97b94dc620 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
@@ -29,7 +29,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileName;
@@ -123,7 +123,7 @@ public class CreateAction implements QProfileWsAction {
private CreateWsResponse doHandle(DbSession dbSession, CreateRequest createRequest, Request request, OrganizationDto organization) {
QProfileResult result = new QProfileResult();
- RulesProfileDto profile = profileFactory.checkAndCreateCustom(dbSession, organization,
+ QProfileDto profile = profileFactory.checkAndCreateCustom(dbSession, organization,
QProfileName.createFor(createRequest.getLanguage(), createRequest.getProfileName()));
result.setProfile(profile);
for (ProfileImporter importer : importers) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
index 43ae0be68b9..d1344c9d6d2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
@@ -28,7 +28,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.user.UserSession;
@@ -76,7 +76,7 @@ public class DeactivateRuleAction implements QProfileWsAction {
String qualityProfileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(qualityProfileKey, ruleKey);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java
index 862be86aa71..aa82dc3615d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java
@@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.rule.ws.RuleQueryFactory;
@@ -77,7 +77,7 @@ public class DeactivateRulesAction implements QProfileWsAction {
userSession.checkLoggedIn();
BulkChangeResult result;
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
result = ruleActivator.bulkDeactivate(ruleQueryFactory.createRuleQuery(dbSession, request), qualityProfileKey);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
index 8e838d80b79..f88014d8195 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
@@ -31,7 +31,7 @@ import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.user.UserSession;
@@ -72,11 +72,11 @@ public class DeleteAction implements QProfileWsAction {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, profile.getOrganizationUuid());
wsSupport.checkNotBuiltInt(profile);
- List<RulesProfileDto> descendants = selectDescendants(dbSession, profile);
+ List<QProfileDto> descendants = selectDescendants(dbSession, profile);
ensureNoneIsMarkedAsDefault(dbSession, profile, descendants);
profileFactory.deleteByKeys(dbSession, toKeys(profile, descendants));
@@ -85,11 +85,11 @@ public class DeleteAction implements QProfileWsAction {
response.noContent();
}
- private List<RulesProfileDto> selectDescendants(DbSession dbSession, RulesProfileDto profile) {
+ private List<QProfileDto> selectDescendants(DbSession dbSession, QProfileDto profile) {
return dbClient.qualityProfileDao().selectDescendants(dbSession, profile.getKee());
}
- private void ensureNoneIsMarkedAsDefault(DbSession dbSession, RulesProfileDto profile, List<RulesProfileDto> descendants) {
+ private void ensureNoneIsMarkedAsDefault(DbSession dbSession, QProfileDto profile, List<QProfileDto> descendants) {
Set<String> allUuids = new HashSet<>();
allUuids.add(profile.getKee());
descendants.forEach(p -> allUuids.add(p.getKee()));
@@ -105,9 +105,9 @@ public class DeleteAction implements QProfileWsAction {
});
}
- private static List<String> toKeys(RulesProfileDto profile, List<RulesProfileDto> descendants) {
+ private static List<String> toKeys(QProfileDto profile, List<QProfileDto> descendants) {
return Stream.concat(Stream.of(profile), descendants.stream())
- .map(RulesProfileDto::getKee)
+ .map(QProfileDto::getKee)
.collect(MoreCollectors.toList(descendants.size() + 1));
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
index d7b88cb8d6a..ecf0cf89f0a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
@@ -38,7 +38,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.util.LanguageParamUtils;
@@ -111,12 +111,12 @@ public class ExportAction implements QProfileWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
- RulesProfileDto profile = loadProfile(dbSession, organization, language, name);
+ QProfileDto profile = loadProfile(dbSession, organization, language, name);
writeResponse(dbSession, profile, exporterKey, response);
}
}
- private void writeResponse(DbSession dbSession, RulesProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
+ private void writeResponse(DbSession dbSession, QProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
Stream stream = response.stream();
try (
OutputStream output = response.stream().output();
@@ -131,13 +131,13 @@ public class ExportAction implements QProfileWsAction {
}
}
- private RulesProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) {
- RulesProfileDto profile;
+ private QProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) {
+ QProfileDto profile;
if (name == null) {
// return the default profile
profile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, organization, language);
} else {
- profile = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, name, language, dbSession);
+ profile = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name, language);
}
return checkFound(profile, "Could not find profile with name '%s' for language '%s'", name, language);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java
index 829ecc69a72..69f0b9ad739 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java
@@ -32,7 +32,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse;
import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse.QualityProfile;
@@ -71,19 +71,19 @@ public class InheritanceAction implements QProfileWsAction {
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
+ QProfileDto profile = wsSupport.getProfile(dbSession, reference);
String organizationUuid = profile.getOrganizationUuid();
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find organization with uuid '%s' for quality profile '%s'", organizationUuid, profile.getKee())));
- List<RulesProfileDto> ancestors = profileLookup.ancestors(profile, dbSession);
- List<RulesProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKee());
+ List<QProfileDto> ancestors = profileLookup.ancestors(profile, dbSession);
+ List<QProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKee());
Statistics statistics = new Statistics(dbSession, organization);
writeProtobuf(buildResponse(profile, ancestors, children, statistics), request, response);
}
}
- private static InheritanceWsResponse buildResponse(RulesProfileDto profile, List<RulesProfileDto> ancestors, List<RulesProfileDto> children, Statistics statistics) {
+ private static InheritanceWsResponse buildResponse(QProfileDto profile, List<QProfileDto> ancestors, List<QProfileDto> children, Statistics statistics) {
return InheritanceWsResponse.newBuilder()
.setProfile(buildProfile(profile, statistics))
.addAllAncestors(buildAncestors(ancestors, statistics))
@@ -91,19 +91,19 @@ public class InheritanceAction implements QProfileWsAction {
.build();
}
- private static Iterable<QualityProfile> buildAncestors(List<RulesProfileDto> ancestors, Statistics statistics) {
+ private static Iterable<QualityProfile> buildAncestors(List<QProfileDto> ancestors, Statistics statistics) {
return ancestors.stream()
.map(ancestor -> buildProfile(ancestor, statistics))
.collect(Collectors.toList());
}
- private static Iterable<QualityProfile> buildChildren(List<RulesProfileDto> children, Statistics statistics) {
+ private static Iterable<QualityProfile> buildChildren(List<QProfileDto> children, Statistics statistics) {
return children.stream()
.map(child -> buildProfile(child, statistics))
.collect(Collectors.toList());
}
- private static QualityProfile buildProfile(RulesProfileDto qualityProfile, Statistics statistics) {
+ private static QualityProfile buildProfile(QProfileDto qualityProfile, Statistics statistics) {
String key = qualityProfile.getKee();
QualityProfile.Builder builder = QualityProfile.newBuilder()
.setKey(key)
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
index af4a35fb627..fd026b29ba9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
@@ -32,7 +32,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -102,7 +102,7 @@ public class OldRestoreAction implements WsAction {
}
private void writeResponse(JsonWriter json, QProfileRestoreSummary result) {
- RulesProfileDto profile = result.getProfile();
+ QProfileDto profile = result.getProfile();
String languageKey = profile.getLanguage();
Language language = languages.get(languageKey);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java
index cae23968911..bf1b85c41a8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java
@@ -40,7 +40,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ProjectQprofileAssociationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
@@ -129,22 +129,22 @@ public class ProjectsAction implements QProfileWsAction {
}
private void checkProfileExists(String profileKey, DbSession session) {
- if (dbClient.qualityProfileDao().selectByKey(session, profileKey) == null) {
+ if (dbClient.qualityProfileDao().selectByUuid(session, profileKey) == null) {
throw new NotFoundException(String.format("Could not find a quality profile with key '%s'", profileKey));
}
}
private List<ProjectQprofileAssociationDto> loadProjects(String profileKey, DbSession session, String selected, String query) {
- RulesProfileDto qualityProfile = dbClient.qualityProfileDao().selectByKey(session, profileKey);
- OrganizationDto organization = wsSupport.getOrganization(session, qualityProfile);
+ QProfileDto profile = dbClient.qualityProfileDao().selectByUuid(session, profileKey);
+ OrganizationDto organization = wsSupport.getOrganization(session, profile);
List<ProjectQprofileAssociationDto> projects = Lists.newArrayList();
SelectionMode selectionMode = SelectionMode.fromParam(selected);
if (SelectionMode.SELECTED == selectionMode) {
- projects.addAll(dbClient.qualityProfileDao().selectSelectedProjects(organization, profileKey, query, session));
+ projects.addAll(dbClient.qualityProfileDao().selectSelectedProjects(session, organization, profile, query));
} else if (SelectionMode.DESELECTED == selectionMode) {
- projects.addAll(dbClient.qualityProfileDao().selectDeselectedProjects(organization, profileKey, query, session));
+ projects.addAll(dbClient.qualityProfileDao().selectDeselectedProjects(session, organization, profile, query));
} else {
- projects.addAll(dbClient.qualityProfileDao().selectProjectAssociations(organization, profileKey, query, session));
+ projects.addAll(dbClient.qualityProfileDao().selectProjectAssociations(session, organization, profile, query));
}
return projects;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java
index 824b1fd14e9..cdbdd95ba6c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java
@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.WsUtils;
@@ -60,7 +60,7 @@ public class QProfileWsSupport {
.setExampleValue("my-org");
}
- public OrganizationDto getOrganization(DbSession dbSession, RulesProfileDto profile) {
+ public OrganizationDto getOrganization(DbSession dbSession, QProfileDto profile) {
requireNonNull(profile);
String organizationUuid = profile.getOrganizationUuid();
return dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
@@ -80,26 +80,26 @@ public class QProfileWsSupport {
*
* @throws org.sonar.server.exceptions.NotFoundException if the specified organization or profile do not exist
*/
- public RulesProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
- RulesProfileDto profile;
+ public QProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
+ QProfileDto profile;
if (ref.hasKey()) {
- profile = dbClient.qualityProfileDao().selectByKey(dbSession, ref.getKey());
+ profile = dbClient.qualityProfileDao().selectByUuid(dbSession, ref.getKey());
checkFound(profile, "Quality Profile with key '%s' does not exist", ref.getKey());
} else {
OrganizationDto org = getOrganizationByKey(dbSession, ref.getOrganizationKey().orElse(null));
- profile = dbClient.qualityProfileDao().selectByNameAndLanguage(org, ref.getName(), ref.getLanguage(), dbSession);
+ profile = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, org, ref.getName(), ref.getLanguage());
checkFound(profile, "Quality Profile for language '%s' and name '%s' does not exist%s", ref.getLanguage(), ref.getName(),
ref.getOrganizationKey().map(o -> " in organization '" + o + "'").orElse(""));
}
return profile;
}
- public void checkPermission(DbSession dbSession, RulesProfileDto rulesProfile) {
+ public void checkPermission(DbSession dbSession, QProfileDto rulesProfile) {
OrganizationDto organization = getOrganization(dbSession, rulesProfile);
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
}
- public void checkNotBuiltInt(RulesProfileDto profile) {
+ public void checkNotBuiltInt(QProfileDto profile) {
checkRequest(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s' with language '%s'", profile.getName(), profile.getLanguage());
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java
index 393ad87fb98..035890436f7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.UserSession;
@@ -80,7 +80,7 @@ public class RemoveProjectAction implements QProfileWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = loadProject(dbSession, request);
- RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
+ QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) {
throw new IllegalArgumentException("Project and Quality profile must have same organization");
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java
index 1d46426707b..f6b43612c1e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java
@@ -30,7 +30,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.user.UserSession;
@@ -89,7 +89,7 @@ public class RenameAction implements QProfileWsAction {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto qualityProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
+ QProfileDto qualityProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
String organizationUuid = qualityProfile.getOrganizationUuid();
userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, organizationUuid);
@@ -99,7 +99,7 @@ public class RenameAction implements QProfileWsAction {
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException("No organization found for uuid " + organizationUuid));
String language = qualityProfile.getLanguage();
- ofNullable(dbClient.qualityProfileDao().selectByNameAndLanguage(organization, newName, language, dbSession))
+ ofNullable(dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, newName, language))
.ifPresent(found -> {
throw BadRequestException.create(format("Quality profile already exists: %s", newName));
});
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java
index 0e6d3037006..eed6317380a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java
@@ -31,7 +31,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -102,7 +102,7 @@ public class RestoreAction implements QProfileWsAction {
}
private void writeResponse(JsonWriter json, OrganizationDto organization, QProfileRestoreSummary summary) {
- RulesProfileDto profile = summary.getProfile();
+ QProfileDto profile = summary.getProfile();
String languageKey = profile.getLanguage();
Language language = languages.get(languageKey);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
index bba002aa86e..50ff44d7a87 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.util.LanguageParamUtils;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
@@ -156,15 +156,15 @@ public class SearchAction implements QProfileWsAction {
}
}
- List<RulesProfileDto> profiles = dataLoader.findProfiles(dbSession, request, organization, project);
- Set<String> defaultProfiles = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, organization.getUuid(), profiles.stream().map(RulesProfileDto::getKee).collect(MoreCollectors.toList()));
+ List<QProfileDto> profiles = dataLoader.findProfiles(dbSession, request, organization, project);
+ Set<String> defaultProfiles = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, organization.getUuid(), profiles.stream().map(QProfileDto::getKee).collect(MoreCollectors.toList()));
return new SearchData()
.setOrganization(organization)
.setProfiles(profiles)
.setActiveRuleCountByProfileKey(dbClient.activeRuleDao().countActiveRulesByProfileKey(dbSession, organization))
.setActiveDeprecatedRuleCountByProfileKey(dbClient.activeRuleDao().countActiveRulesForRuleStatusByProfileKey(dbSession, organization, RuleStatus.DEPRECATED))
- .setProjectCountByProfileKey(dbClient.qualityProfileDao().countProjectsByProfileKey(dbSession, organization))
+ .setProjectCountByProfileKey(dbClient.qualityProfileDao().countProjectsByProfileUuid(dbSession, organization))
.setDefaultProfileKeys(defaultProfiles);
}
}
@@ -190,12 +190,12 @@ public class SearchAction implements QProfileWsAction {
}
private SearchWsResponse buildResponse(SearchData data) {
- List<RulesProfileDto> profiles = data.getProfiles();
- Map<String, RulesProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(RulesProfileDto::getKee, identity()));
+ List<QProfileDto> profiles = data.getProfiles();
+ Map<String, QProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(QProfileDto::getKee, identity()));
SearchWsResponse.Builder response = SearchWsResponse.newBuilder();
- for (RulesProfileDto profile : profiles) {
+ for (QProfileDto profile : profiles) {
QualityProfile.Builder profileBuilder = response.addProfilesBuilder();
String profileKey = profile.getKee();
@@ -222,7 +222,7 @@ public class SearchAction implements QProfileWsAction {
return response.build();
}
- private void writeLanguageFields(QualityProfile.Builder profileBuilder, RulesProfileDto profile) {
+ private void writeLanguageFields(QualityProfile.Builder profileBuilder, QProfileDto profile) {
String languageKey = profile.getLanguage();
if (languageKey == null) {
return;
@@ -235,14 +235,14 @@ public class SearchAction implements QProfileWsAction {
}
}
- private static void writeParentFields(QualityProfile.Builder profileBuilder, RulesProfileDto profile, Map<String, RulesProfileDto> profilesByKey) {
+ private static void writeParentFields(QualityProfile.Builder profileBuilder, QProfileDto profile, Map<String, QProfileDto> profilesByKey) {
String parentKey = profile.getParentKee();
if (parentKey == null) {
return;
}
profileBuilder.setParentKey(parentKey);
- RulesProfileDto parent = profilesByKey.get(parentKey);
+ QProfileDto parent = profilesByKey.get(parentKey);
if (parent != null && parent.getName() != null) {
profileBuilder.setParentName(parent.getName());
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java
index 8f98ab7367d..be04202b33d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java
@@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.ImmutableList.copyOf;
@@ -31,7 +31,7 @@ import static com.google.common.collect.ImmutableMap.copyOf;
public class SearchData {
private OrganizationDto organization;
- private List<RulesProfileDto> profiles;
+ private List<QProfileDto> profiles;
private Map<String, Long> activeRuleCountByProfileKey;
private Map<String, Long> activeDeprecatedRuleCountByProfileKey;
private Map<String, Long> projectCountByProfileKey;
@@ -46,11 +46,11 @@ public class SearchData {
return organization;
}
- public List<RulesProfileDto> getProfiles() {
+ public List<QProfileDto> getProfiles() {
return profiles;
}
- public SearchData setProfiles(List<RulesProfileDto> profiles) {
+ public SearchData setProfiles(List<QProfileDto> profiles) {
this.profiles = copyOf(profiles);
return this;
}
@@ -82,7 +82,7 @@ public class SearchData {
return firstNonNull(activeDeprecatedRuleCountByProfileKey.get(profileKey), 0L);
}
- boolean isDefault(RulesProfileDto profile) {
+ boolean isDefault(QProfileDto profile) {
return defaultProfileKeys.contains(profile.getKee());
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
index 39449bf75cc..dcc7f8cadcb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.client.qualityprofile.SearchWsRequest;
@@ -44,9 +44,9 @@ import static java.lang.String.format;
public class SearchDataLoader {
- private static final Comparator<RulesProfileDto> Q_PROFILE_COMPARATOR = Comparator
- .comparing(RulesProfileDto::getLanguage)
- .thenComparing(RulesProfileDto::getName);
+ private static final Comparator<QProfileDto> Q_PROFILE_COMPARATOR = Comparator
+ .comparing(QProfileDto::getLanguage)
+ .thenComparing(QProfileDto::getName);
private final Languages languages;
private final QProfileLookup profileLookup;
@@ -59,8 +59,8 @@ public class SearchDataLoader {
}
@VisibleForTesting
- List<RulesProfileDto> findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) {
- Collection<RulesProfileDto> profiles;
+ List<QProfileDto> findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) {
+ Collection<QProfileDto> profiles;
if (askDefaultProfiles(request)) {
profiles = findDefaultProfiles(dbSession, request, organization);
} else if (project != null) {
@@ -72,11 +72,11 @@ public class SearchDataLoader {
return profiles.stream().sorted(Q_PROFILE_COMPARATOR).collect(Collectors.toList());
}
- private Collection<RulesProfileDto> findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
+ private Collection<QProfileDto> findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
String profileName = request.getProfileName();
Set<String> languageKeys = getLanguageKeys();
- Map<String, RulesProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
+ Map<String, QProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
Set<String> missingLanguageKeys = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName);
Set<String> noDefaultProfileLanguageKeys = lookupDefaults(dbSession, organization, qualityProfiles, missingLanguageKeys);
@@ -88,11 +88,11 @@ public class SearchDataLoader {
return qualityProfiles.values();
}
- private Collection<RulesProfileDto> findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) {
+ private Collection<QProfileDto> findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) {
String profileName = request.getProfileName();
Set<String> languageKeys = getLanguageKeys();
- Map<String, RulesProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
+ Map<String, QProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
// look up profiles by profileName (if any) for each language
Set<String> unresolvedLanguages = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName);
@@ -108,7 +108,7 @@ public class SearchDataLoader {
return qualityProfiles.values();
}
- private List<RulesProfileDto> findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
+ private Collection<QProfileDto> findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
String language = request.getLanguage();
if (language == null) {
@@ -117,20 +117,20 @@ public class SearchDataLoader {
return profileLookup.profiles(dbSession, language, organization);
}
- private Set<String> lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys,
- @Nullable String profileName) {
+ private Set<String> lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map<String, QProfileDto> qualityProfiles, Set<String> languageKeys,
+ @Nullable String profileName) {
if (languageKeys.isEmpty() || profileName == null) {
return languageKeys;
}
- dbClient.qualityProfileDao().selectByNameAndLanguages(organization, profileName, languageKeys, dbSession)
+ dbClient.qualityProfileDao().selectByNameAndLanguages(dbSession, organization, profileName, languageKeys)
.forEach(qualityProfile -> qualityProfiles
.put(qualityProfile.getLanguage(), qualityProfile));
return difference(languageKeys, qualityProfiles.keySet());
}
- private Set<String> lookupByModule(DbSession dbSession, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys,
- ComponentDto project) {
+ private Set<String> lookupByModule(DbSession dbSession, Map<String, QProfileDto> qualityProfiles, Set<String> languageKeys,
+ ComponentDto project) {
if (languageKeys.isEmpty()) {
return languageKeys;
}
@@ -140,7 +140,7 @@ public class SearchDataLoader {
return difference(languageKeys, qualityProfiles.keySet());
}
- private Set<String> lookupDefaults(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys) {
+ private Set<String> lookupDefaults(DbSession dbSession, OrganizationDto organization, Map<String, QProfileDto> qualityProfiles, Set<String> languageKeys) {
if (languageKeys.isEmpty()) {
return languageKeys;
}
@@ -153,7 +153,7 @@ public class SearchDataLoader {
return Sets.newHashSet(Sets.difference(languageKeys, set2));
}
- private static void addAll(Map<String, RulesProfileDto> qualityProfiles, Collection<RulesProfileDto> list) {
+ private static void addAll(Map<String, QProfileDto> qualityProfiles, Collection<QProfileDto> list) {
list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), qualityProfile));
}
@@ -161,7 +161,7 @@ public class SearchDataLoader {
return Arrays.stream(languages.all()).map(Language::getKey).collect(Collectors.toSet());
}
- private List<RulesProfileDto> findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set<String> languageKeys) {
+ private List<QProfileDto> findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set<String> languageKeys) {
return dbClient.qualityProfileDao().selectDefaultProfiles(dbSession, organization, languageKeys);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java
index 54a9bc5f846..fc4069c27c0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.user.UserSession;
import static java.lang.String.format;
@@ -66,7 +66,7 @@ public class SetDefaultAction implements QProfileWsAction {
userSession.checkLoggedIn();
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
- RulesProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference);
+ QProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference);
dbClient.organizationDao().selectByUuid(dbSession, qualityProfile.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(
format("Cannot find organization '%s' for quality profile '%s'", qualityProfile.getOrganizationUuid(), qualityProfile.getKee())));
@@ -77,7 +77,7 @@ public class SetDefaultAction implements QProfileWsAction {
response.noContent();
}
- public void setDefault(DbSession dbSession, RulesProfileDto profile) {
+ public void setDefault(DbSession dbSession, QProfileDto profile) {
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
index 3fac16bec40..6bbe9d31295 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
@@ -78,7 +78,6 @@ public class RuleIndexDefinition implements IndexDefinition {
public static final String FIELD_ACTIVE_RULE_PROFILE_KEY = "profile";
public static final String FIELD_ACTIVE_RULE_SEVERITY = "severity";
public static final String FIELD_ACTIVE_RULE_RULE_KEY = "ruleKey";
- public static final String FIELD_ACTIVE_RULE_CREATED_AT = "createdAt";
public static final String FIELD_ACTIVE_RULE_UPDATED_AT = "updatedAt";
private final Settings settings;
@@ -106,8 +105,6 @@ public class RuleIndexDefinition implements IndexDefinition {
activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_KEY).disableNorms().build();
activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build();
activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
-
- activeRuleMapping.createLongField(FIELD_ACTIVE_RULE_CREATED_AT);
activeRuleMapping.createLongField(FIELD_ACTIVE_RULE_UPDATED_AT);
// Rule extension type
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
index 21d42e8ed9f..5c27668f370 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
@@ -44,7 +44,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.qualityprofile.ActiveRule;
@@ -178,10 +178,10 @@ public class ActiveRuleCompleter {
}
private Rules.QProfiles.Builder buildQProfiles(DbSession dbSession, Collection<String> harvestedProfileKeys) {
- Map<String, RulesProfileDto> qProfilesByKey = new HashMap<>();
+ Map<String, QProfileDto> qProfilesByKey = new HashMap<>();
for (String qProfileKey : harvestedProfileKeys) {
if (!qProfilesByKey.containsKey(qProfileKey)) {
- RulesProfileDto profile = loadProfile(dbSession, qProfileKey);
+ QProfileDto profile = loadProfile(dbSession, qProfileKey);
if (profile == null) {
LOG.warn("Could not find quality profile with key " + qProfileKey);
continue;
@@ -196,7 +196,7 @@ public class ActiveRuleCompleter {
Rules.QProfiles.Builder qProfilesResponse = Rules.QProfiles.newBuilder();
Map<String, Rules.QProfile> qProfilesMapResponse = qProfilesResponse.getMutableQProfiles();
- for (RulesProfileDto profile : qProfilesByKey.values()) {
+ for (QProfileDto profile : qProfilesByKey.values()) {
writeProfile(qProfilesMapResponse, profile);
}
@@ -204,11 +204,11 @@ public class ActiveRuleCompleter {
}
@CheckForNull
- private RulesProfileDto loadProfile(DbSession dbSession, String qProfileKey) {
- return dbClient.qualityProfileDao().selectByKey(dbSession, qProfileKey);
+ private QProfileDto loadProfile(DbSession dbSession, String qProfileKey) {
+ return dbClient.qualityProfileDao().selectByUuid(dbSession, qProfileKey);
}
- private void writeProfile(Map<String, Rules.QProfile> profilesResponse, RulesProfileDto profile) {
+ private void writeProfile(Map<String, Rules.QProfile> profilesResponse, QProfileDto profile) {
Rules.QProfile.Builder profileResponse = Rules.QProfile.newBuilder();
setNullable(profile.getName(), profileResponse::setName);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java
index bcf317abe07..8c7cee5c1a4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.user.UserSession;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION;
@@ -87,7 +87,7 @@ public class AppAction implements RulesWsAction {
private void addProfiles(DbSession dbSession, OrganizationDto organization, JsonWriter json) {
json.name("qualityprofiles").beginArray();
- for (RulesProfileDto profile : dbClient.qualityProfileDao().selectAll(dbSession, organization)) {
+ for (QProfileDto profile : dbClient.qualityProfileDao().selectAll(dbSession, organization)) {
if (languageIsSupported(profile)) {
json
.beginObject()
@@ -102,7 +102,7 @@ public class AppAction implements RulesWsAction {
json.endArray();
}
- private boolean languageIsSupported(RulesProfileDto profile) {
+ private boolean languageIsSupported(QProfileDto profile) {
return languages.get(profile.getLanguage()) != null;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java
index 73b8f36d9d8..aa0eb767c31 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java
@@ -32,7 +32,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.ws.WsUtils;
@@ -88,8 +88,8 @@ public class RuleQueryFactory {
organizationUuid = wsSupport.getOrganizationByKey(dbSession, organizationKey).getUuid();
languages = request.paramAsStrings(PARAM_LANGUAGES);
} else {
- RulesProfileDto qualityProfileOptional = dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey);
- RulesProfileDto qualityProfile = WsUtils.checkFound(qualityProfileOptional, "The specified qualityProfile '%s' does not exist", qualityProfileKey);
+ QProfileDto qualityProfileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, qualityProfileKey);
+ QProfileDto qualityProfile = WsUtils.checkFound(qualityProfileOptional, "The specified qualityProfile '%s' does not exist", qualityProfileKey);
query.setQProfileKey(qualityProfileKey);
languages = ImmutableList.of(qualityProfile.getLanguage());
organizationUuid = qualityProfile.getOrganizationUuid();
@@ -121,8 +121,8 @@ public class RuleQueryFactory {
}
@CheckForNull
- private RulesProfileDto getProfileByKey(DbSession dbSession, String key) {
- return dbClient.qualityProfileDao().selectByKey(dbSession, key);
+ private QProfileDto getProfileByKey(DbSession dbSession, String key) {
+ return dbClient.qualityProfileDao().selectByUuid(dbSession, key);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
index 1c9ee068195..f9dc210ac5f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
@@ -38,7 +38,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.source.FileSourceDto;
import org.sonar.db.source.FileSourceDto.Type;
@@ -605,7 +605,7 @@ public class ProjectDataLoaderMediumTest {
private void addDefaultProfile() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto, false);
- RulesProfileDto profileDto = newQProfileDto(organizationDto, QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
+ QProfileDto profileDto = newQProfileDto(organizationDto, QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
formatDateTime(new Date()));
dbClient.qualityProfileDao().insert(dbSession, profileDto);
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profileDto));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
index bc0a286f29e..f8ffe401af0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
@@ -274,7 +274,7 @@ public class LoadReportAnalysisMetadataHolderStepTest {
metadataBuilder.getMutableQprofilesPerLanguage().put("js", ScannerReport.Metadata.QProfile.newBuilder().setKey("p1").setName("Sonar way").setLanguage("js").build());
reportReader.setMetadata(metadataBuilder.build());
- dbTester.qualityProfiles().insert(organization, p -> p.setLanguage("js"), p -> p.setKey("p1"));
+ dbTester.qualityProfiles().insert(organization, p -> p.setLanguage("js").setKey("p1"));
ComputationStep underTest = createStep(createCeTask(PROJECT_KEY, organization.getUuid()));
@@ -292,8 +292,8 @@ public class LoadReportAnalysisMetadataHolderStepTest {
metadataBuilder.getMutableQprofilesPerLanguage().put("php", ScannerReport.Metadata.QProfile.newBuilder().setKey("phpInOrg2").setName("PHP way").setLanguage("php").build());
reportReader.setMetadata(metadataBuilder.build());
- dbTester.qualityProfiles().insert(organization1, p -> p.setLanguage("js"), p -> p.setKey("jsInOrg1"));
- dbTester.qualityProfiles().insert(organization2, p -> p.setLanguage("php"), p -> p.setKey("phpInOrg2"));
+ dbTester.qualityProfiles().insert(organization1, p -> p.setLanguage("js").setKey("jsInOrg1"));
+ dbTester.qualityProfiles().insert(organization2, p -> p.setLanguage("php").setKey("phpInOrg2"));
ComputationStep underTest = createStep(createCeTask(PROJECT_KEY, organization1.getUuid()));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java
index ee9733c0096..bb3ba269086 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java
@@ -32,7 +32,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.qualityprofile.QualityProfileDbTester;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
@@ -51,9 +51,9 @@ import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfil
public class UpdateQualityProfilesLastUsedDateStepTest {
static final long ANALYSIS_DATE = 1_123_456_789L;
private static final Component PROJECT = ReportComponent.DUMB_PROJECT;
- private RulesProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
- private RulesProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
- private RulesProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");
+ private QProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
+ private QProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
+ private QProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -81,7 +81,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
@Test
public void doest_not_update_profiles_when_no_measure() {
- qualityProfileDb.insertQualityProfiles(sonarWayJava, sonarWayPhp, myQualityProfile);
+ qualityProfileDb.insert(sonarWayJava, sonarWayPhp, myQualityProfile);
underTest.execute();
@@ -92,7 +92,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
@Test
public void update_profiles_defined_in_quality_profiles_measure() {
- qualityProfileDb.insertQualityProfiles(sonarWayJava, sonarWayPhp, myQualityProfile);
+ qualityProfileDb.insert(sonarWayJava, sonarWayPhp, myQualityProfile);
measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(
toJson(sonarWayJava.getKee(), myQualityProfile.getKee())));
@@ -107,13 +107,13 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
@Test
public void ancestor_profiles_are_updated() throws Exception {
// Parent profiles should be updated
- RulesProfileDto rootProfile = newQualityProfileDto().setKey("root");
- RulesProfileDto parentProfile = newQualityProfileDto().setKey("parent").setParentKee(rootProfile.getKee());
+ QProfileDto rootProfile = newQualityProfileDto().setKey("root");
+ QProfileDto parentProfile = newQualityProfileDto().setKey("parent").setParentKee(rootProfile.getKee());
// Current profile => should be updated
- RulesProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee(parentProfile.getKee());
+ QProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee(parentProfile.getKee());
// Child of current profile => should not be updated
- RulesProfileDto childProfile = newQualityProfileDto().setKey("child").setParentKee(currentProfile.getKee());
- qualityProfileDb.insertQualityProfiles(rootProfile, parentProfile, currentProfile, childProfile);
+ QProfileDto childProfile = newQualityProfileDto().setKey("child").setParentKee(currentProfile.getKee());
+ qualityProfileDb.insert(rootProfile, parentProfile, currentProfile, childProfile);
measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee())));
@@ -127,8 +127,8 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
@Test
public void fail_when_profile_is_linked_to_unknown_parent() throws Exception {
- RulesProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
- qualityProfileDb.insertQualityProfiles(currentProfile);
+ QProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
+ qualityProfileDb.insert(currentProfile);
measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee())));
@@ -141,17 +141,17 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
assertThat(underTest.getDescription()).isEqualTo("Update last usage date of quality profiles");
}
- private void assertQualityProfileIsUpdated(RulesProfileDto qp) {
+ private void assertQualityProfileIsUpdated(QProfileDto qp) {
assertThat(selectLastUser(qp.getKee())).withFailMessage("Quality profile '%s' hasn't been updated. Value: %d", qp.getKee(), qp.getLastUsed()).isEqualTo(ANALYSIS_DATE);
}
- private void assertQualityProfileIsTheSame(RulesProfileDto qp) {
+ private void assertQualityProfileIsTheSame(QProfileDto qp) {
assertThat(selectLastUser(qp.getKee())).isEqualTo(qp.getLastUsed());
}
@CheckForNull
private Long selectLastUser(String qualityProfileKey) {
- return dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey).getLastUsed();
+ return dbClient.qualityProfileDao().selectByUuid(dbSession, qualityProfileKey).getLastUsed();
}
private static String toJson(String... keys) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
index 24320dffb9d..24902363824 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
@@ -37,7 +37,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentCleanerService;
@@ -321,8 +321,8 @@ public class DeleteActionTest {
public void request_also_deletes_quality_profiles_of_specified_organization() {
OrganizationDto org = db.organizations().insert();
OrganizationDto otherOrg = db.organizations().insert();
- RulesProfileDto profileInOrg = db.qualityProfiles().insert(org);
- RulesProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);
+ QProfileDto profileInOrg = db.qualityProfiles().insert(org);
+ QProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);
logInAsAdministrator(org);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
index 9ee4522a455..f848acb9a64 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
@@ -44,7 +44,7 @@ import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -126,14 +126,14 @@ public class QProfileBackuperMediumTest {
ruleIndexer.indexRuleDefinition(blahRule.getKey());
// create profile P1 with rules x2 and x1 activated
- RulesProfileDto profile = newXooP1(organization);
+ QProfileDto profile = newXooP1(organization);
db.qualityProfileDao().insert(dbSession, profile);
RuleActivation activation1 = new RuleActivation(XOO_X2).setSeverity("MINOR");
RuleActivation activation2 = new RuleActivation(XOO_X1);
RuleActivation activation3 = new RuleActivation(blahRuleKey);
activation2.setSeverity(Severity.BLOCKER);
activation2.setParameter("max", "7");
- RulesProfileDto profileDto = get(XOO_P1_NAME);
+ QProfileDto profileDto = get(XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation1, profileDto);
tester.get(RuleActivator.class).activate(dbSession, activation2, profileDto);
tester.get(RuleActivator.class).activate(dbSession, activation3, profileDto);
@@ -156,7 +156,7 @@ public class QProfileBackuperMediumTest {
organization, null);
// Check in db
- RulesProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
+ QProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P1", "xoo");
assertThat(profile).isNotNull();
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profile.getKee());
@@ -182,7 +182,7 @@ public class QProfileBackuperMediumTest {
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(Severity.INFO);
activation.setParameter("max", "10");
- RulesProfileDto profileDto = get(XOO_P1_NAME);
+ QProfileDto profileDto = get(XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation, profileDto);
activation = new RuleActivation(XOO_X2);
@@ -379,7 +379,7 @@ public class QProfileBackuperMediumTest {
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
assertThat(activeRules).hasSize(0);
- RulesProfileDto target = db.qualityProfileDao().selectByNameAndLanguage(organization, "P3", "xoo", dbSession);
+ QProfileDto target = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P3", "xoo");
assertThat(target).isNotNull();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, target.getKee())).hasSize(1);
}
@@ -392,7 +392,7 @@ public class QProfileBackuperMediumTest {
dbSession.clearCache();
assertThat(anyActiveRuleExists()).isFalse();
- List<RulesProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
+ List<QProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
assertThat(profiles).hasSize(1);
assertThat(profiles.get(0).getName()).isEqualTo("P1");
}
@@ -404,7 +404,7 @@ public class QProfileBackuperMediumTest {
}
}
- private RulesProfileDto get(QProfileName profileName) {
- return db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
+ private QProfileDto get(QProfileName profileName) {
+ return db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, profileName.getName(), profileName.getLanguage());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
index 01b8db02cc9..31e4c19eba8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
@@ -30,7 +30,7 @@ import org.sonar.api.rule.Severity;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
@@ -56,8 +56,8 @@ public class QProfileComparisonMediumTest {
RuleDto xooRule1;
RuleDto xooRule2;
- RulesProfileDto left;
- RulesProfileDto right;
+ QProfileDto left;
+ QProfileDto right;
@Before
public void before() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
index ed703457cba..9939f343438 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -65,7 +65,7 @@ public class QProfileCopierMediumTest {
private RuleIndexer ruleIndexer;
private ActiveRuleIndexer activeRuleIndexer;
private OrganizationDto organization;
- private RulesProfileDto sourceProfile;
+ private QProfileDto sourceProfile;
@Before
public void before() {
@@ -169,7 +169,7 @@ public class QProfileCopierMediumTest {
copier.copyToName(dbSession, sourceProfile, QProfileTesting.XOO_P2_NAME.getName());
verifyOneActiveRule(QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
- RulesProfileDto profile2Dto = db.qualityProfileDao().selectByKey(dbSession, QProfileTesting.XOO_P2_KEY);
+ QProfileDto profile2Dto = db.qualityProfileDao().selectByUuid(dbSession, QProfileTesting.XOO_P2_KEY);
assertThat(profile2Dto.getParentKee()).isEqualTo(QProfileTesting.XOO_P1_KEY);
}
@@ -193,7 +193,7 @@ public class QProfileCopierMediumTest {
private void verifyOneActiveRule(QProfileName profileName, String expectedSeverity,
@Nullable String expectedInheritance, Map<String, String> expectedParams) {
- RulesProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
+ QProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, profileName.getName(), profileName.getLanguage());
verifyOneActiveRule(dto.getKee(), expectedSeverity, expectedInheritance, expectedParams);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
index 8a7240bd06c..8c3b8a6bb30 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
@@ -41,7 +41,7 @@ import org.sonar.api.utils.ValidationMessages;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.index.RuleIndex;
@@ -102,7 +102,7 @@ public class QProfileExportersTest {
@Test
public void import_xml() {
- RulesProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
+ QProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
index 376bf919ae0..6a649addf50 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -69,7 +69,7 @@ public class QProfileFactoryMediumTest {
public void checkAndCreate() {
String uuid = organization.getUuid();
- RulesProfileDto writtenDto = factory.checkAndCreateCustom(dbSession, organization, new QProfileName("xoo", "P1"));
+ QProfileDto writtenDto = factory.checkAndCreateCustom(dbSession, organization, new QProfileName("xoo", "P1"));
dbSession.commit();
dbSession.clearCache();
assertThat(writtenDto.getOrganizationUuid()).isEqualTo(uuid);
@@ -80,7 +80,7 @@ public class QProfileFactoryMediumTest {
assertThat(writtenDto.isBuiltIn()).isFalse();
// reload the dto
- RulesProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
+ QProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P1", "xoo");
assertEqual(writtenDto, readDto);
assertThat(db.qualityProfileDao().selectAll(dbSession, organization)).hasSize(1);
@@ -90,7 +90,7 @@ public class QProfileFactoryMediumTest {
public void create() {
String uuid = organization.getUuid();
- RulesProfileDto writtenDto = factory.createBuiltIn(dbSession, organization, new QProfileName("xoo", "P1"), true);
+ QProfileDto writtenDto = factory.createBuiltIn(dbSession, organization, new QProfileName("xoo", "P1"), true);
dbSession.commit();
dbSession.clearCache();
assertThat(writtenDto.getOrganizationUuid()).isEqualTo(uuid);
@@ -101,7 +101,7 @@ public class QProfileFactoryMediumTest {
assertThat(writtenDto.getParentKee()).isNull();
// reload the dto
- RulesProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
+ QProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P1", "xoo");
assertEqual(writtenDto, readDto);
assertThat(db.qualityProfileDao().selectAll(dbSession, organization)).hasSize(1);
@@ -170,7 +170,7 @@ public class QProfileFactoryMediumTest {
thrown.expectMessage(message);
}
- private static void assertEqual(RulesProfileDto writtenDto, RulesProfileDto readDto) {
+ private static void assertEqual(QProfileDto writtenDto, QProfileDto readDto) {
assertThat(readDto.getOrganizationUuid()).isEqualTo(writtenDto.getOrganizationUuid());
assertThat(readDto.getName()).isEqualTo(writtenDto.getName());
assertThat(readDto.getKee()).startsWith(writtenDto.getKee());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java
index 45e765d5113..29dfea82819 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
@@ -65,9 +65,9 @@ public class QProfileFactoryTest {
@Test
public void deleteByKeys_deletes_profiles_in_db_and_elasticsearch() {
OrganizationDto org = db.organizations().insert();
- RulesProfileDto profile1 = createRandomProfile(org);
- RulesProfileDto profile2 = createRandomProfile(org);
- RulesProfileDto profile3 = createRandomProfile(org);
+ QProfileDto profile1 = createRandomProfile(org);
+ QProfileDto profile2 = createRandomProfile(org);
+ QProfileDto profile3 = createRandomProfile(org);
List<String> profileKeys = asList(profile1.getKee(), profile2.getKee(), "does_not_exist");
underTest.deleteByKeys(db.getSession(), profileKeys);
@@ -81,7 +81,7 @@ public class QProfileFactoryTest {
@Test
public void deleteByKeys_accepts_empty_list_of_keys() {
OrganizationDto org = db.organizations().insert();
- RulesProfileDto profile1 = createRandomProfile(org);
+ QProfileDto profile1 = createRandomProfile(org);
underTest.deleteByKeys(db.getSession(), Collections.emptyList());
@@ -89,10 +89,10 @@ public class QProfileFactoryTest {
assertQualityProfileFromDb(profile1).isNotNull();
}
- private RulesProfileDto createRandomProfile(OrganizationDto org) {
- RulesProfileDto profile = db.qualityProfiles().insert(org);
+ private QProfileDto createRandomProfile(OrganizationDto org) {
+ QProfileDto profile = db.qualityProfiles().insert(org);
ComponentDto project = db.components().insertPrivateProject(org);
- db.qualityProfiles().associateProjectWithQualityProfile(project, profile);
+ db.qualityProfiles().associateWithProject(project, profile);
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
.setProfileId(profile.getId())
.setRuleId(rule.getId())
@@ -107,7 +107,7 @@ public class QProfileFactoryTest {
return profile;
}
- private AbstractObjectAssert<?, RulesProfileDto> assertQualityProfileFromDb(RulesProfileDto profile) {
- return assertThat(db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), profile.getKee()));
+ private AbstractObjectAssert<?, QProfileDto> assertQualityProfileFromDb(QProfileDto profile) {
+ return assertThat(db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), profile.getKee()));
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java
index 8d92dd0bb8b..8e4461c1c45 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java
@@ -22,7 +22,7 @@ package org.sonar.server.qualityprofile;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.tester.ServerTester;
@@ -42,15 +42,15 @@ public class QProfileTesting {
* @deprecated provide organization as dto
*/
@Deprecated
- public static RulesProfileDto newQProfileDto(String organizationUuid, QProfileName name, String key) {
- return RulesProfileDto.createFor(key).setOrganizationUuid(organizationUuid).setName(name.getName()).setLanguage(name.getLanguage());
+ public static QProfileDto newQProfileDto(String organizationUuid, QProfileName name, String key) {
+ return QProfileDto.createFor(key).setOrganizationUuid(organizationUuid).setName(name.getName()).setLanguage(name.getLanguage());
}
/**
* @deprecated provide organization as dto
*/
@Deprecated
- public static RulesProfileDto newXooP1(String organizationUuid) {
+ public static QProfileDto newXooP1(String organizationUuid) {
return newQProfileDto(organizationUuid, XOO_P1_NAME, XOO_P1_KEY);
}
@@ -58,7 +58,7 @@ public class QProfileTesting {
* @deprecated provide organization as dto
*/
@Deprecated
- public static RulesProfileDto newXooP2(String organizationUuid) {
+ public static QProfileDto newXooP2(String organizationUuid) {
return newQProfileDto(organizationUuid, XOO_P2_NAME, XOO_P2_KEY);
}
@@ -66,23 +66,23 @@ public class QProfileTesting {
* @deprecated provide organization as dto
*/
@Deprecated
- public static RulesProfileDto newXooP3(String organizationUuid) {
+ public static QProfileDto newXooP3(String organizationUuid) {
return newQProfileDto(organizationUuid, XOO_P3_NAME, XOO_P3_KEY);
}
- public static RulesProfileDto newQProfileDto(OrganizationDto organization, QProfileName name, String key) {
- return RulesProfileDto.createFor(key).setOrganizationUuid(organization.getUuid()).setName(name.getName()).setLanguage(name.getLanguage());
+ public static QProfileDto newQProfileDto(OrganizationDto organization, QProfileName name, String key) {
+ return QProfileDto.createFor(key).setOrganizationUuid(organization.getUuid()).setName(name.getName()).setLanguage(name.getLanguage());
}
- public static RulesProfileDto newXooP1(OrganizationDto organization) {
+ public static QProfileDto newXooP1(OrganizationDto organization) {
return newQProfileDto(organization, XOO_P1_NAME, XOO_P1_KEY);
}
- public static RulesProfileDto newXooP2(OrganizationDto organization) {
+ public static QProfileDto newXooP2(OrganizationDto organization) {
return newQProfileDto(organization, XOO_P2_NAME, XOO_P2_KEY);
}
- public static RulesProfileDto newXooP3(OrganizationDto organization) {
+ public static QProfileDto newXooP3(OrganizationDto organization) {
return newQProfileDto(organization, XOO_P3_NAME, XOO_P3_KEY);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
index 50d68aa9852..e12879c18fe 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
@@ -41,7 +41,7 @@ import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.platform.Platform;
import org.sonar.server.rule.index.RuleIndex;
@@ -80,7 +80,7 @@ public class RegisterQualityProfilesMediumTest {
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession, organization)).hasSize(1);
- RulesProfileDto profile = qualityProfileDao.selectByNameAndLanguage(organization, "Basic", "xoo", dbSession);
+ QProfileDto profile = qualityProfileDao.selectByNameAndLanguage(dbSession, organization, "Basic", "xoo");
assertThat(profile).isNotNull();
assertThat(profile.isBuiltIn()).isTrue();
@@ -130,7 +130,7 @@ public class RegisterQualityProfilesMediumTest {
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession, organization)).hasSize(1);
- RulesProfileDto profile = qualityProfileDao.selectByNameAndLanguage(organization, "Basic", "xoo", dbSession);
+ QProfileDto profile = qualityProfileDao.selectByNameAndLanguage(dbSession, organization, "Basic", "xoo");
assertThat(profile).isNotNull();
assertThat(profile.isBuiltIn()).isTrue();
@@ -212,7 +212,7 @@ public class RegisterQualityProfilesMediumTest {
dbSession = dbClient().openSession(false);
OrganizationDto organization = getDefaultOrganization(tester, dbClient, dbSession);
- RulesProfileDto profile = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "two", "xoo", dbSession);
+ QProfileDto profile = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "two", "xoo");
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
dbSession.commit();
@@ -225,7 +225,7 @@ public class RegisterQualityProfilesMediumTest {
private void verifyDefaultProfile(OrganizationDto organization, String language, String name) {
dbSession = dbClient().openSession(false);
- RulesProfileDto defaultProfile = dbClient().qualityProfileDao().selectDefaultProfile(dbSession, organization, language);
+ QProfileDto defaultProfile = dbClient().qualityProfileDao().selectDefaultProfile(dbSession, organization, language);
assertThat(defaultProfile).isNotNull();
assertThat(defaultProfile.getName()).isEqualTo(name);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java
index b5d09e4ff26..1d8479ad6a5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java
@@ -33,7 +33,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.tester.UserSessionRule;
@@ -108,15 +108,15 @@ public class RegisterQualityProfilesTest {
OrganizationDto org1 = dbTester.organizations().insert(org -> org.setKey("org1"));
OrganizationDto org2 = dbTester.organizations().insert(org -> org.setKey("org2"));
- RulesProfileDto outdatedProfileInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
- RulesProfileDto outdatedProfileInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
+ QProfileDto outdatedProfileInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
+ QProfileDto outdatedProfileInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
builtInQProfileRepositoryRule.add(FOO_LANGUAGE, "Sonar way", false);
builtInQProfileRepositoryRule.initialize();
underTest.start();
- assertThat(dbTester.qualityProfiles().selectByKey(outdatedProfileInOrg1.getKee()).get().getName()).isEqualTo("Sonar way (outdated copy)");
- assertThat(dbTester.qualityProfiles().selectByKey(outdatedProfileInOrg2.getKee()).get().getName()).isEqualTo("Sonar way (outdated copy)");
+ assertThat(dbTester.qualityProfiles().selectByUuid(outdatedProfileInOrg1.getKee()).get().getName()).isEqualTo("Sonar way (outdated copy)");
+ assertThat(dbTester.qualityProfiles().selectByUuid(outdatedProfileInOrg2.getKee()).get().getName()).isEqualTo("Sonar way (outdated copy)");
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Rename Quality profiles [foo/Sonar way] to [Sonar way (outdated copy)] in 2 organizations");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
index 15bb60a2e73..bdf0405f685 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
@@ -40,7 +40,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -98,7 +98,7 @@ public class RuleActivatorMediumTest {
ActiveRuleIndexer activeRuleIndexer;
- RulesProfileDto profileDto;
+ QProfileDto profileDto;
private OrganizationDto organization;
@Before
@@ -964,7 +964,7 @@ public class RuleActivatorMediumTest {
// set parent -> child profile inherits rule x1 and still has x2
ruleActivator.setParent(dbSession, XOO_P2_KEY, XOO_P1_KEY);
dbSession.clearCache();
- assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isEqualTo(XOO_P1_KEY);
+ assertThat(db.qualityProfileDao().selectByUuid(dbSession, XOO_P2_KEY).getParentKee()).isEqualTo(XOO_P1_KEY);
verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X1), MAJOR, INHERITED, ImmutableMap.of("max", "10"));
verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), MAJOR, null, Collections.emptyMap());
@@ -973,7 +973,7 @@ public class RuleActivatorMediumTest {
dbSession.clearCache();
ruleActivator.setParent(dbSession, XOO_P2_KEY, null);
assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
- assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isNull();
+ assertThat(db.qualityProfileDao().selectByUuid(dbSession, XOO_P2_KEY).getParentKee()).isNull();
verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), MAJOR, null, Collections.emptyMap());
}
@@ -981,7 +981,7 @@ public class RuleActivatorMediumTest {
public void unset_no_parent_does_not_fail() {
// P1 has no parent !
ruleActivator.setParent(dbSession, XOO_P1_KEY, null);
- assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P1_KEY).getParentKee()).isNull();
+ assertThat(db.qualityProfileDao().selectByUuid(dbSession, XOO_P1_KEY).getParentKee()).isNull();
}
@Test
@@ -1022,7 +1022,7 @@ public class RuleActivatorMediumTest {
// unset parent -> keep x1
ruleActivator.setParent(dbSession, XOO_P2_KEY, null);
dbSession.clearCache();
- assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isNull();
+ assertThat(db.qualityProfileDao().selectByUuid(dbSession, XOO_P2_KEY).getParentKee()).isNull();
verifyOneActiveRuleInDbAndIndex(XOO_P2_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "333"));
}
@@ -1048,7 +1048,7 @@ public class RuleActivatorMediumTest {
ruleActivator.setParent(dbSession, XOO_P2_KEY, XOO_P1_KEY);
dbSession.clearCache();
- assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isEqualTo(XOO_P1_KEY);
+ assertThat(db.qualityProfileDao().selectByUuid(dbSession, XOO_P2_KEY).getParentKee()).isEqualTo(XOO_P1_KEY);
assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), MAJOR, INHERITED, Collections.emptyMap());
}
@@ -1197,13 +1197,13 @@ public class RuleActivatorMediumTest {
}
private void assertProfileHasBeenUpdatedManually(String profileKey) {
- RulesProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
+ QProfileDto profile = db.qualityProfileDao().selectByUuid(dbSession, profileKey);
assertThat(profile.getRulesUpdatedAt()).isNotEmpty();
assertThat(profile.getUserUpdatedAt()).isNotNull();
}
private void assertProfileHasBeenUpdatedAutomatically(String profileKey) {
- RulesProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
+ QProfileDto profile = db.qualityProfileDao().selectByUuid(dbSession, profileKey);
assertThat(profile.getRulesUpdatedAt()).isNotEmpty();
assertThat(profile.getUserUpdatedAt()).isNull();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java
index bbb79fb205f..e1346250df8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java
@@ -35,7 +35,7 @@ public class ActiveRuleDocTesting {
return new ActiveRuleDoc(key)
.setOrganizationUuid(randomAlphabetic(40))
.setSeverity(Severity.CRITICAL)
- .setInheritance(null).setCreatedAt(150000000L)
- .setUpdatedAt(160000000L);
+ .setInheritance(null)
+ .setUpdatedAt(1_600_000_000L);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
index f1a7a3d73ce..95cc05a6240 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
@@ -24,14 +24,12 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.MapSettings;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.Severity;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
@@ -60,23 +58,24 @@ public class ActiveRuleIndexerTest {
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE);
- private ActiveRuleIndexer indexer = new ActiveRuleIndexer(system2, dbTester.getDbClient(), esTester.client());
-
- private OrganizationDto organization = OrganizationTesting.newOrganizationDto();
+ private ActiveRuleIndexer underTest = new ActiveRuleIndexer(system2, db.getDbClient(), esTester.client());
@Test
public void index_nothing() {
- indexer.index(Iterators.emptyIterator());
+ underTest.index(Iterators.emptyIterator());
assertThat(esTester.countDocuments(INDEX_TYPE_ACTIVE_RULE)).isZero();
}
@Test
- public void index() {
- dbTester.prepareDbUnit(getClass(), "index.xml");
+ public void test_index() {
+ RuleDefinitionDto rule = db.rules().insert();
+ OrganizationDto org = db.organizations().insert();
+ QProfileDto profile = db.qualityProfiles().insert(org);
+ db.qualityProfiles().activateRule(profile, rule);
- indexer.index();
+ underTest.index();
assertThat(esTester.countDocuments(INDEX_TYPE_ACTIVE_RULE)).isEqualTo(1);
}
@@ -90,7 +89,7 @@ public class ActiveRuleIndexerTest {
newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3)));
assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).hasSize(4);
- indexer.deleteByProfileKeys(asList(QUALITY_PROFILE_KEY1));
+ underTest.deleteByProfileKeys(asList(QUALITY_PROFILE_KEY1));
assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).containsOnly(
ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2).toString(),
@@ -106,7 +105,7 @@ public class ActiveRuleIndexerTest {
newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3)));
assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).hasSize(4);
- indexer.deleteByProfileKeys(asList(QUALITY_PROFILE_KEY1, QUALITY_PROFILE_KEY2));
+ underTest.deleteByProfileKeys(asList(QUALITY_PROFILE_KEY1, QUALITY_PROFILE_KEY2));
assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).isEmpty();
}
@@ -126,7 +125,7 @@ public class ActiveRuleIndexerTest {
assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).hasSize(4);
- indexer.index(asList(
+ underTest.index(asList(
ActiveRuleChange.createFor(ACTIVATED, activeRuleKey1),
ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey2),
ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey3)));
@@ -138,43 +137,30 @@ public class ActiveRuleIndexerTest {
@Test
public void index_from_changes_index_new_active_rule() throws Exception {
- long yesterday = 1000000L;
- long now = 2000000L;
-
- // Index one active rule
- RuleDefinitionDto rule = RuleTesting.newRule(RULE_KEY_1);
- dbTester.rules().insert(rule);
- RulesProfileDto profile = RulesProfileDto.createFor("qp")
- .setOrganizationUuid(organization.getUuid())
- .setLanguage("xoo")
- .setName("profile");
- dbTester.getDbClient().qualityProfileDao().insert(dbTester.getSession(), profile);
- ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(Severity.BLOCKER)
- .setCreatedAt(yesterday).setUpdatedAt(yesterday);
- dbTester.getDbClient().activeRuleDao().insert(dbTester.getSession(), activeRule);
- dbTester.getSession().commit();
-
- indexer.index();
-
- assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).containsOnly(activeRule.getKey().toString());
+ long yesterday = 1_000;
+ long now = 2_000L;
+ RuleDefinitionDto rule = db.rules().insert();
+ OrganizationDto org = db.organizations().insert();
+ QProfileDto profile1 = db.qualityProfiles().insert(org);
+ ActiveRuleDto activeRule1 = db.qualityProfiles().activateRule(profile1, rule, ar -> ar.setUpdatedAt(yesterday));
+
+ underTest.index();
+
+ assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).containsOnly(activeRule1.getKey().toString());
// Index another active rule
- RuleDefinitionDto rule2 = RuleTesting.newRule(RULE_KEY_2);
- dbTester.rules().insert(rule2);
- ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profile, rule2).setSeverity(Severity.CRITICAL)
- .setCreatedAt(now).setUpdatedAt(now);
- dbTester.getDbClient().activeRuleDao().insert(dbTester.getSession(), activeRule2);
- dbTester.getSession().commit();
+ QProfileDto profile2 = db.qualityProfiles().insert(org);
+ ActiveRuleDto activeRule2 = db.qualityProfiles().activateRule(profile2, rule, ar -> ar.setUpdatedAt(now));
- indexer.index(singletonList(ActiveRuleChange.createFor(ACTIVATED, activeRule2.getKey())));
+ underTest.index(singletonList(ActiveRuleChange.createFor(ACTIVATED, activeRule2.getKey())));
assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).containsOnly(
- activeRule.getKey().toString(),
+ activeRule1.getKey().toString(),
activeRule2.getKey().toString());
}
private void indexActiveRules(ActiveRuleDoc... docs) {
- indexer.index(asList(docs).iterator());
+ underTest.index(asList(docs).iterator());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
index abd481a0b3a..467a91be551 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
@@ -21,117 +21,92 @@ package org.sonar.server.qualityprofile.index;
import com.google.common.collect.Maps;
import java.util.Map;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
+import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.qualityprofile.ActiveRule;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.api.rule.Severity.BLOCKER;
import static org.sonar.api.rule.Severity.CRITICAL;
-import static org.sonar.api.rule.Severity.INFO;
import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.INHERITED;
public class ActiveRuleResultSetIteratorTest {
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
+ public DbTester db = DbTester.create(System2.INSTANCE);
+
+ private RuleDefinitionDto rule;
+ private OrganizationDto org;
+ private QProfileDto profile1;
+ private QProfileDto profile2;
+
+ @Before
+ public void before() {
+ rule = db.rules().insert();
+ org = db.organizations().insert();
+ profile1 = db.qualityProfiles().insert(org);
+ profile2 = db.qualityProfiles().insert(org);
+ }
@Test
- public void iterator_over_one_active_rule() {
- dbTester.prepareDbUnit(getClass(), "one_active_rule.xml");
- ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
+ public void iterate_over_one_active_rule() {
+ ActiveRuleDto dto = db.qualityProfiles().activateRule(profile1, rule, ar -> ar.setSeverity(CRITICAL).setInheritance(null));
+
+ ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(db.getDbClient(), db.getSession(), 0L);
Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
it.close();
assertThat(activeRulesByKey).hasSize(1);
- ActiveRuleKey key = ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S001"));
+ ActiveRuleKey key = ActiveRuleKey.of(profile1.getKee(), rule.getKey());
ActiveRuleDoc activeRule = activeRulesByKey.get(key);
- assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
+ assertThat(activeRule.organizationUuid()).isEqualTo(org.getUuid());
assertThat(activeRule.key()).isEqualTo(key);
assertThat(activeRule.severity()).isEqualTo(CRITICAL);
assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
- assertThat(activeRule.createdAt()).isEqualTo(1_500_000_000_000L);
- assertThat(activeRule.updatedAt()).isEqualTo(1_600_000_000_000L);
+ assertThat(activeRule.updatedAt()).isEqualTo(dto.getUpdatedAt());
}
@Test
- public void iterator_over_active_rules() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
- ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
- Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
- it.close();
-
- assertThat(activeRulesByKey).hasSize(3);
+ public void iterate_over_multiple_active_rules() {
+ ActiveRuleDto dto1 = db.qualityProfiles().activateRule(profile1, rule);
+ ActiveRuleDto dto2 = db.qualityProfiles().activateRule(profile2, rule);
- ActiveRuleKey key = ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S002"));
- ActiveRuleDoc activeRule = activeRulesByKey.get(key);
- assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
- assertThat(activeRule.key()).isEqualTo(key);
- assertThat(activeRule.severity()).isEqualTo(CRITICAL);
- assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
- assertThat(activeRule.createdAt()).isEqualTo(2_000_000_000_000L);
- assertThat(activeRule.updatedAt()).isEqualTo(2_100_000_000_000L);
-
- key = ActiveRuleKey.of("parent", RuleKey.of("xoo", "S001"));
- activeRule = activeRulesByKey.get(key);
- assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
- assertThat(activeRule.key()).isEqualTo(key);
- assertThat(activeRule.severity()).isEqualTo(INFO);
- assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
- assertThat(activeRule.createdAt()).isEqualTo(1_700_000_000_000L);
- assertThat(activeRule.updatedAt()).isEqualTo(1_800_000_000_000L);
-
- key = ActiveRuleKey.of("child", RuleKey.of("xoo", "S001"));
- activeRule = activeRulesByKey.get(key);
- assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
- assertThat(activeRule.key()).isEqualTo(key);
- assertThat(activeRule.severity()).isEqualTo(BLOCKER);
- assertThat(activeRule.inheritance()).isEqualTo(INHERITED);
- assertThat(activeRule.createdAt()).isEqualTo(1_500_000_000_000L);
- assertThat(activeRule.updatedAt()).isEqualTo(1_600_000_000_000L);
- }
-
- @Test
- public void active_rule_with_inherited_inheritance() {
- dbTester.prepareDbUnit(getClass(), "active_rule_with_inherited_inheritance.xml");
- ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
+ ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(db.getDbClient(), db.getSession(), 0L);
Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
it.close();
assertThat(activeRulesByKey).hasSize(2);
-
- ActiveRuleKey key = ActiveRuleKey.of("child", RuleKey.of("xoo", "S001"));
- ActiveRuleDoc activeRule = activeRulesByKey.get(key);
- assertThat(activeRule.inheritance()).isEqualTo(INHERITED);
+ assertThat(activeRulesByKey.keySet()).containsExactlyInAnyOrder(dto1.getKey(), dto2.getKey());
}
@Test
- public void active_rule_with_overrides_inheritance() {
- dbTester.prepareDbUnit(getClass(), "active_rule_with_overrides_inheritance.xml");
- ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
+ public void iterate_inherited_active_rule() {
+ ActiveRuleDto dto = db.qualityProfiles().activateRule(profile1, rule, ar -> ar.setInheritance(INHERITED.name()));
+
+ ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(db.getDbClient(), db.getSession(), 0L);
Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
it.close();
- assertThat(activeRulesByKey).hasSize(2);
-
- ActiveRuleKey key = ActiveRuleKey.of("child", RuleKey.of("xoo", "S001"));
- ActiveRuleDoc activeRule = activeRulesByKey.get(key);
- assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.OVERRIDES);
+ assertThat(activeRulesByKey).hasSize(1);
+ assertThat(activeRulesByKey.get(dto.getKey()).inheritance()).isEqualTo(INHERITED);
}
@Test
public void select_after_date() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
- ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1_900_000_000_000L);
+ ActiveRuleDto dto1 = db.qualityProfiles().activateRule(profile1, rule, ar -> ar.setUpdatedAt(1_500L));
+ ActiveRuleDto dto2 = db.qualityProfiles().activateRule(profile2, rule, ar -> ar.setUpdatedAt(1_600L));
+ ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(db.getDbClient(), db.getSession(), 1_550L);
assertThat(it.hasNext()).isTrue();
ActiveRuleDoc doc = it.next();
- assertThat(doc.key()).isEqualTo(ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S002")));
+ assertThat(doc.key()).isEqualTo(dto2.getKey());
assertThat(it.hasNext()).isFalse();
it.close();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
index e672b00b864..2147e7b5be7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
@@ -102,7 +102,7 @@ public class ActivateRuleActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
@@ -117,7 +117,7 @@ public class ActivateRuleActionTest {
public void fail_activate_if_built_in_profile() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, profile -> profile.setIsBuiltIn(true).setName("Xoo profile").setLanguage("xoo"));
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, profile -> profile.setIsBuiltIn(true).setName("Xoo profile").setLanguage("xoo"));
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
@@ -132,7 +132,7 @@ public class ActivateRuleActionTest {
@Test
public void activate_rule_in_default_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -156,7 +156,7 @@ public class ActivateRuleActionTest {
@Test
public void activate_rule_in_specific_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java
index f12867f12c0..4c53be97188 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java
@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -110,7 +110,7 @@ public class ActivateRulesActionTest {
@Test
public void fail_if_built_in_profile() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, p -> p.setIsBuiltIn(true));
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, p -> p.setIsBuiltIn(true));
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("profile_key", qualityProfile.getKee());
@@ -123,7 +123,7 @@ public class ActivateRulesActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("profile_key", qualityProfile.getKee());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
index 31c72d476c7..842f92cda66 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
@@ -31,7 +31,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.TestComponentFinder;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -83,7 +83,7 @@ public class AddProjectActionTest {
public void add_project_on_profile_of_default_organization() {
logInAsProfileAdmin(db.getDefaultOrganization());
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
TestResponse response = call(project, profile);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
@@ -96,7 +96,7 @@ public class AddProjectActionTest {
OrganizationDto org1 = db.organizations().insert();
logInAsProfileAdmin(org1);
ComponentDto project = db.components().insertPrivateProject(org1);
- RulesProfileDto profile = db.qualityProfiles().insert(org1, p -> p.setLanguage(LANGUAGE_1));
+ QProfileDto profile = db.qualityProfiles().insert(org1, p -> p.setLanguage(LANGUAGE_1));
TestResponse response = call(org1, project, profile);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
@@ -110,7 +110,7 @@ public class AddProjectActionTest {
OrganizationDto org2 = db.organizations().insert();
logInAsProfileAdmin(org1);
ComponentDto project = db.components().insertPrivateProject(org1);
- RulesProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
+ QProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Project and Quality profile must have same organization");
@@ -126,7 +126,7 @@ public class AddProjectActionTest {
OrganizationDto org2 = db.organizations().insert();
logInAsProfileAdmin(org1);
ComponentDto project = db.components().insertPrivateProject(org1);
- RulesProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
+ QProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
expectedException.expect(NotFoundException.class);
expectedException
@@ -143,9 +143,9 @@ public class AddProjectActionTest {
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
// two profiles on same language
- RulesProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
- RulesProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
- db.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
+ QProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
+ QProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
+ db.qualityProfiles().associateWithProject(project, profile1);
call(project, profile2);
@@ -157,10 +157,10 @@ public class AddProjectActionTest {
public void changing_association_does_not_change_other_language_associations() throws Exception {
logInAsProfileAdmin(db.getDefaultOrganization());
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile1Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
- RulesProfileDto profile2Language2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
- RulesProfileDto profile3Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
- db.qualityProfiles().associateProjectWithQualityProfile(project, profile1Language1, profile2Language2);
+ QProfileDto profile1Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
+ QProfileDto profile2Language2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
+ QProfileDto profile3Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
+ db.qualityProfiles().associateWithProject(project, profile1Language1, profile2Language2);
call(project, profile3Language1);
@@ -171,7 +171,7 @@ public class AddProjectActionTest {
@Test
public void project_administrator_can_change_profile() throws Exception {
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
call(project, profile);
@@ -183,7 +183,7 @@ public class AddProjectActionTest {
public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
userSession.logIn();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@@ -195,7 +195,7 @@ public class AddProjectActionTest {
public void throw_UnauthorizedException_if_not_logged_in() {
userSession.anonymous();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(UnauthorizedException.class);
expectedException.expectMessage("Authentication is required");
@@ -206,7 +206,7 @@ public class AddProjectActionTest {
@Test
public void throw_NotFoundException_if_project_does_not_exist() {
logInAsProfileAdmin(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Component id 'unknown' not found");
@@ -231,13 +231,13 @@ public class AddProjectActionTest {
.execute();
}
- private void assertProjectIsAssociatedToProfile(ComponentDto project, RulesProfileDto profile) {
- RulesProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
+ private void assertProjectIsAssociatedToProfile(ComponentDto project, QProfileDto profile) {
+ QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
assertThat(loaded.getKee()).isEqualTo(profile.getKee());
}
- private void assertProjectIsNotAssociatedToProfile(ComponentDto project, RulesProfileDto profile) {
- RulesProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
+ private void assertProjectIsNotAssociatedToProfile(ComponentDto project, QProfileDto profile) {
+ QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
assertThat(loaded == null || !loaded.getKee().equals(profile.getKee())).isTrue();
}
@@ -245,14 +245,14 @@ public class AddProjectActionTest {
userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES, organization);
}
- private TestResponse call(ComponentDto project, RulesProfileDto qualityProfile) {
+ private TestResponse call(ComponentDto project, QProfileDto qualityProfile) {
TestRequest request = tester.newRequest()
.setParam("projectUuid", project.uuid())
.setParam("profileKey", qualityProfile.getKee());
return request.execute();
}
- private TestResponse call(OrganizationDto organization, ComponentDto project, RulesProfileDto qualityProfile) {
+ private TestResponse call(OrganizationDto organization, ComponentDto project, QProfileDto qualityProfile) {
TestRequest request = tester.newRequest()
.setParam("organization", organization.getKey())
.setParam("projectUuid", project.uuid())
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java
index 35e5c90a6b0..e7a7f0b9a95 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java
@@ -26,7 +26,7 @@ import org.sonar.api.resources.Languages;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
@@ -78,7 +78,7 @@ public class BackupActionTest {
@Test
public void returns_backup_of_profile_with_specified_key() throws Exception {
- RulesProfileDto profile = db.qualityProfiles().insertQualityProfile(QualityProfileTesting.newQualityProfileDto());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
TestResponse response = tester.newRequest().setParam("profileKey", profile.getKee()).execute();
assertThat(response.getMediaType()).isEqualTo("application/xml");
@@ -88,8 +88,7 @@ public class BackupActionTest {
@Test
public void returns_backup_of_profile_with_specified_name_on_default_organization() throws Exception {
- RulesProfileDto profile = newProfile(db.getDefaultOrganization());
- db.qualityProfiles().insertQualityProfile(profile);
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setParam("language", profile.getLanguage())
@@ -101,8 +100,7 @@ public class BackupActionTest {
@Test
public void returns_backup_of_profile_with_specified_name_and_organization() throws Exception {
OrganizationDto org = db.organizations().insert();
- RulesProfileDto profile = newProfile(org);
- db.qualityProfiles().insertQualityProfile(profile);
+ QProfileDto profile = db.qualityProfiles().insert(org, p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setParam("organization", org.getKey())
@@ -135,13 +133,12 @@ public class BackupActionTest {
@Test
public void throws_NotFoundException_if_profile_name_exists_but_in_another_organization() throws Exception {
OrganizationDto org1 = db.organizations().insert();
- RulesProfileDto profileInOrg1 = newProfile(org1);
- db.qualityProfiles().insertQualityProfile(profileInOrg1);
+ QProfileDto profileInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(A_LANGUAGE));
OrganizationDto org2 = db.organizations().insert();
- RulesProfileDto profileInOrg2 = newProfile(org2).setLanguage(profileInOrg1.getLanguage());
+ QProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(A_LANGUAGE));
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Quality Profile for language 'xoo' and name '" + profileInOrg1.getName() + "' does not exist in organization '" + org2.getKey() +"'");
+ expectedException.expectMessage("Quality Profile for language 'xoo' and name '" + profileInOrg1.getName() + "' does not exist in organization '" + org2.getKey() + "'");
tester.newRequest()
.setParam("organization", org2.getKey())
@@ -157,7 +154,7 @@ public class BackupActionTest {
tester.newRequest().execute();
}
- private static String xmlForProfileWithoutRules(RulesProfileDto profile) {
+ private static String xmlForProfileWithoutRules(QProfileDto profile) {
return "<?xml version='1.0' encoding='UTF-8'?>" +
"<profile>" +
" <name>" + profile.getName() + "</name>" +
@@ -166,7 +163,7 @@ public class BackupActionTest {
"</profile>";
}
- private static RulesProfileDto newProfile(OrganizationDto org) {
+ private static QProfileDto newProfile(OrganizationDto org) {
return QualityProfileTesting.newQualityProfileDto()
.setLanguage(A_LANGUAGE)
.setOrganizationUuid(org.getUuid());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
index 7cb6d5ce44a..7ccb0d9a78a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
@@ -40,8 +40,8 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
-import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsClient;
@@ -154,8 +154,8 @@ public class ChangeParentActionTest {
@Test
public void change_parent_with_no_parent_before() throws Exception {
- RulesProfileDto parent1 = createProfile();
- RulesProfileDto child = createProfile();
+ QProfileDto parent1 = createProfile();
+ QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent1);
@@ -181,9 +181,9 @@ public class ChangeParentActionTest {
@Test
public void replace_existing_parent() throws Exception {
- RulesProfileDto parent1 = createProfile();
- RulesProfileDto parent2 = createProfile();
- RulesProfileDto child = createProfile();
+ QProfileDto parent1 = createProfile();
+ QProfileDto parent2 = createProfile();
+ QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
@@ -212,8 +212,8 @@ public class ChangeParentActionTest {
@Test
public void remove_parent() throws Exception {
- RulesProfileDto parent = createProfile();
- RulesProfileDto child = createProfile();
+ QProfileDto parent = createProfile();
+ QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
@@ -238,9 +238,9 @@ public class ChangeParentActionTest {
@Test
public void change_parent_with_names() throws Exception {
- RulesProfileDto parent1 = createProfile();
- RulesProfileDto parent2 = createProfile();
- RulesProfileDto child = createProfile();
+ QProfileDto parent1 = createProfile();
+ QProfileDto parent2 = createProfile();
+ QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
@@ -300,8 +300,8 @@ public class ChangeParentActionTest {
@Test
public void remove_parent_with_empty_key() throws Exception {
- RulesProfileDto parent = createProfile();
- RulesProfileDto child = createProfile();
+ QProfileDto parent = createProfile();
+ QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
@@ -328,7 +328,7 @@ public class ChangeParentActionTest {
@Test
public void fail_if_built_in_profile() {
- RulesProfileDto child = dbTester.qualityProfiles().insert(organization, p -> p
+ QProfileDto child = dbTester.qualityProfiles().insert(organization, p -> p
.setLanguage(language.getKey())
.setIsBuiltIn(true));
@@ -347,7 +347,7 @@ public class ChangeParentActionTest {
@Test
public void fail_if_parent_key_and_name_both_set() throws Exception {
- RulesProfileDto child = createProfile();
+ QProfileDto child = createProfile();
assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, child.getKee())).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKee()), new SearchOptions()).getIds()).isEmpty();
@@ -364,7 +364,7 @@ public class ChangeParentActionTest {
@Test
public void fail_if_profile_key_and_name_both_set() throws Exception {
- RulesProfileDto child = createProfile();
+ QProfileDto child = createProfile();
assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, child.getKee())).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKee()), new SearchOptions()).getIds()).isEmpty();
@@ -384,7 +384,7 @@ public class ChangeParentActionTest {
public void fail_if_missing_permission() throws Exception {
userSessionRule.logIn();
- RulesProfileDto child = createProfile();
+ QProfileDto child = createProfile();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -400,7 +400,7 @@ public class ChangeParentActionTest {
OrganizationDto organization2 = dbTester.organizations().insert();
userSessionRule.logIn().addPermission(ADMINISTER_QUALITY_PROFILES, organization2.getUuid());
- RulesProfileDto child = createProfile();
+ QProfileDto child = createProfile();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -411,8 +411,8 @@ public class ChangeParentActionTest {
request.execute();
}
- private RulesProfileDto createProfile() {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
+ private QProfileDto createProfile() {
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid())
.setLanguage(language.getKey());
dbClient.qualityProfileDao().insert(dbSession, profile);
@@ -430,7 +430,7 @@ public class ChangeParentActionTest {
return rule;
}
- private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, RulesProfileDto profile) {
+ private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
dbClient.activeRuleDao().insert(dbSession, activeRule);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java
index 5cf45fdfd42..4238b37a41d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java
@@ -29,7 +29,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileChangeDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -67,7 +67,7 @@ public class ChangelogActionDatabaseTest {
@Test
public void find_changelog_by_profileKey() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
String response = wsTester.newRequest()
.setMethod("GET")
@@ -80,7 +80,7 @@ public class ChangelogActionDatabaseTest {
@Test
public void find_changelog_by_language_and_name() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
String response = wsTester.newRequest()
.setMethod("GET")
@@ -94,7 +94,7 @@ public class ChangelogActionDatabaseTest {
@Test
public void find_changelog_by_organization_and_language_and_name() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
String response = wsTester.newRequest()
.setMethod("GET")
@@ -112,7 +112,7 @@ public class ChangelogActionDatabaseTest {
OrganizationDto organization1 = dbTester.organizations().insert();
OrganizationDto organization2 = dbTester.organizations().insert();
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);
TestRequest request = wsTester.newRequest()
.setMethod("GET")
@@ -127,7 +127,7 @@ public class ChangelogActionDatabaseTest {
@Test
public void changelog_empty() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
String response = wsTester.newRequest()
.setMethod("GET")
@@ -141,7 +141,7 @@ public class ChangelogActionDatabaseTest {
@Test
public void changelog_not_empty() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
QProfileChangeDto change = QualityProfileTesting.newQProfileChangeDto()
.setKey(null)
.setCreatedAt(0)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogLoaderTest.java
index 5bed5e40245..f479d14af9c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogLoaderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogLoaderTest.java
@@ -29,6 +29,7 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.QProfileChangeDto;
+import org.sonar.db.qualityprofile.QProfileChangeMapper;
import org.sonar.db.qualityprofile.QProfileChangeQuery;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.rule.RuleDefinitionDto;
@@ -155,7 +156,7 @@ public class ChangelogLoaderTest {
.setLogin(login)
.setChangeType(type.name())
.setData(data);
- QualityProfileTesting.insert(dbTester, dto);
+ insert(dto);
}
private void insertRule(RuleKey key, String name) {
@@ -171,4 +172,13 @@ public class ChangelogLoaderTest {
dbTester.getDbClient().userDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
}
+
+ public void insert(QProfileChangeDto dto) {
+ // do not use QProfileChangeDao so that generated fields key and creation date
+ // can be defined by tests
+ DbSession dbSession = dbTester.getSession();
+ QProfileChangeMapper mapper = dbSession.getMapper(QProfileChangeMapper.class);
+ mapper.insert(dto);
+ dbSession.commit();
+ }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
index 0c1c00f6af0..4de309afa09 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -99,7 +99,7 @@ public class CompareActionMediumTest {
* - rule 4 active with different parameters => "modified"
* - rule 5 active with different severity => "modified"
*/
- RulesProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
+ QProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
createActiveRule(rule1, profile1);
createActiveRule(rule2, profile1);
createActiveRuleWithParam(rule4, profile1, "polop");
@@ -112,7 +112,7 @@ public class CompareActionMediumTest {
* - rule 3 active (only in this profile) => "inRight"
* - rule 4 active with different parameters => "modified"
*/
- RulesProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
+ QProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
createActiveRule(rule1, profile2);
createActiveRule(rule3, profile2);
createActiveRuleWithParam(rule4, profile2, "palap");
@@ -129,9 +129,9 @@ public class CompareActionMediumTest {
public void compare_param_on_left() throws Exception {
RuleDefinitionDto rule1 = createRuleWithParam("xoo", "rule1");
createRepository("blah", "xoo", "Blah");
- RulesProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
+ QProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
createActiveRuleWithParam(rule1, profile1, "polop");
- RulesProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
+ QProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
createActiveRule(rule1, profile2);
session.commit();
@@ -145,9 +145,9 @@ public class CompareActionMediumTest {
public void compare_param_on_right() throws Exception {
RuleDefinitionDto rule1 = createRuleWithParam("xoo", "rule1");
createRepository("blah", "xoo", "Blah");
- RulesProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
+ QProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
createActiveRule(rule1, profile1);
- RulesProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
+ QProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
createActiveRuleWithParam(rule1, profile2, "polop");
session.commit();
@@ -189,8 +189,8 @@ public class CompareActionMediumTest {
.execute();
}
- private RulesProfileDto createProfile(String lang, String name, String key) {
- RulesProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), key);
+ private QProfileDto createProfile(String lang, String name, String key) {
+ QProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), key);
db.qualityProfileDao().insert(session, profile);
session.commit();
return profile;
@@ -218,14 +218,14 @@ public class CompareActionMediumTest {
return rule;
}
- private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, RulesProfileDto profile) {
+ private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
- private ActiveRuleDto createActiveRuleWithParam(RuleDefinitionDto rule, RulesProfileDto profile, String value) {
+ private ActiveRuleDto createActiveRuleWithParam(RuleDefinitionDto rule, QProfileDto profile, String value) {
ActiveRuleDto activeRule = createActiveRule(rule, profile);
RuleParamDto paramDto = db.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value);
@@ -233,7 +233,7 @@ public class CompareActionMediumTest {
return activeRule;
}
- private ActiveRuleDto createActiveRuleWithSeverity(RuleDefinitionDto rule, RulesProfileDto profile, String severity) {
+ private ActiveRuleDto createActiveRuleWithSeverity(RuleDefinitionDto rule, QProfileDto profile, String severity) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(severity);
db.activeRuleDao().insert(session, activeRule);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
index d546ff3968d..6f00aa6f86d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
@@ -25,7 +25,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.resources.Languages;
import org.sonar.db.DbTester;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.qualityprofile.QProfileComparison;
import org.sonar.server.tester.UserSessionRule;
@@ -51,9 +51,9 @@ public class CompareActionTest {
@Test
public void should_not_allow_to_compare_quality_profiles_from_different_organizations() {
- RulesProfileDto left = QualityProfileTesting.newQualityProfileDto();
- RulesProfileDto right = QualityProfileTesting.newQualityProfileDto();
- dbTester.qualityProfiles().insertQualityProfiles(left, right);
+ QProfileDto left = QualityProfileTesting.newQualityProfileDto();
+ QProfileDto right = QualityProfileTesting.newQualityProfileDto();
+ dbTester.qualityProfiles().insert(left, right);
TestRequest request = wsTester.newRequest().setMethod("POST")
.setParam("leftKey", left.getKee())
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java
index afa90c5e8b3..a7f7fc21bcd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
@@ -96,7 +96,7 @@ public class CopyActionTest {
OrganizationDto organization = db.organizations().insert();
logInAsQProfileAdministrator(organization);
- RulesProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
+ QProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setMethod("POST")
.setParam("fromKey", sourceProfile.getKee())
@@ -112,8 +112,8 @@ public class CopyActionTest {
" \"isDefault\": false," +
" \"isInherited\": false" +
"}");
- RulesProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(organization, "target-name", sourceProfile.getLanguage(),
- db.getSession());
+ QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(db.getSession(), organization, "target-name", sourceProfile.getLanguage()
+ );
assertThat(loadedProfile.getKee()).isEqualTo(generatedUuid);
assertThat(loadedProfile.getParentKee()).isNull();
@@ -129,8 +129,8 @@ public class CopyActionTest {
public void copy_rules_on_existing_profile_in_default_organization() throws Exception {
OrganizationDto organization = db.organizations().insert();
logInAsQProfileAdministrator(organization);
- RulesProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
- RulesProfileDto targetProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
+ QProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
+ QProfileDto targetProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setMethod("POST")
@@ -146,7 +146,7 @@ public class CopyActionTest {
" \"isDefault\": false," +
" \"isInherited\": false" +
"}");
- RulesProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), targetProfile.getKee());
+ QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), targetProfile.getKee());
assertThat(loadedProfile).isNotNull();
assertThat(backuper.backupedProfile.getKee()).isEqualTo(sourceProfile.getKee());
@@ -158,8 +158,8 @@ public class CopyActionTest {
OrganizationDto organization = db.organizations().insert();
logInAsQProfileAdministrator(organization);
- RulesProfileDto parentProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
- RulesProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE), p -> p.setParentKee(parentProfile.getKee()));
+ QProfileDto parentProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
+ QProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE).setParentKee(parentProfile.getKee()));
TestResponse response = tester.newRequest()
.setMethod("POST")
@@ -176,8 +176,8 @@ public class CopyActionTest {
" \"isDefault\": false," +
" \"isInherited\": true" +
"}");
- RulesProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(organization, "target-name", sourceProfile.getLanguage(),
- db.getSession());
+ QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(db.getSession(), organization, "target-name", sourceProfile.getLanguage()
+ );
assertThat(loadedProfile.getKee()).isEqualTo(generatedUuid);
assertThat(loadedProfile.getParentKee()).isEqualTo(parentProfile.getKee());
@@ -206,7 +206,7 @@ public class CopyActionTest {
@Test
public void throw_ForbiddenException_if_not_profile_administrator_of_organization() {
OrganizationDto organization = db.organizations().insert();
- RulesProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
+ QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
userSession.logIn().addPermission(OrganizationPermission.SCAN, organization);
expectedException.expect(ForbiddenException.class);
@@ -222,7 +222,7 @@ public class CopyActionTest {
@Test
public void throw_ForbiddenException_if_not_profile_administrator() {
OrganizationDto organization = db.organizations().insert();
- RulesProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
+ QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
userSession.logIn().addPermission(OrganizationPermission.SCAN, organization);
expectedException.expect(ForbiddenException.class);
@@ -269,11 +269,11 @@ public class CopyActionTest {
private static class TestBackuper implements QProfileBackuper {
- private RulesProfileDto backupedProfile;
- private RulesProfileDto restoredProfile;
+ private QProfileDto backupedProfile;
+ private QProfileDto restoredProfile;
@Override
- public void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter) {
+ public void backup(DbSession dbSession, QProfileDto profile, Writer backupWriter) {
if (this.backupedProfile != null) {
throw new IllegalStateException("Already backup-ed/backed-up");
}
@@ -286,7 +286,7 @@ public class CopyActionTest {
}
@Override
- public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
+ public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile) {
if (this.restoredProfile != null) {
throw new IllegalStateException("Already restored");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
index e3d1f3961e1..ec2a070e406 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
@@ -38,7 +38,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
@@ -115,7 +115,7 @@ public class CreateActionTest {
CreateWsResponse response = executeRequest("New Profile", XOO_LANGUAGE);
- RulesProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "New Profile", XOO_LANGUAGE, dbSession);
+ QProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "New Profile", XOO_LANGUAGE);
assertThat(dto.getKee()).isNotNull();
assertThat(dto.getLanguage()).isEqualTo(XOO_LANGUAGE);
assertThat(dto.getName()).isEqualTo("New Profile");
@@ -137,7 +137,7 @@ public class CreateActionTest {
executeRequest("New Profile", XOO_LANGUAGE, ImmutableMap.of("xoo_lint", "<xml/>"));
- RulesProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "New Profile", XOO_LANGUAGE, dbSession);
+ QProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "New Profile", XOO_LANGUAGE);
assertThat(dto.getKee()).isNotNull();
assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, dto.getKee())).hasSize(1);
assertThat(ruleIndex.searchAll(new RuleQuery().setQProfileKey(dto.getKee()).setActivation(true))).hasSize(1);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
index f4fb92d191a..06b47cab85d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.ActiveRuleKey;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
@@ -97,7 +97,7 @@ public class DeactivateRuleActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
@@ -111,7 +111,7 @@ public class DeactivateRuleActionTest {
public void fail_deactivate_if_built_in_profile() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, profile -> profile.setIsBuiltIn(true));
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, profile -> profile.setIsBuiltIn(true));
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
@@ -125,7 +125,7 @@ public class DeactivateRuleActionTest {
@Test
public void deactivate_rule_in_default_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -144,7 +144,7 @@ public class DeactivateRuleActionTest {
@Test
public void deactivate_rule_in_specific_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java
index 667c612985a..f53472a4ddb 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java
@@ -28,8 +28,8 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
@@ -108,7 +108,7 @@ public class DeactivateRulesActionTest {
@Test
public void fail_if_built_in_profile() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, p -> p.setIsBuiltIn(true));
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, p -> p.setIsBuiltIn(true));
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("profile_key", qualityProfile.getKee());
@@ -121,7 +121,7 @@ public class DeactivateRulesActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("profile_key", qualityProfile.getKee());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
index e2f93cd6666..a1b8bdb03c1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
@@ -31,8 +31,8 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -73,9 +73,9 @@ public class DeleteActionTest {
public void delete_profile_by_key() {
OrganizationDto organization = dbTester.organizations().insert();
ComponentDto project = dbTester.components().insertPrivateProject(organization);
- RulesProfileDto profile1 = createProfile(organization);
- RulesProfileDto profile2 = createProfile(organization);
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
+ QProfileDto profile1 = createProfile(organization);
+ QProfileDto profile2 = createProfile(organization);
+ dbTester.qualityProfiles().associateWithProject(project, profile1);
logInAsQProfileAdministrator(organization);
@@ -93,9 +93,9 @@ public class DeleteActionTest {
public void delete_profile_by_language_and_name_in_default_organization() throws Exception {
OrganizationDto organization = dbTester.getDefaultOrganization();
ComponentDto project = dbTester.components().insertPrivateProject(organization);
- RulesProfileDto profile1 = createProfile(organization);
- RulesProfileDto profile2 = createProfile(organization);
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
+ QProfileDto profile1 = createProfile(organization);
+ QProfileDto profile2 = createProfile(organization);
+ dbTester.qualityProfiles().associateWithProject(project, profile1);
logInAsQProfileAdministrator(organization);
@@ -115,9 +115,9 @@ public class DeleteActionTest {
public void delete_profile_by_language_and_name_in_specified_organization() {
OrganizationDto organization = dbTester.organizations().insert();
ComponentDto project = dbTester.components().insertPrivateProject(organization);
- RulesProfileDto profile1 = createProfile(organization);
- RulesProfileDto profile2 = createProfile(organization);
- dbTester.qualityProfiles().associateProjectWithQualityProfile(project, profile1);
+ QProfileDto profile1 = createProfile(organization);
+ QProfileDto profile2 = createProfile(organization);
+ dbTester.qualityProfiles().associateWithProject(project, profile1);
logInAsQProfileAdministrator(organization);
TestResponse response = tester.newRequest()
@@ -135,7 +135,7 @@ public class DeleteActionTest {
@Test
public void fail_if_built_in_profile() {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile1 = dbTester.qualityProfiles().insert(organization, p -> p.setIsBuiltIn(true));
+ QProfileDto profile1 = dbTester.qualityProfiles().insert(organization, p -> p.setIsBuiltIn(true));
logInAsQProfileAdministrator(organization);
expectedException.expect(BadRequestException.class);
@@ -151,8 +151,8 @@ public class DeleteActionTest {
OrganizationDto organization1 = dbTester.organizations().insert();
OrganizationDto organization2 = dbTester.organizations().insert();
- RulesProfileDto profileInOrg1 = createProfile(organization1);
- RulesProfileDto profileInOrg2 = createProfile(organization2);
+ QProfileDto profileInOrg1 = createProfile(organization1);
+ QProfileDto profileInOrg2 = createProfile(organization2);
logInAsQProfileAdministrator(organization1);
@@ -167,7 +167,7 @@ public class DeleteActionTest {
@Test
public void throw_UnauthorizedException_if_not_logged_in() {
- RulesProfileDto profile = createProfile(dbTester.getDefaultOrganization());
+ QProfileDto profile = createProfile(dbTester.getDefaultOrganization());
expectedException.expect(UnauthorizedException.class);
@@ -192,7 +192,7 @@ public class DeleteActionTest {
@Test
public void throw_IAE_if_missing_language_parameter() {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile = createProfile(organization);
+ QProfileDto profile = createProfile(organization);
logInAsQProfileAdministrator(organization);
expectedException.expect(IllegalArgumentException.class);
@@ -208,7 +208,7 @@ public class DeleteActionTest {
@Test
public void throw_IAE_if_missing_name_parameter() throws Exception {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile = createProfile(organization);
+ QProfileDto profile = createProfile(organization);
logInAsQProfileAdministrator(organization);
expectedException.expect(IllegalArgumentException.class);
@@ -224,7 +224,7 @@ public class DeleteActionTest {
@Test
public void throw_IAE_if_too_many_parameters_to_reference_profile() {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile = createProfile(organization);
+ QProfileDto profile = createProfile(organization);
logInAsQProfileAdministrator(organization);
expectedException.expect(IllegalArgumentException.class);
@@ -255,8 +255,8 @@ public class DeleteActionTest {
@Test
public void throw_ISE_if_deleting_default_profile() {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile = createProfile(organization);
- dbTester.qualityProfiles().markAsDefault(profile);
+ QProfileDto profile = createProfile(organization);
+ dbTester.qualityProfiles().setAsDefault(profile);
logInAsQProfileAdministrator(organization);
expectedException.expect(IllegalArgumentException.class);
@@ -271,10 +271,9 @@ public class DeleteActionTest {
@Test
public void throw_ISE_if_a_descendant_is_marked_as_default() {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto parentProfile = createProfile(organization);
- RulesProfileDto childProfile = dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE),
- p -> p.setParentKee(parentProfile.getKee()));
- dbTester.qualityProfiles().markAsDefault(childProfile);
+ QProfileDto parentProfile = createProfile(organization);
+ QProfileDto childProfile = dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE).setParentKee(parentProfile.getKee()));
+ dbTester.qualityProfiles().setAsDefault(childProfile);
logInAsQProfileAdministrator(organization);
expectedException.expect(IllegalArgumentException.class);
@@ -293,16 +292,16 @@ public class DeleteActionTest {
.addPermission(ADMINISTER_QUALITY_PROFILES, organization);
}
- private void verifyProfileDoesNotExist(RulesProfileDto profile, OrganizationDto organization) {
- assertThat(dbClient.qualityProfileDao().selectByKey(session, profile.getKee())).isNull();
- assertThat(dbClient.qualityProfileDao().selectSelectedProjects(organization, profile.getKee(), null, session)).isEmpty();
+ private void verifyProfileDoesNotExist(QProfileDto profile, OrganizationDto organization) {
+ assertThat(dbClient.qualityProfileDao().selectByUuid(session, profile.getKee())).isNull();
+ assertThat(dbClient.qualityProfileDao().selectSelectedProjects(session, organization, profile, null)).isEmpty();
}
- private void verifyProfileExists(RulesProfileDto profile) {
- assertThat(dbClient.qualityProfileDao().selectByKey(session, profile.getKee())).isNotNull();
+ private void verifyProfileExists(QProfileDto profile) {
+ assertThat(dbClient.qualityProfileDao().selectByUuid(session, profile.getKee())).isNotNull();
}
- private RulesProfileDto createProfile(OrganizationDto organization) {
+ private QProfileDto createProfile(OrganizationDto organization) {
return dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
index c98e763228a..397a0b4b76b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
@@ -35,7 +35,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
@@ -92,7 +92,7 @@ public class ExportActionTest {
@Test
public void export_profile_in_default_organization() {
- RulesProfileDto profile = createProfile(db.getDefaultOrganization(), false);
+ QProfileDto profile = createProfile(db.getDefaultOrganization(), false);
WsActionTester tester = newWsActionTester(newExporter("polop"), newExporter("palap"));
String result = tester.newRequest()
@@ -107,7 +107,7 @@ public class ExportActionTest {
@Test
public void export_profile_in_specified_organization() {
OrganizationDto organization = db.organizations().insert();
- RulesProfileDto profile = createProfile(organization, false);
+ QProfileDto profile = createProfile(organization, false);
WsActionTester tester = newWsActionTester(newExporter("polop"), newExporter("palap"));
String result = tester.newRequest()
@@ -137,8 +137,8 @@ public class ExportActionTest {
@Test
public void export_default_profile() throws Exception {
- RulesProfileDto nonDefaultProfile = createProfile(db.getDefaultOrganization(), false);
- RulesProfileDto defaultProfile = createProfile(db.getDefaultOrganization(), true);
+ QProfileDto nonDefaultProfile = createProfile(db.getDefaultOrganization(), false);
+ QProfileDto defaultProfile = createProfile(db.getDefaultOrganization(), true);
WsActionTester tester = newWsActionTester(newExporter("polop"), newExporter("palap"));
String result = tester.newRequest()
@@ -172,7 +172,7 @@ public class ExportActionTest {
@Test
public void return_backup_when_exporter_is_not_specified() throws Exception {
OrganizationDto organization = db.getDefaultOrganization();
- RulesProfileDto profile = createProfile(organization, false);
+ QProfileDto profile = createProfile(organization, false);
String result = newWsActionTester(newExporter("polop")).newRequest()
.setParam("language", profile.getLanguage())
@@ -187,15 +187,15 @@ public class ExportActionTest {
public void do_not_mismatch_profiles_with_other_organizations_and_languages() {
OrganizationDto org1 = db.organizations().insert();
OrganizationDto org2 = db.organizations().insert();
- RulesProfileDto defaultJavaInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(JAVA_LANGUAGE), p -> p.setName("Sonar Way"));
- RulesProfileDto nonDefaultJavaInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(JAVA_LANGUAGE), p -> p.setName("My Way"));
- RulesProfileDto defaultXooInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(XOO_LANGUAGE), p -> p.setName("Sonar Way"));
- RulesProfileDto nonDefaultXooInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(XOO_LANGUAGE), p -> p.setName("My Way"));
- RulesProfileDto defaultJavaInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(JAVA_LANGUAGE), p -> p.setName("Sonar Way"));
- RulesProfileDto nonDefaultJavaInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(JAVA_LANGUAGE), p -> p.setName("My Way"));
- RulesProfileDto defaultXooInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(XOO_LANGUAGE), p -> p.setName("Sonar Way"));
- RulesProfileDto nonDefaultXooInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(XOO_LANGUAGE), p -> p.setName("My Way"));
- db.qualityProfiles().markAsDefault(defaultJavaInOrg1, defaultJavaInOrg2, defaultXooInOrg1, defaultXooInOrg2);
+ QProfileDto defaultJavaInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(JAVA_LANGUAGE).setName("Sonar Way"));
+ QProfileDto nonDefaultJavaInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(JAVA_LANGUAGE).setName("My Way"));
+ QProfileDto defaultXooInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(XOO_LANGUAGE).setName("Sonar Way"));
+ QProfileDto nonDefaultXooInOrg1 = db.qualityProfiles().insert(org1, p -> p.setLanguage(XOO_LANGUAGE).setName("My Way"));
+ QProfileDto defaultJavaInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(JAVA_LANGUAGE).setName("Sonar Way"));
+ QProfileDto nonDefaultJavaInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(JAVA_LANGUAGE).setName("My Way"));
+ QProfileDto defaultXooInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(XOO_LANGUAGE).setName("Sonar Way"));
+ QProfileDto nonDefaultXooInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(XOO_LANGUAGE).setName("My Way"));
+ db.qualityProfiles().setAsDefault(defaultJavaInOrg1, defaultJavaInOrg2, defaultXooInOrg1, defaultXooInOrg2);
WsActionTester tester = newWsActionTester();
@@ -218,10 +218,10 @@ public class ExportActionTest {
.isEqualTo("Backup of java/" + defaultJavaInOrg1.getKee());
}
- private RulesProfileDto createProfile(OrganizationDto organization, boolean isDefault) {
- RulesProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO_LANGUAGE));
+ private QProfileDto createProfile(OrganizationDto organization, boolean isDefault) {
+ QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO_LANGUAGE));
if (isDefault) {
- db.qualityProfiles().markAsDefault(profile);
+ db.qualityProfiles().setAsDefault(profile);
}
return profile;
}
@@ -252,7 +252,7 @@ public class ExportActionTest {
private static class TestBackuper implements QProfileBackuper {
@Override
- public void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter) {
+ public void backup(DbSession dbSession, QProfileDto profile, Writer backupWriter) {
try {
backupWriter.write(format("Backup of %s/%s", profile.getLanguage(), profile.getKee()));
} catch (IOException e) {
@@ -266,7 +266,7 @@ public class ExportActionTest {
}
@Override
- public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
+ public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile) {
throw new UnsupportedOperationException();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
index ecd6231471c..d7a73b48858 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
@@ -36,7 +36,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsClient;
@@ -115,28 +115,28 @@ public class InheritanceActionTest {
/*
* sonar way (2) <- companyWide (2) <- buWide (2, 1 overriding) <- (forProject1 (2), forProject2 (2))
*/
- RulesProfileDto sonarway = dbTester.qualityProfiles().insertQualityProfile(
- newQProfileDto(organization, QProfileName.createFor("xoo", "Sonar way"), "xoo-sonar-way").setIsBuiltIn(true));
+ QProfileDto sonarway = dbTester.qualityProfiles().insert(organization, p ->
+ p.setKee("xoo-sonar-way").setLanguage("xoo").setName("Sonar way").setIsBuiltIn(true));
createActiveRule(rule1, sonarway);
createActiveRule(rule2, sonarway);
dbSession.commit();
activeRuleIndexer.index();
- RulesProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345");
+ QProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345");
setParent(sonarway, companyWide);
- RulesProfileDto buWide = createProfile("xoo", "My BU Profile", "xoo-my-bu-profile-23456");
+ QProfileDto buWide = createProfile("xoo", "My BU Profile", "xoo-my-bu-profile-23456");
setParent(companyWide, buWide);
overrideActiveRuleSeverity(rule1, buWide, Severity.CRITICAL);
- RulesProfileDto forProject1 = createProfile("xoo", "For Project One", "xoo-for-project-one-34567");
+ QProfileDto forProject1 = createProfile("xoo", "For Project One", "xoo-for-project-one-34567");
setParent(buWide, forProject1);
createActiveRule(rule3, forProject1);
dbSession.commit();
activeRuleIndexer.index();
- RulesProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678");
+ QProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678");
setParent(buWide, forProject2);
overrideActiveRuleSeverity(rule2, forProject2, Severity.CRITICAL);
@@ -160,12 +160,12 @@ public class InheritanceActionTest {
RuleDefinitionDto rule3 = dbTester.rules().insert();
ruleIndexer.indexRuleDefinition(rule1.getKey());
- RulesProfileDto parent = dbTester.qualityProfiles().insert(organization);
+ QProfileDto parent = dbTester.qualityProfiles().insert(organization);
dbTester.qualityProfiles().activateRule(parent, rule1);
dbTester.qualityProfiles().activateRule(parent, rule2);
long parentRules = 2;
- RulesProfileDto child = dbTester.qualityProfiles().insert(organization, q -> q.setParentKee(parent.getKee()));
+ QProfileDto child = dbTester.qualityProfiles().insert(organization, q -> q.setParentKee(parent.getKee()));
dbTester.qualityProfiles().activateRule(child, rule3);
long childRules = 1;
@@ -192,7 +192,7 @@ public class InheritanceActionTest {
RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setStatus(RuleStatus.REMOVED));
ruleIndexer.indexRuleDefinition(rule.getKey());
- RulesProfileDto profile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto profile = dbTester.qualityProfiles().insert(organization);
dbTester.qualityProfiles().activateRule(profile, rule);
long activeRules = 0;
@@ -213,7 +213,7 @@ public class InheritanceActionTest {
@Test
public void inheritance_no_family() throws Exception {
// Simple profile, no parent, no child
- RulesProfileDto remi = createProfile("xoo", "Nobodys Boy", "xoo-nobody-s-boy-01234");
+ QProfileDto remi = createProfile("xoo", "Nobodys Boy", "xoo-nobody-s-boy-01234");
String response = wsActionTester.newRequest()
.setMethod("GET")
@@ -230,14 +230,14 @@ public class InheritanceActionTest {
.setMethod("GET").setParam("profileKey", "polop").execute();
}
- private RulesProfileDto createProfile(String lang, String name, String key) {
- RulesProfileDto profile = newQProfileDto(organization, new QProfileName(lang, name), key);
+ private QProfileDto createProfile(String lang, String name, String key) {
+ QProfileDto profile = newQProfileDto(organization, new QProfileName(lang, name), key);
dbClient.qualityProfileDao().insert(dbSession, profile);
dbSession.commit();
return profile;
}
- private void setParent(RulesProfileDto profile, RulesProfileDto parent) {
+ private void setParent(QProfileDto profile, QProfileDto parent) {
ruleActivator.setParent(dbSession, parent.getKee(), profile.getKee());
}
@@ -255,7 +255,7 @@ public class InheritanceActionTest {
return rule;
}
- private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, RulesProfileDto profile) {
+ private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) {
long now = new Date().getTime();
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString())
@@ -265,7 +265,7 @@ public class InheritanceActionTest {
return activeRule;
}
- private void overrideActiveRuleSeverity(RuleDefinitionDto rule, RulesProfileDto profile, String severity) {
+ private void overrideActiveRuleSeverity(RuleDefinitionDto rule, QProfileDto profile, String severity) {
ruleActivator.activate(dbSession, new RuleActivation(rule.getKey()).setSeverity(severity), profile.getKee());
dbSession.commit();
activeRuleIndexer.index();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
index ddd2e4a3d64..579c73ce642 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
@@ -30,7 +30,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTesting;
import org.sonar.server.exceptions.NotFoundException;
@@ -52,8 +52,8 @@ public class ProjectsActionTest {
private OrganizationDto organizationDto;
private UserDto user;
- private RulesProfileDto xooP1;
- private RulesProfileDto xooP2;
+ private QProfileDto xooP1;
+ private QProfileDto xooP2;
private ComponentDto project1;
private ComponentDto project2;
private ComponentDto project3;
@@ -205,7 +205,7 @@ public class ProjectsActionTest {
return ComponentTesting.newPrivateProjectDto(organizationDto, uuid).setName(name);
}
- private void associateProjectsWithProfile(DbSession dbSession, RulesProfileDto profile, ComponentDto... projects) {
+ private void associateProjectsWithProfile(DbSession dbSession, QProfileDto profile, ComponentDto... projects) {
for (ComponentDto project : projects) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java
index 51958153504..2e59e846494 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java
@@ -24,7 +24,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -48,9 +48,9 @@ public class QProfileWsSupportTest {
@Test
public void getProfile_returns_the_profile_specified_by_key() {
- RulesProfileDto profile = db.qualityProfiles().insertQualityProfile(QualityProfileTesting.newQualityProfileDto());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
- RulesProfileDto loaded = underTest.getProfile(db.getSession(), QProfileReference.fromKey(profile.getKee()));
+ QProfileDto loaded = underTest.getProfile(db.getSession(), QProfileReference.fromKey(profile.getKee()));
assertThat(loaded.getKee()).isEqualTo(profile.getKee());
assertThat(loaded.getOrganizationUuid()).isEqualTo(profile.getOrganizationUuid());
@@ -68,10 +68,10 @@ public class QProfileWsSupportTest {
@Test
public void getProfile_returns_the_profile_specified_by_name_and_default_organization() {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto().setOrganizationUuid(db.getDefaultOrganization().getUuid());
- db.qualityProfiles().insertQualityProfile(profile);
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setOrganizationUuid(db.getDefaultOrganization().getUuid());
+ db.qualityProfiles().insert(profile);
- RulesProfileDto loaded = underTest.getProfile(db.getSession(), QProfileReference.fromName(null, profile.getLanguage(), profile.getName()));
+ QProfileDto loaded = underTest.getProfile(db.getSession(), QProfileReference.fromName(null, profile.getLanguage(), profile.getName()));
assertThat(loaded.getKee()).isEqualTo(profile.getKee());
assertThat(loaded.getOrganizationUuid()).isEqualTo(profile.getOrganizationUuid());
@@ -81,8 +81,8 @@ public class QProfileWsSupportTest {
@Test
public void getProfile_throws_NotFoundException_if_specified_name_does_not_exist_on_default_organization() {
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto().setOrganizationUuid(db.getDefaultOrganization().getUuid());
- db.qualityProfiles().insertQualityProfile(profile);
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setOrganizationUuid(db.getDefaultOrganization().getUuid());
+ db.qualityProfiles().insert(profile);
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Quality Profile for language 'java' and name 'missing' does not exist");
@@ -93,8 +93,8 @@ public class QProfileWsSupportTest {
@Test
public void getProfile_throws_NotFoundException_if_specified_name_does_not_exist_on_specified_organization() {
OrganizationDto org1 = db.organizations().insert();
- RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto().setOrganizationUuid(org1.getUuid());
- db.qualityProfiles().insertQualityProfile(profile);
+ QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setOrganizationUuid(org1.getUuid());
+ db.qualityProfiles().insert(profile);
OrganizationDto org2 = db.organizations().insert();
expectedException.expect(NotFoundException.class);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
index b54c0147f14..d332ed9359b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
@@ -37,7 +37,7 @@ import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.SearchOptions;
@@ -98,7 +98,7 @@ public class QProfilesWsMediumTest {
@Test
public void deactivate_rule() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
createActiveRule(rule, profile);
session.commit();
@@ -121,7 +121,7 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_deactivate_rule() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto1");
RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "toto2");
RuleDefinitionDto rule2 = createRule(profile.getLanguage(), "toto3");
@@ -148,8 +148,8 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_deactivate_rule_not_all() throws Exception {
- RulesProfileDto profile = createProfile("java");
- RulesProfileDto php = createProfile("php");
+ QProfileDto profile = createProfile("java");
+ QProfileDto php = createProfile("php");
RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto1");
RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "toto2");
createActiveRule(rule0, profile);
@@ -175,7 +175,7 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_deactivate_rule_by_profile() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "hello");
RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "world");
createActiveRule(rule0, profile);
@@ -199,7 +199,7 @@ public class QProfilesWsMediumTest {
@Test
public void activate_rule() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
ruleIndexer.indexRuleDefinition(rule.getKey());
@@ -220,7 +220,7 @@ public class QProfilesWsMediumTest {
@Test
public void activate_rule_diff_languages() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule("php", "toto");
session.commit();
ruleIndexer.indexRuleDefinition(rule.getKey());
@@ -243,7 +243,7 @@ public class QProfilesWsMediumTest {
@Test
public void activate_rule_override_severity() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
ruleIndexer.indexRuleDefinition(rule.getKey());
@@ -268,7 +268,7 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_activate_rule() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
createRule(profile.getLanguage(), "toto");
createRule(profile.getLanguage(), "tata");
createRule(profile.getLanguage(), "hello");
@@ -291,8 +291,8 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_activate_rule_not_all() throws Exception {
- RulesProfileDto java = createProfile("java");
- RulesProfileDto php = createProfile("php");
+ QProfileDto java = createProfile("java");
+ QProfileDto php = createProfile("php");
createRule(java.getLanguage(), "toto");
createRule(java.getLanguage(), "tata");
createRule(php.getLanguage(), "hello");
@@ -315,7 +315,7 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_activate_rule_by_query() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
createRule(profile.getLanguage(), "toto");
createRule(profile.getLanguage(), "tata");
createRule(profile.getLanguage(), "hello");
@@ -348,7 +348,7 @@ public class QProfilesWsMediumTest {
@Test
public void bulk_activate_rule_by_query_with_severity() throws Exception {
- RulesProfileDto profile = createProfile("java");
+ QProfileDto profile = createProfile("java");
RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto");
RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "tata");
session.commit();
@@ -379,10 +379,10 @@ public class QProfilesWsMediumTest {
@Test
public void does_not_return_warnings_when_bulk_activate_on_profile_and_rules_exist_on_another_language_than_profile() throws Exception {
- RulesProfileDto javaProfile = createProfile("java");
+ QProfileDto javaProfile = createProfile("java");
createRule(javaProfile.getLanguage(), "toto");
createRule(javaProfile.getLanguage(), "tata");
- RulesProfileDto phpProfile = createProfile("php");
+ QProfileDto phpProfile = createProfile("php");
createRule(phpProfile.getLanguage(), "hello");
createRule(phpProfile.getLanguage(), "world");
session.commit();
@@ -401,8 +401,8 @@ public class QProfilesWsMediumTest {
@Test
public void reset() throws Exception {
- RulesProfileDto profile = QProfileTesting.newXooP1(organization);
- RulesProfileDto subProfile = QProfileTesting.newXooP2(organization).setParentKee(QProfileTesting.XOO_P1_KEY);
+ QProfileDto profile = QProfileTesting.newXooP1(organization);
+ QProfileDto subProfile = QProfileTesting.newXooP2(organization).setParentKee(QProfileTesting.XOO_P1_KEY);
db.qualityProfileDao().insert(session, profile, subProfile);
RuleDefinitionDto rule = createRule(profile.getLanguage(), "rule");
@@ -431,8 +431,8 @@ public class QProfilesWsMediumTest {
assertThat(db.activeRuleDao().selectOrFailByKey(session, active2.getKey()).getSeverityString()).isNotEqualTo("MINOR");
}
- private RulesProfileDto createProfile(String lang) {
- RulesProfileDto profile = QProfileTesting.newQProfileDto(organization, new QProfileName(lang, "P" + lang), "p" + lang);
+ private QProfileDto createProfile(String lang) {
+ QProfileDto profile = QProfileTesting.newQProfileDto(organization, new QProfileName(lang, "P" + lang), "p" + lang);
db.qualityProfileDao().insert(session, profile);
return profile;
}
@@ -448,7 +448,7 @@ public class QProfilesWsMediumTest {
return rule;
}
- private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, RulesProfileDto profile) {
+ private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java
index 2610ea9f219..0c0aba001a8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java
@@ -31,7 +31,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@@ -85,10 +85,10 @@ public class RemoveProjectActionTest {
logInAsProfileAdmin();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profileLang1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
- RulesProfileDto profileLang2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
- db.qualityProfiles().associateProjectWithQualityProfile(project, profileLang1);
- db.qualityProfiles().associateProjectWithQualityProfile(project, profileLang2);
+ QProfileDto profileLang1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
+ QProfileDto profileLang2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
+ db.qualityProfiles().associateWithProject(project, profileLang1);
+ db.qualityProfiles().associateWithProject(project, profileLang2);
TestResponse response = call(project, profileLang1);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
@@ -102,7 +102,7 @@ public class RemoveProjectActionTest {
logInAsProfileAdmin();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
TestResponse response = call(project, profile);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
@@ -113,8 +113,8 @@ public class RemoveProjectActionTest {
@Test
public void project_administrator_can_remove_profile() throws Exception {
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
- db.qualityProfiles().associateProjectWithQualityProfile(project, profile);
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ db.qualityProfiles().associateWithProject(project, profile);
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
call(project, profile);
@@ -126,7 +126,7 @@ public class RemoveProjectActionTest {
public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
userSession.logIn();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@@ -138,7 +138,7 @@ public class RemoveProjectActionTest {
public void throw_UnauthorizedException_if_not_logged_in() {
userSession.anonymous();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(UnauthorizedException.class);
expectedException.expectMessage("Authentication is required");
@@ -149,7 +149,7 @@ public class RemoveProjectActionTest {
@Test
public void throw_NotFoundException_if_project_does_not_exist() {
logInAsProfileAdmin();
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Component id 'unknown' not found");
@@ -174,13 +174,13 @@ public class RemoveProjectActionTest {
.execute();
}
- private void assertProjectIsAssociatedToProfile(ComponentDto project, RulesProfileDto profile) {
- RulesProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
+ private void assertProjectIsAssociatedToProfile(ComponentDto project, QProfileDto profile) {
+ QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
assertThat(loaded.getKee()).isEqualTo(profile.getKee());
}
- private void assertProjectIsNotAssociatedToProfile(ComponentDto project, RulesProfileDto profile) {
- RulesProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
+ private void assertProjectIsNotAssociatedToProfile(ComponentDto project, QProfileDto profile) {
+ QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
assertThat(loaded == null || !loaded.getKee().equals(profile.getKee())).isTrue();
}
@@ -188,7 +188,7 @@ public class RemoveProjectActionTest {
userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES, db.getDefaultOrganization());
}
- private TestResponse call(ComponentDto project, RulesProfileDto qualityProfile) {
+ private TestResponse call(ComponentDto project, QProfileDto qualityProfile) {
TestRequest request = tester.newRequest()
.setParam("projectUuid", project.uuid())
.setParam("profileKey", qualityProfile.getKee());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
index 442e974f702..ffb47f3ffd6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
@@ -27,7 +27,7 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
@@ -81,7 +81,7 @@ public class RenameActionTest {
underTest.doHandle("the new name", qualityProfileKey);
- RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), qualityProfileKey);
+ QProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), qualityProfileKey);
assertThat(reloaded.getName()).isEqualTo("the new name");
}
@@ -89,18 +89,18 @@ public class RenameActionTest {
public void fail_renaming_if_name_already_exists() {
logInAsQProfileAdministrator();
- RulesProfileDto qualityProfile1 = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto qualityProfile1 = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid())
.setLanguage("xoo")
.setName("Old, valid name");
- db.qualityProfiles().insertQualityProfile(qualityProfile1);
+ db.qualityProfiles().insert(qualityProfile1);
String qualityProfileKey1 = qualityProfile1.getKee();
- RulesProfileDto qualityProfile2 = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto qualityProfile2 = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid())
.setLanguage("xoo")
.setName("Invalid, duplicated name");
- db.qualityProfiles().insertQualityProfile(qualityProfile2);
+ db.qualityProfiles().insert(qualityProfile2);
String qualityProfileKey2 = qualityProfile2.getKee();
expectedException.expect(BadRequestException.class);
@@ -116,23 +116,23 @@ public class RenameActionTest {
userSessionRule.logIn()
.addPermission(ADMINISTER_QUALITY_PROFILES, organizationX);
- RulesProfileDto qualityProfile1 = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto qualityProfile1 = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organizationX.getUuid())
.setLanguage("xoo")
.setName("Old, unique name");
- db.qualityProfiles().insertQualityProfile(qualityProfile1);
+ db.qualityProfiles().insert(qualityProfile1);
String qualityProfileKey1 = qualityProfile1.getKee();
- RulesProfileDto qualityProfile2 = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto qualityProfile2 = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organizationY.getUuid())
.setLanguage("xoo")
.setName("Duplicated name");
- db.qualityProfiles().insertQualityProfile(qualityProfile2);
+ db.qualityProfiles().insert(qualityProfile2);
String qualityProfileKey2 = qualityProfile2.getKee();
underTest.doHandle("Duplicated name", qualityProfileKey1);
- RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), qualityProfileKey1);
+ QProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), qualityProfileKey1);
assertThat(reloaded.getName()).isEqualTo("Duplicated name");
}
@@ -167,9 +167,9 @@ public class RenameActionTest {
userSessionRule.logIn()
.addPermission(ADMINISTER_QUALITY_PROFILES, organizationX);
- RulesProfileDto qualityProfile = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto qualityProfile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organizationY.getUuid());
- db.qualityProfiles().insertQualityProfile(qualityProfile);
+ db.qualityProfiles().insert(qualityProfile);
String qualityProfileKey = qualityProfile.getKee();
expectedException.expect(ForbiddenException.class);
@@ -248,26 +248,26 @@ public class RenameActionTest {
}
private String createNewValidQualityProfileKey() {
- RulesProfileDto qualityProfile = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto qualityProfile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
- db.qualityProfiles().insertQualityProfile(qualityProfile);
+ db.qualityProfiles().insert(qualityProfile);
return qualityProfile.getKee();
}
private void createProfiles() {
String orgUuid = organization.getUuid();
dbClient.qualityProfileDao().insert(db.getSession(),
- RulesProfileDto.createFor("sonar-way-xoo1-12345")
+ QProfileDto.createFor("sonar-way-xoo1-12345")
.setOrganizationUuid(orgUuid)
.setLanguage(xoo1Key)
.setName("Sonar way"),
- RulesProfileDto.createFor("sonar-way-xoo2-23456")
+ QProfileDto.createFor("sonar-way-xoo2-23456")
.setOrganizationUuid(orgUuid)
.setLanguage(xoo2Key)
.setName("Sonar way"),
- RulesProfileDto.createFor("my-sonar-way-xoo2-34567")
+ QProfileDto.createFor("my-sonar-way-xoo2-34567")
.setOrganizationUuid(orgUuid)
.setLanguage(xoo2Key)
.setName("My Sonar way")
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RestoreActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RestoreActionTest.java
index 6433815b4ff..a0b04465cb7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RestoreActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RestoreActionTest.java
@@ -32,7 +32,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -206,7 +206,7 @@ public class RestoreActionTest {
private QProfileRestoreSummary restoredSummary;
@Override
- public void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter) {
+ public void backup(DbSession dbSession, QProfileDto profile, Writer backupWriter) {
throw new UnsupportedOperationException();
}
@@ -220,7 +220,7 @@ public class RestoreActionTest {
} catch (IOException e) {
throw new IllegalStateException(e);
}
- RulesProfileDto profile = RulesProfileDto.createFor("P1")
+ QProfileDto profile = QProfileDto.createFor("P1")
.setLanguage("xoo")
.setName(overriddenProfileName != null ? overriddenProfileName : "the-name-in-backup");
restoredSummary = new QProfileRestoreSummary(profile, new BulkChangeResult());
@@ -228,7 +228,7 @@ public class RestoreActionTest {
}
@Override
- public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
+ public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile) {
throw new UnsupportedOperationException();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
index 5ecb400568a..60a110c736a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
@@ -38,10 +38,9 @@ import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDbTester;
-import org.sonar.db.qualityprofile.QualityProfileTesting;
-import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.language.LanguageTesting;
@@ -141,34 +140,34 @@ public class SearchActionTest {
public void ws_returns_the_profiles_of_default_organization() throws Exception {
OrganizationDto organization = getDefaultOrganization();
- RulesProfileDto defaultProfile = RulesProfileDto.createFor("sonar-way-xoo1-12345")
+ QProfileDto defaultProfile = QProfileDto.createFor("sonar-way-xoo1-12345")
.setOrganizationUuid(organization.getUuid())
.setLanguage(xoo1.getKey())
.setName("Sonar way")
.setIsBuiltIn(false);
- RulesProfileDto parentProfile = RulesProfileDto
+ QProfileDto parentProfile = QProfileDto
.createFor("sonar-way-xoo2-23456")
.setOrganizationUuid(organization.getUuid())
.setLanguage(xoo2.getKey())
.setName("Sonar way")
.setIsBuiltIn(true);
- RulesProfileDto childProfile = RulesProfileDto
+ QProfileDto childProfile = QProfileDto
.createFor("my-sonar-way-xoo2-34567")
.setOrganizationUuid(organization.getUuid())
.setLanguage(xoo2.getKey())
.setName("My Sonar way")
.setParentKee(parentProfile.getKee());
- RulesProfileDto profileOnUnknownLang = RulesProfileDto.createFor("sonar-way-other-666")
+ QProfileDto profileOnUnknownLang = QProfileDto.createFor("sonar-way-other-666")
.setOrganizationUuid(organization.getUuid())
.setLanguage("other")
.setName("Sonar way");
qualityProfileDao.insert(dbSession, defaultProfile, parentProfile, childProfile, profileOnUnknownLang);
- db.qualityProfiles().markAsDefault(defaultProfile, profileOnUnknownLang);
+ db.qualityProfiles().setAsDefault(defaultProfile, profileOnUnknownLang);
ComponentDto project1 = db.components().insertPrivateProject(organization);
ComponentDto project2 = db.components().insertPrivateProject(organization);
- db.qualityProfiles().associateProjectWithQualityProfile(project1, parentProfile);
- db.qualityProfiles().associateProjectWithQualityProfile(project2, parentProfile);
+ db.qualityProfiles().associateWithProject(project1, parentProfile);
+ db.qualityProfiles().associateWithProject(project2, parentProfile);
SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
@@ -188,7 +187,7 @@ public class SearchActionTest {
@Test
public void response_contains_statistics_on_active_rules() {
- RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(xoo1.getKey()));
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(xoo1.getKey()));
RuleDefinitionDto rule = db.rules().insertRule(r -> r.setLanguage(xoo1.getKey())).getDefinition();
RuleDefinitionDto deprecatedRule1 = db.rules().insertRule(r -> r.setStatus(RuleStatus.DEPRECATED)).getDefinition();
RuleDefinitionDto deprecatedRule2 = db.rules().insertRule(r -> r.setStatus(RuleStatus.DEPRECATED)).getDefinition();
@@ -210,7 +209,7 @@ public class SearchActionTest {
@Test
public void search_map_dates() {
long time = DateUtils.parseDateTime("2016-12-22T19:10:03+0100").getTime();
- qualityProfileDb.insertQualityProfiles(newQualityProfileDto()
+ qualityProfileDb.insert(newQualityProfileDto()
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.setLanguage(xoo1.getKey())
.setRulesUpdatedAt("2016-12-21T19:10:03+0100")
@@ -228,8 +227,8 @@ public class SearchActionTest {
@Test
public void search_for_language() throws Exception {
- qualityProfileDb.insertQualityProfiles(
- RulesProfileDto.createFor("sonar-way-xoo1-12345")
+ qualityProfileDb.insert(
+ QProfileDto.createFor("sonar-way-xoo1-12345")
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.setLanguage(xoo1.getKey())
.setName("Sonar way"));
@@ -243,12 +242,12 @@ public class SearchActionTest {
public void search_for_project_qp() {
OrganizationDto org = db.organizations().insert();
ComponentDto project = db.components().insertPrivateProject(org);
- RulesProfileDto qualityProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()));
- db.qualityProfiles().associateProjectWithQualityProfile(project, qualityProfileOnXoo1);
- RulesProfileDto defaultProfileOnXoo2 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo2.getKey()));
- db.qualityProfiles().associateProjectWithQualityProfile(project, defaultProfileOnXoo2);
- RulesProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()));
- db.qualityProfiles().markAsDefault(defaultProfileOnXoo2, defaultProfileOnXoo1);
+ QProfileDto qualityProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()));
+ db.qualityProfiles().associateWithProject(project, qualityProfileOnXoo1);
+ QProfileDto defaultProfileOnXoo2 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo2.getKey()));
+ db.qualityProfiles().associateWithProject(project, defaultProfileOnXoo2);
+ QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()));
+ db.qualityProfiles().setAsDefault(defaultProfileOnXoo2, defaultProfileOnXoo1);
SearchWsResponse result = ws.newRequest()
.setParam(PARAM_PROJECT_KEY, project.key())
@@ -279,20 +278,20 @@ public class SearchActionTest {
@Test
public void search_for_default_qp_with_profile_name() {
String orgUuid = defaultOrganizationProvider.get().getUuid();
- RulesProfileDto qualityProfileOnXoo1 = RulesProfileDto.createFor("sonar-way-xoo1-12345")
+ QProfileDto qualityProfileOnXoo1 = QProfileDto.createFor("sonar-way-xoo1-12345")
.setOrganizationUuid(orgUuid)
.setLanguage(xoo1.getKey())
.setName("Sonar way");
- RulesProfileDto qualityProfileOnXoo2 = RulesProfileDto.createFor("sonar-way-xoo2-12345")
+ QProfileDto qualityProfileOnXoo2 = QProfileDto.createFor("sonar-way-xoo2-12345")
.setOrganizationUuid(orgUuid)
.setLanguage(xoo2.getKey())
.setName("Sonar way");
- RulesProfileDto anotherQualityProfileOnXoo1 = RulesProfileDto.createFor("sonar-way-xoo1-45678")
+ QProfileDto anotherQualityProfileOnXoo1 = QProfileDto.createFor("sonar-way-xoo1-45678")
.setOrganizationUuid(orgUuid)
.setLanguage(xoo1.getKey())
.setName("Another way");
- qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
- db.qualityProfiles().markAsDefault(qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
+ qualityProfileDb.insert(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
+ db.qualityProfiles().setAsDefault(qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
String result = ws.newRequest()
.setParam(PARAM_DEFAULTS, Boolean.TRUE.toString())
@@ -307,10 +306,10 @@ public class SearchActionTest {
@Test
public void search_by_profile_name() {
OrganizationDto org = db.organizations().insert();
- RulesProfileDto qualityProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()).setName("Sonar way"));
- RulesProfileDto qualityProfileOnXoo2 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo2.getKey()).setName("Sonar way"));
- RulesProfileDto anotherQualityProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()).setName("Another way"));
- db.qualityProfiles().markAsDefault(qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
+ QProfileDto qualityProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()).setName("Sonar way"));
+ QProfileDto qualityProfileOnXoo2 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo2.getKey()).setName("Sonar way"));
+ QProfileDto anotherQualityProfileOnXoo1 = db.qualityProfiles().insert(org, q -> q.setLanguage(xoo1.getKey()).setName("Another way"));
+ db.qualityProfiles().setAsDefault(qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
ComponentDto project = componentDb.insertPrivateProject(org);
SearchWsResponse result = ws.newRequest()
@@ -331,11 +330,11 @@ public class SearchActionTest {
OrganizationDto org = db.organizations().insert(OrganizationTesting.newOrganizationDto().setKey(orgKey));
dbClient.qualityProfileDao().insert(dbSession, createProfile("A", xoo1, org, "MATCH"));
dbClient.qualityProfileDao().insert(dbSession, createProfile("B", xoo2, org, "NOMATCH"));
- RulesProfileDto defaultProfileC = createProfile("C", xoo1, org, "NOMATCH");
+ QProfileDto defaultProfileC = createProfile("C", xoo1, org, "NOMATCH");
dbClient.qualityProfileDao().insert(dbSession, defaultProfileC);
- RulesProfileDto defaultProfileD = createProfile("D", xoo2, org, "NOMATCH");
+ QProfileDto defaultProfileD = createProfile("D", xoo2, org, "NOMATCH");
dbClient.qualityProfileDao().insert(dbSession, defaultProfileD);
- db.qualityProfiles().markAsDefault(defaultProfileC, defaultProfileD);
+ db.qualityProfiles().setAsDefault(defaultProfileC, defaultProfileD);
}
SearchWsRequest request = new SearchWsRequest()
@@ -427,16 +426,13 @@ public class SearchActionTest {
private void minimalValidSetup() {
for (Language language : Arrays.asList(xoo1, xoo2)) {
- RulesProfileDto profile = db.qualityProfiles().insertQualityProfile(
- QualityProfileTesting.newQualityProfileDto()
- .setOrganizationUuid(getDefaultOrganization().getUuid())
- .setLanguage(language.getKey()));
- db.qualityProfiles().markAsDefault(profile);
+ QProfileDto profile = db.qualityProfiles().insert(getDefaultOrganization(), p -> p.setLanguage(language.getKey()));
+ db.qualityProfiles().setAsDefault(profile);
}
}
- private RulesProfileDto createProfile(String keySuffix, Language language, OrganizationDto org, String name) {
- return RulesProfileDto.createFor(org.getKey() + "-" + keySuffix)
+ private QProfileDto createProfile(String keySuffix, Language language, OrganizationDto org, String name) {
+ return QProfileDto.createFor(org.getKey() + "-" + keySuffix)
.setOrganizationUuid(org.getUuid())
.setLanguage(language.getKey())
.setName(name);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java
index 29e5ceae6cb..1b7535f5874 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java
@@ -33,8 +33,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
-import org.sonar.db.qualityprofile.QualityProfileTesting;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.QProfileLookup;
@@ -87,8 +86,8 @@ public class SearchDataLoaderTest {
@Test
public void findDefaults() throws Exception {
- RulesProfileDto profile = insertQualityProfile(organization);
- dbTester.qualityProfiles().markAsDefault(profile);
+ QProfileDto profile = insertQualityProfile(organization);
+ dbTester.qualityProfiles().setAsDefault(profile);
assertThat(findProfiles(
new SearchWsRequest()
.setOrganizationKey(organization.getKey())
@@ -98,8 +97,8 @@ public class SearchDataLoaderTest {
@Test
public void findForProject() throws Exception {
- RulesProfileDto profile = insertQualityProfile(organization);
- dbTester.qualityProfiles().markAsDefault(profile);
+ QProfileDto profile = insertQualityProfile(organization);
+ dbTester.qualityProfiles().setAsDefault(profile);
ComponentDto project1 = insertProject();
assertThat(findProfiles(
new SearchWsRequest()
@@ -109,8 +108,8 @@ public class SearchDataLoaderTest {
@Test
public void findAllForLanguage() throws Exception {
- RulesProfileDto profile = insertQualityProfile(organization);
- dbTester.qualityProfiles().markAsDefault(profile);
+ QProfileDto profile = insertQualityProfile(organization);
+ dbTester.qualityProfiles().setAsDefault(profile);
assertThat(findProfiles(
new SearchWsRequest()
.setOrganizationKey(organization.getKey())
@@ -123,18 +122,14 @@ public class SearchDataLoaderTest {
null)).hasSize(0);
}
- private List<RulesProfileDto> findProfiles(SearchWsRequest request, @Nullable ComponentDto project) {
+ private List<QProfileDto> findProfiles(SearchWsRequest request, @Nullable ComponentDto project) {
return new SearchDataLoader(languages, profileLookup, dbTester.getDbClient())
.findProfiles(dbTester.getSession(), request, organization, project);
}
- private RulesProfileDto insertQualityProfile(OrganizationDto organization) {
+ private QProfileDto insertQualityProfile(OrganizationDto organization) {
Language language = insertLanguage();
- RulesProfileDto qualityProfile = QualityProfileTesting.newQualityProfileDto()
- .setOrganizationUuid(organization.getUuid())
- .setLanguage(language.getKey());
- dbTester.qualityProfiles().insertQualityProfile(qualityProfile);
- return qualityProfile;
+ return dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(language.getKey()));
}
private Language insertLanguage() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
index 895ce8d3fab..9603116e128 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@@ -62,11 +62,11 @@ public class SetDefaultActionTest {
private SetDefaultAction underTest;
/** Single, default quality profile for language xoo1 */
- private RulesProfileDto xoo1Profile;
+ private QProfileDto xoo1Profile;
/** Parent quality profile for language xoo2 (not a default) */
- private RulesProfileDto xoo2Profile;
+ private QProfileDto xoo2Profile;
/** Child quality profile for language xoo2, set as default */
- private RulesProfileDto xoo2Profile2;
+ private QProfileDto xoo2Profile2;
@Before
public void setUp() {
@@ -90,7 +90,7 @@ public class SetDefaultActionTest {
.setParentKee(xoo2Profile.getKee());
dbClient.qualityProfileDao().insert(db.getSession(), xoo1Profile, xoo2Profile, xoo2Profile2);
db.commit();
- db.qualityProfiles().markAsDefault(xoo1Profile, xoo2Profile2);
+ db.qualityProfiles().setAsDefault(xoo1Profile, xoo2Profile2);
tester = new WsActionTester(underTest);
}
@@ -149,17 +149,17 @@ public class SetDefaultActionTest {
.logIn()
.addPermission(ADMINISTER_QUALITY_PROFILES, organization1.getUuid());
- RulesProfileDto profileOrg1Old = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto profileOrg1Old = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization1.getUuid())
.setLanguage(xoo1Key);
- RulesProfileDto profileOrg1New = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto profileOrg1New = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization1.getUuid())
.setLanguage(xoo1Key);
- RulesProfileDto profileOrg2 = QualityProfileTesting.newQualityProfileDto()
+ QProfileDto profileOrg2 = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization2.getUuid())
.setLanguage(xoo1Key);
- db.qualityProfiles().insertQualityProfiles(profileOrg1Old, profileOrg1New, profileOrg2);
- db.qualityProfiles().markAsDefault(profileOrg1Old, profileOrg2);
+ db.qualityProfiles().insert(profileOrg1Old, profileOrg1New, profileOrg2);
+ db.qualityProfiles().setAsDefault(profileOrg1Old, profileOrg2);
checkDefaultProfile(organization1, xoo1Key, profileOrg1Old.getKee());
checkDefaultProfile(organization2, xoo1Key, profileOrg2.getKee());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
index 1c8a24ffe89..5f4cbea4f09 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
@@ -42,7 +42,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -446,7 +446,7 @@ public class RuleUpdaterTest {
db.rules().insertRuleParam(customRule, param -> param.setName("message").setType("STRING").setDescription("message"));
// Create a quality profile
- RulesProfileDto profileDto = QProfileTesting.newXooP1(db.getDefaultOrganization());
+ QProfileDto profileDto = QProfileTesting.newXooP1(db.getDefaultOrganization());
db.getDbClient().qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java
index 23be755b07f..4a9f39c50cf 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java
@@ -27,7 +27,7 @@ import org.sonar.api.resources.Languages;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonarqube.ws.Rules;
@@ -43,7 +43,7 @@ public class ActiveRuleCompleterTest {
OrganizationDto organization = dbTester.organizations().insert();
ActiveRuleCompleter activeRuleCompleter = new ActiveRuleCompleter(dbTester.getDbClient(), new Languages());
RuleDefinitionDto rule = dbTester.rules().insert();
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
ActiveRuleDto activeRule = dbTester.qualityProfiles().activateRule(qualityProfile, rule);
List<Rules.Active> result = activeRuleCompleter.completeShow(dbTester.getSession(), organization, rule);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/AppActionTest.java
index 59fe1de4516..7cfeed6dcd5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/AppActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/AppActionTest.java
@@ -29,7 +29,7 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleRepositoryDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
@@ -219,8 +219,8 @@ public class AppActionTest {
}
private void insertQualityProfiles(OrganizationDto organization) {
- RulesProfileDto profile1 = QProfileTesting.newXooP1(organization).setIsBuiltIn(true);
- RulesProfileDto profile2 = QProfileTesting.newXooP2(organization).setParentKee(QProfileTesting.XOO_P1_KEY);
+ QProfileDto profile1 = QProfileTesting.newXooP1(organization).setIsBuiltIn(true);
+ QProfileDto profile2 = QProfileTesting.newXooP2(organization).setParentKee(QProfileTesting.XOO_P1_KEY);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
db.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleQueryFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleQueryFactoryTest.java
index 01b970acd04..7849f2a50ab 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleQueryFactoryTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleQueryFactoryTest.java
@@ -31,7 +31,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.ws.TestRequest;
@@ -117,7 +117,7 @@ public class RuleQueryFactoryTest {
@Test
public void create_query() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RuleQuery result = execute(
PARAM_RULE_KEY, "ruleKey",
@@ -166,7 +166,7 @@ public class RuleQueryFactoryTest {
@Test
public void use_quality_profiles_language_if_available() throws Exception {
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
String qualityProfileKey = qualityProfile.getKee();
RuleQuery result = execute(
@@ -188,7 +188,7 @@ public class RuleQueryFactoryTest {
@Test
public void create_query_add_language_from_profile() throws Exception {
String profileKey = "sonar-way";
- dbClient.qualityProfileDao().insert(dbSession, RulesProfileDto.createFor(profileKey)
+ dbClient.qualityProfileDao().insert(dbSession, QProfileDto.createFor(profileKey)
.setOrganizationUuid(organization.getUuid())
.setName("Sonar Way")
.setLanguage("xoo"));
@@ -205,7 +205,7 @@ public class RuleQueryFactoryTest {
@Test
public void filter_on_quality_profiles_organization_if_searching_for_actives_with_no_organization_specified() throws Exception {
String profileKey = "sonar-way";
- dbClient.qualityProfileDao().insert(dbSession, RulesProfileDto.createFor(profileKey)
+ dbClient.qualityProfileDao().insert(dbSession, QProfileDto.createFor(profileKey)
.setOrganizationUuid(organization.getUuid())
.setName("Sonar Way")
.setLanguage("xoo"));
@@ -223,7 +223,7 @@ public class RuleQueryFactoryTest {
OrganizationDto organization1 = dbTester.organizations().insert();
OrganizationDto organization2 = dbTester.organizations().insert();
- RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);
String qualityProfileKey = qualityProfile.getKee();
String organization2Key = organization2.getKey();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
index c35db2aea05..5c37e47913e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
@@ -41,7 +41,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
@@ -311,7 +311,7 @@ public class SearchActionMediumTest {
@Test
public void search_all_active_rules() throws Exception {
- RulesProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
+ QProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDefinitionDto rule = RuleTesting.newXooX1().getDefinition();
@@ -336,10 +336,10 @@ public class SearchActionMediumTest {
@Test
public void search_profile_active_rules() throws Exception {
- RulesProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
+ QProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
tester.get(QualityProfileDao.class).insert(dbSession, profile);
- RulesProfileDto profile2 = QProfileTesting.newXooP2(defaultOrganizationDto);
+ QProfileDto profile2 = QProfileTesting.newXooP2(defaultOrganizationDto);
tester.get(QualityProfileDao.class).insert(dbSession, profile2);
dbSession.commit();
@@ -411,10 +411,10 @@ public class SearchActionMediumTest {
@Test
public void search_profile_active_rules_with_inheritance() throws Exception {
- RulesProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
+ QProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
tester.get(QualityProfileDao.class).insert(dbSession, profile);
- RulesProfileDto profile2 = QProfileTesting.newXooP2(defaultOrganizationDto).setParentKee(profile.getKee());
+ QProfileDto profile2 = QProfileTesting.newXooP2(defaultOrganizationDto).setParentKee(profile.getKee());
tester.get(QualityProfileDao.class).insert(dbSession, profile2);
dbSession.commit();
@@ -442,7 +442,7 @@ public class SearchActionMediumTest {
@Test
public void search_all_active_rules_params() throws Exception {
- RulesProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
+ QProfileDto profile = QProfileTesting.newXooP1(defaultOrganizationDto);
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDefinitionDto rule = RuleTesting.newXooX1().getDefinition();
insertRule(rule);
@@ -488,7 +488,7 @@ public class SearchActionMediumTest {
@Test
public void get_note_as_markdown_and_html() throws Exception {
- RulesProfileDto profile = QProfileTesting.newXooP1("org-123");
+ QProfileDto profile = QProfileTesting.newXooP1("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1(defaultOrganizationDto).setNoteData("this is *bold*");
insertRule(rule.getDefinition());
@@ -636,7 +636,7 @@ public class SearchActionMediumTest {
result.assertJson(getClass(), "search_rules_with_deprecated_fields.json");
}
- private ActiveRuleDto newActiveRule(RulesProfileDto profile, RuleDefinitionDto rule) {
+ private ActiveRuleDto newActiveRule(QProfileDto profile, RuleDefinitionDto rule) {
return ActiveRuleDto.createFor(profile, rule)
.setInheritance(null)
.setSeverity("BLOCKER");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
index bf86040dce5..53f17b276dd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
@@ -35,7 +35,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
@@ -275,7 +275,7 @@ public class ShowActionMediumTest {
RuleParamDto regexParam = RuleParamDto.createFor(ruleDto).setName("regex").setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*");
ruleDao.insertRuleParam(session, ruleDto, regexParam);
- RulesProfileDto profile = RulesProfileDto.createFor("profile")
+ QProfileDto profile = QProfileDto.createFor("profile")
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.setName("Profile")
.setLanguage("xoo");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
index d33f2a9a809..5cbafcf0a59 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
@@ -35,7 +35,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleMetadataDto;
import org.sonar.server.es.EsClient;
@@ -134,7 +134,7 @@ public class ShowActionTest {
public void show_rule_with_activation() throws Exception {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile = QProfileTesting.newXooP1(organization);
+ QProfileDto profile = QProfileTesting.newXooP1(organization);
dbClient.qualityProfileDao().insert(dbTester.getSession(), profile);
dbTester.commit();
@@ -176,7 +176,7 @@ public class ShowActionTest {
public void show_rule_without_activation() throws Exception {
OrganizationDto organization = dbTester.organizations().insert();
- RulesProfileDto profile = QProfileTesting.newXooP1(organization);
+ QProfileDto profile = QProfileTesting.newXooP1(organization);
dbClient.qualityProfileDao().insert(dbTester.getSession(), profile);
dbTester.commit();