aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-04-23 20:16:38 +0200
committersonartech <sonartech@sonarsource.com>2020-05-25 20:05:22 +0000
commitbf05b3c7c2e5157047dccefcfb38af0033c77f20 (patch)
treeab4dcbce1ecf30e9782c8ec3bdc56f607ce1e1b0
parent88e71c8c976210624ddb296f24f2ddcbe53417b4 (diff)
downloadsonarqube-bf05b3c7c2e5157047dccefcfb38af0033c77f20.tar.gz
sonarqube-bf05b3c7c2e5157047dccefcfb38af0033c77f20.zip
SONAR-13221 change PK of RULES and update FK
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/Rule.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleImpl.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java28
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DumbRule.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java50
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java18
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/UpdateConflictResolverTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/es/RuleExtensionId.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java26
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java25
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java18
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/DeprecatedRuleKeyDto.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java42
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java41
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java18
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleExtensionForIndexingDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java16
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml24
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml46
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml6
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml96
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl40
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java8
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java12
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java70
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java200
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java32
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java34
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java24
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java82
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java38
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java58
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java70
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java63
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java62
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java38
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java81
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java45
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java37
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java49
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java66
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java56
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java74
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java75
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java79
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java84
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java80
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java86
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java81
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java87
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java80
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java56
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java85
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java53
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java78
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java57
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java84
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql29
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql29
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql30
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql30
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql31
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql41
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql41
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql69
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql69
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql70
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql70
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql70
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql50
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql50
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql51
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql41
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql42
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql43
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql43
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java8
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java21
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java7
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java14
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java25
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java40
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java29
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java9
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java24
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java8
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java40
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java3
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java8
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java8
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java14
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java34
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java6
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java234
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java35
-rw-r--r--server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java2
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java2
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/RuleActivation.java22
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java8
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfile.java14
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java11
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImpl.java8
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImpl.java18
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/DescendantProfilesSupplier.java2
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java22
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java42
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java9
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java4
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImplTest.java20
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java5
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesUpdateListenerTest.java10
-rw-r--r--server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryRule.java2
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/rule/CachingRuleFinder.java38
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java61
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/rule/SingleDeprecatedRuleKey.java13
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinder.java6
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java18
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/BackendCleanupTest.java7
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java21
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java68
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java15
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java14
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java20
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java2
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java8
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java12
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java3
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java4
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java25
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java20
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java18
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java26
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java14
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java28
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java57
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java49
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java7
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java17
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java13
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java27
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java22
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java130
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java18
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java32
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java28
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java35
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java10
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java10
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java15
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java15
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java7
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java22
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java4
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java7
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java13
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java8
267 files changed, 7217 insertions, 1537 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java
index 04aaecbf96d..183024ac06a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java
@@ -24,6 +24,7 @@ import java.util.Objects;
import java.util.Optional;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
@@ -45,11 +46,13 @@ public class AdHocRuleCreator {
private final DbClient dbClient;
private final System2 system2;
private final RuleIndexer ruleIndexer;
+ private final UuidFactory uuidFactory;
- public AdHocRuleCreator(DbClient dbClient, System2 system2, RuleIndexer ruleIndexer) {
+ public AdHocRuleCreator(DbClient dbClient, System2 system2, RuleIndexer ruleIndexer, UuidFactory uuidFactory) {
this.dbClient = dbClient;
this.system2 = system2;
this.ruleIndexer = ruleIndexer;
+ this.uuidFactory = uuidFactory;
}
/**
@@ -63,6 +66,7 @@ public class AdHocRuleCreator {
long now = system2.now();
if (!existingRuleDtoOpt.isPresent()) {
RuleDefinitionDto dto = new RuleDefinitionDto()
+ .setUuid(uuidFactory.create())
.setRuleKey(adHoc.getKey())
.setIsExternal(true)
.setIsAdHoc(true)
@@ -73,7 +77,7 @@ public class AdHocRuleCreator {
.setUpdatedAt(now);
dao.insert(dbSession, dto);
metadata = new RuleMetadataDto()
- .setRuleId(dto.getId())
+ .setRuleUuid(dto.getUuid())
.setOrganizationUuid(organizationDto.getUuid());
} else {
// No need to update the rule, only org specific metadata
@@ -110,7 +114,7 @@ public class AdHocRuleCreator {
}
RuleDto ruleDto = dao.selectOrFailByKey(dbSession, organizationDto, adHoc.getKey());
- ruleIndexer.commitAndIndex(dbSession, ruleDto.getId());
+ ruleIndexer.commitAndIndex(dbSession, ruleDto.getUuid());
return ruleDto;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/Rule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/Rule.java
index 31e18f7c855..75aab47be47 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/Rule.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/Rule.java
@@ -27,8 +27,7 @@ import org.sonar.api.rules.RuleType;
import org.sonar.api.server.debt.DebtRemediationFunction;
public interface Rule {
-
- int getId();
+ String getUuid();
RuleKey getKey();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleImpl.java
index 5579ffc5784..f556150ddb8 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleImpl.java
@@ -36,7 +36,7 @@ import static com.google.common.collect.Sets.union;
@Immutable
public class RuleImpl implements Rule {
- private final int id;
+ private final String uuid;
private final RuleKey key;
private final String name;
private final String language;
@@ -49,7 +49,7 @@ public class RuleImpl implements Rule {
private final boolean isAdHoc;
public RuleImpl(RuleDto dto) {
- this.id = dto.getId();
+ this.uuid = dto.getUuid();
this.key = dto.getKey();
this.name = dto.getName();
this.language = dto.getLanguage();
@@ -63,8 +63,8 @@ public class RuleImpl implements Rule {
}
@Override
- public int getId() {
- return id;
+ public String getUuid() {
+ return this.uuid;
}
@Override
@@ -129,7 +129,7 @@ public class RuleImpl implements Rule {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("id", id)
+ .add("uuid", uuid)
.add("key", key)
.add("name", name)
.add("language", language)
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java
index 7056c6d963c..f2ebdac2111 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java
@@ -38,14 +38,14 @@ public interface RuleRepository {
/**
* @throws IllegalArgumentException when there is no Rule for the specified RuleKey in the repository
*/
- Rule getById(int id);
+ Rule getByUuid(String uuid);
/**
* @throws NullPointerException if {@code key} is {@code null}
*/
Optional<Rule> findByKey(RuleKey key);
- Optional<Rule> findById(int id);
+ Optional<Rule> findByUuid(String uuid);
void addOrUpdateAddHocRuleIfNeeded(RuleKey ruleKey, Supplier<NewAdHocRule> ruleSupplier);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java
index 7fc10d7af51..75118b2bd8c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java
@@ -46,7 +46,7 @@ public class RuleRepositoryImpl implements RuleRepository {
@CheckForNull
private Map<RuleKey, Rule> rulesByKey;
@CheckForNull
- private Map<Integer, Rule> rulesById;
+ private Map<String, Rule> rulesByUuid;
private final AdHocRuleCreator creator;
private final DbClient dbClient;
@@ -80,7 +80,7 @@ public class RuleRepositoryImpl implements RuleRepository {
private void persistAndIndex(DbSession dbSession, NewAdHocRule adHocRule) {
Rule rule = new RuleImpl(creator.persistAndIndex(dbSession, adHocRule, analysisMetadataHolder.getOrganization().toDto()));
- rulesById.put(rule.getId(), rule);
+ rulesByUuid.put(rule.getUuid(), rule);
rulesByKey.put(adHocRule.getKey(), rule);
}
@@ -105,19 +105,19 @@ public class RuleRepositoryImpl implements RuleRepository {
}
@Override
- public Rule getById(int id) {
+ public Rule getByUuid(String uuid) {
ensureInitialized();
- Rule rule = rulesById.get(id);
- checkArgument(rule != null, "Can not find rule for id %s. This rule does not exist in DB", id);
+ Rule rule = rulesByUuid.get(uuid);
+ checkArgument(rule != null, "Can not find rule for uuid %s. This rule does not exist in DB", uuid);
return rule;
}
@Override
- public Optional<Rule> findById(int id) {
+ public Optional<Rule> findByUuid(String uuid) {
ensureInitialized();
- return Optional.ofNullable(rulesById.get(id));
+ return Optional.ofNullable(rulesByUuid.get(uuid));
}
private static void verifyKeyArgument(RuleKey key) {
@@ -134,15 +134,15 @@ public class RuleRepositoryImpl implements RuleRepository {
private void loadRulesFromDb(DbSession dbSession) {
this.rulesByKey = new HashMap<>();
- this.rulesById = new HashMap<>();
+ this.rulesByUuid = new HashMap<>();
String organizationUuid = analysisMetadataHolder.getOrganization().getUuid();
- Multimap<Integer, DeprecatedRuleKeyDto> deprecatedRuleKeysByRuleId = dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream()
- .collect(MoreCollectors.index(DeprecatedRuleKeyDto::getRuleId));
+ Multimap<String, DeprecatedRuleKeyDto> deprecatedRuleKeysByRuleUuid = dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream()
+ .collect(MoreCollectors.index(DeprecatedRuleKeyDto::getRuleUuid));
for (RuleDto ruleDto : dbClient.ruleDao().selectAll(dbSession, organizationUuid)) {
Rule rule = new RuleImpl(ruleDto);
rulesByKey.put(ruleDto.getKey(), rule);
- rulesById.put(ruleDto.getId(), rule);
- deprecatedRuleKeysByRuleId.get(ruleDto.getId()).forEach(t -> rulesByKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), rule));
+ rulesByUuid.put(ruleDto.getUuid(), rule);
+ deprecatedRuleKeysByRuleUuid.get(ruleDto.getUuid()).forEach(t -> rulesByKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), rule));
}
}
@@ -158,8 +158,8 @@ public class RuleRepositoryImpl implements RuleRepository {
}
@Override
- public int getId() {
- throw new UnsupportedOperationException("Rule is not persisted, can't know the id");
+ public String getUuid() {
+ throw new UnsupportedOperationException("Rule is not persisted, can't know the uuid");
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
index cda36020584..ca0d94e1e0e 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
@@ -109,8 +109,8 @@ public class PersistIssuesStep implements ComputationStep {
long now = system2.now();
addedIssues.forEach(i -> {
- int ruleId = ruleRepository.getByKey(i.ruleKey()).getId();
- IssueDto dto = IssueDto.toDtoForComputationInsert(i, ruleId, now);
+ String ruleUuid = ruleRepository.getByKey(i.ruleKey()).getUuid();
+ IssueDto dto = IssueDto.toDtoForComputationInsert(i, ruleUuid, now);
mapper.insert(dto);
statistics.inserts++;
});
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java
index 8631e5f44ad..4d259df8683 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java
@@ -24,6 +24,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
@@ -46,7 +47,7 @@ public class AdHocRuleCreatorTest {
public EsTester es = EsTester.create();
private RuleIndexer indexer = new RuleIndexer(es.client(), db.getDbClient());
- private AdHocRuleCreator underTest = new AdHocRuleCreator(db.getDbClient(), System2.INSTANCE, indexer);
+ private AdHocRuleCreator underTest = new AdHocRuleCreator(db.getDbClient(), System2.INSTANCE, indexer, new SequenceUuidFactory());
private DbSession dbSession = db.getSession();
@Test
@@ -59,7 +60,7 @@ public class AdHocRuleCreatorTest {
assertThat(rule).isNotNull();
assertThat(rule.isExternal()).isTrue();
assertThat(rule.isAdHoc()).isTrue();
- assertThat(rule.getId()).isGreaterThan(0);
+ assertThat(rule.getUuid()).isNotBlank();
assertThat(rule.getKey()).isEqualTo(RuleKey.of("external_eslint", "no-cond-assign"));
assertThat(rule.getName()).isEqualTo("eslint:no-cond-assign");
assertThat(rule.getDescription()).isNull();
@@ -88,7 +89,7 @@ public class AdHocRuleCreatorTest {
assertThat(rule).isNotNull();
assertThat(rule.isExternal()).isTrue();
assertThat(rule.isAdHoc()).isTrue();
- assertThat(rule.getId()).isGreaterThan(0);
+ assertThat(rule.getUuid()).isNotBlank();
assertThat(rule.getKey()).isEqualTo(RuleKey.of("external_eslint", "no-cond-assign"));
assertThat(rule.getName()).isEqualTo("eslint:no-cond-assign");
assertThat(rule.getDescription()).isNull();
@@ -145,7 +146,7 @@ public class AdHocRuleCreatorTest {
assertThat(ruleUpdated).isNotNull();
assertThat(ruleUpdated.isExternal()).isTrue();
assertThat(ruleUpdated.isAdHoc()).isTrue();
- assertThat(ruleUpdated.getId()).isGreaterThan(0);
+ assertThat(ruleUpdated.getUuid()).isNotBlank();
assertThat(ruleUpdated.getKey()).isEqualTo(RuleKey.of("external_eslint", "no-cond-assign"));
assertThat(ruleUpdated.getName()).isEqualTo("eslint:no-cond-assign");
assertThat(ruleUpdated.getDescription()).isNull();
@@ -155,7 +156,6 @@ public class AdHocRuleCreatorTest {
assertThat(ruleUpdated.getMetadata().getAdHocDescription()).isEqualTo("A description updated");
assertThat(ruleUpdated.getMetadata().getAdHocSeverity()).isEqualTo(Severity.CRITICAL);
assertThat(ruleUpdated.getMetadata().getAdHocType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant());
-
assertThat(ruleUpdated.getDefinition().getCreatedAt()).isEqualTo(creationDate);
assertThat(ruleUpdated.getMetadata().getCreatedAt()).isEqualTo(creationDate);
assertThat(ruleUpdated.getMetadata().getUpdatedAt()).isGreaterThan(creationDate);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DumbRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DumbRule.java
index d5239af7625..2ba9da99838 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DumbRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DumbRule.java
@@ -31,7 +31,7 @@ import org.sonar.api.server.debt.DebtRemediationFunction;
import static java.util.Objects.requireNonNull;
public class DumbRule implements Rule {
- private Integer id;
+ private String uuid;
private RuleKey key;
private String name;
private String language;
@@ -45,13 +45,13 @@ public class DumbRule implements Rule {
public DumbRule(RuleKey key) {
this.key = key;
- this.id = key.hashCode();
+ this.uuid = key.rule();
this.name = "name_" + key;
}
@Override
- public int getId() {
- return requireNonNull(id);
+ public String getUuid() {
+ return requireNonNull(uuid);
}
@Override
@@ -105,8 +105,8 @@ public class DumbRule implements Rule {
return isAdHoc;
}
- public DumbRule setId(Integer id) {
- this.id = id;
+ public DumbRule setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java
index 5b5db898e6f..7e2e87fc10b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java
@@ -30,6 +30,7 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
+import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -52,14 +53,12 @@ import static org.mockito.Mockito.when;
import static org.mockito.internal.verification.VerificationModeFactory.times;
public class RuleRepositoryImplTest {
-
- private static final RuleDto AB_RULE = createABRuleDto()
- .setId(9688);
+ private static final RuleDto AB_RULE = createABRuleDto().setUuid("rule-uuid");
private static final RuleKey AB_RULE_DEPRECATED_KEY_1 = RuleKey.of("old_a", "old_b");
private static final RuleKey AB_RULE_DEPRECATED_KEY_2 = RuleKey.of(AB_RULE.getRepositoryKey(), "old_b");
private static final RuleKey DEPRECATED_KEY_OF_NON_EXITING_RULE = RuleKey.of("some_rep", "some_key");
private static final RuleKey AC_RULE_KEY = RuleKey.of("a", "c");
- private static final int AC_RULE_ID = 684;
+ private static final String AC_RULE_UUID = "uuid-684";
private static final String ORGANIZATION_UUID = "org-1";
private static final String QUALITY_GATE_UUID = "QUALITY_GATE_UUID";
@@ -77,7 +76,7 @@ public class RuleRepositoryImplTest {
private RuleDao ruleDao = mock(RuleDao.class);
private RuleIndexer ruleIndexer = mock(RuleIndexer.class);
- private AdHocRuleCreator adHocRuleCreator = new AdHocRuleCreator(db.getDbClient(), System2.INSTANCE, ruleIndexer);
+ private AdHocRuleCreator adHocRuleCreator = new AdHocRuleCreator(db.getDbClient(), System2.INSTANCE, ruleIndexer, new SequenceUuidFactory());
private RuleRepositoryImpl underTest = new RuleRepositoryImpl(adHocRuleCreator, dbClient, analysisMetadataHolder);
@Before
@@ -87,17 +86,17 @@ public class RuleRepositoryImplTest {
when(ruleDao.selectAll(any(DbSession.class), eq(ORGANIZATION_UUID))).thenReturn(ImmutableList.of(AB_RULE));
DeprecatedRuleKeyDto abDeprecatedRuleKey1 = deprecatedRuleKeyOf(AB_RULE, AB_RULE_DEPRECATED_KEY_1);
DeprecatedRuleKeyDto abDeprecatedRuleKey2 = deprecatedRuleKeyOf(AB_RULE, AB_RULE_DEPRECATED_KEY_2);
- DeprecatedRuleKeyDto deprecatedRuleOfNonExistingRule = deprecatedRuleKeyOf(77777, DEPRECATED_KEY_OF_NON_EXITING_RULE);
+ DeprecatedRuleKeyDto deprecatedRuleOfNonExistingRule = deprecatedRuleKeyOf("unknown-rule-uuid", DEPRECATED_KEY_OF_NON_EXITING_RULE);
when(ruleDao.selectAllDeprecatedRuleKeys(any(DbSession.class))).thenReturn(ImmutableSet.of(
abDeprecatedRuleKey1, abDeprecatedRuleKey2, deprecatedRuleOfNonExistingRule));
}
private static DeprecatedRuleKeyDto deprecatedRuleKeyOf(RuleDto ruleDto, RuleKey deprecatedRuleKey) {
- return deprecatedRuleKeyOf(ruleDto.getId(), deprecatedRuleKey);
+ return deprecatedRuleKeyOf(ruleDto.getUuid(), deprecatedRuleKey);
}
- private static DeprecatedRuleKeyDto deprecatedRuleKeyOf(int ruleId, RuleKey deprecatedRuleKey) {
- return new DeprecatedRuleKeyDto().setRuleId(ruleId)
+ private static DeprecatedRuleKeyDto deprecatedRuleKeyOf(String ruleUuid, RuleKey deprecatedRuleKey) {
+ return new DeprecatedRuleKeyDto().setRuleUuid(ruleUuid)
.setOldRepositoryKey(deprecatedRuleKey.repository())
.setOldRuleKey(deprecatedRuleKey.rule());
}
@@ -127,7 +126,7 @@ public class RuleRepositoryImplTest {
@Test
public void first_call_to_getById_triggers_call_to_db_and_any_subsequent_get_or_find_call_does_not() {
- underTest.getById(AB_RULE.getId());
+ underTest.getByUuid(AB_RULE.getUuid());
verify(ruleDao, times(1)).selectAll(any(DbSession.class), eq(ORGANIZATION_UUID));
@@ -136,7 +135,7 @@ public class RuleRepositoryImplTest {
@Test
public void first_call_to_findById_triggers_call_to_db_and_any_subsequent_get_or_find_call_does_not() {
- underTest.findById(AB_RULE.getId());
+ underTest.findByUuid(AB_RULE.getUuid());
verify(ruleDao, times(1)).selectAll(any(DbSession.class), eq(ORGANIZATION_UUID));
@@ -237,30 +236,30 @@ public class RuleRepositoryImplTest {
}
@Test
- public void getById_returns_Rule_if_it_exists_in_DB() {
- Rule rule = underTest.getById(AB_RULE.getId());
+ public void getByUuid_returns_Rule_if_it_exists_in_DB() {
+ Rule rule = underTest.getByUuid(AB_RULE.getUuid());
assertIsABRule(rule);
}
@Test
- public void getById_throws_IAE_if_rules_does_not_exist_in_DB() {
+ public void getByUuid_throws_IAE_if_rules_does_not_exist_in_DB() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Can not find rule for id " + AC_RULE_ID + ". This rule does not exist in DB");
+ expectedException.expectMessage("Can not find rule for uuid " + AC_RULE_UUID + ". This rule does not exist in DB");
- underTest.getById(AC_RULE_ID);
+ underTest.getByUuid(AC_RULE_UUID);
}
@Test
- public void findById_returns_absent_if_rule_does_not_exist_in_DB() {
- Optional<Rule> rule = underTest.findById(AC_RULE_ID);
+ public void findByUuid_returns_absent_if_rule_does_not_exist_in_DB() {
+ Optional<Rule> rule = underTest.findByUuid(AC_RULE_UUID);
assertThat(rule).isEmpty();
}
@Test
- public void findById_returns_Rule_if_it_exists_in_DB() {
- Optional<Rule> rule = underTest.findById(AB_RULE.getId());
+ public void findByUuid_returns_Rule_if_it_exists_in_DB() {
+ Optional<Rule> rule = underTest.findByUuid(AB_RULE.getUuid());
assertIsABRule(rule.get());
}
@@ -295,8 +294,8 @@ public class RuleRepositoryImplTest {
Rule rule = underTest.getByKey(ruleKey);
assertThat(rule).isNotNull();
- assertThat(underTest.getById(ruleDefinitionDto.get().getId())).isNotNull();
- verify(ruleIndexer).commitAndIndex(db.getSession(), ruleDefinitionDto.get().getId());
+ assertThat(underTest.getByUuid(ruleDefinitionDto.get().getUuid())).isNotNull();
+ verify(ruleIndexer).commitAndIndex(db.getSession(), ruleDefinitionDto.get().getUuid());
}
private void expectNullRuleKeyNPE() {
@@ -312,10 +311,10 @@ public class RuleRepositoryImplTest {
underTest.findByKey(AB_RULE.getKey());
assertNoCallToDb();
reset(ruleDao);
- underTest.getById(AB_RULE.getId());
+ underTest.getByUuid(AB_RULE.getUuid());
assertNoCallToDb();
reset(ruleDao);
- underTest.findById(AB_RULE.getId());
+ underTest.findByUuid(AB_RULE.getUuid());
assertNoCallToDb();
}
@@ -325,7 +324,7 @@ public class RuleRepositoryImplTest {
private void assertIsABRule(Rule rule) {
assertThat(rule).isNotNull();
- assertThat(rule.getId()).isEqualTo(AB_RULE.getId());
+ assertThat(rule.getUuid()).isEqualTo(AB_RULE.getUuid());
assertThat(rule.getKey()).isEqualTo(AB_RULE.getKey());
assertThat(rule.getRemediationFunction()).isNull();
assertThat(rule.getStatus()).isEqualTo(RuleStatus.REMOVED);
@@ -334,7 +333,6 @@ public class RuleRepositoryImplTest {
private static RuleDto createABRuleDto() {
RuleKey ruleKey = RuleKey.of("a", "b");
return new RuleDto()
- .setId(ruleKey.hashCode())
.setRepositoryKey(ruleKey.repository())
.setRuleKey(ruleKey.rule())
.setStatus(RuleStatus.REMOVED)
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java
index 092fb8179a4..2a4811aa9a7 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java
@@ -33,13 +33,13 @@ import static java.util.Objects.requireNonNull;
public class RuleRepositoryRule extends ExternalResource implements RuleRepository {
private final Map<RuleKey, Rule> rulesByKey = new HashMap<>();
- private final Map<Integer, Rule> rulesById = new HashMap<>();
+ private final Map<String, Rule> rulesByUuid = new HashMap<>();
private final Map<RuleKey, NewAdHocRule> newExternalRulesById = new HashMap<>();
@Override
protected void after() {
rulesByKey.clear();
- rulesById.clear();
+ rulesByUuid.clear();
}
@Override
@@ -50,8 +50,8 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito
}
@Override
- public Rule getById(int id) {
- Rule rule = rulesById.get(id);
+ public Rule getByUuid(String uuid) {
+ Rule rule = rulesByUuid.get(uuid);
checkArgument(rule != null);
return rule;
}
@@ -62,8 +62,8 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito
}
@Override
- public Optional<Rule> findById(int id) {
- return Optional.ofNullable(rulesById.get(id));
+ public Optional<Rule> findByUuid(String uuid) {
+ return Optional.ofNullable(rulesByUuid.get(uuid));
}
@Override
@@ -73,15 +73,15 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito
public DumbRule add(RuleKey key) {
DumbRule rule = new DumbRule(key);
- rule.setId(key.hashCode());
+ rule.setUuid(key.rule());
rulesByKey.put(key, rule);
- rulesById.put(rule.getId(), rule);
+ rulesByUuid.put(rule.getUuid(), rule);
return rule;
}
public RuleRepositoryRule add(DumbRule rule) {
rulesByKey.put(requireNonNull(rule.getKey()), rule);
- rulesById.put(rule.getId(), rule);
+ rulesByUuid.put(rule.getUuid(), rule);
return this;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/UpdateConflictResolverTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/UpdateConflictResolverTest.java
index 8ab76cd2051..8dc65df99d4 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/UpdateConflictResolverTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/UpdateConflictResolverTest.java
@@ -53,7 +53,7 @@ public class UpdateConflictResolverTest {
IssueDto issueDto = new IssueDto()
.setKee("ABCDE")
.setType(CODE_SMELL)
- .setRuleId(10)
+ .setRuleUuid("uuid-10")
.setRuleKey("squid", "AvoidCycles")
.setProjectUuid("U1")
.setComponentUuid("U2")
@@ -97,7 +97,7 @@ public class UpdateConflictResolverTest {
// Issue as seen and changed by end-user
IssueDto dbIssue = new IssueDto()
.setKee("ABCDE")
- .setRuleId(10)
+ .setRuleUuid("uuid-10")
.setRuleKey("squid", "AvoidCycles")
.setComponentUuid("100")
.setComponentKey("struts:org.apache.struts.Action")
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
index ab8b04dd67d..853bbf907c4 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
@@ -30,7 +30,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -41,7 +40,6 @@ import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
import org.sonar.ce.task.projectanalysis.metric.ReportMetricValidator;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.rule.RuleDto;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
@@ -74,8 +72,6 @@ public class MapBasedRawMeasureRepositoryTest {
private static final Measure SOME_MEASURE = Measure.newMeasureBuilder().create("some value");
- private static final RuleDto SOME_RULE = RuleDto.createFor(RuleKey.of("A", "1")).setId(963);
-
private ReportMetricValidator reportMetricValidator = mock(ReportMetricValidator.class);
private MetricRepository metricRepository = mock(MetricRepository.class);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java
index 07a397730ab..939ee87853a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java
@@ -31,6 +31,7 @@ import org.sonar.ce.task.projectanalysis.issue.NewAdHocRule;
import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl;
import org.sonar.ce.task.step.ComputationStep;
import org.sonar.ce.task.step.TestComputationStepContext;
+import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.rule.RuleDao;
@@ -60,7 +61,7 @@ public class PersistAdHocRulesStepTest extends BaseStepTest {
public EsTester es = EsTester.create();
private RuleIndexer indexer = new RuleIndexer(es.client(), dbClient);
- private AdHocRuleCreator adHocRuleCreator = new AdHocRuleCreator(dbClient, System2.INSTANCE, indexer);
+ private AdHocRuleCreator adHocRuleCreator = new AdHocRuleCreator(dbClient, System2.INSTANCE, indexer, new SequenceUuidFactory());
@Override
protected ComputationStep step() {
@@ -77,7 +78,8 @@ public class PersistAdHocRulesStepTest extends BaseStepTest {
public void persist_and_index_new_ad_hoc_rules() {
RuleKey ruleKey = RuleKey.of("external_eslint", "no-cond-assign");
- ruleRepository.addOrUpdateAddHocRuleIfNeeded(ruleKey, () -> new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("no-cond-assign").build()));
+ ruleRepository.addOrUpdateAddHocRuleIfNeeded(ruleKey,
+ () -> new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("no-cond-assign").build()));
underTest.execute(new TestComputationStepContext());
@@ -94,15 +96,16 @@ public class PersistAdHocRulesStepTest extends BaseStepTest {
assertThat(reloaded.getSeverity()).isNull();
assertThat(reloaded.getName()).isEqualTo("eslint:no-cond-assign");
- assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(1l);
- assertThat(es.getDocuments(RuleIndexDefinition.TYPE_RULE).iterator().next().getId()).isEqualTo(Integer.toString(reloaded.getId()));
+ assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(1L);
+ assertThat(es.getDocuments(RuleIndexDefinition.TYPE_RULE).iterator().next().getId()).isEqualTo(reloaded.getUuid());
}
@Test
public void do_not_persist_existing_external_rules() {
RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign");
db.rules().insert(ruleKey, r -> r.setIsExternal(true));
- ruleRepository.addOrUpdateAddHocRuleIfNeeded(ruleKey, () -> new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("no-cond-assign").build()));
+ ruleRepository.addOrUpdateAddHocRuleIfNeeded(ruleKey,
+ () -> new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("no-cond-assign").build()));
underTest.execute(new TestComputationStepContext());
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/es/RuleExtensionId.java b/server/sonar-db-dao/src/main/java/org/sonar/db/es/RuleExtensionId.java
index 483e43769d7..ded4facd8c2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/es/RuleExtensionId.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/es/RuleExtensionId.java
@@ -27,28 +27,28 @@ import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
public class RuleExtensionId {
- private final int ruleId;
+ private final String ruleUuid;
private final String organizationUuid;
private final String id;
private static final Splitter ID_SPLITTER = Splitter.on(CharMatcher.anyOf("|"));
- public RuleExtensionId(String organizationUuid, int ruleId) {
+ public RuleExtensionId(String organizationUuid, String ruleUuid) {
this.organizationUuid = organizationUuid;
- this.ruleId = ruleId;
- this.id = format("%s|%s", ruleId, organizationUuid);
+ this.ruleUuid = ruleUuid;
+ this.id = format("%s|%s", ruleUuid, organizationUuid);
}
public RuleExtensionId(String ruleExtensionId) {
List<String> splittedId = ID_SPLITTER.splitToList(ruleExtensionId);
checkArgument(splittedId.size() == 2, "Incorrect Id %s", ruleExtensionId);
this.id = ruleExtensionId;
- this.ruleId = Integer.parseInt(splittedId.get(0));
+ this.ruleUuid = splittedId.get(0);
this.organizationUuid = splittedId.get(1);
}
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return this.ruleUuid;
}
public String getOrganizationUuid() {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
index 6ce462903ca..d7853d00861 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
@@ -58,7 +58,7 @@ public final class IssueDto implements Serializable {
private String kee;
private String componentUuid;
private String projectUuid;
- private Integer ruleId;
+ private String ruleUuid;
private String severity;
private boolean manualSeverity;
private String message;
@@ -100,10 +100,14 @@ public final class IssueDto implements Serializable {
// populate only when retrieving closed issue for issue tracking
private String closedChangeData;
+ public IssueDto() {
+ // nothing to do
+ }
+
/**
* On batch side, component keys and uuid are useless
*/
- public static IssueDto toDtoForComputationInsert(DefaultIssue issue, int ruleId, long now) {
+ public static IssueDto toDtoForComputationInsert(DefaultIssue issue, String ruleUuid, long now) {
return new IssueDto()
.setKee(issue.key())
.setType(issue.type())
@@ -118,7 +122,7 @@ public final class IssueDto implements Serializable {
.setManualSeverity(issue.manualSeverity())
.setChecksum(issue.checksum())
.setAssigneeUuid(issue.assignee())
- .setRuleId(ruleId)
+ .setRuleUuid(ruleUuid)
.setRuleKey(issue.ruleKey().repository(), issue.ruleKey().rule())
.setExternal(issue.isFromExternalRuleEngine())
.setTags(issue.tags())
@@ -143,8 +147,8 @@ public final class IssueDto implements Serializable {
/**
* On server side, we need component keys and uuid
*/
- public static IssueDto toDtoForServerInsert(DefaultIssue issue, ComponentDto component, ComponentDto project, int ruleId, long now) {
- return toDtoForComputationInsert(issue, ruleId, now)
+ public static IssueDto toDtoForServerInsert(DefaultIssue issue, ComponentDto component, ComponentDto project, String ruleUuid, long now) {
+ return toDtoForComputationInsert(issue, ruleUuid, now)
.setComponent(component)
.setProject(project);
}
@@ -213,15 +217,15 @@ public final class IssueDto implements Serializable {
return this;
}
- public Integer getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
/**
* please use setRule(RuleDto rule)
*/
- public IssueDto setRuleId(Integer ruleId) {
- this.ruleId = ruleId;
+ public IssueDto setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
return this;
}
@@ -437,8 +441,8 @@ public final class IssueDto implements Serializable {
}
public IssueDto setRule(RuleDefinitionDto rule) {
- Preconditions.checkNotNull(rule.getId(), "Rule must be persisted.");
- this.ruleId = rule.getId();
+ Preconditions.checkNotNull(rule.getUuid(), "Rule must be persisted.");
+ this.ruleUuid = rule.getUuid();
this.ruleKey = rule.getRuleKey();
this.ruleRepo = rule.getRepositoryKey();
this.language = rule.getLanguage();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
index a5ef41393fe..650e7dd6a5c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
@@ -58,16 +58,16 @@ public class ActiveRuleDao implements Dao {
return Optional.ofNullable(mapper(dbSession).selectByKey(key.getRuleProfileUuid(), key.getRuleKey().repository(), key.getRuleKey().rule()));
}
- public List<OrgActiveRuleDto> selectByRuleId(DbSession dbSession, OrganizationDto organization, int ruleId) {
- return mapper(dbSession).selectByRuleId(organization.getUuid(), ruleId);
+ public List<OrgActiveRuleDto> selectByRuleUuid(DbSession dbSession, OrganizationDto organization, String ruleUuid) {
+ return mapper(dbSession).selectByRuleUuid(organization.getUuid(), ruleUuid);
}
- public List<ActiveRuleDto> selectByRuleIdOfAllOrganizations(DbSession dbSession, int ruleId) {
- return mapper(dbSession).selectByRuleIdOfAllOrganizations(ruleId);
+ public List<ActiveRuleDto> selectByRuleUuidOfAllOrganizations(DbSession dbSession, String ruleUuid) {
+ return mapper(dbSession).selectByRuleUuidOfAllOrganizations(ruleUuid);
}
- public List<OrgActiveRuleDto> selectByRuleIds(DbSession dbSession, OrganizationDto organization, List<Integer> ids) {
- return executeLargeInputs(ids, chunk -> mapper(dbSession).selectByRuleIds(organization.getUuid(), chunk));
+ public List<OrgActiveRuleDto> selectByRuleUuids(DbSession dbSession, OrganizationDto organization, List<String> uuids) {
+ return executeLargeInputs(uuids, chunk -> mapper(dbSession).selectByRuleUuids(organization.getUuid(), chunk));
}
/**
@@ -89,17 +89,18 @@ public class ActiveRuleDao implements Dao {
return mapper(dbSession).selectByRuleProfileUuid(ruleProfileDto.getUuid());
}
- public Collection<ActiveRuleDto> selectByRulesAndRuleProfileUuids(DbSession dbSession, Collection<Integer> ruleIds, Collection<String> ruleProfileUuids) {
- if (ruleIds.isEmpty() || ruleProfileUuids.isEmpty()) {
+ public Collection<ActiveRuleDto> selectByRulesAndRuleProfileUuids(DbSession dbSession, Collection<String> ruleUuids, Collection<String> ruleProfileUuids) {
+ if (ruleUuids.isEmpty() || ruleProfileUuids.isEmpty()) {
return emptyList();
}
ActiveRuleMapper mapper = mapper(dbSession);
- return executeLargeInputs(ruleIds, ruleIdsChunk -> executeLargeInputs(ruleProfileUuids, chunk -> mapper.selectByRuleIdsAndRuleProfileUuids(ruleIdsChunk, chunk)));
+ return executeLargeInputs(ruleUuids,
+ ruleUuidsChunk -> executeLargeInputs(ruleProfileUuids, chunk -> mapper.selectByRuleUuidsAndRuleProfileUuids(ruleUuidsChunk, chunk)));
}
public ActiveRuleDto insert(DbSession dbSession, ActiveRuleDto item) {
checkArgument(item.getProfileUuid() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
- checkArgument(item.getRuleId() != null, RULE_IS_NOT_PERSISTED);
+ checkArgument(item.getRuleUuid() != null, RULE_IS_NOT_PERSISTED);
checkArgument(item.getUuid() == null, ACTIVE_RULE_IS_ALREADY_PERSISTED);
item.setUuid(uuidFactory.create());
@@ -109,7 +110,7 @@ public class ActiveRuleDao implements Dao {
public ActiveRuleDto update(DbSession dbSession, ActiveRuleDto item) {
checkArgument(item.getProfileUuid() != null, QUALITY_PROFILE_IS_NOT_PERSISTED);
- checkArgument(item.getRuleId() != null, ActiveRuleDao.RULE_IS_NOT_PERSISTED);
+ checkArgument(item.getRuleUuid() != null, ActiveRuleDao.RULE_IS_NOT_PERSISTED);
checkArgument(item.getUuid() != null, ACTIVE_RULE_IS_NOT_PERSISTED);
mapper(dbSession).update(item);
return item;
@@ -176,7 +177,7 @@ public class ActiveRuleDao implements Dao {
}
public void deleteParamsByRuleParamOfAllOrganizations(DbSession dbSession, RuleParamDto param) {
- List<ActiveRuleDto> activeRules = selectByRuleIdOfAllOrganizations(dbSession, param.getRuleId());
+ List<ActiveRuleDto> activeRules = selectByRuleUuidOfAllOrganizations(dbSession, param.getRuleUuid());
for (ActiveRuleDto activeRule : activeRules) {
for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleUuid(dbSession, activeRule.getUuid())) {
if (activeParam.getKey().equals(param.getName())) {
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 21426eea525..88b5f3cdb42 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
@@ -38,7 +38,7 @@ public class ActiveRuleDto {
private String uuid;
private String profileUuid;
- private Integer ruleId;
+ private String ruleUuid;
private Integer severity;
private String inheritance;
@@ -51,6 +51,10 @@ public class ActiveRuleDto {
private String ruleProfileUuid;
private String securityStandards;
+ public ActiveRuleDto() {
+ // nothing to do here
+ }
+
public ActiveRuleDto setKey(ActiveRuleKey key) {
this.repository = key.getRuleKey().repository();
this.ruleField = key.getRuleKey().rule();
@@ -84,12 +88,12 @@ public class ActiveRuleDto {
return this;
}
- public Integer getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
- public ActiveRuleDto setRuleId(Integer ruleId) {
- this.ruleId = ruleId;
+ public ActiveRuleDto setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
return this;
}
@@ -158,10 +162,10 @@ public class ActiveRuleDto {
public static ActiveRuleDto createFor(QProfileDto profile, RuleDefinitionDto ruleDto) {
requireNonNull(profile.getRulesProfileUuid(), "Profile is not persisted");
- requireNonNull(ruleDto.getId(), "Rule is not persisted");
+ requireNonNull(ruleDto.getUuid(), "Rule is not persisted");
ActiveRuleDto dto = new ActiveRuleDto();
dto.setProfileUuid(profile.getRulesProfileUuid());
- dto.setRuleId(ruleDto.getId());
+ dto.setRuleUuid(ruleDto.getUuid());
dto.setKey(ActiveRuleKey.of(profile, ruleDto.getKey()));
return dto;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java
index 36b75922667..c7909a8cdd2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java
@@ -45,11 +45,11 @@ public interface ActiveRuleMapper {
List<ActiveRuleDto> selectByKeys(@Param("keys") List<ActiveRuleKey> keys);
- List<OrgActiveRuleDto> selectByRuleId(@Param("organizationUuid") String organizationUuid, @Param("ruleId") int ruleId);
+ List<OrgActiveRuleDto> selectByRuleUuid(@Param("organizationUuid") String organizationUuid, @Param("ruleUuid") String ruleUuid);
- List<ActiveRuleDto> selectByRuleIdOfAllOrganizations(int ruleId);
+ List<ActiveRuleDto> selectByRuleUuidOfAllOrganizations(String ruleUuid);
- List<OrgActiveRuleDto> selectByRuleIds(@Param("organizationUuid") String organizationUuid, @Param("ruleIds") List<Integer> partitionOfRuleIds);
+ List<OrgActiveRuleDto> selectByRuleUuids(@Param("organizationUuid") String organizationUuid, @Param("ruleUuids") List<String> partitionOfRuleUuids);
List<OrgActiveRuleDto> selectByProfileUuid(String uuid);
@@ -57,8 +57,8 @@ public interface ActiveRuleMapper {
List<ActiveRuleDto> selectByRuleProfileUuid(@Param("ruleProfileUuid") String uuid);
- List<ActiveRuleDto> selectByRuleIdsAndRuleProfileUuids(
- @Param("ruleIds") Collection<Integer> ruleIds,
+ List<ActiveRuleDto> selectByRuleUuidsAndRuleProfileUuids(
+ @Param("ruleUuids") Collection<String> ruleUuids,
@Param("ruleProfileUuids") Collection<String> ruleProfileUuids);
void insertParameter(ActiveRuleParamDto dto);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java
index d953b8e6fc3..8d37c4fb44e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java
@@ -23,19 +23,23 @@ import javax.annotation.CheckForNull;
public class IndexedActiveRuleDto {
private String uuid;
- private int ruleId;
+ private String ruleUuid;
private int severity;
private String inheritance;
private String repository;
private String key;
private String ruleProfileUuid;
+ public IndexedActiveRuleDto() {
+ // nothing to do here
+ }
+
public String getUuid() {
return uuid;
}
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
public int getSeverity() {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/DeprecatedRuleKeyDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/DeprecatedRuleKeyDto.java
index 4e1019196fd..1b110ecb29d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/DeprecatedRuleKeyDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/DeprecatedRuleKeyDto.java
@@ -31,9 +31,9 @@ public class DeprecatedRuleKeyDto {
*/
private String uuid;
/**
- * the id of the current rule for this deprecated key
+ * the uuid of the current rule for this deprecated key
*/
- private Integer ruleId;
+ private String ruleUuid;
/**
* repository key that was deprecated
*/
@@ -56,6 +56,10 @@ public class DeprecatedRuleKeyDto {
*/
private String newRuleKey;
+ public DeprecatedRuleKeyDto() {
+ // nothing to do here
+ }
+
public String getUuid() {
return uuid;
}
@@ -65,12 +69,12 @@ public class DeprecatedRuleKeyDto {
return this;
}
- public Integer getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
- public DeprecatedRuleKeyDto setRuleId(Integer ruleId) {
- this.ruleId = ruleId;
+ public DeprecatedRuleKeyDto setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
index 7fa6d8a3554..419f4485eeb 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
@@ -86,30 +86,30 @@ public class RuleDao implements Dao {
return rule;
}
- public Optional<RuleDto> selectById(long id, String organizationUuid, DbSession session) {
- RuleDto res = mapper(session).selectById(organizationUuid, id);
+ public Optional<RuleDto> selectByUuid(String uuid, String organizationUuid, DbSession session) {
+ RuleDto res = mapper(session).selectByUuid(organizationUuid, uuid);
ensureOrganizationIsSet(organizationUuid, res);
return ofNullable(res);
}
- public Optional<RuleDefinitionDto> selectDefinitionById(long id, DbSession session) {
- return ofNullable(mapper(session).selectDefinitionById(id));
+ public Optional<RuleDefinitionDto> selectDefinitionByUuid(String uuid, DbSession session) {
+ return ofNullable(mapper(session).selectDefinitionByUuid(uuid));
}
- public List<RuleDto> selectByIds(DbSession session, String organizationUuid, List<Integer> ids) {
- if (ids.isEmpty()) {
+ public List<RuleDto> selectByUuids(DbSession session, String organizationUuid, List<String> uuids) {
+ if (uuids.isEmpty()) {
return emptyList();
}
return ensureOrganizationIsSet(
organizationUuid,
- executeLargeInputs(ids, chunk -> mapper(session).selectByIds(organizationUuid, chunk)));
+ executeLargeInputs(uuids, chunk -> mapper(session).selectByUuids(organizationUuid, chunk)));
}
- public List<RuleDefinitionDto> selectDefinitionByIds(DbSession session, Collection<Integer> ids) {
- if (ids.isEmpty()) {
+ public List<RuleDefinitionDto> selectDefinitionByUuids(DbSession session, Collection<String> uuids) {
+ if (uuids.isEmpty()) {
return emptyList();
}
- return executeLargeInputs(ids, mapper(session)::selectDefinitionByIds);
+ return executeLargeInputs(uuids, mapper(session)::selectDefinitionByUuids);
}
public List<RuleDto> selectByKeys(DbSession session, OrganizationDto organization, Collection<RuleKey> keys) {
@@ -168,10 +168,12 @@ public class RuleDao implements Dao {
}
public void insert(DbSession session, RuleDefinitionDto dto) {
+ checkNotNull(dto.getUuid(), "RuleDefinitionDto has no 'uuid'.");
mapper(session).insertDefinition(dto);
}
public void insert(DbSession session, RuleMetadataDto dto) {
+ checkNotNull(dto.getRuleUuid(), "RuleMetadataDto has no 'ruleUuid'.");
mapper(session).insertMetadata(dto);
}
@@ -203,12 +205,12 @@ public class RuleDao implements Dao {
});
}
- public void scrollIndexingRulesByKeys(DbSession dbSession, Collection<Integer> ruleIds, Consumer<RuleForIndexingDto> consumer) {
+ public void scrollIndexingRulesByKeys(DbSession dbSession, Collection<String> ruleUuids, Consumer<RuleForIndexingDto> consumer) {
RuleMapper mapper = mapper(dbSession);
- executeLargeInputsWithoutOutput(ruleIds,
- pageOfRuleIds -> mapper
- .selectIndexingRulesByIds(pageOfRuleIds)
+ executeLargeInputsWithoutOutput(ruleUuids,
+ pageOfRuleUuids -> mapper
+ .selectIndexingRulesByUuids(pageOfRuleUuids)
.forEach(consumer));
}
@@ -235,22 +237,22 @@ public class RuleDao implements Dao {
return executeLargeInputs(ruleKeys, mapper(session)::selectParamsByRuleKeys);
}
- public List<RuleParamDto> selectRuleParamsByRuleIds(DbSession dbSession, Collection<Integer> ruleIds) {
- return executeLargeInputs(ruleIds, mapper(dbSession)::selectParamsByRuleIds);
+ public List<RuleParamDto> selectRuleParamsByRuleUuids(DbSession dbSession, Collection<String> ruleUuids) {
+ return executeLargeInputs(ruleUuids, mapper(dbSession)::selectParamsByRuleUuids);
}
public void insertRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) {
- checkNotNull(rule.getId(), "Rule id must be set");
- param.setRuleId(rule.getId());
+ checkNotNull(rule.getUuid(), "Rule uuid must be set");
+ param.setRuleUuid(rule.getUuid());
param.setUuid(uuidFactory.create());
mapper(session).insertParameter(param);
}
public RuleParamDto updateRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) {
- checkNotNull(rule.getId(), "Rule id must be set");
+ checkNotNull(rule.getUuid(), "Rule uuid must be set");
checkNotNull(param.getUuid(), "Rule parameter is not yet persisted must be set");
- param.setRuleId(rule.getId());
+ param.setRuleUuid(rule.getUuid());
mapper(session).updateParameter(param);
return param;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
index b16251f1264..ad96e58961e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
@@ -38,7 +38,7 @@ public class RuleDefinitionDto {
private static final Splitter SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
- private Integer id;
+ private String uuid;
private String repositoryKey;
private String ruleKey;
@@ -75,7 +75,7 @@ public class RuleDefinitionDto {
private boolean isAdHoc;
private String language;
- private Integer templateId;
+ private String templateUuid;
private String defRemediationFunction;
private String defRemediationGapMultiplier;
private String defRemediationBaseEffort;
@@ -92,6 +92,10 @@ public class RuleDefinitionDto {
private long createdAt;
private long updatedAt;
+ public RuleDefinitionDto() {
+ // nothing to do here
+ }
+
public static Set<String> deserializeTagsString(@Nullable String tags) {
return deserializeStringSet(tags);
}
@@ -126,12 +130,12 @@ public class RuleDefinitionDto {
return this;
}
- public Integer getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
- public RuleDefinitionDto setId(Integer id) {
- this.id = id;
+ public RuleDefinitionDto setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
@@ -267,16 +271,16 @@ public class RuleDefinitionDto {
}
@CheckForNull
- public Integer getTemplateId() {
- return templateId;
+ public String getTemplateUuid() {
+ return templateUuid;
}
public boolean isCustomRule() {
- return getTemplateId() != null;
+ return getTemplateUuid() != null;
}
- public RuleDefinitionDto setTemplateId(@Nullable Integer templateId) {
- this.templateId = templateId;
+ public RuleDefinitionDto setTemplateUuid(@Nullable String templateUuid) {
+ this.templateUuid = templateUuid;
return this;
}
@@ -414,27 +418,20 @@ public class RuleDefinitionDto {
return true;
}
RuleDefinitionDto other = (RuleDefinitionDto) obj;
- return Objects.equals(id, other.id);
+ return Objects.equals(this.uuid, other.uuid);
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(id)
+ .append(this.uuid)
.toHashCode();
}
- public static RuleDto createFor(RuleKey key) {
- return new RuleDto()
- .setId(new HashCodeBuilder(17, 37).append(key.rule()).append(key.repository()).toHashCode())
- .setRepositoryKey(key.repository())
- .setRuleKey(key.rule());
- }
-
@Override
public String toString() {
return "RuleDefinitionDto{" +
- "id=" + id +
+ "uuid=" + uuid +
", repositoryKey='" + repositoryKey + '\'' +
", ruleKey='" + ruleKey + '\'' +
", description='" + description + '\'' +
@@ -445,7 +442,7 @@ public class RuleDefinitionDto {
", severity=" + severity +
", isTemplate=" + isTemplate +
", language='" + language + '\'' +
- ", templateId=" + templateId +
+ ", templateUuid=" + templateUuid +
", defRemediationFunction='" + defRemediationFunction + '\'' +
", defRemediationGapMultiplier='" + defRemediationGapMultiplier + '\'' +
", defRemediationBaseEffort='" + defRemediationBaseEffort + '\'' +
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
index 2371d7d3a45..cae2d18cade 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
@@ -62,13 +62,13 @@ public class RuleDto {
return definition.getKey();
}
- public Integer getId() {
- return definition.getId();
+ public String getUuid() {
+ return definition.getUuid();
}
- public RuleDto setId(Integer id) {
- definition.setId(id);
- metadata.setRuleId(id);
+ public RuleDto setUuid(String uuid) {
+ definition.setUuid(uuid);
+ metadata.setRuleUuid(uuid);
return this;
}
@@ -257,12 +257,12 @@ public class RuleDto {
}
@CheckForNull
- public Integer getTemplateId() {
- return definition.getTemplateId();
+ public String getTemplateUuid() {
+ return definition.getTemplateUuid();
}
- public RuleDto setTemplateId(@Nullable Integer templateId) {
- definition.setTemplateId(templateId);
+ public RuleDto setTemplateUuid(@Nullable String templateUuid) {
+ definition.setTemplateUuid(templateUuid);
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleExtensionForIndexingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleExtensionForIndexingDto.java
index 8e4f1c52b6e..bc82e93c302 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleExtensionForIndexingDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleExtensionForIndexingDto.java
@@ -28,7 +28,7 @@ public class RuleExtensionForIndexingDto {
private static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
- private int ruleId;
+ private String ruleUuid;
private String pluginName;
private String pluginRuleKey;
private String organizationUuid;
@@ -52,12 +52,12 @@ public class RuleExtensionForIndexingDto {
return this;
}
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
- public void setRuleId(int ruleId) {
- this.ruleId = ruleId;
+ public void setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
}
public String getOrganizationUuid() {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java
index 5a427e86aaa..046a4e5c333 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java
@@ -27,7 +27,7 @@ import org.sonar.api.rules.RuleType;
public class RuleForIndexingDto {
- private Integer id;
+ private String uuid;
private String repository;
private String pluginRuleKey;
private String name;
@@ -47,8 +47,12 @@ public class RuleForIndexingDto {
private long createdAt;
private long updatedAt;
- public Integer getId() {
- return id;
+ public RuleForIndexingDto() {
+ // nothing to do here
+ }
+
+ public String getUuid() {
+ return uuid;
}
public String getRepository() {
@@ -110,7 +114,7 @@ public class RuleForIndexingDto {
public int getType() {
return type;
}
-
+
public boolean isExternal() {
return isExternal;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java
index 8c26caa5e10..debac92c73d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java
@@ -35,13 +35,13 @@ public interface RuleMapper {
void selectEnabled(ResultHandler<RuleDefinitionDto> resultHandler);
- RuleDto selectById(@Param("organizationUuid") String organizationUuid, @Param("id") long id);
+ RuleDto selectByUuid(@Param("organizationUuid") String organizationUuid, @Param("uuid") String uuid);
- RuleDefinitionDto selectDefinitionById(long id);
+ RuleDefinitionDto selectDefinitionByUuid(String uuid);
- List<RuleDto> selectByIds(@Param("organizationUuid") String organizationUuid, @Param("ids") List<Integer> ids);
+ List<RuleDto> selectByUuids(@Param("organizationUuid") String organizationUuid, @Param("uuids") List<String> uuids);
- List<RuleDefinitionDto> selectDefinitionByIds(@Param("ids") List<Integer> ids);
+ List<RuleDefinitionDto> selectDefinitionByUuids(@Param("uuids") List<String> uuids);
RuleDto selectByKey(@Param("organizationUuid") String organizationUuid, @Param("ruleKey") RuleKey ruleKey);
@@ -55,7 +55,7 @@ public interface RuleMapper {
void scrollIndexingRules(ResultHandler<RuleForIndexingDto> handler);
- List<RuleForIndexingDto> selectIndexingRulesByIds(@Param("ruleIds") List<Integer> ruleIds);
+ List<RuleForIndexingDto> selectIndexingRulesByUuids(@Param("ruleUuids") List<String> ruleUuids);
void scrollIndexingRuleExtensions(ResultHandler<RuleExtensionForIndexingDto> handler);
@@ -75,7 +75,7 @@ public interface RuleMapper {
void updateMetadata(RuleMetadataDto ruleMetadataDto);
- List<RuleParamDto> selectParamsByRuleIds(@Param("ruleIds") List<Integer> ruleIds);
+ List<RuleParamDto> selectParamsByRuleUuids(@Param("ruleUuids") List<String> ruleUuids);
List<RuleParamDto> selectParamsByRuleKey(RuleKey ruleKey);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java
index 13be206ac0f..168305cc358 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java
@@ -31,7 +31,7 @@ import org.sonar.api.rules.RuleType;
import static com.google.common.base.Preconditions.checkArgument;
public class RuleMetadataDto {
- private int ruleId;
+ private String ruleUuid;
private String organizationUuid;
private String noteData;
private String noteUserUuid;
@@ -42,6 +42,10 @@ public class RuleMetadataDto {
private String remediationBaseEffort;
private String tags;
+ public RuleMetadataDto() {
+ // nothing to do here
+ }
+
/**
* Name of on ad hoc rule.
* When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set
@@ -68,12 +72,12 @@ public class RuleMetadataDto {
private long createdAt;
private long updatedAt;
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
- public RuleMetadataDto setRuleId(int ruleId) {
- this.ruleId = ruleId;
+ public RuleMetadataDto setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
return this;
}
@@ -245,7 +249,7 @@ public class RuleMetadataDto {
@Override
public String toString() {
return "RuleMetadataDto{" +
- "ruleId=" + ruleId +
+ "ruleUuid=" + ruleUuid +
", organizationUuid='" + organizationUuid + '\'' +
", noteData='" + noteData + '\'' +
", noteUserUuid='" + noteUserUuid + '\'' +
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java
index d30ad25377e..646db3038a8 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java
@@ -29,12 +29,16 @@ import static com.google.common.base.Preconditions.checkArgument;
public class RuleParamDto {
private String uuid;
- private Integer ruleId;
+ private String ruleUuid;
private String name;
private String type;
private String defaultValue;
private String description;
+ public RuleParamDto() {
+ // nothing to do here
+ }
+
public String getUuid() {
return uuid;
}
@@ -44,12 +48,12 @@ public class RuleParamDto {
return this;
}
- public Integer getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
- public RuleParamDto setRuleId(Integer ruleId) {
- this.ruleId = ruleId;
+ public RuleParamDto setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
return this;
}
@@ -100,7 +104,7 @@ public class RuleParamDto {
public static RuleParamDto createFor(RuleDefinitionDto rule) {
// Should eventually switch to RuleKey (RuleKey is available before insert)
- return new RuleParamDto().setRuleId(rule.getId());
+ return new RuleParamDto().setRuleUuid(rule.getUuid());
}
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
index ad92cab0658..5dc62303552 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
@@ -6,7 +6,7 @@
<sql id="issueColumns">
i.kee as kee,
- i.rule_id as ruleId,
+ i.rule_uuid as ruleUuid,
i.severity as severity,
i.manual_severity as manualSeverity,
i.message as message,
@@ -99,11 +99,13 @@
<insert id="insert" parameterType="Issue" useGeneratedKeys="false">
- INSERT INTO issues (kee, rule_id, severity, manual_severity,
+ INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
message, line, locations, gap, effort, status, tags,
resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date,
issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type)
- VALUES (#{kee,jdbcType=VARCHAR}, #{ruleId,jdbcType=INTEGER},
+ VALUES (
+ #{kee,jdbcType=VARCHAR},
+ #{ruleUuid,jdbcType=VARCHAR},
#{severity,jdbcType=VARCHAR},
#{manualSeverity,jdbcType=BOOLEAN}, #{message,jdbcType=VARCHAR}, #{line,jdbcType=INTEGER},
#{locations,jdbcType=BINARY},
@@ -179,7 +181,7 @@
select
<include refid="issueColumns"/>
from issues i
- inner join rules r on r.id=i.rule_id
+ inner join rules r on r.uuid=i.rule_uuid
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
where i.kee=#{kee,jdbcType=VARCHAR}
@@ -189,7 +191,7 @@
select
<include refid="issueColumns"/>
from issues i
- inner join rules r on r.id=i.rule_id
+ inner join rules r on r.uuid=i.rule_uuid
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
where
@@ -201,7 +203,7 @@
select
<include refid="issueColumns"/>
from issues i
- inner join rules r on r.id=i.rule_id
+ inner join rules r on r.uuid=i.rule_uuid
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
where
@@ -217,7 +219,7 @@
ic.change_data as closedChangeData
from issues i
inner join rules r on
- r.id = i.rule_id
+ r.uuid = i.rule_uuid
inner join components p on
p.uuid = i.component_uuid
inner join components root on
@@ -259,7 +261,7 @@
select
<include refid="issueColumns"/>
from issues i
- inner join rules r on r.id=i.rule_id
+ inner join rules r on r.uuid=i.rule_uuid
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
where i.kee in
@@ -272,7 +274,7 @@
select
<include refid="issueColumns"/>
from issues i
- inner join rules r on r.id=i.rule_id
+ inner join rules r on r.uuid=i.rule_uuid
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
where
@@ -296,7 +298,7 @@
b.kee as branchKey,
b.key_type as keyType
from issues i
- inner join rules r on r.id = i.rule_id
+ inner join rules r on r.uuid = i.rule_uuid
inner join project_branches b on i.project_uuid = b.uuid
where i.component_uuid in
<foreach collection="list" open="(" close=")" item="key" separator=",">
@@ -309,7 +311,7 @@
select
<include refid="issueColumns"/>
from issues i
- inner join rules r on r.id = i.rule_id
+ inner join rules r on r.uuid = i.rule_uuid
inner join components p on p.uuid = i.component_uuid
inner join components root on root.uuid = i.project_uuid
where
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 c40c83c6e51..3a88ac5f287 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
@@ -6,7 +6,7 @@
<sql id="activeRuleColumns">
a.uuid,
a.profile_uuid as "profileUuid",
- a.rule_id as "ruleId",
+ a.rule_uuid as "ruleUuid",
a.failure_level as "severity",
a.inheritance as "inheritance",
r.plugin_rule_key as "rulefield",
@@ -19,7 +19,7 @@
<sql id="orgActiveRuleColumns">
a.uuid,
a.profile_uuid as "profileUuid",
- a.rule_id as "ruleId",
+ a.rule_uuid as "ruleUuid",
a.failure_level as "severity",
a.inheritance as "inheritance",
r.plugin_rule_key as "rulefield",
@@ -34,22 +34,22 @@
<sql id="activeRuleKeyJoin">
inner join rules_profiles rp on rp.uuid = a.profile_uuid
- inner join rules r on r.id = a.rule_id
+ inner join rules r on r.uuid = a.rule_uuid
</sql>
<insert id="insert" parameterType="ActiveRule">
insert into active_rules (
uuid,
profile_uuid,
- rule_id,
+ rule_uuid,
failure_level,
inheritance,
created_at,
updated_at
) values (
#{uuid, jdbcType=VARCHAR},
- #{profileUuid, jdbcType=BIGINT},
- #{ruleId, jdbcType=BIGINT},
+ #{profileUuid, jdbcType=VARCHAR},
+ #{ruleUuid, jdbcType=VARCHAR},
#{severity, jdbcType=INTEGER},
#{inheritance, jdbcType=VARCHAR},
#{createdAt, jdbcType=BIGINT},
@@ -122,7 +122,7 @@
from active_rules a
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
- inner join rules r on r.id = a.rule_id and r.status != 'REMOVED'
+ inner join rules r on r.uuid = a.rule_uuid and r.status != 'REMOVED'
where oqp.uuid = #{id, jdbcType=VARCHAR}
</select>
@@ -132,7 +132,7 @@
from active_rules a
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
- inner join rules r on r.id = a.rule_id and r.status != 'REMOVED'
+ inner join rules r on r.uuid = a.rule_uuid and r.status != 'REMOVED'
where
r.rule_type in <foreach collection="types" item="type" separator="," open="(" close=")">#{type, jdbcType=INTEGER}</foreach>
and oqp.uuid in <foreach collection="profileUuids" item="uuid" separator="," open="(" close=")">#{uuid, jdbcType=VARCHAR}</foreach>
@@ -147,48 +147,48 @@
rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR}
</select>
- <select id="selectByRuleIdsAndRuleProfileUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.ActiveRuleDto">
+ <select id="selectByRuleUuidsAndRuleProfileUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.ActiveRuleDto">
select
<include refid="activeRuleColumns"/>
from active_rules a
<include refid="activeRuleKeyJoin"/>
where
- r.id in <foreach collection="ruleIds" item="ruleId" separator="," open="(" close=")">#{ruleId, jdbcType=BIGINT}</foreach>
+ r.uuid in <foreach collection="ruleUuids" item="ruleUuid" separator="," open="(" close=")">#{ruleUuid, jdbcType=VARCHAR}</foreach>
and rp.uuid in <foreach collection="ruleProfileUuids" item="ruleProfileUuid" separator="," open="(" close=")">#{ruleProfileUuid, jdbcType=VARCHAR}</foreach>
</select>
- <select id="selectByRuleId" parameterType="map" resultType="org.sonar.db.qualityprofile.OrgActiveRuleDto">
+ <select id="selectByRuleUuid" parameterType="map" resultType="org.sonar.db.qualityprofile.OrgActiveRuleDto">
select
<include refid="orgActiveRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
- inner join rules r on r.id = a.rule_id
+ inner join rules r on r.uuid = a.rule_uuid
where
- a.rule_id = #{ruleId, jdbcType=BIGINT}
+ a.rule_uuid = #{ruleUuid, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
- <select id="selectByRuleIdOfAllOrganizations" parameterType="Integer" resultType="ActiveRule">
+ <select id="selectByRuleUuidOfAllOrganizations" parameterType="String" resultType="ActiveRule">
select
<include refid="activeRuleColumns"/>
from active_rules a
<include refid="activeRuleKeyJoin"/>
where
- a.rule_id = #{ruleId, jdbcType=BIGINT}
+ r.uuid = #{ruleUuid, jdbcType=VARCHAR}
</select>
- <select id="selectByRuleIds" parameterType="List" resultType="org.sonar.db.qualityprofile.OrgActiveRuleDto">
+ <select id="selectByRuleUuids" parameterType="List" resultType="org.sonar.db.qualityprofile.OrgActiveRuleDto">
select
<include refid="orgActiveRuleColumns"/>
from active_rules a
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
- inner join rules r on r.id = a.rule_id
+ inner join rules r on r.uuid = a.rule_uuid
where
- a.rule_id in
- <foreach collection="ruleIds" item="ruleId" separator="," open="(" close=")">
- #{ruleId, jdbcType=BIGINT}
+ a.rule_uuid in
+ <foreach collection="ruleUuids" item="ruleUuid" separator="," open="(" close=")">
+ #{ruleUuid, jdbcType=VARCHAR}
</foreach>
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
@@ -278,7 +278,7 @@
from active_rules ar
inner join rules_profiles rp on rp.uuid = ar.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
- inner join rules r on r.id = ar.rule_id
+ inner join rules r on r.uuid = ar.rule_uuid
<where>
oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and <foreach collection="profileUuids" item="profileUuid" open="(" separator=" or " close=")">
@@ -319,13 +319,13 @@
ar.uuid as "uuid",
ar.failure_level as "severity",
ar.inheritance as "inheritance",
- r.id as "ruleId",
+ r.uuid as "ruleUuid",
r.plugin_name as "repository",
r.plugin_rule_key as "key",
rp.uuid as "ruleProfileUuid"
from active_rules ar
inner join rules_profiles rp on rp.uuid = ar.profile_uuid
- inner join rules r on r.id = ar.rule_id
+ inner join rules r on r.uuid = ar.rule_uuid
</sql>
</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
index 36fdc79bec6..5b1a7825a80 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml
@@ -30,9 +30,9 @@
from active_rules a
inner join rules_profiles rp on rp.uuid = a.profile_uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.uuid
- inner join rules r on r.id = a.rule_id and r.status != 'REMOVED'
- left join rules rt on rt.id = r.template_id
- left join rules_metadata rm on rm.rule_id = r.id
+ inner join rules r on r.uuid = a.rule_uuid and r.status != 'REMOVED'
+ left join rules rt on rt.uuid = r.template_uuid
+ left join rules_metadata rm on rm.rule_uuid = r.uuid
where oqp.uuid = #{id, jdbcType=VARCHAR}
</select>
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 2afa6e164fd..9856551d7ba 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
@@ -157,7 +157,7 @@
AND rp.language IN <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
AND NOT EXISTS (
SELECT 1 FROM active_rules ar
- INNER JOIN rules r ON r.id = ar.rule_id AND r.status &lt;&gt; 'REMOVED'
+ INNER JOIN rules r ON r.uuid = ar.rule_uuid AND r.status &lt;&gt; 'REMOVED'
WHERE profile_uuid = rp.uuid
)
</select>
@@ -181,7 +181,7 @@
where rp.is_built_in = ${_true}
AND EXISTS (
SELECT 1 FROM active_rules ar
- INNER JOIN rules r ON r.id = ar.rule_id AND r.status &lt;&gt; 'REMOVED'
+ INNER JOIN rules r ON r.uuid = ar.rule_uuid AND r.status &lt;&gt; 'REMOVED'
WHERE profile_uuid=rp.uuid
)
</select>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
index b55391d4cbc..c05c5bd0a6b 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
@@ -4,7 +4,7 @@
<mapper namespace="org.sonar.db.rule.RuleMapper">
<sql id="selectDefinitionColumns">
- r.id,
+ r.uuid,
r.plugin_rule_key as "ruleKey",
r.plugin_name as "repositoryKey",
r.description,
@@ -17,7 +17,7 @@
r.is_external as "isExternal",
r.is_ad_hoc as "isAdHoc",
r.language as "language",
- r.template_id as "templateId",
+ r.template_uuid as "templateUuid",
r.def_remediation_function as "defRemediationFunction",
r.def_remediation_gap_mult as "defRemediationGapMultiplier",
r.def_remediation_base_effort as "defRemediationBaseEffort",
@@ -57,7 +57,7 @@
<sql id="outerJoinRulesMetadata">
left outer join rules_metadata rm on
- rm.rule_id = r.id
+ rm.rule_uuid = r.uuid
and rm.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
</sql>
@@ -85,45 +85,45 @@
r.status != 'REMOVED'
</select>
- <select id="selectById" parameterType="map" resultType="Rule">
+ <select id="selectByUuid" parameterType="map" resultType="Rule">
select
<include refid="selectJoinedTablesColumns"/>
from
rules r
<include refid="outerJoinRulesMetadata"/>
where
- r.id=#{id,jdbcType=INTEGER}
+ r.uuid=#{uuid,jdbcType=VARCHAR}
</select>
- <select id="selectDefinitionById" parameterType="Long" resultType="org.sonar.db.rule.RuleDefinitionDto">
+ <select id="selectDefinitionByUuid" parameterType="String" resultType="org.sonar.db.rule.RuleDefinitionDto">
select
<include refid="selectRuleTableColumns"/>
from
rules r
where
- r.id=#{id,jdbcType=INTEGER}
+ r.uuid=#{uuid,jdbcType=VARCHAR}
</select>
- <select id="selectByIds" parameterType="map" resultType="Rule">
+ <select id="selectByUuids" parameterType="map" resultType="Rule">
select
<include refid="selectJoinedTablesColumns"/>
from
rules r
<include refid="outerJoinRulesMetadata"/>
where
- <foreach collection="ids" index="index" item="id" open="" separator=" or " close="">
- r.id=#{id,jdbcType=INTEGER}
+ <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
+ r.uuid=#{uuid,jdbcType=VARCHAR}
</foreach>
</select>
- <select id="selectDefinitionByIds" parameterType="map" resultType="org.sonar.db.rule.RuleDefinitionDto">
+ <select id="selectDefinitionByUuids" parameterType="map" resultType="org.sonar.db.rule.RuleDefinitionDto">
select
<include refid="selectRuleTableColumns"/>
from
rules r
where
- <foreach collection="ids" index="index" item="id" open="" separator=" or " close="">
- r.id=#{id,jdbcType=INTEGER}
+ <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
+ r.uuid=#{uuid,jdbcType=VARCHAR}
</foreach>
</select>
@@ -152,7 +152,7 @@
<include refid="sqlSelectIndexingRuleExtensions" />
and
<foreach collection="ruleExtensionIds" index="index" item="ruleExtId" open="" separator=" or " close="">
- ( r.id = #{ruleExtId.ruleId, jdbcType=INTEGER} and
+ ( r.uuid = #{ruleExtId.ruleUuid, jdbcType=VARCHAR} and
rm.organization_uuid = #{ruleExtId.organizationUuid, jdbcType=VARCHAR} )
</foreach>
</select>
@@ -163,13 +163,13 @@
<sql id="sqlSelectIndexingRuleExtensions">
select
- r.id as "ruleId",
+ r.uuid as "ruleUuid",
r.plugin_name as "pluginName",
r.plugin_rule_key as "pluginRuleKey",
rm.organization_uuid as "organizationUuid",
rm.tags as "tags"
from rules r
- inner join rules_metadata rm on rm.rule_id = r.id
+ inner join rules_metadata rm on rm.rule_uuid = r.uuid
where
rm.tags is not null and
rm.tags != ''
@@ -177,20 +177,20 @@
<sql id="sqlSelectIndexingRuleExtensions" databaseId="oracle">
select
- r.id as "ruleId",
+ r.uuid as "ruleUuid",
r.plugin_name as "pluginName",
r.plugin_rule_key as "pluginRuleKey",
rm.organization_uuid as "organizationUuid",
rm.tags as "tags"
from rules r
- inner join rules_metadata rm on rm.rule_id = r.id
+ inner join rules_metadata rm on rm.rule_uuid = r.uuid
where
rm.tags is not null
</sql>
<select id="selectMetadataByKey" parameterType="map" resultType="org.sonar.db.rule.RuleMetadataDto">
select
- rm.rule_id as "ruleId",
+ rm.rule_uuid as "ruleUuid",
rm.organization_uuid as "organizationUuid",
rm.note_data as "noteData",
rm.note_user_uuid as "noteUserUuid",
@@ -208,7 +208,7 @@
rm.updated_at as "updatedAt"
from
rules_metadata rm
- inner join rules r on rm.rule_id = r.id
+ inner join rules r on rm.rule_uuid = r.uuid
where
r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR}
and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR}
@@ -238,21 +238,23 @@
</foreach>
</select>
- <select id="selectIndexingRulesByIds" parameterType="map" resultType="org.sonar.db.rule.RuleForIndexingDto">
+ <select id="selectIndexingRulesByUuids" parameterType="map" resultType="org.sonar.db.rule.RuleForIndexingDto">
<include refid="sqlSelectIndexingRules"/>
where
- <foreach collection="ruleIds" index="index" item="ruleId" open="" separator=" or " close="">
- r.id=#{ruleId,jdbcType=INTEGER}
+ <foreach collection="ruleUuids" index="index" item="ruleUuid" open="" separator=" or " close="">
+ r.uuid=#{ruleUuid,jdbcType=VARCHAR}
</foreach>
+ order by r.created_at asc
</select>
<select id="scrollIndexingRules" resultType="org.sonar.db.rule.RuleForIndexingDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
<include refid="sqlSelectIndexingRules"/>
+ order by r.created_at asc
</select>
<sql id="sqlSelectIndexingRules">
select
- r.id as "id",
+ r.uuid as "uuid",
r.plugin_name as "repository",
r.plugin_rule_key as "pluginRuleKey",
r.name as "name",
@@ -272,7 +274,7 @@
r.created_at as "createdAt",
r.updated_at as "updatedAt"
from rules r
- left outer join rules t on t.id = r.template_id
+ left outer join rules t on t.uuid = r.template_uuid
</sql>
<select id="selectByQuery" parameterType="map" resultType="Rule">
@@ -308,8 +310,9 @@
and r.language in <foreach collection="languages" item="language" separator="," open="(" close=")">#{language, jdbcType=VARCHAR}</foreach>
</select>
- <insert id="insertDefinition" parameterType="org.sonar.db.rule.RuleDefinitionDto" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <insert id="insertDefinition" parameterType="org.sonar.db.rule.RuleDefinitionDto" useGeneratedKeys="false">
insert into rules (
+ uuid,
plugin_key,
plugin_rule_key,
plugin_name,
@@ -323,7 +326,7 @@
is_external,
is_ad_hoc,
language,
- template_id,
+ template_uuid,
def_remediation_function,
def_remediation_gap_mult,
def_remediation_base_effort,
@@ -336,6 +339,7 @@
updated_at
)
values (
+ #{uuid,jdbcType=VARCHAR},
#{pluginKey,jdbcType=VARCHAR},
#{ruleKey,jdbcType=VARCHAR},
#{repositoryKey,jdbcType=VARCHAR},
@@ -349,7 +353,7 @@
#{isExternal,jdbcType=BOOLEAN},
#{isAdHoc,jdbcType=BOOLEAN},
#{language,jdbcType=VARCHAR},
- #{templateId,jdbcType=INTEGER},
+ #{templateUuid,jdbcType=VARCHAR},
#{defRemediationFunction,jdbcType=VARCHAR},
#{defRemediationGapMultiplier,jdbcType=VARCHAR},
#{defRemediationBaseEffort,jdbcType=VARCHAR},
@@ -378,7 +382,7 @@
is_external=#{isExternal,jdbcType=BOOLEAN},
is_ad_hoc=#{isAdHoc,jdbcType=BOOLEAN},
language=#{language,jdbcType=VARCHAR},
- template_id=#{templateId,jdbcType=INTEGER},
+ template_uuid=#{templateUuid,jdbcType=VARCHAR},
def_remediation_function=#{defRemediationFunction,jdbcType=VARCHAR},
def_remediation_gap_mult=#{defRemediationGapMultiplier,jdbcType=VARCHAR},
def_remediation_base_effort=#{defRemediationBaseEffort,jdbcType=VARCHAR},
@@ -389,7 +393,7 @@
rule_type=#{type,jdbcType=TINYINT},
updated_at=#{updatedAt,jdbcType=BIGINT}
where
- id=#{id,jdbcType=INTEGER}
+ uuid=#{uuid,jdbcType=VARCHAR}
</update>
<select id="countMetadata" parameterType="org.sonar.db.rule.RuleMetadataDto" resultType="int">
@@ -398,13 +402,13 @@
from
rules_metadata rm
where
- rm.rule_id=#{ruleId,jdbcType=INTEGER}
+ rm.rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
and rm.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
</select>
<insert id="insertMetadata" parameterType="org.sonar.db.rule.RuleMetadataDto">
insert into rules_metadata (
- rule_id,
+ rule_uuid,
organization_uuid,
note_data,
note_user_uuid,
@@ -422,7 +426,7 @@
updated_at
)
values (
- #{ruleId,jdbcType=INTEGER},
+ #{ruleUuid,jdbcType=VARCHAR},
#{organizationUuid,jdbcType=VARCHAR},
#{noteData,jdbcType=CLOB},
#{noteUserUuid,jdbcType=VARCHAR},
@@ -457,7 +461,7 @@
ad_hoc_type=#{adHocType,jdbcType=TINYINT},
updated_at=#{updatedAt,jdbcType=BIGINT}
where
- rule_id=#{ruleId,jdbcType=INTEGER}
+ rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
and organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
</update>
@@ -470,21 +474,21 @@
<sql id="paramColumns">
p.uuid as "uuid",
- p.rule_id as "ruleId",
+ p.rule_uuid as "ruleUuid",
p.name as "name",
p.param_type as "type",
p.default_value as "defaultValue",
p.description as "description"
</sql>
- <select id="selectParamsByRuleIds" resultType="RuleParam">
+ <select id="selectParamsByRuleUuids" resultType="RuleParam">
select
<include refid="paramColumns"/>
from
rules_parameters p
where
- <foreach item="id" index="index" collection="ruleIds" open="(" separator=" or " close=")">
- p.rule_id=#{id,jdbcType=INTEGER}
+ <foreach item="uuid" index="index" collection="ruleUuids" open="(" separator=" or " close=")">
+ p.rule_uuid=#{uuid,jdbcType=VARCHAR}
</foreach>
</select>
@@ -494,7 +498,7 @@
from
rules_parameters p, rules r
where
- p.rule_id=r.id
+ p.rule_uuid=r.uuid
and r.plugin_name=#{repository,jdbcType=VARCHAR}
and r.plugin_rule_key=#{rule,jdbcType=VARCHAR}
</select>
@@ -505,7 +509,7 @@
from
rules_parameters p
inner join rules r on
- r.id=p.rule_id
+ r.uuid=p.rule_uuid
where
<foreach collection="ruleKeys" index="index" item="ruleKey" open="" separator=" or " close="">
(r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} AND r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR})
@@ -522,7 +526,7 @@
<insert id="insertParameter" parameterType="RuleParam" useGeneratedKeys="false">
insert into rules_parameters (
uuid,
- rule_id,
+ rule_uuid,
name,
param_type,
default_value,
@@ -530,7 +534,7 @@
)
values (
#{uuid,jdbcType=VARCHAR},
- #{ruleId,jdbcType=INTEGER},
+ #{ruleUuid,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR},
#{defaultValue,jdbcType=VARCHAR},
@@ -550,7 +554,7 @@
<select id="selectAllDeprecatedRuleKeys" resultType="org.sonar.db.rule.DeprecatedRuleKeyDto">
SELECT
drk.uuid,
- drk.rule_id as "ruleId",
+ drk.rule_uuid as "ruleUuid",
drk.old_repository_key as "oldRepositoryKey",
drk.old_rule_key as "oldRuleKey",
r.plugin_rule_key as "newRuleKey",
@@ -558,7 +562,7 @@
drk.created_at as "createdAt"
FROM
deprecated_rule_keys drk
- LEFT OUTER JOIN rules r on r.id = drk.rule_id
+ LEFT OUTER JOIN rules r on r.uuid = drk.rule_uuid
</select>
<delete id="deleteDeprecatedRuleKeys">
@@ -573,14 +577,14 @@
<insert id="insertDeprecatedRuleKey" parameterType="org.sonar.db.rule.DeprecatedRuleKeyDto" keyColumn="uuid" useGeneratedKeys="false" keyProperty="uuid">
INSERT INTO deprecated_rule_keys (
uuid,
- rule_id,
+ rule_uuid,
old_repository_key,
old_rule_key,
created_at
)
values (
#{uuid,jdbcType=VARCHAR},
- #{ruleId,jdbcType=INTEGER},
+ #{ruleUuid,jdbcType=VARCHAR},
#{oldRepositoryKey,jdbcType=VARCHAR},
#{oldRuleKey,jdbcType=VARCHAR},
#{createdAt,jdbcType=BIGINT}
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 6920ec72c82..4690b546381 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -24,16 +24,16 @@ ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS"
CREATE INDEX "ARP_ACTIVE_RULE_UUID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_UUID");
CREATE TABLE "ACTIVE_RULES"(
- "RULE_ID" INTEGER NOT NULL,
"FAILURE_LEVEL" INTEGER NOT NULL,
"INHERITANCE" VARCHAR(10),
"CREATED_AT" BIGINT,
"UPDATED_AT" BIGINT,
"UUID" VARCHAR(40) NOT NULL,
- "PROFILE_UUID" VARCHAR(40) NOT NULL
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_UUIDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_UUID");
CREATE TABLE "ALM_APP_INSTALLS"(
"UUID" VARCHAR(40) NOT NULL,
@@ -226,14 +226,14 @@ CREATE UNIQUE INDEX "UNIQ_DEFAULT_QPROFILES_UUID" ON "DEFAULT_QPROFILES"("QPROFI
CREATE TABLE "DEPRECATED_RULE_KEYS"(
"UUID" VARCHAR(40) NOT NULL,
- "RULE_ID" INTEGER NOT NULL,
"OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
"OLD_RULE_KEY" VARCHAR(200) NOT NULL,
- "CREATED_AT" BIGINT NOT NULL
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
-CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
+CREATE INDEX "RULE_UUID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_UUID");
CREATE TABLE "DUPLICATIONS_INDEX"(
"ANALYSIS_UUID" VARCHAR(50) NOT NULL,
@@ -377,7 +377,6 @@ CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
CREATE TABLE "ISSUES"(
"KEE" VARCHAR(50) NOT NULL,
- "RULE_ID" INTEGER,
"SEVERITY" VARCHAR(10),
"MANUAL_SEVERITY" BOOLEAN NOT NULL,
"MESSAGE" VARCHAR(4000),
@@ -402,7 +401,8 @@ CREATE TABLE "ISSUES"(
"PROJECT_UUID" VARCHAR(50),
"LOCATIONS" BLOB,
"ISSUE_TYPE" TINYINT,
- "FROM_HOTSPOT" BOOLEAN
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
);
ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
@@ -411,8 +411,8 @@ CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
+CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID");
CREATE TABLE "LIVE_MEASURES"(
"UUID" VARCHAR(40) NOT NULL,
@@ -799,7 +799,6 @@ CREATE TABLE "RULE_REPOSITORIES"(
ALTER TABLE "RULE_REPOSITORIES" ADD CONSTRAINT "PK_RULE_REPOSITORIES" PRIMARY KEY("KEE");
CREATE TABLE "RULES"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"NAME" VARCHAR(200),
"PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
"PLUGIN_KEY" VARCHAR(200),
@@ -808,7 +807,6 @@ CREATE TABLE "RULES"(
"SCOPE" VARCHAR(20) NOT NULL,
"DESCRIPTION" CLOB(2147483647),
"PRIORITY" INTEGER,
- "TEMPLATE_ID" INTEGER,
"STATUS" VARCHAR(40),
"LANGUAGE" VARCHAR(20),
"DEF_REMEDIATION_FUNCTION" VARCHAR(20),
@@ -823,13 +821,14 @@ CREATE TABLE "RULES"(
"IS_AD_HOC" BOOLEAN NOT NULL,
"IS_EXTERNAL" BOOLEAN NOT NULL,
"CREATED_AT" BIGINT,
- "UPDATED_AT" BIGINT
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
);
-ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
CREATE TABLE "RULES_METADATA"(
- "RULE_ID" INTEGER NOT NULL,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"NOTE_DATA" CLOB(2147483647),
"NOTE_USER_UUID" VARCHAR(255),
@@ -844,21 +843,22 @@ CREATE TABLE "RULES_METADATA"(
"AD_HOC_SEVERITY" VARCHAR(10),
"AD_HOC_TYPE" TINYINT,
"CREATED_AT" BIGINT NOT NULL,
- "UPDATED_AT" BIGINT NOT NULL
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
);
-ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_UUID", "ORGANIZATION_UUID");
CREATE TABLE "RULES_PARAMETERS"(
- "RULE_ID" INTEGER NOT NULL,
"NAME" VARCHAR(128) NOT NULL,
"DESCRIPTION" VARCHAR(4000),
"PARAM_TYPE" VARCHAR(512) NOT NULL,
"DEFAULT_VALUE" VARCHAR(4000),
- "UUID" VARCHAR(40) NOT NULL
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
-CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
-CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
+CREATE INDEX "RULES_PARAMETERS_RULE_UUID" ON "RULES_PARAMETERS"("RULE_UUID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_UUID", "NAME");
CREATE TABLE "RULES_PROFILES"(
"NAME" VARCHAR(100) NOT NULL,
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
index daeba88d07e..1621814abab 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
@@ -81,7 +81,7 @@ public class IssueDaoTest {
assertThat(issue.getKee()).isEqualTo(ISSUE_KEY1);
assertThat(issue.getComponentUuid()).isEqualTo(FILE_UUID);
assertThat(issue.getProjectUuid()).isEqualTo(PROJECT_UUID);
- assertThat(issue.getRuleId()).isEqualTo(RULE.getId());
+ assertThat(issue.getRuleUuid()).isEqualTo(RULE.getUuid());
assertThat(issue.getLanguage()).isEqualTo(RULE.getLanguage());
assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
assertThat(issue.getType()).isEqualTo(2);
@@ -396,7 +396,7 @@ public class IssueDaoTest {
IssueDto dto = new IssueDto();
dto.setComponent(new ComponentDto().setDbKey("struts:Action").setUuid("component-uuid"));
dto.setProject(new ComponentDto().setDbKey("struts").setUuid("project-uuid"));
- dto.setRule(RuleTesting.newRule(RuleKey.of("squid", "S001")).setId(200));
+ dto.setRule(RuleTesting.newRule(RuleKey.of("squid", "S001")).setUuid("uuid-200"));
dto.setKee(key);
dto.setType(2);
dto.setLine(500);
@@ -425,11 +425,11 @@ public class IssueDaoTest {
db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setDbKey(FILE_KEY));
underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY1)
.setMessage("the message")
- .setRuleId(RULE.getId())
+ .setRuleUuid(RULE.getUuid())
.setComponentUuid(FILE_UUID)
.setProjectUuid(PROJECT_UUID));
underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY2)
- .setRuleId(RULE.getId())
+ .setRuleUuid(RULE.getUuid())
.setComponentUuid(FILE_UUID)
.setProjectUuid(PROJECT_UUID));
db.getSession().commit();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
index 7890696671b..fe148e3fd0c 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
@@ -60,7 +60,7 @@ public class IssueDtoTest {
IssueDto dto = new IssueDto()
.setKee("100")
.setType(RuleType.VULNERABILITY)
- .setRuleId(1)
+ .setRuleUuid("rule-uuid-1")
.setRuleKey("squid", "AvoidCycle")
.setLanguage("xoo")
.setComponentKey("org.sonar.sample:Sample")
@@ -116,10 +116,10 @@ public class IssueDtoTest {
public void set_rule() {
IssueDto dto = new IssueDto()
.setKee("100")
- .setRule(new RuleDefinitionDto().setId(1).setRuleKey("AvoidCycle").setRepositoryKey("squid").setIsExternal(true))
+ .setRule(new RuleDefinitionDto().setUuid("uuid-1").setRuleKey("AvoidCycle").setRepositoryKey("squid").setIsExternal(true))
.setLanguage("xoo");
- assertThat(dto.getRuleId()).isEqualTo(1);
+ assertThat(dto.getRuleUuid()).isEqualTo("uuid-1");
assertThat(dto.getRuleRepo()).isEqualTo("squid");
assertThat(dto.getRule()).isEqualTo("AvoidCycle");
assertThat(dto.getRuleKey().toString()).isEqualTo("squid:AvoidCycle");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
index 3d76317e9b5..036ff6c33ea 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
@@ -97,7 +97,7 @@ public class IssueMapperTest {
assertThat(result.getKey()).isEqualTo("ABCDE");
assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
- assertThat(result.getRuleId()).isEqualTo(rule.getId());
+ assertThat(result.getRuleUuid()).isEqualTo(rule.getUuid());
assertThat(result.getType()).isEqualTo(2);
assertThat(result.getLine()).isEqualTo(500);
assertThat(result.getGap()).isEqualTo(3.14d);
@@ -127,7 +127,7 @@ public class IssueMapperTest {
update.setKee("ABCDE");
update.setComponentUuid("other component uuid");
update.setProjectUuid(project.uuid());
- update.setRuleId(rule.getId());
+ update.setRuleUuid(rule.getUuid());
update.setType(3);
update.setLine(500);
update.setGap(3.14);
@@ -156,7 +156,7 @@ public class IssueMapperTest {
assertThat(result.getKey()).isEqualTo("ABCDE");
assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
- assertThat(result.getRuleId()).isEqualTo(rule.getId());
+ assertThat(result.getRuleUuid()).isEqualTo(rule.getUuid());
assertThat(result.getType()).isEqualTo(3);
assertThat(result.getLine()).isEqualTo(500);
assertThat(result.getGap()).isEqualTo(3.14d);
@@ -273,7 +273,7 @@ public class IssueMapperTest {
ComponentDto component = randomComponent(organization);
IssueDto issueWithRule = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issueWithRule);
- IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDefinitionDto().setType(ruleType).setId(-50));
+ IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDefinitionDto().setType(ruleType).setUuid("uuid-50"));
insertToClosedDiff(issueWithoutRule);
RecorderResultHandler resultHandler = new RecorderResultHandler();
@@ -499,7 +499,7 @@ public class IssueMapperTest {
private final IssueDto insertNewClosedIssue(ComponentDto component, RuleDefinitionDto rule, long issueCloseTime, Consumer<IssueDto>... consumers) {
IssueDto res = new IssueDto()
.setKee(UuidFactoryFast.getInstance().create())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setType(rule.getType())
.setComponentUuid(component.uuid())
.setProjectUuid(component.projectUuid())
@@ -540,7 +540,7 @@ public class IssueMapperTest {
.setKee("ABCDE")
.setComponentUuid(file.uuid())
.setProjectUuid(project.uuid())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setType(2)
.setLine(500)
.setGap(3.14)
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 a190e0ec763..0063c05752a 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
@@ -110,15 +110,16 @@ public class ActiveRuleDaoTest {
}
@Test
- public void selectByRuleId() {
+ public void selectByRuleUuid() {
ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER);
ActiveRuleDto activeRule2 = createFor(profile2, rule1).setSeverity(BLOCKER);
underTest.insert(dbSession, activeRule1);
underTest.insert(dbSession, activeRule2);
dbSession.commit();
- assertThat(underTest.selectByRuleId(dbSession, organization, rule1.getId())).extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey());
- assertThat(underTest.selectByRuleId(dbSession, organization, rule3.getId())).isEmpty();
+ assertThat(underTest.selectByRuleUuid(dbSession, organization, rule1.getUuid())).extracting("key")
+ .containsOnly(activeRule1.getKey(), activeRule2.getKey());
+ assertThat(underTest.selectByRuleUuid(dbSession, organization, rule3.getUuid())).isEmpty();
}
@Test
@@ -131,9 +132,9 @@ public class ActiveRuleDaoTest {
underTest.insert(dbSession, activeRule3);
dbSession.commit();
- assertThat(underTest.selectByRuleIds(dbSession, organization, asList(rule1.getId())))
+ assertThat(underTest.selectByRuleUuids(dbSession, organization, singletonList(rule1.getUuid())))
.extracting("key").containsOnly(activeRule1.getKey(), activeRule3.getKey());
- assertThat(underTest.selectByRuleIds(dbSession, organization, newArrayList(rule1.getId(), rule2.getId())))
+ assertThat(underTest.selectByRuleUuids(dbSession, organization, newArrayList(rule1.getUuid(), rule2.getUuid())))
.extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey(), activeRule3.getKey());
}
@@ -169,8 +170,8 @@ public class ActiveRuleDaoTest {
underTest.insert(dbSession, activeRule1);
assertThat(underTest.selectByTypeAndProfileUuids(dbSession, singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList(profile1.getKee())))
- .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleId)
- .contains(tuple(profile1.getKee(), profile1.getOrganizationUuid(), rule1.getId()));
+ .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleUuid)
+ .contains(tuple(profile1.getKee(), profile1.getOrganizationUuid(), rule1.getUuid()));
}
@Test
@@ -195,14 +196,14 @@ public class ActiveRuleDaoTest {
underTest.selectByTypeAndProfileUuids(dbSession,
singletonList(RuleType.VULNERABILITY.getDbConstant()),
singletonList(profile1.getKee())))
- .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleId)
- .contains(tuple(profile1.getKee(), profile1.getOrganizationUuid(), rule1.getId()));
+ .extracting(OrgActiveRuleDto::getOrgProfileUuid, OrgActiveRuleDto::getOrganizationUuid, OrgActiveRuleDto::getRuleUuid)
+ .contains(tuple(profile1.getKee(), profile1.getOrganizationUuid(), rule1.getUuid()));
assertThat(
underTest.selectByTypeAndProfileUuids(dbSession,
asList(RuleType.CODE_SMELL.getDbConstant(), RuleType.SECURITY_HOTSPOT.getDbConstant(), RuleType.BUG.getDbConstant()),
singletonList(profile1.getKee())))
- .isEmpty();
+ .isEmpty();
}
@Test
@@ -231,29 +232,30 @@ public class ActiveRuleDaoTest {
underTest.insert(dbSession, rule1P2);
// empty rules
- Collection<ActiveRuleDto> result = underTest.selectByRulesAndRuleProfileUuids(dbSession, emptyList(), asList(profile1.getRulesProfileUuid()));
+ Collection<ActiveRuleDto> result = underTest.selectByRulesAndRuleProfileUuids(dbSession, emptyList(), singletonList(profile1.getRulesProfileUuid()));
assertThat(result).isEmpty();
// empty profiles
- result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getId()), emptyList());
+ result = underTest.selectByRulesAndRuleProfileUuids(dbSession, singletonList(rule1.getUuid()), emptyList());
assertThat(result).isEmpty();
// match
- result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getId()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
+ result = underTest.selectByRulesAndRuleProfileUuids(dbSession, singletonList(rule1.getUuid()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
assertThat(result)
.extracting(ActiveRuleDto::getUuid)
.containsExactlyInAnyOrder(rule1P1.getUuid(), rule1P2.getUuid());
- result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getId(), rule2.getId()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
+ result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getUuid(), rule2.getUuid()),
+ asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
assertThat(result)
.extracting(ActiveRuleDto::getUuid)
.containsExactlyInAnyOrder(rule1P1.getUuid(), rule1P2.getUuid(), rule2P1.getUuid());
// do not match
- result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule3.getId()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
+ result = underTest.selectByRulesAndRuleProfileUuids(dbSession, singletonList(rule3.getUuid()), asList(profile1.getRulesProfileUuid(), profile2.getRulesProfileUuid()));
assertThat(result).isEmpty();
- result = underTest.selectByRulesAndRuleProfileUuids(dbSession, asList(rule1.getId()), asList("unknown"));
+ result = underTest.selectByRulesAndRuleProfileUuids(dbSession, singletonList(rule1.getUuid()), singletonList("unknown"));
assertThat(result).isEmpty();
}
@@ -270,7 +272,7 @@ public class ActiveRuleDaoTest {
ActiveRuleDto result = underTest.selectByKey(dbSession, activeRule.getKey()).get();
assertThat(result.getUuid()).isEqualTo(activeRule.getUuid());
assertThat(result.getKey()).isEqualTo(ActiveRuleKey.of(profile1, rule1.getKey()));
- assertThat(result.getRuleId()).isEqualTo(rule1.getId());
+ assertThat(result.getRuleUuid()).isEqualTo(rule1.getUuid());
assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
assertThat(result.getSeverityString()).isEqualTo(BLOCKER);
assertThat(result.getInheritance()).isEqualTo(INHERITED);
@@ -291,7 +293,7 @@ public class ActiveRuleDaoTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Rule is not persisted");
- underTest.insert(dbSession, createFor(profile1, rule1).setRuleId(null));
+ underTest.insert(dbSession, createFor(profile1, rule1).setRuleUuid(null));
}
@Test
@@ -324,7 +326,7 @@ public class ActiveRuleDaoTest {
ActiveRuleDto result = underTest.selectByKey(dbSession, ActiveRuleKey.of(profile1, rule1.getKey())).get();
assertThat(result.getUuid()).isEqualTo(activeRule.getUuid());
assertThat(result.getKey()).isEqualTo(ActiveRuleKey.of(profile1, rule1.getKey()));
- assertThat(result.getRuleId()).isEqualTo(rule1.getId());
+ assertThat(result.getRuleUuid()).isEqualTo(rule1.getUuid());
assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
assertThat(result.getSeverityString()).isEqualTo(MAJOR);
assertThat(result.getInheritance()).isEqualTo(OVERRIDES);
@@ -345,7 +347,7 @@ public class ActiveRuleDaoTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Rule is not persisted");
- underTest.update(dbSession, createFor(profile1, rule1).setUuid("uuid").setRuleId(null));
+ underTest.update(dbSession, createFor(profile1, rule1).setUuid("uuid").setRuleUuid(null));
}
@Test
@@ -381,7 +383,7 @@ public class ActiveRuleDaoTest {
underTest.insert(dbSession, newRow(profile1, rule2));
underTest.insert(dbSession, newRow(profile2, rule1));
- underTest.deleteByRuleProfileUuids(dbSession, asList(profile1.getRulesProfileUuid()));
+ underTest.deleteByRuleProfileUuids(dbSession, singletonList(profile1.getRulesProfileUuid()));
assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1);
assertThat(underTest.selectByKey(dbSession, ActiveRuleKey.of(profile2, rule1.getKey()))).isPresent();
@@ -391,7 +393,7 @@ public class ActiveRuleDaoTest {
public void deleteByRuleProfileUuids_does_not_fail_when_rules_profile_with_specified_key_does_not_exist() {
underTest.insert(dbSession, newRow(profile1, rule1));
- underTest.deleteByRuleProfileUuids(dbSession, asList("does_not_exist"));
+ underTest.deleteByRuleProfileUuids(dbSession, singletonList("does_not_exist"));
assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1);
}
@@ -592,7 +594,7 @@ public class ActiveRuleDaoTest {
ActiveRuleParamDto param2 = ActiveRuleParamDto.createFor(rule2Param1).setValue("bar");
underTest.insertParam(dbSession, ar2, param2);
- underTest.deleteParamsByActiveRuleUuids(dbSession, asList(ar1.getUuid()));
+ underTest.deleteParamsByActiveRuleUuids(dbSession, singletonList(ar1.getUuid()));
assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, ar1.getUuid())).hasSize(0);
assertThat(underTest.selectParamsByActiveRuleUuid(dbSession, ar2.getUuid())).hasSize(1);
@@ -609,7 +611,7 @@ public class ActiveRuleDaoTest {
ActiveRuleCountQuery.Builder builder = ActiveRuleCountQuery.builder().setOrganization(organization);
assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(asList(profile1, profile2)).build()))
.containsOnly(entry(profile1.getKee(), 2L), entry(profile2.getKee(), 1L));
- assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(asList(profileWithoutActiveRule)).build())).isEmpty();
+ assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(singletonList(profileWithoutActiveRule)).build())).isEmpty();
assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(asList(profile1, profile2, profileWithoutActiveRule)).build())).containsOnly(
entry(profile1.getKee(), 2L),
entry(profile2.getKee(), 1L));
@@ -629,9 +631,9 @@ public class ActiveRuleDaoTest {
ActiveRuleCountQuery.Builder builder = ActiveRuleCountQuery.builder().setOrganization(organization);
assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(asList(profile1, profile2)).setRuleStatus(BETA).build()))
.containsOnly(entry(profile1.getKee(), 1L), entry(profile2.getKee(), 1L));
- assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(asList(profile1)).setRuleStatus(READY).build()))
+ assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(singletonList(profile1)).setRuleStatus(READY).build()))
.containsOnly(entry(profile1.getKee(), 2L));
- assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(asList(profile1)).setRuleStatus(REMOVED).build()))
+ assertThat(underTest.countActiveRulesByQuery(dbSession, builder.setProfiles(singletonList(profile1)).setRuleStatus(REMOVED).build()))
.containsOnly(entry(profile1.getKee(), 1L));
}
@@ -679,13 +681,13 @@ public class ActiveRuleDaoTest {
underTest.scrollAllForIndexing(dbSession, accumulator);
assertThat(accumulator.list)
.extracting(IndexedActiveRuleDto::getUuid,
- IndexedActiveRuleDto::getRuleId, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey,
+ IndexedActiveRuleDto::getRuleUuid, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey,
IndexedActiveRuleDto::getRuleProfileUuid,
IndexedActiveRuleDto::getSeverity, IndexedActiveRuleDto::getInheritance)
.containsExactlyInAnyOrder(
- tuple(ar1.getUuid(), rule1.getId(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity(), ar1.getInheritance()),
- tuple(ar2.getUuid(), rule1.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity(), ar2.getInheritance()),
- tuple(ar3.getUuid(), rule2.getId(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity(), ar3.getInheritance()));
+ tuple(ar1.getUuid(), rule1.getUuid(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity(), ar1.getInheritance()),
+ tuple(ar2.getUuid(), rule1.getUuid(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity(), ar2.getInheritance()),
+ tuple(ar3.getUuid(), rule2.getUuid(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity(), ar3.getInheritance()));
}
@Test
@@ -695,14 +697,14 @@ public class ActiveRuleDaoTest {
ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2);
Accumulator accumulator = new Accumulator();
- underTest.scrollByUuidsForIndexing(dbSession, asList( ar1.getUuid(), ar2.getUuid()), accumulator);
+ underTest.scrollByUuidsForIndexing(dbSession, asList(ar1.getUuid(), ar2.getUuid()), accumulator);
assertThat(accumulator.list)
.extracting(IndexedActiveRuleDto::getUuid,
- IndexedActiveRuleDto::getRuleId, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey,
+ IndexedActiveRuleDto::getRuleUuid, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey,
IndexedActiveRuleDto::getRuleProfileUuid, IndexedActiveRuleDto::getSeverity)
.containsExactlyInAnyOrder(
- tuple(ar1.getUuid(), rule1.getId(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity()),
- tuple(ar2.getUuid(), rule1.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()));
+ tuple(ar1.getUuid(), rule1.getUuid(), ar1.getRuleKey().repository(), ar1.getRuleKey().rule(), profile1.getRulesProfileUuid(), ar1.getSeverity()),
+ tuple(ar2.getUuid(), rule1.getUuid(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()));
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
index ab01c620b85..e1133e84e37 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
@@ -72,16 +72,16 @@ public class QualityProfileExportDaoTest {
public void selectRulesByProfile_verify_columns() {
String language = "java";
RuleDefinitionDto ruleTemplate = createRule(language);
- RuleDefinitionDto customRule = createRule(language, RuleStatus.READY, ruleTemplate.getId());
+ RuleDefinitionDto customRule = createRule(language, RuleStatus.READY, ruleTemplate.getUuid());
RuleMetadataDto customRuleMetadata = createRuleMetadata(new RuleMetadataDto()
- .setRuleId(customRule.getId())
+ .setRuleUuid(customRule.getUuid())
.setOrganizationUuid(db.getDefaultOrganization().getUuid())
.setNoteData("Extended description")
.setTags(Sets.newHashSet("tag1", "tag2", "tag3")));
RuleDefinitionDto rule = createRule(language, RuleStatus.READY, null);
RuleMetadataDto ruleMetadata = createRuleMetadata(new RuleMetadataDto()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setOrganizationUuid(db.getDefaultOrganization().getUuid()));
QProfileDto profile = createProfile(language);
@@ -92,7 +92,7 @@ public class QualityProfileExportDaoTest {
assertThat(results).isNotNull();
assertThat(results).isNotEmpty();
- //verify custom rule
+ // verify custom rule
ExportRuleDto exportCustomRuleDto = results.stream().filter(ExportRuleDto::isCustomRule).findFirst().get();
assertThat(exportCustomRuleDto).isNotNull();
assertThat(exportCustomRuleDto.isCustomRule()).isTrue();
@@ -108,7 +108,7 @@ public class QualityProfileExportDaoTest {
ActiveRuleDto activeCustomRule = activeRules.stream().filter(activeRuleDto -> activeRuleDto.getRuleKey().equals(customRule.getKey())).findFirst().get();
assertThat(exportCustomRuleDto.getSeverityString()).isEqualTo(activeCustomRule.getSeverityString());
- //verify regular rule
+ // verify regular rule
ExportRuleDto exportRuleDto = results.stream().filter(regularRule -> !regularRule.isCustomRule()).findFirst().get();
assertThat(exportRuleDto).isNotNull();
assertThat(exportRuleDto.isCustomRule()).isFalse();
@@ -192,7 +192,6 @@ public class QualityProfileExportDaoTest {
.containsOnly(ruleParamsOfThirdRule.stream().map(RuleParamDto::getName).toArray());
}
-
private ExportRuleDto findExportedRuleByUuid(String uuid, List<ExportRuleDto> results) {
Optional<ExportRuleDto> found = results.stream().filter(exportRuleDto -> uuid.equals(exportRuleDto.getActiveRuleUuid())).findFirst();
if (!found.isPresent()) {
@@ -204,7 +203,7 @@ public class QualityProfileExportDaoTest {
private List<RuleParamDto> addParamsToRule(RuleDefinitionDto firstRule, int numberOfParams) {
return IntStream.range(0, numberOfParams)
.mapToObj(value -> db.rules().insertRuleParam(firstRule,
- ruleParamDto -> ruleParamDto.setName("name_" + firstRule.getId() + "_" + value)))
+ ruleParamDto -> ruleParamDto.setName("name_" + firstRule.getUuid() + "_" + value)))
.collect(Collectors.toList());
}
@@ -216,8 +215,9 @@ public class QualityProfileExportDaoTest {
return createRule(language, status, null);
}
- private RuleDefinitionDto createRule(String language, RuleStatus status, @Nullable Integer templateId) {
- return db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setRepositoryKey("repoKey").setLanguage(language).setStatus(status).setTemplateId(templateId));
+ private RuleDefinitionDto createRule(String language, RuleStatus status, @Nullable String templateUuid) {
+ return db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setRepositoryKey("repoKey").setLanguage(language).setStatus(status)
+ .setTemplateUuid(templateUuid));
}
private RuleMetadataDto createRuleMetadata(RuleMetadataDto metadataDto) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
index e93569a7d1e..e5b8035ce44 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
@@ -61,7 +61,7 @@ import static org.sonar.db.rule.RuleTesting.newRuleMetadata;
public class RuleDaoTest {
private static final String ORGANIZATION_UUID = "org-1";
- private static final int UNKNOWN_RULE_ID = 1_234_567_890;
+ private static final String UNKNOWN_RULE_UUID = "unknown-uuid";
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -104,7 +104,7 @@ public class RuleDaoTest {
RuleDefinitionDto ruleDefinition = db.rules().insert();
RuleDto rule = underTest.selectByKey(db.getSession(), organization.getUuid(), ruleDefinition.getKey()).get();
- verifyNoMetadata(rule.getMetadata(), ruleDefinition, organization);
+ verifyNoMetadata(rule.getMetadata(), organization);
}
@Test
@@ -134,38 +134,38 @@ public class RuleDaoTest {
}
@Test
- public void selectById() {
+ public void selectByUuid() {
RuleDefinitionDto ruleDefinition = db.rules().insert();
OrganizationDto organization = db.organizations().insert();
RuleMetadataDto metadata = newRuleMetadata(ruleDefinition, organization);
RuleDto expected = db.rules().insertRule(ruleDefinition, metadata);
- assertThat(underTest.selectById(expected.getId() + 500, organization.getUuid(), db.getSession()))
+ assertThat(underTest.selectByUuid(expected.getUuid() + 500, organization.getUuid(), db.getSession()))
.isEmpty();
- RuleDto rule = underTest.selectById(expected.getId(), organization.getUuid(), db.getSession()).get();
+ RuleDto rule = underTest.selectByUuid(expected.getUuid(), organization.getUuid(), db.getSession()).get();
assertEquals(rule.getDefinition(), ruleDefinition);
verifyMetadata(rule.getMetadata(), ruleDefinition, metadata);
}
@Test
- public void selectById_return_rule_even_if_organization_does_not_exist() {
+ public void selectByUuid_return_rule_even_if_organization_does_not_exist() {
RuleDefinitionDto ruleDefinition = db.rules().insert();
- assertThat(underTest.selectById(ruleDefinition.getId(), "dfdfdf", db.getSession()))
+ assertThat(underTest.selectByUuid(ruleDefinition.getUuid(), "dfdfdf", db.getSession()))
.isNotEmpty();
}
@Test
- public void selectById_populates_organizationUuid_even_when_organization_has_no_metadata() {
+ public void selectByUuid_populates_organizationUuid_even_when_organization_has_no_metadata() {
OrganizationDto organization = db.organizations().insert();
RuleDefinitionDto ruleDefinition = db.rules().insert();
- RuleDto rule = underTest.selectById(ruleDefinition.getId(), organization.getUuid(), db.getSession()).get();
- verifyNoMetadata(rule.getMetadata(), ruleDefinition, organization);
+ RuleDto rule = underTest.selectByUuid(ruleDefinition.getUuid(), organization.getUuid(), db.getSession()).get();
+ verifyNoMetadata(rule.getMetadata(), organization);
}
@Test
- public void selectById_returns_metadata_of_specified_organization() {
+ public void selectByUuid_returns_metadata_of_specified_organization() {
RuleDefinitionDto ruleDefinition = db.rules().insert();
OrganizationDto organization1 = db.organizations().insert();
RuleMetadataDto expectedOrg1 = newRuleMetadata(ruleDefinition, organization1);
@@ -174,23 +174,23 @@ public class RuleDaoTest {
RuleMetadataDto expectedOrg2 = newRuleMetadata(ruleDefinition, organization2);
db.rules().insertRule(ruleDefinition, expectedOrg2);
- RuleDto rule = underTest.selectById(ruleDefinition.getId(), organization1.getUuid(), db.getSession()).get();
+ RuleDto rule = underTest.selectByUuid(ruleDefinition.getUuid(), organization1.getUuid(), db.getSession()).get();
verifyMetadata(rule.getMetadata(), ruleDefinition, expectedOrg1);
- rule = underTest.selectById(ruleDefinition.getId(), organization2.getUuid(), db.getSession()).get();
+ rule = underTest.selectByUuid(ruleDefinition.getUuid(), organization2.getUuid(), db.getSession()).get();
verifyMetadata(rule.getMetadata(), ruleDefinition, expectedOrg2);
}
@Test
- public void selectDefinitionById() {
+ public void selectDefinitionByUuid() {
RuleDefinitionDto rule = db.rules().insert();
- assertThat(underTest.selectDefinitionById(1_234_567L, db.getSession())).isEmpty();
- Optional<RuleDefinitionDto> ruleDtoOptional = underTest.selectDefinitionById(rule.getId(), db.getSession());
+ assertThat(underTest.selectDefinitionByUuid(UNKNOWN_RULE_UUID, db.getSession())).isEmpty();
+ Optional<RuleDefinitionDto> ruleDtoOptional = underTest.selectDefinitionByUuid(rule.getUuid(), db.getSession());
assertThat(ruleDtoOptional).isPresent();
}
@Test
- public void selectByIds() {
+ public void selectByUuids() {
OrganizationDto organization = db.organizations().insert();
RuleDefinitionDto rule1 = db.rules().insert();
db.rules().insertOrUpdateMetadata(rule1, organization);
@@ -199,44 +199,43 @@ public class RuleDaoTest {
RuleDefinitionDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED));
db.rules().insertOrUpdateMetadata(removedRule, organization);
- assertThat(underTest.selectByIds(db.getSession(), organization.getUuid(), singletonList(rule1.getId()))).hasSize(1);
- assertThat(underTest.selectByIds(db.getSession(), organization.getUuid(), asList(rule1.getId(), rule2.getId()))).hasSize(2);
- assertThat(underTest.selectByIds(db.getSession(), organization.getUuid(), asList(rule1.getId(), rule2.getId(), UNKNOWN_RULE_ID))).hasSize(2);
- assertThat(underTest.selectByIds(db.getSession(), organization.getUuid(), asList(rule1.getId(), rule2.getId(), removedRule.getId()))).hasSize(3);
- assertThat(underTest.selectByIds(db.getSession(), organization.getUuid(), singletonList(UNKNOWN_RULE_ID))).isEmpty();
+ assertThat(underTest.selectByUuids(db.getSession(), organization.getUuid(), singletonList(rule1.getUuid()))).hasSize(1);
+ assertThat(underTest.selectByUuids(db.getSession(), organization.getUuid(), asList(rule1.getUuid(), rule2.getUuid()))).hasSize(2);
+ assertThat(underTest.selectByUuids(db.getSession(), organization.getUuid(), asList(rule1.getUuid(), rule2.getUuid(), UNKNOWN_RULE_UUID))).hasSize(2);
+ assertThat(underTest.selectByUuids(db.getSession(), organization.getUuid(), asList(rule1.getUuid(), rule2.getUuid(), removedRule.getUuid()))).hasSize(3);
+ assertThat(underTest.selectByUuids(db.getSession(), organization.getUuid(), singletonList(UNKNOWN_RULE_UUID))).isEmpty();
}
@Test
- public void selectByIds_populates_organizationUuid_even_when_organization_has_no_metadata() {
+ public void selectByUuids_populates_organizationUuid_even_when_organization_has_no_metadata() {
OrganizationDto organization = db.organizations().insert();
RuleDefinitionDto rule1 = db.rules().insert();
RuleDefinitionDto rule2 = db.rules().insert();
- assertThat(underTest.selectByIds(db.getSession(), organization.getUuid(), asList(rule1.getId(), rule2.getId())))
+ assertThat(underTest.selectByUuids(db.getSession(), organization.getUuid(), asList(rule1.getUuid(), rule2.getUuid())))
.extracting(RuleDto::getOrganizationUuid)
.containsExactly(organization.getUuid(), organization.getUuid());
}
@Test
- public void selectDefinitionByIds() {
+ public void selectDefinitionByUuids() {
RuleDefinitionDto rule1 = db.rules().insert();
RuleDefinitionDto rule2 = db.rules().insert();
- assertThat(underTest.selectDefinitionByIds(db.getSession(), singletonList(rule1.getId()))).hasSize(1);
- assertThat(underTest.selectDefinitionByIds(db.getSession(), asList(rule1.getId(), rule2.getId()))).hasSize(2);
- assertThat(underTest.selectDefinitionByIds(db.getSession(), asList(rule1.getId(), rule2.getId(), UNKNOWN_RULE_ID))).hasSize(2);
-
- assertThat(underTest.selectDefinitionByIds(db.getSession(), singletonList(UNKNOWN_RULE_ID))).isEmpty();
+ assertThat(underTest.selectDefinitionByUuids(db.getSession(), singletonList(rule1.getUuid()))).hasSize(1);
+ assertThat(underTest.selectDefinitionByUuids(db.getSession(), asList(rule1.getUuid(), rule2.getUuid()))).hasSize(2);
+ assertThat(underTest.selectDefinitionByUuids(db.getSession(), asList(rule1.getUuid(), rule2.getUuid(), UNKNOWN_RULE_UUID))).hasSize(2);
+ assertThat(underTest.selectDefinitionByUuids(db.getSession(), singletonList(UNKNOWN_RULE_UUID))).isEmpty();
}
@Test
public void selectOrFailByKey() {
OrganizationDto organization = db.organizations().insert();
RuleDefinitionDto rule1 = db.rules().insert();
- RuleDefinitionDto rule2 = db.rules().insert();
+ db.rules().insert();
RuleDto rule = underTest.selectOrFailByKey(db.getSession(), organization, rule1.getKey());
- assertThat(rule.getId()).isEqualTo(rule1.getId());
+ assertThat(rule.getUuid()).isEqualTo(rule1.getUuid());
}
@Test
@@ -275,11 +274,11 @@ public class RuleDaoTest {
db.rules().insertOrUpdateMetadata(rule2, organization);
assertThat(underTest.selectByKeys(db.getSession(), organization.getUuid(), Collections.emptyList())).isEmpty();
- assertThat(underTest.selectByKeys(db.getSession(), organization.getUuid(), asList(RuleKey.of("NOT", "FOUND")))).isEmpty();
+ assertThat(underTest.selectByKeys(db.getSession(), organization.getUuid(), singletonList(RuleKey.of("NOT", "FOUND")))).isEmpty();
List<RuleDto> rules = underTest.selectByKeys(db.getSession(), organization.getUuid(), asList(rule1.getKey(), RuleKey.of("java", "OTHER")));
assertThat(rules).hasSize(1);
- assertThat(rules.get(0).getId()).isEqualTo(rule1.getId());
+ assertThat(rules.get(0).getUuid()).isEqualTo(rule1.getUuid());
}
@Test
@@ -297,11 +296,11 @@ public class RuleDaoTest {
RuleDefinitionDto rule = db.rules().insert();
assertThat(underTest.selectDefinitionByKeys(db.getSession(), Collections.emptyList())).isEmpty();
- assertThat(underTest.selectDefinitionByKeys(db.getSession(), asList(RuleKey.of("NOT", "FOUND")))).isEmpty();
+ assertThat(underTest.selectDefinitionByKeys(db.getSession(), singletonList(RuleKey.of("NOT", "FOUND")))).isEmpty();
List<RuleDefinitionDto> rules = underTest.selectDefinitionByKeys(db.getSession(), asList(rule.getKey(), RuleKey.of("java", "OTHER")));
assertThat(rules).hasSize(1);
- assertThat(rules.get(0).getId()).isEqualTo(rule.getId());
+ assertThat(rules.get(0).getUuid()).isEqualTo(rule.getUuid());
}
@Test
@@ -312,8 +311,8 @@ public class RuleDaoTest {
RuleDto rule3 = db.rules().insertRule(organization);
assertThat(underTest.selectAll(db.getSession(), organization.getUuid()))
- .extracting(RuleDto::getId)
- .containsOnly(rule1.getId(), rule2.getId(), rule3.getId());
+ .extracting(RuleDto::getUuid)
+ .containsOnly(rule1.getUuid(), rule2.getUuid(), rule3.getUuid());
}
@Test
@@ -323,8 +322,8 @@ public class RuleDaoTest {
RuleDefinitionDto rule3 = db.rules().insert();
assertThat(underTest.selectAll(db.getSession(), "dfdfdf"))
- .extracting(RuleDto::getId)
- .containsOnly(rule1.getId(), rule2.getId(), rule3.getId());
+ .extracting(RuleDto::getUuid)
+ .containsOnly(rule1.getUuid(), rule2.getUuid(), rule3.getUuid());
}
@Test
@@ -335,8 +334,8 @@ public class RuleDaoTest {
List<RuleDto> rules = underTest.selectAll(db.getSession(), organization.getUuid());
assertThat(rules)
- .extracting(RuleDto::getId)
- .containsOnly(ruleDefinition1.getId(), ruleDefinition2.getId());
+ .extracting(RuleDto::getUuid)
+ .containsOnly(ruleDefinition1.getUuid(), ruleDefinition2.getUuid());
assertThat(rules)
.extracting(RuleDto::getOrganizationUuid)
.containsExactly(organization.getUuid(), organization.getUuid());
@@ -356,7 +355,7 @@ public class RuleDaoTest {
}
private void assertEquals(RuleDefinitionDto actual, RuleDefinitionDto expected) {
- assertThat(actual.getId()).isEqualTo(expected.getId());
+ assertThat(actual.getUuid()).isEqualTo(expected.getUuid());
assertThat(actual.getRepositoryKey()).isEqualTo(expected.getRepositoryKey());
assertThat(actual.getRuleKey()).isEqualTo(expected.getRuleKey());
assertThat(actual.getKey()).isEqualTo(expected.getKey());
@@ -370,7 +369,7 @@ public class RuleDaoTest {
assertThat(actual.isExternal()).isEqualTo(expected.isExternal());
assertThat(actual.isTemplate()).isEqualTo(expected.isTemplate());
assertThat(actual.getLanguage()).isEqualTo(expected.getLanguage());
- assertThat(actual.getTemplateId()).isEqualTo(expected.getTemplateId());
+ assertThat(actual.getTemplateUuid()).isEqualTo(expected.getTemplateUuid());
assertThat(actual.getDefRemediationFunction()).isEqualTo(expected.getDefRemediationFunction());
assertThat(actual.getDefRemediationGapMultiplier()).isEqualTo(expected.getDefRemediationGapMultiplier());
assertThat(actual.getDefRemediationBaseEffort()).isEqualTo(expected.getDefRemediationBaseEffort());
@@ -395,7 +394,7 @@ public class RuleDaoTest {
assertThat(metadata.getAdHocType()).isEqualTo(expected.getAdHocType());
}
- private static void verifyNoMetadata(RuleMetadataDto metadata, RuleDefinitionDto ruleDefinition, OrganizationDto organization) {
+ private static void verifyNoMetadata(RuleMetadataDto metadata, OrganizationDto organization) {
assertThat(metadata.getOrganizationUuid()).isEqualTo(organization.getUuid());
assertThat(metadata.getRemediationBaseEffort()).isNull();
assertThat(metadata.getRemediationFunction()).isNull();
@@ -418,13 +417,13 @@ public class RuleDaoTest {
List<RuleDefinitionDto> ruleDtos = underTest.selectAllDefinitions(db.getSession());
- assertThat(ruleDtos).extracting(RuleDefinitionDto::getId).containsOnly(rule1.getId(), rule2.getId(), removedRule.getId());
+ assertThat(ruleDtos).extracting(RuleDefinitionDto::getUuid).containsOnly(rule1.getUuid(), rule2.getUuid(), removedRule.getUuid());
}
@Test
public void selectEnabled_with_ResultHandler() {
RuleDefinitionDto rule = db.rules().insert();
- RuleDefinitionDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED));
+ db.rules().insert(r -> r.setStatus(REMOVED));
final List<RuleDefinitionDto> rules = new ArrayList<>();
ResultHandler<RuleDefinitionDto> resultHandler = resultContext -> rules.add(resultContext.getResultObject());
@@ -432,7 +431,7 @@ public class RuleDaoTest {
assertThat(rules.size()).isEqualTo(1);
RuleDefinitionDto ruleDto = rules.get(0);
- assertThat(ruleDto.getId()).isEqualTo(rule.getId());
+ assertThat(ruleDto.getUuid()).isEqualTo(rule.getUuid());
}
@Test
@@ -442,34 +441,34 @@ public class RuleDaoTest {
RuleDefinitionDto rule1 = db.rules().insert(
r -> r.setKey(RuleKey.of("java", "S001"))
- .setConfigKey("S1")
- .setType(RuleType.VULNERABILITY)
- .setLanguage("java"));
+ .setConfigKey("S1")
+ .setType(RuleType.VULNERABILITY)
+ .setLanguage("java"));
db.rules().insertOrUpdateMetadata(rule1, organization);
RuleDefinitionDto rule2 = db.rules().insert(
r -> r.setKey(RuleKey.of("js", "S002"))
- .setType(RuleType.SECURITY_HOTSPOT)
- .setLanguage("js"));
+ .setType(RuleType.SECURITY_HOTSPOT)
+ .setLanguage("js"));
db.rules().insertOrUpdateMetadata(rule2, organization);
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization.getUuid(), singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList("java")))
- .extracting(RuleDto::getOrganizationUuid, RuleDto::getId, RuleDto::getLanguage, RuleDto::getType)
- .containsExactly(tuple(organization.getUuid(), rule1.getId(), "java", RuleType.VULNERABILITY.getDbConstant()));
+ .extracting(RuleDto::getOrganizationUuid, RuleDto::getUuid, RuleDto::getLanguage, RuleDto::getType)
+ .containsExactly(tuple(organization.getUuid(), rule1.getUuid(), "java", RuleType.VULNERABILITY.getDbConstant()));
// Rule available also on organization2
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization2.getUuid(), singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList("java")))
- .extracting(RuleDto::getOrganizationUuid, RuleDto::getId, RuleDto::getLanguage, RuleDto::getType)
- .containsExactly(tuple(organization2.getUuid(), rule1.getId(), "java", RuleType.VULNERABILITY.getDbConstant()));
+ .extracting(RuleDto::getOrganizationUuid, RuleDto::getUuid, RuleDto::getLanguage, RuleDto::getType)
+ .containsExactly(tuple(organization2.getUuid(), rule1.getUuid(), "java", RuleType.VULNERABILITY.getDbConstant()));
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization.getUuid(), singletonList(RuleType.SECURITY_HOTSPOT.getDbConstant()), singletonList("js")))
- .extracting(RuleDto::getOrganizationUuid, RuleDto::getId, RuleDto::getLanguage, RuleDto::getType)
- .containsExactly(tuple(organization.getUuid(), rule2.getId(), "js", RuleType.SECURITY_HOTSPOT.getDbConstant()));
+ .extracting(RuleDto::getOrganizationUuid, RuleDto::getUuid, RuleDto::getLanguage, RuleDto::getType)
+ .containsExactly(tuple(organization.getUuid(), rule2.getUuid(), "js", RuleType.SECURITY_HOTSPOT.getDbConstant()));
// Rule available also on organization2
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization2.getUuid(), singletonList(RuleType.SECURITY_HOTSPOT.getDbConstant()), singletonList("js")))
- .extracting(RuleDto::getOrganizationUuid, RuleDto::getId, RuleDto::getLanguage, RuleDto::getType)
- .containsExactly(tuple(organization2.getUuid(), rule2.getId(), "js", RuleType.SECURITY_HOTSPOT.getDbConstant()));
+ .extracting(RuleDto::getOrganizationUuid, RuleDto::getUuid, RuleDto::getLanguage, RuleDto::getType)
+ .containsExactly(tuple(organization2.getUuid(), rule2.getUuid(), "js", RuleType.SECURITY_HOTSPOT.getDbConstant()));
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization.getUuid(), singletonList(RuleType.SECURITY_HOTSPOT.getDbConstant()), singletonList("java")))
.isEmpty();
@@ -538,7 +537,7 @@ public class RuleDaoTest {
db.rules().insertOrUpdateMetadata(rule1, organization);
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization.getUuid(), singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList("java")))
- .extracting(RuleDto::getOrganizationUuid, RuleDto::getId, RuleDto::getLanguage, RuleDto::getType)
+ .extracting(RuleDto::getOrganizationUuid, RuleDto::getUuid, RuleDto::getLanguage, RuleDto::getType)
.isEmpty();
}
@@ -555,7 +554,7 @@ public class RuleDaoTest {
db.rules().insertOrUpdateMetadata(rule1, organization);
assertThat(underTest.selectByTypeAndLanguages(db.getSession(), organization.getUuid(), singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList("java")))
- .extracting(RuleDto::getOrganizationUuid, RuleDto::getId, RuleDto::getLanguage, RuleDto::getType)
+ .extracting(RuleDto::getOrganizationUuid, RuleDto::getUuid, RuleDto::getLanguage, RuleDto::getType)
.isEmpty();
}
@@ -579,8 +578,8 @@ public class RuleDaoTest {
@Test
public void select_by_query_populates_organizationUuid_even_when_organization_has_no_metadata() {
OrganizationDto organization = db.organizations().insert();
- RuleDefinitionDto rule1 = db.rules().insert();
- RuleDefinitionDto rule2 = db.rules().insert();
+ db.rules().insert();
+ db.rules().insert();
assertThat(underTest.selectByQuery(db.getSession(), organization.getUuid(), RuleQuery.create()))
.extracting(RuleDto::getOrganizationUuid)
@@ -590,6 +589,7 @@ public class RuleDaoTest {
@Test
public void insert() {
RuleDefinitionDto newRule = new RuleDefinitionDto()
+ .setUuid("rule-uuid")
.setRuleKey("NewRuleKey")
.setRepositoryKey("plugin")
.setName("new name")
@@ -602,7 +602,7 @@ public class RuleDaoTest {
.setIsExternal(true)
.setIsAdHoc(true)
.setLanguage("dart")
- .setTemplateId(3)
+ .setTemplateUuid("uuid-3")
.setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
.setDefRemediationGapMultiplier("5d")
.setDefRemediationBaseEffort("10h")
@@ -617,7 +617,7 @@ public class RuleDaoTest {
db.getSession().commit();
RuleDefinitionDto ruleDto = underTest.selectOrFailDefinitionByKey(db.getSession(), RuleKey.of("plugin", "NewRuleKey"));
- assertThat(ruleDto.getId()).isNotNull();
+ assertThat(ruleDto.getUuid()).isNotNull();
assertThat(ruleDto.getName()).isEqualTo("new name");
assertThat(ruleDto.getDescription()).isEqualTo("new description");
assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN);
@@ -630,7 +630,7 @@ public class RuleDaoTest {
assertThat(ruleDto.isTemplate()).isTrue();
assertThat(ruleDto.isExternal()).isTrue();
assertThat(ruleDto.isAdHoc()).isTrue();
- assertThat(ruleDto.getTemplateId()).isEqualTo(3);
+ assertThat(ruleDto.getTemplateUuid()).isEqualTo("uuid-3");
assertThat(ruleDto.getDefRemediationFunction()).isEqualTo("LINEAR_OFFSET");
assertThat(ruleDto.getDefRemediationGapMultiplier()).isEqualTo("5d");
assertThat(ruleDto.getDefRemediationBaseEffort()).isEqualTo("10h");
@@ -647,7 +647,7 @@ public class RuleDaoTest {
public void update_RuleDefinitionDto() {
RuleDefinitionDto rule = db.rules().insert();
RuleDefinitionDto ruleToUpdate = new RuleDefinitionDto()
- .setId(rule.getId())
+ .setUuid(rule.getUuid())
.setRuleKey("NewRuleKey")
.setRepositoryKey("plugin")
.setName("new name")
@@ -660,7 +660,7 @@ public class RuleDaoTest {
.setIsExternal(true)
.setIsAdHoc(true)
.setLanguage("dart")
- .setTemplateId(3)
+ .setTemplateUuid("uuid-3")
.setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
.setDefRemediationGapMultiplier("5d")
.setDefRemediationBaseEffort("10h")
@@ -687,7 +687,7 @@ public class RuleDaoTest {
assertThat(ruleDto.isTemplate()).isTrue();
assertThat(ruleDto.isExternal()).isTrue();
assertThat(ruleDto.isAdHoc()).isTrue();
- assertThat(ruleDto.getTemplateId()).isEqualTo(3);
+ assertThat(ruleDto.getTemplateUuid()).isEqualTo("uuid-3");
assertThat(ruleDto.getDefRemediationFunction()).isEqualTo("LINEAR_OFFSET");
assertThat(ruleDto.getDefRemediationGapMultiplier()).isEqualTo("5d");
assertThat(ruleDto.getDefRemediationBaseEffort()).isEqualTo("10h");
@@ -706,7 +706,7 @@ public class RuleDaoTest {
String organizationUuid = "org-1";
RuleMetadataDto metadataToUpdate = new RuleMetadataDto()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setOrganizationUuid(organizationUuid)
.setNoteData("My note")
.setNoteUserUuid("admin")
@@ -758,12 +758,12 @@ public class RuleDaoTest {
String organizationUuid = "org-1";
OrganizationDto organization = OrganizationTesting.newOrganizationDto().setUuid(organizationUuid);
RuleMetadataDto metadataV1 = new RuleMetadataDto()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setOrganizationUuid(organizationUuid)
.setCreatedAt(3_500_000_000_000L)
.setUpdatedAt(4_000_000_000_000L);
RuleMetadataDto metadataV2 = new RuleMetadataDto()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setOrganizationUuid(organizationUuid)
.setNoteData("My note")
.setNoteUserUuid("admin")
@@ -835,7 +835,7 @@ public class RuleDaoTest {
assertThat(ruleDto.getName()).isEqualTo(ruleParam.getName());
assertThat(ruleDto.getDescription()).isEqualTo(ruleParam.getDescription());
assertThat(ruleDto.getType()).isEqualTo(ruleParam.getType());
- assertThat(ruleDto.getRuleId()).isEqualTo(rule.getId());
+ assertThat(ruleDto.getRuleUuid()).isEqualTo(rule.getUuid());
}
@Test
@@ -868,7 +868,7 @@ public class RuleDaoTest {
assertThat(ruleParamDtos).hasSize(1);
RuleParamDto loaded = ruleParamDtos.get(0);
- assertThat(loaded.getRuleId()).isEqualTo(orig.getRuleId());
+ assertThat(loaded.getRuleUuid()).isEqualTo(orig.getRuleUuid());
assertThat(loaded.getName()).isEqualTo(orig.getName());
assertThat(loaded.getType()).isEqualTo(orig.getType());
assertThat(loaded.getDefaultValue()).isEqualTo(orig.getDefaultValue());
@@ -900,7 +900,7 @@ public class RuleDaoTest {
assertThat(params).hasSize(1);
RuleParamDto param = new RuleParamDto()
.setUuid(ruleParam.getUuid())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
// Name will not be updated
.setName("format")
.setType("STRING")
@@ -943,8 +943,8 @@ public class RuleDaoTest {
underTest.scrollIndexingRules(db.getSession(), accumulator);
assertThat(accumulator.list)
- .extracting(RuleForIndexingDto::getId, RuleForIndexingDto::getRuleKey)
- .containsExactlyInAnyOrder(tuple(r1.getId(), r1.getKey()), tuple(r2.getId(), r2.getKey()));
+ .extracting(RuleForIndexingDto::getUuid, RuleForIndexingDto::getRuleKey)
+ .containsExactlyInAnyOrder(tuple(r1.getUuid(), r1.getKey()), tuple(r2.getUuid(), r2.getKey()));
Iterator<RuleForIndexingDto> it = accumulator.list.iterator();
RuleForIndexingDto firstRule = it.next();
@@ -975,7 +975,7 @@ public class RuleDaoTest {
public void scrollIndexingRules_maps_rule_definition_fields_for_regular_rule_and_template_rule() {
Accumulator<RuleForIndexingDto> accumulator = new Accumulator<>();
RuleDefinitionDto r1 = db.rules().insert();
- RuleDefinitionDto r2 = db.rules().insert(rule -> rule.setTemplateId(r1.getId()));
+ RuleDefinitionDto r2 = db.rules().insert(rule -> rule.setTemplateUuid(r1.getUuid()));
underTest.scrollIndexingRules(db.getSession(), accumulator);
@@ -997,24 +997,24 @@ public class RuleDaoTest {
RuleDefinitionDto r1 = db.rules().insert();
db.rules().insert();
- underTest.scrollIndexingRulesByKeys(db.getSession(), singletonList(r1.getId()), accumulator);
+ underTest.scrollIndexingRulesByKeys(db.getSession(), singletonList(r1.getUuid()), accumulator);
assertThat(accumulator.list)
- .extracting(RuleForIndexingDto::getId, RuleForIndexingDto::getRuleKey)
- .containsExactlyInAnyOrder(tuple(r1.getId(), r1.getKey()));
+ .extracting(RuleForIndexingDto::getUuid, RuleForIndexingDto::getRuleKey)
+ .containsExactlyInAnyOrder(tuple(r1.getUuid(), r1.getKey()));
}
@Test
public void scrollIndexingRulesByKeys_maps_rule_definition_fields_for_regular_rule_and_template_rule() {
Accumulator<RuleForIndexingDto> accumulator = new Accumulator<>();
RuleDefinitionDto r1 = db.rules().insert();
- RuleDefinitionDto r2 = db.rules().insert(rule -> rule.setTemplateId(r1.getId()));
+ RuleDefinitionDto r2 = db.rules().insert(rule -> rule.setTemplateUuid(r1.getUuid()));
- underTest.scrollIndexingRulesByKeys(db.getSession(), Arrays.asList(r1.getId(), r2.getId()), accumulator);
+ underTest.scrollIndexingRulesByKeys(db.getSession(), Arrays.asList(r1.getUuid(), r2.getUuid()), accumulator);
assertThat(accumulator.list).hasSize(2);
- RuleForIndexingDto firstRule = accumulator.list.stream().filter(t -> t.getId().equals(r1.getId())).findFirst().get();
- RuleForIndexingDto secondRule = accumulator.list.stream().filter(t -> t.getId().equals(r2.getId())).findFirst().get();
+ RuleForIndexingDto firstRule = accumulator.list.stream().filter(t -> t.getUuid().equals(r1.getUuid())).findFirst().get();
+ RuleForIndexingDto secondRule = accumulator.list.stream().filter(t -> t.getUuid().equals(r2.getUuid())).findFirst().get();
assertRuleDefinitionFieldsAreEquals(r1, firstRule);
assertThat(firstRule.getTemplateRuleKey()).isNull();
@@ -1025,7 +1025,7 @@ public class RuleDaoTest {
}
private void assertRuleDefinitionFieldsAreEquals(RuleDefinitionDto r1, RuleForIndexingDto firstRule) {
- assertThat(firstRule.getId()).isEqualTo(r1.getId());
+ assertThat(firstRule.getUuid()).isEqualTo(r1.getUuid());
assertThat(firstRule.getRuleKey()).isEqualTo(r1.getKey());
assertThat(firstRule.getRepository()).isEqualTo(r1.getRepositoryKey());
assertThat(firstRule.getPluginRuleKey()).isEqualTo(r1.getRuleKey());
@@ -1050,9 +1050,9 @@ public class RuleDaoTest {
public void scrollIndexingRulesByKeys_scrolls_nothing_if_key_does_not_exist() {
Accumulator<RuleForIndexingDto> accumulator = new Accumulator<>();
db.rules().insert();
- int nonExistingRuleId = 42;
+ String nonExistingRuleUuid = "non-existing-uuid";
- underTest.scrollIndexingRulesByKeys(db.getSession(), singletonList(nonExistingRuleId), accumulator);
+ underTest.scrollIndexingRulesByKeys(db.getSession(), singletonList(nonExistingRuleUuid), accumulator);
assertThat(accumulator.list).isEmpty();
}
@@ -1068,12 +1068,12 @@ public class RuleDaoTest {
underTest.scrollIndexingRuleExtensions(db.getSession(), accumulator);
assertThat(accumulator.list)
- .extracting(RuleExtensionForIndexingDto::getRuleId,
+ .extracting(RuleExtensionForIndexingDto::getRuleUuid,
RuleExtensionForIndexingDto::getRuleKey,
RuleExtensionForIndexingDto::getOrganizationUuid, RuleExtensionForIndexingDto::getTags)
.containsExactlyInAnyOrder(
- tuple(r1.getId(), r1.getKey(), organization.getUuid(), r1Extension.getTagsAsString()),
- tuple(r2.getId(), r2.getKey(), organization.getUuid(), r2Extension.getTagsAsString()));
+ tuple(r1.getUuid(), r1.getKey(), organization.getUuid(), r1Extension.getTagsAsString()),
+ tuple(r2.getUuid(), r2.getKey(), organization.getUuid(), r2Extension.getTagsAsString()));
}
@Test
@@ -1081,18 +1081,18 @@ public class RuleDaoTest {
Accumulator<RuleExtensionForIndexingDto> accumulator = new Accumulator<>();
RuleDefinitionDto r1 = db.rules().insert();
RuleMetadataDto r1Extension = db.rules().insertOrUpdateMetadata(r1, organization, r -> r.setTagsField("t1,t2"));
- RuleExtensionId r1ExtensionId = new RuleExtensionId(organization.getUuid(), r1.getId());
+ RuleExtensionId r1ExtensionId = new RuleExtensionId(organization.getUuid(), r1.getUuid());
RuleDefinitionDto r2 = db.rules().insert();
db.rules().insertOrUpdateMetadata(r2, organization, r -> r.setTagsField("t1,t3"));
underTest.scrollIndexingRuleExtensionsByIds(db.getSession(), singletonList(r1ExtensionId), accumulator);
assertThat(accumulator.list)
- .extracting(RuleExtensionForIndexingDto::getRuleId,
+ .extracting(RuleExtensionForIndexingDto::getRuleUuid,
RuleExtensionForIndexingDto::getRuleKey,
RuleExtensionForIndexingDto::getOrganizationUuid, RuleExtensionForIndexingDto::getTags)
.containsExactlyInAnyOrder(
- tuple(r1.getId(), r1.getKey(), organization.getUuid(), r1Extension.getTagsAsString()));
+ tuple(r1.getUuid(), r1.getKey(), organization.getUuid(), r1Extension.getTagsAsString()));
}
@Test
@@ -1100,8 +1100,8 @@ public class RuleDaoTest {
RuleDefinitionDto r1 = db.rules().insert();
RuleDefinitionDto r2 = db.rules().insert();
- db.rules().insertDeprecatedKey(r -> r.setRuleId(r1.getId()));
- db.rules().insertDeprecatedKey(r -> r.setRuleId(r2.getId()));
+ db.rules().insertDeprecatedKey(r -> r.setRuleUuid(r1.getUuid()));
+ db.rules().insertDeprecatedKey(r -> r.setRuleUuid(r2.getUuid()));
db.getSession().commit();
@@ -1161,7 +1161,7 @@ public class RuleDaoTest {
@Test
public void insertDeprecatedRuleKey() {
RuleDefinitionDto r1 = db.rules().insert();
- DeprecatedRuleKeyDto deprecatedRuleKeyDto = db.rules().insertDeprecatedKey(d -> d.setRuleId(r1.getId()));
+ DeprecatedRuleKeyDto deprecatedRuleKeyDto = db.rules().insertDeprecatedKey(d -> d.setRuleUuid(r1.getUuid()));
db.getSession().commit();
@@ -1175,7 +1175,7 @@ public class RuleDaoTest {
assertThat(deprecatedRuleKeyDto1.getNewRuleKey()).isEqualTo(r1.getRuleKey());
assertThat(deprecatedRuleKeyDto1.getUuid()).isEqualTo(deprecatedRuleKeyDto.getUuid());
assertThat(deprecatedRuleKeyDto1.getCreatedAt()).isEqualTo(deprecatedRuleKeyDto.getCreatedAt());
- assertThat(deprecatedRuleKeyDto1.getRuleId()).isEqualTo(r1.getId());
+ assertThat(deprecatedRuleKeyDto1.getRuleUuid()).isEqualTo(r1.getUuid());
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java
index c5f3560d984..290d80cf5e7 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java
@@ -19,41 +19,39 @@
*/
package org.sonar.db.rule;
-import java.util.Random;
import org.junit.Test;
+import org.sonar.core.util.Uuids;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.rule.RuleTesting.newRule;
public class RuleDefinitionDtoTest {
- private static final Random RANDOM = new Random();
-
@Test
- public void equals_is_based_on_id() {
- int id = RANDOM.nextInt(153151);
- RuleDefinitionDto dto = newRule().setId(id);
+ public void equals_is_based_on_uuid() {
+ String uuid = Uuids.createFast();
+ RuleDefinitionDto dto = newRule().setUuid(uuid);
assertThat(dto).isEqualTo(dto);
- assertThat(dto).isEqualTo(newRule().setId(id));
- assertThat(dto).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setId(id));
+ assertThat(dto).isEqualTo(newRule().setUuid(uuid));
+ assertThat(dto).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid));
assertThat(dto).isNotEqualTo(null);
assertThat(dto).isNotEqualTo(new Object());
- assertThat(dto).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setId(id - 1));
- assertThat(dto).isNotEqualTo(newRule().setId(id + 1));
+ assertThat(dto).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast()));
+ assertThat(dto).isNotEqualTo(newRule().setUuid(Uuids.createFast()));
}
@Test
- public void hashcode_is_based_on_id() {
- int id = RANDOM.nextInt(153151);
- RuleDefinitionDto dto = newRule().setId(id);
+ public void hashcode_is_based_on_uuid() {
+ String uuid = Uuids.createFast();
+ RuleDefinitionDto dto = newRule().setUuid(uuid);
assertThat(dto.hashCode()).isEqualTo(dto.hashCode());
- assertThat(dto.hashCode()).isEqualTo(newRule().setId(id).hashCode());
- assertThat(dto.hashCode()).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setId(id).hashCode());
+ assertThat(dto.hashCode()).isEqualTo(newRule().setUuid(uuid).hashCode());
+ assertThat(dto.hashCode()).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid).hashCode());
assertThat(dto.hashCode()).isNotEqualTo(null);
assertThat(dto.hashCode()).isNotEqualTo(new Object().hashCode());
- assertThat(dto.hashCode()).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setId(id - 1).hashCode());
- assertThat(dto.hashCode()).isNotEqualTo(newRule().setId(id + 1).hashCode());
+ assertThat(dto.hashCode()).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast()).hashCode());
+ assertThat(dto.hashCode()).isNotEqualTo(newRule().setUuid(Uuids.createFast()).hashCode());
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
index ec78cc49cc9..c97a88fd380 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
@@ -25,6 +25,7 @@ import java.util.function.Consumer;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.UserDto;
@@ -100,10 +101,6 @@ public class RuleDbTester {
return insert(newHotspotRule());
}
- public RuleDefinitionDto insertHotspotRule(RuleKey key) {
- return insert(newHotspotRule(key));
- }
-
@SafeVarargs
public final RuleDefinitionDto insertHotspotRule(Consumer<RuleDefinitionDto>... populaters) {
RuleDefinitionDto rule = newHotspotRule();
@@ -111,21 +108,15 @@ public class RuleDbTester {
return insert(rule);
}
- public RuleDefinitionDto insertHotspotRule(RuleKey key, Consumer<RuleDefinitionDto> populater) {
- RuleDefinitionDto rule = newHotspotRule(key);
- populater.accept(rule);
- return insert(rule);
- }
-
- private static RuleDefinitionDto newHotspotRule(RuleKey key) {
- return newRule(key).setType(SECURITY_HOTSPOT);
- }
-
private static RuleDefinitionDto newHotspotRule() {
return newRule().setType(SECURITY_HOTSPOT);
}
public RuleDefinitionDto insert(RuleDefinitionDto rule) {
+ if (rule.getUuid() == null) {
+ rule.setUuid(Uuids.createFast());
+ }
+
db.getDbClient().ruleDao().insert(db.getSession(), rule);
db.commit();
return rule;
@@ -172,10 +163,14 @@ public class RuleDbTester {
}
public RuleDto insertRule(RuleDto ruleDto) {
+ if (ruleDto.getUuid() == null) {
+ ruleDto.setUuid(Uuids.createFast());
+ }
+
insert(ruleDto.getDefinition());
RuleMetadataDto metadata = ruleDto.getMetadata();
if (metadata.getOrganizationUuid() != null) {
- db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), metadata.setRuleId(ruleDto.getId()));
+ db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), metadata.setRuleUuid(ruleDto.getUuid()));
db.commit();
}
return ruleDto;
@@ -199,6 +194,11 @@ public class RuleDbTester {
public RuleDto insertRule(Consumer<RuleDto> populateRuleDto) {
RuleDto ruleDto = newRuleDto();
populateRuleDto.accept(ruleDto);
+
+ if (ruleDto.getUuid() == null) {
+ ruleDto.setUuid(Uuids.createFast());
+ }
+
return insertRule(ruleDto);
}
@@ -212,7 +212,7 @@ public class RuleDbTester {
public RuleParamDto insertRuleParam(RuleDto rule) {
RuleParamDto param = new RuleParamDto();
- param.setRuleId(rule.getId());
+ param.setRuleUuid(rule.getUuid());
param.setName(randomAlphabetic(10));
param.setType(RuleParamType.STRING.type());
db.getDbClient().ruleDao().insertRuleParam(db.getSession(), rule.getDefinition(), param);
@@ -221,7 +221,7 @@ public class RuleDbTester {
}
public RuleDto insertRule(RuleDefinitionDto ruleDefinition, RuleMetadataDto ruleMetadata) {
- db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), ruleMetadata.setRuleId(ruleDefinition.getId()));
+ db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), ruleMetadata.setRuleUuid(ruleDefinition.getUuid()));
db.commit();
return new RuleDto(ruleDefinition, ruleMetadata);
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
index 7164588afef..56c70c72080 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
@@ -31,6 +31,7 @@ import org.sonar.api.rules.RuleType;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.core.util.Uuids;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDto.Format;
import org.sonar.db.rule.RuleDto.Scope;
@@ -69,7 +70,7 @@ public class RuleTesting {
return new RuleDefinitionDto()
.setRepositoryKey(key.repository())
.setRuleKey(key.rule())
- .setId(nextInt(100_000))
+ .setUuid("rule_uuid_" + randomAlphanumeric(5))
.setName("name_" + randomAlphanumeric(5))
.setDescription("description_" + randomAlphanumeric(5))
.setDescriptionFormat(Format.HTML)
@@ -93,7 +94,7 @@ public class RuleTesting {
public static RuleMetadataDto newRuleMetadata() {
return new RuleMetadataDto()
- .setRuleId(nextInt(100_000))
+ .setRuleUuid("uuid_" + randomAlphanumeric(5))
.setOrganizationUuid("org_" + randomAlphanumeric(5))
.setRemediationBaseEffort(nextInt(10) + "h")
.setRemediationGapMultiplier(nextInt(10) + "h")
@@ -113,7 +114,7 @@ public class RuleTesting {
public static RuleMetadataDto newRuleMetadata(RuleDefinitionDto rule, OrganizationDto organization) {
return newRuleMetadata()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setOrganizationUuid(organization.getUuid());
}
@@ -124,7 +125,7 @@ public class RuleTesting {
public static RuleParamDto newRuleParam(RuleDefinitionDto rule) {
return new RuleParamDto()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setName("name_" + randomAlphabetic(5))
.setDefaultValue("default_" + randomAlphabetic(5))
.setDescription("description_" + randomAlphabetic(5))
@@ -136,7 +137,7 @@ public class RuleTesting {
.setUuid(uuidFactory.create())
.setOldRepositoryKey(randomAlphanumeric(50))
.setOldRuleKey(randomAlphanumeric(50))
- .setRuleId(nextInt(100_000))
+ .setRuleUuid(randomAlphanumeric(40))
.setCreatedAt(System.currentTimeMillis());
}
@@ -202,6 +203,7 @@ public class RuleTesting {
@Deprecated
public static RuleDto newDto(RuleKey ruleKey, @Nullable OrganizationDto organization) {
RuleDto res = new RuleDto()
+ .setUuid("uuid_" + Uuids.createFast())
.setRuleKey(ruleKey.rule())
.setRepositoryKey(ruleKey.repository())
.setName("Rule " + ruleKey.rule())
@@ -262,18 +264,18 @@ public class RuleTesting {
*/
@Deprecated
public static RuleDto newCustomRule(RuleDto templateRule) {
- checkNotNull(templateRule.getId(), "The template rule need to be persisted before creating this custom rule.");
+ checkNotNull(templateRule.getUuid(), "The template rule need to be persisted before creating this custom rule.");
return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis()))
.setLanguage(templateRule.getLanguage())
- .setTemplateId(templateRule.getId())
+ .setTemplateUuid(templateRule.getUuid())
.setType(templateRule.getType());
}
public static RuleDefinitionDto newCustomRule(RuleDefinitionDto templateRule) {
- checkNotNull(templateRule.getId(), "The template rule need to be persisted before creating this custom rule.");
+ checkNotNull(templateRule.getUuid(), "The template rule need to be persisted before creating this custom rule.");
return newRule(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis()))
.setLanguage(templateRule.getLanguage())
- .setTemplateId(templateRule.getId())
+ .setTemplateUuid(templateRule.getUuid())
.setType(templateRule.getType());
}
@@ -333,8 +335,8 @@ public class RuleTesting {
return rule -> rule.setIsTemplate(isTemplate);
}
- public static Consumer<RuleDefinitionDto> setTemplateId(@Nullable Integer templateId) {
- return rule -> rule.setTemplateId(templateId);
+ public static Consumer<RuleDefinitionDto> setTemplateId(@Nullable String templateUuid) {
+ return rule -> rule.setTemplateUuid(templateUuid);
}
public static Consumer<RuleDefinitionDto> setSystemTags(String... tags) {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
index 200853aebe8..73716cd4e5e 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
@@ -221,6 +221,43 @@ import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropQGate
import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropUniqueIndexOnUuidColumnOfQualityGatesTable;
import org.sonar.server.platform.db.migration.version.v83.qualitygates.MakeQGateUuidColumnNotNullableForQGateConditions;
import org.sonar.server.platform.db.migration.version.v83.qualitygates.PopulateQGateUuidColumnForQGateConditions;
+import org.sonar.server.platform.db.migration.version.v83.rules.AddPrimaryKeyOnUuidColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.AddUuidAndTemplateUuidColumnsToRules;
+import org.sonar.server.platform.db.migration.version.v83.rules.DropIdColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.DropPrimaryKeyOnIdColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.DropTemplateIdColumnOfRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.MakeRulesUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.PopulateRulesTemplateUuid;
+import org.sonar.server.platform.db.migration.version.v83.rules.PopulateRulesUuid;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.AddIndexToActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.AddRuleUuidColumnToActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.DropIndexOnRuleIdColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.DropRuleIdColumnOfActiveRulesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.MakeActiveRulesRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.activerules.PopulateActiveRulesRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.AddIndexToDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.AddRuleUuidColumnToDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.DropRuleIdColumnOfDeprecatedRuleKeysTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.MakeDeprecatedRuleKeysRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.deprecatedrulekeys.PopulateDeprecatedRuleKeysRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.AddIndexToIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.AddRuleUuidColumnToIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.DropIndexOnRuleIdColumnOfIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.DropRuleIdColumnOfIssuesTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.issues.PopulateIssuesRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.AddRuleUuidColumnToRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.DropPrimaryKeyOnIdColumnOfRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.DropRuleIdColumnOfRulesMetadataTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.MakeRulesMetadataRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesmetadata.PopulateRulesMetadataRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.AddIndexesToRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.AddRuleUuidColumnToRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.DropIndexesOnRuleIdColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.DropRuleIdColumnOfRulesParametersTable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.MakeRulesParametersRuleUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.rules.rulesparameters.PopulateRulesParametersRuleUuidColumn;
import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddPrimaryKeyOnUuidColumnOfRulesParametersTable;
import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddUuidColumnToRulesParameters;
import org.sonar.server.platform.db.migration.version.v83.rulesparameters.DropIdColumnOfRulesParametersTable;
@@ -716,6 +753,51 @@ public class DbVersion83 implements DbVersion {
.add(3671, "Add PK index on 'uuid' column of 'USERS' table", AddPrimaryKeyOnUuidColumnOfUsersTable.class)
.add(3672, "Drop 'id' column of 'USERS' table", DropIdColumnOfUsersTable.class)
+ // Migration of RULES table
+ .add(3673, "Add 'uuid' column for 'RULES'", AddUuidAndTemplateUuidColumnsToRules.class)
+ .add(3674, "Populate 'uuid' column for 'RULES'", PopulateRulesUuid.class)
+ .add(3675, "Make 'uuid' column not nullable for 'RULES'", MakeRulesUuidColumnNotNullable.class)
+ .add(3676, "Populate 'templateUuid' column for 'RULES'", PopulateRulesTemplateUuid.class)
+ .add(3677, "Drop column 'templateId' column for 'RULES'", DropTemplateIdColumnOfRulesTable.class)
+ // Migration of RULES_METADATA FK to RULES, switch from rule_id to rule_uuid
+ .add(3678, "Add 'RULE_UUID' column for 'RULES_METADATA' table", AddRuleUuidColumnToRulesMetadataTable.class)
+ .add(3679, "Populate 'RULE_UUID' column for 'RULES_METADATA' table", PopulateRulesMetadataRuleUuidColumn.class)
+ .add(3680, "Make 'RULE_UUID' column not nullable for 'RULES_METADATA' table", MakeRulesMetadataRuleUuidColumnNotNullable.class)
+ .add(3681, "Drop primary key on 'RULE_ID' column of 'RULES_METADATA' table", DropPrimaryKeyOnIdColumnOfRulesMetadataTable.class)
+ .add(3682, "Add primary key on 'RULE_UUID' column of 'RULES_METADATA' table", AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.class)
+ .add(3683, "Drop column 'RULE_ID' of 'RULES_METADATA' table", DropRuleIdColumnOfRulesMetadataTable.class)
+ // Migration of RULES_PARAMETERS FK to RULES, switch from rule_id to rule_uuid
+ .add(3684, "Add 'RULE_UUID' column for 'RULES_PARAMETERS' table", AddRuleUuidColumnToRulesParametersTable.class)
+ .add(3685, "Populate 'RULE_UUID' column for 'RULES_PARAMETERS' table", PopulateRulesParametersRuleUuidColumn.class)
+ .add(3686, "Make 'RULE_UUID' column not nullable for 'RULES_PARAMETERS' table", MakeRulesParametersRuleUuidColumnNotNullable.class)
+ .add(3687, "Drop indexes on 'RULE_ID' of 'RULES_PARAMETERS' table", DropIndexesOnRuleIdColumnOfRulesParametersTable.class)
+ .add(3688, "Add indexes to 'RULES_PARAMETERS' table", AddIndexesToRulesParametersTable.class)
+ .add(3689, "Drop column 'RULE_ID' of 'RULES_PARAMETERS' table", DropRuleIdColumnOfRulesParametersTable.class)
+ // Migration of ACTIVE_RULES FK to RULES, switch from rule_id to rule_uuid
+ .add(3690, "Add 'RULE_UUID' column for 'ACTIVE_RULES' table", AddRuleUuidColumnToActiveRulesTable.class)
+ .add(3691, "Populate 'RULE_UUID' column for 'ACTIVE_RULES' table", PopulateActiveRulesRuleUuidColumn.class)
+ .add(3692, "Make 'RULE_UUID' column not nullable for 'ACTIVE_RULES' table", MakeActiveRulesRuleUuidColumnNotNullable.class)
+ .add(3693, "Drop indexes on 'RULE_ID' of 'ACTIVE_RULES' table", DropIndexOnRuleIdColumnOfActiveRulesTable.class)
+ .add(3694, "Add indexes to 'ACTIVE_RULES' table", AddIndexToActiveRulesTable.class)
+ .add(3695, "Drop column 'RULE_ID' of 'ACTIVE_RULES' table", DropRuleIdColumnOfActiveRulesTable.class)
+ // Migration of DEPRECATED_RULE_KEYS FK to RULES, switch from rule_id to rule_uuid
+ .add(3696, "Add 'RULE_UUID' column for 'DEPRECATED_RULE_KEYS' table", AddRuleUuidColumnToDeprecatedRuleKeysTable.class)
+ .add(3697, "Populate 'RULE_UUID' column for 'DEPRECATED_RULE_KEYS' table", PopulateDeprecatedRuleKeysRuleUuidColumn.class)
+ .add(3698, "Make 'RULE_UUID' column not nullable for 'DEPRECATED_RULE_KEYS' table", MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.class)
+ .add(3699, "Drop index on 'RULE_ID' of 'DEPRECATED_RULE_KEYS' table", DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.class)
+ .add(3700, "Add index to 'DEPRECATED_RULE_KEYS' table", AddIndexToDeprecatedRuleKeysTable.class)
+ .add(3701, "Drop column 'RULE_ID' of 'DEPRECATED_RULE_KEYS' table", DropRuleIdColumnOfDeprecatedRuleKeysTable.class)
+ // Migration of ISSUE FK to RULES, switch from rule_id to rule_uuid
+ .add(3702, "Add 'RULE_UUID' column for 'ISSUES' table", AddRuleUuidColumnToIssuesTable.class)
+ .add(3703, "Populate 'RULE_UUID' column for 'ISSUES' table", PopulateIssuesRuleUuidColumn.class)
+ .add(3704, "Drop index on 'RULE_ID' of 'ISSUES' table", DropIndexOnRuleIdColumnOfIssuesTable.class)
+ .add(3705, "Add index to 'ISSUES' table", AddIndexToIssuesTable.class)
+ .add(3706, "Drop column 'RULE_ID' of 'ISSUES' table", DropRuleIdColumnOfIssuesTable.class)
+ // continue with RULES table cleanup
+ .add(3707, "Drop primary key on 'ID' column of 'RULES' table", DropPrimaryKeyOnIdColumnOfRulesTable.class)
+ .add(3708, "Add primary key on 'UUID' column of 'RULES' table", AddPrimaryKeyOnUuidColumnOfRulesTable.class)
+ .add(3709, "Drop column 'ID' of 'RULES' table", DropIdColumnOfRulesTable.class)
+
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java
new file mode 100644
index 00000000000..54636e8f742
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfRulesTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidColumnOfRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("rules", "uuid").build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java
new file mode 100644
index 00000000000..ba203f53a7d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRules.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddUuidAndTemplateUuidColumnsToRules extends DdlChange {
+ private static final String TABLE = "rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef templateUuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("template_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddUuidAndTemplateUuidColumnsToRules(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .addColumn(templateUuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java
new file mode 100644
index 00000000000..cdde386e05a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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 DropIdColumnOfRulesTable extends DdlChange {
+
+ public DropIdColumnOfRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules", "id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java
new file mode 100644
index 00000000000..20c1b53c9ea
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfRulesTable extends DdlChange {
+
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+ public DropPrimaryKeyOnIdColumnOfRulesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(dropPrimaryKeySqlGenerator.generate("rules", "id", true));
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java
new file mode 100644
index 00000000000..027f971fe70
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+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 DropTemplateIdColumnOfRulesTable extends DdlChange {
+
+ public DropTemplateIdColumnOfRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules", "template_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java
new file mode 100644
index 00000000000..86bf5f85471
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeRulesUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeRulesUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java
new file mode 100644
index 00000000000..9b235a2c47d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuid.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+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 PopulateRulesTemplateUuid extends DataChange {
+
+ public PopulateRulesTemplateUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select(
+ "select ru.id, rt.uuid from rules ru " +
+ "left join rules rt on rt.id = ru.template_id " +
+ "where ru.template_uuid is null and ru.template_id is not null");
+ massUpdate.update("update rules set template_uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java
new file mode 100644
index 00000000000..1d919988bd8
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuid.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.sonar.core.util.UuidFactory;
+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 PopulateRulesUuid extends DataChange {
+
+ private final UuidFactory uuidFactory;
+
+ public PopulateRulesUuid(Database db, UuidFactory uuidFactory) {
+ super(db);
+ this.uuidFactory = uuidFactory;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select id from rules where uuid is null");
+ massUpdate.update("update rules set uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, uuidFactory.create());
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java
new file mode 100644
index 00000000000..0e2c2158d1c
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTable.java
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexToActiveRulesTable extends DdlChange {
+ private static final String TABLE = "active_rules";
+ private static final String INDEX_NAME = "uniq_profile_rule_uuids";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+ private static final VarcharColumnDef profileUuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("profile_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddIndexToActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(INDEX_NAME)
+ .addColumn(profileUuidColumnDefinition)
+ .addColumn(uuidColumnDefinition)
+ .setUnique(true)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
+ }
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java
new file mode 100644
index 00000000000..fee60d1416a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToActiveRulesTable extends DdlChange {
+ private static final String TABLE = "active_rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java
new file mode 100644
index 00000000000..c177926955a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTable.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnRuleIdColumnOfActiveRulesTable extends DdlChange {
+ private static final String TABLE_NAME = "active_rules";
+ private static final String INDEX_NAME = "uniq_profile_rule_ids";
+
+ public DropIndexOnRuleIdColumnOfActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java
new file mode 100644
index 00000000000..b2f9995af46
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+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 DropRuleIdColumnOfActiveRulesTable extends DdlChange {
+
+ public DropRuleIdColumnOfActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "active_rules", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..b4b0ffa2c36
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeActiveRulesRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "active_rules";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeActiveRulesRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java
new file mode 100644
index 00000000000..f6ce521e292
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+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 PopulateActiveRulesRuleUuidColumn extends DataChange {
+
+ public PopulateActiveRulesRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select ar.rule_id, ru.uuid " +
+ "from active_rules ar " +
+ "join rules ru on ar.rule_id = ru.id " +
+ "where ar.rule_uuid is null");
+ massUpdate.update("update active_rules set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..129f57b3e7f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTable.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexToDeprecatedRuleKeysTable extends DdlChange {
+ private static final String TABLE = "deprecated_rule_keys";
+ private static final String INDEX_NAME = "rule_uuid_deprecated_rule_keys";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddIndexToDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(INDEX_NAME)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
+ }
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..7920fe3c0fe
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToDeprecatedRuleKeysTable extends DdlChange {
+ private static final String TABLE = "deprecated_rule_keys";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..047a4981073
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable extends DdlChange {
+
+ public DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("deprecated_rule_keys")
+ .setName("rule_id_deprecated_rule_keys")
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java
new file mode 100644
index 00000000000..4c671299c08
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+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 DropRuleIdColumnOfDeprecatedRuleKeysTable extends DdlChange {
+
+ public DropRuleIdColumnOfDeprecatedRuleKeysTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "deprecated_rule_keys", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..8023282925b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeDeprecatedRuleKeysRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "deprecated_rule_keys";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeDeprecatedRuleKeysRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java
new file mode 100644
index 00000000000..b58d8988bda
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+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 PopulateDeprecatedRuleKeysRuleUuidColumn extends DataChange {
+
+ public PopulateDeprecatedRuleKeysRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select drk.rule_id, ru.uuid " +
+ "from deprecated_rule_keys drk " +
+ "join rules ru on drk.rule_id = ru.id " +
+ "where drk.rule_uuid is null");
+ massUpdate.update("update deprecated_rule_keys set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java
new file mode 100644
index 00000000000..6e1a5a84447
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTable.java
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexToIssuesTable extends DdlChange {
+ private static final String TABLE = "issues";
+ private static final String INDEX_NAME = "issues_rule_uuid";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddIndexToIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(INDEX_NAME)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java
new file mode 100644
index 00000000000..0808b9defc9
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTable.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToIssuesTable extends DdlChange {
+ private static final String TABLE = "issues";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java
new file mode 100644
index 00000000000..f28152e0807
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnRuleIdColumnOfIssuesTable extends DdlChange {
+
+ public DropIndexOnRuleIdColumnOfIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("issues")
+ .setName("issues_rule_id")
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java
new file mode 100644
index 00000000000..069d44556af
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+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 DropRuleIdColumnOfIssuesTable extends DdlChange {
+
+ public DropRuleIdColumnOfIssuesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "issues", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java
new file mode 100644
index 00000000000..afa594c2692
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+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 PopulateIssuesRuleUuidColumn extends DataChange {
+
+ public PopulateIssuesRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select iss.rule_id, ru.uuid " +
+ "from issues iss " +
+ "join rules ru on iss.rule_id = ru.id " +
+ "where iss.rule_uuid is null");
+ massUpdate.update("update issues set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java
new file mode 100644
index 00000000000..8eb875ecb8a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("rules_metadata", "rule_uuid", "organization_uuid").build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java
new file mode 100644
index 00000000000..5cfa390a7ec
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToRulesMetadataTable extends DdlChange {
+ private static final String TABLE = "rules_metadata";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToRulesMetadataTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java
new file mode 100644
index 00000000000..ef9a32a26c6
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfRulesMetadataTable extends DdlChange {
+
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+ public DropPrimaryKeyOnIdColumnOfRulesMetadataTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(dropPrimaryKeySqlGenerator.generate("rules_metadata", "rule_id", false));
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java
new file mode 100644
index 00000000000..cd1b7d8eb8e
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+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 DropRuleIdColumnOfRulesMetadataTable extends DdlChange {
+
+ public DropRuleIdColumnOfRulesMetadataTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules_metadata", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..c71a1b9e32f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeRulesMetadataRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "rules_metadata";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeRulesMetadataRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java
new file mode 100644
index 00000000000..646ae438e41
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+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 PopulateRulesMetadataRuleUuidColumn extends DataChange {
+
+ public PopulateRulesMetadataRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select rm.rule_id, ru.uuid " +
+ "from rules_metadata rm " +
+ "join rules ru on rm.rule_id = ru.id " +
+ "where rm.rule_uuid is null");
+ massUpdate.update("update rules_metadata set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java
new file mode 100644
index 00000000000..aab7f110df7
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTable.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexesToRulesParametersTable extends DdlChange {
+ private static final String TABLE = "rules_parameters";
+ private static final String RULE_UUID_INDEX = "rules_parameters_rule_uuid";
+ private static final String RULE_UUID_NAME_UNIQUE_INDEX = "rules_parameters_unique";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef nameColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("name")
+ .setLimit(128)
+ .setIsNullable(false)
+ .build();
+
+ public AddIndexesToRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (indexDoesNotExist(RULE_UUID_INDEX)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(RULE_UUID_INDEX)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+
+ if (indexDoesNotExist(RULE_UUID_NAME_UNIQUE_INDEX)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName(RULE_UUID_NAME_UNIQUE_INDEX)
+ .addColumn(uuidColumnDefinition)
+ .addColumn(nameColumnDefinition)
+ .setUnique(true)
+ .build());
+ }
+ }
+
+ private boolean indexDoesNotExist(String index) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return !DatabaseUtils.indexExists(TABLE, index, connection);
+ }
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java
new file mode 100644
index 00000000000..edb9de28196
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddRuleUuidColumnToRulesParametersTable extends DdlChange {
+ private static final String TABLE = "rules_parameters";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddRuleUuidColumnToRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java
new file mode 100644
index 00000000000..b512dfbecba
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTable.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexesOnRuleIdColumnOfRulesParametersTable extends DdlChange {
+
+ public DropIndexesOnRuleIdColumnOfRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("rules_parameters")
+ .setName("rules_parameters_rule_id")
+ .build());
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable("rules_parameters")
+ .setName("rules_parameters_unique")
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java
new file mode 100644
index 00000000000..c078f553a83
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTable.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+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 DropRuleIdColumnOfRulesParametersTable extends DdlChange {
+
+ public DropRuleIdColumnOfRulesParametersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "rules_parameters", "rule_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java
new file mode 100644
index 00000000000..103ed3541d1
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullable.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeRulesParametersRuleUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE = "rules_parameters";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("rule_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeRulesParametersRuleUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java
new file mode 100644
index 00000000000..89a16ddc5b6
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumn.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+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 PopulateRulesParametersRuleUuidColumn extends DataChange {
+
+ public PopulateRulesParametersRuleUuidColumn(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select rp.rule_id, ru.uuid " +
+ "from rules_parameters rp " +
+ "join rules ru on rp.rule_id = ru.id " +
+ "where rp.rule_uuid is null");
+ massUpdate.update("update rules_parameters set rule_uuid = ? where rule_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..d13c9e7300d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("rules", "pk_rules", "uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java
new file mode 100644
index 00000000000..f5c6c269cb3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidAndTemplateUuidColumnsToRulesTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUuidAndTemplateUuidColumnsToRulesTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddUuidAndTemplateUuidColumnsToRules(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L);
+ insertRule(2L);
+ insertRule(3L);
+ insertRule(4L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules", "uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countSql("select count(*) from rules"))
+ .isEqualTo(4);
+ }
+
+ private void insertRule(long id) {
+ db.executeInsert("rules",
+ "id", id,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..dcc9910b73f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropIdColumnOfRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..e49d5b9a201
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesTable(db.database(),
+ new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("rules");
+ db.assertPrimaryKey("rules", "pk_rules", "id");
+
+ underTest.execute();
+
+ db.assertNoPrimaryKey("rules");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java
new file mode 100644
index 00000000000..0bc6c4b94b3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropTemplateIdColumnOfRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropTemplateIdColumnOfRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropTemplateIdColumnOfRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules", "template_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..f1c661646a5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeRulesUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeRulesUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules", "uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java
new file mode 100644
index 00000000000..3503979f94a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest.java
@@ -0,0 +1,74 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateRulesTemplateUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesTemplateUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateRulesTemplateUuid(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-1", 1L);
+ insertRule(2L, "uuid-2", 1L);
+ insertRule(3L, "uuid-3", null);
+ insertRule(4L, "uuid-4", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules"))
+ .isEqualTo(4);
+ assertThat(db.select("select uuid, template_id, template_uuid from rules"))
+ .extracting(m -> m.get("UUID"), m -> m.get("TEMPLATE_ID"), m -> m.get("TEMPLATE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-1", 1L, "uuid-1"),
+ tuple("uuid-2", 1L, "uuid-1"),
+ tuple("uuid-3", null, null),
+ tuple("uuid-4", 2L, "uuid-2"));
+ }
+
+ private void insertRule(long id, String uuid, @Nullable Long templateId) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "template_id", templateId,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java
new file mode 100644
index 00000000000..5c4d8bae2bd
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest.java
@@ -0,0 +1,75 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.ArgumentMatchers.anyString;
+
+public class PopulateRulesUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesUuidTest.class, "schema.sql");
+
+ private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private DataChange underTest = new PopulateRulesUuid(db.database(), uuidFactory);
+
+ @Before
+ public void setup() {
+ insertRule(1L);
+ insertRule(2L);
+ insertRule(3L);
+ insertRule(4L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules"))
+ .isEqualTo(4);
+ assertThat(db.select("select uuid from rules")
+ .stream()
+ .map(row -> row.get("UUID"))
+ .filter(Objects::isNull)
+ .collect(Collectors.toList())).isEmpty();
+ }
+
+ private void insertRule(long id) {
+ db.executeInsert("rules",
+ "id", id,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java
new file mode 100644
index 00000000000..fd4282d750f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexToActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToActiveRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexToActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertUniqueIndex("active_rules", "uniq_profile_rule_uuids", "profile_uuid", "rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertUniqueIndex("active_rules", "uniq_profile_rule_uuids", "profile_uuid", "rule_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java
new file mode 100644
index 00000000000..3b660a6cac0
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToActiveRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToActiveRulesTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertActiveRule("uuid-ar-1", 1L, "uuid-profile-1");
+ insertActiveRule("uuid-ar-2", 1L, "uuid-profile-2");
+ insertActiveRule("uuid-ar-3", 2L, "uuid-profile-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rules", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from active_rules"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertActiveRule(String uuid, long ruleId, String profileUuid) {
+ db.executeInsert("active_rules",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "profile_uuid", profileUuid,
+ "failure_level", 1);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java
new file mode 100644
index 00000000000..4cd93709c2f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnRuleIdColumnOfActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnRuleIdColumnOfActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("active_rules");
+ db.assertUniqueIndex("active_rules", "uniq_profile_rule_ids", "profile_uuid", "rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("active_rules", "uniq_profile_rule_ids");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("active_rules", "uniq_profile_rule_ids");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java
new file mode 100644
index 00000000000..b8c2a7a0285
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfActiveRulesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfActiveRulesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfActiveRulesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("active_rules", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..98a0fe477e4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeActiveRulesRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeActiveRulesRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeActiveRulesRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("active_rules", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java
new file mode 100644
index 00000000000..9431c36ab30
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.activerules;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateActiveRulesRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRulesRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateActiveRulesRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertActiveRule("uuid-ar-1", 1L, "uuid-profile-1");
+ insertActiveRule("uuid-ar-2", 1L, "uuid-profile-2");
+ insertActiveRule("uuid-ar-3", 2L, "uuid-profile-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from active_rules"))
+ .isEqualTo(3);
+ assertThat(db.select("select uuid, rule_id, rule_uuid from active_rules"))
+ .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-ar-1", 1L, "uuid-rule-1"),
+ tuple("uuid-ar-2", 1L, "uuid-rule-1"),
+ tuple("uuid-ar-3", 2L, "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertActiveRule(String uuid, long ruleId, String profileUuid) {
+ db.executeInsert("active_rules",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "profile_uuid", profileUuid,
+ "failure_level", 1);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..aa35897ee63
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexToDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexToDeprecatedRuleKeysTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("deprecated_rule_keys", "rule_uuid_deprecated_rule_keys", "rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("deprecated_rule_keys", "rule_uuid_deprecated_rule_keys", "rule_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..63fe5aabc74
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,80 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToDeprecatedRuleKeysTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+
+ insertDeprecatedRuleKeyRow("uuid-drk-1", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-2", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("deprecated_rule_keys", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from deprecated_rule_keys"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertDeprecatedRuleKeyRow(String uuid, long ruleId) {
+ db.executeInsert("deprecated_rule_keys",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "old_repository_key", "old-repo-key" + uuid,
+ "old_rule_key", "old-rule-key" + uuid,
+ "created_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..242bda7ec84
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("deprecated_rule_keys");
+ db.assertIndex("deprecated_rule_keys", "rule_id_deprecated_rule_keys", "rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("deprecated_rule_keys", "rule_id_deprecated_rule_keys");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("deprecated_rule_keys", "rule_id_deprecated_rule_keys");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java
new file mode 100644
index 00000000000..c733836c101
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfDeprecatedRuleKeysTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfDeprecatedRuleKeysTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfDeprecatedRuleKeysTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("deprecated_rule_keys", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..25d4c0d689e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeDeprecatedRuleKeysRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("deprecated_rule_keys", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java
new file mode 100644
index 00000000000..6621b2b96f2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest.java
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.deprecatedrulekeys;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateDeprecatedRuleKeysRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateDeprecatedRuleKeysRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateDeprecatedRuleKeysRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertDeprecatedRuleKeyRow("uuid-drk-1", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-2", 1L);
+ insertDeprecatedRuleKeyRow("uuid-drk-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from deprecated_rule_keys"))
+ .isEqualTo(3);
+ assertThat(db.select("select uuid, rule_id, rule_uuid from deprecated_rule_keys"))
+ .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-drk-1", 1L, "uuid-rule-1"),
+ tuple("uuid-drk-2", 1L, "uuid-rule-1"),
+ tuple("uuid-drk-3", 2L, "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertDeprecatedRuleKeyRow(String uuid, long ruleId) {
+ db.executeInsert("deprecated_rule_keys",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "old_repository_key", "old-repo-key" + uuid,
+ "old_rule_key", "old-rule-key" + uuid,
+ "created_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java
new file mode 100644
index 00000000000..6433bd453fb
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexToIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToIssuesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexToIssuesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java
new file mode 100644
index 00000000000..4e62b298628
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToIssuesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToIssuesTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertIssue("kee-iss-1", 1L);
+ insertIssue("kee-iss-2", 1L);
+ insertIssue("kee-iss-3", 2L);
+ insertIssue("kee-iss-4", null);
+ insertIssue("kee-iss-5", null);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("issues", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from issues"))
+ .isEqualTo(5);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertIssue(String kee, @Nullable Long ruleId) {
+ db.executeInsert("issues",
+ "kee", kee,
+ "rule_id", ruleId,
+ "manual_severity", false);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java
new file mode 100644
index 00000000000..dfe194f3465
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnRuleIdColumnOfIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfIssuesTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnRuleIdColumnOfIssuesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("issues");
+ db.assertIndex("issues", "issues_rule_id", "rule_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("issues", "issues_rule_id");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("issues", "issues_rule_id");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java
new file mode 100644
index 00000000000..b529a45245d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfIssuesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfIssuesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfIssuesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("issues", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java
new file mode 100644
index 00000000000..5de76c19f38
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest.java
@@ -0,0 +1,87 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.issues;
+
+import java.sql.SQLException;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateIssuesRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateIssuesRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateIssuesRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertIssue("kee-iss-1", 1L);
+ insertIssue("kee-iss-2", 1L);
+ insertIssue("kee-iss-3", 2L);
+ insertIssue("kee-iss-4", null);
+ insertIssue("kee-iss-5", null);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from issues")).isEqualTo(5);
+ assertThat(db.select("select kee, rule_id, rule_uuid from issues"))
+ .extracting(m -> m.get("KEE"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("kee-iss-1", 1L, "uuid-rule-1"),
+ tuple("kee-iss-2", 1L, "uuid-rule-1"),
+ tuple("kee-iss-3", 2L, "uuid-rule-2"),
+ tuple("kee-iss-4", null, null),
+ tuple("kee-iss-5", null, null));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertIssue(String kee, @Nullable Long ruleId) {
+ db.executeInsert("issues",
+ "kee", kee,
+ "rule_id", ruleId,
+ "manual_severity", false);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java
new file mode 100644
index 00000000000..992c26cf15b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("rules_metadata", "pk_rules_metadata", "rule_uuid", "organization_uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java
new file mode 100644
index 00000000000..64b45d13936
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest.java
@@ -0,0 +1,80 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToRulesMetadataTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToRulesMetadataTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertRuleMetadata(1L, "org-1");
+ insertRuleMetadata(1L, "org-2");
+ insertRuleMetadata(2L, "org-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_metadata", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from rules_metadata"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRuleMetadata(long ruleId, String organizationUuid) {
+ db.executeInsert("rules_metadata",
+ "rule_id", ruleId,
+ "organization_uuid", organizationUuid,
+ "created_at", System2.INSTANCE.now(),
+ "updated_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java
new file mode 100644
index 00000000000..e2b617b16ba
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesMetadataTable(db.database(),
+ new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("rules_metadata");
+ db.assertPrimaryKey("rules_metadata", "pk_rules_metadata", "rule_id", "organization_uuid");
+
+ underTest.execute();
+
+ db.assertNoPrimaryKey("rules_metadata");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java
new file mode 100644
index 00000000000..24eeacc8495
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfRulesMetadataTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfRulesMetadataTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfRulesMetadataTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules_metadata", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..2fdb200fee3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeRulesMetadataRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesMetadataRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeRulesMetadataRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_metadata", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java
new file mode 100644
index 00000000000..02333f271aa
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest.java
@@ -0,0 +1,85 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesmetadata;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateRulesMetadataRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesMetadataRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateRulesMetadataRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+ insertRule(4L, "uuid-rule-4");
+
+ insertRuleMetadata(1L, "org-1");
+ insertRuleMetadata(1L, "org-2");
+ insertRuleMetadata(2L, "org-1");
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules_metadata"))
+ .isEqualTo(3);
+ assertThat(db.select("select rule_id, organization_uuid, rule_uuid from rules_metadata"))
+ .extracting(m -> m.get("RULE_ID"), m -> m.get("ORGANIZATION_UUID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple(1L, "org-1", "uuid-rule-1"),
+ tuple(1L, "org-2", "uuid-rule-1"),
+ tuple(2L, "org-1", "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRuleMetadata(long ruleId, String organizationUuid) {
+ db.executeInsert("rules_metadata",
+ "rule_id", ruleId,
+ "organization_uuid", organizationUuid,
+ "created_at", System2.INSTANCE.now(),
+ "updated_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java
new file mode 100644
index 00000000000..a442c2f1311
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexesToRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexesToRulesParametersTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexesToRulesParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("rules_parameters", "rules_parameters_rule_uuid", "rule_uuid");
+ db.assertUniqueIndex("rules_parameters", "rules_parameters_unique", "rule_uuid", "name");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("rules_parameters", "rules_parameters_rule_uuid", "rule_uuid");
+ db.assertUniqueIndex("rules_parameters", "rules_parameters_unique", "rule_uuid", "name");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java
new file mode 100644
index 00000000000..7a8d1d95d0f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest.java
@@ -0,0 +1,78 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddRuleUuidColumnToRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToRulesParametersTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddRuleUuidColumnToRulesParametersTable(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+
+ insertRulesParametersEntry("uuid-rp-1", 1L);
+ insertRulesParametersEntry("uuid-rp-2", 1L);
+ insertRulesParametersEntry("uuid-rp-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_parameters", "rule_uuid", Types.VARCHAR, 40, true);
+ assertThat(db.countSql("select count(*) from rules_parameters"))
+ .isEqualTo(3);
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRulesParametersEntry(String uuid, long ruleId) {
+ db.executeInsert("rules_parameters",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "name", "name-" + uuid,
+ "param_type", "STRING");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java
new file mode 100644
index 00000000000..35418be3a2f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexesOnRuleIdColumnOfRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexesOnRuleIdColumnOfRulesParametersTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexesOnRuleIdColumnOfRulesParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("rules_parameters");
+ db.assertIndex("rules_parameters", "rules_parameters_rule_id", "rule_id");
+ db.assertUniqueIndex("rules_parameters", "rules_parameters_unique", "rule_id", "name");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_rule_id");
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_unique");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_rule_id");
+ db.assertIndexDoesNotExist("rules_parameters", "rules_parameters_unique");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java
new file mode 100644
index 00000000000..7c4f9b3c242
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropRuleIdColumnOfRulesParametersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfRulesParametersTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropRuleIdColumnOfRulesParametersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("rules_parameters", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..b657984f530
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeRulesParametersRuleUuidColumnNotNullableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeRulesParametersRuleUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeRulesParametersRuleUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("rules_parameters", "rule_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java
new file mode 100644
index 00000000000..4f8b401bc88
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.rules.rulesparameters;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateRulesParametersRuleUuidColumnTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesParametersRuleUuidColumnTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateRulesParametersRuleUuidColumn(db.database());
+
+ @Before
+ public void setup() {
+ insertRule(1L, "uuid-rule-1");
+ insertRule(2L, "uuid-rule-2");
+ insertRule(3L, "uuid-rule-3");
+
+ insertRulesParametersEntry("uuid-rp-1", 1L);
+ insertRulesParametersEntry("uuid-rp-2", 1L);
+ insertRulesParametersEntry("uuid-rp-3", 2L);
+ }
+
+ @Test
+ public void add_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from rules_parameters"))
+ .isEqualTo(3);
+ assertThat(db.select("select uuid, rule_id, rule_uuid from rules_parameters"))
+ .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-rp-1", 1L, "uuid-rule-1"),
+ tuple("uuid-rp-2", 1L, "uuid-rule-1"),
+ tuple("uuid-rp-3", 2L, "uuid-rule-2"));
+ }
+
+ private void insertRule(long id, String uuid) {
+ db.executeInsert("rules",
+ "id", id,
+ "uuid", uuid,
+ "plugin_rule_key", "rk" + id,
+ "plugin_name", "rn" + id,
+ "scope", "MAIN",
+ "is_ad_hoc", false,
+ "is_external", false);
+ }
+
+ private void insertRulesParametersEntry(String uuid, long ruleId) {
+ db.executeInsert("rules_parameters",
+ "uuid", uuid,
+ "rule_id", ruleId,
+ "name", "name-" + uuid,
+ "param_type", "STRING");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..df25471a0ba
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddPrimaryKeyOnUuidColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,29 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql
new file mode 100644
index 00000000000..66e55fb1b3f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/AddUuidAndTemplateUuidColumnsToRulesTest/schema.sql
@@ -0,0 +1,29 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..4045c3e578a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropIdColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,30 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..04dc8de79c8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,30 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql
new file mode 100644
index 00000000000..ee19fb605ea
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/DropTemplateIdColumnOfRulesTableTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..e2d578ae008
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/MakeRulesUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40),
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql
new file mode 100644
index 00000000000..ee19fb605ea
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesTemplateUuidTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql
new file mode 100644
index 00000000000..e2d578ae008
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/PopulateRulesUuidTest/schema.sql
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "TEMPLATE_ID" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40),
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..b3b1b4d7c04
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddIndexToActiveRulesTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..d05e47d8bc5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/AddRuleUuidColumnToActiveRulesTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..9156127c902
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropIndexOnRuleIdColumnOfActiveRulesTableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql
new file mode 100644
index 00000000000..d786db82af6
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/DropRuleIdColumnOfActiveRulesTableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_UUIDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..ac68fc9c530
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/MakeActiveRulesRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..ac68fc9c530
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/activerules/PopulateActiveRulesRuleUuidColumnTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ACTIVE_RULES"(
+ "RULE_ID" INTEGER NOT NULL,
+ "FAILURE_LEVEL" INTEGER NOT NULL,
+ "INHERITANCE" VARCHAR(10),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROFILE_UUID" VARCHAR(40) NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PROFILE_RULE_IDS" ON "ACTIVE_RULES"("PROFILE_UUID", "RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..7d99e6c84e9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddIndexToDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,41 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..5f7d81c739c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/AddRuleUuidColumnToDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,41 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..9f9a6ff004a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropIndexOnRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
new file mode 100644
index 00000000000..557f113a0c2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/DropRuleIdColumnOfDeprecatedRuleKeysTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_UUID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..a33abf46805
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/MakeDeprecatedRuleKeysRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..a33abf46805
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/deprecatedrulekeys/PopulateDeprecatedRuleKeysRuleUuidColumnTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "DEPRECATED_RULE_KEYS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "OLD_REPOSITORY_KEY" VARCHAR(255) NOT NULL,
+ "OLD_RULE_KEY" VARCHAR(200) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "DEPRECATED_RULE_KEYS" ADD CONSTRAINT "PK_DEPRECATED_RULE_KEYS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY", "OLD_RULE_KEY");
+CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..d02b9c74ec2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddIndexToIssuesTableTest/schema.sql
@@ -0,0 +1,69 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..89488e5506f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql
@@ -0,0 +1,69 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..d6c8f6b855e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql
@@ -0,0 +1,70 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql
new file mode 100644
index 00000000000..a2da6523742
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql
@@ -0,0 +1,70 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..d6c8f6b855e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql
@@ -0,0 +1,70 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "ISSUES"(
+ "KEE" VARCHAR(50) NOT NULL,
+ "RULE_ID" INTEGER,
+ "SEVERITY" VARCHAR(10),
+ "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+ "MESSAGE" VARCHAR(4000),
+ "LINE" INTEGER,
+ "GAP" DOUBLE,
+ "STATUS" VARCHAR(20),
+ "RESOLUTION" VARCHAR(20),
+ "CHECKSUM" VARCHAR(1000),
+ "REPORTER" VARCHAR(255),
+ "ASSIGNEE" VARCHAR(255),
+ "AUTHOR_LOGIN" VARCHAR(255),
+ "ACTION_PLAN_KEY" VARCHAR(50),
+ "ISSUE_ATTRIBUTES" VARCHAR(4000),
+ "EFFORT" INTEGER,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "ISSUE_CREATION_DATE" BIGINT,
+ "ISSUE_UPDATE_DATE" BIGINT,
+ "ISSUE_CLOSE_DATE" BIGINT,
+ "TAGS" VARCHAR(4000),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROJECT_UUID" VARCHAR(50),
+ "LOCATIONS" BLOB,
+ "ISSUE_TYPE" TINYINT,
+ "FROM_HOTSPOT" BOOLEAN,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..7e46834a915
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTableTest/schema.sql
@@ -0,0 +1,50 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..6dd1263edd1
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/AddRuleUuidColumnToRulesMetadataTableTest/schema.sql
@@ -0,0 +1,50 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..9f014613799
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest/schema.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql
new file mode 100644
index 00000000000..d7862acb77c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/DropRuleIdColumnOfRulesMetadataTableTest/schema.sql
@@ -0,0 +1,51 @@
+create TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+alter table "RULES" add CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+create UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_UUID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..9e725d8243b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/MakeRulesMetadataRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..9e725d8243b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesmetadata/PopulateRulesMetadataRuleUuidColumnTest/schema.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_METADATA"(
+ "RULE_ID" INTEGER NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "NOTE_DATA" CLOB(2147483647),
+ "NOTE_USER_UUID" VARCHAR(255),
+ "NOTE_CREATED_AT" BIGINT,
+ "NOTE_UPDATED_AT" BIGINT,
+ "REMEDIATION_FUNCTION" VARCHAR(20),
+ "REMEDIATION_GAP_MULT" VARCHAR(20),
+ "REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "TAGS" VARCHAR(4000),
+ "AD_HOC_NAME" VARCHAR(200),
+ "AD_HOC_DESCRIPTION" CLOB(2147483647),
+ "AD_HOC_SEVERITY" VARCHAR(10),
+ "AD_HOC_TYPE" TINYINT,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..13198189e57
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddIndexesToRulesParametersTableTest/schema.sql
@@ -0,0 +1,41 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..88e9e77a4e3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/AddRuleUuidColumnToRulesParametersTableTest/schema.sql
@@ -0,0 +1,42 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..81bbe5119c2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropIndexesOnRuleIdColumnOfRulesParametersTableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql
new file mode 100644
index 00000000000..eafb90192e1
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/DropRuleIdColumnOfRulesParametersTableTest/schema.sql
@@ -0,0 +1,43 @@
+create TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+alter table "RULES" add CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+create UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+create TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40) NOT NULL
+);
+alter table "RULES_PARAMETERS" add CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+create INDEX "RULES_PARAMETERS_RULE_UUID" ON "RULES_PARAMETERS"("RULE_UUID");
+create UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_UUID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..9fdc54dfb08
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/MakeRulesParametersRuleUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql
new file mode 100644
index 00000000000..9fdc54dfb08
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/rules/rulesparameters/PopulateRulesParametersRuleUuidColumnTest/schema.sql
@@ -0,0 +1,43 @@
+CREATE TABLE "RULES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(200),
+ "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+ "PLUGIN_KEY" VARCHAR(200),
+ "PLUGIN_CONFIG_KEY" VARCHAR(200),
+ "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+ "SCOPE" VARCHAR(20) NOT NULL,
+ "DESCRIPTION" CLOB(2147483647),
+ "PRIORITY" INTEGER,
+ "STATUS" VARCHAR(40),
+ "LANGUAGE" VARCHAR(20),
+ "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+ "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+ "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+ "GAP_DESCRIPTION" VARCHAR(4000),
+ "SYSTEM_TAGS" VARCHAR(4000),
+ "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "DESCRIPTION_FORMAT" VARCHAR(20),
+ "RULE_TYPE" TINYINT,
+ "SECURITY_STANDARDS" VARCHAR(4000),
+ "IS_AD_HOC" BOOLEAN NOT NULL,
+ "IS_EXTERNAL" BOOLEAN NOT NULL,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "UUID" VARCHAR(40) NOT NULL,
+ "TEMPLATE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
+
+CREATE TABLE "RULES_PARAMETERS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(128) NOT NULL,
+ "DESCRIPTION" VARCHAR(4000),
+ "PARAM_TYPE" VARCHAR(512) NOT NULL,
+ "DEFAULT_VALUE" VARCHAR(4000),
+ "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID");
+CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID");
+CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME");
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java
index ac6c2596f8d..6313b59eeca 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java
@@ -30,18 +30,18 @@ import org.elasticsearch.search.SearchHits;
public class SearchIdResult<ID> {
- private final List<ID> ids;
+ private final List<ID> uuids;
private final Facets facets;
private final long total;
public SearchIdResult(SearchResponse response, Function<String, ID> converter, TimeZone timeZone) {
this.facets = new Facets(response, timeZone);
this.total = response.getHits().getTotalHits();
- this.ids = convertToIds(response.getHits(), converter);
+ this.uuids = convertToIds(response.getHits(), converter);
}
- public List<ID> getIds() {
- return ids;
+ public List<ID> getUuids() {
+ return uuids;
}
public long getTotal() {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java
index 292139ef1a7..c5854408c1d 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java
@@ -25,11 +25,9 @@ import java.util.Date;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.Duration;
-import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.es.BaseDoc;
import org.sonar.server.permission.index.AuthorizationDoc;
import org.sonar.server.security.SecurityStandards;
@@ -81,9 +79,8 @@ public class IssueDoc extends BaseDoc {
return getField(IssueIndexDefinition.FIELD_ISSUE_IS_MAIN_BRANCH);
}
- public Integer ruleId() {
- String field = getField(IssueIndexDefinition.FIELD_ISSUE_RULE_ID);
- return Integer.valueOf(field);
+ public String ruleUuid() {
+ return getField(IssueIndexDefinition.FIELD_ISSUE_RULE_UUID);
}
public String language() {
@@ -193,21 +190,11 @@ public class IssueDoc extends BaseDoc {
return this;
}
- public IssueDoc setRuleId(Integer s) {
- // leftpad with 0 to have correct sorting on this fields (other 10 becomes lower than 9)
- String str = formatRuleId(s);
- setField(IssueIndexDefinition.FIELD_ISSUE_RULE_ID, str);
+ public IssueDoc setRuleUuid(String s) {
+ setField(IssueIndexDefinition.FIELD_ISSUE_RULE_UUID, s);
return this;
}
- public static String formatRuleId(RuleDefinitionDto dto) {
- return formatRuleId(dto.getId());
- }
-
- private static String formatRuleId(int s) {
- return StringUtils.leftPad(String.valueOf(s), 10, "0");
- }
-
public IssueDoc setLanguage(@Nullable String s) {
setField(IssueIndexDefinition.FIELD_ISSUE_LANGUAGE, s);
return this;
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
index f02f7536cfc..fb9e19da2f0 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
@@ -90,7 +90,7 @@ public class IssueIndexDefinition implements IndexDefinition {
public static final String FIELD_ISSUE_DIRECTORY_PATH = "dirPath";
public static final String FIELD_ISSUE_RESOLUTION = "resolution";
- public static final String FIELD_ISSUE_RULE_ID = "ruleId";
+ public static final String FIELD_ISSUE_RULE_UUID = "ruleUuid";
public static final String FIELD_ISSUE_SEVERITY = "severity";
public static final String FIELD_ISSUE_SEVERITY_VALUE = "severityValue";
public static final String FIELD_ISSUE_STATUS = "status";
@@ -152,7 +152,7 @@ public class IssueIndexDefinition implements IndexDefinition {
mapping.createBooleanField(FIELD_ISSUE_IS_MAIN_BRANCH);
mapping.keywordFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build();
mapping.keywordFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
- mapping.keywordFieldBuilder(FIELD_ISSUE_RULE_ID).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_ISSUE_RULE_UUID).disableNorms().build();
mapping.keywordFieldBuilder(FIELD_ISSUE_SEVERITY).disableNorms().build();
mapping.createByteField(FIELD_ISSUE_SEVERITY_VALUE);
mapping.keywordFieldBuilder(FIELD_ISSUE_STATUS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java
index 0a6b6f0ae06..d77b094947c 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java
@@ -67,7 +67,7 @@ class IssueIteratorForSingleChunk implements IssueIterator {
// column 11
"i.issue_update_date",
- "r.id",
+ "r.uuid",
"r.language",
"c.uuid",
"c.module_uuid_path",
@@ -84,7 +84,7 @@ class IssueIteratorForSingleChunk implements IssueIterator {
};
private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from issues i " +
- "inner join rules r on r.id = i.rule_id " +
+ "inner join rules r on r.uuid = i.rule_uuid " +
"inner join components c on c.uuid = i.component_uuid ";
private static final String PROJECT_FILTER = " and c.project_uuid = ? and i.project_uuid = ? ";
@@ -203,8 +203,7 @@ class IssueIteratorForSingleChunk implements IssueIterator {
doc.setFuncCloseDate(longToDate(getLong(rs, 9)));
doc.setFuncCreationDate(longToDate(getLong(rs, 10)));
doc.setFuncUpdateDate(longToDate(getLong(rs, 11)));
- Integer ruleId = rs.getInt(12);
- doc.setRuleId(ruleId);
+ doc.setRuleUuid(rs.getString(12));
doc.setLanguage(rs.getString(13));
doc.setComponentUuid(rs.getString(14));
String moduleUuidPath = rs.getString(15);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java
index e9e7d2e0295..b9e1bedc84f 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java
@@ -40,7 +40,7 @@ public class ActiveRuleChange {
private final Type type;
private final ActiveRuleKey key;
- private final int ruleId;
+ private final String ruleUuid;
private String severity = null;
private ActiveRuleInheritance inheritance = null;
private final Map<String, String> parameters = new HashMap<>();
@@ -48,22 +48,22 @@ public class ActiveRuleChange {
public ActiveRuleChange(Type type, ActiveRuleDto activeRule, RuleDefinitionDto ruleDefinition) {
this.type = type;
this.key = activeRule.getKey();
- this.ruleId = ruleDefinition.getId();
+ this.ruleUuid = ruleDefinition.getUuid();
this.activeRule = activeRule;
}
public ActiveRuleChange(Type type, ActiveRuleKey key, RuleDefinitionDto ruleDefinition) {
this.type = type;
this.key = key;
- this.ruleId = ruleDefinition.getId();
+ this.ruleUuid = ruleDefinition.getUuid();
}
public ActiveRuleKey getKey() {
return key;
}
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
public Type getType() {
@@ -121,7 +121,7 @@ public class ActiveRuleChange {
dto.setRulesProfileUuid(getKey().getRuleProfileUuid());
dto.setUserUuid(userUuid);
Map<String, String> data = new HashMap<>();
- data.put("ruleId", String.valueOf(getRuleId()));
+ data.put("ruleUuid", getRuleUuid());
parameters.entrySet().stream()
.filter(param -> !param.getKey().isEmpty())
@@ -142,7 +142,7 @@ public class ActiveRuleChange {
return MoreObjects.toStringHelper(this)
.add("type", type)
.add("key", key)
- .add("ruleId", ruleId)
+ .add("ruleUuid", ruleUuid)
.add("severity", severity)
.add("inheritance", inheritance)
.add("parameters", parameters)
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
index 96f3266202a..95b55cd2094 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
@@ -26,11 +26,11 @@ import org.sonar.server.es.BaseDoc;
import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_ID;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_UUID;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
public class ActiveRuleDoc extends BaseDoc {
@@ -39,22 +39,18 @@ public class ActiveRuleDoc extends BaseDoc {
public ActiveRuleDoc(String uuid) {
super(TYPE_ACTIVE_RULE, Maps.newHashMapWithExpectedSize(10));
- setField(FIELD_ACTIVE_RULE_ID, uuid);
+ setField(FIELD_ACTIVE_RULE_UUID, uuid);
}
public ActiveRuleDoc(Map<String, Object> source) {
super(TYPE_ACTIVE_RULE, source);
}
- public static String docIdOf(long activeRuleId) {
- return docIdOf(String.valueOf(activeRuleId));
+ public static String docIdOf(String activeRuleUuid) {
+ return DOC_ID_PREFIX + activeRuleUuid;
}
- public static String docIdOf(String activeRuleId) {
- return DOC_ID_PREFIX + activeRuleId;
- }
-
- public static String activeRuleIdOf(String docId) {
+ public static String activeRuleUuidOf(String docId) {
if (docId.startsWith(DOC_ID_PREFIX)) {
return docId.substring(DOC_ID_PREFIX.length());
}
@@ -64,13 +60,12 @@ public class ActiveRuleDoc extends BaseDoc {
@Override
public String getId() {
- return docIdOf(getField(FIELD_ACTIVE_RULE_ID));
+ return docIdOf(getField(FIELD_ACTIVE_RULE_UUID));
}
- ActiveRuleDoc setRuleId(int ruleId) {
- String parent = String.valueOf(ruleId);
- setParent(parent);
- setField(FIELD_RULE_ID, parent);
+ ActiveRuleDoc setRuleUuid(String ruleUuid) {
+ setParent(ruleUuid);
+ setField(FIELD_RULE_UUID, ruleUuid);
return this;
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
index 2657619ff60..92387e6b754 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
@@ -59,7 +59,7 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
public class ActiveRuleIndexer implements ResilientIndexer {
private static final Logger LOGGER = Loggers.get(ActiveRuleIndexer.class);
- private static final String ID_TYPE_ACTIVE_RULE_ID = "activeRuleId";
+ private static final String ID_TYPE_ACTIVE_RULE_UUID = "activeRuleUuid";
private static final String ID_TYPE_RULE_PROFILE_UUID = "ruleProfileUuid";
private final DbClient dbClient;
@@ -88,7 +88,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
public void commitAndIndex(DbSession dbSession, Collection<ActiveRuleChange> changes) {
List<EsQueueDto> items = changes.stream()
.map(ActiveRuleChange::getActiveRule)
- .map(ar -> newQueueDto(docIdOf(ar.getUuid()), ID_TYPE_ACTIVE_RULE_ID, String.valueOf(ar.getRuleId())))
+ .map(ar -> newQueueDto(docIdOf(ar.getUuid()), ID_TYPE_ACTIVE_RULE_UUID, ar.getRuleUuid()))
.collect(toArrayList());
dbClient.esQueueDao().insert(dbSession, items);
@@ -131,7 +131,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
items.forEach(i -> {
if (ID_TYPE_RULE_PROFILE_UUID.equals(i.getDocIdType())) {
ruleProfileItems.put(i.getDocId(), i);
- } else if (ID_TYPE_ACTIVE_RULE_ID.equals(i.getDocIdType())) {
+ } else if (ID_TYPE_ACTIVE_RULE_UUID.equals(i.getDocIdType())) {
activeRuleItems.put(i.getDocId(), i);
} else {
LOGGER.error("Unsupported es_queue.doc_id_type. Removing row from queue: " + i);
@@ -169,7 +169,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
private static Collection<String> toActiveRuleUuids(Map<String, EsQueueDto> activeRuleItems) {
Set<String> docIds = activeRuleItems.keySet();
return docIds.stream()
- .map(ActiveRuleDoc::activeRuleIdOf)
+ .map(ActiveRuleDoc::activeRuleUuidOf)
.collect(toSet(docIds.size()));
}
@@ -215,7 +215,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
private static IndexRequest newIndexRequest(IndexedActiveRuleDto dto) {
ActiveRuleDoc doc = new ActiveRuleDoc(dto.getUuid())
- .setRuleId(dto.getRuleId())
+ .setRuleUuid(dto.getRuleUuid())
.setRuleProfileUuid(dto.getRuleProfileUuid())
.setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()));
// all the fields must be present, even if value is null
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
index a6b660940d2..1b4752ab9c4 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
@@ -28,27 +28,29 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
-import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDao;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.markdown.Markdown;
import org.sonar.server.organization.DefaultOrganizationProvider;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Optional.empty;
/**
* Will be removed in the future.
*/
-public class DefaultRuleFinder implements RuleFinder {
+public class DefaultRuleFinder implements ServerRuleFinder {
private final DbClient dbClient;
private final RuleDao ruleDao;
@@ -61,14 +63,14 @@ public class DefaultRuleFinder implements RuleFinder {
}
@Override
- @CheckForNull
- public org.sonar.api.rules.Rule findById(int ruleId) {
+ public Optional<RuleDefinitionDto> findDtoByKey(RuleKey key) {
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<RuleDto> rule = ruleDao.selectById(ruleId, defaultOrganizationProvider.get().getUuid(), dbSession);
+ Optional<RuleDefinitionDto> rule = ruleDao.selectDefinitionByKey(dbSession, key);
if (rule.isPresent() && rule.get().getStatus() != RuleStatus.REMOVED) {
- return toRule(rule.get(), ruleDao.selectRuleParamsByRuleKey(dbSession, rule.get().getKey()));
+ return rule;
+ } else {
+ return empty();
}
- return null;
}
}
@@ -119,11 +121,11 @@ public class DefaultRuleFinder implements RuleFinder {
private Collection<org.sonar.api.rules.Rule> convertToRuleApi(DbSession dbSession, List<RuleDto> ruleDtos) {
List<org.sonar.api.rules.Rule> rules = new ArrayList<>();
- List<RuleKey> ruleKeys = FluentIterable.from(ruleDtos).transform(RuleDtoToKey.INSTANCE).toList();
+ List<RuleKey> ruleKeys = ruleDtos.stream().map(RuleDto::getKey).collect(Collectors.toList());
List<RuleParamDto> ruleParamDtos = ruleDao.selectRuleParamsByRuleKeys(dbSession, ruleKeys);
- ImmutableListMultimap<Integer, RuleParamDto> ruleParamByRuleId = FluentIterable.from(ruleParamDtos).index(RuleParamDtoToRuleId.INSTANCE);
+ ImmutableListMultimap<String, RuleParamDto> ruleParamByRuleUuid = FluentIterable.from(ruleParamDtos).index(RuleParamDtoToRuleUuid.INSTANCE);
for (RuleDto rule : ruleDtos) {
- rules.add(toRule(rule, ruleParamByRuleId.get(rule.getId())));
+ rules.add(toRule(rule, ruleParamByRuleUuid.get(rule.getUuid())));
}
return rules;
}
@@ -146,8 +148,7 @@ public class DefaultRuleFinder implements RuleFinder {
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(rule.getStatus().name())
.setSystemTags(rule.getSystemTags().toArray(new String[rule.getSystemTags().size()]))
- .setTags(rule.getTags().toArray(new String[rule.getTags().size()]))
- .setId(rule.getId());
+ .setTags(rule.getTags().toArray(new String[rule.getTags().size()]));
if (description != null && descriptionFormat != null) {
if (RuleDto.Format.HTML.equals(descriptionFormat)) {
apiRule.setDescription(description);
@@ -166,21 +167,12 @@ public class DefaultRuleFinder implements RuleFinder {
return apiRule;
}
- private enum RuleDtoToKey implements Function<RuleDto, RuleKey> {
- INSTANCE;
-
- @Override
- public RuleKey apply(@Nonnull RuleDto input) {
- return input.getKey();
- }
- }
-
- private enum RuleParamDtoToRuleId implements Function<RuleParamDto, Integer> {
+ private enum RuleParamDtoToRuleUuid implements Function<RuleParamDto, String> {
INSTANCE;
@Override
- public Integer apply(@Nonnull RuleParamDto input) {
- return input.getRuleId();
+ public String apply(@Nonnull RuleParamDto input) {
+ return input.getRuleUuid();
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java
new file mode 100644
index 00000000000..8449147d44c
--- /dev/null
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java
@@ -0,0 +1,29 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.rule;
+
+import java.util.Optional;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.db.rule.RuleDefinitionDto;
+
+public interface ServerRuleFinder extends RuleFinder {
+ Optional<RuleDefinitionDto> findDtoByKey(RuleKey key);
+}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java
index cc9630bb542..ab65bcb66b8 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java
@@ -40,7 +40,6 @@ import org.sonar.server.security.SecurityStandards.SQCategory;
import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_RULE;
-
/**
* Implementation of Rule based on an Elasticsearch document
*/
@@ -61,11 +60,11 @@ public class RuleDoc extends BaseDoc {
}
private String idAsString() {
- return getField(RuleIndexDefinition.FIELD_RULE_ID);
+ return getField(RuleIndexDefinition.FIELD_RULE_UUID);
}
- public RuleDoc setId(int ruleId) {
- setField(RuleIndexDefinition.FIELD_RULE_ID, String.valueOf(ruleId));
+ public RuleDoc setUuid(String ruleUuid) {
+ setField(RuleIndexDefinition.FIELD_RULE_UUID, ruleUuid);
return this;
}
@@ -271,7 +270,7 @@ public class RuleDoc extends BaseDoc {
public static RuleDoc of(RuleForIndexingDto dto, SecurityStandards securityStandards) {
RuleDoc ruleDoc = new RuleDoc()
- .setId(dto.getId())
+ .setUuid(dto.getUuid())
.setKey(dto.getRuleKey().toString())
.setRepository(dto.getRepository())
.setInternalKey(dto.getInternalKey())
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java
index 8894f8f15e2..361f9120c5c 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java
@@ -41,20 +41,20 @@ public class RuleExtensionDoc extends BaseDoc {
@Override
public String getId() {
- return idOf(getRuleId(), getScope());
+ return idOf(getRuleUuid(), getScope());
}
- public int getRuleId() {
- return Integer.valueOf(ruleIdAsString());
+ public String getRuleUuid() {
+ return ruleUuidAsString();
}
- private String ruleIdAsString() {
- return getField(RuleIndexDefinition.FIELD_RULE_ID);
+ private String ruleUuidAsString() {
+ return getField(RuleIndexDefinition.FIELD_RULE_UUID);
}
- public RuleExtensionDoc setRuleId(int ruleId) {
- String parent = String.valueOf(ruleId);
- setField(RuleIndexDefinition.FIELD_RULE_ID, parent);
+ public RuleExtensionDoc setRuleUuid(String ruleUuid) {
+ String parent = ruleUuid;
+ setField(RuleIndexDefinition.FIELD_RULE_UUID, parent);
setParent(parent);
return this;
}
@@ -79,20 +79,20 @@ public class RuleExtensionDoc extends BaseDoc {
public static RuleExtensionDoc of(RuleForIndexingDto rule) {
return new RuleExtensionDoc()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setScope(RuleExtensionScope.system())
.setTags(rule.getSystemTags());
}
public static RuleExtensionDoc of(RuleExtensionForIndexingDto rule) {
return new RuleExtensionDoc()
- .setRuleId(rule.getRuleId())
+ .setRuleUuid(rule.getRuleUuid())
.setScope(RuleExtensionScope.organization(rule.getOrganizationUuid()))
.setTags(rule.getTagsAsSet());
}
- public static String idOf(int ruleId, RuleExtensionScope scope) {
- return ruleId + "|" + scope.getScope();
+ public static String idOf(String ruleUuid, RuleExtensionScope scope) {
+ return ruleUuid + "|" + scope.getScope();
}
@Override
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
index b38348ac7b2..f2c25324126 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
@@ -149,7 +149,7 @@ public class RuleIndex {
this.system2 = system2;
}
- public SearchIdResult<Integer> search(RuleQuery query, SearchOptions options) {
+ public SearchIdResult<String> search(RuleQuery query, SearchOptions options) {
SearchRequestBuilder esSearch = client
.prepareSearch(TYPE_RULE);
@@ -171,13 +171,13 @@ public class RuleIndex {
}
esSearch.setQuery(boolQuery().must(qb).filter(fb));
- return new SearchIdResult<>(esSearch.get(), Integer::parseInt, system2.getDefaultTimeZone());
+ return new SearchIdResult<>(esSearch.get(), input -> input, system2.getDefaultTimeZone());
}
/**
- * Return all rule ids matching the search query, without pagination nor facets
+ * Return all rule uuids matching the search query, without pagination nor facets
*/
- public Iterator<Integer> searchAll(RuleQuery query) {
+ public Iterator<String> searchAll(RuleQuery query) {
SearchRequestBuilder esSearch = client
.prepareSearch(TYPE_RULE)
.setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES));
@@ -193,7 +193,7 @@ public class RuleIndex {
esSearch.setQuery(boolQuery().must(qb).filter(fb));
SearchResponse response = esSearch.get();
- return scrollIds(client, response, Integer::parseInt);
+ return scrollIds(client, response, i -> i);
}
/* Build main query (search based) */
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
index 1e10efc1b63..daf8a1a1cd0 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
@@ -44,7 +44,7 @@ public class RuleIndexDefinition implements IndexDefinition {
public static final Index DESCRIPTOR = Index.withRelations("rules");
public static final IndexMainType TYPE_RULE = IndexType.main(DESCRIPTOR, "rule");
- public static final String FIELD_RULE_ID = "ruleId";
+ public static final String FIELD_RULE_UUID = "ruleUuid";
public static final String FIELD_RULE_KEY = "key";
public static final String FIELD_RULE_REPOSITORY = "repo";
public static final String FIELD_RULE_RULE_KEY = "ruleKey";
@@ -81,7 +81,7 @@ public class RuleIndexDefinition implements IndexDefinition {
// Active rule fields
public static final IndexRelationType TYPE_ACTIVE_RULE = IndexType.relation(TYPE_RULE, "activeRule");
- public static final String FIELD_ACTIVE_RULE_ID = "activeRule_id";
+ public static final String FIELD_ACTIVE_RULE_UUID = "activeRule_uuid";
public static final String FIELD_ACTIVE_RULE_INHERITANCE = "activeRule_inheritance";
public static final String FIELD_ACTIVE_RULE_PROFILE_UUID = "activeRule_ruleProfile";
public static final String FIELD_ACTIVE_RULE_SEVERITY = "activeRule_severity";
@@ -121,7 +121,7 @@ public class RuleIndexDefinition implements IndexDefinition {
// Rule type
TypeMapping ruleMapping = index.createTypeMapping(TYPE_RULE);
- ruleMapping.keywordFieldBuilder(FIELD_RULE_ID).disableNorms().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_UUID).disableNorms().build();
ruleMapping.keywordFieldBuilder(FIELD_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
ruleMapping.keywordFieldBuilder(FIELD_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
ruleMapping.keywordFieldBuilder(FIELD_RULE_REPOSITORY).build();
@@ -154,7 +154,7 @@ public class RuleIndexDefinition implements IndexDefinition {
// Active rule
index.createTypeMapping(TYPE_ACTIVE_RULE)
- .keywordFieldBuilder(FIELD_ACTIVE_RULE_ID).disableNorms().build()
+ .keywordFieldBuilder(FIELD_ACTIVE_RULE_UUID).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
index 839890d3e68..e7447d060f8 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
@@ -96,12 +96,12 @@ public class RuleIndexer implements ResilientIndexer {
}
}
- public void commitAndIndex(DbSession dbSession, int ruleId) {
- commitAndIndex(dbSession, singletonList(ruleId));
+ public void commitAndIndex(DbSession dbSession, String ruleUuid) {
+ commitAndIndex(dbSession, singletonList(ruleUuid));
}
- public void commitAndIndex(DbSession dbSession, Collection<Integer> ruleIds) {
- List<EsQueueDto> items = ruleIds.stream()
+ public void commitAndIndex(DbSession dbSession, Collection<String> ruleUuids) {
+ List<EsQueueDto> items = ruleUuids.stream()
.map(RuleIndexer::createQueueDtoForRule)
.collect(MoreCollectors.toArrayList());
@@ -113,8 +113,8 @@ public class RuleIndexer implements ResilientIndexer {
/**
* Commit a change on a rule and its extension on the given organization
*/
- public void commitAndIndex(DbSession dbSession, int ruleId, OrganizationDto organization) {
- List<EsQueueDto> items = asList(createQueueDtoForRule(ruleId), createQueueDtoForRuleExtension(ruleId, organization));
+ public void commitAndIndex(DbSession dbSession, String ruleUuid, OrganizationDto organization) {
+ List<EsQueueDto> items = asList(createQueueDtoForRule(ruleUuid), createQueueDtoForRuleExtension(ruleUuid, organization));
dbClient.esQueueDao().insert(dbSession, items);
dbSession.commit();
postCommit(dbSession, items);
@@ -146,23 +146,23 @@ public class RuleIndexer implements ResilientIndexer {
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items));
bulkIndexer.start();
- Set<Integer> ruleIds = items
+ Set<String> ruleUuids = items
.stream()
- .map(i -> Integer.parseInt(i.getDocId()))
+ .map(EsQueueDto::getDocId)
.collect(toHashSet(items.size()));
- dbClient.ruleDao().scrollIndexingRulesByKeys(dbSession, ruleIds,
+ dbClient.ruleDao().scrollIndexingRulesByKeys(dbSession, ruleUuids,
r -> {
bulkIndexer.add(ruleDocOf(r).toIndexRequest());
bulkIndexer.add(RuleExtensionDoc.of(r).toIndexRequest());
- ruleIds.remove(r.getId());
+ ruleUuids.remove(r.getUuid());
});
// the remaining items reference rows that don't exist in db. They must
// be deleted from index.
- ruleIds.forEach(ruleId -> {
- bulkIndexer.addDeletion(TYPE_RULE, ruleId.toString(), ruleId.toString());
- bulkIndexer.addDeletion(TYPE_RULE_EXTENSION, RuleExtensionDoc.idOf(ruleId, RuleExtensionScope.system()), ruleId.toString());
+ ruleUuids.forEach(ruleUuid -> {
+ bulkIndexer.addDeletion(TYPE_RULE, ruleUuid, ruleUuid);
+ bulkIndexer.addDeletion(TYPE_RULE_EXTENSION, RuleExtensionDoc.idOf(ruleUuid, RuleExtensionScope.system()), ruleUuid);
});
return Optional.of(bulkIndexer.stop());
@@ -185,14 +185,14 @@ public class RuleIndexer implements ResilientIndexer {
// only index requests, no deletion requests.
// Deactivated users are not deleted but updated.
r -> {
- RuleExtensionId docId = new RuleExtensionId(r.getOrganizationUuid(), r.getRuleId());
+ RuleExtensionId docId = new RuleExtensionId(r.getOrganizationUuid(), r.getRuleUuid());
docIds.remove(docId);
bulkIndexer.add(RuleExtensionDoc.of(r).toIndexRequest());
});
// the remaining items reference rows that don't exist in db. They must
// be deleted from index.
- docIds.forEach(docId -> bulkIndexer.addDeletion(TYPE_RULE_EXTENSION, docId.getId(), String.valueOf(docId.getRuleId())));
+ docIds.forEach(docId -> bulkIndexer.addDeletion(TYPE_RULE_EXTENSION, docId.getId(), docId.getRuleUuid()));
return Optional.of(bulkIndexer.stop());
}
@@ -239,14 +239,14 @@ public class RuleIndexer implements ResilientIndexer {
return new RuleExtensionId(esQueueDto.getDocId());
}
- private static EsQueueDto createQueueDtoForRule(int ruleId) {
- String docId = String.valueOf(ruleId);
+ private static EsQueueDto createQueueDtoForRule(String ruleUuid) {
+ String docId = ruleUuid;
return EsQueueDto.create(TYPE_RULE.format(), docId, null, docId);
}
- private static EsQueueDto createQueueDtoForRuleExtension(int ruleId, OrganizationDto organization) {
- String docId = RuleExtensionDoc.idOf(ruleId, RuleExtensionScope.organization(organization));
- return EsQueueDto.create(TYPE_RULE_EXTENSION.format(), docId, null, String.valueOf(ruleId));
+ private static EsQueueDto createQueueDtoForRuleExtension(String ruleUuid, OrganizationDto organization) {
+ String docId = RuleExtensionDoc.idOf(ruleUuid, RuleExtensionScope.organization(organization));
+ return EsQueueDto.create(TYPE_RULE_EXTENSION.format(), docId, null, ruleUuid);
}
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
index a6489aebce4..1c01e4c4b7d 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
@@ -55,6 +55,7 @@ import org.sonar.server.security.SecurityStandards.VulnerabilityProbability;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.rules.ExpectedException.none;
import static org.sonar.db.component.ComponentTesting.newFileDto;
@@ -426,7 +427,7 @@ public class IssueIndexerTest {
}
private IndexingResult indexProject(String projectUuid, ProjectIndexer.Cause cause) {
- Collection<EsQueueDto> items = underTest.prepareForRecovery(db.getSession(), asList(projectUuid), cause);
+ Collection<EsQueueDto> items = underTest.prepareForRecovery(db.getSession(), singletonList(projectUuid), cause);
db.commit();
return underTest.index(db.getSession(), items);
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java
index 3aa3a68072d..baf22b047f8 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java
@@ -63,7 +63,7 @@ public class IssueIteratorFactoryTest {
.setEffort(10L)
.setMessage(null)
.setLine(444)
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setIssueAttributes("JIRA=http://jira.com")
.setTags(ImmutableList.of("tag1", "tag2", "tag3"))
.setCreatedAt(1400000000000L)
@@ -85,7 +85,7 @@ public class IssueIteratorFactoryTest {
assertThat(issue.assigneeUuid()).isEqualTo("uuid-of-guy1");
assertThat(issue.authorLogin()).isEqualTo("guy2");
assertThat(issue.line()).isEqualTo(444);
- assertThat(issue.ruleId()).isEqualTo(rule.getId());
+ assertThat(issue.ruleUuid()).isEqualTo(rule.getUuid());
assertThat(issue.componentUuid()).isEqualTo(file.uuid());
assertThat(issue.projectUuid()).isEqualTo(file.projectUuid());
assertThat(issue.moduleUuid()).isEqualTo(file.projectUuid());
@@ -110,14 +110,14 @@ public class IssueIteratorFactoryTest {
t -> t
.setAssigneeUuid("uuid-of-guy1")
.setAuthorLogin("guy2")
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setIssueAttributes("JIRA=http://jira.com")
.setEffort(10L)
.setType(1));
IssueDto moduleIssue = dbTester.issues().insert(rule, project, module, t -> t
.setAssigneeUuid("uuid-of-guy2")
.setAuthorLogin("guy2")
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setIssueAttributes("JIRA=http://jira.com"));
IssueDto dirIssue = dbTester.issues().insert(rule, project, directory);
IssueDto projectIssue = dbTester.issues().insert(rule, project, project);
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java
index a9f4172d7e1..b001bd315cf 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java
@@ -19,9 +19,9 @@
*/
package org.sonar.server.qualityprofile;
-import java.util.Random;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
+import org.sonar.core.util.Uuids;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QProfileChangeDto;
import org.sonar.db.qualityprofile.QProfileDto;
@@ -39,14 +39,14 @@ public class ActiveRuleChangeTest {
public void toDto() {
QProfileDto profile = newQualityProfileDto();
ActiveRuleKey key = ActiveRuleKey.of(profile, RuleKey.of("P1", "R1"));
- int ruleId = new Random().nextInt(963);
- ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDefinitionDto().setId(ruleId));
+ String ruleUuid = Uuids.createFast();
+ ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDefinitionDto().setUuid(ruleUuid));
QProfileChangeDto result = underTest.toDto(A_USER_UUID);
assertThat(result.getChangeType()).isEqualTo(ACTIVATED.name());
assertThat(result.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(result.getUserUuid()).isEqualTo(A_USER_UUID);
- assertThat(result.getDataAsMap().get("ruleId")).isEqualTo(String.valueOf(ruleId));
+ assertThat(result.getDataAsMap().get("ruleUuid")).isEqualTo(ruleUuid);
}
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
index a580c71b27d..58ae6cc54e2 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
@@ -37,8 +37,6 @@ import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.qualityprofile.ActiveRuleChange;
-import static java.lang.String.valueOf;
-import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.Collections.emptySet;
import static java.util.Collections.singletonList;
@@ -97,7 +95,7 @@ public class ActiveRuleIndexerTest {
public void test_commitAndIndex() {
ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1);
ActiveRuleDto ar2 = db.qualityProfiles().activateRule(profile2, rule1);
- ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2);
+ db.qualityProfiles().activateRule(profile2, rule2);
commitAndIndex(rule1, ar1, ar2);
@@ -107,7 +105,7 @@ public class ActiveRuleIndexerTest {
@Test
public void commitAndIndex_empty_list() {
- ActiveRuleDto ar = db.qualityProfiles().activateRule(profile1, rule1);
+ db.qualityProfiles().activateRule(profile1, rule1);
underTest.commitAndIndex(db.getSession(), Collections.emptyList());
@@ -122,7 +120,7 @@ public class ActiveRuleIndexerTest {
commitAndIndex(rule1, ar);
- EsQueueDto expectedItem = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "ar_" + ar.getUuid(), "activeRuleId", valueOf(ar.getRuleId()));
+ EsQueueDto expectedItem = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "ar_" + ar.getUuid(), "activeRuleUuid", ar.getRuleUuid());
assertThatEsQueueContainsExactly(expectedItem);
es.unlockWrites(TYPE_ACTIVE_RULE);
}
@@ -145,7 +143,7 @@ public class ActiveRuleIndexerTest {
EsQueueDto item = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "the_id", "unsupported", "the_routing");
db.getDbClient().esQueueDao().insert(db.getSession(), item);
- underTest.index(db.getSession(), asList(item));
+ underTest.index(db.getSession(), singletonList(item));
assertThatEsQueueTableIsEmpty();
assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isEqualTo(0);
@@ -154,8 +152,8 @@ public class ActiveRuleIndexerTest {
@Test
public void commitDeletionOfProfiles() {
ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1);
- ActiveRuleDto ar2 = db.qualityProfiles().activateRule(profile2, rule1);
- ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2);
+ db.qualityProfiles().activateRule(profile2, rule1);
+ db.qualityProfiles().activateRule(profile2, rule2);
indexAll();
db.getDbClient().qualityProfileDao().deleteRulesProfilesByUuids(db.getSession(), singletonList(profile2.getRulesProfileUuid()));
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
index 00b60d44d1f..b1d8498dee0 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
@@ -97,15 +97,6 @@ public class DefaultRuleFinderTest {
@Test
public void should_success_finder_wrap() {
- // has Id
- assertThat(underTest.findById(rule1.getId()).getId()).isEqualTo(rule1.getId());
-
- // should_find_by_id
- assertThat(underTest.findById(rule3.getId()).getConfigKey()).isEqualTo("Checker/Treewalker/AnnotationUseStyleCheck");
-
- // should_not_find_disabled_rule_by_id
- assertThat(underTest.findById(rule2.getId())).isNull();
-
// should_find_by_key
Rule rule = underTest.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck");
assertThat(rule).isNotNull();
@@ -120,7 +111,7 @@ public class DefaultRuleFinderTest {
assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2);
// find_all_enabled
- assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId());
+ assertThat(underTest.findAll(RuleQuery.create())).extracting("ruleKey").containsOnly(rule1.getKey(), rule3.getKey(), rule4.getKey());
assertThat(underTest.findAll(RuleQuery.create())).hasSize(3);
// do_not_find_disabled_rules
@@ -131,28 +122,9 @@ public class DefaultRuleFinderTest {
}
@Test
- public void find_id_return_null_on_removed_rule() {
- // find rule with id 2 is REMOVED
- assertThat(underTest.findById(rule2.getId())).isNull();
- }
-
- @Test
public void find_all_not_include_removed_rule() {
- // find rule with id 2 is REMOVED
- assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId());
- }
-
- @Test
- public void findById_populates_system_tags_but_not_tags() {
- RuleDefinitionDto ruleDefinition = dbTester.rules()
- .insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6))));
- OrganizationDto organization = dbTester.organizations().insert();
- dbTester.rules().insertRule(organization);
-
- Rule rule = underTest.findById(ruleDefinition.getId());
- assertThat(rule.getSystemTags())
- .containsOnlyElementsOf(ruleDefinition.getSystemTags());
- assertThat(rule.getTags()).isEmpty();
+ // rule 3 is REMOVED
+ assertThat(underTest.findAll(RuleQuery.create())).extracting("ruleKey").containsOnly(rule1.getKey(), rule3.getKey(), rule4.getKey());
}
@Test
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
index 4f019b9b932..e123607d8e3 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
@@ -36,11 +36,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.ENGLISH_HTML_ANALYZER;
-import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_RULE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_HTML_DESCRIPTION;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_ID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_KEY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_REPOSITORY;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_UUID;
+import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_RULE;
public class RuleIndexDefinitionTest {
@@ -88,7 +88,7 @@ public class RuleIndexDefinitionTest {
// the following method fails if PUT fails
tester.putDocuments(TYPE_RULE, new RuleDoc(ImmutableMap.of(
- FIELD_RULE_ID, "123",
+ FIELD_RULE_UUID, "123",
FIELD_RULE_HTML_DESCRIPTION, longText,
FIELD_RULE_REPOSITORY, "squid",
FIELD_RULE_KEY, "squid:S001")));
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
index d4280569e4e..b52303120b4 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
@@ -25,7 +25,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
-import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -111,10 +110,10 @@ public class RuleIndexTest {
createRule();
index();
- SearchIdResult results = underTest.search(new RuleQuery(), new SearchOptions());
+ SearchIdResult<String> results = underTest.search(new RuleQuery(), new SearchOptions());
assertThat(results.getTotal()).isEqualTo(2);
- assertThat(results.getIds()).hasSize(2);
+ assertThat(results.getUuids()).hasSize(2);
}
@Test
@@ -132,15 +131,15 @@ public class RuleIndexTest {
// key
RuleQuery query = new RuleQuery().setQueryText("X001");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).containsOnly(js1.getId(), cobol1.getId());
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(js1.getUuid(), cobol1.getUuid());
// partial key does not match
query = new RuleQuery().setQueryText("X00");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// repo:key -> nice-to-have !
query = new RuleQuery().setQueryText("javascript:X001");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).containsOnly(js1.getId());
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(js1.getUuid());
}
@Test
@@ -151,7 +150,7 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setQueryText("x001");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).containsOnly(ruleDto.getId());
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(ruleDto.getUuid());
}
@Test
@@ -170,11 +169,11 @@ public class RuleIndexTest {
// key
RuleQuery query = new RuleQuery().setKey(RuleKey.of("javascript", "X001").toString());
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(1);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(1);
// partial key does not match
query = new RuleQuery().setKey("X001");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
}
@Test
@@ -184,19 +183,19 @@ public class RuleIndexTest {
// substring
RuleQuery query = new RuleQuery().setQueryText("test");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(1);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(1);
// substring
query = new RuleQuery().setQueryText("partial match");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(1);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(1);
// case-insensitive
query = new RuleQuery().setQueryText("TESTING");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(1);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(1);
// not found
query = new RuleQuery().setQueryText("not present");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
}
@Test
@@ -205,8 +204,8 @@ public class RuleIndexTest {
index();
RuleQuery protectedCharsQuery = new RuleQuery().setQueryText(rule.getName());
- List<Integer> results = underTest.search(protectedCharsQuery, new SearchOptions()).getIds();
- assertThat(results).containsOnly(rule.getId());
+ List<String> results = underTest.search(protectedCharsQuery, new SearchOptions()).getUuids();
+ assertThat(results).containsOnly(rule.getUuid());
}
@Test
@@ -231,39 +230,40 @@ public class RuleIndexTest {
index();
// partial match at word boundary
- assertThat(underTest.search(new RuleQuery().setQueryText("CWE"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule1.getId(), rule2.getId(), rule3.getId());
+ assertThat(underTest.search(new RuleQuery().setQueryText("CWE"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule1.getUuid(), rule2.getUuid(), rule3.getUuid());
// full match
- assertThat(underTest.search(new RuleQuery().setQueryText("CWE-123"), new SearchOptions()).getIds()).containsExactly(rule1.getId());
+ assertThat(underTest.search(new RuleQuery().setQueryText("CWE-123"), new SearchOptions()).getUuids()).containsExactly(rule1.getUuid());
// match somewhere else in the text
- assertThat(underTest.search(new RuleQuery().setQueryText("CWE-1000"), new SearchOptions()).getIds()).containsExactly(rule3.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("CWE 1000"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule3.getId(), rule1.getId());
+ assertThat(underTest.search(new RuleQuery().setQueryText("CWE-1000"), new SearchOptions()).getUuids()).containsExactly(rule3.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("CWE 1000"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule3.getUuid(), rule1.getUuid());
// several words
- assertThat(underTest.search(new RuleQuery().setQueryText("great rule"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule1.getId(), rule2.getId(), rule3.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("rule Another"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule2.getId(), rule3.getId());
+ assertThat(underTest.search(new RuleQuery().setQueryText("great rule"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule1.getUuid(), rule2.getUuid(),
+ rule3.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("rule Another"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule2.getUuid(), rule3.getUuid());
// no matches
- assertThat(underTest.search(new RuleQuery().setQueryText("unexisting"), new SearchOptions()).getIds()).isEmpty();
- assertThat(underTest.search(new RuleQuery().setQueryText("great rule unexisting"), new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("unexisting"), new SearchOptions()).getUuids()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("great rule unexisting"), new SearchOptions()).getUuids()).isEmpty();
// stopwords
- assertThat(underTest.search(new RuleQuery().setQueryText("and"), new SearchOptions()).getIds()).isEmpty();
- assertThat(underTest.search(new RuleQuery().setQueryText("great and shiny"), new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("and"), new SearchOptions()).getUuids()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("great and shiny"), new SearchOptions()).getUuids()).isEmpty();
// html
- assertThat(underTest.search(new RuleQuery().setQueryText("h1"), new SearchOptions()).getIds()).isEmpty();
- assertThat(underTest.search(new RuleQuery().setQueryText("style"), new SearchOptions()).getIds()).isEmpty();
- assertThat(underTest.search(new RuleQuery().setQueryText("special"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule4.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("geeks formatting inside tables"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule4.getId());
+ assertThat(underTest.search(new RuleQuery().setQueryText("h1"), new SearchOptions()).getUuids()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("style"), new SearchOptions()).getUuids()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("special"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule4.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("geeks formatting inside tables"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule4.getUuid());
// long words
- assertThat(underTest.search(new RuleQuery().setQueryText("missunderstand"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("missunderstandings"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("alsdkjfnadklsjfnadkdfnsksdjfn"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("internationalization"), new SearchOptions()).getIds()).containsExactlyInAnyOrder(rule5.getId());
- assertThat(underTest.search(new RuleQuery().setQueryText("internationalizationBlaBla"), new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(new RuleQuery().setQueryText("missunderstand"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule5.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("missunderstandings"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule5.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("alsdkjfnadklsjfnadkdfnsksdjfn"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule5.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("internationalization"), new SearchOptions()).getUuids()).containsExactlyInAnyOrder(rule5.getUuid());
+ assertThat(underTest.search(new RuleQuery().setQueryText("internationalizationBlaBla"), new SearchOptions()).getUuids()).isEmpty();
}
@Test
@@ -277,16 +277,16 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setRepositories(asList("checkstyle", "pmd"));
- SearchIdResult results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsExactly(pmd.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).containsExactly(pmd.getUuid());
// no results
query = new RuleQuery().setRepositories(singletonList("checkstyle"));
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// empty list => no filter
query = new RuleQuery().setRepositories(emptyList());
- assertThat(underTest.search(query, new SearchOptions()).getIds()).containsOnly(findbugs.getId(), pmd.getId());
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(findbugs.getUuid(), pmd.getUuid());
}
@Test
@@ -336,7 +336,7 @@ public class RuleIndexTest {
@Test
public void search_by_types() {
- RuleDefinitionDto codeSmell = createRule(setType(CODE_SMELL));
+ createRule(setType(CODE_SMELL));
RuleDefinitionDto vulnerability = createRule(setType(VULNERABILITY));
RuleDefinitionDto bug1 = createRule(setType(BUG));
RuleDefinitionDto bug2 = createRule(setType(BUG));
@@ -344,26 +344,26 @@ public class RuleIndexTest {
// find all
RuleQuery query = new RuleQuery();
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(4);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(4);
// type3 in filter
query = new RuleQuery().setTypes(of(VULNERABILITY));
- assertThat(underTest.search(query, new SearchOptions()).getIds()).containsOnly(vulnerability.getId());
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(vulnerability.getUuid());
query = new RuleQuery().setTypes(of(BUG));
- assertThat(underTest.search(query, new SearchOptions()).getIds()).containsOnly(bug1.getId(), bug2.getId());
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(bug1.getUuid(), bug2.getUuid());
// types in query => nothing
query = new RuleQuery().setQueryText("code smell bug vulnerability");
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// null list => no filter
query = new RuleQuery().setTypes(emptySet());
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(4);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(4);
// null list => no filter
query = new RuleQuery().setTypes(null);
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(4);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(4);
}
@Test
@@ -374,23 +374,23 @@ public class RuleIndexTest {
// find all
RuleQuery query = new RuleQuery();
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).hasSize(2);
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).hasSize(2);
// Only template
query = new RuleQuery().setIsTemplate(true);
results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(ruleIsTemplate.getId());
+ assertThat(results.getUuids()).containsOnly(ruleIsTemplate.getUuid());
// Only not template
query = new RuleQuery().setIsTemplate(false);
results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(ruleNoTemplate.getId());
+ assertThat(results.getUuids()).containsOnly(ruleNoTemplate.getUuid());
// null => no filter
query = new RuleQuery().setIsTemplate(null);
results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(ruleIsTemplate.getId(), ruleNoTemplate.getId());
+ assertThat(results.getUuids()).containsOnly(ruleIsTemplate.getUuid(), ruleNoTemplate.getUuid());
}
@Test
@@ -401,57 +401,57 @@ public class RuleIndexTest {
// Only external
RuleQuery query = new RuleQuery().setIncludeExternal(true);
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(ruleIsExternal.getId(), ruleIsNotExternal.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).containsOnly(ruleIsExternal.getUuid(), ruleIsNotExternal.getUuid());
// Only not external
query = new RuleQuery().setIncludeExternal(false);
results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(ruleIsNotExternal.getId());
+ assertThat(results.getUuids()).containsOnly(ruleIsNotExternal.getUuid());
}
@Test
public void search_by_template_key() {
RuleDefinitionDto template = createRule(setIsTemplate(true));
- RuleDefinitionDto customRule = createRule(setTemplateId(template.getId()));
+ RuleDefinitionDto customRule = createRule(setTemplateId(template.getUuid()));
index();
// find all
RuleQuery query = new RuleQuery();
- SearchIdResult results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).hasSize(2);
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).hasSize(2);
// Only custom rule
query = new RuleQuery().setTemplateKey(template.getKey().toString());
results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(customRule.getId());
+ assertThat(results.getUuids()).containsOnly(customRule.getUuid());
// null => no filter
query = new RuleQuery().setTemplateKey(null);
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
}
@Test
public void search_by_any_of_languages() {
- RuleDefinitionDto java = createRule(setLanguage("java"));
+ createRule(setLanguage("java"));
RuleDefinitionDto javascript = createRule(setLanguage("js"));
index();
RuleQuery query = new RuleQuery().setLanguages(asList("cobol", "js"));
- SearchIdResult results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(javascript.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).containsOnly(javascript.getUuid());
// no results
query = new RuleQuery().setLanguages(singletonList("cpp"));
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// empty list => no filter
query = new RuleQuery().setLanguages(emptyList());
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
// null list => no filter
query = new RuleQuery().setLanguages(null);
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
}
@Test
@@ -462,8 +462,8 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setCwe(of("543"));
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions().addFacets("cwe"));
- assertThat(results.getIds()).containsOnly(rule1.getId(), rule2.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("cwe"));
+ assertThat(results.getUuids()).containsOnly(rule1.getUuid(), rule2.getUuid());
}
@Test
@@ -474,8 +474,8 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setOwaspTop10(of("a5", "a10"));
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions().addFacets("owaspTop10"));
- assertThat(results.getIds()).containsOnly(rule1.getId(), rule2.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("owaspTop10"));
+ assertThat(results.getUuids()).containsOnly(rule1.getUuid(), rule2.getUuid());
}
@Test
@@ -486,8 +486,8 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setSansTop25(of(SANS_TOP_25_INSECURE_INTERACTION, SANS_TOP_25_RISKY_RESOURCE));
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions().addFacets("sansTop25"));
- assertThat(results.getIds()).containsOnly(rule1.getId(), rule2.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("sansTop25"));
+ assertThat(results.getUuids()).containsOnly(rule1.getUuid(), rule2.getUuid());
}
@Test
@@ -498,8 +498,8 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setSonarsourceSecurity(of("sql-injection", "open-redirect"));
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions().addFacets("sonarsourceSecurity"));
- assertThat(results.getIds()).containsOnly(rule1.getId(), rule3.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("sonarsourceSecurity"));
+ assertThat(results.getUuids()).containsOnly(rule1.getUuid(), rule3.getUuid());
}
@Test
@@ -548,25 +548,25 @@ public class RuleIndexTest {
@Test
public void search_by_any_of_severities() {
- RuleDefinitionDto blocker = createRule(setSeverity(BLOCKER));
+ createRule(setSeverity(BLOCKER));
RuleDefinitionDto info = createRule(setSeverity(INFO));
index();
RuleQuery query = new RuleQuery().setSeverities(asList(INFO, MINOR));
- SearchIdResult results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(info.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).containsOnly(info.getUuid());
// no results
query = new RuleQuery().setSeverities(singletonList(MINOR));
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// empty list => no filter
query = new RuleQuery().setSeverities(emptyList());
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
// null list => no filter
query = new RuleQuery().setSeverities();
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
}
@Test
@@ -576,20 +576,20 @@ public class RuleIndexTest {
index();
RuleQuery query = new RuleQuery().setStatuses(asList(RuleStatus.DEPRECATED, RuleStatus.READY));
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsOnly(ready.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).containsOnly(ready.getUuid());
// no results
query = new RuleQuery().setStatuses(singletonList(RuleStatus.DEPRECATED));
- assertThat(underTest.search(query, new SearchOptions()).getIds()).isEmpty();
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// empty list => no filter
query = new RuleQuery().setStatuses(emptyList());
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
// null list => no filter
query = new RuleQuery().setStatuses(null);
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(2);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
}
@Test
@@ -630,11 +630,11 @@ public class RuleIndexTest {
}
private void verifySearch(RuleQuery query, RuleDefinitionDto... expectedRules) {
- SearchIdResult<Integer> result = underTest.search(query, new SearchOptions());
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions());
assertThat(result.getTotal()).isEqualTo((long) expectedRules.length);
- assertThat(result.getIds()).hasSize(expectedRules.length);
+ assertThat(result.getUuids()).hasSize(expectedRules.length);
for (RuleDefinitionDto expectedRule : expectedRules) {
- assertThat(result.getIds()).contains(expectedRule.getId());
+ assertThat(result.getUuids()).contains(expectedRule.getUuid());
}
}
@@ -720,13 +720,13 @@ public class RuleIndexTest {
}
private void verifyFacet(RuleQuery query, String facet, Map.Entry<String, Long>... expectedBuckets) {
- SearchIdResult<Integer> result = underTest.search(query, new SearchOptions().addFacets(facet));
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(facet));
assertThat(result.getFacets().get(facet))
.containsOnly(expectedBuckets);
}
private void verifyNoFacet(RuleQuery query, String facet) {
- SearchIdResult<Integer> result = underTest.search(query, new SearchOptions().addFacets(facet));
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(facet));
assertThat(result.getFacets().get(facet)).isNull();
}
@@ -848,7 +848,7 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery();
- assertThat(underTest.search(query, new SearchOptions()).getIds()).hasSize(9);
+ assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(9);
}
/**
@@ -861,7 +861,7 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery().setOrganization(organization);
- SearchIdResult result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES,
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES,
FACET_TAGS, FACET_TYPES)));
Map<String, LinkedHashMap<String, Long>> facets = result.getFacets().getAll();
assertThat(facets).hasSize(4);
@@ -882,9 +882,9 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery().setOrganization(organization).setLanguages(ImmutableList.of("cpp"));
- SearchIdResult result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES,
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES,
FACET_REPOSITORIES, FACET_TAGS)));
- assertThat(result.getIds()).hasSize(3);
+ assertThat(result.getUuids()).hasSize(3);
assertThat(result.getFacets().getAll()).hasSize(3);
assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java", "cobol");
assertThat(result.getFacets().get(FACET_REPOSITORIES).keySet()).containsOnly("foo");
@@ -896,7 +896,7 @@ public class RuleIndexTest {
rangeClosed(1, 101).forEach(i -> db.rules().insert(r -> r.setLanguage("lang" + i)));
index();
- SearchIdResult result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_LANGUAGES)));
+ SearchIdResult<String> result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_LANGUAGES)));
assertThat(result.getFacets().get(FACET_LANGUAGES).size()).isEqualTo(100);
}
@@ -906,7 +906,7 @@ public class RuleIndexTest {
rangeClosed(1, 11).forEach(i -> db.rules().insert(r -> r.setRepositoryKey("repo" + i)));
index();
- SearchIdResult result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_REPOSITORIES)));
+ SearchIdResult<String> result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_REPOSITORIES)));
assertThat(result.getFacets().get(FACET_REPOSITORIES).size()).isEqualTo(10);
}
@@ -921,7 +921,7 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery().setOrganization(organization);
SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS));
- SearchIdResult result = underTest.search(query, options);
+ SearchIdResult<String> result = underTest.search(query, options);
assertThat(result.getFacets().get(FACET_TAGS)).contains(entry("bla", 1L));
}
@@ -935,7 +935,7 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery()
.setOrganization(db.getDefaultOrganization());
SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS));
- SearchIdResult result = underTest.search(query, options);
+ SearchIdResult<String> result = underTest.search(query, options);
assertThat(result.getFacets().get(FACET_TAGS).size()).isEqualTo(100);
assertThat(result.getFacets().get(FACET_TAGS)).contains(entry("tag0", 1L), entry("tag25", 1L), entry("tag99", 1L));
assertThat(result.getFacets().get(FACET_TAGS)).doesNotContain(entry("tagA", 1L));
@@ -952,7 +952,7 @@ public class RuleIndexTest {
.setOrganization(db.getDefaultOrganization())
.setTags(singletonList("tagA"));
SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS));
- SearchIdResult result = underTest.search(query, options);
+ SearchIdResult<String> result = underTest.search(query, options);
assertThat(result.getFacets().get(FACET_TAGS).size()).isEqualTo(101);
assertThat(result.getFacets().get(FACET_TAGS).entrySet()).extracting(e -> entry(e.getKey(), e.getValue())).contains(
@@ -974,7 +974,7 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery().setOrganization(organization2);
SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS));
- SearchIdResult result = underTest.search(query, options);
+ SearchIdResult<String> result = underTest.search(query, options);
assertThat(result.getFacets().get(FACET_TAGS).entrySet()).extracting(e -> entry(e.getKey(), e.getValue())).containsExactly(
entry("bla2", 1L));
}
@@ -985,7 +985,7 @@ public class RuleIndexTest {
RuleQuery query = new RuleQuery().setOrganization(organization);
SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS));
- SearchIdResult result = underTest.search(query, options);
+ SearchIdResult<String> result = underTest.search(query, options);
assertThat(result.getFacets().get(FACET_TAGS)).isNotNull();
}
@@ -1013,9 +1013,9 @@ public class RuleIndexTest {
.setLanguages(ImmutableList.of("cpp"))
.setTags(ImmutableList.of("T2"));
- SearchIdResult result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES,
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES,
FACET_TAGS)));
- assertThat(result.getIds()).hasSize(1);
+ assertThat(result.getUuids()).hasSize(1);
Facets facets = result.getFacets();
assertThat(facets.getAll()).hasSize(3);
assertThat(facets.get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java");
@@ -1040,9 +1040,9 @@ public class RuleIndexTest {
.setTags(ImmutableList.of("T2"))
.setTypes(asList(BUG, CODE_SMELL));
- SearchIdResult result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS,
+ SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS,
FACET_TYPES)));
- assertThat(result.getIds()).hasSize(2);
+ assertThat(result.getUuids()).hasSize(2);
assertThat(result.getFacets().getAll()).hasSize(4);
assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java");
assertThat(result.getFacets().get(FACET_REPOSITORIES).keySet()).containsOnly("foo", "xoo");
@@ -1059,13 +1059,13 @@ public class RuleIndexTest {
// ascending
RuleQuery query = new RuleQuery().setSortField(RuleIndexDefinition.FIELD_RULE_NAME);
- SearchIdResult<Integer> results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsExactly(abc.getId(), abcd.getId(), fgh.getId());
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions());
+ assertThat(results.getUuids()).containsExactly(abc.getUuid(), abcd.getUuid(), fgh.getUuid());
// descending
query = new RuleQuery().setSortField(RuleIndexDefinition.FIELD_RULE_NAME).setAscendingSort(false);
results = underTest.search(query, new SearchOptions());
- assertThat(results.getIds()).containsExactly(fgh.getId(), abcd.getId(), abc.getId());
+ assertThat(results.getUuids()).containsExactly(fgh.getUuid(), abcd.getUuid(), abc.getUuid());
}
@Test
@@ -1075,8 +1075,8 @@ public class RuleIndexTest {
RuleDefinitionDto older = createRule(setCreatedAt(1000L), setUpdatedAt(2000L));
index();
- SearchIdResult<Integer> results = underTest.search(new RuleQuery(), new SearchOptions());
- assertThat(results.getIds()).containsExactly(oldest.getId(), older.getId(), old.getId());
+ SearchIdResult<String> results = underTest.search(new RuleQuery(), new SearchOptions());
+ assertThat(results.getUuids()).containsExactly(oldest.getUuid(), older.getUuid(), old.getUuid());
}
@Test
@@ -1100,27 +1100,27 @@ public class RuleIndexTest {
// from 0 to 1 included
SearchOptions options = new SearchOptions();
options.setOffset(0).setLimit(2);
- SearchIdResult results = underTest.search(new RuleQuery(), options);
+ SearchIdResult<String> results = underTest.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
- assertThat(results.getIds()).hasSize(2);
+ assertThat(results.getUuids()).hasSize(2);
// from 0 to 9 included
options.setOffset(0).setLimit(10);
results = underTest.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
- assertThat(results.getIds()).hasSize(3);
+ assertThat(results.getUuids()).hasSize(3);
// from 2 to 11 included
options.setOffset(2).setLimit(10);
results = underTest.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
- assertThat(results.getIds()).hasSize(1);
+ assertThat(results.getUuids()).hasSize(1);
// from 2 to 11 included
options.setOffset(2).setLimit(0);
results = underTest.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
- assertThat(results.getIds()).hasSize(1);
+ assertThat(results.getUuids()).hasSize(1);
}
@Test
@@ -1153,16 +1153,16 @@ public class RuleIndexTest {
index();
// inactive rules on profile
- List<SearchHit> ruleDocs = es.getDocuments(TYPE_RULE);
- List<SearchHit> activeRuleDocs = es.getDocuments(TYPE_ACTIVE_RULE);
+ es.getDocuments(TYPE_RULE);
+ es.getDocuments(TYPE_ACTIVE_RULE);
assertThat(underTest.searchAll(new RuleQuery().setActivation(false).setQProfile(profile2)))
.toIterable()
- .containsOnly(rule2.getId(), rule3.getId());
+ .containsOnly(rule2.getUuid(), rule3.getUuid());
// active rules on profile
assertThat(underTest.searchAll(new RuleQuery().setActivation(true).setQProfile(profile2)))
.toIterable()
- .containsOnly(rule1.getId());
+ .containsOnly(rule1.getUuid());
}
private String[] get101Tags() {
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
index adf46c0335d..9b9d1915615 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
@@ -83,6 +83,7 @@ public class RuleIndexerTest {
private final RuleIndexer underTest = new RuleIndexer(es.client(), dbClient);
private DbSession dbSession = dbTester.getSession();
private RuleDefinitionDto rule = new RuleDefinitionDto()
+ .setUuid("rule-uuid")
.setRuleKey("S001")
.setRepositoryKey("xoo")
.setConfigKey("S1")
@@ -108,7 +109,7 @@ public class RuleIndexerTest {
@Test
public void index() {
dbClient.ruleDao().insert(dbSession, rule);
- underTest.commitAndIndex(dbSession, rule.getId());
+ underTest.commitAndIndex(dbSession, rule.getUuid());
assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1);
}
@@ -118,12 +119,12 @@ public class RuleIndexerTest {
// Create and Index rule
dbClient.ruleDao().insert(dbSession, rule.setStatus(RuleStatus.READY));
dbSession.commit();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId());
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1);
// Remove rule
dbTester.getDbClient().ruleDao().update(dbTester.getSession(), rule.setStatus(RuleStatus.READY).setUpdatedAt(2000000000000L));
- underTest.commitAndIndex(dbTester.getSession(), rule.getId());
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1);
}
@@ -131,14 +132,14 @@ public class RuleIndexerTest {
@Test
public void index_rule_extension_with_long_id() {
RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setRuleKey(RuleTesting.randomRuleKeyOfMaximumLength()));
- underTest.commitAndIndex(dbTester.getSession(), rule.getId());
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
OrganizationDto organization = dbTester.organizations().insert();
RuleMetadataDto metadata = RuleTesting.newRuleMetadata(rule, organization).setTags(ImmutableSet.of("bla"));
dbTester.getDbClient().ruleDao().insertOrUpdate(dbTester.getSession(), metadata);
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
RuleExtensionDoc doc = new RuleExtensionDoc()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setScope(RuleExtensionScope.organization(organization.getUuid()));
assertThat(
es.client()
@@ -153,22 +154,22 @@ public class RuleIndexerTest {
@Test
public void delete_rule_extension_from_index_when_setting_rule_tags_to_empty() {
RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setRuleKey(RuleTesting.randomRuleKeyOfMaximumLength()));
- underTest.commitAndIndex(dbTester.getSession(), rule.getId());
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
OrganizationDto organization = dbTester.organizations().insert();
RuleMetadataDto metadata = RuleTesting.newRuleMetadata(rule, organization).setTags(ImmutableSet.of("bla"));
dbTester.getDbClient().ruleDao().insertOrUpdate(dbTester.getSession(), metadata);
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
// index tags
RuleExtensionDoc doc = new RuleExtensionDoc()
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setScope(RuleExtensionScope.organization(organization.getUuid()));
assertThat(es.getIds(TYPE_RULE_EXTENSION)).contains(doc.getId());
// update db table "rules_metadata" with empty tags and delete tags from index
metadata = RuleTesting.newRuleMetadata(rule, organization).setTags(emptySet());
dbTester.getDbClient().ruleDao().insertOrUpdate(dbTester.getSession(), metadata);
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(es.getIds(TYPE_RULE_EXTENSION)).doesNotContain(doc.getId());
}
@@ -176,7 +177,7 @@ public class RuleIndexerTest {
public void index_long_rule_description() {
String description = IntStream.range(0, 100000).map(i -> i % 100).mapToObj(Integer::toString).collect(joining(" "));
RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setDescription(description));
- underTest.commitAndIndex(dbTester.getSession(), rule.getId());
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1);
}
@@ -193,7 +194,7 @@ public class RuleIndexerTest {
.setSecurityStandards(standards)
.setDescription(VALID_HOTSPOT_RULE_DESCRIPTION));
OrganizationDto organization = dbTester.organizations().insert();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN).get(0))
@@ -229,7 +230,7 @@ public class RuleIndexerTest {
.setType(RuleType.SECURITY_HOTSPOT)
.setDescription(description));
OrganizationDto organization = dbTester.organizations().insert();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN).get(0))
@@ -252,7 +253,7 @@ public class RuleIndexerTest {
.setType(RuleType.SECURITY_HOTSPOT)
.setDescription(randomAlphabetic(30)));
OrganizationDto organization = dbTester.organizations().insert();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN).get(0))
@@ -269,7 +270,7 @@ public class RuleIndexerTest {
"<h2>Ask Yourself Whether</h2>\n" +
"foo"));
OrganizationDto organization = dbTester.organizations().insert();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN).get(0))
@@ -287,7 +288,7 @@ public class RuleIndexerTest {
"<h2>Recommended Secure Coding Practices</h2>\n" +
"foo"));
OrganizationDto organization = dbTester.organizations().insert();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN).get(0))
@@ -304,7 +305,7 @@ public class RuleIndexerTest {
"<h2>Recommended Secure Coding Practices</h2>\n" +
"foo"));
OrganizationDto organization = dbTester.organizations().insert();
- underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization);
+ underTest.commitAndIndex(dbTester.getSession(), rule.getUuid(), organization);
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN).get(0))
diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java
index 4bc01eb2118..fbe410e598f 100644
--- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java
+++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java
@@ -56,7 +56,7 @@ public class IssueDocTesting {
public static IssueDoc newDoc() {
IssueDoc doc = new IssueDoc(new HashMap<>());
doc.setKey(Uuids.createFast());
- doc.setRuleId(nextInt(1000));
+ doc.setRuleUuid(Uuids.createFast());
doc.setType(RuleType.CODE_SMELL);
doc.setAssigneeUuid("assignee_uuid_" + randomAlphabetic(26));
doc.setAuthorLogin("author_" + randomAlphabetic(5));
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java
index afa3e91a150..a866e16b168 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java
@@ -52,7 +52,7 @@ public interface QProfileRules {
*/
BulkChangeResult bulkActivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, @Nullable String severity);
- List<ActiveRuleChange> deactivateAndCommit(DbSession dbSession, QProfileDto profile, Collection<Integer> ruleIds);
+ List<ActiveRuleChange> deactivateAndCommit(DbSession dbSession, QProfileDto profile, Collection<String> ruleUuids);
BulkChangeResult bulkDeactivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery);
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/RuleActivation.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/RuleActivation.java
index 59905c5c3e8..e1fb91327a6 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/RuleActivation.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/RuleActivation.java
@@ -33,13 +33,13 @@ import org.sonar.api.rule.Severity;
@Immutable
public class RuleActivation {
- private final int ruleId;
+ private final String ruleUuid;
private final boolean reset;
private final String severity;
private final Map<String, String> parameters = new HashMap<>();
- private RuleActivation(int ruleId, boolean reset, @Nullable String severity, @Nullable Map<String, String> parameters) {
- this.ruleId = ruleId;
+ private RuleActivation(String ruleUuid, boolean reset, @Nullable String severity, @Nullable Map<String, String> parameters) {
+ this.ruleUuid = ruleUuid;
this.reset = reset;
this.severity = severity;
if (severity != null && !Severity.ALL.contains(severity)) {
@@ -52,16 +52,16 @@ public class RuleActivation {
}
}
- public static RuleActivation createReset(int ruleId) {
- return new RuleActivation(ruleId, true, null, null);
+ public static RuleActivation createReset(String ruleUuid) {
+ return new RuleActivation(ruleUuid, true, null, null);
}
- public static RuleActivation create(int ruleId, @Nullable String severity, @Nullable Map<String, String> parameters) {
- return new RuleActivation(ruleId, false, severity, parameters);
+ public static RuleActivation create(String ruleUuid, @Nullable String severity, @Nullable Map<String, String> parameters) {
+ return new RuleActivation(ruleUuid, false, severity, parameters);
}
- public static RuleActivation create(int ruleId) {
- return create(ruleId, null, null);
+ public static RuleActivation create(String ruleUuid) {
+ return create(ruleUuid, null, null);
}
/**
@@ -72,8 +72,8 @@ public class RuleActivation {
return severity;
}
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
@CheckForNull
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java
index 77b76b8b017..3d2a99abd97 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java
@@ -64,9 +64,9 @@ public class OrganisationSupport {
if (!organizationFlags.isEnabled(dbSession)) {
flagAdminUserAsRoot(dbSession, login);
createDefaultMembersGroup(dbSession, defaultOrganizationUuid);
- List<Integer> disabledTemplateAndCustomRuleIds = disableTemplateRulesAndCustomRules(dbSession);
+ List<String> disabledTemplateAndCustomRuleUuids = disableTemplateRulesAndCustomRules(dbSession);
enableFeature(dbSession);
- ruleIndexer.commitAndIndex(dbSession, disabledTemplateAndCustomRuleIds);
+ ruleIndexer.commitAndIndex(dbSession, disabledTemplateAndCustomRuleUuids);
}
}
}
@@ -109,7 +109,7 @@ public class OrganisationSupport {
permissionTemplateGroup.getTemplateUuid(), membersGroup.getUuid(), permissionTemplateGroup.getPermission()));
}
- private List<Integer> disableTemplateRulesAndCustomRules(DbSession dbSession) {
+ private List<String> disableTemplateRulesAndCustomRules(DbSession dbSession) {
List<RuleDefinitionDto> rules = dbClient.ruleDao().selectAllDefinitions(dbSession).stream()
.filter(r -> r.isTemplate() || r.isCustomRule())
.collect(toList());
@@ -117,7 +117,7 @@ public class OrganisationSupport {
r.setStatus(RuleStatus.REMOVED);
dbClient.ruleDao().update(dbSession, r);
});
- return rules.stream().map(RuleDefinitionDto::getId).collect(toList());
+ return rules.stream().map(RuleDefinitionDto::getUuid).collect(toList());
}
private void enableFeature(DbSession dbSession) {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfile.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfile.java
index de0863b7eb1..b38ffdc255d 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfile.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfile.java
@@ -67,24 +67,24 @@ public final class BuiltInQProfile {
}
static final class ActiveRule {
- private final int ruleId;
+ private final String ruleUuid;
private final RuleKey ruleKey;
private final String severity;
private final List<OverriddenParam> params;
- ActiveRule(int ruleId, BuiltInActiveRule builtIn) {
- this(ruleId, RuleKey.of(builtIn.repoKey(), builtIn.ruleKey()), builtIn.overriddenSeverity(), builtIn.overriddenParams());
+ ActiveRule(String ruleUuid, BuiltInActiveRule builtIn) {
+ this(ruleUuid, RuleKey.of(builtIn.repoKey(), builtIn.ruleKey()), builtIn.overriddenSeverity(), builtIn.overriddenParams());
}
- ActiveRule(int ruleId, RuleKey ruleKey, @Nullable String severity, List<OverriddenParam> params) {
- this.ruleId = ruleId;
+ ActiveRule(String ruleUuid, RuleKey ruleKey, @Nullable String severity, List<OverriddenParam> params) {
+ this.ruleUuid = ruleUuid;
this.ruleKey = ruleKey;
this.severity = severity;
this.params = params;
}
- public int getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
public RuleKey getRuleKey() {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
index 3f5cc01fd2a..ceebfeff22e 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
@@ -146,7 +146,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
ActiveRuleDto dto = new ActiveRuleDto();
dto.setProfileUuid(rulesProfileDto.getUuid());
- dto.setRuleId(ruleDefinitionDto.getId());
+ dto.setRuleUuid(ruleDefinitionDto.getUuid());
dto.setKey(ActiveRuleKey.of(rulesProfileDto, ruleDefinitionDto.getKey()));
dto.setSeverity(firstNonNull(activeRule.getSeverity(), ruleDefinitionDto.getSeverityString()));
dto.setUpdatedAt(now);
@@ -187,7 +187,6 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
return paramDto;
}
- @CheckForNull
private String validateParam(RuleParamDto ruleParam, String value) {
RuleParamType ruleParamType = RuleParamType.parse(ruleParam.getType());
if (ruleParamType.multiple()) {
@@ -207,13 +206,13 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
this.definitions = dbClient.ruleDao().selectAllDefinitions(session)
.stream()
.collect(Collectors.toMap(RuleDefinitionDto::getKey, Function.identity()));
- Map<Integer, RuleKey> ruleIdsByKey = definitions.values()
+ Map<String, RuleKey> ruleUuidsByKey = definitions.values()
.stream()
- .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getId, RuleDefinitionDto::getKey));
- this.params = new HashMap<>(ruleIdsByKey.size());
+ .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getUuid, RuleDefinitionDto::getKey));
+ this.params = new HashMap<>(ruleUuidsByKey.size());
dbClient.ruleDao().selectRuleParamsByRuleKeys(session, definitions.keySet())
.forEach(ruleParam -> params.compute(
- ruleIdsByKey.get(ruleParam.getRuleId()),
+ ruleUuidsByKey.get(ruleParam.getRuleUuid()),
(key, value) -> {
if (value == null) {
return ImmutableSet.of(ruleParam);
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImpl.java
index f1b07877384..98b43530104 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImpl.java
@@ -142,12 +142,12 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository
private Map<RuleKey, RuleDefinitionDto> loadRuleDefinitionsByRuleKey() {
try (DbSession dbSession = dbClient.openSession(false)) {
List<RuleDefinitionDto> ruleDefinitions = dbClient.ruleDao().selectAllDefinitions(dbSession);
- Multimap<Integer, DeprecatedRuleKeyDto> deprecatedRuleKeysByRuleId = dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream()
- .collect(MoreCollectors.index(DeprecatedRuleKeyDto::getRuleId));
+ Multimap<String, DeprecatedRuleKeyDto> deprecatedRuleKeysByRuleId = dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream()
+ .collect(MoreCollectors.index(DeprecatedRuleKeyDto::getRuleUuid));
Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = new HashMap<>();
for (RuleDefinitionDto ruleDefinition : ruleDefinitions) {
rulesByRuleKey.put(ruleDefinition.getKey(), ruleDefinition);
- deprecatedRuleKeysByRuleId.get(ruleDefinition.getId()).forEach(t -> rulesByRuleKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), ruleDefinition));
+ deprecatedRuleKeysByRuleId.get(ruleDefinition.getUuid()).forEach(t -> rulesByRuleKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), ruleDefinition));
}
return rulesByRuleKey;
}
@@ -198,7 +198,7 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository
RuleKey ruleKey = RuleKey.of(builtInActiveRule.repoKey(), builtInActiveRule.ruleKey());
RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey);
checkState(ruleDefinition != null, "Rule with key '%s' not found", ruleKey);
- builder.addRule(new BuiltInQProfile.ActiveRule(ruleDefinition.getId(), ruleDefinition.getKey(),
+ builder.addRule(new BuiltInQProfile.ActiveRule(ruleDefinition.getUuid(), ruleDefinition.getKey(),
builtInActiveRule.overriddenSeverity(), builtInActiveRule.overriddenParams()));
});
return builder;
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImpl.java
index 4668b42c99d..326a05e2356 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImpl.java
@@ -49,32 +49,32 @@ public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
public List<ActiveRuleChange> update(DbSession dbSession, BuiltInQProfile builtInDefinition, RulesProfileDto initialRuleProfile) {
// Keep reference to all the activated rules before update
- Set<Integer> deactivatedRuleIds = dbClient.activeRuleDao().selectByRuleProfile(dbSession, initialRuleProfile)
+ Set<String> deactivatedRuleUuids = dbClient.activeRuleDao().selectByRuleProfile(dbSession, initialRuleProfile)
.stream()
- .map(ActiveRuleDto::getRuleId)
+ .map(ActiveRuleDto::getRuleUuid)
.collect(MoreCollectors.toHashSet());
// all rules, including those which are removed from built-in profile
- Set<Integer> ruleIds = Stream.concat(
- deactivatedRuleIds.stream(),
- builtInDefinition.getActiveRules().stream().map(BuiltInQProfile.ActiveRule::getRuleId))
+ Set<String> ruleUuids = Stream.concat(
+ deactivatedRuleUuids.stream(),
+ builtInDefinition.getActiveRules().stream().map(BuiltInQProfile.ActiveRule::getRuleUuid))
.collect(toSet());
Collection<RuleActivation> activations = new ArrayList<>();
for (BuiltInQProfile.ActiveRule ar : builtInDefinition.getActiveRules()) {
RuleActivation activation = convert(ar);
activations.add(activation);
- deactivatedRuleIds.remove(activation.getRuleId());
+ deactivatedRuleUuids.remove(activation.getRuleUuid());
}
- RuleActivationContext context = ruleActivator.createContextForBuiltInProfile(dbSession, initialRuleProfile, ruleIds);
+ RuleActivationContext context = ruleActivator.createContextForBuiltInProfile(dbSession, initialRuleProfile, ruleUuids);
List<ActiveRuleChange> changes = new ArrayList<>();
for (RuleActivation activation : activations) {
changes.addAll(ruleActivator.activate(dbSession, activation, context));
}
// these rules are no longer part of the built-in profile
- deactivatedRuleIds.forEach(ruleKey -> changes.addAll(ruleActivator.deactivate(dbSession, context, ruleKey, false)));
+ deactivatedRuleUuids.forEach(ruleUuid -> changes.addAll(ruleActivator.deactivate(dbSession, context, ruleUuid, false)));
activeRuleIndexer.commitAndIndex(dbSession, changes);
return changes;
@@ -83,7 +83,7 @@ public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
private static RuleActivation convert(BuiltInQProfile.ActiveRule ar) {
Map<String, String> params = ar.getParams().stream()
.collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
- return RuleActivation.create(ar.getRuleId(), ar.getSeverity(), params);
+ return RuleActivation.create(ar.getRuleUuid(), ar.getSeverity(), params);
}
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/DescendantProfilesSupplier.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/DescendantProfilesSupplier.java
index 9f803c3106f..4b35efdc5db 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/DescendantProfilesSupplier.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/DescendantProfilesSupplier.java
@@ -27,7 +27,7 @@ import org.sonar.db.qualityprofile.QProfileDto;
@FunctionalInterface
public interface DescendantProfilesSupplier {
- Result get(Collection<QProfileDto> profiles, Collection<Integer> ruleIds);
+ Result get(Collection<QProfileDto> profiles, Collection<String> ruleUuids);
final class Result {
private final Collection<QProfileDto> profiles;
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java
index 169eada1b8a..0a81f77350c 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java
@@ -61,7 +61,7 @@ class RuleActivationContext {
private final ListMultimap<String, QProfileDto> profilesByParentUuid = ArrayListMultimap.create();
// The rules/active rules involved in the group of activations/de-activations
- private final Map<Integer, RuleWrapper> rulesById = new HashMap<>();
+ private final Map<String, RuleWrapper> rulesByUuid = new HashMap<>();
private final Map<ActiveRuleKey, ActiveRuleWrapper> activeRulesByKey = new HashMap<>();
// Cursors used to move in the rules and in the tree of profiles.
@@ -81,10 +81,10 @@ class RuleActivationContext {
this.date = builder.date;
this.descendantProfilesSupplier = builder.descendantProfilesSupplier;
- ListMultimap<Integer, RuleParamDto> paramsByRuleId = builder.ruleParams.stream().collect(index(RuleParamDto::getRuleId));
+ ListMultimap<String, RuleParamDto> paramsByRuleId = builder.ruleParams.stream().collect(index(RuleParamDto::getRuleUuid));
for (RuleDefinitionDto rule : builder.rules) {
- RuleWrapper wrapper = new RuleWrapper(rule, paramsByRuleId.get(rule.getId()));
- rulesById.put(rule.getId(), wrapper);
+ RuleWrapper wrapper = new RuleWrapper(rule, paramsByRuleId.get(rule.getUuid()));
+ rulesByUuid.put(rule.getUuid(), wrapper);
}
this.baseRulesProfile = builder.baseRulesProfile;
@@ -195,7 +195,7 @@ class RuleActivationContext {
Collection<QProfileDto> baseProfiles = profilesByUuid.values().stream()
.filter(p -> p.getRulesProfileUuid().equals(baseRulesProfile.getUuid()))
.collect(toArrayList(profilesByUuid.size()));
- DescendantProfilesSupplier.Result result = descendantProfilesSupplier.get(baseProfiles, rulesById.keySet());
+ DescendantProfilesSupplier.Result result = descendantProfilesSupplier.get(baseProfiles, rulesByUuid.keySet());
register(result.getProfiles());
register(result.getActiveRules(), result.getActiveRuleParams());
descendantsLoaded = true;
@@ -204,8 +204,8 @@ class RuleActivationContext {
/**
* Move the cursor to the given rule and back to the base profile.
*/
- public void reset(int ruleId) {
- doSwitch(this.baseRulesProfile, ruleId);
+ public void reset(String ruleUuid) {
+ doSwitch(this.baseRulesProfile, ruleUuid);
}
/**
@@ -216,12 +216,12 @@ class RuleActivationContext {
QProfileDto qp = requireNonNull(this.profilesByUuid.get(to.getKee()), () -> "No profile with uuid " + to.getKee());
RulesProfileDto ruleProfile = RulesProfileDto.from(qp);
- doSwitch(ruleProfile, getRule().get().getId());
+ doSwitch(ruleProfile, getRule().get().getUuid());
}
- private void doSwitch(RulesProfileDto ruleProfile, int ruleId) {
- this.currentRule = rulesById.get(ruleId);
- checkRequest(this.currentRule != null, "Rule with ID %s not found", ruleId);
+ private void doSwitch(RulesProfileDto ruleProfile, String ruleUuid) {
+ this.currentRule = rulesByUuid.get(ruleUuid);
+ checkRequest(this.currentRule != null, "Rule with UUID %s not found", ruleUuid);
RuleKey ruleKey = currentRule.get().getKey();
checkRequest(ruleProfile.getLanguage().equals(currentRule.get().getLanguage()),
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
index be862460f9e..f79eb22d382 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
@@ -73,7 +73,7 @@ public class RuleActivator {
}
public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, RuleActivationContext context) {
- context.reset(activation.getRuleId());
+ context.reset(activation.getRuleUuid());
return doActivate(dbSession, activation, context);
}
@@ -200,10 +200,10 @@ public class RuleActivator {
String activeRuleValue = activeRule == null ? null : activeRule.getParamValue(paramKey);
paramValue = context.hasRequestedParamValue(request, paramKey) ?
// If the request contains the parameter then we're using either value from request, or parent value, or default value
- firstNonNull(
- context.getRequestedParamValue(request, paramKey),
- parentValue,
- rule.getParamDefaultValue(paramKey))
+ firstNonNull(
+ context.getRequestedParamValue(request, paramKey),
+ parentValue,
+ rule.getParamDefaultValue(paramKey))
// If the request doesn't contain the parameter, then we're using either value in DB, or parent value, or default value
: firstNonNull(
activeRuleValue,
@@ -247,7 +247,7 @@ public class RuleActivator {
ActiveRuleDto activeRule = new ActiveRuleDto();
activeRule.setProfileUuid(context.getRulesProfile().getUuid());
- activeRule.setRuleId(rule.get().getId());
+ activeRule.setRuleUuid(rule.get().getUuid());
activeRule.setKey(ActiveRuleKey.of(context.getRulesProfile(), rule.get().getKey()));
String severity = change.getSeverity();
if (severity != null) {
@@ -308,8 +308,8 @@ public class RuleActivator {
return activeRule.get();
}
- public List<ActiveRuleChange> deactivate(DbSession dbSession, RuleActivationContext context, int ruleId, boolean force) {
- context.reset(ruleId);
+ public List<ActiveRuleChange> deactivate(DbSession dbSession, RuleActivationContext context, String ruleUuid, boolean force) {
+ context.reset(ruleUuid);
return doDeactivate(dbSession, context, force);
}
@@ -353,14 +353,14 @@ public class RuleActivator {
return value;
}
- public RuleActivationContext createContextForBuiltInProfile(DbSession dbSession, RulesProfileDto builtInProfile, Collection<Integer> ruleIds) {
+ public RuleActivationContext createContextForBuiltInProfile(DbSession dbSession, RulesProfileDto builtInProfile, Collection<String> ruleUuids) {
checkArgument(builtInProfile.isBuiltIn(), "Rules profile with UUID %s is not built-in", builtInProfile.getUuid());
RuleActivationContext.Builder builder = new RuleActivationContext.Builder();
builder.setDescendantProfilesSupplier(createDescendantProfilesSupplier(dbSession));
// load rules
- completeWithRules(dbSession, builder, ruleIds);
+ completeWithRules(dbSession, builder, ruleUuids);
// load org profiles. Their parents are null by nature.
List<QProfileDto> profiles = db.qualityProfileDao().selectQProfilesByRuleProfile(dbSession, builtInProfile);
@@ -371,17 +371,17 @@ public class RuleActivator {
Collection<String> ruleProfileUuids = Stream
.concat(Stream.of(builtInProfile.getUuid()), profiles.stream().map(QProfileDto::getRulesProfileUuid))
.collect(MoreCollectors.toHashSet(profiles.size() + 1));
- completeWithActiveRules(dbSession, builder, ruleIds, ruleProfileUuids);
+ completeWithActiveRules(dbSession, builder, ruleUuids, ruleProfileUuids);
return builder.build();
}
- public RuleActivationContext createContextForUserProfile(DbSession dbSession, QProfileDto profile, Collection<Integer> ruleIds) {
+ public RuleActivationContext createContextForUserProfile(DbSession dbSession, QProfileDto profile, Collection<String> ruleUuids) {
checkArgument(!profile.isBuiltIn(), "Profile with UUID %s is built-in", profile.getKee());
RuleActivationContext.Builder builder = new RuleActivationContext.Builder();
builder.setDescendantProfilesSupplier(createDescendantProfilesSupplier(dbSession));
// load rules
- completeWithRules(dbSession, builder, ruleIds);
+ completeWithRules(dbSession, builder, ruleUuids);
// load profiles
List<QProfileDto> profiles = new ArrayList<>();
@@ -396,32 +396,32 @@ public class RuleActivator {
Collection<String> ruleProfileUuids = profiles.stream()
.map(QProfileDto::getRulesProfileUuid)
.collect(MoreCollectors.toHashSet(profiles.size()));
- completeWithActiveRules(dbSession, builder, ruleIds, ruleProfileUuids);
+ completeWithActiveRules(dbSession, builder, ruleUuids, ruleProfileUuids);
return builder.build();
}
DescendantProfilesSupplier createDescendantProfilesSupplier(DbSession dbSession) {
- return (parents, ruleIds) -> {
+ return (parents, ruleUuids) -> {
Collection<QProfileDto> profiles = db.qualityProfileDao().selectDescendants(dbSession, parents);
Set<String> ruleProfileUuids = profiles.stream()
.map(QProfileDto::getRulesProfileUuid)
.collect(MoreCollectors.toHashSet());
- Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids);
+ Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleUuids, ruleProfileUuids);
List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size()));
List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
return new DescendantProfilesSupplier.Result(profiles, activeRules, activeRuleParams);
};
}
- private void completeWithRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection<Integer> ruleIds) {
- List<RuleDefinitionDto> rules = db.ruleDao().selectDefinitionByIds(dbSession, ruleIds);
+ private void completeWithRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection<String> ruleUuids) {
+ List<RuleDefinitionDto> rules = db.ruleDao().selectDefinitionByUuids(dbSession, ruleUuids);
builder.setRules(rules);
- builder.setRuleParams(db.ruleDao().selectRuleParamsByRuleIds(dbSession, ruleIds));
+ builder.setRuleParams(db.ruleDao().selectRuleParamsByRuleUuids(dbSession, ruleUuids));
}
- private void completeWithActiveRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection<Integer> ruleIds, Collection<String> ruleProfileUuids) {
- Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleIds, ruleProfileUuids);
+ private void completeWithActiveRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection<String> ruleUuids, Collection<String> ruleProfileUuids) {
+ Collection<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRulesAndRuleProfileUuids(dbSession, ruleUuids, ruleProfileUuids);
builder.setActiveRules(activeRules);
List<String> activeRuleUuids = activeRules.stream().map(ActiveRuleDto::getUuid).collect(MoreCollectors.toArrayList(activeRules.size()));
builder.setActiveRuleParams(db.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids));
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java
index b90e0c0c255..919c7daab07 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java
@@ -150,7 +150,7 @@ public class OrganisationSupportTest {
public void enabling_organizations_should_remove_template_rule_and_custom_rule() {
RuleDefinitionDto normal = dbTester.rules().insert();
RuleDefinitionDto template = dbTester.rules().insert(r -> r.setIsTemplate(true));
- RuleDefinitionDto custom = dbTester.rules().insert(r -> r.setTemplateId(template.getId()));
+ RuleDefinitionDto custom = dbTester.rules().insert(r -> r.setTemplateUuid(template.getUuid()));
UserDto user = dbTester.users().insertUser();
dbTester.users().insertDefaultGroup(dbTester.getDefaultOrganization(), "sonar-users");
@@ -172,10 +172,10 @@ public class OrganisationSupportTest {
tuple(custom.getKey(), RuleStatus.REMOVED));
@SuppressWarnings("unchecked")
- Class<ArrayList<Integer>> listClass = (Class<ArrayList<Integer>>) (Class) ArrayList.class;
- ArgumentCaptor<ArrayList<Integer>> indexedRuleKeys = ArgumentCaptor.forClass(listClass);
+ Class<ArrayList<String>> listClass = (Class<ArrayList<String>>) (Class) ArrayList.class;
+ ArgumentCaptor<ArrayList<String>> indexedRuleKeys = ArgumentCaptor.forClass(listClass);
verify(ruleIndexer).commitAndIndex(any(), indexedRuleKeys.capture());
- assertThat(indexedRuleKeys.getValue()).containsExactlyInAnyOrder(template.getId(), custom.getId());
+ assertThat(indexedRuleKeys.getValue()).containsExactlyInAnyOrder(template.getUuid(), custom.getUuid());
}
@Test
@@ -216,5 +216,4 @@ public class OrganisationSupportTest {
dbTester.rootFlag().verify(user.getLogin(), root);
}
-
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java
index 91a99f264c1..1d49048f134 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java
@@ -175,7 +175,7 @@ public class BuiltInQProfileInsertImplTest {
assertThat(activeRule.getUuid()).isNotNull();
assertThat(activeRule.getInheritance()).isNull();
assertThat(activeRule.doesOverride()).isFalse();
- assertThat(activeRule.getRuleId()).isEqualTo(rule.getId());
+ assertThat(activeRule.getRuleUuid()).isEqualTo(rule.getUuid());
assertThat(activeRule.getProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getCreatedAt()).isPositive();
@@ -186,7 +186,7 @@ public class BuiltInQProfileInsertImplTest {
QProfileChangeQuery changeQuery = new QProfileChangeQuery(profile.getKee());
QProfileChangeDto change = db.getDbClient().qProfileChangeDao().selectByQuery(dbSession, changeQuery).stream()
- .filter(c -> c.getDataAsMap().get("ruleId").equals(String.valueOf(rule.getId())))
+ .filter(c -> c.getDataAsMap().get("ruleUuid").equals(rule.getUuid()))
.findFirst()
.get();
assertThat(change.getChangeType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED.name());
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImplTest.java
index bd478b69c54..4b0db8c0cc2 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImplTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryImplTest.java
@@ -57,7 +57,7 @@ public class BuiltInQProfileRepositoryImplTest {
public void create_qprofile_with_rule() {
RuleDefinitionDto rule1 = db.rules().insert();
RuleDefinitionDto rule2 = db.rules().insert();
- RuleDefinitionDto ruleNotToBeActivated = db.rules().insert();
+ db.rules().insert();
List<DummyProfileDefinition> definitions = singletonList(new DummyProfileDefinition("foo", "foo", false,
asList(rule1.getKey(), rule2.getKey())));
BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl(dbClient, new Languages(FOO_LANGUAGE), definitions.toArray(new BuiltInQualityProfilesDefinition[0]));
@@ -68,11 +68,10 @@ public class BuiltInQProfileRepositoryImplTest {
.extracting(BuiltInQProfile::getName)
.containsExactlyInAnyOrder("foo");
assertThat(underTest.get().get(0).getActiveRules())
- .extracting(ActiveRule::getRuleId, ActiveRule::getRuleKey)
+ .extracting(ActiveRule::getRuleUuid, ActiveRule::getRuleKey)
.containsExactlyInAnyOrder(
- tuple(rule1.getId(), rule1.getKey()),
- tuple(rule2.getId(), rule2.getKey())
- );
+ tuple(rule1.getUuid(), rule1.getKey()),
+ tuple(rule2.getUuid(), rule2.getKey()));
}
@Test
@@ -171,7 +170,7 @@ public class BuiltInQProfileRepositoryImplTest {
@Test
public void create_qprofile_with_deprecated_rule() {
RuleDefinitionDto rule1 = db.rules().insert();
- db.rules().insertDeprecatedKey(d -> d.setRuleId(rule1.getId()).setOldRepositoryKey("oldRepo").setOldRuleKey("oldKey"));
+ db.rules().insertDeprecatedKey(d -> d.setRuleUuid(rule1.getUuid()).setOldRepositoryKey("oldRepo").setOldRuleKey("oldKey"));
RuleDefinitionDto rule2 = db.rules().insert();
List<DummyProfileDefinition> definitions = singletonList(new DummyProfileDefinition("foo", "foo", false,
asList(RuleKey.of("oldRepo", "oldKey"), rule2.getKey())));
@@ -183,11 +182,10 @@ public class BuiltInQProfileRepositoryImplTest {
.extracting(BuiltInQProfile::getName)
.containsExactlyInAnyOrder("foo");
assertThat(underTest.get().get(0).getActiveRules())
- .extracting(ActiveRule::getRuleId, ActiveRule::getRuleKey)
+ .extracting(ActiveRule::getRuleUuid, ActiveRule::getRuleKey)
.containsExactlyInAnyOrder(
- tuple(rule1.getId(), rule1.getKey()),
- tuple(rule2.getId(), rule2.getKey())
- );
+ tuple(rule1.getUuid(), rule1.getKey()),
+ tuple(rule2.getUuid(), rule2.getKey()));
}
@Test
@@ -263,7 +261,7 @@ public class BuiltInQProfileRepositoryImplTest {
@Override
public void define(Context context) {
NewBuiltInQualityProfile builtInQualityProfile = context.createBuiltInQualityProfile(name, language);
- activeRuleKeys.stream().forEach(activeRuleKey -> builtInQualityProfile.activateRule(activeRuleKey.repository(), activeRuleKey.rule()));
+ activeRuleKeys.forEach(activeRuleKey -> builtInQualityProfile.activateRule(activeRuleKey.repository(), activeRuleKey.rule()));
builtInQualityProfile.setDefault(defaultProfile);
builtInQualityProfile.done();
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java
index c4184597696..09741edd18c 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java
@@ -404,7 +404,8 @@ public class BuiltInQProfileUpdateImplTest {
}
private void assertThatRuleIsDeactivated(QProfileDto profile, RuleDefinitionDto rule) {
- Collection<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRulesAndRuleProfileUuids(db.getSession(), singletonList(rule.getId()), singletonList(profile.getRulesProfileUuid()));
+ Collection<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRulesAndRuleProfileUuids(
+ db.getSession(), singletonList(rule.getUuid()), singletonList(profile.getRulesProfileUuid()));
assertThat(activeRules).isEmpty();
}
@@ -440,7 +441,7 @@ public class BuiltInQProfileUpdateImplTest {
ActiveRuleDto dto = new ActiveRuleDto()
.setProfileUuid(profile.getUuid())
.setSeverity(severity.name())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setCreatedAt(PAST)
.setUpdatedAt(PAST);
db.getDbClient().activeRuleDao().insert(db.getSession(), dto);
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesUpdateListenerTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesUpdateListenerTest.java
index f6736b112aa..86210a4f4b8 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesUpdateListenerTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesUpdateListenerTest.java
@@ -21,7 +21,6 @@ package org.sonar.server.qualityprofile;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
-import java.util.Random;
import org.assertj.core.groups.Tuple;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -29,6 +28,7 @@ import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.notifications.Notification;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
+import org.sonar.core.util.Uuids;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.notification.NotificationManager;
@@ -161,15 +161,15 @@ public class BuiltInQualityProfilesUpdateListenerTest {
private Tuple addProfile(Multimap<QProfileName, ActiveRuleChange> profiles, Languages languages, ActiveRuleChange.Type type) {
String profileName = randomLowerCaseText();
- int ruleId1 = new Random().nextInt(952);
- int ruleId2 = new Random().nextInt(952);
+ String ruleUuid1 = Uuids.createFast();
+ String ruleUuid2 = Uuids.createFast();
Language language = newLanguage(randomLowerCaseText(), randomLowerCaseText());
languages.add(language);
profiles.putAll(new QProfileName(language.getKey(), profileName),
asList(new ActiveRuleChange(
type,
- ActiveRuleKey.parse("qp:repo:rule1"), new RuleDefinitionDto().setId(ruleId1)),
- new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule2"), new RuleDefinitionDto().setId(ruleId2))));
+ ActiveRuleKey.parse("qp:repo:rule1"), new RuleDefinitionDto().setUuid(ruleUuid1)),
+ new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule2"), new RuleDefinitionDto().setUuid(ruleUuid2))));
return tuple(profileName, language.getKey(), language.getName(), 2);
}
diff --git a/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryRule.java b/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryRule.java
index 282b609055f..aa3afce6964 100644
--- a/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryRule.java
+++ b/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/qualityprofile/BuiltInQProfileRepositoryRule.java
@@ -95,7 +95,7 @@ public class BuiltInQProfileRepositoryRule extends ExternalResource implements B
RuleKey ruleKey = RuleKey.of(rule.repoKey(), rule.ruleKey());
RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey);
Preconditions.checkState(ruleDefinition != null, "Rule '%s' not found", ruleKey);
- builder.addRule(new BuiltInQProfile.ActiveRule(ruleDefinition.getId(), rule));
+ builder.addRule(new BuiltInQProfile.ActiveRule(ruleDefinition.getUuid(), rule));
});
return builder
.build();
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
index 1916f4eb649..703da4070b7 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
@@ -29,7 +29,9 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.rule.RuleKey;
@@ -54,49 +56,41 @@ import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
* A {@link RuleFinder} implementation that retrieves all rule definitions and their parameter when instantiated, cache
* them in memory and provide implementation of {@link RuleFinder}'s method which only read from this data in memory.
*/
-public class CachingRuleFinder implements RuleFinder {
+public class CachingRuleFinder implements ServerRuleFinder {
private static final Ordering<Map.Entry<RuleDefinitionDto, Rule>> FIND_BY_QUERY_ORDER = Ordering.natural().reverse().onResultOf(entry -> entry.getKey().getUpdatedAt());
+ private final Map<RuleKey, RuleDefinitionDto> ruleDtosByKey;
private final Map<RuleDefinitionDto, Rule> rulesByRuleDefinition;
- private final Map<Integer, Rule> rulesById;
private final Map<RuleKey, Rule> rulesByKey;
public CachingRuleFinder(DbClient dbClient) {
try (DbSession dbSession = dbClient.openSession(false)) {
- this.rulesByRuleDefinition = buildRulesByRuleDefinitionDto(dbClient, dbSession);
- this.rulesById = this.rulesByRuleDefinition.entrySet().stream()
- .collect(uniqueIndex(entry -> entry.getKey().getId(), Map.Entry::getValue));
+ List<RuleDefinitionDto> dtos = dbClient.ruleDao().selectAllDefinitions(dbSession);
+ this.ruleDtosByKey = dtos.stream().collect(Collectors.toMap(RuleDefinitionDto::getKey, d -> d));
+ this.rulesByRuleDefinition = buildRulesByRuleDefinitionDto(dbClient, dbSession, dtos);
this.rulesByKey = this.rulesByRuleDefinition.entrySet().stream()
.collect(uniqueIndex(entry -> entry.getKey().getKey(), Map.Entry::getValue));
}
}
- private static Map<RuleDefinitionDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession) {
- List<RuleDefinitionDto> dtos = dbClient.ruleDao().selectAllDefinitions(dbSession);
+ private static Map<RuleDefinitionDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List<RuleDefinitionDto> dtos) {
Set<RuleKey> ruleKeys = dtos.stream().map(RuleDefinitionDto::getKey).collect(toSet(dtos.size()));
- ListMultimap<Integer, RuleParamDto> ruleParamsByRuleId = retrieveRuleParameters(dbClient, dbSession, ruleKeys);
+ ListMultimap<String, RuleParamDto> ruleParamsByRuleUuid = retrieveRuleParameters(dbClient, dbSession, ruleKeys);
Map<RuleDefinitionDto, Rule> rulesByDefinition = new HashMap<>(dtos.size());
for (RuleDefinitionDto definition : dtos) {
- rulesByDefinition.put(definition, toRule(definition, ruleParamsByRuleId.get(definition.getId())));
+ rulesByDefinition.put(definition, toRule(definition, ruleParamsByRuleUuid.get(definition.getUuid())));
}
return ImmutableMap.copyOf(rulesByDefinition);
}
- private static ImmutableListMultimap<Integer, RuleParamDto> retrieveRuleParameters(DbClient dbClient, DbSession dbSession, Set<RuleKey> ruleKeys) {
+ private static ImmutableListMultimap<String, RuleParamDto> retrieveRuleParameters(DbClient dbClient, DbSession dbSession, Set<RuleKey> ruleKeys) {
if (ruleKeys.isEmpty()) {
return ImmutableListMultimap.of();
}
return dbClient.ruleDao().selectRuleParamsByRuleKeys(dbSession, ruleKeys)
.stream()
- .collect(MoreCollectors.index(RuleParamDto::getRuleId));
- }
-
- @Override
- @Deprecated
- @CheckForNull
- public Rule findById(int ruleId) {
- return rulesById.get(ruleId);
+ .collect(MoreCollectors.index(RuleParamDto::getRuleUuid));
}
@Override
@@ -175,8 +169,7 @@ public class CachingRuleFinder implements RuleFinder {
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(ruleDefinition.getStatus().name())
.setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
- .setTags(new String[0])
- .setId(ruleDefinition.getId());
+ .setTags(new String[0]);
if (description != null && descriptionFormat != null) {
if (RuleDto.Format.HTML.equals(descriptionFormat)) {
apiRule.setDescription(description);
@@ -194,4 +187,9 @@ public class CachingRuleFinder implements RuleFinder {
return apiRule;
}
+
+ @Override
+ public Optional<RuleDefinitionDto> findDtoByKey(RuleKey key) {
+ return Optional.ofNullable(this.ruleDtosByKey.get(key));
+ }
}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
index 232778f3572..1a70591f2ff 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -142,7 +142,7 @@ public class RegisterRules implements Startable {
persistRepositories(dbSession, ruleDefinitionContext.repositories());
// FIXME lack of resiliency, active rules index is corrupted if rule index fails
// to be updated. Only a single DB commit should be executed.
- ruleIndexer.commitAndIndex(dbSession, registerRulesContext.getAllModified().map(RuleDefinitionDto::getId).collect(toSet()));
+ ruleIndexer.commitAndIndex(dbSession, registerRulesContext.getAllModified().map(RuleDefinitionDto::getUuid).collect(toSet()));
activeRuleIndexer.commitAndIndex(dbSession, changes);
registerRulesContext.getRenamed().forEach(e -> LOG.info("Rule {} re-keyed to {}", e.getValue(), e.getKey().getKey()));
profiler.stopDebug();
@@ -171,14 +171,14 @@ public class RegisterRules implements Startable {
private RegisterRulesContext createRegisterRulesContext(DbSession dbSession) {
Map<RuleKey, RuleDefinitionDto> allRules = dbClient.ruleDao().selectAllDefinitions(dbSession).stream()
.collect(uniqueIndex(RuleDefinitionDto::getKey));
- Map<Integer, Set<SingleDeprecatedRuleKey>> existingDeprecatedKeysById = loadDeprecatedRuleKeys(dbSession);
+ Map<String, Set<SingleDeprecatedRuleKey>> existingDeprecatedKeysById = loadDeprecatedRuleKeys(dbSession);
return new RegisterRulesContext(allRules, existingDeprecatedKeysById);
}
- private Map<Integer, Set<SingleDeprecatedRuleKey>> loadDeprecatedRuleKeys(DbSession dbSession) {
+ private Map<String, Set<SingleDeprecatedRuleKey>> loadDeprecatedRuleKeys(DbSession dbSession) {
return dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream()
.map(SingleDeprecatedRuleKey::from)
- .collect(Collectors.groupingBy(SingleDeprecatedRuleKey::getRuleId, Collectors.toSet()));
+ .collect(Collectors.groupingBy(SingleDeprecatedRuleKey::getRuleUuid, Collectors.toSet()));
}
private static boolean noTemplateRuleWithOrganizationsEnabled(RegisterRulesContext registerRulesContext, boolean orgsEnabled, RulesDefinition.Rule ruleDef) {
@@ -201,7 +201,7 @@ public class RegisterRules implements Startable {
// initial immutable data
private final Map<RuleKey, RuleDefinitionDto> dbRules;
private final Set<RuleDefinitionDto> known;
- private final Map<Integer, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysById;
+ private final Map<String, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysByUuid;
private final Map<RuleKey, RuleDefinitionDto> dbRulesByDbDeprecatedKey;
// mutable data
private final Set<RuleDefinitionDto> created = new HashSet<>();
@@ -210,26 +210,26 @@ public class RegisterRules implements Startable {
private final Set<RuleDefinitionDto> unchanged = new HashSet<>();
private final Set<RuleDefinitionDto> removed = new HashSet<>();
- private RegisterRulesContext(Map<RuleKey, RuleDefinitionDto> dbRules, Map<Integer, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysById) {
+ private RegisterRulesContext(Map<RuleKey, RuleDefinitionDto> dbRules, Map<String, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysByUuid) {
this.dbRules = ImmutableMap.copyOf(dbRules);
this.known = ImmutableSet.copyOf(dbRules.values());
- this.dbDeprecatedKeysById = dbDeprecatedKeysById;
- this.dbRulesByDbDeprecatedKey = buildDbRulesByDbDeprecatedKey(dbDeprecatedKeysById, dbRules);
+ this.dbDeprecatedKeysByUuid = dbDeprecatedKeysByUuid;
+ this.dbRulesByDbDeprecatedKey = buildDbRulesByDbDeprecatedKey(dbDeprecatedKeysByUuid, dbRules);
}
- private static Map<RuleKey, RuleDefinitionDto> buildDbRulesByDbDeprecatedKey(Map<Integer, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysById,
+ private static Map<RuleKey, RuleDefinitionDto> buildDbRulesByDbDeprecatedKey(Map<String, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysByUuid,
Map<RuleKey, RuleDefinitionDto> dbRules) {
- Map<Integer, RuleDefinitionDto> dbRulesByRuleId = dbRules.values().stream()
- .collect(uniqueIndex(RuleDefinitionDto::getId));
+ Map<String, RuleDefinitionDto> dbRulesByRuleUuid = dbRules.values().stream()
+ .collect(uniqueIndex(RuleDefinitionDto::getUuid));
ImmutableMap.Builder<RuleKey, RuleDefinitionDto> builder = ImmutableMap.builder();
- for (Map.Entry<Integer, Set<SingleDeprecatedRuleKey>> entry : dbDeprecatedKeysById.entrySet()) {
- Integer ruleId = entry.getKey();
- RuleDefinitionDto rule = dbRulesByRuleId.get(ruleId);
+ for (Map.Entry<String, Set<SingleDeprecatedRuleKey>> entry : dbDeprecatedKeysByUuid.entrySet()) {
+ String ruleUuid = entry.getKey();
+ RuleDefinitionDto rule = dbRulesByRuleUuid.get(ruleUuid);
if (rule == null) {
- LOG.warn("Could not retrieve rule with id %s referenced by a deprecated rule key. " +
- "The following deprecated rule keys seem to be referencing a non-existing rule",
- ruleId, entry.getValue());
+ LOG.warn("Could not retrieve rule with uuid %s referenced by a deprecated rule key. " +
+ "The following deprecated rule keys seem to be referencing a non-existing rule",
+ ruleUuid, entry.getValue());
} else {
entry.getValue().forEach(d -> builder.put(d.getOldRuleKeyAsRuleKey(), rule));
}
@@ -255,13 +255,13 @@ public class RegisterRules implements Startable {
}
private ImmutableMap<RuleKey, SingleDeprecatedRuleKey> getDbDeprecatedKeysByOldRuleKey() {
- return dbDeprecatedKeysById.values().stream()
+ return dbDeprecatedKeysByUuid.values().stream()
.flatMap(Collection::stream)
.collect(uniqueIndex(SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey));
}
private Set<SingleDeprecatedRuleKey> getDBDeprecatedKeysFor(RuleDefinitionDto rule) {
- return dbDeprecatedKeysById.getOrDefault(rule.getId(), emptySet());
+ return dbDeprecatedKeysByUuid.getOrDefault(rule.getUuid(), emptySet());
}
private Stream<RuleDefinitionDto> getRemaining() {
@@ -392,6 +392,7 @@ public class RegisterRules implements Startable {
private RuleDefinitionDto createRuleDto(RulesDefinition.Rule ruleDef, DbSession session) {
RuleDefinitionDto ruleDto = new RuleDefinitionDto()
+ .setUuid(uuidFactory.create())
.setRuleKey(RuleKey.of(ruleDef.repository().key(), ruleDef.key()))
.setPluginKey(ruleDef.pluginKey())
.setIsTemplate(ruleDef.template())
@@ -580,7 +581,7 @@ public class RegisterRules implements Startable {
}
// Propagate the default value to existing active rule parameters
profiler.start();
- for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleIdOfAllOrganizations(session, rule.getId())) {
+ for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleUuidOfAllOrganizations(session, rule.getUuid())) {
ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
}
@@ -624,7 +625,7 @@ public class RegisterRules implements Startable {
deprecatedRuleKeysToBeCreated
.forEach(r -> dbClient.ruleDao().insert(dbSession, new DeprecatedRuleKeyDto()
.setUuid(uuidFactory.create())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setOldRepositoryKey(r.getOldRepositoryKey())
.setOldRuleKey(r.getOldRuleKey())
.setCreatedAt(system2.now())));
@@ -638,9 +639,9 @@ public class RegisterRules implements Startable {
changed = true;
} else if (dto.getSystemTags().size() != ruleDef.tags().size() ||
!dto.getSystemTags().containsAll(ruleDef.tags())) {
- dto.setSystemTags(ruleDef.tags());
- changed = true;
- }
+ dto.setSystemTags(ruleDef.tags());
+ changed = true;
+ }
return changed;
}
@@ -652,9 +653,9 @@ public class RegisterRules implements Startable {
changed = true;
} else if (dto.getSecurityStandards().size() != ruleDef.securityStandards().size() ||
!dto.getSecurityStandards().containsAll(ruleDef.securityStandards())) {
- dto.setSecurityStandards(ruleDef.securityStandards());
- changed = true;
- }
+ dto.setSecurityStandards(ruleDef.securityStandards());
+ changed = true;
+ }
return changed;
}
@@ -671,9 +672,9 @@ public class RegisterRules implements Startable {
});
for (RuleDefinitionDto customRule : customRules) {
- Integer templateId = customRule.getTemplateId();
- checkNotNull(templateId, "Template id of the custom rule '%s' is null", customRule);
- Optional<RuleDefinitionDto> template = dbClient.ruleDao().selectDefinitionById(templateId, dbSession);
+ String templateUuid = customRule.getTemplateUuid();
+ checkNotNull(templateUuid, "Template uuid of the custom rule '%s' is null", customRule);
+ Optional<RuleDefinitionDto> template = dbClient.ruleDao().selectDefinitionByUuid(templateUuid, dbSession);
if (template.isPresent() && template.get().getStatus() != RuleStatus.REMOVED) {
if (updateCustomRuleFromTemplateRule(customRule, template.get())) {
recorder.updated(customRule);
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/SingleDeprecatedRuleKey.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/SingleDeprecatedRuleKey.java
index 074a06cfb34..0c3155a5313 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/SingleDeprecatedRuleKey.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/SingleDeprecatedRuleKey.java
@@ -36,7 +36,7 @@ class SingleDeprecatedRuleKey {
private String newRuleKey;
private String newRepositoryKey;
private String uuid;
- private Integer ruleId;
+ private String ruleUuid;
/**
* static methods {@link #from(RulesDefinition.Rule)} and {@link #from(DeprecatedRuleKeyDto)} must be used
@@ -58,7 +58,7 @@ class SingleDeprecatedRuleKey {
public static SingleDeprecatedRuleKey from(DeprecatedRuleKeyDto rule) {
return new SingleDeprecatedRuleKey()
.setUuid(rule.getUuid())
- .setRuleId(rule.getRuleId())
+ .setRuleUuid(rule.getRuleUuid())
.setNewRepositoryKey(rule.getNewRepositoryKey())
.setNewRuleKey(rule.getNewRuleKey())
.setOldRepositoryKey(rule.getOldRepositoryKey())
@@ -77,7 +77,6 @@ class SingleDeprecatedRuleKey {
return RuleKey.of(oldRepositoryKey, oldRuleKey);
}
-
public RuleKey getNewRuleKeyAsRuleKey() {
return RuleKey.of(newRepositoryKey, newRuleKey);
}
@@ -98,8 +97,8 @@ class SingleDeprecatedRuleKey {
}
@CheckForNull
- public Integer getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
@Override
@@ -122,8 +121,8 @@ class SingleDeprecatedRuleKey {
return Objects.hash(oldRuleKey, oldRepositoryKey, newRuleKey, newRepositoryKey);
}
- private SingleDeprecatedRuleKey setRuleId(Integer ruleId) {
- this.ruleId = ruleId;
+ private SingleDeprecatedRuleKey setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
return this;
}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinder.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinder.java
index 3b642bf5966..b8fcc2773f4 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinder.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinder.java
@@ -19,16 +19,14 @@
*/
package org.sonar.server.rule;
-import org.sonar.api.rules.RuleFinder;
-
/**
- * {@link RuleFinder} implementation that supports caching used by the Web Server.
+ * {@link ServerRuleFinder} implementation that supports caching used by the Web Server.
* <p>
* Caching is enabled right after loading of rules is done (see {@link RegisterRules}) and disabled
* once all startup tasks are done (see {@link org.sonar.server.platform.platformlevel.PlatformLevelStartup}).
* </p>
*/
-public interface WebServerRuleFinder extends RuleFinder {
+public interface WebServerRuleFinder extends ServerRuleFinder {
/**
* Enable caching.
*/
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
index 8afc7248155..448222ad30d 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
@@ -21,19 +21,20 @@ package org.sonar.server.rule;
import com.google.common.annotations.VisibleForTesting;
import java.util.Collection;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
import org.sonar.db.DbClient;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
public class WebServerRuleFinderImpl implements WebServerRuleFinder {
private final DbClient dbClient;
- private final RuleFinder defaultFinder;
+ private final ServerRuleFinder defaultFinder;
@VisibleForTesting
- RuleFinder delegate;
+ ServerRuleFinder delegate;
public WebServerRuleFinderImpl(DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider) {
this.dbClient = dbClient;
@@ -53,13 +54,6 @@ public class WebServerRuleFinderImpl implements WebServerRuleFinder {
@Override
@CheckForNull
- @Deprecated
- public Rule findById(int ruleId) {
- return delegate.findById(ruleId);
- }
-
- @Override
- @CheckForNull
public Rule findByKey(String repositoryKey, String key) {
return delegate.findByKey(repositoryKey, key);
}
@@ -81,4 +75,8 @@ public class WebServerRuleFinderImpl implements WebServerRuleFinder {
return delegate.findAll(query);
}
+ @Override
+ public Optional<RuleDefinitionDto> findDtoByKey(RuleKey key) {
+ return delegate.findDtoByKey(key);
+ }
}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/BackendCleanupTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/BackendCleanupTest.java
index 0a11cce7034..dd8173b2367 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/BackendCleanupTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/BackendCleanupTest.java
@@ -19,11 +19,11 @@
*/
package org.sonar.server.platform;
-import java.util.Random;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
@@ -146,12 +146,11 @@ public class BackendCleanupTest {
dbTester.properties().insertProperty(new PropertyDto()
.setKey("sonar.profile.java")
.setValue("Sonar Way")
- .setComponentUuid(project.uuid())
- );
+ .setComponentUuid(project.uuid()));
}
private static RuleDoc newRuleDoc() {
- return new RuleDoc().setId(new Random().nextInt(942)).setKey(RuleTesting.XOO_X1.toString()).setRepository(RuleTesting.XOO_X1.repository());
+ return new RuleDoc().setUuid(Uuids.createFast()).setKey(RuleTesting.XOO_X1.toString()).setRepository(RuleTesting.XOO_X1.repository());
}
private ComponentDoc newComponentDoc() {
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
index dcd12ce830f..2cf8ee28c92 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
@@ -22,8 +22,8 @@ package org.sonar.server.rule;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.List;
-import java.util.Random;
import java.util.function.Consumer;
+import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
@@ -114,22 +114,6 @@ public class CachingRuleFinderTest {
}
@Test
- public void findById_returns_all_loaded_rules_by_id() {
- for (int i = 0; i < ruleDefinitions.length; i++) {
- RuleDefinitionDto ruleDefinition = ruleDefinitions[i];
- RuleParamDto ruleParam = ruleParams[i];
-
- org.sonar.api.rules.Rule rule = underTest.findById(ruleDefinition.getId());
- verifyRule(rule, ruleDefinition, ruleParam);
- }
- }
-
- @Test
- public void findById_returns_null_for_non_existing_id() {
- assertThat(underTest.findById(new Random().nextInt())).isNull();
- }
-
- @Test
public void findByKey_returns_all_loaded_rules_by_id() {
for (int i = 0; i < ruleDefinitions.length; i++) {
RuleDefinitionDto ruleDefinition = ruleDefinitions[i];
@@ -396,7 +380,7 @@ public class CachingRuleFinderTest {
return RuleKey.of(rule.getRepositoryKey(), rule.getKey());
}
- private void verifyRule(Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) {
+ private void verifyRule(@Nullable Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) {
assertThat(rule).isNotNull();
assertThat(rule.getName()).isEqualTo(ruleDefinition.getName());
@@ -410,7 +394,6 @@ public class CachingRuleFinderTest {
assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().toArray(new String[0]));
assertThat(rule.getTags()).isEmpty();
- assertThat(rule.getId()).isEqualTo(ruleDefinition.getId());
assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription());
assertThat(rule.getParams()).hasSize(1);
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
index 8f47993eef5..7cda019478b 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
@@ -176,7 +176,7 @@ public class RegisterRulesTest {
// verify index
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), db.getDefaultOrganization(), RULE_KEY2);
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule1.getId(), rule2.getId(), hotspotRule.getId());
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).containsOnly(rule1.getUuid(), rule2.getUuid(), hotspotRule.getUuid());
verifyIndicesMarkedAsInitialized();
// verify repositories
@@ -239,8 +239,8 @@ public class RegisterRulesTest {
RuleDefinitionDto rule = rules.iterator().next();
// verify index
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds())
- .containsExactly(rule.getId());
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids())
+ .containsExactly(rule.getUuid());
verifyIndicesMarkedAsInitialized();
// register no rule
@@ -256,7 +256,7 @@ public class RegisterRulesTest {
.containsExactly(REMOVED);
// verify index
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds())
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids())
.isEmpty();
verifyIndicesNotMarkedAsInitialized();
}
@@ -284,7 +284,7 @@ public class RegisterRulesTest {
// verify index
assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds())
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids())
.isNotEmpty();
// register no rule
@@ -298,7 +298,7 @@ public class RegisterRulesTest {
// verify index (documents are still in the index, but all are removed)
assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds())
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids())
.isEmpty();
}
@@ -321,7 +321,7 @@ public class RegisterRulesTest {
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY1);
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY2);
RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, HOTSPOT_RULE_KEY);
- assertThat(es.getIds(RuleIndexDefinition.TYPE_RULE)).containsOnly(valueOf(rule1.getId()), valueOf(rule2.getId()), valueOf(hotspotRule.getId()));
+ assertThat(es.getIds(RuleIndexDefinition.TYPE_RULE)).containsOnly(valueOf(rule1.getUuid()), valueOf(rule2.getUuid()), valueOf(hotspotRule.getUuid()));
verifyIndicesMarkedAsInitialized();
// user adds tags and sets markdown note
@@ -367,7 +367,7 @@ public class RegisterRulesTest {
assertThat(rule3.getStatus()).isEqualTo(READY);
// verify index
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule1.getId(), rule3.getId());
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).containsOnly(rule1.getUuid(), rule3.getUuid());
// verify repositories
assertThat(dbClient.ruleRepositoryDao().selectAll(db.getSession())).extracting(RuleRepositoryDto::getKey).containsOnly("fake");
@@ -475,11 +475,11 @@ public class RegisterRulesTest {
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of("squid", "rule"));
// insert custom rule
- dbClient.ruleDao().insert(db.getSession(), new RuleDefinitionDto()
+ db.rules().insert(new RuleDefinitionDto()
.setRuleKey(RuleKey.of("squid", "custom"))
.setLanguage("java")
.setScope(Scope.ALL)
- .setTemplateId(rule1.getId())
+ .setTemplateUuid(rule1.getUuid())
.setName("custom1"));
db.commit();
@@ -515,8 +515,8 @@ public class RegisterRulesTest {
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repository, ruleKey1));
- SearchIdResult<Integer> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions());
- assertThat(searchRule1.getIds()).containsOnly(rule1.getId());
+ SearchIdResult<String> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions());
+ assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid());
assertThat(searchRule1.getTotal()).isEqualTo(1);
when(system.now()).thenReturn(DATE2.getTime());
@@ -531,12 +531,12 @@ public class RegisterRulesTest {
// rule2 is actually rule1
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repository, ruleKey2));
- assertThat(rule2.getId()).isEqualTo(rule1.getId());
+ assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo("Name2");
assertThat(rule2.getDescription()).isEqualTo(rule1.getDescription());
- SearchIdResult<Integer> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
- assertThat(searchRule2.getIds()).containsOnly(rule2.getId());
+ SearchIdResult<String> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
+ assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid());
assertThat(searchRule2.getTotal()).isEqualTo(1);
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isEqualTo(0);
}
@@ -557,8 +557,8 @@ public class RegisterRulesTest {
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repository1, ruleKey));
- SearchIdResult<Integer> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions());
- assertThat(searchRule1.getIds()).containsOnly(rule1.getId());
+ SearchIdResult<String> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions());
+ assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid());
assertThat(searchRule1.getTotal()).isEqualTo(1);
when(system.now()).thenReturn(DATE2.getTime());
@@ -573,12 +573,12 @@ public class RegisterRulesTest {
// rule2 is actually rule1
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repository2, ruleKey));
- assertThat(rule2.getId()).isEqualTo(rule1.getId());
+ assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo("Name2");
assertThat(rule2.getDescription()).isEqualTo(rule1.getDescription());
- SearchIdResult<Integer> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
- assertThat(searchRule2.getIds()).containsOnly(rule2.getId());
+ SearchIdResult<String> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
+ assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid());
assertThat(searchRule2.getTotal()).isEqualTo(1);
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isEqualTo(0);
}
@@ -598,8 +598,8 @@ public class RegisterRulesTest {
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repo1, ruleKey1));
- assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getIds())
- .containsOnly(rule1.getId());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getUuids())
+ .containsOnly(rule1.getUuid());
when(system.now()).thenReturn(DATE2.getTime());
execute(context -> {
@@ -613,12 +613,12 @@ public class RegisterRulesTest {
// rule2 is actually rule1
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repo2, ruleKey2));
- assertThat(rule2.getId()).isEqualTo(rule1.getId());
+ assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo(rule1.getName());
assertThat(rule2.getDescription()).isEqualTo(rule1.getDescription());
- assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getIds())
- .containsOnly(rule2.getId());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getUuids())
+ .containsOnly(rule2.getUuid());
}
@DataProvider
@@ -647,8 +647,8 @@ public class RegisterRulesTest {
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repository1, ruleKey1));
- assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getIds())
- .containsOnly(rule1.getId());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getUuids())
+ .containsOnly(rule1.getUuid());
when(system.now()).thenReturn(DATE2.getTime());
execute(context -> {
@@ -664,10 +664,10 @@ public class RegisterRulesTest {
// rule2 is actually rule1
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RuleKey.of(repository2, ruleKey2));
- assertThat(rule2.getId()).isEqualTo(rule1.getId());
+ assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
- assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getIds())
- .containsOnly(rule1.getId());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getUuids())
+ .containsOnly(rule1.getUuid());
}
@Test
@@ -785,7 +785,7 @@ public class RegisterRulesTest {
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY1);
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY2);
RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, HOTSPOT_RULE_KEY);
- assertThat(es.getIds(RuleIndexDefinition.TYPE_RULE)).containsOnly(valueOf(rule1.getId()), valueOf(rule2.getId()), valueOf(hotspotRule.getId()));
+ assertThat(es.getIds(RuleIndexDefinition.TYPE_RULE)).containsOnly(valueOf(rule1.getUuid()), valueOf(rule2.getUuid()), valueOf(hotspotRule.getUuid()));
assertThat(rule2.getStatus()).isEqualTo(READY);
@@ -801,7 +801,7 @@ public class RegisterRulesTest {
RuleDto rule3 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY3);
assertThat(rule2.getStatus()).isEqualTo(REMOVED);
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule1.getId(), rule3.getId());
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).containsOnly(rule1.getUuid(), rule3.getUuid());
when(system.now()).thenReturn(DATE3.getTime());
execute(new FakeRepositoryV2());
@@ -812,7 +812,7 @@ public class RegisterRulesTest {
assertThat(rule2.getStatus()).isEqualTo(REMOVED);
assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2.getTime());
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule1.getId(), rule3.getId());
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).containsOnly(rule1.getUuid(), rule3.getUuid());
}
@Test
@@ -836,7 +836,7 @@ public class RegisterRulesTest {
@Test
public void remove_system_tags_when_plugin_does_not_provide_any() {
// Rule already exists in DB, with some system tags
- dbClient.ruleDao().insert(db.getSession(), new RuleDefinitionDto()
+ db.rules().insert(new RuleDefinitionDto()
.setRuleKey("rule1")
.setRepositoryKey("findbugs")
.setName("Rule One")
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java
index 146505ebbff..e7280145b27 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java
@@ -29,7 +29,6 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.rule.DeprecatedRuleKeyDto;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.mockito.Mockito.mock;
@@ -43,7 +42,7 @@ public class SingleDeprecatedRuleKeyTest {
DeprecatedRuleKeyDto deprecatedRuleKeyDto = new DeprecatedRuleKeyDto()
.setOldRuleKey(randomAlphanumeric(50))
.setOldRepositoryKey(randomAlphanumeric(50))
- .setRuleId(nextInt(1000))
+ .setRuleUuid(randomAlphanumeric(50))
.setUuid(randomAlphanumeric(40));
SingleDeprecatedRuleKey singleDeprecatedRuleKey = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto);
@@ -53,7 +52,7 @@ public class SingleDeprecatedRuleKeyTest {
assertThat(singleDeprecatedRuleKey.getNewRepositoryKey()).isEqualTo(deprecatedRuleKeyDto.getNewRepositoryKey());
assertThat(singleDeprecatedRuleKey.getNewRuleKey()).isEqualTo(deprecatedRuleKeyDto.getNewRuleKey());
assertThat(singleDeprecatedRuleKey.getUuid()).isEqualTo(deprecatedRuleKeyDto.getUuid());
- assertThat(singleDeprecatedRuleKey.getRuleId()).isEqualTo(deprecatedRuleKeyDto.getRuleId());
+ assertThat(singleDeprecatedRuleKey.getRuleUuid()).isEqualTo(deprecatedRuleKeyDto.getRuleUuid());
assertThat(singleDeprecatedRuleKey.getOldRuleKeyAsRuleKey())
.isEqualTo(RuleKey.of(deprecatedRuleKeyDto.getOldRepositoryKey(), deprecatedRuleKeyDto.getOldRuleKey()));
}
@@ -64,8 +63,7 @@ public class SingleDeprecatedRuleKeyTest {
ImmutableSet<RuleKey> deprecatedRuleKeys = ImmutableSet.of(
RuleKey.of(randomAlphanumeric(50), randomAlphanumeric(50)),
RuleKey.of(randomAlphanumeric(50), randomAlphanumeric(50)),
- RuleKey.of(randomAlphanumeric(50), randomAlphanumeric(50))
- );
+ RuleKey.of(randomAlphanumeric(50), randomAlphanumeric(50)));
RulesDefinition.Repository repository = mock(RulesDefinition.Repository.class);
when(repository.key()).thenReturn(randomAlphanumeric(50));
@@ -82,9 +80,8 @@ public class SingleDeprecatedRuleKeyTest {
SingleDeprecatedRuleKey::getNewRepositoryKey, SingleDeprecatedRuleKey::getNewRuleKey, SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey)
.containsExactlyInAnyOrder(
deprecatedRuleKeys.stream().map(
- r -> tuple(null, r.repository(), r.rule(), rule.repository().key(), rule.key(), RuleKey.of(r.repository(), r.rule()))
- ).collect(MoreCollectors.toArrayList(deprecatedRuleKeys.size())).toArray(new Tuple[deprecatedRuleKeys.size()])
- );
+ r -> tuple(null, r.repository(), r.rule(), rule.repository().key(), rule.key(), RuleKey.of(r.repository(), r.rule())))
+ .collect(MoreCollectors.toArrayList(deprecatedRuleKeys.size())).toArray(new Tuple[deprecatedRuleKeys.size()]));
}
@Test
@@ -93,7 +90,7 @@ public class SingleDeprecatedRuleKeyTest {
.setOldRuleKey(randomAlphanumeric(50))
.setOldRepositoryKey(randomAlphanumeric(50))
.setUuid(randomAlphanumeric(40))
- .setRuleId(1);
+ .setRuleUuid("some-uuid");
DeprecatedRuleKeyDto deprecatedRuleKeyDto1WithoutUuid = new DeprecatedRuleKeyDto()
.setOldRuleKey(deprecatedRuleKeyDto1.getOldRuleKey())
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
index e076722fa16..67fafd572d5 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java
@@ -154,7 +154,7 @@ import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_ORGA
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_OWASP_TOP_10;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_RESOLUTION;
-import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_RULE_ID;
+import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_RULE_UUID;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SANS_TOP_25;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SEVERITY;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_SEVERITY_VALUE;
@@ -233,7 +233,7 @@ public class IssueIndex {
RESOLUTIONS(PARAM_RESOLUTIONS, FIELD_ISSUE_RESOLUTION, STICKY, Issue.RESOLUTIONS.size() + 1),
TYPES(PARAM_TYPES, FIELD_ISSUE_TYPE, STICKY, RuleType.values().length),
LANGUAGES(PARAM_LANGUAGES, FIELD_ISSUE_LANGUAGE, STICKY, MAX_FACET_SIZE),
- RULES(PARAM_RULES, FIELD_ISSUE_RULE_ID, STICKY, MAX_FACET_SIZE),
+ RULES(PARAM_RULES, FIELD_ISSUE_RULE_UUID, STICKY, MAX_FACET_SIZE),
TAGS(PARAM_TAGS, FIELD_ISSUE_TAGS, STICKY, MAX_FACET_SIZE),
AUTHORS(DEPRECATED_PARAM_AUTHORS, FIELD_ISSUE_AUTHOR_LOGIN, STICKY, MAX_FACET_SIZE),
AUTHOR(PARAM_AUTHOR, FIELD_ISSUE_AUTHOR_LOGIN, STICKY, MAX_FACET_SIZE),
@@ -327,7 +327,7 @@ public class IssueIndex {
this.sorting.add(IssueQuery.SORT_BY_FILE_LINE, FIELD_ISSUE_KEY);
this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_VULNERABILITY_PROBABILITY).reverse();
this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_SQ_SECURITY_CATEGORY);
- this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_RULE_ID);
+ this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_RULE_UUID);
this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_PROJECT_UUID);
this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_FILE_PATH);
this.sorting.add(IssueQuery.SORT_HOTSPOTS, FIELD_ISSUE_LINE);
@@ -427,9 +427,9 @@ public class IssueIndex {
FIELD_ISSUE_AUTHOR_LOGIN, AUTHOR.getFilterScope(),
createTermsFilter(FIELD_ISSUE_AUTHOR_LOGIN, query.authors()));
filters.addFilter(
- FIELD_ISSUE_RULE_ID, RULES.getFilterScope(), createTermsFilter(
- FIELD_ISSUE_RULE_ID,
- query.rules().stream().map(IssueDoc::formatRuleId).collect(toList())));
+ FIELD_ISSUE_RULE_UUID, RULES.getFilterScope(), createTermsFilter(
+ FIELD_ISSUE_RULE_UUID,
+ query.rules().stream().map(RuleDefinitionDto::getUuid).collect(toList())));
filters.addFilter(FIELD_ISSUE_STATUS, STATUSES.getFilterScope(), createTermsFilter(FIELD_ISSUE_STATUS, query.statuses()));
filters.addFilter(
FIELD_ISSUE_ORGANIZATION_UUID, new SimpleFieldFilterScope(FIELD_ISSUE_ORGANIZATION_UUID),
@@ -655,7 +655,7 @@ public class IssueIndex {
addFacetIfNeeded(options, aggregationHelper, esRequest, DIRECTORIES, query.directories().toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, FILE_UUIDS, query.fileUuids().toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, LANGUAGES, query.languages().toArray());
- addFacetIfNeeded(options, aggregationHelper, esRequest, RULES, query.rules().stream().map(RuleDefinitionDto::getId).toArray());
+ addFacetIfNeeded(options, aggregationHelper, esRequest, RULES, query.rules().stream().map(RuleDefinitionDto::getUuid).toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, AUTHORS, query.authors().toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, AUTHOR, query.authors().toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, TAGS, query.tags().toArray());
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
index 4b454819d92..7d4c2bcb1e9 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
@@ -61,14 +61,14 @@ public class ComponentIndexSearchTest {
@Test
public void filter_by_language() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto javaFile = db.components().insertComponent(newFileDto(project).setLanguage("java"));
+ db.components().insertComponent(newFileDto(project).setLanguage("java"));
ComponentDto jsFile1 = db.components().insertComponent(newFileDto(project).setLanguage("js"));
ComponentDto jsFile2 = db.components().insertComponent(newFileDto(project).setLanguage("js"));
index(project);
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setLanguage("js").build(), new SearchOptions());
- assertThat(result.getIds()).containsExactlyInAnyOrder(jsFile1.uuid(), jsFile2.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(jsFile1.uuid(), jsFile2.uuid());
}
@Test
@@ -79,19 +79,19 @@ public class ComponentIndexSearchTest {
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQuery("shiny").build(), new SearchOptions());
- assertThat(result.getIds()).containsExactlyInAnyOrder(project.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
}
@Test
public void filter_by_key_with_exact_match() {
ComponentDto ignoredProject = db.components().insertPrivateProject(p -> p.setDbKey("ignored-project"));
ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("shiny-project"));
- ComponentDto anotherIgnoreProject = db.components().insertPrivateProject(p -> p.setDbKey("another-shiny-project"));
+ db.components().insertPrivateProject(p -> p.setDbKey("another-shiny-project"));
index(ignoredProject, project);
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQuery("shiny-project").build(), new SearchOptions());
- assertThat(result.getIds()).containsExactlyInAnyOrder(project.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
}
@Test
@@ -102,7 +102,7 @@ public class ComponentIndexSearchTest {
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQualifiers(singleton(Qualifiers.FILE)).build(), new SearchOptions());
- assertThat(result.getIds()).containsExactlyInAnyOrder(file.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(file.uuid());
}
@Test
@@ -115,7 +115,7 @@ public class ComponentIndexSearchTest {
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setOrganization(organization.getUuid()).build(), new SearchOptions());
- assertThat(result.getIds()).containsExactlyInAnyOrder(project.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
}
@Test
@@ -127,7 +127,7 @@ public class ComponentIndexSearchTest {
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions());
- assertThat(result.getIds()).containsExactly(project1.uuid(), project2.uuid(), project3.uuid());
+ assertThat(result.getUuids()).containsExactly(project1.uuid(), project2.uuid(), project3.uuid());
}
@Test
@@ -139,7 +139,7 @@ public class ComponentIndexSearchTest {
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions().setPage(2, 3));
- assertThat(result.getIds()).containsExactlyInAnyOrder(projects.get(3).uuid(), projects.get(4).uuid(), projects.get(5).uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(projects.get(3).uuid(), projects.get(4).uuid(), projects.get(5).uuid());
}
@Test
@@ -153,7 +153,7 @@ public class ComponentIndexSearchTest {
SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions());
- assertThat(result.getIds()).containsExactlyInAnyOrder(project1.uuid(), project2.uuid())
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project1.uuid(), project2.uuid())
.doesNotContain(unauthorizedProject.uuid());
}
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
index 63697542156..a4ee52291ec 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java
@@ -262,7 +262,7 @@ public class IssueIndexFacetsTest {
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
- indexIssues(newDoc("I1", file).setRuleId(ruleDefinitionDto.getId()).setLanguage("xoo"));
+ indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
assertThatFacetHasOnly(IssueQuery.builder(), "languages", entry("xoo", 1L));
}
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
index 1bde99b73d9..579aa05a5cd 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java
@@ -29,10 +29,10 @@ import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.System2;
-import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
@@ -517,10 +517,10 @@ public class IssueIndexFiltersTest {
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
- indexIssues(newDoc("I1", file).setRuleId(ruleDefinitionDto.getId()));
+ indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()));
assertThatSearchReturnsOnly(IssueQuery.builder().rules(singletonList(ruleDefinitionDto)), "I1");
- assertThatSearchReturnsEmpty(IssueQuery.builder().rules(singletonList(new RuleDefinitionDto().setId(-1))));
+ assertThatSearchReturnsEmpty(IssueQuery.builder().rules(singletonList(new RuleDefinitionDto().setUuid("uuid-abc"))));
}
@Test
@@ -530,7 +530,7 @@ public class IssueIndexFiltersTest {
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
- indexIssues(newDoc("I1", file).setRuleId(ruleDefinitionDto.getId()).setLanguage("xoo"));
+ indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
assertThatSearchReturnsOnly(IssueQuery.builder().languages(singletonList("xoo")), "I1");
assertThatSearchReturnsEmpty(IssueQuery.builder().languages(singletonList("unknown")));
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index fcba3067c1b..9cff9a010d5 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -217,18 +217,18 @@ public class IssueIndexTest {
public void list_tags() {
RuleDefinitionDto r1 = db.rules().insert();
RuleDefinitionDto r2 = db.rules().insert();
- ruleIndexer.commitAndIndex(db.getSession(), asList(r1.getId(), r2.getId()));
+ ruleIndexer.commitAndIndex(db.getSession(), asList(r1.getUuid(), r2.getUuid()));
OrganizationDto org = db.organizations().insert();
OrganizationDto anotherOrg = db.organizations().insert();
ComponentDto project = newPrivateProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
indexIssues(
- newDoc("I42", file).setOrganizationUuid(anotherOrg.getUuid()).setRuleId(r1.getId()).setTags(of("another")),
- newDoc("I1", file).setOrganizationUuid(org.getUuid()).setRuleId(r1.getId()).setTags(of("convention", "java8", "bug")),
- newDoc("I2", file).setOrganizationUuid(org.getUuid()).setRuleId(r1.getId()).setTags(of("convention", "bug")),
- newDoc("I3", file).setOrganizationUuid(org.getUuid()).setRuleId(r2.getId()),
- newDoc("I4", file).setOrganizationUuid(org.getUuid()).setRuleId(r1.getId()).setTags(of("convention")));
+ newDoc("I42", file).setOrganizationUuid(anotherOrg.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("another")),
+ newDoc("I1", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("convention", "java8", "bug")),
+ newDoc("I2", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("convention", "bug")),
+ newDoc("I3", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r2.getUuid()),
+ newDoc("I4", file).setOrganizationUuid(org.getUuid()).setRuleUuid(r1.getUuid()).setTags(of("convention")));
assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), null, 100)).containsOnly("convention", "java8", "bug");
assertThat(underTest.searchTags(IssueQuery.builder().organizationUuid(org.getUuid()).build(), null, 2)).containsOnly("bug", "convention");
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java
index 9caf196dec0..d046c7bfc39 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java
@@ -25,6 +25,7 @@ import java.util.Date;
import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
+import org.sonar.core.util.Uuids;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.issue.index.IssueQuery.PeriodStart;
@@ -37,7 +38,7 @@ public class IssueQueryTest {
@Test
public void build_query() {
- RuleDefinitionDto rule = new RuleDefinitionDto().setId(nextInt(1000));
+ RuleDefinitionDto rule = new RuleDefinitionDto().setUuid(Uuids.createFast());
PeriodStart filterDate = new IssueQuery.PeriodStart(new Date(10_000_000_000L), false);
IssueQuery query = IssueQuery.builder()
.issueKeys(newArrayList("ABCDE"))
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
index b4b54c18c93..be7cdf6be7d 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
@@ -213,7 +213,7 @@ public class ProjectMeasuresIndexTest {
SearchIdResult<String> result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().setPage(2, 3));
- assertThat(result.getIds()).containsExactly("P4", "P5", "P6");
+ assertThat(result.getUuids()).containsExactly("P4", "P5", "P6");
assertThat(result.getTotal()).isEqualTo(9);
}
@@ -1726,7 +1726,7 @@ public class ProjectMeasuresIndexTest {
}
private void assertResults(ProjectMeasuresQuery query, ComponentDto... expectedProjects) {
- List<String> result = underTest.search(query, new SearchOptions()).getIds();
+ List<String> result = underTest.search(query, new SearchOptions()).getUuids();
assertThat(result).containsExactly(Arrays.stream(expectedProjects).map(ComponentDto::uuid).toArray(String[]::new));
}
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java
index 090f01b8f3e..37b4b87ebb1 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java
@@ -309,7 +309,7 @@ public class ProjectMeasuresIndexTextSearchTest {
}
private void assertResults(ProjectMeasuresQuery query, String... expectedProjectUuids) {
- List<String> result = underTest.search(query, new SearchOptions()).getIds();
+ List<String> result = underTest.search(query, new SearchOptions()).getUuids();
assertThat(result).containsExactly(expectedProjectUuids);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
index a5d915478ac..4d81269850c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
@@ -90,8 +90,7 @@ public class SearchAction implements ComponentsWsAction {
.addPagingParams(100, MAX_LIMIT)
.setChangelog(
new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)),
- new Change("8.0", "Field 'id' from response has been removed")
- )
+ new Change("8.0", "Field 'id' from response has been removed"))
.setResponseExample(getClass().getResource("search-components-example.json"))
.setHandler(this);
@@ -141,7 +140,7 @@ public class SearchAction implements ComponentsWsAction {
ComponentQuery esQuery = buildEsQuery(organization, request);
SearchIdResult<String> results = componentIndex.search(esQuery, new SearchOptions().setPage(request.getPage(), request.getPageSize()));
- List<ComponentDto> components = dbClient.componentDao().selectByUuids(dbSession, results.getIds());
+ List<ComponentDto> components = dbClient.componentDao().selectByUuids(dbSession, results.getUuids());
Map<String, String> projectKeysByUuids = searchProjectsKeysByUuids(dbSession, components);
return buildResponse(components, organization, projectKeysByUuids,
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
index 16d4170e02a..597c2e1965b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
@@ -278,7 +278,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
.addFacets(request.getFacets())
.setPage(request.getPage(), request.getPageSize()));
- List<String> projectUuids = esResults.getIds();
+ List<String> projectUuids = esResults.getUuids();
Ordering<ProjectDto> ordering = Ordering.explicit(projectUuids).onResultOf(ProjectDto::getUuid);
List<ProjectDto> projects = ordering.immutableSortedCopy(dbClient.projectDao().selectByUuids(dbSession, new HashSet<>(projectUuids)));
Map<String, SnapshotDto> analysisByProjectUuid = getSnapshots(dbSession, request, projectUuids);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java
index d5d9467840b..10555e88ed9 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java
@@ -23,13 +23,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-import javax.annotation.CheckForNull;
import org.sonar.api.issue.Issue;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.System2;
import org.sonar.core.issue.DefaultIssue;
@@ -40,12 +38,13 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueChangeMapper;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.rule.ServerRuleFinder;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
-import static java.util.Objects.requireNonNull;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
/**
@@ -59,12 +58,12 @@ import static org.sonar.core.util.stream.MoreCollectors.toSet;
public class WebIssueStorage extends IssueStorage {
private final System2 system2;
- private final RuleFinder ruleFinder;
+ private final ServerRuleFinder ruleFinder;
private final DbClient dbClient;
private final IssueIndexer indexer;
private final UuidFactory uuidFactory;
- public WebIssueStorage(System2 system2, DbClient dbClient, RuleFinder ruleFinder, IssueIndexer indexer, UuidFactory uuidFactory) {
+ public WebIssueStorage(System2 system2, DbClient dbClient, ServerRuleFinder ruleFinder, IssueIndexer indexer, UuidFactory uuidFactory) {
this.system2 = system2;
this.dbClient = dbClient;
this.ruleFinder = ruleFinder;
@@ -123,8 +122,8 @@ public class WebIssueStorage extends IssueStorage {
private IssueDto doInsert(DbSession session, long now, DefaultIssue issue) {
ComponentDto component = component(session, issue);
ComponentDto project = project(session, issue);
- int ruleId = requireNonNull(getRuleId(issue), "Rule not found: " + issue.ruleKey());
- IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleId, now);
+ String ruleUuid = getRuleUuid(issue).orElseThrow(() -> new IllegalStateException("Rule not found: " + issue.ruleKey()));
+ IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleUuid, now);
getDbClient().issueDao().insert(session, dto);
return dto;
@@ -161,13 +160,11 @@ public class WebIssueStorage extends IssueStorage {
IssueDto dto = IssueDto.toDtoForUpdate(issue, now);
getDbClient().issueDao().update(session, dto);
// Rule id does not exist in DefaultIssue
- Integer ruleId = getRuleId(issue);
- return dto.setRuleId(ruleId);
+ getRuleUuid(issue).ifPresent(dto::setRuleUuid);
+ return dto;
}
- @CheckForNull
- protected Integer getRuleId(Issue issue) {
- Rule rule = ruleFinder.findByKey(issue.ruleKey());
- return rule != null ? rule.getId() : null;
+ protected Optional<String> getRuleUuid(Issue issue) {
+ return ruleFinder.findDtoByKey(issue.ruleKey()).map(RuleDefinitionDto::getUuid);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java
index 7d7aae8b371..ad7fbc05556 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java
@@ -43,11 +43,11 @@ import org.sonar.api.utils.System2;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.Facets;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.issue.SearchRequest;
-import org.sonar.server.issue.index.IssueDoc;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueQuery;
import org.sonar.server.issue.index.IssueQueryFactory;
@@ -458,7 +458,7 @@ public class SearchAction implements IssuesWsAction {
}
addMandatoryValuesToFacet(facets, PARAM_ASSIGNEES, assignees);
addMandatoryValuesToFacet(facets, FACET_ASSIGNED_TO_ME, singletonList(userSession.getUuid()));
- addMandatoryValuesToFacet(facets, PARAM_RULES, query.rules().stream().map(IssueDoc::formatRuleId).collect(toList()));
+ addMandatoryValuesToFacet(facets, PARAM_RULES, query.rules().stream().map(RuleDefinitionDto::getUuid).collect(toList()));
addMandatoryValuesToFacet(facets, PARAM_LANGUAGES, request.getLanguages());
addMandatoryValuesToFacet(facets, PARAM_TAGS, request.getTags());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
index 452d4b5690c..5092b8ee638 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
@@ -45,8 +45,8 @@ import org.sonar.server.es.Facets;
import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.issue.workflow.Transition;
import org.sonarqube.ws.Common;
-import org.sonarqube.ws.Common.User;
import org.sonarqube.ws.Common.Comment;
+import org.sonarqube.ws.Common.User;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Issues.Actions;
import org.sonarqube.ws.Issues.Comments;
@@ -418,11 +418,11 @@ public class SearchResponseFormat {
return;
}
- Map<Integer, RuleKey> ruleIdsByRuleKeys = data.getRules().stream().collect(uniqueIndex(RuleDefinitionDto::getId, RuleDefinitionDto::getKey));
+ Map<String, RuleKey> ruleUuidsByRuleKeys = data.getRules().stream().collect(uniqueIndex(RuleDefinitionDto::getUuid, RuleDefinitionDto::getKey));
Common.Facet.Builder wsFacet = wsFacets.addFacetsBuilder();
wsFacet.setProperty(PARAM_RULES);
- facet.forEach((ruleId, count) -> wsFacet.addValuesBuilder()
- .setVal(ruleIdsByRuleKeys.get(Integer.parseInt(ruleId)).toString())
+ facet.forEach((ruleUuid, count) -> wsFacet.addValuesBuilder()
+ .setVal(ruleUuidsByRuleKeys.get(ruleUuid).toString())
.setCount(count)
.build());
wsFacet.build();
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
index 0b96bb9d28a..d8c15102dc8 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
@@ -166,9 +166,9 @@ public class SearchResponseLoader {
private void loadRules(SearchResponseData preloadedResponseData, Collector collector, DbSession dbSession, SearchResponseData result) {
List<RuleDefinitionDto> preloadedRules = firstNonNull(preloadedResponseData.getRules(), emptyList());
result.addRules(preloadedRules);
- Set<Integer> ruleIdsToLoad = collector.getRuleIds();
- ruleIdsToLoad.removeAll(preloadedRules.stream().map(RuleDefinitionDto::getId).collect(toList(preloadedRules.size())));
- result.addRules(dbClient.ruleDao().selectDefinitionByIds(dbSession, ruleIdsToLoad));
+ Set<String> ruleUuidsToLoad = collector.getRuleUuids();
+ ruleUuidsToLoad.removeAll(preloadedRules.stream().map(RuleDefinitionDto::getUuid).collect(toList(preloadedRules.size())));
+ result.addRules(dbClient.ruleDao().selectDefinitionByUuids(dbSession, ruleUuidsToLoad));
}
private void loadComments(Collector collector, DbSession dbSession, Set<SearchAdditionalField> fields, SearchResponseData result) {
@@ -257,7 +257,7 @@ public class SearchResponseLoader {
private final Set<String> componentUuids = new HashSet<>();
private final Set<String> projectUuids = new HashSet<>();
private final List<String> issueKeys;
- private final Set<Integer> ruleIds = new HashSet<>();
+ private final Set<String> ruleUuids = new HashSet<>();
private final Set<String> userUuids = new HashSet<>();
public Collector(List<String> issueKeys) {
@@ -268,7 +268,7 @@ public class SearchResponseLoader {
for (IssueDto issue : issues) {
componentUuids.add(issue.getComponentUuid());
projectUuids.add(issue.getProjectUuid());
- ruleIds.add(issue.getRuleId());
+ ruleUuids.add(issue.getRuleUuid());
String issueAssigneeUuid = issue.getAssigneeUuid();
if (issueAssigneeUuid != null) {
userUuids.add(issueAssigneeUuid);
@@ -306,9 +306,9 @@ public class SearchResponseLoader {
}
}
- void addRuleIds(@Nullable Collection<String> ruleIds) {
- if (ruleIds != null) {
- this.ruleIds.addAll(ruleIds.stream().map(Integer::parseInt).collect(MoreCollectors.toList()));
+ void addRuleIds(@Nullable Collection<String> ruleUuids) {
+ if (ruleUuids != null) {
+ this.ruleUuids.addAll(ruleUuids);
}
}
@@ -330,8 +330,8 @@ public class SearchResponseLoader {
return projectUuids;
}
- public Set<Integer> getRuleIds() {
- return ruleIds;
+ public Set<String> getRuleUuids() {
+ return ruleUuids;
}
Set<String> getUserUuids() {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
index 1df67984c4b..b9c41abecd6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
@@ -197,7 +197,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
if (ruleDefinition == null) {
return null;
}
- return RuleActivation.create(ruleDefinition.getId(), r.getSeverity(), r.getParameters());
+ return RuleActivation.create(ruleDefinition.getUuid(), r.getSeverity(), r.getParameters());
})
.filter(Objects::nonNull)
.collect(MoreCollectors.toList(rules.size()));
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
index 54432c9af0b..824d8a32e7e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
@@ -195,7 +195,7 @@ public class QProfileExporters {
String severity = activeRule.getSeverity().name();
Map<String, String> params = activeRule.getActiveRuleParams().stream()
.collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue));
- return RuleActivation.create(ruleDefinition.getId(), severity, params);
+ return RuleActivation.create(ruleDefinition.getUuid(), severity, params);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
index 83b9f3cc2a0..872500be45c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
@@ -54,23 +54,23 @@ public class QProfileResetImpl implements QProfileReset {
checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s'", profile.getKee());
BulkChangeResult result = new BulkChangeResult();
- Set<Integer> rulesToBeDeactivated = new HashSet<>();
+ Set<String> rulesToBeDeactivated = new HashSet<>();
// Keep reference to all the activated rules before backup restore
for (ActiveRuleDto activeRuleDto : db.activeRuleDao().selectByProfile(dbSession, profile)) {
if (activeRuleDto.getInheritance() == null) {
// inherited rules can't be deactivated
- rulesToBeDeactivated.add(activeRuleDto.getRuleId());
+ rulesToBeDeactivated.add(activeRuleDto.getRuleUuid());
}
}
- Set<Integer> ruleIds = new HashSet<>(rulesToBeDeactivated.size() + activations.size());
- ruleIds.addAll(rulesToBeDeactivated);
- activations.forEach(a -> ruleIds.add(a.getRuleId()));
- RuleActivationContext context = activator.createContextForUserProfile(dbSession, profile, ruleIds);
+ Set<String> ruleUuids = new HashSet<>(rulesToBeDeactivated.size() + activations.size());
+ ruleUuids.addAll(rulesToBeDeactivated);
+ activations.forEach(a -> ruleUuids.add(a.getRuleUuid()));
+ RuleActivationContext context = activator.createContextForUserProfile(dbSession, profile, ruleUuids);
for (RuleActivation activation : activations) {
try {
List<ActiveRuleChange> changes = activator.activate(dbSession, activation, context);
- rulesToBeDeactivated.remove(activation.getRuleId());
+ rulesToBeDeactivated.remove(activation.getRuleUuid());
result.incrementSucceeded();
result.addChanges(changes);
} catch (BadRequestException e) {
@@ -80,9 +80,9 @@ public class QProfileResetImpl implements QProfileReset {
}
List<ActiveRuleChange> changes = new ArrayList<>(result.getChanges());
- for (Integer ruleId : rulesToBeDeactivated) {
+ for (String ruleUuid : rulesToBeDeactivated) {
try {
- changes.addAll(activator.deactivate(dbSession, context, ruleId, false));
+ changes.addAll(activator.deactivate(dbSession, context, ruleUuid, false));
} catch (BadRequestException e) {
// ignore, probably a rule inherited from parent that can't be deactivated
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java
index 9978e30fdf9..b08efa0d4da 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java
@@ -56,8 +56,8 @@ public class QProfileRulesImpl implements QProfileRules {
public List<ActiveRuleChange> activateAndCommit(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations) {
verifyNotBuiltIn(profile);
- Set<Integer> ruleIds = activations.stream().map(RuleActivation::getRuleId).collect(MoreCollectors.toHashSet(activations.size()));
- RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleIds);
+ Set<String> ruleUuids = activations.stream().map(RuleActivation::getRuleUuid).collect(MoreCollectors.toHashSet(activations.size()));
+ RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
List<ActiveRuleChange> changes = new ArrayList<>();
for (RuleActivation activation : activations) {
@@ -71,19 +71,19 @@ public class QProfileRulesImpl implements QProfileRules {
public BulkChangeResult bulkActivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, @Nullable String severity) {
verifyNotBuiltIn(profile);
return doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> {
- RuleActivation activation = RuleActivation.create(ruleDefinition.getId(), severity, null);
+ RuleActivation activation = RuleActivation.create(ruleDefinition.getUuid(), severity, null);
return ruleActivator.activate(dbSession, activation, context);
});
}
@Override
- public List<ActiveRuleChange> deactivateAndCommit(DbSession dbSession, QProfileDto profile, Collection<Integer> ruleIds) {
+ public List<ActiveRuleChange> deactivateAndCommit(DbSession dbSession, QProfileDto profile, Collection<String> ruleUuids) {
verifyNotBuiltIn(profile);
- RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleIds);
+ RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
List<ActiveRuleChange> changes = new ArrayList<>();
- for (Integer ruleId : ruleIds) {
- changes.addAll(ruleActivator.deactivate(dbSession, context, ruleId, false));
+ for (String ruleUuid : ruleUuids) {
+ changes.addAll(ruleActivator.deactivate(dbSession, context, ruleUuid, false));
}
activeRuleIndexer.commitAndIndex(dbSession, changes);
return changes;
@@ -92,14 +92,14 @@ public class QProfileRulesImpl implements QProfileRules {
@Override
public BulkChangeResult bulkDeactivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery) {
verifyNotBuiltIn(profile);
- return doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> ruleActivator.deactivate(dbSession, context, ruleDefinition.getId(), false));
+ return doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> ruleActivator.deactivate(dbSession, context, ruleDefinition.getUuid(), false));
}
@Override
public List<ActiveRuleChange> deleteRule(DbSession dbSession, RuleDefinitionDto rule) {
List<ActiveRuleChange> changes = new ArrayList<>();
List<String> activeRuleUuids = new ArrayList<>();
- db.activeRuleDao().selectByRuleIdOfAllOrganizations(dbSession, rule.getId()).forEach(ar -> {
+ db.activeRuleDao().selectByRuleUuidOfAllOrganizations(dbSession, rule.getUuid()).forEach(ar -> {
activeRuleUuids.add(ar.getUuid());
changes.add(new ActiveRuleChange(ActiveRuleChange.Type.DEACTIVATED, ar, rule));
});
@@ -116,12 +116,12 @@ public class QProfileRulesImpl implements QProfileRules {
private BulkChangeResult doBulk(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, BiFunction<RuleActivationContext, RuleDefinitionDto, List<ActiveRuleChange>> fn) {
BulkChangeResult result = new BulkChangeResult();
- Collection<Integer> ruleIds = Sets.newHashSet(ruleIndex.searchAll(ruleQuery));
- RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleIds);
+ Collection<String> ruleUuids = Sets.newHashSet(ruleIndex.searchAll(ruleQuery));
+ RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
- for (Integer ruleId : ruleIds) {
+ for (String ruleUuid : ruleUuids) {
try {
- context.reset(ruleId);
+ context.reset(ruleUuid);
RuleDefinitionDto ruleDefinition = context.getRule().get();
List<ActiveRuleChange> changes = fn.apply(context, ruleDefinition);
result.addChanges(changes);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java
index 07a5e0abfd7..68b8de7cf69 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java
@@ -80,12 +80,12 @@ public class QProfileTreeImpl implements QProfileTree {
db.qualityProfileDao().update(dbSession, profile);
List<OrgActiveRuleDto> parentActiveRules = db.activeRuleDao().selectByProfile(dbSession, parent);
- Collection<Integer> ruleIds = parentActiveRules.stream().map(ActiveRuleDto::getRuleId).collect(MoreCollectors.toArrayList());
- RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleIds);
+ Collection<String> ruleUuids = parentActiveRules.stream().map(ActiveRuleDto::getRuleUuid).collect(MoreCollectors.toArrayList());
+ RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
for (ActiveRuleDto parentActiveRule : parentActiveRules) {
try {
- RuleActivation activation = RuleActivation.create(parentActiveRule.getRuleId(), null, null);
+ RuleActivation activation = RuleActivation.create(parentActiveRule.getRuleUuid(), null, null);
changes.addAll(ruleActivator.activate(dbSession, activation, context));
} catch (BadRequestException e) {
// for example because rule status is REMOVED
@@ -105,15 +105,15 @@ public class QProfileTreeImpl implements QProfileTree {
db.qualityProfileDao().update(dbSession, profile);
List<OrgActiveRuleDto> activeRules = db.activeRuleDao().selectByProfile(dbSession, profile);
- Collection<Integer> ruleIds = activeRules.stream().map(ActiveRuleDto::getRuleId).collect(MoreCollectors.toArrayList());
- RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleIds);
+ Collection<String> ruleUuids = activeRules.stream().map(ActiveRuleDto::getRuleUuid).collect(MoreCollectors.toArrayList());
+ RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
for (OrgActiveRuleDto activeRule : activeRules) {
if (ActiveRuleDto.INHERITED.equals(activeRule.getInheritance())) {
- changes.addAll(ruleActivator.deactivate(dbSession, context, activeRule.getRuleId(), true));
+ changes.addAll(ruleActivator.deactivate(dbSession, context, activeRule.getRuleUuid(), true));
} else if (ActiveRuleDto.OVERRIDES.equals(activeRule.getInheritance())) {
- context.reset(activeRule.getRuleId());
+ context.reset(activeRule.getRuleUuid());
activeRule.setInheritance(null);
activeRule.setUpdatedAt(system2.now());
db.activeRuleDao().update(dbSession, activeRule);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
index 3983f674360..51ced557419 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
@@ -115,7 +115,7 @@ public class ActivateRuleAction implements QProfileWsAction {
RuleDefinitionDto ruleDefinition = wsSupport.getRule(dbSession, ruleKey);
boolean reset = Boolean.TRUE.equals(request.paramAsBoolean(PARAM_RESET));
if (reset) {
- return RuleActivation.createReset(ruleDefinition.getId());
+ return RuleActivation.createReset(ruleDefinition.getUuid());
}
String severity = request.param(PARAM_SEVERITY);
Map<String, String> params = null;
@@ -123,7 +123,7 @@ public class ActivateRuleAction implements QProfileWsAction {
if (paramsAsString != null) {
params = KeyValueFormat.parse(paramsAsString);
}
- return RuleActivation.create(ruleDefinition.getId(), severity, params);
+ return RuleActivation.create(ruleDefinition.getUuid(), severity, params);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
index edceb50ff66..5d7e74f6330 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
@@ -114,7 +114,7 @@ public class ChangelogAction implements QProfileWsAction {
List<Change> changelogs = load(dbSession, query);
Map<String, UserDto> usersByUuid = getUsersByUserUuid(dbSession, changelogs);
- Map<Integer, RuleDefinitionDto> rulesByRuleIds = getRulesByRuleIds(dbSession, changelogs);
+ Map<String, RuleDefinitionDto> rulesByRuleIds = getRulesByRuleUuids(dbSession, changelogs);
writeResponse(response.newJsonWriter(), total, page, pageSize, changelogs, usersByUuid, rulesByRuleIds);
}
}
@@ -130,19 +130,19 @@ public class ChangelogAction implements QProfileWsAction {
.collect(uniqueIndex(UserDto::getUuid));
}
- private Map<Integer, RuleDefinitionDto> getRulesByRuleIds(DbSession dbSession, List<Change> changes) {
- Set<Integer> ruleIds = changes.stream()
- .map(c -> c.ruleId)
+ private Map<String, RuleDefinitionDto> getRulesByRuleUuids(DbSession dbSession, List<Change> changes) {
+ Set<String> ruleUuids = changes.stream()
+ .map(c -> c.ruleUuid)
.filter(Objects::nonNull)
.collect(toSet());
return dbClient.ruleDao()
- .selectDefinitionByIds(dbSession, Lists.newArrayList(ruleIds))
+ .selectDefinitionByUuids(dbSession, Lists.newArrayList(ruleUuids))
.stream()
- .collect(uniqueIndex(RuleDefinitionDto::getId));
+ .collect(uniqueIndex(RuleDefinitionDto::getUuid));
}
private static void writeResponse(JsonWriter json, int total, int page, int pageSize, List<Change> changelogs,
- Map<String, UserDto> usersByUuid, Map<Integer, RuleDefinitionDto> rulesByRuleIds) {
+ Map<String, UserDto> usersByUuid, Map<String, RuleDefinitionDto> rulesByRuleUuids) {
json.beginObject();
json.prop("total", total);
json.prop(Param.PAGE, page);
@@ -159,7 +159,7 @@ public class ChangelogAction implements QProfileWsAction {
.prop("authorLogin", user.getLogin())
.prop("authorName", user.getName());
}
- RuleDefinitionDto rule = rulesByRuleIds.get(change.getRuleId());
+ RuleDefinitionDto rule = rulesByRuleUuids.get(change.getRuleUuid());
if (rule != null) {
changeWriter
.prop("ruleKey", rule.getKey().toString())
@@ -198,7 +198,7 @@ public class ChangelogAction implements QProfileWsAction {
private String severity;
private String userUuid;
private String inheritance;
- private Integer ruleId;
+ private String ruleUuid;
private final Map<String, String> params = new HashMap<>();
private Change() {
@@ -228,8 +228,8 @@ public class ChangelogAction implements QProfileWsAction {
}
@CheckForNull
- public Integer getRuleId() {
- return ruleId;
+ public String getRuleUuid() {
+ return ruleUuid;
}
public long getCreatedAt() {
@@ -249,9 +249,9 @@ public class ChangelogAction implements QProfileWsAction {
change.at = dto.getCreatedAt();
// see content of data in class org.sonar.server.qualityprofile.ActiveRuleChange
change.severity = data.get("severity");
- String ruleId = data.get("ruleId");
- if (ruleId != null) {
- change.ruleId = Integer.parseInt(ruleId);
+ String ruleUuid = data.get("ruleUuid");
+ if (ruleUuid != null) {
+ change.ruleUuid = ruleUuid;
}
change.inheritance = data.get("inheritance");
data.entrySet().stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
index 2404b3ae181..f1d0587bbd4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
@@ -85,7 +85,7 @@ public class DeactivateRuleAction implements QProfileWsAction {
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
OrganizationDto organization = wsSupport.getOrganization(dbSession, profile);
wsSupport.checkCanEdit(dbSession, organization, profile);
- ruleActivator.deactivateAndCommit(dbSession, profile, singletonList(rule.getId()));
+ ruleActivator.deactivateAndCommit(dbSession, profile, singletonList(rule.getUuid()));
}
response.noContent();
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
index 57ffaa9629a..39eca8c454a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java
@@ -28,7 +28,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
@@ -36,6 +35,7 @@ import org.sonar.api.rule.Severity;
import org.sonar.api.server.ServerSide;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
@@ -63,13 +63,16 @@ public class RuleCreator {
private final DbClient dbClient;
private final TypeValidations typeValidations;
private final DefaultOrganizationProvider defaultOrganizationProvider;
+ private final UuidFactory uuidFactory;
- public RuleCreator(System2 system2, RuleIndexer ruleIndexer, DbClient dbClient, TypeValidations typeValidations, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public RuleCreator(System2 system2, RuleIndexer ruleIndexer, DbClient dbClient, TypeValidations typeValidations,
+ DefaultOrganizationProvider defaultOrganizationProvider, UuidFactory uuidFactory) {
this.system2 = system2;
this.ruleIndexer = ruleIndexer;
this.dbClient = dbClient;
this.typeValidations = typeValidations;
this.defaultOrganizationProvider = defaultOrganizationProvider;
+ this.uuidFactory = uuidFactory;
}
public RuleKey create(DbSession dbSession, NewCustomRule newRule) {
@@ -86,10 +89,10 @@ public class RuleCreator {
RuleKey customRuleKey = RuleKey.of(templateRule.getRepositoryKey(), newRule.ruleKey());
Optional<RuleDefinitionDto> definition = loadRule(dbSession, customRuleKey);
- int customRuleId = definition.map(d -> updateExistingRule(d, newRule, dbSession))
+ String customRuleUuid = definition.map(d -> updateExistingRule(d, newRule, dbSession))
.orElseGet(() -> createCustomRule(customRuleKey, newRule, templateRule, dbSession));
- ruleIndexer.commitAndIndex(dbSession, customRuleId);
+ ruleIndexer.commitAndIndex(dbSession, customRuleUuid);
return customRuleKey;
}
@@ -103,33 +106,29 @@ public class RuleCreator {
.stream()
.collect(Collectors.toMap(
RuleDto::getKey,
- Function.identity())
- );
+ Function.identity()));
checkArgument(!templateRules.isEmpty() && templateKeys.size() == templateRules.size(), "Rule template keys should exists for each custom rule!");
templateRules.values().forEach(ruleDto -> {
- checkArgument(ruleDto.isTemplate(), "This rule is not a template rule: %s", ruleDto.getKey().toString());
- checkArgument(ruleDto.getStatus() != RuleStatus.REMOVED, TEMPLATE_KEY_NOT_EXIST_FORMAT, ruleDto.getKey().toString());
- }
- );
+ checkArgument(ruleDto.isTemplate(), "This rule is not a template rule: %s", ruleDto.getKey().toString());
+ checkArgument(ruleDto.getStatus() != RuleStatus.REMOVED, TEMPLATE_KEY_NOT_EXIST_FORMAT, ruleDto.getKey().toString());
+ });
- List<Integer> customRuleIds = newRules.stream()
+ List<String> customRuleUuids = newRules.stream()
.map(newCustomRule -> {
- RuleDto templateRule = templateRules.get(newCustomRule.templateKey());
- validateCustomRule(newCustomRule, dbSession, templateRule.getKey());
- RuleKey customRuleKey = RuleKey.of(templateRule.getRepositoryKey(), newCustomRule.ruleKey());
- return createCustomRule(customRuleKey, newCustomRule, templateRule, dbSession);
- }
- )
+ RuleDto templateRule = templateRules.get(newCustomRule.templateKey());
+ validateCustomRule(newCustomRule, dbSession, templateRule.getKey());
+ RuleKey customRuleKey = RuleKey.of(templateRule.getRepositoryKey(), newCustomRule.ruleKey());
+ return createCustomRule(customRuleKey, newCustomRule, templateRule, dbSession);
+ })
.collect(Collectors.toList());
- ruleIndexer.commitAndIndex(dbSession, customRuleIds);
+ ruleIndexer.commitAndIndex(dbSession, customRuleUuids);
return newRules.stream()
.map(newCustomRule -> {
- RuleDto templateRule = templateRules.get(newCustomRule.templateKey());
- return RuleKey.of(templateRule.getRepositoryKey(), newCustomRule.ruleKey());
- }
- )
+ RuleDto templateRule = templateRules.get(newCustomRule.templateKey());
+ return RuleKey.of(templateRule.getRepositoryKey(), newCustomRule.ruleKey());
+ })
.collect(Collectors.toList());
}
@@ -160,7 +159,6 @@ public class RuleCreator {
checkRequest(errors.isEmpty(), errors);
}
- @CheckForNull
private void validateParam(RuleParamDto ruleParam, @Nullable String value) {
if (value != null) {
RuleParamType ruleParamType = RuleParamType.parse(ruleParam.getType());
@@ -195,11 +193,12 @@ public class RuleCreator {
return dbClient.ruleDao().selectDefinitionByKey(dbSession, ruleKey);
}
- private int createCustomRule(RuleKey ruleKey, NewCustomRule newRule, RuleDto templateRuleDto, DbSession dbSession) {
+ private String createCustomRule(RuleKey ruleKey, NewCustomRule newRule, RuleDto templateRuleDto, DbSession dbSession) {
RuleDefinitionDto ruleDefinition = new RuleDefinitionDto()
+ .setUuid(uuidFactory.create())
.setRuleKey(ruleKey)
.setPluginKey(templateRuleDto.getPluginKey())
- .setTemplateId(templateRuleDto.getId())
+ .setTemplateUuid(templateRuleDto.getUuid())
.setConfigKey(templateRuleDto.getConfigKey())
.setName(newRule.name())
.setDescription(newRule.markdownDescription())
@@ -225,7 +224,7 @@ public class RuleCreator {
if (!tags.isEmpty()) {
RuleMetadataDto ruleMetadata = new RuleMetadataDto()
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
- .setRuleId(ruleDefinition.getId())
+ .setRuleUuid(ruleDefinition.getUuid())
.setTags(tags)
.setCreatedAt(system2.now())
.setUpdatedAt(system2.now());
@@ -236,7 +235,7 @@ public class RuleCreator {
String customRuleParamValue = Strings.emptyToNull(newRule.parameter(templateRuleParamDto.getName()));
createCustomRuleParams(customRuleParamValue, ruleDefinition, templateRuleParamDto, dbSession);
}
- return ruleDefinition.getId();
+ return ruleDefinition.getUuid();
}
private void createCustomRuleParams(@Nullable String paramValue, RuleDefinitionDto ruleDto, RuleParamDto templateRuleParam, DbSession dbSession) {
@@ -248,7 +247,7 @@ public class RuleCreator {
dbClient.ruleDao().insertRuleParam(dbSession, ruleDto, ruleParamDto);
}
- private int updateExistingRule(RuleDefinitionDto ruleDto, NewCustomRule newRule, DbSession dbSession) {
+ private String updateExistingRule(RuleDefinitionDto ruleDto, NewCustomRule newRule, DbSession dbSession) {
if (ruleDto.getStatus().equals(RuleStatus.REMOVED)) {
if (newRule.isPreventReactivation()) {
throw new ReactivationException(format("A removed rule with the key '%s' already exists", ruleDto.getKey().rule()), ruleDto.getKey());
@@ -260,7 +259,7 @@ public class RuleCreator {
} else {
throw new IllegalArgumentException(format("A rule with the key '%s' already exists", ruleDto.getKey().rule()));
}
- return ruleDto.getId();
+ return ruleDto.getUuid();
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java
index 73b40ae3c4f..5f4ef2d59be 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java
@@ -81,7 +81,7 @@ public class RuleUpdater {
apply(update, rule, userSession);
update(dbSession, rule);
updateParameters(dbSession, organization, update, rule);
- ruleIndexer.commitAndIndex(dbSession, rule.getId(), organization);
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid(), organization);
return true;
}
@@ -212,12 +212,12 @@ public class RuleUpdater {
private void updateParameters(DbSession dbSession, OrganizationDto organization, RuleUpdate update, RuleDto rule) {
if (update.isChangeParameters() && update.isCustomRule()) {
RuleDto customRule = rule;
- Integer templateId = customRule.getTemplateId();
- checkNotNull(templateId, "Rule '%s' has no persisted template!", customRule);
- Optional<RuleDefinitionDto> templateRule = dbClient.ruleDao().selectDefinitionById(templateId, dbSession);
+ String templateUuid = customRule.getTemplateUuid();
+ checkNotNull(templateUuid, "Rule '%s' has no persisted template!", customRule);
+ Optional<RuleDefinitionDto> templateRule = dbClient.ruleDao().selectDefinitionByUuid(templateUuid, dbSession);
if (!templateRule.isPresent()) {
throw new IllegalStateException(String.format("Template %s of rule %s does not exist",
- customRule.getTemplateId(), customRule.getKey()));
+ customRule.getTemplateUuid(), customRule.getKey()));
}
List<String> paramKeys = newArrayList();
@@ -229,7 +229,7 @@ public class RuleUpdater {
}
private Multimap<ActiveRuleDto, ActiveRuleParamDto> getActiveRuleParamsByActiveRule(DbSession dbSession, OrganizationDto organization, RuleDto customRule) {
- List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, customRule.getId());
+ List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleUuid(dbSession, organization, customRule.getUuid());
Map<String, OrgActiveRuleDto> activeRuleByUuid = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getUuid);
List<String> activeRuleUuids = Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid);
List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
index 3e73b991842..993f80031b4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
@@ -99,8 +99,8 @@ public class ActiveRuleCompleter {
}
} else {
// Load details of all active rules
- List<Integer> ruleIds = Lists.transform(rules, RuleDto::getId);
- List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleIds(dbSession, query.getOrganization(), ruleIds);
+ List<String> ruleUuids = Lists.transform(rules, RuleDto::getUuid);
+ List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleUuids(dbSession, query.getOrganization(), ruleUuids);
Multimap<RuleKey, OrgActiveRuleDto> activeRulesByRuleKey = activeRules.stream()
.collect(MoreCollectors.index(OrgActiveRuleDto::getRuleKey));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = loadParams(dbSession, activeRules);
@@ -141,7 +141,7 @@ public class ActiveRuleCompleter {
}
List<Rules.Active> completeShow(DbSession dbSession, OrganizationDto organization, RuleDefinitionDto rule) {
- List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule.getId());
+ List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleUuid(dbSession, organization, rule.getUuid());
Map<String, ActiveRuleKey> activeRuleUuidsByKey = new HashMap<>();
for (OrgActiveRuleDto activeRuleDto : activeRules) {
activeRuleUuidsByKey.put(activeRuleDto.getUuid(), activeRuleDto.getKey());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java
index 7fafe5ab1d9..a1d6c972851 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java
@@ -173,10 +173,10 @@ public class CreateAction implements RulesWsAction {
.orElseThrow(() -> new IllegalStateException(String.format("Cannot load rule, that has just been created '%s'", ruleKey)));
List<RuleDefinitionDto> templateRules = new ArrayList<>();
if (rule.isCustomRule()) {
- Optional<RuleDefinitionDto> templateRule = dbClient.ruleDao().selectDefinitionById(rule.getTemplateId(), dbSession);
+ Optional<RuleDefinitionDto> templateRule = dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession);
templateRule.ifPresent(templateRules::add);
}
- List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, singletonList(rule.getId()));
+ List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid()));
SearchAction.SearchResult searchResult = new SearchAction.SearchResult()
.setRuleParameters(ruleParameters)
.setTemplateRules(templateRules)
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java
index 4b96dbdab55..b0a4364c91a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java
@@ -86,7 +86,7 @@ public class DeleteAction implements RulesWsAction {
rule.setUpdatedAt(system2.now());
dbClient.ruleDao().update(dbSession, rule);
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
}
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
index 4036b834c40..a374c6f2feb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
@@ -287,8 +287,8 @@ public class RuleMapper {
private static void setParams(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, SearchResult searchResult, Set<String> fieldsToReturn) {
if (shouldReturnField(fieldsToReturn, FIELD_PARAMS)) {
- List<RuleParamDto> ruleParameters = searchResult.getRuleParamsByRuleId().get(ruleDto.getId());
- ruleResponse.getParamsBuilder().addAllParams(ruleParameters.stream().map(RuleParamDtoToWsRuleParam.INSTANCE::apply).collect(toList()));
+ List<RuleParamDto> ruleParameters = searchResult.getRuleParamsByRuleUuid().get(ruleDto.getUuid());
+ ruleResponse.getParamsBuilder().addAllParams(ruleParameters.stream().map(RuleParamDtoToWsRuleParam.INSTANCE).collect(toList()));
}
}
@@ -368,7 +368,7 @@ public class RuleMapper {
private static void setTemplateKey(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, SearchResult result, Set<String> fieldsToReturn) {
if (shouldReturnField(fieldsToReturn, FIELD_TEMPLATE_KEY) && ruleDto.isCustomRule()) {
- RuleDefinitionDto templateRule = result.getTemplateRulesByRuleId().get(ruleDto.getTemplateId());
+ RuleDefinitionDto templateRule = result.getTemplateRulesByRuleUuid().get(ruleDto.getTemplateUuid());
if (templateRule != null) {
ruleResponse.setTemplateKey(templateRule.getKey().toString());
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java
index 9fea8ca882e..946d5f02215 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java
@@ -23,7 +23,6 @@ import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import java.util.ArrayList;
import java.util.Collection;
@@ -34,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.rule.Severity;
@@ -235,24 +235,15 @@ public class SearchAction implements RulesWsAction {
}
private SearchResult doSearch(DbSession dbSession, RuleQuery query, SearchOptions context) {
- SearchIdResult<Integer> result = ruleIndex.search(query, context);
- List<Integer> ruleIds = result.getIds();
- // rule order is managed by ES
- Map<Integer, RuleDto> rulesByRuleKey = Maps.uniqueIndex(
- dbClient.ruleDao().selectByIds(dbSession, query.getOrganization().getUuid(), ruleIds), RuleDto::getId);
- List<RuleDto> rules = new ArrayList<>();
- for (Integer ruleId : ruleIds) {
- RuleDto rule = rulesByRuleKey.get(ruleId);
- if (rule != null) {
- rules.add(rule);
- }
- }
- List<Integer> templateRuleIds = rules.stream()
- .map(RuleDto::getTemplateId)
+ SearchIdResult<String> result = ruleIndex.search(query, context);
+ List<RuleDto> rules = dbClient.ruleDao().selectByUuids(dbSession, query.getOrganization().getUuid(), result.getUuids());
+ List<String> ruleUuids = rules.stream().map(RuleDto::getUuid).collect(Collectors.toList());
+ List<String> templateRuleUuids = rules.stream()
+ .map(RuleDto::getTemplateUuid)
.filter(Objects::nonNull)
.collect(MoreCollectors.toList());
- List<RuleDefinitionDto> templateRules = dbClient.ruleDao().selectDefinitionByIds(dbSession, templateRuleIds);
- List<RuleParamDto> ruleParamDtos = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, ruleIds);
+ List<RuleDefinitionDto> templateRules = dbClient.ruleDao().selectDefinitionByUuids(dbSession, templateRuleUuids);
+ List<RuleParamDto> ruleParamDtos = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, ruleUuids);
return new SearchResult()
.setRules(rules)
.setRuleParameters(ruleParamDtos)
@@ -362,15 +353,15 @@ public class SearchAction implements RulesWsAction {
static class SearchResult {
private List<RuleDto> rules;
- private final ListMultimap<Integer, RuleParamDto> ruleParamsByRuleId;
- private final Map<Integer, RuleDefinitionDto> templateRulesByRuleId;
+ private final ListMultimap<String, RuleParamDto> ruleParamsByRuleUuid;
+ private final Map<String, RuleDefinitionDto> templateRulesByRuleUuid;
private Long total;
private Facets facets;
public SearchResult() {
this.rules = new ArrayList<>();
- this.ruleParamsByRuleId = ArrayListMultimap.create();
- this.templateRulesByRuleId = new HashMap<>();
+ this.ruleParamsByRuleUuid = ArrayListMultimap.create();
+ this.templateRulesByRuleUuid = new HashMap<>();
}
public List<RuleDto> getRules() {
@@ -382,26 +373,26 @@ public class SearchAction implements RulesWsAction {
return this;
}
- public ListMultimap<Integer, RuleParamDto> getRuleParamsByRuleId() {
- return ruleParamsByRuleId;
+ public ListMultimap<String, RuleParamDto> getRuleParamsByRuleUuid() {
+ return ruleParamsByRuleUuid;
}
public SearchResult setRuleParameters(List<RuleParamDto> ruleParams) {
- ruleParamsByRuleId.clear();
+ ruleParamsByRuleUuid.clear();
for (RuleParamDto ruleParam : ruleParams) {
- ruleParamsByRuleId.put(ruleParam.getRuleId(), ruleParam);
+ ruleParamsByRuleUuid.put(ruleParam.getRuleUuid(), ruleParam);
}
return this;
}
- public Map<Integer, RuleDefinitionDto> getTemplateRulesByRuleId() {
- return templateRulesByRuleId;
+ public Map<String, RuleDefinitionDto> getTemplateRulesByRuleUuid() {
+ return templateRulesByRuleUuid;
}
public SearchResult setTemplateRules(List<RuleDefinitionDto> templateRules) {
- templateRulesByRuleId.clear();
+ templateRulesByRuleUuid.clear();
for (RuleDefinitionDto templateRule : templateRules) {
- templateRulesByRuleId.put(templateRule.getId(), templateRule);
+ templateRulesByRuleUuid.put(templateRule.getUuid(), templateRule);
}
return this;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java
index 7c2618b9729..731ce4b4810 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java
@@ -107,11 +107,11 @@ public class ShowAction implements RulesWsAction {
RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, organization.getUuid(), key)
.orElseThrow(() -> new NotFoundException(String.format("Rule not found: %s", key)));
- List<RuleDefinitionDto> templateRules = ofNullable(rule.getTemplateId())
- .flatMap(templateId -> dbClient.ruleDao().selectDefinitionById(rule.getTemplateId(), dbSession))
+ List<RuleDefinitionDto> templateRules = ofNullable(rule.getTemplateUuid())
+ .flatMap(templateUuid -> dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession))
.map(Collections::singletonList).orElseGet(Collections::emptyList);
- List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, singletonList(rule.getId()));
+ List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid()));
ShowResponse showResponse = buildResponse(dbSession, organization, request,
new SearchAction.SearchResult()
.setRules(singletonList(rule))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java
index e825f89002d..8278393a945 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java
@@ -209,7 +209,7 @@ public class UpdateAction implements RulesWsAction {
private RuleUpdate createRuleUpdate(DbSession dbSession, RuleKey key, OrganizationDto organization) {
RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, organization.getUuid(), key)
.orElseThrow(() -> new NotFoundException(format("This rule does not exist: %s", key)));
- RuleUpdate ruleUpdate = ofNullable(rule.getTemplateId())
+ RuleUpdate ruleUpdate = ofNullable(rule.getTemplateUuid())
.map(x -> RuleUpdate.createForCustomRule(key))
.orElseGet(() -> RuleUpdate.createForPluginRule(key));
ruleUpdate.setOrganization(organization);
@@ -256,10 +256,9 @@ public class UpdateAction implements RulesWsAction {
.orElseThrow(() -> new NotFoundException(format("Rule not found: %s", key)));
List<RuleDefinitionDto> templateRules = new ArrayList<>(1);
if (rule.getDefinition().isCustomRule()) {
- dbClient.ruleDao().selectDefinitionById(rule.getTemplateId(), dbSession)
- .ifPresent(templateRules::add);
+ dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession).ifPresent(templateRules::add);
}
- List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, singletonList(rule.getId()));
+ List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid()));
UpdateResponse.Builder responseBuilder = UpdateResponse.newBuilder();
SearchAction.SearchResult searchResult = new SearchAction.SearchResult()
.setRules(singletonList(rule))
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java
index d72b013aba8..a0d34b11bd3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java
@@ -183,7 +183,7 @@ public class IssuesActionTest {
IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot()));
RuleDefinitionDto migrated = db.rules().insert();
- db.executeUpdateSql("update rules set is_external=? where rules.id = ?", false, migrated.getId());
+ db.executeUpdateSql("update rules set is_external=? where rules.uuid = ?", false, migrated.getUuid());
IssueDto issueFromMigratedRule = db.issues().insert(migrated, project, file, i -> i.setKee("MIGRATED").setType(randomRuleTypeExceptHotspot()));
addPermissionTo(project);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java
index c4f2c6a6cc5..a8fe30dda30 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java
@@ -376,7 +376,7 @@ public class SearchActionTest {
.toArray(IssueDto[]::new);
indexIssues();
IssueDto hotspotWithoutRule = hotspots[RANDOM.nextInt(hotspots.length)];
- dbTester.executeUpdateSql("delete from rules where id=" + hotspotWithoutRule.getRuleId());
+ dbTester.executeUpdateSql("delete from rules where uuid=?", hotspotWithoutRule.getRuleUuid());
SearchWsResponse response = newRequest(project)
.executeProtobuf(SearchWsResponse.class);
@@ -1093,7 +1093,7 @@ public class SearchActionTest {
}
@Test
- public void returns_hotspots_ordered_by_vulnerabilityProbability_score_then_rule_id() {
+ public void returns_hotspots_ordered_by_vulnerabilityProbability_score_then_rule_uuid() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
@@ -1106,10 +1106,10 @@ public class SearchActionTest {
Set<String> securityStandards = singleton("cwe:" + (cwes == null ? "unknown" : cwes.iterator().next()));
RuleDefinitionDto rule1 = newRule(
SECURITY_HOTSPOT,
- t -> t.setName("rule_" + sqCategory.name() + "_a").setSecurityStandards(securityStandards));
+ t -> t.setUuid(sqCategory.name() + "_a").setName("rule_" + sqCategory.name() + "_a").setSecurityStandards(securityStandards));
RuleDefinitionDto rule2 = newRule(
SECURITY_HOTSPOT,
- t -> t.setName("rule_" + sqCategory.name() + "_b").setSecurityStandards(securityStandards));
+ t -> t.setUuid(sqCategory.name() + "_b").setName("rule_" + sqCategory.name() + "_b").setSecurityStandards(securityStandards));
return Stream.of(
newHotspot(rule1, project, file).setKee(sqCategory + "_a"),
newHotspot(rule2, project, file).setKee(sqCategory + "_b"));
@@ -1419,16 +1419,14 @@ public class SearchActionTest {
ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto
.setName("test-project")
.setLongName("test-project")
- .setDbKey("com.sonarsource:test-project")
- );
+ .setDbKey("com.sonarsource:test-project"));
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project)
.setDbKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java")
.setName("FourthClass.java")
.setLongName("src/main/java/com/sonarsource/FourthClass.java")
- .setPath("src/main/java/com/sonarsource/FourthClass.java")
- );
+ .setPath("src/main/java/com/sonarsource/FourthClass.java"));
long time = 1577976190000L;
@@ -1442,8 +1440,7 @@ public class SearchActionTest {
.setMessage("message-" + i)
.setLine(10 + i)
.setIssueCreationTime(time)
- .setIssueUpdateTime(time)
- );
+ .setIssueUpdateTime(time));
})
.toArray(IssueDto[]::new);
indexIssues();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java
index 8b455183a40..4916295a099 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java
@@ -29,11 +29,13 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.issue.Issue;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
+import org.sonar.core.util.Uuids;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.issue.IssueTesting;
import org.sonar.db.organization.OrganizationTesting;
-import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.issue.workflow.FunctionExecutor;
import org.sonar.server.issue.workflow.IssueWorkflow;
import org.sonar.server.tester.UserSessionRule;
@@ -45,8 +47,7 @@ import static org.mockito.Mockito.when;
import static org.sonar.api.issue.Issue.STATUS_CLOSED;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.issue.IssueTesting.newDto;
-import static org.sonar.db.rule.RuleTesting.newRuleDto;
+import static org.sonar.db.rule.RuleTesting.newRule;
public class TransitionActionTest {
@@ -104,7 +105,7 @@ public class TransitionActionTest {
public void fail_to_verify_when_parameter_not_found() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Missing parameter : 'transition'");
- action.verify(ImmutableMap.of("unknwown", "reopen"), Lists.newArrayList(), userSession);
+ action.verify(ImmutableMap.of("unknown", "reopen"), Lists.newArrayList(), userSession);
}
@Test
@@ -114,10 +115,10 @@ public class TransitionActionTest {
}
private IssueDto newIssue() {
- RuleDto rule = newRuleDto().setId(10);
+ RuleDefinitionDto rule = newRule().setUuid(Uuids.createFast());
ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto());
ComponentDto file = (newFileDto(project));
- return newDto(rule, file, project);
+ return IssueTesting.newIssue(rule, project, file);
}
private void loginAndAddProjectPermission(String login, String permission) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java
index 9ea07039ae1..60b54d7aec1 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java
@@ -225,7 +225,7 @@ public class WebIssueStorageTest {
}
@Test
- public void rule_id_is_set_on_updated_issue() {
+ public void rule_uuid_is_set_on_updated_issue() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
@@ -235,11 +235,11 @@ public class WebIssueStorageTest {
Collection<IssueDto> results = underTest.save(db.getSession(), singletonList(issue));
assertThat(results).hasSize(1);
- assertThat(results.iterator().next().getRuleId()).isEqualTo(rule.getId());
+ assertThat(results.iterator().next().getRuleUuid()).isEqualTo(rule.getUuid());
}
@Test
- public void rule_id_is_not_set_on_updated_issue_when_rule_is_removed() {
+ public void rule_uuid_is_not_set_on_updated_issue_when_rule_is_removed() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(REMOVED));
ComponentDto project = db.components().insertPublicProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
@@ -249,7 +249,7 @@ public class WebIssueStorageTest {
Collection<IssueDto> results = underTest.save(db.getSession(), singletonList(issue));
assertThat(results).hasSize(1);
- assertThat(results.iterator().next().getRuleId()).isNull();
+ assertThat(results.iterator().next().getRuleUuid()).isNull();
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java
index 59ed3bcaa39..507945d95c7 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java
@@ -67,7 +67,6 @@ public class AssignActionTest {
private static final String PREVIOUS_ASSIGNEE = "previous";
private static final String CURRENT_USER_LOGIN = "john";
- private static final String CURRENT_USER_UUID = "1";
private static final long PAST = 10_000_000_000L;
private static final long NOW = 50_000_000_000L;
@@ -98,6 +97,8 @@ public class AssignActionTest {
responseWriter);
private WsActionTester ws = new WsActionTester(underTest);
+ private UserDto currentUser;
+
@Test
public void assign_to_someone() {
IssueDto issue = newIssueWithBrowsePermission();
@@ -124,10 +125,10 @@ public class AssignActionTest {
.setParam("assignee", "_me")
.execute();
- checkIssueAssignee(issue.getKey(), CURRENT_USER_UUID);
+ checkIssueAssignee(issue.getKey(), currentUser.getUuid());
Optional<IssueDto> optionalIssueDto = dbClient.issueDao().selectByKey(session, issue.getKey());
assertThat(optionalIssueDto).isPresent();
- assertThat(optionalIssueDto.get().getAssigneeUuid()).isEqualTo(CURRENT_USER_UUID);
+ assertThat(optionalIssueDto.get().getAssigneeUuid()).isEqualTo(currentUser.getUuid());
assertThat(issueChangePostProcessor.wasCalled()).isFalse();
}
@@ -210,8 +211,7 @@ public class AssignActionTest {
h -> h
.setAssigneeUuid(PREVIOUS_ASSIGNEE)
.setCreatedAt(PAST).setIssueCreationTime(PAST)
- .setUpdatedAt(PAST).setIssueUpdateTime(PAST)
- );
+ .setUpdatedAt(PAST).setIssueUpdateTime(PAST));
setUserWithBrowsePermission(hotspot);
UserDto arthur = insertUser("arthur");
@@ -311,8 +311,8 @@ public class AssignActionTest {
}
private void setUserWithPermission(IssueDto issue, String permission) {
- UserDto user = insertUser(CURRENT_USER_LOGIN);
- userSession.logIn(user)
+ currentUser = insertUser(CURRENT_USER_LOGIN);
+ userSession.logIn(currentUser)
.addProjectPermission(permission,
dbClient.componentDao().selectByUuid(db.getSession(), issue.getProjectUuid()).get(),
dbClient.componentDao().selectByUuid(db.getSession(), issue.getComponentUuid()).get());
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
index c0116aa02a2..3dfb2835c2a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
@@ -44,7 +44,6 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.rule.RuleDefinitionDto;
-import org.sonar.db.rule.RuleMetadataDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.rule.RuleCreator;
@@ -148,7 +147,7 @@ public class QProfileBackuperImplTest {
.setDescription("custom rule description")
.setName("custom rule name")
.setStatus(RuleStatus.READY)
- .setTemplateId(templateRule.getId()));
+ .setTemplateUuid(templateRule.getUuid()));
RuleParamDto param = db.rules().insertRuleParam(rule);
QProfileDto profile = createProfile(rule.getLanguage());
ActiveRuleDto activeRule = activate(profile, rule, param);
@@ -205,7 +204,7 @@ public class QProfileBackuperImplTest {
@Test
public void restore_resets_the_activated_rules() {
- Integer ruleId = db.rules().insert(RuleKey.of("sonarjs", "s001")).getId();
+ String ruleUuid = db.rules().insert(RuleKey.of("sonarjs", "s001")).getUuid();
OrganizationDto organization = db.organizations().insert();
Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
"<profile><name>foo</name>" +
@@ -227,14 +226,13 @@ public class QProfileBackuperImplTest {
assertThat(reset.calledActivations).hasSize(1);
RuleActivation activation = reset.calledActivations.get(0);
assertThat(activation.getSeverity()).isEqualTo("BLOCKER");
- assertThat(activation.getRuleId()).isEqualTo(ruleId);
+ assertThat(activation.getRuleUuid()).isEqualTo(ruleUuid);
assertThat(activation.getParameter("bar")).isEqualTo("baz");
}
@Test
public void restore_custom_rule() {
- when(ruleCreator.create(any(), anyList())).then(invocation ->
- Collections.singletonList(db.rules().insert(RuleKey.of("sonarjs", "s001")).getKey()));
+ when(ruleCreator.create(any(), anyList())).then(invocation -> Collections.singletonList(db.rules().insert(RuleKey.of("sonarjs", "s001")).getKey()));
OrganizationDto organization = db.organizations().insert();
Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
@@ -266,7 +264,7 @@ public class QProfileBackuperImplTest {
@Test
public void restore_skips_rule_without_template_key_and_db_definition() {
- Integer ruleId = db.rules().insert(RuleKey.of("sonarjs", "s001")).getId();
+ String ruleUuid = db.rules().insert(RuleKey.of("sonarjs", "s001")).getUuid();
OrganizationDto organization = db.organizations().insert();
Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
"<profile><name>foo</name>" +
@@ -292,7 +290,7 @@ public class QProfileBackuperImplTest {
assertThat(reset.calledActivations).hasSize(1);
RuleActivation activation = reset.calledActivations.get(0);
- assertThat(activation.getRuleId()).isEqualTo(ruleId);
+ assertThat(activation.getRuleUuid()).isEqualTo(ruleUuid);
assertThat(activation.getSeverity()).isEqualTo("BLOCKER");
assertThat(activation.getParameter("bar")).isEqualTo("baz");
}
@@ -305,9 +303,9 @@ public class QProfileBackuperImplTest {
ActiveRuleDto activeRule = activate(from, rule, param);
QProfileDto to = createProfile(rule.getLanguage());
- QProfileRestoreSummary summary = underTest.copy(db.getSession(), from, to);
+ underTest.copy(db.getSession(), from, to);
- assertThat(reset.calledActivations).extracting(RuleActivation::getRuleId).containsOnly(activeRule.getRuleId());
+ assertThat(reset.calledActivations).extracting(RuleActivation::getRuleUuid).containsOnly(activeRule.getRuleUuid());
assertThat(reset.calledActivations.get(0).getParameter(param.getName())).isEqualTo("20");
assertThat(reset.calledProfile).isEqualTo(to);
}
@@ -360,7 +358,7 @@ public class QProfileBackuperImplTest {
@Test
public void fail_to_restore_external_rule() {
- db.rules().insert(RuleKey.of("sonarjs", "s001"), r -> r.setIsExternal(true)).getId();
+ db.rules().insert(RuleKey.of("sonarjs", "s001"), r -> r.setIsExternal(true));
OrganizationDto organization = db.organizations().insert();
Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
"<profile><name>foo</name>" +
@@ -386,10 +384,6 @@ public class QProfileBackuperImplTest {
return db.rules().insert();
}
- private RuleMetadataDto createRuleMetadata(RuleMetadataDto metadataDto) {
- return db.rules().insertOrUpdateMetadata(metadataDto);
- }
-
private QProfileDto createProfile(String language) {
return db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(language));
}
@@ -433,7 +427,8 @@ public class QProfileBackuperImplTest {
throw new UnsupportedOperationException();
}
- @Override public QProfileDto createCustom(DbSession dbSession, OrganizationDto organization, QProfileName name, @Nullable String parentKey) {
+ @Override
+ public QProfileDto createCustom(DbSession dbSession, OrganizationDto organization, QProfileName name, @Nullable String parentKey) {
throw new UnsupportedOperationException();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java
index db6542e779a..2426ee15662 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java
@@ -112,7 +112,7 @@ public class QProfileComparisonTest {
@Test
public void compare_same() {
- RuleActivation commonActivation = RuleActivation.create(xooRule1.getId(), Severity.CRITICAL,
+ RuleActivation commonActivation = RuleActivation.create(xooRule1.getUuid(), Severity.CRITICAL,
ImmutableMap.of("min", "7", "max", "42"));
qProfileRules.activateAndCommit(dbSession, left, singleton(commonActivation));
qProfileRules.activateAndCommit(dbSession, right, singleton(commonActivation));
@@ -129,7 +129,7 @@ public class QProfileComparisonTest {
@Test
public void compare_only_left() {
- RuleActivation activation = RuleActivation.create(xooRule1.getId());
+ RuleActivation activation = RuleActivation.create(xooRule1.getUuid());
qProfileRules.activateAndCommit(dbSession, left, singleton(activation));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
@@ -144,7 +144,7 @@ public class QProfileComparisonTest {
@Test
public void compare_only_right() {
- qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId())));
+ qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid())));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -158,8 +158,8 @@ public class QProfileComparisonTest {
@Test
public void compare_disjoint() {
- qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId())));
- qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule2.getId())));
+ qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid())));
+ qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule2.getUuid())));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -173,8 +173,8 @@ public class QProfileComparisonTest {
@Test
public void compare_modified_severity() {
- qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), Severity.CRITICAL, null)));
- qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), Severity.BLOCKER, null)));
+ qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid(), Severity.CRITICAL, null)));
+ qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid(), Severity.BLOCKER, null)));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -193,8 +193,8 @@ public class QProfileComparisonTest {
@Test
public void compare_modified_param() {
- qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), null, ImmutableMap.of("max", "20"))));
- qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), null, ImmutableMap.of("max", "30"))));
+ qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("max", "20"))));
+ qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("max", "30"))));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -216,8 +216,8 @@ public class QProfileComparisonTest {
@Test
public void compare_different_params() {
- qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), null, ImmutableMap.of("max", "20"))));
- qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), null, ImmutableMap.of("min", "5"))));
+ qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("max", "20"))));
+ qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("min", "5"))));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
index eb4f0b4b1be..f2363c41624 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
@@ -114,7 +114,7 @@ public class QProfileExportersTest {
Collection<RuleActivation> activations = activationCapture.getValue();
assertThat(activations).hasSize(1);
RuleActivation activation = activations.iterator().next();
- assertThat(activation.getRuleId()).isEqualTo(rule.getId());
+ assertThat(activation.getRuleUuid()).isEqualTo(rule.getUuid());
assertThat(activation.getSeverity()).isEqualTo("CRITICAL");
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java
index 6239bbcf78d..516df5641ad 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java
@@ -272,7 +272,7 @@ public class QProfileFactoryImplTest {
db.getDbClient().qualityProfileDao().insert(dbSession, rulesProfileDto);
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
.setProfileUuid(rulesProfileDto.getUuid())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setSeverity(Severity.BLOCKER);
db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java
index 50cc76d3619..b93f42d95e8 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java
@@ -67,10 +67,10 @@ public class QProfileResetImplTest {
public void reset() {
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE));
RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
- qProfileRules.activateAndCommit(db.getSession(), profile, singleton(RuleActivation.create(existingRule.getId())));
+ qProfileRules.activateAndCommit(db.getSession(), profile, singleton(RuleActivation.create(existingRule.getUuid())));
RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
- BulkChangeResult result = underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(newRule.getId())));
+ BulkChangeResult result = underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(newRule.getUuid())));
assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile))
.extracting(OrgActiveRuleDto::getRuleKey)
@@ -87,11 +87,11 @@ public class QProfileResetImplTest {
QProfileDto childProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE));
qProfileTree.setParentAndCommit(db.getSession(), childProfile, parentProfile);
RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
- qProfileRules.activateAndCommit(db.getSession(), parentProfile, singleton(RuleActivation.create(existingRule.getId())));
- qProfileRules.activateAndCommit(db.getSession(), childProfile, singleton(RuleActivation.create(existingRule.getId())));
+ qProfileRules.activateAndCommit(db.getSession(), parentProfile, singleton(RuleActivation.create(existingRule.getUuid())));
+ qProfileRules.activateAndCommit(db.getSession(), childProfile, singleton(RuleActivation.create(existingRule.getUuid())));
RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
- underTest.reset(db.getSession(), childProfile, singletonList(RuleActivation.create(newRule.getId())));
+ underTest.reset(db.getSession(), childProfile, singletonList(RuleActivation.create(newRule.getUuid())));
assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), childProfile))
.extracting(OrgActiveRuleDto::getRuleKey)
@@ -106,7 +106,7 @@ public class QProfileResetImplTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(String.format("Operation forbidden for built-in Quality Profile '%s'", profile.getKee()));
- underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getId())));
+ underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getUuid())));
}
@Test
@@ -117,6 +117,6 @@ public class QProfileResetImplTest {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("Quality profile must be persisted");
- underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getId())));
+ underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getUuid())));
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
index 5f58d10367c..f6307c0622f 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
@@ -92,7 +92,7 @@ public class QProfileRuleImplTest {
public void system_activates_rule_without_parameters() {
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, BLOCKER, null, emptyMap());
@@ -104,7 +104,7 @@ public class QProfileRuleImplTest {
userSession.logIn();
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, BLOCKER, null, emptyMap());
@@ -117,7 +117,7 @@ public class QProfileRuleImplTest {
RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "10"));
@@ -130,7 +130,7 @@ public class QProfileRuleImplTest {
RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of(ruleParam.getName(), "15"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of(ruleParam.getName(), "15"));
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "15"));
@@ -142,7 +142,7 @@ public class QProfileRuleImplTest {
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, emptyMap());
@@ -158,7 +158,7 @@ public class QProfileRuleImplTest {
RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of("min", ""));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of("min", ""));
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "10"));
@@ -176,7 +176,7 @@ public class QProfileRuleImplTest {
RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of(paramWithoutDefault.getName(), "-10"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of(paramWithoutDefault.getName(), "-10"));
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null,
@@ -190,7 +190,7 @@ public class QProfileRuleImplTest {
RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of("xxx", "yyy"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of("xxx", "yyy"));
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
@@ -204,11 +204,11 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation
- RuleActivation activation = RuleActivation.create(rule.getId(), MAJOR, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), MAJOR, null);
activate(profile, activation);
// update
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), CRITICAL, of(param.getName(), "20"));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "20"));
List<ActiveRuleChange> changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, CRITICAL, null, of(param.getName(), "20"));
@@ -223,11 +223,11 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation -> param "max" has a default value
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
activate(profile, activation);
// update param "min", which has no default value
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), MAJOR, of(paramWithoutDefault.getName(), "3"));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(paramWithoutDefault.getName(), "3"));
List<ActiveRuleChange> changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, MAJOR, null, of(paramWithDefault.getName(), "10", paramWithoutDefault.getName(), "3"));
@@ -241,11 +241,11 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation -> param "max" has a default value
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of(paramWithDefault.getName(), "20"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of(paramWithDefault.getName(), "20"));
activate(profile, activation);
// reset to default_value
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), null, of(paramWithDefault.getName(), ""));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), null, of(paramWithDefault.getName(), ""));
List<ActiveRuleChange> changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(paramWithDefault.getName(), "10"));
@@ -260,11 +260,11 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation -> param "max" has a default value
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of(paramWithoutDefault.getName(), "20"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of(paramWithoutDefault.getName(), "20"));
activate(profile, activation);
// remove parameter
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), null, of(paramWithoutDefault.getName(), ""));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), null, of(paramWithoutDefault.getName(), ""));
List<ActiveRuleChange> changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(paramWithDefault.getName(), paramWithDefault.getDefaultValue()));
@@ -278,13 +278,13 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation -> param "max" has a default value
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, activation);
db.getDbClient().activeRuleDao().deleteParametersByRuleProfileUuids(db.getSession(), asList(profile.getRulesProfileUuid()));
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, emptyMap());
// contrary to activerule, the param is supposed to be inserted but not updated
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), null, of(param.getName(), ""));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), null, of(param.getName(), ""));
changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
@@ -297,11 +297,11 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
activate(profile, activation);
// update with exactly the same severity and params
- activation = RuleActivation.create(rule.getId());
+ activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, activation);
assertThat(changes).isEmpty();
@@ -314,11 +314,11 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(rule);
// initial activation -> param "max" has a default value
- RuleActivation activation = RuleActivation.create(rule.getId(), BLOCKER, of(param.getName(), "20"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, of(param.getName(), "20"));
activate(profile, activation);
// update without any severity or params => keep
- RuleActivation update = RuleActivation.create(rule.getId());
+ RuleActivation update = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, update);
assertThat(changes).isEmpty();
@@ -328,7 +328,7 @@ public class QProfileRuleImplTest {
public void fail_to_activate_rule_if_profile_is_on_different_languages() {
RuleDefinitionDto rule = createJavaRule();
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage("js"));
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
expectFailure("java rule " + rule.getKey() + " cannot be activated on js profile " + profile.getKee(), () -> activate(profile, activation));
}
@@ -337,7 +337,7 @@ public class QProfileRuleImplTest {
public void fail_to_activate_rule_if_rule_has_REMOVED_status() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
expectFailure("Rule was removed: " + rule.getKey(), () -> activate(profile, activation));
}
@@ -346,7 +346,7 @@ public class QProfileRuleImplTest {
public void fail_to_activate_if_template() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setIsTemplate(true));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
expectFailure("Rule template can't be activated on a Quality profile: " + rule.getKey(), () -> activate(profile, activation));
}
@@ -357,7 +357,7 @@ public class QProfileRuleImplTest {
RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10").setType(PropertyType.INTEGER.name()));
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId(), null, of(param.getName(), "foo"));
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of(param.getName(), "foo"));
expectFailure("Value 'foo' must be an integer.", () -> activate(profile, activation));
}
@@ -370,12 +370,12 @@ public class QProfileRuleImplTest {
QProfileDto profile = createProfile(customRule);
// initial activation
- RuleActivation activation = RuleActivation.create(customRule.getId(), MAJOR, emptyMap());
+ RuleActivation activation = RuleActivation.create(customRule.getUuid(), MAJOR, emptyMap());
activate(profile, activation);
assertThatRuleIsActivated(profile, customRule, null, MAJOR, null, of("format", "txt"));
// update -> parameter is not changed
- RuleActivation updateActivation = RuleActivation.create(customRule.getId(), BLOCKER, of("format", "xml"));
+ RuleActivation updateActivation = RuleActivation.create(customRule.getUuid(), BLOCKER, of("format", "xml"));
activate(profile, updateActivation);
assertThatRuleIsActivated(profile, customRule, null, BLOCKER, null, of("format", "txt"));
}
@@ -385,7 +385,7 @@ public class QProfileRuleImplTest {
userSession.logIn();
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
activate(profile, activation);
List<ActiveRuleChange> changes = deactivate(profile, rule);
@@ -399,7 +399,7 @@ public class QProfileRuleImplTest {
public void system_deactivates_a_rule() {
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
activate(profile, activation);
List<ActiveRuleChange> changes = deactivate(profile, rule);
@@ -429,7 +429,7 @@ public class QProfileRuleImplTest {
public void deactivate_rule_that_has_REMOVED_status() {
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
activate(profile, activation);
rule.setStatus(RuleStatus.REMOVED);
@@ -447,7 +447,7 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
- List<ActiveRuleChange> changes = activate(childProfile, RuleActivation.create(rule.getId()));
+ List<ActiveRuleChange> changes = activate(childProfile, RuleActivation.create(rule.getUuid()));
assertThatProfileHasNoActiveRules(parentProfile);
assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsActivated(grandChildProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
@@ -462,12 +462,12 @@ public class QProfileRuleImplTest {
QProfileDto grandChildProfile = createChildProfile(childProfile);
System.out.println("ACTIVATE ON " + childProfile.getName());
- RuleActivation initialActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation initialActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
activate(childProfile, initialActivation);
System.out.println("---------------");
System.out.println("ACTIVATE ON " + childProfile.getName());
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), CRITICAL, of(param.getName(), "bar"));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
List<ActiveRuleChange> changes = activate(childProfile, updateActivation);
assertThatProfileHasNoActiveRules(parentProfile);
@@ -484,10 +484,10 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
- RuleActivation initialActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation initialActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
activate(childProfile, initialActivation);
- RuleActivation overrideActivation = RuleActivation.create(rule.getId(), CRITICAL, of(param.getName(), "bar"));
+ RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
List<ActiveRuleChange> changes = activate(grandChildProfile, overrideActivation);
assertThatProfileHasNoActiveRules(parentProfile);
@@ -504,14 +504,14 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
- RuleActivation initialActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation initialActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
activate(childProfile, initialActivation);
- RuleActivation overrideActivation = RuleActivation.create(rule.getId(), CRITICAL, of(param.getName(), "bar"));
+ RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
activate(grandChildProfile, overrideActivation);
// update child --> do not touch grandChild
- RuleActivation updateActivation = RuleActivation.create(rule.getId(), BLOCKER, of(param.getName(), "baz"));
+ RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), BLOCKER, of(param.getName(), "baz"));
List<ActiveRuleChange> changes = activate(childProfile, updateActivation);
assertThatProfileHasNoActiveRules(parentProfile);
@@ -528,14 +528,14 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
- RuleActivation initialActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation initialActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
activate(parentProfile, initialActivation);
- RuleActivation overrideActivation = RuleActivation.create(rule.getId(), CRITICAL, of(param.getName(), "bar"));
+ RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
activate(grandChildProfile, overrideActivation);
// reset parent --> touch child but not grandChild
- RuleActivation updateActivation = RuleActivation.createReset(rule.getId());
+ RuleActivation updateActivation = RuleActivation.createReset(rule.getUuid());
List<ActiveRuleChange> changes = activate(parentProfile, updateActivation);
assertThatRuleIsUpdated(parentProfile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
@@ -551,10 +551,10 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- RuleActivation childActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation childActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
activate(childProfile, childActivation);
- RuleActivation parentActivation = RuleActivation.create(rule.getId(), CRITICAL, of(param.getName(), "bar"));
+ RuleActivation parentActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
List<ActiveRuleChange> changes = activate(parentProfile, parentActivation);
assertThatRuleIsUpdated(parentProfile, rule, CRITICAL, null, of(param.getName(), "bar"));
@@ -569,10 +569,10 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- RuleActivation parentActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation parentActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
activate(parentProfile, parentActivation);
- RuleActivation overrideActivation = RuleActivation.create(rule.getId(), MAJOR, of(param.getName(), "foo"));
+ RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
List<ActiveRuleChange> changes = activate(childProfile, overrideActivation);
assertThatRuleIsUpdated(childProfile, rule, MAJOR, INHERITED, of(param.getName(), "foo"));
@@ -585,7 +585,7 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(parentProfile, activation);
assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
@@ -602,12 +602,12 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(parentProfile, activation);
assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
- activation = RuleActivation.create(rule.getId(), CRITICAL, null);
+ activation = RuleActivation.create(rule.getUuid(), CRITICAL, null);
activate(childProfile, activation);
changes = deactivate(parentProfile, rule);
@@ -622,7 +622,7 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(parentProfile, activation);
assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
@@ -638,18 +638,18 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- RuleActivation activation = RuleActivation.create(rule.getId(), CRITICAL, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), CRITICAL, null);
List<ActiveRuleChange> changes = activate(parentProfile, activation);
assertThatRuleIsActivated(parentProfile, rule, changes, CRITICAL, null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
assertThat(changes).hasSize(2);
- RuleActivation childActivation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation childActivation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
changes = activate(childProfile, childActivation);
assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThat(changes).hasSize(1);
- RuleActivation resetActivation = RuleActivation.createReset(rule.getId());
+ RuleActivation resetActivation = RuleActivation.createReset(rule.getUuid());
changes = activate(childProfile, resetActivation);
assertThatRuleIsUpdated(childProfile, rule, CRITICAL, INHERITED, emptyMap());
assertThatRuleIsUpdated(parentProfile, rule, CRITICAL, null, emptyMap());
@@ -663,21 +663,21 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(baseProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
- RuleActivation activation = RuleActivation.create(rule.getId(), CRITICAL, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), CRITICAL, null);
List<ActiveRuleChange> changes = activate(baseProfile, activation);
assertThatRuleIsActivated(baseProfile, rule, changes, CRITICAL, null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
assertThatRuleIsActivated(grandChildProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
assertThat(changes).hasSize(3);
- RuleActivation childActivation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation childActivation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
changes = activate(childProfile, childActivation);
assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThatRuleIsUpdated(grandChildProfile, rule, BLOCKER, INHERITED, emptyMap());
assertThat(changes).hasSize(2);
// Reset on parent do not change child nor grandchild
- RuleActivation resetActivation = RuleActivation.createReset(rule.getId());
+ RuleActivation resetActivation = RuleActivation.createReset(rule.getUuid());
changes = activate(baseProfile, resetActivation);
assertThatRuleIsUpdated(baseProfile, rule, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
@@ -685,7 +685,7 @@ public class QProfileRuleImplTest {
assertThat(changes).hasSize(1);
// Reset on child change grandchild
- resetActivation = RuleActivation.createReset(rule.getId());
+ resetActivation = RuleActivation.createReset(rule.getUuid());
changes = activate(childProfile, resetActivation);
assertThatRuleIsUpdated(baseProfile, rule, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsUpdated(childProfile, rule, rule.getSeverityString(), INHERITED, emptyMap());
@@ -699,7 +699,7 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
createChildProfile(parentProfile);
- RuleActivation resetActivation = RuleActivation.createReset(rule.getId());
+ RuleActivation resetActivation = RuleActivation.createReset(rule.getUuid());
List<ActiveRuleChange> changes = activate(parentProfile, resetActivation);
verifyNoActiveRules();
assertThat(changes).hasSize(0);
@@ -773,7 +773,7 @@ public class QProfileRuleImplTest {
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
- List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule.getId()));
+ List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule.getUuid()));
assertThatRuleIsActivated(parentProfile, rule, null, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, null, rule.getSeverityString(), INHERITED, emptyMap());
@@ -798,8 +798,8 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandchildProfile = createChildProfile(childProfile);
- activate(parentProfile, RuleActivation.create(rule1.getId()));
- activate(parentProfile, RuleActivation.create(rule2.getId()));
+ activate(parentProfile, RuleActivation.create(rule1.getUuid()));
+ activate(parentProfile, RuleActivation.create(rule2.getUuid()));
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
@@ -830,10 +830,10 @@ public class QProfileRuleImplTest {
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
- RuleActivation activation = RuleActivation.create(rule.getId(), CRITICAL, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), CRITICAL, null);
activate(parentProfile, activation);
- RuleActivation overrideActivation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
activate(grandChildProfile, overrideActivation);
// Reset on parent do not change child nor grandchild
@@ -856,7 +856,7 @@ public class QProfileRuleImplTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The built-in profile " + builtInProfile.getName() + " is read-only and can't be updated");
- underTest.activateAndCommit(db.getSession(), builtInProfile, singleton(RuleActivation.create(rule.getId())));
+ underTest.activateAndCommit(db.getSession(), builtInProfile, singleton(RuleActivation.create(rule.getUuid())));
}
private void assertThatProfileHasNoActiveRules(QProfileDto profile) {
@@ -865,7 +865,7 @@ public class QProfileRuleImplTest {
}
private List<ActiveRuleChange> deactivate(QProfileDto profile, RuleDefinitionDto rule) {
- return underTest.deactivateAndCommit(db.getSession(), profile, singleton(rule.getId()));
+ return underTest.deactivateAndCommit(db.getSession(), profile, singleton(rule.getUuid()));
}
private List<ActiveRuleChange> activate(QProfileDto profile, RuleActivation activation) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java
index 88334c2e036..abfc7d442f9 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java
@@ -65,7 +65,7 @@ public class QProfileRulesImplTest {
OrganizationDto organization = db.organizations().insert();
QProfileDto qProfile = db.qualityProfiles().insert(organization);
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage()));
- RuleActivation ruleActivation = RuleActivation.create(rule.getId(), Severity.CRITICAL, Collections.emptyMap());
+ RuleActivation ruleActivation = RuleActivation.create(rule.getUuid(), Severity.CRITICAL, Collections.emptyMap());
qProfileRules.activateAndCommit(db.getSession(), qProfile, singleton(ruleActivation));
@@ -81,12 +81,12 @@ public class QProfileRulesImplTest {
OrganizationDto organization = db.organizations().insert();
QProfileDto qProfile = db.qualityProfiles().insert(organization);
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage()));
- RuleActivation ruleActivation = RuleActivation.create(rule.getId(), Severity.CRITICAL, Collections.emptyMap());
+ RuleActivation ruleActivation = RuleActivation.create(rule.getUuid(), Severity.CRITICAL, Collections.emptyMap());
qProfileRules.activateAndCommit(db.getSession(), qProfile, singleton(ruleActivation));
assertThat(db.getDbClient().qProfileChangeDao().selectByQuery(db.getSession(), new QProfileChangeQuery(qProfile.getKee())))
.extracting(QProfileChangeDto::getUserUuid, QProfileChangeDto::getDataAsMap)
- .containsExactlyInAnyOrder(tuple(user.getUuid(), ImmutableMap.of("ruleId", Integer.toString(rule.getId()), "severity", Severity.CRITICAL)));
+ .containsExactlyInAnyOrder(tuple(user.getUuid(), ImmutableMap.of("ruleUuid", rule.getUuid(), "severity", Severity.CRITICAL)));
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java
index 4add5ec8ab8..cae00247fe4 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java
@@ -108,11 +108,11 @@ public class QProfileTreeImplTest {
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("bar"));
QProfileDto parentProfile = createProfile(rule1);
- List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule1.getId()));
+ List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule1.getUuid()));
assertThat(changes).hasSize(1);
QProfileDto childProfile = createProfile(rule2);
- changes = activate(childProfile, RuleActivation.create(rule2.getId()));
+ changes = activate(childProfile, RuleActivation.create(rule2.getUuid()));
assertThat(changes).hasSize(1);
expectedException.expect(BadRequestException.class);
@@ -127,11 +127,11 @@ public class QProfileTreeImplTest {
RuleDefinitionDto rule2 = createJavaRule();
QProfileDto profile1 = createProfile(rule1);
- List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getId()));
+ List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getUuid()));
assertThat(changes).hasSize(1);
QProfileDto profile2 = createProfile(rule2);
- changes = activate(profile2, RuleActivation.create(rule2.getId()));
+ changes = activate(profile2, RuleActivation.create(rule2.getUuid()));
assertThat(changes).hasSize(1);
changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
@@ -150,11 +150,11 @@ public class QProfileTreeImplTest {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
QProfileDto profile1 = createProfile(rule1);
- List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getId()));
+ List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getUuid()));
assertThat(changes).hasSize(1);
QProfileDto profile2 = createProfile(rule2);
- changes = activate(profile2, RuleActivation.create(rule2.getId()));
+ changes = activate(profile2, RuleActivation.create(rule2.getUuid()));
assertThat(changes).hasSize(1);
changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
@@ -162,7 +162,7 @@ public class QProfileTreeImplTest {
assertThatRuleIsActivated(profile2, rule1, changes, rule1.getSeverityString(), INHERITED, emptyMap());
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
- RuleActivation activation = RuleActivation.create(rule1.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule1.getUuid(), BLOCKER, null);
changes = activate(profile2, activation);
assertThat(changes).hasSize(1);
assertThatRuleIsUpdated(profile2, rule1, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
@@ -180,8 +180,8 @@ public class QProfileTreeImplTest {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
QProfileDto parentProfile = createProfile(rule1);
- activate(parentProfile, RuleActivation.create(rule1.getId()));
- activate(parentProfile, RuleActivation.create(rule2.getId()));
+ activate(parentProfile, RuleActivation.create(rule1.getUuid()));
+ activate(parentProfile, RuleActivation.create(rule2.getUuid()));
rule1.setStatus(RuleStatus.REMOVED);
db.rules().update(rule1);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java
index 82789a370e6..570d404d63d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java
@@ -143,8 +143,8 @@ public class RegisterQualityProfilesNotificationTest {
.extracting(QProfileName::getName, QProfileName::getLanguage)
.containsExactlyInAnyOrder(tuple(dbProfile.getName(), dbProfile.getLanguage()));
assertThat(updatedProfiles.values())
- .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType)
- .containsExactlyInAnyOrder(tuple(newRule.getId(), ACTIVATED));
+ .extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType)
+ .containsExactlyInAnyOrder(tuple(newRule.getUuid(), ACTIVATED));
}
@Test
@@ -165,8 +165,8 @@ public class RegisterQualityProfilesNotificationTest {
.extracting(QProfileName::getName, QProfileName::getLanguage)
.containsExactlyInAnyOrder(tuple(dbProfile.getName(), dbProfile.getLanguage()));
assertThat(updatedProfiles.values())
- .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType)
- .containsExactlyInAnyOrder(tuple(existingRule.getId(), DEACTIVATED));
+ .extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType)
+ .containsExactlyInAnyOrder(tuple(existingRule.getUuid(), DEACTIVATED));
}
@Test
@@ -197,10 +197,10 @@ public class RegisterQualityProfilesNotificationTest {
tuple(dbProfile1.getName(), dbProfile1.getLanguage()),
tuple(dbProfile2.getName(), dbProfile2.getLanguage()));
assertThat(updatedProfiles.values())
- .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType)
+ .extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType)
.containsExactlyInAnyOrder(
- tuple(newRule1.getId(), ACTIVATED),
- tuple(newRule2.getId(), ACTIVATED));
+ tuple(newRule1.getUuid(), ACTIVATED),
+ tuple(newRule2.getUuid(), ACTIVATED));
}
@Test
@@ -223,8 +223,8 @@ public class RegisterQualityProfilesNotificationTest {
.extracting(QProfileName::getName, QProfileName::getLanguage)
.containsExactlyInAnyOrder(tuple(builtInQProfileDto.getName(), builtInQProfileDto.getLanguage()));
assertThat(updatedProfiles.values())
- .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType)
- .containsExactlyInAnyOrder(tuple(newRule.getId(), ACTIVATED));
+ .extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType)
+ .containsExactlyInAnyOrder(tuple(newRule.getUuid(), ACTIVATED));
}
@Test
@@ -250,8 +250,8 @@ public class RegisterQualityProfilesNotificationTest {
.extracting(QProfileName::getName, QProfileName::getLanguage)
.containsExactlyInAnyOrder(tuple(builtInProfile.getName(), builtInProfile.getLanguage()));
assertThat(updatedProfiles.values())
- .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType)
- .containsExactlyInAnyOrder(tuple(rule.getId(), UPDATED));
+ .extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType)
+ .containsExactlyInAnyOrder(tuple(rule.getUuid(), UPDATED));
}
@Test
@@ -265,7 +265,7 @@ public class RegisterQualityProfilesNotificationTest {
db.qualityProfiles().activateRule(builtInQProfileDto, rule);
QProfileDto childQProfileDto = insertProfile(organization,
orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInQProfileDto.getKee()));
- qProfileRules.activateAndCommit(db.getSession(), childQProfileDto, singleton(RuleActivation.create(rule.getId())));
+ qProfileRules.activateAndCommit(db.getSession(), childQProfileDto, singleton(RuleActivation.create(rule.getUuid())));
db.commit();
addPluginProfile(builtInQProfileDto);
@@ -280,8 +280,8 @@ public class RegisterQualityProfilesNotificationTest {
.extracting(QProfileName::getName, QProfileName::getLanguage)
.containsExactlyInAnyOrder(tuple(builtInQProfileDto.getName(), builtInQProfileDto.getLanguage()));
assertThat(updatedProfiles.values())
- .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType)
- .containsExactlyInAnyOrder(tuple(rule.getId(), DEACTIVATED));
+ .extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType)
+ .containsExactlyInAnyOrder(tuple(rule.getUuid(), DEACTIVATED));
}
@Test
@@ -321,7 +321,7 @@ public class RegisterQualityProfilesNotificationTest {
RuleKey ruleKey = RuleKey.of(r.repoKey(), r.ruleKey());
RuleDefinitionDto ruleDefinitionDto = dbRulesByRuleKey.get(ruleKey);
checkState(ruleDefinitionDto != null, "Rule '%s' not found", ruleKey);
- return new BuiltInQProfile.ActiveRule(ruleDefinitionDto.getId(), r);
+ return new BuiltInQProfile.ActiveRule(ruleDefinitionDto.getUuid(), r);
}).toArray(BuiltInQProfile.ActiveRule[]::new);
}
@@ -346,7 +346,7 @@ public class RegisterQualityProfilesNotificationTest {
ActiveRuleDto dto = new ActiveRuleDto()
.setProfileUuid(profile.getUuid())
.setSeverity(severity.name())
- .setRuleId(rule.getId())
+ .setRuleUuid(rule.getUuid())
.setCreatedAt(nextLong())
.setUpdatedAt(nextLong());
db.getDbClient().activeRuleDao().insert(db.getSession(), dto);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
index 70393d1c13b..87aa992a286 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
@@ -175,7 +175,7 @@ public class ActivateRuleActionTest {
assertThat(activations).hasSize(1);
RuleActivation activation = activations.iterator().next();
- assertThat(activation.getRuleId()).isEqualTo(rule.getId());
+ assertThat(activation.getRuleUuid()).isEqualTo(rule.getUuid());
assertThat(activation.getSeverity()).isEqualTo(Severity.BLOCKER);
assertThat(activation.isReset()).isFalse();
}
@@ -185,7 +185,7 @@ public class ActivateRuleActionTest {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
QProfileDto qualityProfile = db.qualityProfiles().insert(organization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
- Integer ruleId = db.rules().insert(ruleKey).getId();
+ String ruleUuid = db.rules().insert(ruleKey).getUuid();
TestRequest request = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_RULE, ruleKey.toString())
@@ -202,7 +202,7 @@ public class ActivateRuleActionTest {
Collection<RuleActivation> activations = ruleActivationCaptor.getValue();
assertThat(activations).hasSize(1);
RuleActivation activation = activations.iterator().next();
- assertThat(activation.getRuleId()).isEqualTo(ruleId);
+ assertThat(activation.getRuleUuid()).isEqualTo(ruleUuid);
assertThat(activation.getSeverity()).isEqualTo(Severity.BLOCKER);
assertThat(activation.isReset()).isFalse();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
index ff65939a967..49e5e52cade 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
@@ -137,7 +137,7 @@ public class ChangeParentActionTest {
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent1);
- ruleIndexer.commitAndIndex(dbSession, rule1.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
activeRuleIndexer.indexOnStartup(emptySet());
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
@@ -156,7 +156,7 @@ public class ChangeParentActionTest {
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().getRuleKey().rule()).isEqualTo(rule1.getRuleKey());
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).hasSize(1);
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
}
@Test
@@ -169,7 +169,7 @@ public class ChangeParentActionTest {
RuleDefinitionDto rule2 = createRule();
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
- ruleIndexer.commitAndIndex(dbSession, asList(rule1.getId(), rule2.getId()));
+ ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid()));
activeRuleIndexer.indexOnStartup(emptySet());
// Set parent 1
@@ -189,7 +189,7 @@ public class ChangeParentActionTest {
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().getRuleKey().rule()).isEqualTo(rule2.getRuleKey());
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).hasSize(1);
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
}
@Test
@@ -199,7 +199,7 @@ public class ChangeParentActionTest {
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
- ruleIndexer.commitAndIndex(dbSession, rule1.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
activeRuleIndexer.indexOnStartup(emptySet());
// Set parent
@@ -216,7 +216,7 @@ public class ChangeParentActionTest {
// Check no rule enabled
assertThat(dbClient.activeRuleDao().selectByProfile(dbSession, child)).isEmpty();
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).isEmpty();
}
@Test
@@ -229,7 +229,7 @@ public class ChangeParentActionTest {
RuleDefinitionDto rule2 = createRule();
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
- ruleIndexer.commitAndIndex(dbSession, rule1.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
activeRuleIndexer.indexOnStartup(emptySet());
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
@@ -250,7 +250,7 @@ public class ChangeParentActionTest {
List<OrgActiveRuleDto> activeRules1 = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().getRuleKey().rule()).isEqualTo(rule1.getRuleKey());
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).hasSize(1);
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
// 2. Set parent 2
ws.newRequest()
@@ -278,7 +278,7 @@ public class ChangeParentActionTest {
// 3. check no rule enabled
List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules).isEmpty();
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).isEmpty();
}
@Test
@@ -288,7 +288,7 @@ public class ChangeParentActionTest {
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
- ruleIndexer.commitAndIndex(dbSession, rule1.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
activeRuleIndexer.indexOnStartup(emptySet());
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
@@ -307,7 +307,7 @@ public class ChangeParentActionTest {
// Check no rule enabled
assertThat(dbClient.activeRuleDao().selectByProfile(dbSession, child)).isEmpty();
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).isEmpty();
}
@Test
@@ -320,7 +320,7 @@ public class ChangeParentActionTest {
RuleDefinitionDto rule2 = createRule();
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
- ruleIndexer.commitAndIndex(dbSession, asList(rule1.getId(), rule2.getId()));
+ ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid()));
activeRuleIndexer.indexOnStartup(emptySet());
// Set parent 1
qProfileTree.setParentAndCommit(dbSession, child, parent1);
@@ -340,7 +340,7 @@ public class ChangeParentActionTest {
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().getRuleKey().rule()).isEqualTo(rule2.getRuleKey());
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).hasSize(1);
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
}
@Test
@@ -350,7 +350,7 @@ public class ChangeParentActionTest {
.setIsBuiltIn(true));
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
- assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).isEmpty();
+ assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).isEmpty();
TestRequest request = ws.newRequest()
.setMethod("POST")
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
index 07363a6278f..8e0dba6bee0 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
@@ -27,11 +27,11 @@ import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.DateUtils;
-import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileChangeDto;
@@ -47,7 +47,6 @@ import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
-import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.organization.OrganizationDto.Subscription.PAID;
import static org.sonar.test.JsonAssert.assertJson;
@@ -80,7 +79,7 @@ public class ChangelogActionTest {
UserDto user = db.users().insertUser();
RuleDefinitionDto rule = db.rules().insert(RuleKey.of("java", "S001"));
insertChange(profile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR",
"inheritance", ActiveRuleInheritance.INHERITED.name(),
"param_foo", "foo_value",
@@ -123,7 +122,7 @@ public class ChangelogActionTest {
UserDto user = db.users().insertUser();
insertChange(profile, ActiveRuleChange.Type.ACTIVATED, user,
ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR"));
String response = ws.newRequest()
@@ -156,7 +155,7 @@ public class ChangelogActionTest {
UserDto user = db.users().insertUser();
insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR"));
String response = ws.newRequest()
@@ -189,7 +188,7 @@ public class ChangelogActionTest {
UserDto user = db.users().insertUser();
insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR"));
String response = ws.newRequest()
@@ -239,7 +238,7 @@ public class ChangelogActionTest {
UserDto user = db.users().insertUser();
insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR"));
assertJson(ws.newRequest()
@@ -279,13 +278,13 @@ public class ChangelogActionTest {
RuleDefinitionDto rule1 = db.rules().insert();
insertChange(profile, ActiveRuleChange.Type.ACTIVATED, null,
ImmutableMap.of(
- "ruleId", valueOf(rule1.getId()),
+ "ruleUuid", rule1.getUuid(),
"severity", "MINOR"));
system2.setNow(DateUtils.parseDateTime("2011-04-25T01:15:43+0100").getTime());
UserDto user = db.users().insertUser();
RuleDefinitionDto rule2 = db.rules().insert();
insertChange(profile, ActiveRuleChange.Type.DEACTIVATED, user,
- ImmutableMap.of("ruleId", valueOf(rule2.getId())));
+ ImmutableMap.of("ruleUuid", rule2.getUuid()));
String response = ws.newRequest()
.setParam(PARAM_LANGUAGE, profile.getLanguage())
@@ -323,7 +322,7 @@ public class ChangelogActionTest {
QProfileDto qualityProfile = db.qualityProfiles().insert(organization);
UserDto user = db.users().insertUser();
insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
- ImmutableMap.of("ruleId", "123"));
+ ImmutableMap.of("ruleUuid", "123"));
String response = ws.newRequest()
.setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
@@ -352,7 +351,7 @@ public class ChangelogActionTest {
insertChange(c -> c.setRulesProfileUuid(qualityProfile.getRulesProfileUuid())
.setUserUuid("UNKNOWN")
.setChangeType(ActiveRuleChange.Type.ACTIVATED.name())
- .setData(ImmutableMap.of("ruleId", rule.getId())));
+ .setData(ImmutableMap.of("ruleUuid", rule.getUuid())));
String response = ws.newRequest()
.setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
@@ -384,7 +383,7 @@ public class ChangelogActionTest {
RuleDefinitionDto rule = db.rules().insert();
insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, db.users().insertUser(),
ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR"));
String response = ws.newRequest()
@@ -412,7 +411,7 @@ public class ChangelogActionTest {
UserDto user = db.users().insertUser();
insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
ImmutableMap.of(
- "ruleId", valueOf(rule.getId()),
+ "ruleUuid", rule.getUuid(),
"severity", "MINOR"));
expectedException.expect(NotFoundException.class);
@@ -451,23 +450,23 @@ public class ChangelogActionTest {
insertChange(c -> c.setRulesProfileUuid(profileUuid)
.setUserUuid(user1.getUuid())
.setChangeType(ActiveRuleChange.Type.ACTIVATED.name())
- .setData(ImmutableMap.of("severity", "CRITICAL", "ruleId", valueOf(rule1.getId()))));
+ .setData(ImmutableMap.of("severity", "CRITICAL", "ruleUuid", rule1.getUuid())));
system2.setNow(DateUtils.parseDateTime("2015-02-23T17:58:18+0100").getTime());
RuleDefinitionDto rule2 = db.rules().insert(RuleKey.of("squid", "S2162"), r -> r.setName("\"equals\" methods should be symmetric and work for subclasses"));
UserDto user2 = db.users().insertUser(u -> u.setLogin("padme.amidala").setName("Padme Amidala"));
- QProfileChangeDto change2 = insertChange(c -> c.setRulesProfileUuid(profileUuid)
+ insertChange(c -> c.setRulesProfileUuid(profileUuid)
.setUserUuid(user2.getUuid())
.setChangeType(ActiveRuleChange.Type.DEACTIVATED.name())
- .setData(ImmutableMap.of("ruleId", valueOf(rule2.getId()))));
+ .setData(ImmutableMap.of("ruleUuid", rule2.getUuid())));
system2.setNow(DateUtils.parseDateTime("2014-09-12T15:20:46+0200").getTime());
RuleDefinitionDto rule3 = db.rules().insert(RuleKey.of("squid", "S00101"), r -> r.setName("Class names should comply with a naming convention"));
UserDto user3 = db.users().insertUser(u -> u.setLogin("obiwan.kenobi").setName("Obiwan Kenobi"));
- QProfileChangeDto change3 = insertChange(c -> c.setRulesProfileUuid(profileUuid)
+ insertChange(c -> c.setRulesProfileUuid(profileUuid)
.setUserUuid(user3.getUuid())
.setChangeType(ActiveRuleChange.Type.ACTIVATED.name())
- .setData(ImmutableMap.of("severity", "MAJOR", "param_format", "^[A-Z][a-zA-Z0-9]*$", "ruleId", valueOf(rule3.getId()))));
+ .setData(ImmutableMap.of("severity", "MAJOR", "param_format", "^[A-Z][a-zA-Z0-9]*$", "ruleUuid", rule3.getUuid())));
String response = ws.newRequest()
.setMethod("GET")
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
index b82ff73745a..00f8baabc10 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
@@ -29,6 +29,7 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.server.ws.WebService;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -241,6 +242,7 @@ public class CompareActionTest {
private RuleDefinitionDto createRule(String lang, String id) {
RuleDto rule = RuleDto.createFor(RuleKey.of("blah", id))
+ .setUuid(Uuids.createFast())
.setName(StringUtils.capitalize(id))
.setLanguage(lang)
.setSeverity(Severity.BLOCKER)
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
index 89bac8aa014..5ae62daf598 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
@@ -247,7 +247,7 @@ public class CreateActionTest {
private void insertRule(RuleDefinitionDto ruleDto) {
dbClient.ruleDao().insert(dbSession, ruleDto);
dbSession.commit();
- ruleIndexer.commitAndIndex(dbSession, ruleDto.getId());
+ ruleIndexer.commitAndIndex(dbSession, ruleDto.getUuid());
}
private CreateWsResponse executeRequest(String name, String language) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
index cbdcb172812..a9ce0bf03bc 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
@@ -67,7 +67,7 @@ public class DeactivateRuleActionTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private ArgumentCaptor<Collection<Integer>> ruleIdsCaptor = ArgumentCaptor.forClass(Collection.class);
+ private ArgumentCaptor<Collection<String>> ruleUuidsCaptor = ArgumentCaptor.forClass(Collection.class);
private DbClient dbClient = db.getDbClient();
private QProfileRules qProfileRules = mock(QProfileRules.class);
private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
@@ -105,8 +105,8 @@ public class DeactivateRuleActionTest {
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
ArgumentCaptor<QProfileDto> qProfileDtoCaptor = ArgumentCaptor.forClass(QProfileDto.class);
- verify(qProfileRules).deactivateAndCommit(any(DbSession.class), qProfileDtoCaptor.capture(), ruleIdsCaptor.capture());
- assertThat(ruleIdsCaptor.getValue()).containsExactly(rule.getId());
+ verify(qProfileRules).deactivateAndCommit(any(DbSession.class), qProfileDtoCaptor.capture(), ruleUuidsCaptor.capture());
+ assertThat(ruleUuidsCaptor.getValue()).containsExactly(rule.getUuid());
assertThat(qProfileDtoCaptor.getValue().getKee()).isEqualTo(qualityProfile.getKee());
}
@@ -125,8 +125,8 @@ public class DeactivateRuleActionTest {
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
ArgumentCaptor<QProfileDto> qProfileDtoCaptor = ArgumentCaptor.forClass(QProfileDto.class);
- verify(qProfileRules).deactivateAndCommit(any(DbSession.class), qProfileDtoCaptor.capture(), ruleIdsCaptor.capture());
- assertThat(ruleIdsCaptor.getValue()).containsExactly(rule.getId());
+ verify(qProfileRules).deactivateAndCommit(any(DbSession.class), qProfileDtoCaptor.capture(), ruleUuidsCaptor.capture());
+ assertThat(ruleUuidsCaptor.getValue()).containsExactly(rule.getUuid());
assertThat(qProfileDtoCaptor.getValue().getKee()).isEqualTo(qualityProfile.getKee());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
index 6f6f794c5bb..2121a1aeb7a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
@@ -148,7 +148,7 @@ public class InheritanceActionTest {
RuleDefinitionDto rule1 = db.rules().insert();
RuleDefinitionDto rule2 = db.rules().insert();
RuleDefinitionDto rule3 = db.rules().insert();
- ruleIndexer.commitAndIndex(db.getSession(), asList(rule1.getId(), rule2.getId(), rule3.getId()));
+ ruleIndexer.commitAndIndex(db.getSession(), asList(rule1.getUuid(), rule2.getUuid(), rule3.getUuid()));
QProfileDto parent = db.qualityProfiles().insert(organization);
db.qualityProfiles().activateRule(parent, rule1);
@@ -182,7 +182,7 @@ public class InheritanceActionTest {
public void inheritance_ignores_removed_rules() throws Exception {
OrganizationDto organization = db.organizations().insert();
RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED));
- ruleIndexer.commitAndIndex(db.getSession(), rule.getId());
+ ruleIndexer.commitAndIndex(db.getSession(), rule.getUuid());
QProfileDto profile = db.qualityProfiles().insert(organization);
db.qualityProfiles().activateRule(profile, rule);
@@ -207,7 +207,7 @@ public class InheritanceActionTest {
public void inheritance_no_family() {
// Simple profile, no parent, no child
OrganizationDto organization = db.organizations().insert();
- QProfileDto remi = createProfile(organization,"xoo", "Nobodys Boy", "xoo-nobody-s-boy-01234");
+ QProfileDto remi = createProfile(organization, "xoo", "Nobodys Boy", "xoo-nobody-s-boy-01234");
String response = ws.newRequest()
.setParam(PARAM_LANGUAGE, remi.getLanguage())
@@ -281,7 +281,7 @@ public class InheritanceActionTest {
.setUpdatedAt(now)
.setCreatedAt(now);
dbClient.ruleDao().insert(dbSession, rule);
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
return rule;
}
@@ -296,6 +296,6 @@ public class InheritanceActionTest {
}
private void overrideActiveRuleSeverity(RuleDefinitionDto rule, QProfileDto profile, String severity) {
- qProfileRules.activateAndCommit(dbSession, profile, singleton(RuleActivation.create(rule.getId(), severity, null)));
+ qProfileRules.activateAndCommit(dbSession, profile, singleton(RuleActivation.create(rule.getUuid(), severity, null)));
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
index 76c299bf5dd..01785428cc1 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
@@ -110,7 +110,7 @@ public class QProfilesWsMediumTest {
QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
createActiveRule(rule, profile);
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
// 0. Assert No Active Rule for profile
@@ -209,7 +209,7 @@ public class QProfilesWsMediumTest {
public void activate_rule() {
QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
// 0. Assert No Active Rule for profile
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
@@ -229,7 +229,7 @@ public class QProfilesWsMediumTest {
public void activate_rule_diff_languages() {
QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule("php", "toto");
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
// 0. Assert No Active Rule for profile
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
@@ -251,7 +251,7 @@ public class QProfilesWsMediumTest {
public void activate_rule_override_severity() {
QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
// 0. Assert No Active Rule for profile
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
@@ -367,7 +367,7 @@ public class QProfilesWsMediumTest {
// 2. Assert ActiveRule with BLOCKER severity
assertThat(ruleIndex.search(
new RuleQuery().setSeverities(ImmutableSet.of("BLOCKER")),
- new SearchOptions()).getIds()).hasSize(2);
+ new SearchOptions()).getUuids()).hasSize(2);
// 1. Activate Rule with query returning 2 hits
wsActivateRules.newRequest().setMethod("POST")
@@ -377,7 +377,7 @@ public class QProfilesWsMediumTest {
dbSession.commit();
// 2. Assert ActiveRule with MINOR severity
- assertThat(dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule0.getId()).get(0).getSeverityString()).isEqualTo("MINOR");
+ assertThat(dbClient.activeRuleDao().selectByRuleUuid(dbSession, organization, rule0.getUuid()).get(0).getSeverityString()).isEqualTo("MINOR");
assertThat(ruleIndex.searchAll(new RuleQuery()
.setQProfile(profile)
.setKey(rule0.getKey().toString())
@@ -456,7 +456,7 @@ public class QProfilesWsMediumTest {
.setSeverity(Severity.BLOCKER)
.setStatus(RuleStatus.READY);
dbClient.ruleDao().insert(dbSession, rule);
- ruleIndexer.commitAndIndex(dbSession, rule.getId());
+ ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
return rule;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
index 5a5ae107d40..a9f4d089c82 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
@@ -34,6 +34,8 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.rule.RuleDefinitionDto;
@@ -71,9 +73,10 @@ public class RuleCreatorTest {
private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbTester.getDbClient());
private DbSession dbSession = dbTester.getSession();
+ private UuidFactory uuidFactory = new SequenceUuidFactory();
private RuleCreator underTest = new RuleCreator(system2, new RuleIndexer(es.client(), dbTester.getDbClient()), dbTester.getDbClient(), newFullTypeValidations(),
- TestDefaultOrganizationProvider.from(dbTester));
+ TestDefaultOrganizationProvider.from(dbTester), uuidFactory);
@Test
public void create_custom_rule() {
@@ -92,7 +95,7 @@ public class RuleCreatorTest {
assertThat(rule).isNotNull();
assertThat(rule.getKey()).isEqualTo(RuleKey.of("java", "CUSTOM_RULE"));
assertThat(rule.getPluginKey()).isEqualTo("sonarjava");
- assertThat(rule.getTemplateId()).isEqualTo(templateRule.getId());
+ assertThat(rule.getTemplateUuid()).isEqualTo(templateRule.getUuid());
assertThat(rule.getName()).isEqualTo("My custom");
assertThat(rule.getDescription()).isEqualTo("Some description");
assertThat(rule.getSeverityString()).isEqualTo("MAJOR");
@@ -120,7 +123,7 @@ public class RuleCreatorTest {
// From user
assertThat(param.getDefaultValue()).isEqualTo("a.*");
- assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule.getId(), templateRule.getId());
+ assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).containsOnly(rule.getUuid(), templateRule.getUuid());
}
@Test
@@ -524,9 +527,9 @@ public class RuleCreatorTest {
.setCreatedAt(new Date().getTime())
.setUpdatedAt(new Date().getTime());
dbTester.rules().insert(templateRule.getDefinition());
- dbTester.rules().insertOrUpdateMetadata(templateRule.getMetadata().setRuleId(templateRule.getId()));
+ dbTester.rules().insertOrUpdateMetadata(templateRule.getMetadata().setRuleUuid(templateRule.getUuid()));
dbTester.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*"));
- ruleIndexer.commitAndIndex(dbTester.getSession(), templateRule.getDefinition().getId());
+ ruleIndexer.commitAndIndex(dbTester.getSession(), templateRule.getDefinition().getUuid());
return templateRule;
}
@@ -544,7 +547,7 @@ public class RuleCreatorTest {
dbTester.rules().insert(templateRule);
dbTester.rules().insertRuleParam(templateRule,
param -> param.setName("myIntegers").setType("INTEGER,multiple=true,values=1;2;3").setDescription("My Integers").setDefaultValue("1"));
- ruleIndexer.commitAndIndex(dbTester.getSession(), templateRule.getId());
+ ruleIndexer.commitAndIndex(dbTester.getSession(), templateRule.getUuid());
return templateRule;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
index 74915655c0e..f2a539aec00 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
@@ -112,7 +112,7 @@ public class RuleUpdaterTest {
.setRemediationGapMultiplier("1d")
.setRemediationBaseEffort("5min");
db.rules().insert(ruleDto.getDefinition());
- db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleId(ruleDto.getId()));
+ db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid()));
dbSession.commit();
RuleUpdate update = createForPluginRule(RULE_KEY);
@@ -144,7 +144,7 @@ public class RuleUpdaterTest {
.setRemediationGapMultiplier("1d")
.setRemediationBaseEffort("5min");
db.rules().insert(ruleDto.getDefinition());
- db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleId(ruleDto.getId()));
+ db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid()));
dbSession.commit();
RuleUpdate update = createForPluginRule(RULE_KEY)
@@ -171,7 +171,7 @@ public class RuleUpdaterTest {
.setNoteData("my *note*")
.setNoteUserUuid("me");
db.rules().insert(ruleDto.getDefinition());
- db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleId(ruleDto.getId()));
+ db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid()));
dbSession.commit();
RuleUpdate update = createForPluginRule(RULE_KEY)
@@ -213,6 +213,7 @@ public class RuleUpdaterTest {
@Test
public void remove_tags() {
RuleDto ruleDto = RuleTesting.newDto(RULE_KEY, db.getDefaultOrganization())
+ .setUuid("57a3af91-32f8-48b0-9e11-0eac14ffa915")
.setTags(Sets.newHashSet("security"))
.setSystemTags(Sets.newHashSet("java8", "javadoc"));
db.rules().insert(ruleDto.getDefinition());
@@ -320,7 +321,7 @@ public class RuleUpdaterTest {
.setRemediationGapMultiplier(null)
.setRemediationBaseEffort("1min");
db.rules().insert(ruleDto.getDefinition());
- db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleId(ruleDto.getId()));
+ db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid()));
dbSession.commit();
RuleUpdate update = createForPluginRule(RULE_KEY)
@@ -383,8 +384,8 @@ public class RuleUpdaterTest {
assertThat(params).extracting(RuleParamDto::getDefaultValue).containsOnly("b.*", null);
// Verify in index
- assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(customRule.getId());
- assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(customRule.getId());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getUuids()).containsOnly(customRule.getUuid());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getUuids()).containsOnly(customRule.getUuid());
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero();
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero();
@@ -453,7 +454,7 @@ public class RuleUpdaterTest {
// Activate the custom rule
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
.setProfileUuid(profileDto.getRulesProfileUuid())
- .setRuleId(customRule.getId())
+ .setRuleUuid(customRule.getUuid())
.setSeverity(Severity.BLOCKER);
db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, new ActiveRuleParamDto()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java
index 6d802c959d5..24fb092c90c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java
@@ -27,6 +27,8 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbTester;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
@@ -73,10 +75,11 @@ public class CreateActionTest {
public EsTester es = EsTester.create();
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
+ private UuidFactory uuidFactory = new SequenceUuidFactory();
private WsActionTester ws = new WsActionTester(new CreateAction(db.getDbClient(),
new RuleCreator(system2, new RuleIndexer(es.client(), db.getDbClient()), db.getDbClient(), newFullTypeValidations(),
- TestDefaultOrganizationProvider.from(db)),
+ TestDefaultOrganizationProvider.from(db), uuidFactory),
new RuleMapper(new Languages(), createMacroInterpreter()),
new RuleWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider)));
@@ -94,7 +97,7 @@ public class CreateActionTest {
// Template rule
RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001"), db.getDefaultOrganization()).setType(CODE_SMELL);
db.rules().insert(templateRule.getDefinition());
- db.rules().insertOrUpdateMetadata(templateRule.getMetadata().setRuleId(templateRule.getId()));
+ db.rules().insertOrUpdateMetadata(templateRule.getMetadata().setRuleUuid(templateRule.getUuid()));
db.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*"));
String result = ws.newRequest()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java
index 9c680ebe303..542dd291068 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java
@@ -76,7 +76,7 @@ public class DeleteActionTest {
r -> r.setCreatedAt(PAST),
r -> r.setUpdatedAt(PAST));
RuleDefinitionDto customRule = dbTester.rules().insert(
- r -> r.setTemplateId(templateRule.getId()),
+ r -> r.setTemplateUuid(templateRule.getUuid()),
r -> r.setCreatedAt(PAST),
r -> r.setUpdatedAt(PAST));
@@ -85,7 +85,7 @@ public class DeleteActionTest {
.setParam("key", customRule.getKey().toString())
.execute();
- verify(ruleIndexer).commitAndIndex(any(), eq(customRule.getId()));
+ verify(ruleIndexer).commitAndIndex(any(), eq(customRule.getUuid()));
// Verify custom rule has status REMOVED
RuleDefinitionDto customRuleReloaded = dbClient.ruleDao().selectOrFailDefinitionByKey(dbSession, customRule.getKey());
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
index 928ab44e12e..751668263af 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
@@ -589,7 +589,7 @@ public class SearchActionTest {
RuleDefinitionDto templateRule = db.rules().insert(r -> r.setLanguage("java")
.setIsTemplate(true));
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")
- .setTemplateId(templateRule.getId()));
+ .setTemplateUuid(templateRule.getUuid()));
indexRules();
@@ -611,7 +611,7 @@ public class SearchActionTest {
RuleDefinitionDto templateRule = db.rules().insert(r -> r.setLanguage("java")
.setIsTemplate(true));
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")
- .setTemplateId(templateRule.getId()));
+ .setTemplateUuid(templateRule.getUuid()));
indexRules();
@@ -644,7 +644,7 @@ public class SearchActionTest {
OrganizationDto organization = db.organizations().insert();
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage("java"));
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
- RuleActivation activation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
indexRules();
@@ -685,7 +685,7 @@ public class SearchActionTest {
.setDescription("Empty Param")
.setName("empty_var"));
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> activeRuleChanges1 = qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
qProfileRules.activateAndCommit(db.getSession(), waterproofProfile, singleton(activation));
assertThat(activeRuleChanges1).hasSize(1);
@@ -734,7 +734,7 @@ public class SearchActionTest {
.setDescription("My small description")
.setName("my_var"));
- RuleActivation activation = RuleActivation.create(rule.getId());
+ RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> activeRuleChanges = qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
// Insert directly in database a rule parameter with a null value
@@ -795,7 +795,7 @@ public class SearchActionTest {
.setSeverity("MAJOR")
.setStatus(RuleStatus.DEPRECATED)
.setType(RuleType.VULNERABILITY));
- RuleActivation activation = RuleActivation.create(rule2.getId(), null, null);
+ RuleActivation activation = RuleActivation.create(rule2.getUuid(), null, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
// on other language, not activated => no match
@@ -929,7 +929,7 @@ public class SearchActionTest {
OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(PAID));
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage("java"));
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
- RuleActivation activation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
userSession.logIn(db.users().insertUser()).addMembership(organization);
@@ -949,7 +949,7 @@ public class SearchActionTest {
OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(PAID));
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage("java"));
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
- RuleActivation activation = RuleActivation.create(rule.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
indexRules();
@@ -969,7 +969,7 @@ public class SearchActionTest {
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage("java"));
// Rule1 is activated on profile
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("java"));
- RuleActivation activation = RuleActivation.create(rule1.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule1.getUuid(), BLOCKER, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
// Rule2 is not activated
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("java"));
@@ -994,7 +994,7 @@ public class SearchActionTest {
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage("java"));
// Rule1 is activated on profile
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("java"));
- RuleActivation activation = RuleActivation.create(rule1.getId(), BLOCKER, null);
+ RuleActivation activation = RuleActivation.create(rule1.getUuid(), BLOCKER, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
// Rule2 is not activated
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("java"));
@@ -1025,7 +1025,7 @@ public class SearchActionTest {
@SafeVarargs
private final RuleMetadataDto insertMetadata(OrganizationDto organization, RuleDefinitionDto rule, Consumer<RuleMetadataDto>... populaters) {
RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(rule, organization, populaters);
- ruleIndexer.commitAndIndex(db.getSession(), rule.getId(), organization);
+ ruleIndexer.commitAndIndex(db.getSession(), rule.getUuid(), organization);
return metadata;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java
index 97991070256..e4204570e4d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java
@@ -98,7 +98,7 @@ public class TagsActionTest {
@Test
public void system_tag() {
RuleDefinitionDto r = db.rules().insert(setSystemTags("tag"));
- ruleIndexer.commitAndIndex(db.getSession(), r.getId());
+ ruleIndexer.commitAndIndex(db.getSession(), r.getUuid());
String result = ws.newRequest().execute().getInput();
assertJson(result).isSimilarTo("{\"tags\":[\"tag\"]}");
@@ -107,9 +107,9 @@ public class TagsActionTest {
@Test
public void tag() {
RuleDefinitionDto r = db.rules().insert(setSystemTags());
- ruleIndexer.commitAndIndex(db.getSession(), r.getId());
+ ruleIndexer.commitAndIndex(db.getSession(), r.getUuid());
db.rules().insertOrUpdateMetadata(r, organization, setTags("tag"));
- ruleIndexer.commitAndIndex(db.getSession(), r.getId(), organization);
+ ruleIndexer.commitAndIndex(db.getSession(), r.getUuid(), organization);
String result = ws.newRequest().setParam("organization", organization.getKey()).execute().getInput();
assertJson(result).isSimilarTo("{\"tags\":[\"tag\"]}");
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java
index 37244806b80..0419187f977 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java
@@ -118,7 +118,7 @@ public class UpdateActionTest {
r -> r.setDescription("Old description"),
r -> r.setSeverity(Severity.MINOR),
r -> r.setStatus(RuleStatus.BETA),
- r -> r.setTemplateId(templateRule.getId()),
+ r -> r.setTemplateUuid(templateRule.getUuid()),
r -> r.setLanguage("js"),
r -> r.setCreatedAt(PAST),
r -> r.setUpdatedAt(PAST));
@@ -284,7 +284,7 @@ public class UpdateActionTest {
r -> r.setRuleKey(RuleKey.of("java", "MY_CUSTOM")),
r -> r.setName("Old custom"),
r -> r.setDescription("Old description"),
- r -> r.setTemplateId(templateRule.getId()),
+ r -> r.setTemplateUuid(templateRule.getUuid()),
r -> r.setCreatedAt(PAST),
r -> r.setUpdatedAt(PAST));
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
index 0acee4c0a30..5915ff716ce 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
@@ -34,7 +34,6 @@ import org.sonar.api.rule.RuleStatus;
public class DefaultRule implements Rule {
private final RuleKey key;
- private final Integer id;
private final String name;
private final String severity;
private final String type;
@@ -45,7 +44,6 @@ public class DefaultRule implements Rule {
public DefaultRule(NewRule newRule) {
this.key = newRule.key;
- this.id = newRule.id;
this.name = newRule.name;
this.severity = newRule.severity;
this.type = newRule.type;
@@ -65,11 +63,6 @@ public class DefaultRule implements Rule {
return key;
}
- @CheckForNull
- public Integer id() {
- return id;
- }
-
@Override
public String name() {
return name;
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
index 3cef62bbf2f..116f82621a8 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
@@ -33,7 +33,6 @@ public class NewRule {
private static final String DEFAULT_SEVERITY = Severity.defaultSeverity();
final RuleKey key;
- Integer id;
String name;
String description;
String severity = DEFAULT_SEVERITY;
@@ -46,11 +45,6 @@ public class NewRule {
this.key = key;
}
- public NewRule setId(@Nullable Integer id) {
- this.id = id;
- return this;
- }
-
public NewRule setDescription(@Nullable String description) {
this.description = description;
return this;
@@ -65,7 +59,7 @@ public class NewRule {
this.severity = StringUtils.defaultIfBlank(severity, DEFAULT_SEVERITY);
return this;
}
-
+
public NewRule setType(@Nullable String type) {
this.type = type;
return this;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index aca64a548c7..d2e5cd0778b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -66,8 +66,6 @@ public class Rule {
*/
private static final Set<String> STATUS_LIST = unmodifiableSet(new LinkedHashSet<>(asList(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED)));
- private Integer id;
-
/**
* The default priority given to a rule if not explicitly set
*/
@@ -111,16 +109,12 @@ public class Rule {
this.configKey = key;
}
- public Integer getId() {
- return id;
- }
-
/**
- * @deprecated since 2.3. visibility should be decreased to protected or package
+ * @deprecated since 8.4. Use {@link #ruleKey()} instead
*/
@Deprecated
- public void setId(Integer id) {
- this.id = id;
+ public Integer getId() {
+ return null;
}
public String getName() {
@@ -476,7 +470,6 @@ public class Rule {
public String toString() {
// Note that ReflectionToStringBuilder will not work here - see SONAR-3077
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
- .append("id", id)
.append("name", name)
.append("key", key)
.append("configKey", configKey)
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
index 9fd218fec90..47a0190ac6e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
@@ -35,14 +35,6 @@ import org.sonar.api.server.ServerSide;
@ComputeEngineSide
public interface RuleFinder {
- /**
- * @since 2.5
- * @deprecated since 4.4, Please use {@link #findByKey(org.sonar.api.rule.RuleKey)}}
- */
- @CheckForNull
- @Deprecated
- Rule findById(int ruleId);
-
@CheckForNull
Rule findByKey(String repositoryKey, String key);