aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-03-24 11:13:08 -0500
committersonartech <sonartech@sonarsource.com>2020-04-14 20:04:04 +0000
commitd8081f847f92247a64166572605876e67e9a34ed (patch)
tree6d267df0fdb86df044c04c7436e465318cdf8afa
parentd662d0c0269e1a12da0c3ecdb8f9d33b765ccdcc (diff)
downloadsonarqube-d8081f847f92247a64166572605876e67e9a34ed.tar.gz
sonarqube-d8081f847f92247a64166572605876e67e9a34ed.zip
SONAR-13193 Stop using legacy project ID and use project UUID instead
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepository.java27
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MapBasedDbIdsRepository.java61
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepository.java27
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MovedFilesRepository.java11
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImplTest.java63
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepositoryRule.java80
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImplTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ClosedIssuesInputFactoryTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RemoveProcessedComponentsVisitorTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerBaseInputFactoryTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java28
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java5
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java15
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/FileMoveRowDto.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ResourceDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java20
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/CountPerProjectPermission.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java46
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java32
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionMapper.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java47
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPair.java77
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java39
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java25
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java7
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ProjectQprofileAssociationDto.java5
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml39
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml151
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml86
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml42
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml86
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml28
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml5
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml12
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl21
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java92
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java251
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java237
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java94
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java398
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java21
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoAssert.java93
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java16
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java49
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java77
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java34
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java20
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java24
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java4
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java6
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java6
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java30
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java17
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java70
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRoles.java72
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToProperties.java59
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRoles.java58
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java14
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTable.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTable.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTable.java (renamed from server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPairs.java)27
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTable.java (renamed from server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImpl.java)27
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRoles.java55
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInProperties.java56
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRoles.java56
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest.java49
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest.java (renamed from server/sonar-db-dao/src/test/java/org/sonar/db/purge/IdUuidPairsTest.java)39
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest.java48
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest.java49
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest.java46
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest.java49
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest.java87
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest.java89
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest.java87
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql10
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql12
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql10
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest/schema.sql44
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql13
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql14
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql12
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql58
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql59
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql57
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java6
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java6
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java6
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java2
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/ProjectUuid.java (renamed from server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/ProjectId.java)13
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java30
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java4
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java14
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/BackendCleanup.java7
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/BackendCleanupTest.java2
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java4
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java2
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java36
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java14
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java59
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java27
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java7
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java48
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java18
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java38
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java38
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java18
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java14
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java13
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java25
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java7
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java30
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java20
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java8
-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/SearchActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java38
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java24
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java52
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java36
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java32
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java12
-rw-r--r--sonar-ws/src/main/protobuf/ws-qualitygates.proto1
188 files changed, 2815 insertions, 2416 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepository.java
deleted file mode 100644
index fc038a2ba57..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepository.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.ce.task.projectanalysis.component;
-
-public interface DbIdsRepository {
- /**
- * @throws IllegalStateException if there is no id for the specified Component
- */
- long getComponentId(Component component);
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MapBasedDbIdsRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MapBasedDbIdsRepository.java
deleted file mode 100644
index d795b085245..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MapBasedDbIdsRepository.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.ce.task.projectanalysis.component;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Function;
-
-import static com.google.common.base.Preconditions.checkState;
-
-/**
- * Cache of database ids for components (component id and snapshot id) based in Maps.
- *
- * This class is intended as a to be used as a delegate in another implementation of MutableDbIdsRepository, hence the
- * final keyword.
- */
-public final class MapBasedDbIdsRepository<T> implements MutableDbIdsRepository {
-
- private final Function<Component, T> componentToKey;
- private final Map<T, Long> componentIdsByRef = new HashMap<>();
-
- public MapBasedDbIdsRepository(Function<Component, T> componentToKey) {
- this.componentToKey = componentToKey;
- }
-
- @Override
- public DbIdsRepository setComponentId(Component component, long componentId) {
- T ref = componentToKey.apply(component);
- Long existingComponentId = componentIdsByRef.get(ref);
- checkState(existingComponentId == null,
- "Component id '%s' is already registered in repository for Component '%s', can not set new id '%s'", existingComponentId, component.getDbKey(), componentId);
- componentIdsByRef.put(ref, componentId);
- return this;
- }
-
- @Override
- public long getComponentId(Component component) {
- T ref = componentToKey.apply(component);
- Long componentId = componentIdsByRef.get(ref);
- checkState(componentId != null, "No component id registered in repository for Component '%s'", component.getDbKey());
- return componentId;
- }
-
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepository.java
deleted file mode 100644
index e1383b75a91..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepository.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.ce.task.projectanalysis.component;
-
-public interface MutableDbIdsRepository extends DbIdsRepository {
- /**
- * @throws IllegalStateException if the component id for the specified component has already been set
- */
- DbIdsRepository setComponentId(Component component, long componentId);
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
index f38405ef195..cfc3da144b5 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
@@ -32,7 +32,6 @@ import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderImpl;
import org.sonar.ce.task.projectanalysis.component.BranchLoader;
import org.sonar.ce.task.projectanalysis.component.BranchPersisterImpl;
import org.sonar.ce.task.projectanalysis.component.ConfigurationRepositoryImpl;
-import org.sonar.ce.task.projectanalysis.component.DbIdsRepositoryImpl;
import org.sonar.ce.task.projectanalysis.component.DisabledComponentsHolderImpl;
import org.sonar.ce.task.projectanalysis.component.ProjectPersister;
import org.sonar.ce.task.projectanalysis.component.ReferenceBranchComponentUuids;
@@ -208,7 +207,6 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop
MeasureRepositoryImpl.class,
EventRepositoryImpl.class,
ConfigurationRepositoryImpl.class,
- DbIdsRepositoryImpl.class,
DisabledComponentsHolderImpl.class,
QualityGateServiceImpl.class,
EvaluationResultTextConverterImpl.class,
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
index 4f28c15ddbe..a82e6b67576 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
@@ -201,7 +201,7 @@ public class FileMoveDetectionStep implements ComputationStep {
dbClient.componentDao().scrollAllFilesForFileMove(dbSession, rootHolder.getRoot().getUuid(),
resultContext -> {
FileMoveRowDto row = resultContext.getResultObject();
- builder.add(new DbComponent(row.getId(), row.getKey(), row.getUuid(), row.getPath(), row.getLineCount()));
+ builder.add(new DbComponent(row.getKey(), row.getUuid(), row.getPath(), row.getLineCount()));
});
return builder.build().stream()
.collect(MoreCollectors.uniqueIndex(DbComponent::getUuid));
@@ -363,29 +363,23 @@ public class FileMoveDetectionStep implements ComputationStep {
}
private static MovedFilesRepository.OriginalFile toOriginalFile(DbComponent dbComponent) {
- return new MovedFilesRepository.OriginalFile(dbComponent.getId(), dbComponent.getUuid(), dbComponent.getKey());
+ return new MovedFilesRepository.OriginalFile(dbComponent.getUuid(), dbComponent.getKey());
}
@Immutable
private static final class DbComponent {
- private final long id;
private final String key;
private final String uuid;
private final String path;
private final int lineCount;
- private DbComponent(long id, String key, String uuid, String path, int lineCount) {
- this.id = id;
+ private DbComponent(String key, String uuid, String path, int lineCount) {
this.key = key;
this.uuid = uuid;
this.path = path;
this.lineCount = lineCount;
}
- public long getId() {
- return id;
- }
-
public String getKey() {
return key;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MovedFilesRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MovedFilesRepository.java
index ddd90a7467b..e15fcd32fc3 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MovedFilesRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MovedFilesRepository.java
@@ -35,20 +35,14 @@ public interface MovedFilesRepository {
Optional<OriginalFile> getOriginalFile(Component file);
final class OriginalFile {
- private final long id;
private final String uuid;
private final String key;
- public OriginalFile(long id, String uuid, String key) {
- this.id = id;
+ public OriginalFile(String uuid, String key) {
this.uuid = requireNonNull(uuid, "uuid can not be null");
this.key = requireNonNull(key, "key can not be null");
}
- public long getId() {
- return id;
- }
-
public String getUuid() {
return uuid;
}
@@ -77,8 +71,7 @@ public interface MovedFilesRepository {
@Override
public String toString() {
return "OriginalFile{" +
- "id=" + id +
- ", uuid='" + uuid + '\'' +
+ "uuid='" + uuid + '\'' +
", key='" + key + '\'' +
'}';
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
index 2ed3f307a52..5996e150430 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
@@ -38,8 +38,6 @@ import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.component.BranchPersister;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
-import org.sonar.ce.task.projectanalysis.component.DbIdsRepositoryImpl;
-import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepository;
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder;
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler;
import org.sonar.ce.task.projectanalysis.component.PathAwareVisitor;
@@ -62,25 +60,21 @@ import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
/**
* Persist report components
- * Also feed the components cache {@link DbIdsRepositoryImpl} with component ids
*/
public class PersistComponentsStep implements ComputationStep {
private final DbClient dbClient;
private final TreeRootHolder treeRootHolder;
- private final MutableDbIdsRepository dbIdsRepository;
private final System2 system2;
private final MutableDisabledComponentsHolder disabledComponentsHolder;
private final AnalysisMetadataHolder analysisMetadataHolder;
private final BranchPersister branchPersister;
private final ProjectPersister projectPersister;
- public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder,
- MutableDbIdsRepository dbIdsRepository, System2 system2,
+ public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder, System2 system2,
MutableDisabledComponentsHolder disabledComponentsHolder, AnalysisMetadataHolder analysisMetadataHolder,
BranchPersister branchPersister, ProjectPersister projectPersister) {
this.dbClient = dbClient;
this.treeRootHolder = treeRootHolder;
- this.dbIdsRepository = dbIdsRepository;
this.system2 = system2;
this.disabledComponentsHolder = disabledComponentsHolder;
this.analysisMetadataHolder = analysisMetadataHolder;
@@ -172,6 +166,7 @@ public class PersistComponentsStep implements ComputationStep {
private final DbSession dbSession;
@Nullable
private final String mainBranchProjectUuid;
+ private int componentRef = 1;
PersistComponentStepsVisitor(Map<String, ComponentDto> existingComponentDtosByUuids, DbSession dbSession, @Nullable String mainBranchProjectUuid) {
super(
@@ -238,7 +233,6 @@ public class PersistComponentsStep implements ComputationStep {
private ComponentDto persistAndPopulateCache(Component component, ComponentDto dto) {
ComponentDto projectDto = persistComponent(dto);
- addToCache(component, projectDto);
return projectDto;
}
@@ -273,10 +267,6 @@ public class PersistComponentsStep implements ComputationStep {
return existingComponent;
}
- private void addToCache(Component component, ComponentDto componentDto) {
- dbIdsRepository.setComponentId(component, componentDto.getId());
- }
-
public ComponentDto createForProject(Component project) {
ComponentDto res = createBase(project);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
index 6c8b5144e8c..301d92dbcae 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
@@ -140,6 +140,6 @@ public class ConfigurationRepositoryTest {
}
private void insertProjectProperty(ComponentDto project, String propertyKey, String propertyValue) {
- db.properties().insertProperties(new PropertyDto().setKey(propertyKey).setValue(propertyValue).setResourceId(project.getId()));
+ db.properties().insertProperties(new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid()));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImplTest.java
deleted file mode 100644
index 0ea37c18007..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImplTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.ce.task.projectanalysis.component;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
-
-public class DbIdsRepositoryImplTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private static final String SOME_COMPONENT_KEY = "SOME_COMPONENT_KEY";
- private static final Component SOME_COMPONENT = ReportComponent.builder(PROJECT, 1).setKey(SOME_COMPONENT_KEY).build();
-
- @Test
- public void add_and_get_component_id() {
- DbIdsRepositoryImpl cache = new DbIdsRepositoryImpl();
- cache.setComponentId(SOME_COMPONENT, 10L);
-
- assertThat(cache.getComponentId(SOME_COMPONENT)).isEqualTo(10L);
- }
-
- @Test
- public void fail_to_get_component_id_on_unknown_ref() {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("No component id registered in repository for Component '" + SOME_COMPONENT_KEY + "'");
-
- new DbIdsRepositoryImpl().getComponentId(SOME_COMPONENT);
- }
-
- @Test
- public void fail_if_component_id_already_set() {
- DbIdsRepositoryImpl cache = new DbIdsRepositoryImpl();
- cache.setComponentId(SOME_COMPONENT, 10L);
-
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Component id '10' is already registered in repository for Component '" + SOME_COMPONENT_KEY + "', can not set new id '11'");
- cache.setComponentId(SOME_COMPONENT, 11L);
- }
-
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepositoryRule.java
deleted file mode 100644
index d0bd8ae59c0..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepositoryRule.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.ce.task.projectanalysis.component;
-
-import java.util.function.Function;
-import javax.annotation.Nullable;
-import org.junit.rules.ExternalResource;
-
-/**
- * Implementation of {@link DbIdsRepository} as a JUnit {@link org.junit.Rule} which supports both
- * {@link ViewsComponent} and {@link ReportComponent}.
- */
-public class MutableDbIdsRepositoryRule extends ExternalResource implements MutableDbIdsRepository {
- private final ComponentProvider componentProvider;
- private MutableDbIdsRepository delegate = newDelegate();
-
- private MutableDbIdsRepositoryRule(ComponentProvider componentProvider) {
- this.componentProvider = componentProvider;
- }
-
- public static MutableDbIdsRepositoryRule standalone() {
- return new MutableDbIdsRepositoryRule(NoComponentProvider.INSTANCE);
- }
-
- public static MutableDbIdsRepositoryRule create(TreeRootHolderRule treeRootHolder) {
- return new MutableDbIdsRepositoryRule(new TreeRootHolderComponentProvider(treeRootHolder));
- }
-
- public static MutableDbIdsRepositoryRule create(Component root) {
- return new MutableDbIdsRepositoryRule(new TreeComponentProvider(root));
- }
-
- private static MapBasedDbIdsRepository<String> newDelegate() {
- return new MapBasedDbIdsRepository<>(new Function<Component, String>() {
- @Nullable
- @Override
- public String apply(Component input) {
- return input.getType().isReportType() ? input.getUuid() : input.getDbKey();
- }
- });
- }
-
- @Override
- protected void before() {
- this.delegate = newDelegate();
- }
-
- public DbIdsRepository setComponentId(int componentRef, long componentId) {
- this.componentProvider.ensureInitialized();
- return delegate.setComponentId(componentProvider.getByRef(componentRef), componentId);
- }
-
- @Override
- public DbIdsRepository setComponentId(Component component, long componentId) {
- return delegate.setComponentId(component, componentId);
- }
-
- @Override
- public long getComponentId(Component component) {
- return delegate.getComponentId(component);
- }
-
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java
index 6393b7f7dec..54173e19e6d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java
@@ -330,7 +330,6 @@ public class FileMoveDetectionStepTest {
assertThat(movedFilesRepository.getComponentsWithOriginal()).containsExactly(file2);
MovedFilesRepository.OriginalFile originalFile = movedFilesRepository.getOriginalFile(file2).get();
- assertThat(originalFile.getId()).isEqualTo(dtos[0].getId());
assertThat(originalFile.getKey()).isEqualTo(dtos[0].getDbKey());
assertThat(originalFile.getUuid()).isEqualTo(dtos[0].uuid());
assertThat(addedFileRepository.getComponents()).isEmpty();
@@ -496,11 +495,9 @@ public class FileMoveDetectionStepTest {
assertThat(movedFilesRepository.getComponentsWithOriginal()).containsOnly(file3, file6);
MovedFilesRepository.OriginalFile originalFile2 = movedFilesRepository.getOriginalFile(file3).get();
- assertThat(originalFile2.getId()).isEqualTo(dtos[0].getId());
assertThat(originalFile2.getKey()).isEqualTo(dtos[0].getDbKey());
assertThat(originalFile2.getUuid()).isEqualTo(dtos[0].uuid());
MovedFilesRepository.OriginalFile originalFile5 = movedFilesRepository.getOriginalFile(file6).get();
- assertThat(originalFile5.getId()).isEqualTo(dtos[3].getId());
assertThat(originalFile5.getKey()).isEqualTo(dtos[3].getDbKey());
assertThat(originalFile5.getUuid()).isEqualTo(dtos[3].uuid());
assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isGreaterThan(MIN_REQUIRED_SCORE);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImplTest.java
index e7ebf5151aa..8575de39fb7 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImplTest.java
@@ -39,7 +39,7 @@ public class MutableMovedFilesRepositoryImplTest {
ViewsComponent.builder(Component.Type.SUBVIEW, 1).build(),
ViewsComponent.builder(Component.Type.PROJECT_VIEW, 1).build()
};
- private static final MovedFilesRepository.OriginalFile SOME_ORIGINAL_FILE = new MovedFilesRepository.OriginalFile(100, "uuid for 100", "key for 100");
+ private static final MovedFilesRepository.OriginalFile SOME_ORIGINAL_FILE = new MovedFilesRepository.OriginalFile("uuid for 100", "key for 100");
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -81,10 +81,10 @@ public class MutableMovedFilesRepositoryImplTest {
underTest.setOriginalFile(SOME_FILE, SOME_ORIGINAL_FILE);
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Original file OriginalFile{id=100, uuid='uuid for 100', key='key for 100'} " +
+ expectedException.expectMessage("Original file OriginalFile{uuid='uuid for 100', key='key for 100'} " +
"already registered for file ReportComponent{ref=1, key='key_1', type=FILE}");
- underTest.setOriginalFile(SOME_FILE, new MovedFilesRepository.OriginalFile(987, "uudi", "key"));
+ underTest.setOriginalFile(SOME_FILE, new MovedFilesRepository.OriginalFile("uudi", "key"));
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ClosedIssuesInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ClosedIssuesInputFactoryTest.java
index 2113bce0b92..4c1895d78dd 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ClosedIssuesInputFactoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ClosedIssuesInputFactoryTest.java
@@ -65,7 +65,7 @@ public class ClosedIssuesInputFactoryTest {
String originalComponentUuid = randomAlphanumeric(12);
ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).setUuid(componentUuid).build();
when(movedFilesRepository.getOriginalFile(component))
- .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(1, originalComponentUuid, randomAlphanumeric(2))));
+ .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(originalComponentUuid, randomAlphanumeric(2))));
Input<DefaultIssue> input = underTest.create(component);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java
index 3f228813d62..acad6933890 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java
@@ -271,7 +271,7 @@ public class IntegrateIssuesVisitorTest {
public void remove_uuid_of_original_file_from_componentsWithUnprocessedIssues_if_component_has_one() {
String originalFileUuid = "original file uuid";
when(movedFilesRepository.getOriginalFile(FILE))
- .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(4851, originalFileUuid, "original file key")));
+ .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(originalFileUuid, "original file key")));
underTest.visitAny(FILE);
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java
index e69963d7deb..54d12c34214 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java
@@ -100,7 +100,7 @@ public class MovedIssueVisitorTest {
DefaultIssue issue = mockIssue("other component uuid");
when(issue.toString()).thenReturn("[bad issue, bad!]");
when(movedFilesRepository.getOriginalFile(FILE))
- .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(6451, "original uuid", "original key")));
+ .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile("original uuid", "original key")));
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Issue [bad issue, bad!] doesn't belong to file original uuid registered as original " +
@@ -111,7 +111,7 @@ public class MovedIssueVisitorTest {
@Test
public void onIssue_update_component_and_module_fields_to_component_and_flag_issue_has_changed() {
- MovedFilesRepository.OriginalFile originalFile = new MovedFilesRepository.OriginalFile(6451, "original uuid", "original key");
+ MovedFilesRepository.OriginalFile originalFile = new MovedFilesRepository.OriginalFile("original uuid", "original key");
DefaultIssue issue = mockIssue(originalFile.getUuid());
when(movedFilesRepository.getOriginalFile(FILE))
.thenReturn(Optional.of(originalFile));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RemoveProcessedComponentsVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RemoveProcessedComponentsVisitorTest.java
index 362eebf6c92..f10a4092a3e 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RemoveProcessedComponentsVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RemoveProcessedComponentsVisitorTest.java
@@ -57,7 +57,7 @@ public class RemoveProcessedComponentsVisitorTest {
@Test
public void also_remove_moved_files() {
String uuid2 = "uuid2";
- OriginalFile movedFile = new OriginalFile(0, uuid2, "key");
+ OriginalFile movedFile = new OriginalFile(uuid2, "key");
when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.of(movedFile));
underTest.afterComponent(component);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerBaseInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerBaseInputFactoryTest.java
index e2abc551938..8c340db81d7 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerBaseInputFactoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerBaseInputFactoryTest.java
@@ -86,7 +86,7 @@ public class TrackerBaseInputFactoryTest {
String originalUuid = "original uuid";
when(movedFilesRepository.getOriginalFile(FILE)).thenReturn(
- Optional.of(new MovedFilesRepository.OriginalFile(6542, originalUuid, "original key")));
+ Optional.of(new MovedFilesRepository.OriginalFile(originalUuid, "original key")));
underTest.create(FILE).getLineHashSequence();
@@ -106,7 +106,7 @@ public class TrackerBaseInputFactoryTest {
String originalUuid = "original uuid";
when(movedFilesRepository.getOriginalFile(FILE)).thenReturn(
- Optional.of(new MovedFilesRepository.OriginalFile(6542, originalUuid, "original key")));
+ Optional.of(new MovedFilesRepository.OriginalFile(originalUuid, "original key")));
underTest.create(FILE).getIssues();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
index d4da264cdc2..af5bdc76943 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
@@ -26,7 +26,6 @@ import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.component.BranchPersister;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepository;
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder;
import org.sonar.ce.task.projectanalysis.component.ProjectPersister;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
@@ -66,7 +65,6 @@ public class PersistComponentsStepTest {
new PersistComponentsStep(
dbClient,
treeRootHolder,
- mock(MutableDbIdsRepository.class),
System2.INSTANCE,
mock(MutableDisabledComponentsHolder.class),
mock(AnalysisMetadataHolder.class),
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java
index 83fe62990c4..bbf7cc39fdc 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java
@@ -28,7 +28,6 @@ import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.DbIdsRepositoryImpl;
import org.sonar.ce.task.projectanalysis.component.ReportComponent;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.ce.task.projectanalysis.period.Period;
@@ -65,7 +64,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
public PeriodHolderRule periodsHolder = new PeriodHolderRule();
private System2 system2 = mock(System2.class);
- private DbIdsRepositoryImpl dbIdsRepository;
private DbClient dbClient = dbTester.getDbClient();
private long analysisDate;
private long now;
@@ -77,7 +75,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
analysisMetadataHolder.setUuid(ANALYSIS_UUID);
analysisMetadataHolder.setAnalysisDate(analysisDate);
analysisMetadataHolder.setScmRevision(REVISION_ID);
- dbIdsRepository = new DbIdsRepositoryImpl();
now = DateUtils.parseDateQuietly("2015-06-02").getTime();
@@ -121,10 +118,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
.build();
treeRootHolder.setRoot(project);
- dbIdsRepository.setComponentId(project, projectDto.getId());
- dbIdsRepository.setComponentId(directory, directoryDto.getId());
- dbIdsRepository.setComponentId(file, fileDto.getId());
-
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
@@ -139,9 +132,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
assertThat(projectSnapshot.getRevision()).isEqualTo(REVISION_ID);
-
- assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
- assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
@Test
@@ -156,7 +146,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
treeRootHolder.setRoot(project);
- dbIdsRepository.setComponentId(project, projectDto.getId());
underTest.execute(new TestComputationStepContext());
@@ -192,10 +181,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(directory).build();
treeRootHolder.setRoot(project);
- dbIdsRepository.setComponentId(project, projectDto.getId());
- dbIdsRepository.setComponentId(directory, directoryDto.getId());
- dbIdsRepository.setComponentId(file, fileDto.getId());
-
underTest.execute(new TestComputationStepContext());
SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
@@ -212,7 +197,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
treeRootHolder.setRoot(project);
- dbIdsRepository.setComponentId(project, projectDto.getId());
underTest.execute(new TestComputationStepContext());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
index 7aa8e00db31..da466c1f677 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
@@ -36,7 +36,6 @@ import org.sonar.ce.task.projectanalysis.component.BranchPersister;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl;
import org.sonar.ce.task.projectanalysis.component.FileAttributes;
-import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepositoryRule;
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder;
import org.sonar.ce.task.projectanalysis.component.ProjectPersister;
import org.sonar.ce.task.projectanalysis.component.ReportComponent;
@@ -78,8 +77,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
- public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder);
- @Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
.setOrganizationUuid(ORGANIZATION_UUID, QUALITY_GATE_UUID);
@@ -97,7 +94,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
db.organizations().insertForUuid(ORGANIZATION_UUID);
BranchPersister branchPersister = mock(BranchPersister.class);
ProjectPersister projectPersister = mock(ProjectPersister.class);
- underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister);
+ underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister);
}
@Override
@@ -161,9 +158,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(fileDto.scope()).isEqualTo("FIL");
assertThat(fileDto.getRootUuid()).isEqualTo(projectDto.uuid());
assertThat(fileDto.getCreatedAt()).isEqualTo(now);
-
- assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
- assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
@Test
@@ -223,9 +217,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(fileDto.scope()).isEqualTo("FIL");
assertThat(fileDto.getRootUuid()).isEqualTo(project.uuid());
assertThat(fileDto.getCreatedAt()).isEqualTo(now);
-
- assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
- assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
@Test
@@ -370,7 +361,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(db.countRowsOfTable("components")).isEqualTo(3);
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get();
- assertThat(projectReloaded.getId()).isEqualTo(project.getId());
assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
assertThat(projectReloaded.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT);
assertThat(projectReloaded.getMainBranchProjectUuid()).isNull();
@@ -417,12 +407,11 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
underTest.execute(new TestComputationStepContext());
assertThat(db.countRowsOfTable("components")).isEqualTo(3);
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().getId()).isEqualTo(directory.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(file.getId());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().uuid()).isEqualTo(project.uuid());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().uuid()).isEqualTo(directory.uuid());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().uuid()).isEqualTo(file.uuid());
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get();
- assertThat(projectReloaded.getId()).isEqualTo(project.getId());
assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
assertThat(projectReloaded.moduleUuid()).isEqualTo(project.moduleUuid());
assertThat(projectReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
@@ -551,16 +540,15 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
underTest.execute(new TestComputationStepContext());
assertThat(db.countRowsOfTable("components")).isEqualTo(3);
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().getId()).isEqualTo(removedDirectory.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(removedFile.getId());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().uuid()).isEqualTo(project.uuid());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().uuid()).isEqualTo(removedDirectory.uuid());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().uuid()).isEqualTo(removedFile.uuid());
assertExistButDisabled(removedDirectory.getDbKey(), removedFile.getDbKey());
// commit the functional transaction
dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get();
- assertThat(projectReloaded.getId()).isEqualTo(project.getId());
assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
assertThat(projectReloaded.getUuidPath()).isEqualTo(project.getUuidPath());
assertThat(projectReloaded.moduleUuid()).isEqualTo(project.moduleUuid());
@@ -570,7 +558,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(projectReloaded.isEnabled()).isTrue();
ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
- assertThat(directoryReloaded.getId()).isEqualTo(removedDirectory.getId());
assertThat(directoryReloaded.uuid()).isEqualTo(removedDirectory.uuid());
assertThat(directoryReloaded.getUuidPath()).isEqualTo(removedDirectory.getUuidPath());
assertThat(directoryReloaded.moduleUuid()).isEqualTo(removedDirectory.moduleUuid());
@@ -583,7 +570,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
assertThat(directoryReloaded.isEnabled()).isTrue();
ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
- assertThat(fileReloaded.getId()).isEqualTo(fileReloaded.getId());
assertThat(fileReloaded.uuid()).isEqualTo(removedFile.uuid());
assertThat(fileReloaded.getUuidPath()).isEqualTo(removedFile.getUuidPath());
assertThat(fileReloaded.moduleUuid()).isEqualTo(removedFile.moduleUuid());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java
index fe5c7f40f8e..7ad6b12745c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java
@@ -34,7 +34,6 @@ import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.component.BranchPersister;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl;
-import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepositoryRule;
import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder;
import org.sonar.ce.task.projectanalysis.component.ProjectPersister;
import org.sonar.ce.task.projectanalysis.component.ProjectViewAttributes;
@@ -85,8 +84,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
- public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder);
- @Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
.setOrganizationUuid(ORGANIZATION_UUID, QUALITY_GATE_UUID);
@@ -106,7 +103,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
analysisMetadataHolder.setBranch(new DefaultBranchImpl());
BranchPersister branchPersister = mock(BranchPersister.class);
ProjectPersister projectPersister = mock(ProjectPersister.class);
- underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister);
+ underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister);
}
@Override
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java b/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java
index ce3efe07ac5..fb4cce6abf0 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java
@@ -51,12 +51,12 @@ public class ReadOnlyPropertiesDao extends PropertiesDao {
}
@Override
- public void deleteProjectProperty(String key, Long projectId) {
+ public void deleteProjectProperty(String key, String projectUuid) {
// do nothing
}
@Override
- public void deleteProjectProperty(String key, Long projectId, DbSession session) {
+ public void deleteProjectProperty(String key, String projectUuid, DbSession session) {
// do nothing
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index a4ed208f414..c56a9646c00 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -111,7 +111,6 @@ import org.sonar.db.property.InternalPropertiesMapper;
import org.sonar.db.property.InternalPropertyDto;
import org.sonar.db.property.PropertiesMapper;
import org.sonar.db.property.ScrapPropertyDto;
-import org.sonar.db.purge.IdUuidPair;
import org.sonar.db.purge.PurgeMapper;
import org.sonar.db.purge.PurgeableAnalysisDto;
import org.sonar.db.qualitygate.ProjectQgateAssociationDto;
@@ -187,7 +186,6 @@ public class MyBatis implements Startable {
confBuilder.loadAlias("Group", GroupDto.class);
confBuilder.loadAlias("GroupMembership", GroupMembershipDto.class);
confBuilder.loadAlias("GroupPermission", GroupPermissionDto.class);
- confBuilder.loadAlias("IdUuidPair", IdUuidPair.class);
confBuilder.loadAlias("InternalProperty", InternalPropertyDto.class);
confBuilder.loadAlias("InternalComponentProperty", InternalComponentPropertyDto.class);
confBuilder.loadAlias("IssueChange", IssueChangeDto.class);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index ccda0b0c410..3cf5437e300 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -72,10 +72,6 @@ public class ComponentDao implements Dao {
return session.getMapper(ComponentMapper.class);
}
- public Optional<ComponentDto> selectById(DbSession session, long id) {
- return Optional.ofNullable(mapper(session).selectById(id));
- }
-
public Optional<ComponentDto> selectByUuid(DbSession session, String uuid) {
return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
@@ -147,10 +143,6 @@ public class ComponentDao implements Dao {
return mapper(session).selectEnabledFilesFromProject(rootComponentUuid);
}
- public List<ComponentDto> selectByIds(DbSession session, Collection<Long> ids) {
- return executeLargeInputs(ids, mapper(session)::selectByIds);
- }
-
public List<ComponentDto> selectByUuids(DbSession session, Collection<String> uuids) {
return executeLargeInputs(uuids, mapper(session)::selectByUuids);
}
@@ -386,12 +378,11 @@ public class ComponentDao implements Dao {
mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate);
}
- public void delete(DbSession session, long componentId) {
- mapper(session).delete(componentId);
+ public void delete(DbSession session, String componentUuid) {
+ mapper(session).delete(componentUuid);
}
private static void checkThatNotTooManyComponents(ComponentQuery query) {
- checkThatNotTooManyConditions(query.getComponentIds(), "Too many component ids in query");
checkThatNotTooManyConditions(query.getComponentKeys(), "Too many component keys in query");
checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query");
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
index 5e9c633eca9..0dc9a85540c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
@@ -55,11 +55,6 @@ public class ComponentDto {
private static final Splitter UUID_PATH_SPLITTER = Splitter.on(UUID_PATH_SEPARATOR).omitEmptyStrings();
/**
- * ID generated by database. Do not use.
- */
- private Long id;
-
- /**
* The UUID of the organization the component belongs to. Can't be null in DB.
*/
private String organizationUuid;
@@ -161,15 +156,6 @@ public class ComponentDto {
return buildLikeValue(formatUuidPathFromParent(this), WildcardPosition.AFTER);
}
- public Long getId() {
- return id;
- }
-
- public ComponentDto setId(Long id) {
- this.id = id;
- return this;
- }
-
public String getOrganizationUuid() {
return organizationUuid;
}
@@ -431,7 +417,6 @@ public class ComponentDto {
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", id)
.append("uuid", uuid)
.append("uuidPath", uuidPath)
.append("kee", kee)
@@ -455,7 +440,6 @@ public class ComponentDto {
public ComponentDto copy() {
ComponentDto copy = new ComponentDto();
copy.projectUuid = projectUuid;
- copy.id = id;
copy.organizationUuid = organizationUuid;
copy.kee = kee;
copy.uuid = uuid;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
index 0626ee076ac..32f99628b4b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -40,9 +40,6 @@ public interface ComponentMapper {
ComponentDto selectPrByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch);
@CheckForNull
- ComponentDto selectById(long id);
-
- @CheckForNull
ComponentDto selectByUuid(String uuid);
@CheckForNull
@@ -59,8 +56,6 @@ public interface ComponentMapper {
List<ComponentDto> selectByKeysAndBranch(@Param("keys") Collection<String> keys, @Param("branch") String branch);
- List<ComponentDto> selectByIds(@Param("ids") Collection<Long> ids);
-
List<ComponentDto> selectByUuids(@Param("uuids") Collection<String> uuids);
List<ComponentDto> selectByProjectUuid(@Param("projectUuid") String projectUuid);
@@ -77,7 +72,7 @@ public interface ComponentMapper {
* @return 1 or 0. Either because the organization uuid is not the one of the component or because the component does
* not exist.
*/
- int countComponentByOrganizationAndId(@Param("organizationUuid") String organizationUuid, @Param("componentId") long componentId);
+ int countComponentByOrganizationAndUuid(@Param("organizationUuid") String organizationUuid, @Param("componentUuid") String componentUuid);
List<ComponentDto> selectByQuery(@Nullable @Param("organizationUuid") String organizationUuid, @Param("query") ComponentQuery query, RowBounds rowBounds);
@@ -154,7 +149,7 @@ public interface ComponentMapper {
void setPrivateForRootComponentUuid(@Param("projectUuid") String projectUuid, @Param("isPrivate") boolean isPrivate);
- void delete(long componentId);
+ void delete(String componentUuid);
List<KeyWithUuidDto> selectAllSiblingComponentKeysHavingOpenIssues(@Param("referenceBranchUuid") String referenceBranchUuid,
@Param("currentBranchUuid") String currentBranchUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
index a89157a5539..7668b8270f0 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
@@ -35,7 +35,6 @@ public class ComponentQuery {
private final boolean partialMatchOnKey;
private final String[] qualifiers;
private final Boolean isPrivate;
- private final Set<Long> componentIds;
private final Set<String> componentUuids;
private final Set<String> componentKeys;
private final Long analyzedBefore;
@@ -48,7 +47,6 @@ public class ComponentQuery {
this.nameOrKeyQuery = builder.nameOrKeyQuery;
this.partialMatchOnKey = builder.partialMatchOnKey == null ? false : builder.partialMatchOnKey;
this.qualifiers = builder.qualifiers;
- this.componentIds = builder.componentIds;
this.componentUuids = builder.componentUuids;
this.componentKeys = builder.componentKeys;
this.isPrivate = builder.isPrivate;
@@ -84,11 +82,6 @@ public class ComponentQuery {
}
@CheckForNull
- public Set<Long> getComponentIds() {
- return componentIds;
- }
-
- @CheckForNull
public Set<String> getComponentUuids() {
return componentUuids;
}
@@ -128,7 +121,7 @@ public class ComponentQuery {
}
boolean hasEmptySetOfComponents() {
- return Stream.of(componentIds, componentKeys, componentUuids)
+ return Stream.of(componentKeys, componentUuids)
.anyMatch(list -> list != null && list.isEmpty());
}
@@ -141,7 +134,6 @@ public class ComponentQuery {
private Boolean partialMatchOnKey;
private String[] qualifiers;
private Boolean isPrivate;
- private Set<Long> componentIds;
private Set<String> componentUuids;
private Set<String> componentKeys;
private Long analyzedBefore;
@@ -168,11 +160,6 @@ public class ComponentQuery {
return this;
}
- public Builder setComponentIds(@Nullable Set<Long> componentIds) {
- this.componentIds = componentIds;
- return this;
- }
-
public Builder setComponentUuids(@Nullable Set<String> componentUuids) {
this.componentUuids = componentUuids;
return this;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/FileMoveRowDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/FileMoveRowDto.java
index 5e62f63264c..159469f2151 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/FileMoveRowDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/FileMoveRowDto.java
@@ -20,16 +20,11 @@
package org.sonar.db.component;
public class FileMoveRowDto {
- private long id;
private String kee;
private String uuid;
private String path;
private int lineCount;
- public long getId() {
- return id;
- }
-
public String getKey() {
return kee;
}
@@ -49,8 +44,7 @@ public class FileMoveRowDto {
@Override
public String toString() {
return "FileMoveRowDto{" +
- "id=" + id +
- ", kee='" + kee + '\'' +
+ "kee='" + kee + '\'' +
", uuid='" + uuid + '\'' +
", path='" + path + '\'' +
", lineCount=" + lineCount +
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ResourceDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ResourceDto.java
index e089b2b32d5..5fa6993cd53 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ResourceDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ResourceDto.java
@@ -30,7 +30,6 @@ import static org.sonar.db.component.ComponentValidator.checkDescription;
public class ResourceDto {
- private Long id;
private String uuid;
private String projectUuid;
private String moduleUuid;
@@ -49,15 +48,6 @@ public class ResourceDto {
private String copyComponentUuid;
private Date createdAt;
- public Long getId() {
- return id;
- }
-
- public ResourceDto setId(Long id) {
- this.id = id;
- return this;
- }
-
public String getUuid() {
return uuid;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java
index 7a91c79da51..13fcc11397f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java
@@ -136,22 +136,6 @@ public class AuthorizationDao implements Dao {
return mapper(dbSession).selectOrganizationUuidsOfUserWithGlobalPermission(userId, permission);
}
- /**
- * @deprecated replaced by {@link #keepAuthorizedProjectUuids(DbSession, Collection, Integer, String)}
- */
- @Deprecated
- public Set<Long> keepAuthorizedProjectIds(DbSession dbSession, Collection<Long> componentIds, @Nullable Integer userId, String permission) {
- return executeLargeInputsIntoSet(
- componentIds,
- partition -> {
- if (userId == null) {
- return mapper(dbSession).keepAuthorizedProjectIdsForAnonymous(permission, partition);
- }
- return mapper(dbSession).keepAuthorizedProjectIdsForUser(userId, permission, partition);
- },
- partitionSize -> partitionSize / 2);
- }
-
public Set<String> keepAuthorizedProjectUuids(DbSession dbSession, Collection<String> projectUuids, @Nullable Integer userId, String permission) {
return executeLargeInputsIntoSet(
projectUuids,
@@ -168,10 +152,10 @@ public class AuthorizationDao implements Dao {
* Keep only authorized user that have the given permission on a given project.
* Please Note that if the permission is 'Anyone' is NOT taking into account by this method.
*/
- public Collection<Integer> keepAuthorizedUsersForRoleAndProject(DbSession dbSession, Collection<Integer> userIds, String role, long projectId) {
+ public Collection<Integer> keepAuthorizedUsersForRoleAndProject(DbSession dbSession, Collection<Integer> userIds, String role, String projectUuid) {
return executeLargeInputs(
userIds,
- partitionOfIds -> mapper(dbSession).keepAuthorizedUsersForRoleAndProject(role, projectId, partitionOfIds),
+ partitionOfIds -> mapper(dbSession).keepAuthorizedUsersForRoleAndProject(role, projectUuid, partitionOfIds),
partitionSize -> partitionSize / 3);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java
index 6be5a51fcb8..8712e4bb5f4 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java
@@ -50,15 +50,11 @@ public interface AuthorizationMapper {
Set<String> selectOrganizationUuidsOfUserWithGlobalPermission(@Param("userId") int userId, @Param("permission") String permission);
- Set<Long> keepAuthorizedProjectIdsForAnonymous(@Param("role") String role, @Param("componentIds") Collection<Long> componentIds);
+ List<Integer> keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentUuid") String componentUuid, @Param("userIds") List<Integer> userIds);
- Set<Long> keepAuthorizedProjectIdsForUser(@Param("userId") int userId, @Param("role") String role, @Param("componentIds") Collection<Long> componentIds);
+ Set<String> keepAuthorizedProjectUuidsForUser(@Param("userId") int userId, @Param("role") String role, @Param("projectUuids") Collection<String> projectUuids);
- List<Integer> keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentId") long componentId, @Param("userIds") List<Integer> userIds);
-
- Set<String> keepAuthorizedProjectUuidsForUser(@Param("userId") int userId, @Param("permission") String permission, @Param("projectUuids") Collection<String> projectUuids);
-
- Set<String> keepAuthorizedProjectUuidsForAnonymous(@Param("permission") String permission, @Param("projectUuids") Collection<String> projectUuids);
+ Set<String> keepAuthorizedProjectUuidsForAnonymous(@Param("role") String role, @Param("projectUuids") Collection<String> projectUuids);
Set<String> selectProjectPermissions(@Param("projectUuid") String projectUuid, @Param("userId") long userId);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/CountPerProjectPermission.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/CountPerProjectPermission.java
index 953d8446826..0128927b577 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/CountPerProjectPermission.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/CountPerProjectPermission.java
@@ -25,7 +25,7 @@ import com.google.common.annotations.VisibleForTesting;
* Count the number of users or groups for a given project and permission
*/
public class CountPerProjectPermission {
- private long componentId;
+ private String componentUuid;
private String permission;
private int count;
@@ -34,14 +34,14 @@ public class CountPerProjectPermission {
}
@VisibleForTesting
- CountPerProjectPermission(long componentId, String permission, int count) {
- this.componentId = componentId;
+ CountPerProjectPermission(String componentUuid, String permission, int count) {
+ this.componentUuid = componentUuid;
this.permission = permission;
this.count = count;
}
- public long getComponentId() {
- return componentId;
+ public String getComponentUuid() {
+ return componentUuid;
}
public String getPermission() {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
index 3577669e3d0..6d4ee373de6 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
@@ -61,8 +61,8 @@ public class GroupPermissionDao implements Dao {
* Select global or project permission of given groups and organization. Anyone virtual group is supported
* through the value "zero" (0L) in {@code groupIds}.
*/
- public List<GroupPermissionDto> selectByGroupIds(DbSession dbSession, String organizationUuid, List<Integer> groupIds, @Nullable Long projectId) {
- return executeLargeInputs(groupIds, groups -> mapper(dbSession).selectByGroupIds(organizationUuid, groups, projectId));
+ public List<GroupPermissionDto> selectByGroupIds(DbSession dbSession, String organizationUuid, List<Integer> groupIds, @Nullable String projectUuid) {
+ return executeLargeInputs(groupIds, groups -> mapper(dbSession).selectByGroupIds(organizationUuid, groups, projectUuid));
}
/**
@@ -76,15 +76,15 @@ public class GroupPermissionDao implements Dao {
/**
* Each row returns a {@link CountPerProjectPermission}
*/
- public void groupsCountByComponentIdAndPermission(DbSession dbSession, List<Long> componentIds, ResultHandler resultHandler) {
+ public void groupsCountByComponentUuidAndPermission(DbSession dbSession, List<String> componentUuids, ResultHandler resultHandler) {
Map<String, Object> parameters = new HashMap<>(2);
parameters.put(ANYONE_GROUP_PARAMETER, DefaultGroups.ANYONE);
executeLargeInputsWithoutOutput(
- componentIds,
- partitionedComponentIds -> {
- parameters.put("componentIds", partitionedComponentIds);
- mapper(dbSession).groupsCountByProjectIdAndPermission(parameters, resultHandler);
+ componentUuids,
+ partitionedComponentUuids -> {
+ parameters.put("componentUuids", partitionedComponentUuids);
+ mapper(dbSession).groupsCountByProjectUuidAndPermission(parameters, resultHandler);
});
}
@@ -100,8 +100,8 @@ public class GroupPermissionDao implements Dao {
* Selects the permissions granted to group and project. An empty list is returned if the
* group or project do not exist.
*/
- public List<String> selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId, long projectId) {
- return mapper(session).selectProjectPermissionsOfGroup(organizationUuid, groupId, projectId);
+ public List<String> selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId, String projectUuid) {
+ return mapper(session).selectProjectPermissionsOfGroup(organizationUuid, groupId, projectUuid);
}
/**
@@ -109,8 +109,8 @@ public class GroupPermissionDao implements Dao {
* permission, <strong>excluding group "AnyOne"</strong> (which implies the returned {@code Sett} can't contain
* {@code null}).
*/
- public Set<Integer> selectGroupIdsWithPermissionOnProjectBut(DbSession session, long projectId, String permission) {
- return mapper(session).selectGroupIdsWithPermissionOnProjectBut(projectId, permission);
+ public Set<Integer> selectGroupIdsWithPermissionOnProjectBut(DbSession session, String projectUuid, String permission) {
+ return mapper(session).selectGroupIdsWithPermissionOnProjectBut(projectUuid, permission);
}
public void insert(DbSession dbSession, GroupPermissionDto dto) {
@@ -120,14 +120,14 @@ public class GroupPermissionDao implements Dao {
}
private static void ensureComponentPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) {
- if (dto.getResourceId() == null) {
+ if (dto.getComponentUuid() == null) {
return;
}
ComponentMapper componentMapper = dbSession.getMapper(ComponentMapper.class);
checkArgument(
- componentMapper.countComponentByOrganizationAndId(dto.getOrganizationUuid(), dto.getResourceId()) == 1,
+ componentMapper.countComponentByOrganizationAndUuid(dto.getOrganizationUuid(), dto.getComponentUuid()) == 1,
"Can't insert permission '%s' for component with id '%s' in organization with uuid '%s' because this component does not belong to organization with uuid '%s'",
- dto.getRole(), dto.getResourceId(), dto.getOrganizationUuid(), dto.getOrganizationUuid());
+ dto.getRole(), dto.getComponentUuid(), dto.getOrganizationUuid(), dto.getOrganizationUuid());
}
private static void ensureGroupPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) {
@@ -144,23 +144,23 @@ public class GroupPermissionDao implements Dao {
/**
* Delete all the permissions associated to a root component (project)
*/
- public void deleteByRootComponentId(DbSession dbSession, long rootComponentId) {
- mapper(dbSession).deleteByRootComponentId(rootComponentId);
+ public void deleteByRootComponentUuid(DbSession dbSession, String rootComponentUuid) {
+ mapper(dbSession).deleteByRootComponentUuid(rootComponentUuid);
}
/**
* Delete all permissions of the specified group (group "AnyOne" if {@code groupId} is {@code null}) for the specified
* component.
*/
- public int deleteByRootComponentIdAndGroupId(DbSession dbSession, long rootComponentId, @Nullable Integer groupId) {
- return mapper(dbSession).deleteByRootComponentIdAndGroupId(rootComponentId, groupId);
+ public int deleteByRootComponentUuidAndGroupId(DbSession dbSession, String rootComponentUuid, @Nullable Integer groupId) {
+ return mapper(dbSession).deleteByRootComponentUuidAndGroupId(rootComponentUuid, groupId);
}
/**
* Delete the specified permission for the specified component for any group (including group AnyOne).
*/
- public int deleteByRootComponentIdAndPermission(DbSession dbSession, long rootComponentId, String permission) {
- return mapper(dbSession).deleteByRootComponentIdAndPermission(rootComponentId, permission);
+ public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String rootComponentUuid, String permission) {
+ return mapper(dbSession).deleteByRootComponentUuidAndPermission(rootComponentUuid, permission);
}
/**
@@ -175,10 +175,10 @@ public class GroupPermissionDao implements Dao {
* @param permission the kind of permission
* @param organizationUuid UUID of organization, even if parameter {@code groupId} is not null
* @param groupId if null, then anyone, else id of group
- * @param rootComponentId if null, then global permission, else id of root component (project)
+ * @param rootComponentUuid if null, then global permission, otherwise the uuid of root component (project)
*/
- public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Integer groupId, @Nullable Long rootComponentId) {
- mapper(dbSession).delete(permission, organizationUuid, groupId, rootComponentId);
+ public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Integer groupId, @Nullable String rootComponentUuid) {
+ mapper(dbSession).delete(permission, organizationUuid, groupId, rootComponentUuid);
}
public void deleteByOrganization(DbSession dbSession, String organizationUuid) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
index 344b289b361..28d5b87e432 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
@@ -25,7 +25,7 @@ public class GroupPermissionDto {
private String organizationUuid;
private Integer groupId;
- private Long resourceId;
+ private String componentUuid;
private String role;
public Integer getGroupId() {
@@ -50,12 +50,12 @@ public class GroupPermissionDto {
}
@Nullable
- public Long getResourceId() {
- return resourceId;
+ public String getComponentUuid() {
+ return componentUuid;
}
- public GroupPermissionDto setResourceId(@Nullable Long resourceId) {
- this.resourceId = resourceId;
+ public GroupPermissionDto setComponentUuid(@Nullable String componentUuid) {
+ this.componentUuid = componentUuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
index a10b51ea00f..7d0c9122262 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
@@ -34,20 +34,20 @@ public interface GroupPermissionMapper {
int countGroupsByQuery(@Param("query") PermissionQuery query);
List<GroupPermissionDto> selectByGroupIds(@Param("organizationUuid") String organizationUuid,
- @Param("groupIds") List<Integer> groupIds, @Nullable @Param("projectId") Long projectId);
+ @Param("groupIds") List<Integer> groupIds, @Nullable @Param("projectUuid") String projectUuid);
- void groupsCountByProjectIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler);
+ void groupsCountByProjectUuidAndPermission(Map<String, Object> parameters, ResultHandler resultHandler);
void insert(GroupPermissionDto dto);
void delete(@Param("permission") String permission, @Param("organizationUuid") String organizationUuid,
- @Nullable @Param("groupId") Integer groupId, @Nullable @Param("rootComponentId") Long rootComponentId);
+ @Nullable @Param("groupId") Integer groupId, @Nullable @Param("rootComponentUuid") String rootComponentUuid);
List<String> selectGlobalPermissionsOfGroup(@Param("organizationUuid") String organizationUuid,
@Nullable @Param("groupId") Integer groupId);
List<String> selectProjectPermissionsOfGroup(@Param("organizationUuid") String organizationUuid,
- @Nullable @Param("groupId") Integer groupId, @Param("projectId") long projectId);
+ @Nullable @Param("groupId") Integer groupId, @Param("projectUuid") String projectUuid);
void selectAllPermissionsByGroupId(@Param("organizationUuid") String organizationUuid,
@Param("groupId") Integer groupId, ResultHandler resultHandler);
@@ -57,13 +57,13 @@ public interface GroupPermissionMapper {
* permission, <strong>excluding group "AnyOne"</strong> (which implies the returned {@code Set} can't contain
* {@code null}).
*/
- Set<Integer> selectGroupIdsWithPermissionOnProjectBut(@Param("projectId") long projectId, @Param("role") String permission);
+ Set<Integer> selectGroupIdsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("role") String permission);
void deleteByOrganization(@Param("organizationUuid") String organizationUuid);
- void deleteByRootComponentId(@Param("rootComponentId") long componentId);
+ void deleteByRootComponentUuid(@Param("rootComponentUuid") String rootComponentUuid);
- int deleteByRootComponentIdAndGroupId(@Param("rootComponentId") long rootComponentId, @Nullable @Param("groupId") Integer groupId);
+ int deleteByRootComponentUuidAndGroupId(@Param("rootComponentUuid") String rootComponentUuid, @Nullable @Param("groupId") Integer groupId);
- int deleteByRootComponentIdAndPermission(@Param("rootComponentId") long rootComponentId, @Param("permission") String permission);
+ int deleteByRootComponentUuidAndPermission(@Param("rootComponentUuid") String rootComponentUuid, @Param("permission") String permission);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java
index e71aa775780..4ceaf9889bb 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java
@@ -49,7 +49,6 @@ public class PermissionQuery {
private final String permission;
// filter on project, else filter org permissions
private final String componentUuid;
- private final Long componentId;
// filter on login, email or name of users or groups
private final String searchQuery;
@@ -68,7 +67,6 @@ public class PermissionQuery {
this.permission = builder.permission;
this.withAtLeastOnePermission = builder.withAtLeastOnePermission;
this.componentUuid = builder.componentUuid;
- this.componentId = builder.componentId;
this.searchQuery = builder.searchQuery;
this.searchQueryToSql = builder.searchQuery == null ? null : buildLikeValue(builder.searchQuery, WildcardPosition.BEFORE_AND_AFTER);
this.searchQueryToSqlLowercase = searchQueryToSql == null ? null : searchQueryToSql.toLowerCase(Locale.ENGLISH);
@@ -95,11 +93,6 @@ public class PermissionQuery {
}
@CheckForNull
- public Long getComponentId() {
- return componentId;
- }
-
- @CheckForNull
public String getSearchQuery() {
return searchQuery;
}
@@ -130,7 +123,6 @@ public class PermissionQuery {
private String permission;
private String organizationUuid;
private String componentUuid;
- private Long componentId;
private String searchQuery;
private boolean withAtLeastOnePermission;
@@ -148,12 +140,11 @@ public class PermissionQuery {
}
public Builder setComponent(ComponentDto component) {
- return setComponent(component.uuid(), component.getId());
+ return setComponent(component.uuid());
}
- public Builder setComponent(String componentUuid, long componentId) {
+ public Builder setComponent(String componentUuid) {
this.componentUuid = componentUuid;
- this.componentId = componentId;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java
index adb57fa8910..7dab1f11eb3 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java
@@ -75,10 +75,10 @@ public class UserPermissionDao implements Dao {
/**
* Count the number of users per permission for a given list of projects
*
- * @param projectIds a non-null list of project ids to filter on. If empty then an empty list is returned.
+ * @param projectUuids a non-null list of project uuids to filter on. If empty then an empty list is returned.
*/
- public List<CountPerProjectPermission> countUsersByProjectPermission(DbSession dbSession, Collection<Long> projectIds) {
- return executeLargeInputs(projectIds, mapper(dbSession)::countUsersByProjectPermission);
+ public List<CountPerProjectPermission> countUsersByProjectPermission(DbSession dbSession, Collection<String> projectUuids) {
+ return executeLargeInputs(projectUuids, mapper(dbSession)::countUsersByProjectPermission);
}
/**
@@ -95,12 +95,12 @@ public class UserPermissionDao implements Dao {
*
* @return the project permissions. An empty list is returned if project or user do not exist.
*/
- public List<String> selectProjectPermissionsOfUser(DbSession dbSession, int userId, long projectId) {
- return mapper(dbSession).selectProjectPermissionsOfUser(userId, projectId);
+ public List<String> selectProjectPermissionsOfUser(DbSession dbSession, int userId, String projectUuid) {
+ return mapper(dbSession).selectProjectPermissionsOfUser(userId, projectUuid);
}
- public Set<Integer> selectUserIdsWithPermissionOnProjectBut(DbSession session, long projectId, String permission) {
- return mapper(session).selectUserIdsWithPermissionOnProjectBut(projectId, permission);
+ public Set<Integer> selectUserIdsWithPermissionOnProjectBut(DbSession session, String projectUuid, String permission) {
+ return mapper(session).selectUserIdsWithPermissionOnProjectBut(projectUuid, permission);
}
public void insert(DbSession dbSession, UserPermissionDto dto) {
@@ -109,14 +109,14 @@ public class UserPermissionDao implements Dao {
}
private static void ensureComponentPermissionConsistency(DbSession dbSession, UserPermissionDto dto) {
- if (dto.getComponentId() == null) {
+ if (dto.getComponentUuid() == null) {
return;
}
ComponentMapper componentMapper = dbSession.getMapper(ComponentMapper.class);
checkArgument(
- componentMapper.countComponentByOrganizationAndId(dto.getOrganizationUuid(), dto.getComponentId()) == 1,
+ componentMapper.countComponentByOrganizationAndUuid(dto.getOrganizationUuid(), dto.getComponentUuid()) == 1,
"Can't insert permission '%s' for component with id '%s' in organization with uuid '%s' because this component does not belong to organization with uuid '%s'",
- dto.getPermission(), dto.getComponentId(), dto.getOrganizationUuid(), dto.getOrganizationUuid());
+ dto.getPermission(), dto.getComponentUuid(), dto.getOrganizationUuid(), dto.getOrganizationUuid());
}
/**
@@ -129,22 +129,22 @@ public class UserPermissionDao implements Dao {
/**
* Removes a single project permission from user
*/
- public void deleteProjectPermission(DbSession dbSession, int userId, String permission, long projectId) {
- mapper(dbSession).deleteProjectPermission(userId, permission, projectId);
+ public void deleteProjectPermission(DbSession dbSession, int userId, String permission, String projectUuid) {
+ mapper(dbSession).deleteProjectPermission(userId, permission, projectUuid);
}
/**
* Deletes all the permissions defined on a project
*/
- public void deleteProjectPermissions(DbSession dbSession, long projectId) {
- mapper(dbSession).deleteProjectPermissions(projectId);
+ public void deleteProjectPermissions(DbSession dbSession, String projectUuid) {
+ mapper(dbSession).deleteProjectPermissions(projectUuid);
}
/**
* Deletes the specified permission on the specified project for any user.
*/
- public int deleteProjectPermissionOfAnyUser(DbSession dbSession, long projectId, String permission) {
- return mapper(dbSession).deleteProjectPermissionOfAnyUser(projectId, permission);
+ public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String projectUuid, String permission) {
+ return mapper(dbSession).deleteProjectPermissionOfAnyUser(projectUuid, permission);
}
public void deleteByOrganization(DbSession dbSession, String organizationUuid) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
index 680b77fc154..785d8082c78 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
@@ -27,17 +27,17 @@ public class UserPermissionDto {
private String organizationUuid;
private String permission;
private int userId;
- private Long componentId;
+ private String componentUuid;
public UserPermissionDto() {
// used by MyBatis
}
- public UserPermissionDto(String organizationUuid, String permission, int userId, @Nullable Long componentId) {
+ public UserPermissionDto(String organizationUuid, String permission, int userId, @Nullable String componentUuid) {
this.organizationUuid = organizationUuid;
this.permission = permission;
this.userId = userId;
- this.componentId = componentId;
+ this.componentUuid = componentUuid;
}
public String getPermission() {
@@ -53,11 +53,11 @@ public class UserPermissionDto {
}
/**
- * @return {@code null} if it's a global permission, else return the project id.
+ * @return {@code null} if it's a global permission, otherwise return the project uiid.
*/
@CheckForNull
- public Long getComponentId() {
- return componentId;
+ public String getComponentUuid() {
+ return componentUuid;
}
@Override
@@ -66,7 +66,7 @@ public class UserPermissionDto {
sb.append("permission='").append(permission).append('\'');
sb.append(", userId=").append(userId);
sb.append(", organizationUuid=").append(organizationUuid);
- sb.append(", componentId=").append(componentId);
+ sb.append(", componentUuid=").append(componentUuid);
sb.append('}');
return sb.toString();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionMapper.java
index 70af662bf25..4318a4d0403 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionMapper.java
@@ -43,14 +43,14 @@ public interface UserPermissionMapper {
/**
* Count the number of users per permission for a given list of projects.
- * @param projectIds a non-null and non-empty list of project ids
+ * @param projectUuids a non-null and non-empty list of project ids
*/
- List<CountPerProjectPermission> countUsersByProjectPermission(@Param("projectIds") List<Long> projectIds);
+ List<CountPerProjectPermission> countUsersByProjectPermission(@Param("projectUuids") List<String> projectUuids);
/**
* select id of users with at least one permission on the specified project but which do not have the specified permission.
*/
- Set<Integer> selectUserIdsWithPermissionOnProjectBut(@Param("projectId") long projectId, @Param("permission") String permission);
+ Set<Integer> selectUserIdsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("permission") String permission);
void insert(UserPermissionDto dto);
@@ -58,15 +58,15 @@ public interface UserPermissionMapper {
@Param("organizationUuid") String organizationUuid);
void deleteProjectPermission(@Param("userId") int userId, @Param("permission") String permission,
- @Param("projectId") long projectId);
+ @Param("projectUuid") String projectUuid);
- void deleteProjectPermissions(@Param("projectId") long projectId);
+ void deleteProjectPermissions(@Param("projectUuid") String projectUuid);
- int deleteProjectPermissionOfAnyUser(@Param("projectId") long projectId, @Param("permission") String permission);
+ int deleteProjectPermissionOfAnyUser(@Param("projectUuid") String projectUuid, @Param("permission") String permission);
List<String> selectGlobalPermissionsOfUser(@Param("userId") int userId, @Param("organizationUuid") String organizationUuid);
- List<String> selectProjectPermissionsOfUser(@Param("userId") int userId, @Param("projectId") long projectId);
+ List<String> selectProjectPermissionsOfUser(@Param("userId") int userId, @Param("projectUuid") String projectUuid);
void deleteByOrganization(@Param("organizationUuid") String organizationUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
index b3a902160b1..53a1db397e5 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
@@ -109,8 +109,8 @@ public class PropertiesDao implements Dao {
private static PreparedStatement createStatement(String projectUuid, Collection<String> dispatcherKeys, Connection connection) throws SQLException {
String sql = "SELECT count(1) FROM properties pp " +
- "left outer join components pj on pp.resource_id = pj.id " +
- "where pp.user_id is not null and (pp.resource_id is null or pj.uuid=?) " +
+ "left outer join components pj on pp.component_uuid = pj.uuid " +
+ "where pp.user_id is not null and (pp.component_uuid is null or pj.uuid=?) " +
"and (" + repeat("pp.prop_key like ?", " or ", dispatcherKeys.size()) + ")";
PreparedStatement res = connection.prepareStatement(sql);
res.setString(1, projectUuid);
@@ -155,32 +155,32 @@ public class PropertiesDao implements Dao {
}
@CheckForNull
- public PropertyDto selectProjectProperty(long componentId, String propertyKey) {
+ public PropertyDto selectProjectProperty(String projectUuid, String propertyKey) {
try (DbSession session = mybatis.openSession(false)) {
- return selectProjectProperty(session, componentId, propertyKey);
+ return selectProjectProperty(session, projectUuid, propertyKey);
}
}
@CheckForNull
- public PropertyDto selectProjectProperty(DbSession dbSession, long componentId, String propertyKey) {
- return getMapper(dbSession).selectByKey(new PropertyDto().setKey(propertyKey).setResourceId(componentId));
+ public PropertyDto selectProjectProperty(DbSession dbSession, String projectUuid, String propertyKey) {
+ return getMapper(dbSession).selectByKey(new PropertyDto().setKey(propertyKey).setComponentUuid(projectUuid));
}
public List<PropertyDto> selectByQuery(PropertyQuery query, DbSession session) {
return getMapper(session).selectByQuery(query);
}
- public List<PropertyDto> selectGlobalPropertiesByKeys(DbSession session, Set<String> keys) {
+ public List<PropertyDto> selectGlobalPropertiesByKeys(DbSession session, Collection<String> keys) {
return executeLargeInputs(keys, partitionKeys -> getMapper(session).selectByKeys(partitionKeys));
}
- public List<PropertyDto> selectPropertiesByKeysAndComponentIds(DbSession session, Set<String> keys, Set<Long> componentIds) {
- return executeLargeInputs(keys, partitionKeys -> executeLargeInputs(componentIds,
- partitionComponentIds -> getMapper(session).selectByKeysAndComponentIds(partitionKeys, partitionComponentIds)));
+ public List<PropertyDto> selectPropertiesByKeysAndComponentUuids(DbSession session, Collection<String> keys, Collection<String> componentUuids) {
+ return executeLargeInputs(keys, partitionKeys -> executeLargeInputs(componentUuids,
+ partitionComponentUuids -> getMapper(session).selectByKeysAndComponentUuids(partitionKeys, partitionComponentUuids)));
}
- public List<PropertyDto> selectPropertiesByComponentIds(DbSession session, Set<Long> componentIds) {
- return executeLargeInputs(componentIds, getMapper(session)::selectByComponentIds);
+ public List<PropertyDto> selectPropertiesByComponentUuids(DbSession session, Collection<String> componentUuids) {
+ return executeLargeInputs(componentUuids, getMapper(session)::selectByComponentUuids);
}
public List<PropertyDto> selectByKeyAndMatchingValue(DbSession session, String key, String value) {
@@ -200,22 +200,21 @@ public class PropertiesDao implements Dao {
* @throws IllegalArgumentException if {@link PropertyDto#getKey()} is {@code null} or empty
*/
public void saveProperty(DbSession session, PropertyDto property) {
- save(getMapper(session), property.getKey(), property.getUserId(), property.getResourceId(), property.getValue());
+ save(getMapper(session), property.getKey(), property.getUserId(), property.getComponentUuid(), property.getValue());
}
private void save(PropertiesMapper mapper,
- String key, @Nullable Integer userId, @Nullable Long componentId,
- @Nullable String value) {
+ String key, @Nullable Integer userId, @Nullable String componentUuid, @Nullable String value) {
checkKey(key);
long now = system2.now();
- mapper.delete(key, userId, componentId);
+ mapper.delete(key, userId, componentUuid);
if (isEmpty(value)) {
- mapper.insertAsEmpty(key, userId, componentId, now);
+ mapper.insertAsEmpty(key, userId, componentUuid, now);
} else if (mustBeStoredInClob(value)) {
- mapper.insertAsClob(key, userId, componentId, value, now);
+ mapper.insertAsClob(key, userId, componentUuid, value, now);
} else {
- mapper.insertAsText(key, userId, componentId, value, now);
+ mapper.insertAsText(key, userId, componentUuid, value, now);
}
}
@@ -250,18 +249,18 @@ public class PropertiesDao implements Dao {
}
public int delete(DbSession dbSession, PropertyDto dto) {
- return getMapper(dbSession).delete(dto.getKey(), dto.getUserId(), dto.getResourceId());
+ return getMapper(dbSession).delete(dto.getKey(), dto.getUserId(), dto.getComponentUuid());
}
- public void deleteProjectProperty(String key, Long projectId) {
+ public void deleteProjectProperty(String key, String projectUuid) {
try (DbSession session = mybatis.openSession(false)) {
- deleteProjectProperty(key, projectId, session);
+ deleteProjectProperty(key, projectUuid, session);
session.commit();
}
}
- public void deleteProjectProperty(String key, Long projectId, DbSession session) {
- getMapper(session).deleteProjectProperty(key, projectId);
+ public void deleteProjectProperty(String key, String projectUuid, DbSession session) {
+ getMapper(session).deleteProjectProperty(key, projectUuid);
}
public void deleteProjectProperties(String key, String value, DbSession session) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java
index 7f4d98b1636..5e8c4912860 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java
@@ -40,11 +40,11 @@ public interface PropertiesMapper {
List<PropertyDto> selectByKeys(@Param("keys") List<String> keys);
- List<PropertyDto> selectByKeysAndComponentIds(@Param("keys") List<String> keys, @Param("componentIds") List<Long> componentIds);
+ List<PropertyDto> selectByKeysAndComponentUuids(@Param("keys") List<String> keys, @Param("componentUuids") List<String> componentUuids);
List<PropertyDto> selectByKeyAndUserIdAndComponentQualifier(@Param("key") String key, @Param("userId") int userId, @Param("qualifier") String qualifier);
- List<PropertyDto> selectByComponentIds(@Param("componentIds") List<Long> componentIds);
+ List<PropertyDto> selectByComponentUuids(@Param("componentUuids") List<String> componentUuids);
List<PropertyDto> selectByQuery(@Param("query") PropertyQuery query);
@@ -55,20 +55,20 @@ public interface PropertiesMapper {
List<Long> selectIdsByOrganizationAndMatchingLogin(@Param("organizationUuid") String organizationUuid, @Param("login") String login,
@Param("propertyKeys") List<String> propertyKeys);
- void insertAsEmpty(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId,
+ void insertAsEmpty(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid,
@Param("now") long now);
- void insertAsText(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId,
+ void insertAsText(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid,
@Param("value") String value, @Param("now") long now);
- void insertAsClob(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId,
+ void insertAsClob(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid,
@Param("value") String value, @Param("now") long now);
- int delete(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId);
+ int delete(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid);
int deleteById(long id);
- int deleteProjectProperty(@Param("key") String key, @Param("rId") Long componentId);
+ int deleteProjectProperty(@Param("key") String key, @Param("componentUuid") String componentUuid);
int deleteProjectProperties(@Param("key") String key, @Param("value") String value);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java
index ef7dfd01e93..aa257f20997 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java
@@ -31,7 +31,7 @@ public class PropertyDto {
private String key;
private String value;
- private Long resourceId;
+ private String componentUuid;
private Integer userId;
public String getKey() {
@@ -54,12 +54,12 @@ public class PropertyDto {
}
@CheckForNull
- public Long getResourceId() {
- return resourceId;
+ public String getComponentUuid() {
+ return componentUuid;
}
- public PropertyDto setResourceId(@Nullable Long resourceId) {
- this.resourceId = resourceId;
+ public PropertyDto setComponentUuid(@Nullable String componentUuid) {
+ this.componentUuid = componentUuid;
return this;
}
@@ -84,13 +84,13 @@ public class PropertyDto {
PropertyDto other = (PropertyDto) obj;
return Objects.equals(this.key, other.key)
&& Objects.equals(this.userId, other.userId)
- && Objects.equals(this.resourceId, other.resourceId)
+ && Objects.equals(this.componentUuid, other.componentUuid)
&& Objects.equals(this.value, other.value);
}
@Override
public int hashCode() {
- return Objects.hash(this.key, this.value, this.resourceId, this.userId);
+ return Objects.hash(this.key, this.value, this.componentUuid, this.userId);
}
@Override
@@ -98,7 +98,7 @@ public class PropertyDto {
return MoreObjects.toStringHelper(this)
.addValue(this.key)
.addValue(this.value)
- .addValue(this.resourceId)
+ .addValue(this.componentUuid)
.addValue(this.userId)
.toString();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java
index 2053c2fe141..04f5eafa324 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java
@@ -24,12 +24,12 @@ import javax.annotation.Nullable;
public class PropertyQuery {
private final String key;
- private final Long componentId;
+ private final String componentUuid;
private final Integer userId;
private PropertyQuery(Builder builder) {
this.key = builder.key;
- this.componentId = builder.componentId;
+ this.componentUuid = builder.componentUuid;
this.userId = builder.userId;
}
@@ -37,8 +37,8 @@ public class PropertyQuery {
return key;
}
- public Long componentId() {
- return componentId;
+ public String componentUuid() {
+ return componentUuid;
}
public Integer userId() {
@@ -51,7 +51,7 @@ public class PropertyQuery {
public static class Builder {
private String key;
- private Long componentId;
+ private String componentUuid;
private Integer userId;
public Builder setKey(String key) {
@@ -59,8 +59,8 @@ public class PropertyQuery {
return this;
}
- public Builder setComponentId(@Nullable Long componentId) {
- this.componentId = componentId;
+ public Builder setComponentUuid(@Nullable String componentUuid) {
+ this.componentUuid = componentUuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPair.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPair.java
deleted file mode 100644
index d03a84beefb..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPair.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.db.purge;
-
-import java.util.Objects;
-import javax.annotation.Nullable;
-
-public class IdUuidPair {
- private Long id;
- private String uuid;
-
- public IdUuidPair() {
- }
-
- public IdUuidPair(long id, String uuid) {
- this.id = id;
- this.uuid = uuid;
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- @Override
- public String toString() {
- return "IdUuidPair{" +
- "id=" + id +
- ", uuid='" + uuid + '\'' +
- '}';
- }
-
- @Override
- public boolean equals(@Nullable Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- IdUuidPair that = (IdUuidPair) o;
- return Objects.equals(id, that.id) && Objects.equals(uuid, that.uuid);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(id, uuid);
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
index ac0cabedd62..8f3e4309222 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -54,8 +54,8 @@ class PurgeCommands {
this(session, session.getMapper(PurgeMapper.class), profiler, system2);
}
- List<IdUuidPair> selectSnapshotIdUuids(PurgeSnapshotQuery query) {
- return purgeMapper.selectAnalysisIdsAndUuids(query);
+ List<String> selectSnapshotUuids(PurgeSnapshotQuery query) {
+ return purgeMapper.selectAnalysisUuids(query);
}
void deleteAnalyses(String rootComponentUuid) {
@@ -69,8 +69,7 @@ class PurgeCommands {
session.commit();
profiler.stop();
- List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(
- purgeMapper.selectAnalysisIdsAndUuids(new PurgeSnapshotQuery(rootComponentUuid))), MAX_SNAPSHOTS_PER_QUERY);
+ List<List<String>> analysisUuidsPartitions = Lists.partition(purgeMapper.selectAnalysisUuids(new PurgeSnapshotQuery(rootComponentUuid)), MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
@@ -94,12 +93,12 @@ class PurgeCommands {
PurgeSnapshotQuery query = new PurgeSnapshotQuery(rootUuid)
.setIslast(false)
.setStatus(UNPROCESSED_STATUS);
- deleteAnalyses(purgeMapper.selectAnalysisIdsAndUuids(query));
+ deleteAnalyses(purgeMapper.selectAnalysisUuids(query));
}
@VisibleForTesting
- void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
- List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
+ void deleteAnalyses(List<String> analysisIdUuids) {
+ List<List<String>> analysisUuidsPartitions = Lists.partition(analysisIdUuids, MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
@@ -129,8 +128,8 @@ class PurgeCommands {
profiler.stop();
}
- void purgeAnalyses(List<IdUuidPair> analysisUuids) {
- List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
+ void purgeAnalyses(List<String> analysisUuids) {
+ List<List<String>> analysisUuidsPartitions = Lists.partition(analysisUuids, MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
@@ -190,14 +189,14 @@ class PurgeCommands {
profiler.stop();
}
- void deletePermissions(long rootId) {
+ void deletePermissions(String rootUuid) {
profiler.start("deletePermissions (group_roles)");
- purgeMapper.deleteGroupRolesByComponentId(rootId);
+ purgeMapper.deleteGroupRolesByComponentUuid(rootUuid);
session.commit();
profiler.stop();
profiler.start("deletePermissions (user_roles)");
- purgeMapper.deleteUserRolesByComponentId(rootId);
+ purgeMapper.deleteUserRolesByComponentUuid(rootUuid);
session.commit();
profiler.stop();
}
@@ -221,15 +220,14 @@ class PurgeCommands {
profiler.stop();
}
- void deleteByRootAndModulesOrSubviews(List<IdUuidPair> rootAndModulesOrSubviewsIds) {
- if (rootAndModulesOrSubviewsIds.isEmpty()) {
+ void deleteByRootAndModulesOrSubviews(List<String> rootAndModulesOrSubviewsUuids) {
+ if (rootAndModulesOrSubviewsUuids.isEmpty()) {
return;
}
- List<List<Long>> idPartitions = Lists.partition(IdUuidPairs.ids(rootAndModulesOrSubviewsIds), MAX_RESOURCES_PER_QUERY);
- List<List<String>> uuidsPartitions = Lists.partition(IdUuidPairs.uuids(rootAndModulesOrSubviewsIds), MAX_RESOURCES_PER_QUERY);
+ List<List<String>> uuidsPartitions = Lists.partition(rootAndModulesOrSubviewsUuids, MAX_RESOURCES_PER_QUERY);
profiler.start("deleteByRootAndModulesOrSubviews (properties)");
- idPartitions.forEach(purgeMapper::deletePropertiesByComponentIds);
+ uuidsPartitions.forEach(purgeMapper::deletePropertiesByComponentUuids);
session.commit();
profiler.stop();
@@ -239,15 +237,14 @@ class PurgeCommands {
profiler.stop();
}
- void deleteDisabledComponentsWithoutIssues(List<IdUuidPair> disabledComponentsWithoutIssue) {
+ void deleteDisabledComponentsWithoutIssues(List<String> disabledComponentsWithoutIssue) {
if (disabledComponentsWithoutIssue.isEmpty()) {
return;
}
- List<List<Long>> idPartitions = Lists.partition(IdUuidPairs.ids(disabledComponentsWithoutIssue), MAX_RESOURCES_PER_QUERY);
- List<List<String>> uuidsPartitions = Lists.partition(IdUuidPairs.uuids(disabledComponentsWithoutIssue), MAX_RESOURCES_PER_QUERY);
+ List<List<String>> uuidsPartitions = Lists.partition(disabledComponentsWithoutIssue, MAX_RESOURCES_PER_QUERY);
profiler.start("deleteDisabledComponentsWithoutIssues (properties)");
- idPartitions.forEach(purgeMapper::deletePropertiesByComponentIds);
+ uuidsPartitions.forEach(purgeMapper::deletePropertiesByComponentUuids);
session.commit();
profiler.stop();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index b88546e6a6e..10a2e5ba01a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -88,7 +88,7 @@ public class PurgeDao implements Dao {
}
private static void purgeAnalyses(PurgeCommands commands, String rootUuid) {
- List<IdUuidPair> analysisUuids = commands.selectSnapshotIdUuids(
+ List<String> analysisUuids = commands.selectSnapshotUuids(
new PurgeSnapshotQuery(rootUuid)
.setIslast(false)
.setNotPurged(true));
@@ -122,7 +122,7 @@ public class PurgeDao implements Dao {
}
private static void deleteOldDisabledComponents(PurgeCommands commands, PurgeMapper mapper, String rootUuid) {
- List<IdUuidPair> disabledComponentsWithoutIssue = mapper.selectDisabledComponentsWithoutIssues(rootUuid);
+ List<String> disabledComponentsWithoutIssue = mapper.selectDisabledComponentsWithoutIssues(rootUuid);
commands.deleteDisabledComponentsWithoutIssues(disabledComponentsWithoutIssue);
}
@@ -190,12 +190,7 @@ public class PurgeDao implements Dao {
}
private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) {
- List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid);
- long rootId = rootAndModulesOrSubviews.stream()
- .filter(pair -> pair.getUuid().equals(rootUuid))
- .map(IdUuidPair::getId)
- .findFirst()
- .orElseThrow(() -> new IllegalArgumentException("Couldn't find root component with uuid " + rootUuid));
+ List<String> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid);
commands.deleteLinks(rootUuid);
commands.deleteAnalyses(rootUuid);
commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews);
@@ -208,7 +203,7 @@ public class PurgeDao implements Dao {
commands.deleteLiveMeasures(rootUuid);
commands.deleteProjectMappings(rootUuid);
commands.deleteProjectAlmBindings(rootUuid);
- commands.deletePermissions(rootId);
+ commands.deletePermissions(rootUuid);
commands.deleteNewCodePeriods(rootUuid);
commands.deleteBranch(rootUuid);
commands.deleteComponents(rootUuid);
@@ -234,9 +229,9 @@ public class PurgeDao implements Dao {
}
private static void deleteNonRootComponentsInView(Set<ComponentDto> nonRootComponents, PurgeCommands purgeCommands) {
- List<IdUuidPair> subviewsOrProjectCopies = nonRootComponents.stream()
+ List<String> subviewsOrProjectCopies = nonRootComponents.stream()
.filter(PurgeDao::isModuleOrSubview)
- .map(PurgeDao::toIdUuidPair)
+ .map(ComponentDto::uuid)
.collect(MoreCollectors.toList());
purgeCommands.deleteByRootAndModulesOrSubviews(subviewsOrProjectCopies);
List<String> nonRootComponentUuids = nonRootComponents.stream().map(ComponentDto::uuid).collect(MoreCollectors.toList(nonRootComponents.size()));
@@ -252,12 +247,8 @@ public class PurgeDao implements Dao {
return SCOPE_PROJECT.equals(dto.scope()) && QUALIFIERS_MODULE_SUBVIEW.contains(dto.qualifier());
}
- private static IdUuidPair toIdUuidPair(ComponentDto dto) {
- return new IdUuidPair(dto.getId(), dto.uuid());
- }
-
- public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<IdUuidPair> analysisIdUuids) {
- new PurgeCommands(session, profiler, system2).deleteAnalyses(analysisIdUuids);
+ public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<String> analysisUuids) {
+ new PurgeCommands(session, profiler, system2).deleteAnalyses(analysisUuids);
}
private static PurgeMapper mapper(DbSession session) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 5000b6fcbec..b269b5010c1 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -27,12 +27,12 @@ import org.apache.ibatis.annotations.Param;
public interface PurgeMapper {
- List<IdUuidPair> selectAnalysisIdsAndUuids(PurgeSnapshotQuery query);
+ List<String> selectAnalysisUuids(PurgeSnapshotQuery query);
/**
* Returns the list of modules/subviews and the application/view/project for the specified project_uuid.
*/
- List<IdUuidPair> selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid);
+ List<String> selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid);
Set<String> selectDisabledComponentsWithFileSource(@Param("projectUuid") String projectUuid);
@@ -64,7 +64,7 @@ public interface PurgeMapper {
void deleteProjectLinksByProjectUuid(@Param("rootUuid") String rootUuid);
- void deletePropertiesByComponentIds(@Param("componentIds") List<Long> componentIds);
+ void deletePropertiesByComponentUuids(@Param("componentUuids") List<String> componentUuids);
void deleteComponentsByProjectUuid(@Param("rootUuid") String rootUuid);
@@ -72,9 +72,9 @@ public interface PurgeMapper {
void deleteComponentsByUuids(@Param("componentUuids") List<String> componentUuids);
- void deleteGroupRolesByComponentId(@Param("rootId") long rootId);
+ void deleteGroupRolesByComponentUuid(@Param("rootUuid") String rootUuid);
- void deleteUserRolesByComponentId(@Param("rootId") long rootId);
+ void deleteUserRolesByComponentUuid(@Param("rootUuid") String rootUuid);
void deleteManualMeasuresByComponentUuids(@Param("componentUuids") List<String> componentUuids);
@@ -95,7 +95,7 @@ public interface PurgeMapper {
@CheckForNull
String selectSpecificAnalysisNewCodePeriod(@Param("projectUuid") String projectUuid);
- List<IdUuidPair> selectDisabledComponentsWithoutIssues(@Param("projectUuid") String projectUuid);
+ List<String> selectDisabledComponentsWithoutIssues(@Param("projectUuid") String projectUuid);
void deleteIssuesFromKeys(@Param("keys") List<String> keys);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java
index 01ce032d9e4..57119b9ef73 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java
@@ -29,7 +29,6 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbSession;
-import org.sonar.db.purge.IdUuidPair;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.purge.PurgeProfiler;
import org.sonar.db.purge.PurgeableAnalysisDto;
@@ -69,14 +68,10 @@ public class DefaultPeriodCleaner {
}
purgeDao.deleteAnalyses(
session, profiler,
- snapshots.stream().map(DefaultPeriodCleaner::toIdUuidPair).collect(MoreCollectors.toList(snapshots.size())));
+ snapshots.stream().map(PurgeableAnalysisDto::getAnalysisUuid).collect(MoreCollectors.toList(snapshots.size())));
return snapshots;
}
- private static IdUuidPair toIdUuidPair(PurgeableAnalysisDto snapshot) {
- return new IdUuidPair(snapshot.getAnalysisId(), snapshot.getAnalysisUuid());
- }
-
private List<PurgeableAnalysisDto> selectAnalysesOfComponent(String componentUuid, DbSession session) {
return purgeDao.selectPurgeableAnalyses(componentUuid, session);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java
index 4eb43445c95..a0a21feb9ab 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java
@@ -27,17 +27,17 @@ import javax.annotation.Nullable;
*/
public class ProjectQgateAssociationDto {
- private Long id;
+ private String uuid;
private String key;
private String name;
private String gateId;
- public Long getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
- public ProjectQgateAssociationDto setId(Long id) {
- this.id = id;
+ public ProjectQgateAssociationDto setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ProjectQprofileAssociationDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ProjectQprofileAssociationDto.java
index 25255663287..ed125cde64a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ProjectQprofileAssociationDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ProjectQprofileAssociationDto.java
@@ -23,16 +23,11 @@ import javax.annotation.CheckForNull;
public class ProjectQprofileAssociationDto {
- private Long projectId;
private String projectUuid;
private String projectKey;
private String projectName;
private String profileKey;
- public Long getProjectId() {
- return projectId;
- }
-
public String getProjectUuid() {
return projectUuid;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
index bd7541a9caa..4cc86238ccf 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
@@ -40,11 +40,11 @@ public class RoleDao implements Dao {
* @throws IllegalArgumentException this method does not support permissions {@link UserRole#USER user} nor
* {@link UserRole#CODEVIEWER codeviewer} because it does not support public root components.
*/
- public List<Long> selectComponentIdsByPermissionAndUserId(DbSession dbSession, String permission, int userId) {
+ public List<String> selectComponentUuidsByPermissionAndUserId(DbSession dbSession, String permission, int userId) {
checkArgument(
!UNSUPPORTED_PROJECT_PERMISSIONS.contains(permission),
- "Permissions %s are not supported by selectComponentIdsByPermissionAndUserId", UNSUPPORTED_PROJECT_PERMISSIONS);
- return mapper(dbSession).selectComponentIdsByPermissionAndUserId(permission, userId);
+ "Permissions %s are not supported by selectComponentUuidsByPermissionAndUserId", UNSUPPORTED_PROJECT_PERMISSIONS);
+ return mapper(dbSession).selectComponentUuidsByPermissionAndUserId(permission, userId);
}
public void deleteGroupRolesByGroupId(DbSession session, int groupId) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
index 2a4f251352c..01dd4f2f6c2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
@@ -24,7 +24,7 @@ import org.apache.ibatis.annotations.Param;
public interface RoleMapper {
- List<Long> selectComponentIdsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") int userId);
+ List<String> selectComponentUuidsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") int userId);
void deleteGroupRolesByGroupId(int groupId);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml
index d215bb58a2a..6a836e97aed 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml
@@ -4,7 +4,6 @@
<mapper namespace="org.sonar.db.component.ComponentKeyUpdaterMapper">
<resultMap id="resourceResultMap" type="Resource">
- <id property="id" column="id"/>
<result property="key" column="kee"/>
<result property="uuid" column="uuid"/>
<result property="deprecatedKey" column="deprecated_kee"/>
@@ -42,7 +41,7 @@
<update id="updateComponent" parameterType="Resource">
update components
set kee = #{key,jdbcType=VARCHAR}, deprecated_kee = #{deprecatedKey,jdbcType=VARCHAR}
- where id = #{id,jdbcType=BIGINT}
+ where uuid = #{uuid,jdbcType=VARCHAR}
</update>
<update id="updateProject">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 6eb7660e890..ebaec604d12 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -3,7 +3,6 @@
<mapper namespace="org.sonar.db.component.ComponentMapper">
<sql id="componentColumns">
- p.id,
p.organization_uuid as organizationUuid,
p.uuid as uuid,
p.uuid_path as uuidPath,
@@ -56,13 +55,6 @@
and pb.branch_type='PULL_REQUEST'
</select>
- <select id="selectById" parameterType="long" resultType="Component">
- SELECT
- <include refid="componentColumns"/>
- FROM components p
- where p.id = #{id,jdbcType=BIGINT}
- </select>
-
<select id="selectByUuid" parameterType="String" resultType="Component">
SELECT
<include refid="componentColumns"/>
@@ -131,18 +123,6 @@
</where>
</select>
- <select id="selectByIds" parameterType="long" resultType="Component">
- select
- <include refid="componentColumns"/>
- from components p
- where
- p.enabled=${_true}
- and p.id in
- <foreach collection="ids" open="(" close=")" item="id" separator=",">
- #{id,jdbcType=BIGINT}
- </foreach>
- </select>
-
<select id="selectByUuids" parameterType="String" resultType="Component">
select
<include refid="componentColumns"/>
@@ -285,13 +265,13 @@
and p.qualifier = 'BRC'
</select>
- <select id="countComponentByOrganizationAndId" resultType="int">
+ <select id="countComponentByOrganizationAndUuid" resultType="int">
select
count(1)
from components p
where
p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
- and p.id = #{componentId,jdbcType=BIGINT}
+ and p.uuid = #{componentUuid,jdbcType=BIGINT}
</select>
<select id="selectByQuery" resultType="Component">
@@ -302,7 +282,7 @@
</select>
<select id="countByQuery" resultType="int">
- select count(p.id)
+ select count(p.uuid)
<include refid="sqlSelectByQuery"/>
</select>
@@ -325,12 +305,6 @@
#{qualifier,jdbcType=VARCHAR}
</foreach>
</if>
- <if test="query.componentIds!=null">
- and p.id in
- <foreach collection="query.componentIds" item="componentId" open="(" close=")" separator=",">
- #{componentId,jdbcType=BIGINT}
- </foreach>
- </if>
<if test="query.componentKeys!=null">
and p.kee in
<foreach collection="query.componentKeys" item="componentKey" open="(" close=")" separator=",">
@@ -549,7 +523,6 @@
<select id="scrollAllFilesForFileMove" parameterType="map" resultType="org.sonar.db.component.FileMoveRowDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
select
- p.id,
p.uuid as uuid,
p.kee as kee,
p.path as path,
@@ -565,7 +538,7 @@
and p.path is not null
</select>
- <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <insert id="insert" parameterType="Component">
INSERT INTO components (
organization_uuid,
kee,
@@ -740,8 +713,8 @@
and private &lt;&gt; #{isPrivate,jdbcType=BOOLEAN}
</update>
- <delete id="delete" parameterType="long">
- DELETE FROM components WHERE id=#{id,jdbcType=BIGINT}
+ <delete id="delete" parameterType="String">
+ DELETE FROM components WHERE uuid=#{componentUuid,jdbcType=VARCHAR}
</delete>
<select id="selectAllSiblingComponentKeysHavingOpenIssues" resultType="KeyWithUuid">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index bffb4c01753..47a12351ea4 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -151,7 +151,7 @@
inner join user_roles u on
u.organization_uuid = org.uuid
and u.user_id = #{userId,jdbcType=INTEGER}
- and u.resource_id is null
+ and u.component_uuid is null
and u.role = #{permission,jdbcType=VARCHAR}
union
select
@@ -159,7 +159,7 @@
from organizations org
inner join group_roles g on
g.organization_uuid = org.uuid
- and g.resource_id is null
+ and g.component_uuid is null
and g.role = #{permission,jdbcType=VARCHAR}
inner join groups_users gu on
gu.group_id = g.group_id
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
index 987719d1afe..32c918d3135 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
@@ -9,7 +9,7 @@
inner join groups_users gu on gr.group_id=gu.group_id
where
gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gu.user_id=#{userId, jdbcType=INTEGER}
union
@@ -19,7 +19,7 @@
where
gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
gr.group_id is null and
- gr.resource_id is null
+ gr.component_uuid is null
union
@@ -28,7 +28,7 @@
where
ur.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
ur.user_id=#{userId, jdbcType=INTEGER}
- and ur.resource_id is null
+ and ur.component_uuid is null
</select>
<select id="selectOrganizationPermissionsOfAnonymous" parameterType="map" resultType="string">
@@ -36,7 +36,7 @@
from group_roles gr
where
gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is null
</select>
@@ -49,7 +49,7 @@
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is not null and
gr.group_id != #{excludedGroupId, jdbcType=INTEGER}
@@ -59,7 +59,7 @@
from user_roles ur
where
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
- ur.resource_id is null and
+ ur.component_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR}
) remaining
</select>
@@ -73,7 +73,7 @@
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is not null and
gu.user_id != #{excludedUserId, jdbcType=INTEGER}
@@ -83,7 +83,7 @@
from user_roles ur
where
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
- ur.resource_id is null and
+ ur.component_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR} and
ur.user_id != #{excludedUserId, jdbcType=INTEGER}
) remaining
@@ -96,7 +96,7 @@
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is not null
union
@@ -105,7 +105,7 @@
from user_roles ur
where
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
- ur.resource_id is null and
+ ur.component_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR}
</select>
@@ -118,7 +118,7 @@
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is not null and
(gu.group_id != #{groupId, jdbcType=INTEGER} or gu.user_id != #{userId, jdbcType=INTEGER})
@@ -128,7 +128,7 @@
from user_roles ur
where
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
- ur.resource_id is null and
+ ur.component_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR}
) remaining
</select>
@@ -142,7 +142,7 @@
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is not null
union
@@ -151,7 +151,7 @@
from user_roles ur
where
ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
- ur.resource_id is null and
+ ur.component_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR} and
ur.user_id != #{userId, jdbcType=INTEGER}
) remaining
@@ -163,7 +163,7 @@
inner join groups_users gu on gr.group_id = gu.group_id
where
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
gr.group_id is not null and
gu.user_id = #{userId, jdbcType=INTEGER}
@@ -172,14 +172,14 @@
select ur.organization_uuid
from user_roles ur
where
- ur.resource_id is null and
+ ur.component_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR} and
ur.user_id = #{userId, jdbcType=INTEGER}
</select>
- <select id="keepAuthorizedProjectIdsForUser" parameterType="map" resultType="long">
+ <select id="keepAuthorizedProjectUuidsForUser" parameterType="map" resultType="String">
select
- gr.resource_id
+ gr.component_uuid
from
group_roles gr
where
@@ -196,23 +196,23 @@
and gr.group_id = gu.group_id
)
)
- and <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">
- gr.resource_id=#{element, jdbcType=BIGINT}
+ and <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or ">
+ gr.component_uuid=#{element, jdbcType=VARCHAR}
</foreach>
union
select
- p.id
+ p.uuid
from
user_roles ur
inner join components p on
- p.id = ur.resource_id
+ p.uuid = ur.component_uuid
where
ur.role=#{role, jdbcType=VARCHAR}
and ur.user_id=#{userId, jdbcType=INTEGER}
- and <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">
- p.id=#{element, jdbcType=BIGINT}
+ and <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or ">
+ p.uuid=#{element, jdbcType=VARCHAR}
</foreach>
union
@@ -220,89 +220,34 @@
<include refid="sqlSelectPublicProjectsIfRole"/>
</select>
- <select id="keepAuthorizedProjectIdsForAnonymous" parameterType="map" resultType="long">
- select
- gr.resource_id
- from
- group_roles gr
- where
- gr.role=#{role, jdbcType=VARCHAR}
- and gr.group_id is null
- and <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">
- gr.resource_id=#{element, jdbcType=BIGINT}
- </foreach>
-
- union
-
- <include refid="sqlSelectPublicProjectsIfRole"/>
- </select>
-
<sql id="sqlSelectPublicProjectsIfRole">
select
- p.id
+ p.uuid
from
components p
where
- <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">
- p.id=#{element ,jdbcType=BIGINT}
+ <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or ">
+ p.uuid=#{element ,jdbcType=VARCHAR}
</foreach>
and p.private = ${_false}
and #{role, jdbcType=VARCHAR} in ('user','codeviewer')
</sql>
- <select id="keepAuthorizedProjectUuidsForUser" parameterType="map" resultType="String">
- select p.uuid
- from components p
- inner join group_roles gr on p.id = gr.resource_id
- where
- gr.role = #{permission, jdbcType=VARCHAR}
- and (gr.group_id is null or exists (
- select 1 from groups_users gu
- where
- gu.user_id = #{userId, jdbcType=INTEGER}
- and gr.group_id = gu.group_id)
- )
- and p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach>
-
- union
-
- select p.uuid
- from components p
- inner join user_roles ur on p.id = ur.resource_id
- where
- ur.role=#{permission, jdbcType=VARCHAR}
- and ur.user_id=#{userId, jdbcType=INTEGER}
- and p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach>
-
- <if test="permission == 'user' or permission == 'codeviewer'">
- union
-
- select p.uuid
- from components p
- where
- p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach>
- and p.private = ${_false}
- </if>
- </select>
-
- <select id="keepAuthorizedProjectUuidsForAnonymous" parameterType="map" resultType="String">
- select p.uuid
- from components p
- inner join group_roles gr on p.id = gr.resource_id
+ <select id="keepAuthorizedProjectUuidsForAnonymous" parameterType="map" resultType="String">
+ select
+ gr.component_uuid
+ from
+ group_roles gr
where
- gr.role=#{permission, jdbcType=VARCHAR}
+ gr.role=#{role, jdbcType=VARCHAR}
and gr.group_id is null
- and p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach>
+ and <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or ">
+ gr.component_uuid=#{element, jdbcType=VARCHAR}
+ </foreach>
- <if test="permission == 'user' or permission == 'codeviewer'">
- union
+ union
- select p.uuid
- from components p
- where
- p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" index="index" separator=",">#{projectUuid, jdbcType=VARCHAR}</foreach>
- and p.private = ${_false}
- </if>
+ <include refid="sqlSelectPublicProjectsIfRole"/>
</select>
<select id="keepAuthorizedUsersForRoleAndProject" parameterType="map" resultType="int">
@@ -313,7 +258,7 @@
inner join group_roles gr on
gr.group_id=gu.group_id
where
- gr.resource_id=#{componentId, jdbcType=BIGINT}
+ gr.component_uuid=#{componentUuid, jdbcType=VARCHAR}
and gr.role=#{role, jdbcType=VARCHAR}
and gu.user_id in
<foreach collection="userIds" open="(" close=")" item="id" separator=",">
@@ -327,7 +272,7 @@
from
user_roles ur
where
- ur.resource_id=#{componentId, jdbcType=BIGINT}
+ ur.component_uuid=#{componentUuid, jdbcType=VARCHAR}
and ur.role=#{role, jdbcType=VARCHAR}
and ur.user_id IN
<foreach collection="userIds" open="(" close=")" item="id" separator=",">
@@ -351,7 +296,7 @@
from
components p
where
- p.id =#{componentId, jdbcType=BIGINT}
+ p.uuid =#{componentUuid, jdbcType=VARCHAR}
and p.private = ${_false}
and #{role, jdbcType=VARCHAR} in ('user','codeviewer')
)
@@ -360,7 +305,7 @@
<select id="selectProjectPermissions" parameterType="map" resultType="String">
select ur.role
from user_roles ur
- inner join components p on p.id = ur.resource_id
+ inner join components p on p.uuid = ur.component_uuid
where
p.uuid = #{projectUuid, jdbcType=VARCHAR} and
p.organization_uuid = ur.organization_uuid and
@@ -371,7 +316,7 @@
select gr.role
from group_roles gr
inner join groups_users gu on gr.group_id = gu.group_id
- inner join components p on p.id = gr.resource_id
+ inner join components p on p.uuid = gr.component_uuid
where
p.uuid = #{projectUuid, jdbcType=VARCHAR} and
p.organization_uuid = gr.organization_uuid and
@@ -392,7 +337,7 @@
from
group_roles gr
inner join components p on
- p.id = gr.resource_id
+ p.uuid = gr.component_uuid
where
p.uuid = #{projectUuid, jdbcType=VARCHAR}
and p.organization_uuid = gr.organization_uuid
@@ -409,7 +354,7 @@
inner join user_roles ur on
ur.user_id = u.id
and ur.role=#{permission, jdbcType=VARCHAR}
- and ur.resource_id is null
+ and ur.component_uuid is null
where
u.email is not null
@@ -425,7 +370,7 @@
inner join group_roles gr on
gr.group_id = gu.group_id
and gr.role = #{permission, jdbcType=VARCHAR}
- and gr.resource_id is null
+ and gr.component_uuid is null
where
u.email is not null
@@ -440,7 +385,7 @@
exists (
select 1
from user_roles ur
- inner join components p on p.id = ur.resource_id and p.organization_uuid = ur.organization_uuid
+ inner join components p on p.uuid = ur.component_uuid and p.organization_uuid = ur.organization_uuid
where
p.kee = #{projectKey, jdbcType=VARCHAR}
and ur.role = #{permission, jdbcType=VARCHAR}
@@ -448,7 +393,7 @@
) or exists (
select 1
from components p
- inner join group_roles gr on gr.resource_id = p.id and gr.organization_uuid = p.organization_uuid
+ inner join group_roles gr on gr.component_uuid = p.uuid and gr.organization_uuid = p.organization_uuid
inner join groups_users gu on gu.group_id = gr.group_id
where
p.kee = #{projectKey, jdbcType=VARCHAR}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
index dda0afa919e..d46247961af 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
@@ -3,17 +3,17 @@
<mapper namespace="org.sonar.db.permission.GroupPermissionMapper">
- <select id="groupsCountByProjectIdAndPermission" parameterType="map"
+ <select id="groupsCountByProjectUuidAndPermission" parameterType="map"
resultType="org.sonar.db.permission.CountPerProjectPermission">
SELECT
count(1) as count,
permission,
- componentId
+ componentUuid
FROM (
SELECT
g.name as name,
group_role.role as permission,
- group_role.resource_id as componentId
+ group_role.component_uuid as componentUuid
FROM
groups g
INNER JOIN group_roles group_role ON
@@ -23,20 +23,20 @@
SELECT
#{anyoneGroup} as name,
group_role.role as permission,
- group_role.resource_id as componentId
+ group_role.component_uuid as componentUuid
FROM
group_roles group_role
where
group_role.group_id IS NULL
) groups
where
- groups.componentId in
- <foreach collection="componentIds" open="(" close=")" item="id" separator=",">
- #{id,jdbcType=BIGINT}
+ groups.componentUuid in
+ <foreach collection="componentUuids" open="(" close=")" item="id" separator=",">
+ #{id,jdbcType=VARCHAR}
</foreach>
GROUP BY
groups.permission,
- groups.componentId
+ groups.componentUuid
</select>
<select id="selectGroupNamesByQuery" parameterType="map" resultType="string">
@@ -55,28 +55,28 @@
<sql id="groupsByQuery">
from (
- select g.id as groupId, g.name as name, gr.role as permission, gr.resource_id as componentId, gr.id as id
+ select g.id as groupId, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.id as id
from groups g
left join group_roles gr on g.id = gr.group_id
- <if test="query.componentId == null">
- and gr.resource_id is null
+ <if test="query.componentUuid == null">
+ and gr.component_uuid is null
</if>
- <if test="query.componentId != null">
- and gr.resource_id = #{query.componentId,jdbcType=BIGINT}
+ <if test="query.componentUuid != null">
+ and gr.component_uuid = #{query.componentUuid,jdbcType=VARCHAR}
</if>
where
g.organization_uuid = #{query.organizationUuid,jdbcType=VARCHAR}
union all
- select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.resource_id as componentId, gr.id as id
+ select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.id as id
from group_roles gr
<where>
- <if test="query.componentId == null">
- and gr.resource_id is null
+ <if test="query.componentUuid == null">
+ and gr.component_uuid is null
</if>
- <if test="query.componentId != null">
- and gr.resource_id = #{query.componentId,jdbcType=BIGINT}
+ <if test="query.componentUuid != null">
+ and gr.component_uuid = #{query.componentUuid,jdbcType=VARCHAR}
</if>
<if test="query.withAtLeastOnePermission()">
and gr.organization_uuid = #{query.organizationUuid,jdbcType=VARCHAR} and
@@ -85,7 +85,7 @@
</where>
) sub
- left join components p on sub.componentId = p.id
+ left join components p on sub.componentUuid = p.uuid
<where>
<if test="query.searchQueryToSql != null">
and lower(sub.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/'
@@ -94,7 +94,7 @@
<if test="query.withAtLeastOnePermission()">
and sub.permission is not null
<if test="query.componentUuid==null">
- and sub.componentId is null
+ and sub.componentUuid is null
</if>
<if test="query.componentUuid!=null">
and p.uuid = #{query.componentUuid,jdbcType=VARCHAR}
@@ -107,10 +107,10 @@
</sql>
<select id="selectByGroupIds" parameterType="map" resultType="GroupPermission">
- select sub.groupId as groupId, sub.componentId as resourceId, sub.permission as role, sub.organizationUuid as organizationUuid
+ select sub.groupId as groupId, sub.componentUuid as componentUuid, sub.permission as role, sub.organizationUuid as organizationUuid
from
(
- select gr.group_id as groupId, gr.resource_id as componentId, gr.role as permission, g.name as name, gr.organization_uuid as organizationUuid
+ select gr.group_id as groupId, gr.component_uuid as componentUuid, gr.role as permission, g.name as name, gr.organization_uuid as organizationUuid
from group_roles gr
inner join groups g ON g.id = gr.group_id
where gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
@@ -118,7 +118,7 @@
union all
- select 0 as groupId, gr.resource_id as componentId, gr.role as permission, 'Anyone' as name, gr.organization_uuid as organizationUuid
+ select 0 as groupId, gr.component_uuid as componentUuid, gr.role as permission, 'Anyone' as name, gr.organization_uuid as organizationUuid
from group_roles gr
where
gr.group_id is null and
@@ -129,11 +129,11 @@
<foreach collection="groupIds" open="(" close=")" item="groupId" separator=",">
#{groupId,jdbcType=INTEGER}
</foreach>
- <if test="projectId != null">
- and sub.componentId=#{projectId,jdbcType=BIGINT}
+ <if test="projectUuid != null">
+ and sub.componentUuid=#{projectUuid,jdbcType=VARCHAR}
</if>
- <if test="projectId==null">
- and sub.componentId is null
+ <if test="projectUuid==null">
+ and sub.componentUuid is null
</if>
</select>
@@ -142,7 +142,7 @@
from group_roles gr
where
gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
- gr.resource_id is null and
+ gr.component_uuid is null and
<choose>
<when test="groupId != null">
gr.group_id = #{groupId,jdbcType=INTEGER}
@@ -158,7 +158,7 @@
from group_roles gr
where
gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
- gr.resource_id = #{projectId,jdbcType=BIGINT} and
+ gr.component_uuid = #{projectUuid,jdbcType=VARCHAR} and
<choose>
<when test="groupId != null">
gr.group_id = #{groupId,jdbcType=INTEGER}
@@ -170,7 +170,7 @@
</select>
<select id="selectAllPermissionsByGroupId" parameterType="map" resultType="GroupPermission">
- select gr.group_id as groupId, gr.resource_id as resourceId, gr.role as role, gr.organization_uuid as organizationUuid
+ select gr.group_id as groupId, gr.component_uuid as componentUuid, gr.role as role, gr.organization_uuid as organizationUuid
from group_roles gr
where gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
and gr.group_id = #{groupId,jdbcType=INTEGER}
@@ -182,7 +182,7 @@
from
group_roles gr1
where
- gr1.resource_id = #{projectId,jdbcType=BIGINT}
+ gr1.component_uuid = #{projectUuid,jdbcType=VARCHAR}
and gr1.group_id is not null
and not exists (
select
@@ -190,7 +190,7 @@
from
group_roles gr2
where
- gr2.resource_id = gr1.resource_id
+ gr2.component_uuid = gr1.component_uuid
and gr2.group_id = gr1.group_id
and gr2.role = #{role,jdbcType=VARCHAR}
)
@@ -200,26 +200,26 @@
insert into group_roles (
organization_uuid,
group_id,
- resource_id,
+ component_uuid,
role
) values (
#{organizationUuid,jdbcType=VARCHAR},
#{groupId,jdbcType=INTEGER},
- #{resourceId,jdbcType=BIGINT},
+ #{componentUuid,jdbcType=BIGINT},
#{role,jdbcType=VARCHAR}
)
</insert>
- <delete id="deleteByRootComponentId" parameterType="long">
+ <delete id="deleteByRootComponentUuid" parameterType="String">
delete from group_roles
- where resource_id=#{rootComponentId,jdbcType=BIGINT}
+ where component_uuid=#{rootComponentUuid,jdbcType=VARCHAR}
</delete>
- <delete id="deleteByRootComponentIdAndGroupId">
+ <delete id="deleteByRootComponentUuidAndGroupId">
delete from
group_roles
where
- resource_id=#{rootComponentId,jdbcType=BIGINT}
+ component_uuid=#{rootComponentUuid,jdbcType=VARCHAR}
<choose>
<when test="groupId != null">
and group_id = #{groupId,jdbcType=INTEGER}
@@ -230,11 +230,11 @@
</choose>
</delete>
- <delete id="deleteByRootComponentIdAndPermission">
+ <delete id="deleteByRootComponentUuidAndPermission">
delete from
group_roles
where
- resource_id=#{rootComponentId,jdbcType=BIGINT}
+ component_uuid=#{rootComponentUuid,jdbcType=VARCHAR}
and role=#{permission,jdbcType=VARCHAR}
</delete>
@@ -244,11 +244,11 @@
role=#{permission,jdbcType=VARCHAR} and
organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and
<choose>
- <when test="rootComponentId != null">
- resource_id=#{rootComponentId,jdbcType=BIGINT}
+ <when test="rootComponentUuid != null">
+ component_uuid=#{rootComponentUuid,jdbcType=BIGINT}
</when>
<otherwise>
- resource_id is null
+ component_uuid is null
</otherwise>
</choose>
and
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
index 2df73ecf881..f3958e809f7 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
@@ -7,7 +7,7 @@
select
u.id as userId,
ur.organization_uuid as organizationUuid,
- ur.resource_id as componentId,
+ ur.component_uuid as componentUuid,
ur.role as permission
<include refid="sqlQueryJoins" />
<where>
@@ -33,14 +33,14 @@
from users u
left join user_roles ur on ur.user_id = u.id and ur.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
<choose>
- <when test="query.componentId == null">
- and ur.resource_id is null
+ <when test="query.componentUuid == null">
+ and ur.component_uuid is null
</when>
<otherwise>
- and ur.resource_id = #{query.componentId,jdbcType=BIGINT}
+ and ur.component_uuid = #{query.componentUuid,jdbcType=VARCHAR}
</otherwise>
</choose>
- left join components p on ur.resource_id = p.id
+ left join components p on ur.component_uuid = p.uuid
inner join organization_members om on u.id=om.user_id and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
<where>
<include refid="sqlQueryFilters" />
@@ -60,7 +60,7 @@
<sql id="sqlQueryJoins">
from users u
left join user_roles ur on ur.user_id = u.id
- left join components p on ur.resource_id = p.id
+ left join components p on ur.component_uuid = p.uuid
inner join organization_members om on u.id=om.user_id and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
</sql>
@@ -77,7 +77,7 @@
and ur.organization_uuid = om.organization_uuid
and ur.role is not null
<if test="query.componentUuid==null">
- and ur.resource_id is null
+ and ur.component_uuid is null
</if>
<if test="query.componentUuid!=null">
and p.uuid = #{query.componentUuid,jdbcType=VARCHAR}
@@ -94,7 +94,7 @@
where
ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
ur.user_id = #{userId,jdbcType=INTEGER} and
- ur.resource_id is null
+ ur.component_uuid is null
</select>
<select id="selectProjectPermissionsOfUser" parameterType="map" resultType="string">
@@ -102,17 +102,17 @@
from user_roles ur
where
ur.user_id = #{userId,jdbcType=INTEGER} and
- ur.resource_id = #{projectId,jdbcType=BIGINT}
+ ur.component_uuid = #{projectUuid,jdbcType=VARCHAR}
</select>
<select id="countUsersByProjectPermission" resultType="org.sonar.db.permission.CountPerProjectPermission">
- select ur.resource_id as componentId, ur.role as permission, count(u.login) as count
+ select ur.component_uuid as componentUuid, ur.role as permission, count(u.login) as count
from users u
inner join user_roles ur on ur.user_id = u.id
- inner join components p on p.id = ur.resource_id
+ inner join components p on p.uuid = ur.component_uuid
where u.active = ${_true}
- and p.id in <foreach collection="projectIds" open="(" close=")" item="projectId" separator=",">#{projectId}</foreach>
- group by ur.resource_id, ur.role
+ and p.uuid in <foreach collection="projectUuids" open="(" close=")" item="projectUuid" separator=",">#{projectUuid}</foreach>
+ group by ur.component_uuid, ur.role
</select>
<select id="selectUserIdsWithPermissionOnProjectBut" resultType="Integer">
@@ -121,7 +121,7 @@
from
user_roles ur1
where
- ur1.resource_id = #{projectId,jdbcType=BIGINT}
+ ur1.component_uuid = #{projectUuid,jdbcType=VARCHAR}
and role &lt;&gt; #{permission,jdbcType=VARCHAR}
and not exists (
select
@@ -129,7 +129,7 @@
from
user_roles ur2
where
- ur2.resource_id = ur1.resource_id
+ ur2.component_uuid = ur1.component_uuid
and ur2.user_id = ur1.user_id
and role = #{permission,jdbcType=VARCHAR}
)
@@ -139,12 +139,12 @@
insert into user_roles (
organization_uuid,
user_id,
- resource_id,
+ component_uuid,
role
) values (
#{organizationUuid,jdbcType=VARCHAR},
#{userId,jdbcType=INTEGER},
- #{componentId,jdbcType=BIGINT},
+ #{componentUuid,jdbcType=VARCHAR},
#{permission,jdbcType=VARCHAR}
)
</insert>
@@ -155,7 +155,7 @@
role = #{permission,jdbcType=VARCHAR} and
user_id = #{userId,jdbcType=INTEGER} and
organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
- resource_id is null
+ component_uuid is null
</delete>
<delete id="deleteProjectPermission" parameterType="map">
@@ -163,20 +163,20 @@
where
role = #{permission,jdbcType=VARCHAR} and
user_id = #{userId,jdbcType=INTEGER} and
- resource_id = #{projectId,jdbcType=BIGINT}
+ component_uuid = #{projectUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteProjectPermissions" parameterType="map">
delete from user_roles
where
- resource_id = #{projectId,jdbcType=BIGINT}
+ component_uuid = #{projectUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteProjectPermissionOfAnyUser" parameterType="map">
delete from
user_roles
where
- resource_id = #{projectId,jdbcType=BIGINT}
+ component_uuid = #{projectUuid,jdbcType=VARCHAR}
and role = #{permission,jdbcType=VARCHAR}
</delete>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
index ac862b11999..d7c96de6d65 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
@@ -13,7 +13,7 @@
WHERE
p.prop_key = #{notifKey,jdbcType=VARCHAR}
AND p.text_value = 'true'
- AND p.resource_id IS NULL
+ AND p.component_uuid IS NULL
<if test="projectKey != null">
UNION
@@ -28,7 +28,7 @@
WHERE
p.prop_key = #{notifKey,jdbcType=VARCHAR}
AND p.text_value = 'true'
- AND p.resource_id = c.id
+ AND p.component_uuid = c.uuid
</if>
</select>
@@ -43,7 +43,7 @@
p.user_id = u.id
and p.prop_key = #{notifKey,jdbcType=VARCHAR}
and p.text_value = 'true'
- and p.resource_id IS NULL
+ and p.component_uuid IS NULL
WHERE
u.email is not null
<if test="logins != null">
@@ -65,7 +65,7 @@
p.user_id = u.id
and p.prop_key = #{notifKey,jdbcType=VARCHAR}
and p.text_value = 'true'
- and p.resource_id = c.id
+ and p.component_uuid = c.uuid
WHERE
u.email is not null
<if test="logins != null">
@@ -80,7 +80,7 @@
p.is_empty as empty,
p.text_value as textValue,
p.clob_value as clobValue,
- p.resource_id as resourceId,
+ p.component_uuid as componentUuid,
p.user_id as userId
</sql>
@@ -90,7 +90,7 @@
from
properties p
where
- p.resource_id is null
+ p.component_uuid is null
and p.user_id is null
</select>
@@ -101,7 +101,7 @@
properties p,
components r
where
- p.resource_id=r.id
+ p.component_uuid=r.uuid
and p.user_id is null
and r.kee=#{resourceKey,jdbcType=VARCHAR}
</select>
@@ -113,11 +113,11 @@
properties p
where
p.prop_key=#{key}
- <if test="resourceId == null">
- and p.resource_id is null
+ <if test="componentUuid == null">
+ and p.component_uuid is null
</if>
- <if test="resourceId != null">
- and p.resource_id=#{resourceId}
+ <if test="componentUuid != null">
+ and p.component_uuid=#{componentUuid}
</if>
<if test="userId == null">
and p.user_id is null
@@ -137,12 +137,12 @@
<foreach collection="keys" open="(" close=")" item="key" separator=",">
#{key}
</foreach>
- and p.resource_id is null
+ and p.component_uuid is null
and p.user_id is null
order by p.created_at
</select>
- <select id="selectByKeysAndComponentIds" parameterType="map" resultType="ScrapProperty">
+ <select id="selectByKeysAndComponentUuids" parameterType="map" resultType="ScrapProperty">
select
<include refid="columnsToScrapPropertyDto"/>
from
@@ -152,22 +152,22 @@
<foreach collection="keys" open="(" close=")" item="key" separator=",">
#{key}
</foreach>
- and p.resource_id in
- <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
- #{componentId}
+ and p.component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
</foreach>
and p.user_id is null
</select>
- <select id="selectByComponentIds" parameterType="map" resultType="ScrapProperty">
+ <select id="selectByComponentUuids" parameterType="map" resultType="ScrapProperty">
select
<include refid="columnsToScrapPropertyDto"/>
from
properties p
where
- p.resource_id in
- <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
- #{componentId}
+ p.component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
</foreach>
and p.user_id is null
</select>
@@ -177,7 +177,7 @@
<include refid="columnsToScrapPropertyDto"/>
from
properties p
- inner join components prj on prj.id=p.resource_id and prj.qualifier = #{qualifier, jdbcType=VARCHAR}
+ inner join components prj on prj.uuid=p.component_uuid and prj.qualifier = #{qualifier, jdbcType=VARCHAR}
where
p.prop_key = #{key, jdbcType=VARCHAR}
and p.user_id = #{userId, jdbcType=INTEGER}
@@ -192,8 +192,8 @@
<if test="query.key() != null">
and p.prop_key=#{query.key,jdbcType=VARCHAR}
</if>
- <if test="query.componentId() != null">
- and p.resource_id=#{query.componentId,jdbcType=BIGINT}
+ <if test="query.componentUuid() != null">
+ and p.component_uuid=#{query.componentUuid,jdbcType=BIGINT}
</if>
<if test="query.userId() != null">
and p.user_id=#{query.userId,jdbcType=INTEGER}
@@ -204,7 +204,7 @@
<select id="selectIdsByOrganizationAndUser" parameterType="map" resultType="long">
select py.id
from properties py
- inner join components ps on py.resource_id = ps.id
+ inner join components ps on py.component_uuid = ps.uuid
where
py.user_id=#{userId,jdbcType=INTEGER}
and ps.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
@@ -213,7 +213,7 @@
<select id="selectIdsByOrganizationAndMatchingLogin" parameterType="String" resultType="long">
select py.id
from properties py
- inner join components ps on py.resource_id = ps.id
+ inner join components ps on py.component_uuid = ps.uuid
where
py.text_value like #{login,jdbcType=VARCHAR}
and py.prop_key in
@@ -237,14 +237,14 @@
insert into properties
(
prop_key,
- resource_id,
+ component_uuid,
user_id,
is_empty,
created_at
)
values (
#{key},
- #{componentId},
+ #{componentUuid},
#{userId,jdbcType=INTEGER},
${_true},
#{now}
@@ -255,7 +255,7 @@
insert into properties
(
prop_key,
- resource_id,
+ component_uuid,
user_id,
is_empty,
text_value,
@@ -263,7 +263,7 @@
)
values (
#{key},
- #{componentId},
+ #{componentUuid},
#{userId,jdbcType=INTEGER},
${_false},
#{value},
@@ -275,7 +275,7 @@
insert into properties
(
prop_key,
- resource_id,
+ component_uuid,
user_id,
is_empty,
clob_value,
@@ -283,7 +283,7 @@
)
values (
#{key},
- #{componentId},
+ #{componentUuid},
#{userId,jdbcType=INTEGER},
${_false},
#{value},
@@ -296,20 +296,20 @@
where
prop_key=#{key}
<choose>
- <when test="componentId != null &amp;&amp; userId != null">
- and resource_id=#{componentId}
+ <when test="componentUuid != null &amp;&amp; userId != null">
+ and component_uuid=#{componentUuid}
and user_id=#{userId,jdbcType=INTEGER}
</when>
- <when test="componentId != null">
- and resource_id=#{componentId}
+ <when test="componentUuid != null">
+ and component_uuid=#{componentUuid}
and user_id is null
</when>
<when test="userId != null">
- and resource_id is null
+ and component_uuid is null
and user_id=#{userId,jdbcType=INTEGER}
</when>
<otherwise>
- and resource_id is null
+ and component_uuid is null
and user_id is null
</otherwise>
</choose>
@@ -319,7 +319,7 @@
delete from properties
where
prop_key=#{key}
- and resource_id=#{rId}
+ and component_uuid=#{componentUuid}
and user_id is null
</delete>
@@ -328,7 +328,7 @@
where
prop_key=#{key}
and text_value = #{value}
- and resource_id is not null
+ and component_uuid is not null
and user_id is null
</delete>
@@ -336,14 +336,14 @@
delete from properties
where
prop_key=#{key}
- and resource_id is null
+ and component_uuid is null
and user_id is null
</delete>
<delete id="deleteGlobalProperties">
delete from properties
where
- resource_id is null
+ component_uuid is null
and user_id is null
</delete>
@@ -353,8 +353,8 @@
<if test="query.key() != null">
and prop_key=#{query.key,jdbcType=VARCHAR}
</if>
- <if test="query.componentId() != null">
- and resource_id=#{query.componentId,jdbcType=BIGINT}
+ <if test="query.componentUuid() != null">
+ and component_uuid=#{query.componentUuid,jdbcType=BIGINT}
</if>
<if test="query.userId() != null">
and user_id=#{query.userId,jdbcType=INTEGER}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index ede9138c4ad..d7869650ff4 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -3,9 +3,9 @@
<mapper namespace="org.sonar.db.purge.PurgeMapper">
- <select id="selectAnalysisIdsAndUuids" parameterType="map" resultType="IdUuidPair">
+ <select id="selectAnalysisUuids" parameterType="map" resultType="String">
select
- s.id as id, s.uuid as uuid
+ s.uuid as uuid
from
snapshots s
where
@@ -58,9 +58,9 @@
and pb.updated_at &lt; #{toDate}
</select>
- <select id="selectRootAndModulesOrSubviewsByProjectUuid" resultType="IdUuidPair" parameterType="String">
+ <select id="selectRootAndModulesOrSubviewsByProjectUuid" resultType="String" parameterType="String">
select
- p.id, p.uuid
+ p.uuid
from
components p
where
@@ -204,12 +204,12 @@
project_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
- <delete id="deletePropertiesByComponentIds" parameterType="map">
+ <delete id="deletePropertiesByComponentUuids" parameterType="map">
delete from properties
where
- resource_id in
- <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
- #{componentId}
+ component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
</foreach>
</delete>
@@ -234,16 +234,16 @@
</foreach>
</delete>
- <delete id="deleteGroupRolesByComponentId" parameterType="map">
+ <delete id="deleteGroupRolesByComponentUuid" parameterType="map">
delete from group_roles
where
- resource_id = #{rootId,jdbcType=INTEGER}
+ component_uuid = #{rootUuid,jdbcType=INTEGER}
</delete>
- <delete id="deleteUserRolesByComponentId" parameterType="map">
+ <delete id="deleteUserRolesByComponentUuid" parameterType="map">
delete from user_roles
where
- resource_id = #{rootId,jdbcType=INTEGER}
+ component_uuid = #{rootUuid,jdbcType=INTEGER}
</delete>
<delete id="deleteManualMeasuresByComponentUuids" parameterType="map">
@@ -311,9 +311,9 @@
</choose>
</select>
- <select id="selectDisabledComponentsWithoutIssues" resultType="IdUuidPair" parameterType="String">
+ <select id="selectDisabledComponentsWithoutIssues" resultType="String" parameterType="String">
SELECT
- p.id, p.uuid
+ p.uuid
FROM
components p
WHERE
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml
index d99aea3a41d..1ce91b0da20 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml
@@ -4,7 +4,7 @@
<mapper namespace="org.sonar.db.qualitygate.ProjectQgateAssociationMapper">
<select id="selectProjects" parameterType="map" resultType="ProjectQgateAssociation">
- SELECT proj.id as id, proj.kee as "key", proj.name as name, qg.id as gateId
+ SELECT proj.uuid as uuid, proj.kee as "key", proj.name as name, qg.id as gateId
FROM components proj
LEFT JOIN project_qgates prqg ON prqg.project_uuid=proj.uuid AND prqg.quality_gate_uuid = #{query.gateUuid, jdbcType=VARCHAR}
LEFT JOIN quality_gates qg ON qg.uuid = prqg.quality_gate_uuid
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 a8c61196813..b27d667f21c 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
@@ -335,7 +335,6 @@
<select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
select
pp.id as id,
- pj.id as projectId,
pj.uuid as projectUuid,
pj.kee as projectKey,
pj.name as projectName,
@@ -352,7 +351,7 @@
</select>
<select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
+ SELECT pp.id as id, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM components pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
@@ -364,7 +363,7 @@
</select>
<select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
+ SELECT pp.id as id, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM components pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
index 28d06b6c651..abd64ce07f0 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
@@ -3,28 +3,28 @@
<mapper namespace="org.sonar.db.user.RoleMapper">
- <select id="selectComponentIdsByPermissionAndUserId" parameterType="map" resultType="long">
+ <select id="selectComponentUuidsByPermissionAndUserId" parameterType="map" resultType="String">
select
- ur.resource_id
+ ur.component_uuid
from
user_roles ur
where
ur.user_id = #{userId,jdbcType=INTEGER}
and ur.role = #{permission,jdbcType=VARCHAR}
- and ur.resource_id is not null
+ and ur.component_uuid is not null
union
select
- gr.resource_id
+ gr.component_uuid
from
group_roles gr
inner join groups_users gu on
gr.group_id=gu.group_id
where
gr.role = #{permission,jdbcType=VARCHAR}
- and gr.resource_id is not null
+ and gr.component_uuid is not null
and gu.user_id=#{userId,jdbcType=INTEGER}
order by
- resource_id
+ component_uuid
</select>
<delete id="deleteGroupRolesByGroupId" parameterType="int">
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 2589b2325b3..dd428bb2980 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -175,7 +175,6 @@ ALTER TABLE "CE_TASK_MESSAGE" ADD CONSTRAINT "PK_CE_TASK_MESSAGE" PRIMARY KEY("U
CREATE INDEX "CE_TASK_MESSAGE_TASK" ON "CE_TASK_MESSAGE"("TASK_UUID");
CREATE TABLE "COMPONENTS"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"UUID" VARCHAR(50) NOT NULL,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"KEE" VARCHAR(400),
@@ -210,7 +209,6 @@ CREATE TABLE "COMPONENTS"(
"B_MODULE_UUID_PATH" VARCHAR(1500),
"CREATED_AT" TIMESTAMP
);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
@@ -321,12 +319,12 @@ CREATE TABLE "GROUP_ROLES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"GROUP_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50)
);
ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
CREATE TABLE "GROUPS"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
@@ -734,15 +732,16 @@ CREATE INDEX "IDX_QUALIFIER" ON "PROJECTS"("QUALIFIER");
CREATE TABLE "PROPERTIES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"PROP_KEY" VARCHAR(512) NOT NULL,
- "RESOURCE_ID" BIGINT,
"USER_ID" BIGINT,
"IS_EMPTY" BOOLEAN NOT NULL,
"TEXT_VALUE" VARCHAR(4000),
"CLOB_VALUE" CLOB(2147483647),
- "CREATED_AT" BIGINT NOT NULL
+ "CREATED_AT" BIGINT NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50)
);
ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+CREATE INDEX "PROPERTIES_COMPONENT_UUID" ON "PROPERTIES"("COMPONENT_UUID");
CREATE TABLE "QPROFILE_CHANGES"(
"KEE" VARCHAR(40) NOT NULL,
@@ -929,12 +928,12 @@ CREATE TABLE "USER_ROLES"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"USER_ID" INTEGER,
- "RESOURCE_ID" INTEGER,
- "ROLE" VARCHAR(64) NOT NULL
+ "ROLE" VARCHAR(64) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50)
);
ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
CREATE TABLE "USER_TOKENS"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index bd105e39d18..bced88cba5d 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -36,7 +36,6 @@ import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import java.util.stream.LongStream;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.assertj.core.api.ListAssert;
@@ -337,22 +336,6 @@ public class ComponentDaoTest {
}
@Test
- public void get_by_ids() {
- ComponentDto project1 = db.components().insertPrivateProject();
- ComponentDto project2 = db.components().insertPrivateProject();
-
- List<ComponentDto> results = underTest.selectByIds(dbSession, asList(project1.getId(), project2.getId()));
-
- assertThat(results)
- .extracting(ComponentDto::uuid, ComponentDto::getDbKey)
- .containsExactlyInAnyOrder(
- tuple(project1.uuid(), project1.getDbKey()),
- tuple(project2.uuid(), project2.getDbKey()));
-
- assertThat(underTest.selectByIds(dbSession, singletonList(0L))).isEmpty();
- }
-
- @Test
public void get_by_uuids() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
@@ -393,31 +376,6 @@ public class ComponentDaoTest {
}
@Test
- public void get_by_id() {
- ComponentDto project = db.components().insertPrivateProject();
-
- assertThat(underTest.selectById(dbSession, project.getId())).isNotNull();
- }
-
- @Test
- public void get_by_id_on_disabled_component() {
- ComponentDto enabledProject = db.components().insertPrivateProject();
- ComponentDto disabledProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
-
- Optional<ComponentDto> result = underTest.selectById(dbSession, disabledProject.getId());
- assertThat(result).isPresent();
- assertThat(result.get().isEnabled()).isFalse();
- }
-
- @Test
- public void get_nullable_by_id() {
- ComponentDto project = db.components().insertPrivateProject();
-
- assertThat(underTest.selectById(dbSession, project.getId())).isPresent();
- assertThat(underTest.selectById(dbSession, 0L)).isEmpty();
- }
-
- @Test
public void select_component_keys_by_qualifiers() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
@@ -1215,16 +1173,6 @@ public class ComponentDaoTest {
}
@Test
- public void countByQuery_throws_IAE_if_too_many_component_ids() {
- Set<Long> ids = LongStream.range(0L, 1_010L).boxed().collect(toSet());
- ComponentQuery.Builder query = ComponentQuery.builder()
- .setQualifiers(PROJECT)
- .setComponentIds(ids);
-
- assertThatCountByQueryThrowsIAE(query, "Too many component ids in query");
- }
-
- @Test
public void countByQuery_throws_IAE_if_too_many_component_keys() {
Set<String> keys = IntStream.range(0, 1_010).mapToObj(String::valueOf).collect(toSet());
ComponentQuery.Builder query = ComponentQuery.builder()
@@ -1404,7 +1352,7 @@ public class ComponentDaoTest {
ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_1"));
db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_2"));
- underTest.delete(dbSession, project1.getId());
+ underTest.delete(dbSession, project1.uuid());
dbSession.commit();
assertThat(underTest.selectByKey(dbSession, "PROJECT_1")).isEmpty();
@@ -1420,16 +1368,6 @@ public class ComponentDaoTest {
}
@Test
- public void selectByQuery_throws_IAE_if_too_many_component_ids() {
- Set<Long> ids = LongStream.range(0L, 1_010L).boxed().collect(toSet());
- ComponentQuery.Builder query = ComponentQuery.builder()
- .setQualifiers(PROJECT)
- .setComponentIds(ids);
-
- assertThatSelectByQueryThrowsIAE(query, "Too many component ids in query");
- }
-
- @Test
public void selectByQuery_throws_IAE_if_too_many_component_keys() {
Set<String> keys = IntStream.range(0, 1_010).mapToObj(String::valueOf).collect(toSet());
ComponentQuery.Builder query = ComponentQuery.builder()
@@ -1676,34 +1614,6 @@ public class ComponentDaoTest {
}
@Test
- public void selectByQuery_on_empty_list_of_component_id() {
- db.components().insertPrivateProject();
- ComponentQuery dbQuery = ComponentQuery.builder().setQualifiers(PROJECT).setComponentIds(emptySet()).build();
-
- List<ComponentDto> result = underTest.selectByQuery(dbSession, dbQuery, 0, 10);
- int count = underTest.countByQuery(dbSession, dbQuery);
-
- assertThat(result).isEmpty();
- assertThat(count).isEqualTo(0);
- }
-
- @Test
- public void selectByQuery_on_component_ids() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto(organizationDto));
- ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto(organizationDto));
- ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto(organizationDto));
-
- ComponentQuery query = ComponentQuery.builder().setQualifiers(PROJECT)
- .setComponentIds(newHashSet(sonarqube.getId(), jdk8.getId())).build();
- List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
-
- assertThat(result).hasSize(2).extracting(ComponentDto::getId)
- .containsOnlyOnce(sonarqube.getId(), jdk8.getId())
- .doesNotContain(cLang.getId());
- }
-
- @Test
public void selectByQuery_on_empty_list_of_component_key() {
db.components().insertPrivateProject();
ComponentQuery dbQuery = ComponentQuery.builder().setQualifiers(PROJECT).setComponentKeys(emptySet()).build();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java
index 675af9f4365..0271571a08f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java
@@ -32,7 +32,6 @@ public class ComponentDtoTest {
@Test
public void setters_and_getters() {
ComponentDto componentDto = new ComponentDto()
- .setId(1L)
.setDbKey("org.struts:struts-core:src/org/struts/RequestContext.java")
.setName("RequestContext.java")
.setLongName("org.struts.RequestContext")
@@ -44,7 +43,6 @@ public class ComponentDtoTest {
.setCopyComponentUuid("uuid_5")
.setRootUuid("uuid_3");
- assertThat(componentDto.getId()).isEqualTo(1L);
assertThat(componentDto.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
assertThat(componentDto.getBranch()).isNull();
assertThat(componentDto.name()).isEqualTo("RequestContext.java");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
index 96161adde08..21cdc78701f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
@@ -79,10 +79,8 @@ public class ComponentQueryTest {
public void empty_list_of_components() {
Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setQualifiers(PROJECT);
- assertThat(query.get().setComponentIds(emptySet()).build().hasEmptySetOfComponents()).isTrue();
assertThat(query.get().setComponentKeys(emptySet()).build().hasEmptySetOfComponents()).isTrue();
assertThat(query.get().setComponentUuids(emptySet()).build().hasEmptySetOfComponents()).isTrue();
- assertThat(query.get().setComponentIds(singleton(404L)).build().hasEmptySetOfComponents()).isFalse();
assertThat(query.get().setComponentKeys(singleton("P1")).build().hasEmptySetOfComponents()).isFalse();
assertThat(query.get().setComponentUuids(singleton("U1")).build().hasEmptySetOfComponents()).isFalse();
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
index b026886b217..209b77d019b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
@@ -217,8 +217,8 @@ public class ScrollForFileMoveComponentDaoTest {
dtos.add(resultContext.getResultObject());
}
- private java.util.Optional<FileMoveRowDto> getById(long id) {
- return dtos.stream().filter(t -> t.getId() == id).findAny();
+ private java.util.Optional<FileMoveRowDto> getByUuid(String uuid) {
+ return dtos.stream().filter(t -> t.getUuid().equals(uuid)).findAny();
}
}
@@ -240,7 +240,7 @@ public class ScrollForFileMoveComponentDaoTest {
}
private static void verifyFileMoveRowDto(RecordingResultHandler resultHander, ComponentAndSource componentAndSource) {
- FileMoveRowDto dto = resultHander.getById(componentAndSource.component.getId()).get();
+ FileMoveRowDto dto = resultHander.getByUuid(componentAndSource.component.uuid()).get();
assertThat(dto.getKey()).isEqualTo(componentAndSource.component.getDbKey());
assertThat(dto.getUuid()).isEqualTo(componentAndSource.component.uuid());
assertThat(dto.getPath()).isEqualTo(componentAndSource.component.path());
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 df9236be1da..0e5e3280444 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
@@ -395,8 +395,8 @@ public class IssueDaoTest {
private static IssueDto newIssueDto(String key) {
IssueDto dto = new IssueDto();
- dto.setComponent(new ComponentDto().setDbKey("struts:Action").setId(123L).setUuid("component-uuid"));
- dto.setProject(new ComponentDto().setDbKey("struts").setId(100L).setUuid("project-uuid"));
+ 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.setKee(key);
dto.setType(2);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
index bec25766b6f..00ca9b3c9ed 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
@@ -56,7 +56,7 @@ import static org.sonar.db.permission.OrganizationPermission.SCAN;
public class AuthorizationDaoTest {
- private static final Long PROJECT_ID = 300L;
+ private static final String PROJECT_UUID = "uuid";
private static final int MISSING_ID = -1;
private static final String A_PERMISSION = "a-permission";
private static final String DOES_NOT_EXIST = "does-not-exist";
@@ -71,8 +71,8 @@ public class AuthorizationDaoTest {
private UserDto user;
private GroupDto group1;
private GroupDto group2;
- private Set<Long> randomPublicProjectIds;
- private Set<Long> randomPrivateProjectIds;
+ private Set<String> randomPublicProjectUuids;
+ private Set<String> randomPrivateProjectUuids;
private Set<Integer> randomExistingUserIds;
private String randomPermission = "p" + random.nextInt();
@@ -86,13 +86,11 @@ public class AuthorizationDaoTest {
.map(i -> db.users().insertUser().getId())
.boxed()
.collect(MoreCollectors.toSet());
- randomPublicProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
- .mapToLong(i -> db.components().insertPublicProject(organization).getId())
- .boxed()
+ randomPublicProjectUuids = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
+ .mapToObj(i -> db.components().insertPublicProject(organization).uuid())
.collect(MoreCollectors.toSet());
- randomPrivateProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
- .mapToLong(i -> db.components().insertPrivateProject(organization).getId())
- .boxed()
+ randomPrivateProjectUuids = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
+ .mapToObj(i -> db.components().insertPrivateProject(organization).uuid())
.collect(MoreCollectors.toSet());
}
@@ -259,202 +257,200 @@ public class AuthorizationDaoTest {
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_if_project_set_is_empty_on_public_project() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, Collections.emptySet(), null, UserRole.USER))
+ public void keepAuthorizedProjectUuids_returns_empty_for_group_AnyOne_if_project_set_is_empty_on_public_project() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, Collections.emptySet(), null, UserRole.USER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_user_if_project_set_is_empty_on_public_project() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, Collections.emptySet(), user.getId(), UserRole.USER))
+ public void keepAuthorizedProjectUuids_returns_empty_for_user_if_project_set_is_empty_on_public_project() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, Collections.emptySet(), user.getId(), UserRole.USER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_for_non_existent_projects() {
- Set<Long> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
- .mapToLong(i -> 3_562 + i)
- .boxed()
+ public void keepAuthorizedProjectUuids_returns_empty_for_group_AnyOne_for_non_existent_projects() {
+ Set<String> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
+ .mapToObj(i -> Integer.toString(3_562 + i))
.collect(MoreCollectors.toSet());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomNonProjectsSet, null, UserRole.USER))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomNonProjectsSet, null, UserRole.USER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_user_for_non_existent_projects() {
- Set<Long> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
- .mapToLong(i -> 9_666 + i)
- .boxed()
+ public void keepAuthorizedProjectUuids_returns_empty_for_user_for_non_existent_projects() {
+ Set<String> randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
+ .mapToObj(i -> Integer.toString(9_666 + i))
.collect(MoreCollectors.toSet());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomNonProjectsSet, user.getId(), UserRole.USER))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomNonProjectsSet, user.getId(), UserRole.USER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_any_public_project_for_group_AnyOne_without_any_permission_in_DB_and_permission_USER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPublicProjectIds, null, UserRole.USER))
- .containsAll(randomPublicProjectIds);
+ public void keepAuthorizedProjectUuids_returns_any_public_project_for_group_AnyOne_without_any_permission_in_DB_and_permission_USER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPublicProjectUuids, null, UserRole.USER))
+ .containsAll(randomPublicProjectUuids);
}
@Test
- public void keepAuthorizedProjectIds_returns_any_public_project_for_user_without_any_permission_in_DB_and_permission_USER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPublicProjectIds, user.getId(), UserRole.USER))
- .containsAll(randomPublicProjectIds);
+ public void keepAuthorizedProjectUuids_returns_any_public_project_for_user_without_any_permission_in_DB_and_permission_USER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPublicProjectUuids, user.getId(), UserRole.USER))
+ .containsAll(randomPublicProjectUuids);
}
@Test
- public void keepAuthorizedProjectIds_returns_any_public_project_for_group_AnyOne_without_any_permission_in_DB_and_permission_CODEVIEWER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPublicProjectIds, null, UserRole.CODEVIEWER))
- .containsAll(randomPublicProjectIds);
+ public void keepAuthorizedProjectUuids_returns_any_public_project_for_group_AnyOne_without_any_permission_in_DB_and_permission_CODEVIEWER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPublicProjectUuids, null, UserRole.CODEVIEWER))
+ .containsAll(randomPublicProjectUuids);
}
@Test
- public void keepAuthorizedProjectIds_returns_any_public_project_for_user_without_any_permission_in_DB_and_permission_CODEVIEWER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPublicProjectIds, user.getId(), UserRole.CODEVIEWER))
- .containsAll(randomPublicProjectIds);
+ public void keepAuthorizedProjectUuids_returns_any_public_project_for_user_without_any_permission_in_DB_and_permission_CODEVIEWER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPublicProjectUuids, user.getId(), UserRole.CODEVIEWER))
+ .containsAll(randomPublicProjectUuids);
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_other_permission_for_group_AnyOne_on_public_project_without_any_permission_in_DB() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPublicProjectIds, null, randomPermission))
+ public void keepAuthorizedProjectUuids_returns_empty_for_other_permission_for_group_AnyOne_on_public_project_without_any_permission_in_DB() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPublicProjectUuids, null, randomPermission))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_any_permission_for_user_on_public_project_without_any_permission_in_DB() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPublicProjectIds, user.getId(), randomPermission))
+ public void keepAuthorizedProjectUuids_returns_empty_for_any_permission_for_user_on_public_project_without_any_permission_in_DB() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPublicProjectUuids, user.getId(), randomPermission))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_public_project_if_user_is_granted_project_permission_directly() {
+ public void keepAuthorizedProjectUuids_returns_public_project_if_user_is_granted_project_permission_directly() {
ComponentDto project = db.components().insertPublicProject(organization);
ComponentDto otherProject = db.components().insertPublicProject(organization);
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, randomPermission, project);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), otherUser.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), otherUser.getId(), randomPermission))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(otherProject.getId()), user.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), user.getId(), randomPermission))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), randomPermission))
- .containsOnly(project.getId());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), "another perm"))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), randomPermission))
+ .containsOnly(project.uuid());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), "another perm"))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_public_project_if_user_is_granted_project_permission_by_group() {
+ public void keepAuthorizedProjectUuids_returns_public_project_if_user_is_granted_project_permission_by_group() {
ComponentDto project = db.components().insertPublicProject(organization);
ComponentDto otherProject = db.components().insertPublicProject(organization);
UserDto otherUser = db.users().insertUser();
db.users().insertMember(group1, user);
db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), randomPermission))
- .containsOnly(project.getId());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(otherProject.getId()), user.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), randomPermission))
+ .containsOnly(project.uuid());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), user.getId(), randomPermission))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), otherUser.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), otherUser.getId(), randomPermission))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), "another perm"))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), "another perm"))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_public_project_if_group_AnyOne_is_granted_project_permission_directly() {
+ public void keepAuthorizedProjectUuids_returns_public_project_if_group_AnyOne_is_granted_project_permission_directly() {
ComponentDto project = db.components().insertPublicProject(organization);
ComponentDto otherProject = db.components().insertPublicProject(organization);
db.users().insertProjectPermissionOnAnyone(randomPermission, project);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), null, randomPermission))
- .containsOnly(project.getId());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), null, "another perm"))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), null, randomPermission))
+ .containsOnly(project.uuid());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), null, "another perm"))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(otherProject.getId()), null, randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), null, randomPermission))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_user_on_private_project_without_any_permission_in_DB_and_permission_USER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, user.getId(), UserRole.USER))
+ public void keepAuthorizedProjectUuids_returns_empty_for_user_on_private_project_without_any_permission_in_DB_and_permission_USER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, user.getId(), UserRole.USER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_on_private_project_without_any_permission_in_DB_and_permission_USER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, null, UserRole.USER))
+ public void keepAuthorizedProjectUuids_returns_empty_for_group_AnyOne_on_private_project_without_any_permission_in_DB_and_permission_USER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, null, UserRole.USER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_user_on_private_project_without_any_permission_in_DB_and_permission_CODEVIEWER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, user.getId(), UserRole.CODEVIEWER))
+ public void keepAuthorizedProjectUuids_returns_empty_for_user_on_private_project_without_any_permission_in_DB_and_permission_CODEVIEWER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, user.getId(), UserRole.CODEVIEWER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_on_private_project_without_any_permission_in_DB_and_permission_CODEVIEWER() {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, null, UserRole.CODEVIEWER))
+ public void keepAuthorizedProjectUuids_returns_empty_for_group_AnyOne_on_private_project_without_any_permission_in_DB_and_permission_CODEVIEWER() {
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, null, UserRole.CODEVIEWER))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_user_and_any_permission_on_private_project_without_any_permission_in_DB() {
+ public void keepAuthorizedProjectUuids_returns_empty_for_user_and_any_permission_on_private_project_without_any_permission_in_DB() {
PermissionsTestHelper.ALL_PERMISSIONS
.forEach(perm -> {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, user.getId(), perm))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, user.getId(), perm))
.isEmpty();
});
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, user.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, user.getId(), randomPermission))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_and_any_permission_on_private_project_without_any_permission_in_DB() {
+ public void keepAuthorizedProjectUuids_returns_empty_for_group_AnyOne_and_any_permission_on_private_project_without_any_permission_in_DB() {
PermissionsTestHelper.ALL_PERMISSIONS
.forEach(perm -> {
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, null, perm))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, null, perm))
.isEmpty();
});
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, randomPrivateProjectIds, null, randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, randomPrivateProjectUuids, null, randomPermission))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_private_project_if_user_is_granted_project_permission_directly() {
+ public void keepAuthorizedProjectUuids_returns_private_project_if_user_is_granted_project_permission_directly() {
ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto otherProject = db.components().insertPrivateProject(organization);
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, randomPermission, project);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), randomPermission))
- .containsOnly(project.getId());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), "another perm"))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), randomPermission))
+ .containsOnly(project.uuid());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), "another perm"))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(otherProject.getId()), user.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), user.getId(), randomPermission))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), otherUser.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), otherUser.getId(), randomPermission))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_returns_private_project_if_user_is_granted_project_permission_by_group() {
+ public void keepAuthorizedProjectUuids_returns_private_project_if_user_is_granted_project_permission_by_group() {
ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto otherProject = db.components().insertPrivateProject(organization);
UserDto otherUser = db.users().insertUser();
db.users().insertMember(group1, user);
db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), randomPermission))
- .containsOnly(project.getId());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), user.getId(), "another perm"))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), randomPermission))
+ .containsOnly(project.uuid());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getId(), "another perm"))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(otherProject.getId()), user.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), user.getId(), randomPermission))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, singleton(project.getId()), otherUser.getId(), randomPermission))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), otherUser.getId(), randomPermission))
.isEmpty();
}
@@ -470,14 +466,14 @@ public class AuthorizationDaoTest {
db.users().insertMember(group, user);
db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project1);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, newHashSet(project2.getId(), project3.getId()), user.getId(), UserRole.USER))
- .containsOnly(project2.getId(), project3.getId());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project2.uuid(), project3.uuid()), user.getId(), UserRole.USER))
+ .containsOnly(project2.uuid(), project3.uuid());
// user does not have the role "admin"
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, newHashSet(project2.getId()), user.getId(), UserRole.ADMIN))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project2.uuid()), user.getId(), UserRole.ADMIN))
.isEmpty();
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, Collections.emptySet(), user.getId(), UserRole.ADMIN))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, Collections.emptySet(), user.getId(), UserRole.ADMIN))
.isEmpty();
}
@@ -493,11 +489,11 @@ public class AuthorizationDaoTest {
db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project2);
db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project3);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, newHashSet(project2.getId(), project3.getId()), user1.getId(), UserRole.USER))
- .containsOnly(project2.getId(), project3.getId());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project2.uuid(), project3.uuid()), user1.getId(), UserRole.USER))
+ .containsOnly(project2.uuid(), project3.uuid());
// group does not have the role "admin"
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, newHashSet(project2.getId(), project3.getId()), user1.getId(), UserRole.ADMIN))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project2.uuid(), project3.uuid()), user1.getId(), UserRole.ADMIN))
.isEmpty();
}
@@ -509,24 +505,15 @@ public class AuthorizationDaoTest {
GroupDto group = db.users().insertGroup(organization);
db.users().insertMembers(group, user1);
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, newHashSet(project1.getId(), project2.getId()), null, UserRole.USER))
- .containsOnly(project1.getId(), project2.getId());
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project1.uuid(), project2.uuid()), null, UserRole.USER))
+ .containsOnly(project1.uuid(), project2.uuid());
// group does not have the role "admin"
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, newHashSet(project1.getId()), null, "admin"))
+ assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project1.uuid()), null, "admin"))
.isEmpty();
}
@Test
- public void keepAuthorizedProjectIds_should_be_able_to_handle_lots_of_projects() {
- List<ComponentDto> projects = IntStream.range(0, 2000).mapToObj(i -> db.components().insertPublicProject(organization)).collect(Collectors.toList());
-
- Collection<Long> ids = projects.stream().map(ComponentDto::getId).collect(Collectors.toSet());
- assertThat(underTest.keepAuthorizedProjectIds(dbSession, ids, null, UserRole.USER))
- .containsOnly(ids.toArray(new Long[0]));
- }
-
- @Test
public void keepAuthorizedProjectUuids_should_be_able_to_handle_lots_of_projects() {
List<ComponentDto> projects = IntStream.range(0, 2000).mapToObj(i -> db.components().insertPublicProject(organization)).collect(Collectors.toList());
@@ -540,7 +527,7 @@ public class AuthorizationDaoTest {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, Collections.emptySet(), UserRole.USER, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, Collections.emptySet(), UserRole.USER, project.uuid()))
.isEmpty();
}
@@ -552,7 +539,7 @@ public class AuthorizationDaoTest {
.boxed()
.collect(MoreCollectors.toSet());
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomNonExistingUserIdsSet, UserRole.USER, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomNonExistingUserIdsSet, UserRole.USER, project.uuid()))
.isEmpty();
}
@@ -560,7 +547,7 @@ public class AuthorizationDaoTest {
public void keepAuthorizedUsersForRoleAndProject_returns_any_users_for_public_project_without_any_permission_in_DB_and_permission_USER() {
ComponentDto project = db.components().insertPublicProject(organization);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.USER, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.USER, project.uuid()))
.containsAll(randomExistingUserIds);
}
@@ -568,7 +555,7 @@ public class AuthorizationDaoTest {
public void keepAuthorizedUsersForRoleAndProject_returns_any_users_for_public_project_without_any_permission_in_DB_and_permission_CODEVIEWER() {
ComponentDto project = db.components().insertPublicProject(organization);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.CODEVIEWER, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.CODEVIEWER, project.uuid()))
.containsAll(randomExistingUserIds);
}
@@ -576,7 +563,7 @@ public class AuthorizationDaoTest {
public void keepAuthorizedUsersForRoleAndProject_returns_empty_for_any_users_on_public_project_without_any_permission_in_DB() {
ComponentDto project = db.components().insertPublicProject(organization);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, randomPermission, project.uuid()))
.isEmpty();
}
@@ -587,13 +574,13 @@ public class AuthorizationDaoTest {
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, randomPermission, project);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.uuid()))
.containsOnly(user.getId());
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.uuid()))
.isEmpty();
}
@@ -605,13 +592,13 @@ public class AuthorizationDaoTest {
db.users().insertMember(group1, user);
db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.uuid()))
.containsOnly(user.getId());
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.uuid()))
.isEmpty();
}
@@ -622,13 +609,13 @@ public class AuthorizationDaoTest {
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnAnyone(randomPermission, project);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.uuid()))
.isEmpty();
}
@@ -636,7 +623,7 @@ public class AuthorizationDaoTest {
public void keepAuthorizedUsersForRoleAndProject_returns_empty_for_any_user_on_private_project_without_any_permission_in_DB_and_permission_USER() {
ComponentDto project = db.components().insertPrivateProject(organization);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.USER, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.USER, project.uuid()))
.isEmpty();
}
@@ -644,7 +631,7 @@ public class AuthorizationDaoTest {
public void keepAuthorizedUsersForRoleAndProject_returns_empty_for_any_user_on_private_project_without_any_permission_in_DB_and_permission_CODEVIEWER() {
ComponentDto project = db.components().insertPrivateProject(organization);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.CODEVIEWER, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, UserRole.CODEVIEWER, project.uuid()))
.isEmpty();
}
@@ -654,10 +641,10 @@ public class AuthorizationDaoTest {
PermissionsTestHelper.ALL_PERMISSIONS
.forEach(perm -> {
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, perm, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, perm, project.uuid()))
.isEmpty();
});
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, randomExistingUserIds, randomPermission, project.uuid()))
.isEmpty();
}
@@ -668,13 +655,13 @@ public class AuthorizationDaoTest {
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, randomPermission, project);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.uuid()))
.containsOnly(user.getId());
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.uuid()))
.isEmpty();
}
@@ -686,13 +673,13 @@ public class AuthorizationDaoTest {
db.users().insertMember(group1, user);
db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, project.uuid()))
.containsOnly(user.getId());
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), "another perm", project.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getId()), randomPermission, otherProject.uuid()))
.isEmpty();
- assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.getId()))
+ assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getId()), randomPermission, project.uuid()))
.isEmpty();
}
@@ -715,7 +702,7 @@ public class AuthorizationDaoTest {
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession,
// Only 100 and 101 has 'user' role on project
- newHashSet(100, 101, 102), "user", PROJECT_ID)).isEmpty();
+ newHashSet(100, 101, 102), "user", PROJECT_UUID)).isEmpty();
}
@Test
@@ -723,7 +710,7 @@ public class AuthorizationDaoTest {
List<UserDto> users = IntStream.range(0, 2000).mapToObj(i -> db.users().insertUser()).collect(Collectors.toList());
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession,
- users.stream().map(UserDto::getId).collect(Collectors.toSet()), "user", PROJECT_ID)).isEmpty();
+ users.stream().map(UserDto::getId).collect(Collectors.toSet()), "user", PROJECT_UUID)).isEmpty();
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
index bfd4e63e1c2..181ce66e8cf 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
@@ -87,12 +87,12 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, USER, project3);
final List<CountPerProjectPermission> result = new ArrayList<>();
- underTest.groupsCountByComponentIdAndPermission(dbSession, asList(project2.getId(), project3.getId(), 789L),
+ underTest.groupsCountByComponentUuidAndPermission(dbSession, asList(project2.uuid(), project3.uuid(), "789"),
context -> result.add((CountPerProjectPermission) context.getResultObject()));
assertThat(result).hasSize(3);
assertThat(result).extracting("permission").containsOnly(ADMIN, USER);
- assertThat(result).extracting("componentId").containsOnly(project2.getId(), project3.getId());
+ assertThat(result).extracting("componentUuid").containsOnly(project2.uuid(), project3.uuid());
assertThat(result).extracting("count").containsOnly(3, 1);
}
@@ -115,12 +115,12 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "p3", project3);
final List<CountPerProjectPermission> result = new ArrayList<>();
- underTest.groupsCountByComponentIdAndPermission(dbSession, asList(project2.getId(), project3.getId(), 789L),
+ underTest.groupsCountByComponentUuidAndPermission(dbSession, asList(project2.uuid(), project3.uuid(), "789"),
context -> result.add((CountPerProjectPermission) context.getResultObject()));
assertThat(result).hasSize(3);
assertThat(result).extracting("permission").containsOnly("p2", "p3");
- assertThat(result).extracting("componentId").containsOnly(project2.getId(), project3.getId());
+ assertThat(result).extracting("componentUuid").containsOnly(project2.uuid(), project3.uuid());
assertThat(result).extracting("count").containsOnly(4, 1);
}
@@ -151,8 +151,8 @@ public class GroupPermissionDaoTest {
assertThat(underTest.selectGroupNamesByQuery(dbSession, newQuery()
.setOrganizationUuid(organizationDto.getUuid()).build()))
- .hasSize(DEFAULT_PAGE_SIZE)
- .startsWith(ANYONE, lastGroupName, "Group-1");
+ .hasSize(DEFAULT_PAGE_SIZE)
+ .startsWith(ANYONE, lastGroupName, "Group-1");
}
@Test
@@ -171,8 +171,8 @@ public class GroupPermissionDaoTest {
.setOrganizationUuid(organizationDto.getUuid())
.setComponent(project)
.build()))
- .hasSize(DEFAULT_PAGE_SIZE)
- .startsWith(ANYONE, lastGroupName, "Group-1");
+ .hasSize(DEFAULT_PAGE_SIZE)
+ .startsWith(ANYONE, lastGroupName, "Group-1");
}
@Test
@@ -300,8 +300,8 @@ public class GroupPermissionDaoTest {
assertThat(underTest.selectGroupNamesByQuery(dbSession,
newQuery().build()))
- .doesNotContain(ANYONE)
- .containsExactly(group.getName());
+ .doesNotContain(ANYONE)
+ .containsExactly(group.getName());
}
@Test
@@ -323,17 +323,17 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(organizationDto, PROVISION_PROJECTS);
assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group1.getId()), null))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group1.getId(), SCAN_EXECUTION, null));
assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group2.getId()), null)).isEmpty();
assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group3.getId()), null))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group3.getId(), ADMINISTER.getKey(), null));
assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(ANYONE_ID), null))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(
tuple(0, SCAN.getKey(), null),
tuple(0, PROVISION_PROJECTS.getKey(), null));
@@ -360,24 +360,24 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(org, "p3");
db.users().insertProjectPermissionOnAnyone("p4", project);
- assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.uuid())).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.getId()))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
- .containsOnly(tuple(group2.getId(), "p2", project.getId()));
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.uuid()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+ .containsOnly(tuple(group2.getId(), "p2", project.uuid()));
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.getId()))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
- .containsOnly(tuple(group3.getId(), "p2", project.getId()));
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.uuid()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+ .containsOnly(tuple(group3.getId(), "p2", project.uuid()));
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId()))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
- .containsOnly(tuple(0, "p4", project.getId()));
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.uuid()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+ .containsOnly(tuple(0, "p4", project.uuid()));
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2);
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.uuid())).hasSize(2);
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.uuid())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), "123")).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.uuid())).isEmpty();
}
@Test
@@ -396,23 +396,23 @@ public class GroupPermissionDaoTest {
// Anyone group
db.users().insertPermissionOnAnyone(org, SCAN);
- assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.uuid())).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.getId()))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
- .containsOnly(tuple(group2.getId(), USER, project.getId()));
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.uuid()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+ .containsOnly(tuple(group2.getId(), USER, project.uuid()));
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.getId()))
- .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
- .containsOnly(tuple(group3.getId(), USER, project.getId()));
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.uuid()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+ .containsOnly(tuple(group3.getId(), USER, project.uuid()));
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId()))
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.uuid()))
.isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(1);
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.uuid())).hasSize(1);
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.uuid())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), "123")).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.uuid())).isEmpty();
}
@Test
@@ -453,13 +453,13 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
db.users().insertProjectPermissionOnAnyone("perm6", project1);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.uuid()))
.containsOnly("perm3", "perm4");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.uuid()))
.containsOnly("perm5");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.uuid()))
.containsOnly("perm6");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project2.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project2.uuid()))
.isEmpty();
}
@@ -476,13 +476,13 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm4", project1);
db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.uuid()))
.containsOnly("perm3", "perm4");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.uuid()))
.containsOnly("perm5");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.uuid()))
.isEmpty();
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project2.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project2.uuid()))
.isEmpty();
}
@@ -501,9 +501,9 @@ public class GroupPermissionDaoTest {
List<GroupPermissionDto> result = new ArrayList<>();
underTest.selectAllPermissionsByGroupId(dbSession, org1.getUuid(), group1.getId(), context -> result.add((GroupPermissionDto) context.getResultObject()));
- assertThat(result).extracting(GroupPermissionDto::getResourceId, GroupPermissionDto::getRole).containsOnly(
+ assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
tuple(null, "perm2"),
- tuple(project1.getId(), "perm3"), tuple(project1.getId(), "perm4"), tuple(project2.getId(), "perm5"));
+ tuple(project1.uuid(), "perm3"), tuple(project1.uuid(), "perm4"), tuple(project2.uuid(), "perm5"));
}
@Test
@@ -520,9 +520,9 @@ public class GroupPermissionDaoTest {
List<GroupPermissionDto> result = new ArrayList<>();
underTest.selectAllPermissionsByGroupId(dbSession, org1.getUuid(), group1.getId(), context -> result.add((GroupPermissionDto) context.getResultObject()));
- assertThat(result).extracting(GroupPermissionDto::getResourceId, GroupPermissionDto::getRole).containsOnly(
+ assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
tuple(null, "perm2"),
- tuple(project1.getId(), "perm3"), tuple(project1.getId(), "perm4"), tuple(project2.getId(), "perm5"));
+ tuple(project1.uuid(), "perm3"), tuple(project1.uuid(), "perm4"), tuple(project2.uuid(), "perm5"));
}
@Test
@@ -532,7 +532,7 @@ public class GroupPermissionDaoTest {
GroupDto group = db.users().insertGroup(organization);
db.users().insertProjectPermissionOnGroup(group, "foo", project);
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, 1234, UserRole.USER))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER))
.isEmpty();
}
@@ -545,11 +545,11 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "p1", project);
db.users().insertProjectPermissionOnGroup(group2, "p2", project);
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p2"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getId());
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p1"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getId());
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p3"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p3"))
.containsOnly(group1.getId(), group2.getId());
}
@@ -563,9 +563,9 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group2, "p2", project);
db.users().insertProjectPermissionOnAnyone("p2", project);
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p2"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getId());
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p1"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getId());
}
@@ -579,14 +579,14 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "p1", project);
db.users().insertProjectPermissionOnGroup(group2, "p2", project);
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p2"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getId());
- assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p1"))
+ assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getId());
}
@Test
- public void deleteByRootComponentId_on_private_project() {
+ public void deleteByRootComponentUuid_on_private_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
GroupDto group2 = db.users().insertGroup(org);
@@ -596,15 +596,15 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
- underTest.deleteByRootComponentId(dbSession, project1.getId());
+ underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
dbSession.commit();
- assertThat(db.countSql("select count(id) from group_roles where resource_id=" + project1.getId())).isEqualTo(0);
+ assertThat(db.countSql("select count(id) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
}
@Test
- public void deleteByRootComponentId_on_public_project() {
+ public void deleteByRootComponentUuid_on_public_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
GroupDto group2 = db.users().insertGroup(org);
@@ -616,10 +616,10 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnAnyone("perm4", project1);
db.users().insertProjectPermissionOnAnyone("perm5", project2);
- underTest.deleteByRootComponentId(dbSession, project1.getId());
+ underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
dbSession.commit();
- assertThat(db.countSql("select count(id) from group_roles where resource_id=" + project1.getId())).isEqualTo(0);
+ assertThat(db.countSql("select count(id) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
}
@@ -682,7 +682,7 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.getId());
+ underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.uuid());
dbSession.commit();
assertThatNoPermission("perm3");
@@ -699,7 +699,7 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
- underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.getId());
+ underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.uuid());
dbSession.commit();
assertThatNoPermission("perm3");
@@ -716,7 +716,7 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
- underTest.delete(dbSession, "perm4", group1.getOrganizationUuid(), null, project1.getId());
+ underTest.delete(dbSession, "perm4", group1.getOrganizationUuid(), null, project1.uuid());
dbSession.commit();
assertThatNoPermission("perm4");
@@ -765,7 +765,7 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndGroupId_deletes_all_permissions_of_group_AnyOne_of_specified_component_if_groupId_is_null() {
+ public void deleteByRootComponentUuidAndGroupId_deletes_all_permissions_of_group_AnyOne_of_specified_component_if_groupId_is_null() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group = db.users().insertGroup(organization);
@@ -773,21 +773,21 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group, "p2", project);
db.users().insertPermissionOnAnyone(organization, "p3");
db.users().insertPermissionOnGroup(group, "p4");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), project.uuid()))
.containsOnly("p2");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p3");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group.getId()))
.containsOnly("p4");
- int deletedCount = underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), null);
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), null);
assertThat(deletedCount).isEqualTo(1);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.isEmpty();
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), project.uuid()))
.containsOnly("p2");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p3");
@@ -796,7 +796,7 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndGroupId_deletes_all_permissions_of_specified_group_of_specified_component_if_groupId_is_non_null() {
+ public void deleteByRootComponentUuidAndGroupId_deletes_all_permissions_of_specified_group_of_specified_component_if_groupId_is_non_null() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
@@ -808,11 +808,11 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(organization, "p5");
db.users().insertPermissionOnGroup(group1, "p6");
db.users().insertPermissionOnGroup(group2, "p7");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.containsOnly("p2");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
.containsOnly("p3", "p4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p5");
@@ -821,28 +821,28 @@ public class GroupPermissionDaoTest {
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId()))
.containsOnly("p7");
- int deletedCount = underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), group1.getId());
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group1.getId());
assertThat(deletedCount).isEqualTo(1);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.isEmpty();
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
.containsOnly("p3", "p4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
.containsOnly("p6");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId()))
.containsOnly("p7");
- deletedCount = underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), group2.getId());
+ deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group2.getId());
assertThat(deletedCount).isEqualTo(2);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.isEmpty();
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
.isEmpty();
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
.containsOnly("p6");
@@ -851,51 +851,51 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndGroupId_has_no_effect_if_component_does_not_exist() {
+ public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
GroupDto group = db.users().insertGroup(organization);
- assertThat(underTest.deleteByRootComponentIdAndGroupId(dbSession, 1234L, null)).isEqualTo(0);
- assertThat(underTest.deleteByRootComponentIdAndGroupId(dbSession, 1234L, group.getId())).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, "1234", null)).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, "1234", group.getId())).isEqualTo(0);
}
@Test
- public void deleteByRootComponentIdAndGroupId_has_no_effect_if_component_has_no_group_permission_at_all() {
+ public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_has_no_group_permission_at_all() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
GroupDto group = db.users().insertGroup(organization);
- assertThat(underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), null)).isEqualTo(0);
- assertThat(underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), group.getId())).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), null)).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group.getId())).isEqualTo(0);
}
@Test
- public void deleteByRootComponentIdAndGroupId_has_no_effect_if_group_does_not_exist() {
+ public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_group_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
- assertThat(underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), 5678)).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), 5678)).isEqualTo(0);
}
@Test
- public void deleteByRootComponentIdAndGroupId_has_no_effect_if_component_has_no_group_permission_for_group_AnyOne() {
+ public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_has_no_group_permission_for_group_AnyOne() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPrivateProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
db.users().insertProjectPermissionOnGroup(group1, "p1", project);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.isEmpty();
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.containsOnly("p1");
db.users().insertPermissionOnAnyone(organization, "p2");
db.users().insertPermissionOnGroup(group1, "p3");
- int deletedCount = underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), null);
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), null);
assertThat(deletedCount).isEqualTo(0);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.isEmpty();
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p2");
@@ -904,7 +904,7 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndGroupId_has_no_effect_if_component_has_no_group_permission_for_specified_group() {
+ public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_has_no_group_permission_for_specified_group() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPrivateProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
@@ -913,12 +913,12 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(organization, "p2");
db.users().insertPermissionOnGroup(group1, "p3");
- int deletedCount = underTest.deleteByRootComponentIdAndGroupId(dbSession, project.getId(), group2.getId());
+ int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group2.getId());
assertThat(deletedCount).isEqualTo(0);
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.containsOnly("p1");
- assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.getId()))
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
.isEmpty();
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p2");
@@ -927,7 +927,7 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndPermission_deletes_all_rows_for_specified_role_of_specified_component() {
+ public void deleteByRootComponentUuidAndPermission_deletes_all_rows_for_specified_role_of_specified_component() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group = db.users().insertGroup(organization);
@@ -942,7 +942,7 @@ public class GroupPermissionDaoTest {
assertThat(getProjectPermissionsForAnyOne(project)).containsOnly("p1", "p2");
assertThat(getProjectPermissionsForGroup(project, group)).containsOnly("p1", "p2");
- int deletedRows = underTest.deleteByRootComponentIdAndPermission(dbSession, project.getId(), "p1");
+ int deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1");
assertThat(deletedRows).isEqualTo(2);
assertThat(getGlobalPermissionsForAnyone(organization)).containsOnly("p1", "p2");
@@ -950,7 +950,7 @@ public class GroupPermissionDaoTest {
assertThat(getProjectPermissionsForAnyOne(project)).containsOnly("p2");
assertThat(getProjectPermissionsForGroup(project, group)).containsOnly("p2");
- deletedRows = underTest.deleteByRootComponentIdAndPermission(dbSession, project.getId(), "p2");
+ deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p2");
assertThat(deletedRows).isEqualTo(2);
assertThat(getGlobalPermissionsForAnyone(organization)).containsOnly("p1", "p2");
@@ -960,14 +960,14 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndPermission_has_no_effect_if_component_has_no_group_permission_at_all() {
+ public void deleteByRootComponentUuidAndPermission_has_no_effect_if_component_has_no_group_permission_at_all() {
OrganizationDto organization = db.organizations().insert();
GroupDto group = db.users().insertGroup(organization);
ComponentDto project = randomPublicOrPrivateProject(organization);
db.users().insertPermissionOnAnyone(organization, "p1");
db.users().insertPermissionOnGroup(group, "p1");
- assertThat(underTest.deleteByRootComponentIdAndPermission(dbSession, project.getId(), "p1")).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1")).isEqualTo(0);
assertThat(getGlobalPermissionsForAnyone(organization)).containsOnly("p1");
assertThat(getGlobalPermissionsForGroup(group)).containsOnly("p1");
@@ -976,7 +976,7 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndPermission_has_no_effect_if_component_does_not_exist() {
+ public void deleteByRootComponentUuidAndPermission_has_no_effect_if_component_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group = db.users().insertGroup(organization);
@@ -985,7 +985,7 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group, "p1", project);
db.users().insertProjectPermissionOnAnyone("p1", project);
- assertThat(underTest.deleteByRootComponentIdAndPermission(dbSession, 1324, "p1")).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, "1324", "p1")).isEqualTo(0);
assertThat(getGlobalPermissionsForAnyone(organization)).containsOnly("p1");
assertThat(getGlobalPermissionsForGroup(group)).containsOnly("p1");
@@ -994,30 +994,33 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentIdAndPermission_has_no_effect_if_component_does_not_have_specified_permission() {
+ public void deleteByRootComponentUuidAndPermission_has_no_effect_if_component_does_not_have_specified_permission() {
OrganizationDto organization = db.organizations().insert();
GroupDto group = db.users().insertGroup(organization);
ComponentDto project = randomPublicOrPrivateProject(organization);
db.users().insertPermissionOnAnyone(organization, "p1");
db.users().insertPermissionOnGroup(group, "p1");
- assertThat(underTest.deleteByRootComponentIdAndPermission(dbSession, project.getId(), "p1")).isEqualTo(0);
+ assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1")).isEqualTo(0);
}
private Collection<String> getGlobalPermissionsForAnyone(OrganizationDto organization) {
- return getPermissions("organization_uuid = '" + organization.getUuid() + "' and group_id is null and resource_id is null");
+ return getPermissions("organization_uuid = '" + organization.getUuid() + "' and group_id is null and component_uuid is null");
}
private Collection<String> getGlobalPermissionsForGroup(GroupDto groupDto) {
- return getPermissions("organization_uuid = '" + groupDto.getOrganizationUuid() + "' and group_id = " + groupDto.getId() + " and resource_id is null");
+ return getPermissions("organization_uuid = '" + groupDto.getOrganizationUuid() +
+ "' and group_id = " + groupDto.getId() + " and component_uuid is null");
}
private Collection<String> getProjectPermissionsForAnyOne(ComponentDto project) {
- return getPermissions("organization_uuid = '" + project.getOrganizationUuid() + "' and group_id is null and resource_id = " + project.getId());
+ return getPermissions("organization_uuid = '" + project.getOrganizationUuid() +
+ "' and group_id is null and component_uuid = '" + project.uuid() + "'");
}
private Collection<String> getProjectPermissionsForGroup(ComponentDto project, GroupDto group) {
- return getPermissions("organization_uuid = '" + project.getOrganizationUuid() + "' and group_id = " + group.getId() + " and resource_id = " + project.getId());
+ return getPermissions("organization_uuid = '" + project.getOrganizationUuid() +
+ "' and group_id = " + group.getId() + " and component_uuid = '" + project.uuid() + "'");
}
private Collection<String> getPermissions(String whereClauses) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java
index 341073dc1eb..47560e7dabb 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java
@@ -46,7 +46,6 @@ public class PermissionQueryTest {
.build();
assertThat(query.getComponentUuid()).isEqualTo(project.uuid());
- assertThat(query.getComponentId()).isEqualTo(project.getId());
assertThat(query.getOrganizationUuid()).isEqualTo("ORGANIZATION_UUID");
assertThat(query.getPermission()).isEqualTo("user");
assertThat(query.getSearchQuery()).isEqualTo("sonar");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java
index ae6e44a5500..e8324750e2b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java
@@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
@@ -253,15 +252,15 @@ public class UserPermissionDaoTest {
assertThat(underTest.countUsersByProjectPermission(dbSession, emptyList())).isEmpty();
// one project
- expectCount(singletonList(project1.getId()),
- new CountPerProjectPermission(project1.getId(), USER, 1),
- new CountPerProjectPermission(project1.getId(), ISSUE_ADMIN, 2));
+ expectCount(singletonList(project1.uuid()),
+ new CountPerProjectPermission(project1.uuid(), USER, 1),
+ new CountPerProjectPermission(project1.uuid(), ISSUE_ADMIN, 2));
// multiple projects
- expectCount(asList(project1.getId(), project2.getId(), -1L),
- new CountPerProjectPermission(project1.getId(), USER, 1),
- new CountPerProjectPermission(project1.getId(), ISSUE_ADMIN, 2),
- new CountPerProjectPermission(project2.getId(), ISSUE_ADMIN, 1));
+ expectCount(asList(project1.uuid(), project2.uuid(), "invalid"),
+ new CountPerProjectPermission(project1.uuid(), USER, 1),
+ new CountPerProjectPermission(project1.uuid(), ISSUE_ADMIN, 2),
+ new CountPerProjectPermission(project2.uuid(), ISSUE_ADMIN, 1));
}
@Test
@@ -414,7 +413,7 @@ public class UserPermissionDaoTest {
// global permission exists -> delete it, but not the project permission with the same name !
underTest.deleteGlobalPermission(dbSession, user1.getId(), "perm1", organization.getUuid());
- assertThat(db.countSql(dbSession, "select count(id) from user_roles where role='perm1' and resource_id is null")).isEqualTo(0);
+ assertThat(db.countSql(dbSession, "select count(id) from user_roles where role='perm1' and component_uuid is null")).isEqualTo(0);
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
}
@@ -431,10 +430,10 @@ public class UserPermissionDaoTest {
addProjectPermission(organization, "perm", user2, project1);
// no such provision -> ignore
- underTest.deleteProjectPermission(dbSession, user1.getId(), "anotherPerm", project1.getId());
+ underTest.deleteProjectPermission(dbSession, user1.getId(), "anotherPerm", project1.uuid());
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
- underTest.deleteProjectPermission(dbSession, user1.getId(), "perm", project1.getId());
+ underTest.deleteProjectPermission(dbSession, user1.getId(), "perm", project1.uuid());
assertThatProjectPermissionDoesNotExist(user1, "perm", project1);
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(3);
}
@@ -451,7 +450,7 @@ public class UserPermissionDaoTest {
addProjectPermission(organization, "perm", user2, project1);
addProjectPermission(organization, "perm", user1, project2);
- underTest.deleteProjectPermissions(dbSession, project1.getId());
+ underTest.deleteProjectPermissions(dbSession, project1.uuid());
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(2);
assertThatProjectHasNoPermissions(project1);
}
@@ -490,9 +489,9 @@ public class UserPermissionDaoTest {
addProjectPermission(organization, "perm4", user1, project2);
addProjectPermission(organization, "perm5", user2, project1);
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.getId())).containsOnly("perm2", "perm3");
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.getId())).containsOnly("perm4");
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project3.getId())).isEmpty();
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.uuid())).containsOnly("perm2", "perm3");
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.uuid())).containsOnly("perm4");
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project3.uuid())).isEmpty();
}
@Test
@@ -502,7 +501,7 @@ public class UserPermissionDaoTest {
UserDto user = insertUser(organization);
db.users().insertProjectPermissionOnUser(user, "foo", project);
- assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, 1234, UserRole.USER))
+ assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER))
.isEmpty();
}
@@ -515,11 +514,11 @@ public class UserPermissionDaoTest {
db.users().insertProjectPermissionOnUser(user1, "p1", project);
db.users().insertProjectPermissionOnUser(user2, "p2", project);
- assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p2"))
+ assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(user1.getId());
- assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p1"))
+ assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(user2.getId());
- assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p3"))
+ assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p3"))
.containsOnly(user1.getId(), user2.getId());
}
@@ -532,9 +531,9 @@ public class UserPermissionDaoTest {
db.users().insertProjectPermissionOnUser(user1, "p1", project);
db.users().insertProjectPermissionOnUser(user2, "p2", project);
- assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p2"))
+ assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(user1.getId());
- assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.getId(), "p1"))
+ assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(user2.getId());
}
@@ -626,9 +625,9 @@ public class UserPermissionDaoTest {
underTest.deleteByUserId(dbSession, user1.getId());
dbSession.commit();
- assertThat(db.select("select user_id as \"userId\", resource_id as \"projectId\", role as \"permission\" from user_roles"))
- .extracting((row) -> row.get("userId"), (row) -> row.get("projectId"), (row) -> row.get("permission"))
- .containsOnly(tuple(user2.getId().longValue(), null, SCAN.getKey()), tuple(user2.getId().longValue(), project.getId(), ADMINISTER_QUALITY_GATES.getKey()));
+ assertThat(db.select("select user_id as \"userId\", component_uuid as \"projectUuid\", role as \"permission\" from user_roles"))
+ .extracting((row) -> row.get("userId"), (row) -> row.get("projectUuid"), (row) -> row.get("permission"))
+ .containsOnly(tuple(user2.getId().longValue(), null, SCAN.getKey()), tuple(user2.getId().longValue(), project.uuid(), ADMINISTER_QUALITY_GATES.getKey()));
}
@Test
@@ -637,7 +636,7 @@ public class UserPermissionDaoTest {
UserDto user = insertUser(organization);
db.users().insertPermissionOnUser(organization, user, SCAN);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, 124L, SCAN.getKey());
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "124", SCAN.getKey());
assertThat(deletedCount).isEqualTo(0);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
@@ -650,7 +649,7 @@ public class UserPermissionDaoTest {
db.users().insertPermissionOnUser(organization, user, SCAN);
ComponentDto project = randomPublicOrPrivateProject(organization);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.getId(), SCAN.getKey());
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), SCAN.getKey());
assertThat(deletedCount).isEqualTo(0);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
@@ -664,11 +663,11 @@ public class UserPermissionDaoTest {
ComponentDto project = randomPublicOrPrivateProject(organization);
db.users().insertProjectPermissionOnUser(user, SCAN.getKey(), project);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.getId(), "p1");
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), "p1");
assertThat(deletedCount).isEqualTo(0);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getId(), project.getId())).containsOnly(SCAN.getKey());
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).containsOnly(SCAN.getKey());
}
@Test
@@ -686,25 +685,25 @@ public class UserPermissionDaoTest {
db.users().insertProjectPermissionOnUser(user2, SCAN.getKey(), project2);
db.users().insertProjectPermissionOnUser(user2, PROVISION_PROJECTS.getKey(), project2);
- int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.getId(), SCAN.getKey());
+ int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.uuid(), SCAN.getKey());
assertThat(deletedCount).isEqualTo(2);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user2.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.getId())).isEmpty();
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project1.getId())).isEmpty();
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.getId())).containsOnly(SCAN.getKey());
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project2.getId())).containsOnly(SCAN.getKey(), PROVISION_PROJECTS.getKey());
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.uuid())).isEmpty();
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project1.uuid())).isEmpty();
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.uuid())).containsOnly(SCAN.getKey());
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project2.uuid())).containsOnly(SCAN.getKey(), PROVISION_PROJECTS.getKey());
- deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.getId(), SCAN.getKey());
+ deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.uuid(), SCAN.getKey());
assertThat(deletedCount).isEqualTo(2);
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user2.getId(), organization.getUuid())).containsOnly(SCAN.getKey());
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.getId())).isEmpty();
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project1.getId())).isEmpty();
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.getId())).containsOnly();
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project2.getId())).containsOnly(PROVISION_PROJECTS.getKey());
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project1.uuid())).isEmpty();
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project1.uuid())).isEmpty();
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getId(), project2.uuid())).containsOnly();
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getId(), project2.uuid())).containsOnly(PROVISION_PROJECTS.getKey());
}
private ComponentDto randomPublicOrPrivateProject(OrganizationDto organization) {
@@ -729,14 +728,14 @@ public class UserPermissionDaoTest {
.containsOnly(organizationUuids);
}
- private void expectCount(List<Long> projectIds, CountPerProjectPermission... expected) {
- List<CountPerProjectPermission> got = underTest.countUsersByProjectPermission(dbSession, projectIds);
+ private void expectCount(List<String> projectUuids, CountPerProjectPermission... expected) {
+ List<CountPerProjectPermission> got = underTest.countUsersByProjectPermission(dbSession, projectUuids);
assertThat(got).hasSize(expected.length);
for (CountPerProjectPermission expect : expected) {
boolean found = got.stream().anyMatch(b -> b.getPermission().equals(expect.getPermission()) &&
b.getCount() == expect.getCount() &&
- b.getComponentId() == expect.getComponentId());
+ b.getComponentUuid().equals(expect.getComponentUuid()));
assertThat(found).isTrue();
}
}
@@ -746,11 +745,11 @@ public class UserPermissionDaoTest {
List<UserPermissionDto> currentPermissions = underTest.selectUserPermissionsByQuery(dbSession, query, expectedUserIds);
assertThat(currentPermissions).hasSize(expectedPermissions.length);
Tuple[] expectedPermissionsAsTuple = Arrays.stream(expectedPermissions)
- .map(expectedPermission -> tuple(expectedPermission.getUserId(), expectedPermission.getPermission(), expectedPermission.getComponentId(),
+ .map(expectedPermission -> tuple(expectedPermission.getUserId(), expectedPermission.getPermission(), expectedPermission.getComponentUuid(),
expectedPermission.getOrganizationUuid()))
.toArray(Tuple[]::new);
assertThat(currentPermissions)
- .extracting(UserPermissionDto::getUserId, UserPermissionDto::getPermission, UserPermissionDto::getComponentId, UserPermissionDto::getOrganizationUuid)
+ .extracting(UserPermissionDto::getUserId, UserPermissionDto::getPermission, UserPermissionDto::getComponentUuid, UserPermissionDto::getOrganizationUuid)
.containsOnly(expectedPermissionsAsTuple);
// test method "countUsers()"
@@ -766,19 +765,20 @@ public class UserPermissionDaoTest {
}
private UserPermissionDto addProjectPermission(OrganizationDto org, String permission, UserDto user, ComponentDto project) {
- UserPermissionDto dto = new UserPermissionDto(org.getUuid(), permission, user.getId(), project.getId());
+ UserPermissionDto dto = new UserPermissionDto(org.getUuid(), permission, user.getId(), project.uuid());
underTest.insert(dbSession, dto);
db.commit();
return dto;
}
private void assertThatProjectPermissionDoesNotExist(UserDto user, String permission, ComponentDto project) {
- assertThat(db.countSql(dbSession, "select count(id) from user_roles where role='" + permission + "' and user_id=" + user.getId() + " and resource_id=" + project.getId()))
+ assertThat(db.countSql(dbSession, "select count(id) from user_roles where role='" + permission + "' and user_id=" + user.getId()
+ + " and component_uuid='" + project.uuid() + "'"))
.isEqualTo(0);
}
private void assertThatProjectHasNoPermissions(ComponentDto project) {
- assertThat(db.countSql(dbSession, "select count(id) from user_roles where resource_id=" + project.getId())).isEqualTo(0);
+ assertThat(db.countSql(dbSession, "select count(id) from user_roles where component_uuid='" + project.uuid() + "'")).isEqualTo(0);
}
private void assertOrgPermissionsOfUser(UserDto user, OrganizationDto organization, OrganizationPermission... permissions) {
@@ -788,6 +788,6 @@ public class UserPermissionDaoTest {
}
private void assertProjectPermissionsOfUser(UserDto user, ComponentDto project, String... permissions) {
- assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getId(), project.getId())).containsOnly(permissions);
+ assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).containsOnly(permissions);
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
index 133923435e2..1ad6a2b0e63 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
@@ -83,11 +83,11 @@ public class PropertiesDaoTest {
UserDto user1 = db.users().insertUser(u -> u.setLogin("user1"));
UserDto user2 = db.users().insertUser(u -> u.setLogin("user2"));
UserDto user3 = db.users().insertUser(u -> u.setLogin("user3"));
- insertProperty("notification.NewViolations.Email", "true", project1.getId(), user2.getId());
+ insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getId());
insertProperty("notification.NewViolations.Twitter", "true", null, user3.getId());
- insertProperty("notification.NewViolations.Twitter", "true", project2.getId(), user1.getId());
- insertProperty("notification.NewViolations.Twitter", "true", project1.getId(), user2.getId());
- insertProperty("notification.NewViolations.Twitter", "true", project2.getId(), user3.getId());
+ insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getId());
+ insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getId());
+ insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getId());
db.users().insertProjectPermissionOnUser(user2, UserRole.USER, project1);
db.users().insertProjectPermissionOnUser(user3, UserRole.USER, project2);
db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project2);
@@ -122,13 +122,14 @@ public class PropertiesDaoTest {
int userId1 = db.users().insertUser(u -> u.setLogin("user1")).getId();
int userId2 = db.users().insertUser(u -> u.setLogin("user2")).getId();
String projectUuid = randomAlphabetic(8);
- Long projectId = db.components().insertPrivateProject(db.getDefaultOrganization(), projectUuid).getId();
+ db.components().insertPrivateProject(db.getDefaultOrganization(), projectUuid);
+
// global subscription
insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userId2);
// project subscription
- insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectId, userId1);
- insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", 56L, userId1);
- insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectId, userId1);
+ insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, userId1);
+ insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", userId1);
+ insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, userId1);
// global subscription
insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userId2);
@@ -184,7 +185,7 @@ public class PropertiesDaoTest {
int userId2 = db.users().insertUser(withEmail("user2")).getId();
int userId3 = db.users().insertUser(withEmail("user3")).getId();
int userId4 = db.users().insertUser(withEmail("user4")).getId();
- long projectId = insertPrivateProject("PROJECT_A").getId();
+ String projectUuid = insertPrivateProject("PROJECT_A").uuid();
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
@@ -193,11 +194,11 @@ public class PropertiesDaoTest {
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1);
// user2 subscribed on project and globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2);
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3);
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectId, userId4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4);
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null))
.containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2")));
@@ -216,7 +217,7 @@ public class PropertiesDaoTest {
int userId2 = db.users().insertUser(withEmail("user2")).getId();
int userId3 = db.users().insertUser(withEmail("user3")).getId();
int userId4 = db.users().insertUser(withEmail("user4")).getId();
- long projectId = insertPrivateProject("PROJECT_A").getId();
+ String projectUuid = insertPrivateProject("PROJECT_A").uuid();
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
@@ -225,11 +226,11 @@ public class PropertiesDaoTest {
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1);
// user2 subscribed on project and globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2);
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3);
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectId, userId4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4);
Set<String> allLogins = of("user1", "user2", "user3", "user4");
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins))
@@ -259,7 +260,7 @@ public class PropertiesDaoTest {
int userId4 = db.users().insertUser(withEmail("user4")).getId();
String projectKey = randomAlphabetic(3);
String otherProjectKey = randomAlphabetic(4);
- long projectId = insertPrivateProject(projectKey).getId();
+ String projectUuid = insertPrivateProject(projectKey).uuid();
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
@@ -268,11 +269,11 @@ public class PropertiesDaoTest {
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1);
// user2 subscribed on project and globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2);
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3);
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectId, userId4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4);
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey))
.containsOnly(
@@ -298,7 +299,7 @@ public class PropertiesDaoTest {
int userId4 = db.users().insertUser(withEmail("user4")).getId();
String projectKey = randomAlphabetic(3);
String otherProjectKey = randomAlphabetic(4);
- long projectId = insertPrivateProject(projectKey).getId();
+ String projectUuid = insertPrivateProject(projectKey).uuid();
String dispatcherKey = randomAlphabetic(5);
String otherDispatcherKey = randomAlphabetic(6);
String channelKey = randomAlphabetic(7);
@@ -307,11 +308,11 @@ public class PropertiesDaoTest {
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1);
// user2 subscribed on project and globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2);
// user3 subscribed on project only
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId3);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3);
// user4 did not subscribe
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectId, userId4);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4);
Set<String> allLogins = of("user1", "user2", "user3", "user4");
assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins))
@@ -347,14 +348,14 @@ public class PropertiesDaoTest {
int userId3 = db.users().insertUser(withEmail("user3")).getId();
int userId4 = db.users().insertUser(noEmail("user4")).getId();
String projectKey = randomAlphabetic(3);
- long projectId = insertPrivateProject(projectKey).getId();
+ String projectUuid = insertPrivateProject(projectKey).uuid();
String dispatcherKey = randomAlphabetic(4);
String channelKey = randomAlphabetic(5);
// user1 and user2 subscribed on project and globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId1);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId1);
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2);
// user3 and user4 subscribed only globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId3);
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId4);
@@ -377,14 +378,14 @@ public class PropertiesDaoTest {
int userId4 = db.users().insertUser(noEmail("user4")).getId();
Set<String> allLogins = of("user1", "user2", "user3");
String projectKey = randomAlphabetic(3);
- long projectId = insertPrivateProject(projectKey).getId();
+ String projectUuid = insertPrivateProject(projectKey).uuid();
String dispatcherKey = randomAlphabetic(4);
String channelKey = randomAlphabetic(5);
// user1 and user2 subscribed on project and globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId1);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId1);
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2);
- insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectId, userId2);
+ insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2);
// user3 and user4 subscribed only globally
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId3);
insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId4);
@@ -409,17 +410,13 @@ public class PropertiesDaoTest {
assertThat(properties.size())
.isEqualTo(2);
- assertThatDto(findByKey(properties, "global.one"))
- .hasKey("global.one")
- .hasNoUserId()
- .hasNoResourceId()
- .hasValue("one");
+ assertThat(findByKey(properties, "global.one"))
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue)
+ .containsExactly("global.one", null, null, "one");
- assertThatDto(findByKey(properties, "global.two"))
- .hasKey("global.two")
- .hasNoResourceId()
- .hasNoUserId()
- .hasValue("two");
+ assertThat(findByKey(properties, "global.two"))
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue)
+ .containsExactly("global.two", null, null, "two");
}
@Test
@@ -430,11 +427,10 @@ public class PropertiesDaoTest {
List<PropertyDto> dtos = underTest.selectGlobalProperties();
assertThat(dtos)
.hasSize(1);
- assertThatDto(dtos.iterator().next())
- .hasKey("global.one")
- .hasNoResourceId()
- .hasNoUserId()
- .hasValue(expected);
+
+ assertThat(dtos.iterator().next())
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue)
+ .containsExactly("global.one", null, null, expected);
}
@Test
@@ -443,14 +439,13 @@ public class PropertiesDaoTest {
insertProperty("global.one", "one", null, null);
insertProperty("global.two", "two", null, null);
// project
- insertProperty("project.one", "one", 10L, null);
+ insertProperty("project.one", "one", "uuid10", null);
// user
insertProperty("user.one", "one", null, 100);
- assertThatDto(underTest.selectGlobalProperty("global.one"))
- .hasNoResourceId()
- .hasNoUserId()
- .hasValue("one");
+ assertThat(underTest.selectGlobalProperty("global.one"))
+ .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue)
+ .containsExactly(null, null, "one");
assertThat(underTest.selectGlobalProperty("project.one")).isNull();
assertThat(underTest.selectGlobalProperty("user.one")).isNull();
@@ -462,48 +457,46 @@ public class PropertiesDaoTest {
public void selectGlobalProperty_supports_all_values(String dbValue, String expected) {
insertProperty("global.one", dbValue, null, null);
- assertThatDto(underTest.selectGlobalProperty("global.one"))
- .hasNoResourceId()
- .hasNoUserId()
- .hasValue(expected);
+ assertThat(underTest.selectGlobalProperty("global.one"))
+ .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue)
+ .containsExactly(null, null, expected);
}
@Test
public void selectProjectProperties() {
ComponentDto projectDto = insertPrivateProject("A");
- long projectId = projectDto.getId();
+ String projectUuid = projectDto.uuid();
// global
insertProperty("global.one", "one", null, null);
insertProperty("global.two", "two", null, null);
// project
- insertProperty("project.one", "Pone", projectId, null);
- insertProperty("project.two", "Ptwo", projectId, null);
+ insertProperty("project.one", "Pone", projectUuid, null);
+ insertProperty("project.two", "Ptwo", projectUuid, null);
List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey());
assertThat(dtos)
.hasSize(2);
- assertThatDto(findByKey(dtos, "project.one"))
- .hasKey("project.one")
- .hasResourceId(projectId)
- .hasValue("Pone");
- assertThatDto(findByKey(dtos, "project.two"))
- .hasKey("project.two")
- .hasResourceId(projectId)
- .hasValue("Ptwo");
+ assertThat(findByKey(dtos, "project.one"))
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getValue)
+ .containsExactly("project.one", projectUuid, "Pone");
+
+ assertThat(findByKey(dtos, "project.two"))
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getValue)
+ .containsExactly("project.two", projectUuid, "Ptwo");
}
@Test
@UseDataProvider("allValuesForSelect")
public void selectProjectProperties_supports_all_values(String dbValue, String expected) {
ComponentDto projectDto = insertPrivateProject("A");
- insertProperty("project.one", dbValue, projectDto.getId(), null);
+ insertProperty("project.one", dbValue, projectDto.uuid(), null);
List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey());
assertThat(dtos).hasSize(1);
- assertThatDto(dtos.iterator().next())
- .hasKey("project.one")
- .hasResourceId(projectDto.getId())
- .hasValue(expected);
+
+ assertThat(dtos.iterator().next())
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getValue)
+ .containsExactly("project.one", projectDto.uuid(), expected);
}
@DataProvider
@@ -519,15 +512,13 @@ public class PropertiesDaoTest {
@Test
public void selectProjectProperty() {
- insertProperty("project.one", "one", 10L, null);
+ insertProperty("project.one", "one", "uuid10", null);
- PropertyDto property = underTest.selectProjectProperty(10L, "project.one");
+ PropertyDto property = underTest.selectProjectProperty("uuid10", "project.one");
- assertThatDto(property)
- .hasKey("project.one")
- .hasResourceId(10L)
- .hasNoUserId()
- .hasValue("one");
+ assertThat(property)
+ .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue)
+ .containsExactly("project.one", "uuid10", null, "one");
}
@Test
@@ -536,16 +527,17 @@ public class PropertiesDaoTest {
insertProperty("global.one", "one", null, null);
insertProperty("global.two", "two", null, null);
// struts
- insertProperty("struts.one", "one", 10L, null);
+ insertProperty("struts.one", "one", "uuid10", null);
// commons
- insertProperty("commonslang.one", "one", 11L, null);
+ insertProperty("commonslang.one", "one", "uuid11", null);
// user
insertProperty("user.one", "one", null, 100);
- insertProperty("user.two", "two", 10L, 100);
+ insertProperty("user.two", "two", "uuid10", 100);
// other
- insertProperty("other.one", "one", 12L, null);
+ insertProperty("other.one", "one", "uuid12", null);
- List<PropertyDto> results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.two").setComponentId(10L).setUserId(100).build(), db.getSession());
+ List<PropertyDto> results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.two").setComponentUuid("uuid10")
+ .setUserId(100).build(), db.getSession());
assertThat(results).hasSize(1);
assertThat(results.get(0).getValue()).isEqualTo("two");
@@ -562,7 +554,7 @@ public class PropertiesDaoTest {
String key = "key";
String anotherKey = "anotherKey";
insertProperty(key, "value", null, null);
- insertProperty(key, "value", 10L, null);
+ insertProperty(key, "value", "uuid10", null);
insertProperty(key, "value", null, userId);
insertProperty(anotherKey, "value", null, null);
@@ -603,15 +595,15 @@ public class PropertiesDaoTest {
newComponentPropertyDto(project2).setKey(anotherKey),
newUserPropertyDto(user).setKey(key));
- assertThat(underTest.selectPropertiesByComponentIds(session, newHashSet(project.getId())))
- .extracting("key", "resourceId").containsOnly(tuple(key, project.getId()));
- assertThat(underTest.selectPropertiesByComponentIds(session, newHashSet(project.getId(), project2.getId())))
- .extracting("key", "resourceId").containsOnly(
- tuple(key, project.getId()),
- tuple(key, project2.getId()),
- tuple(anotherKey, project2.getId()));
+ assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet(project.uuid())))
+ .extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid()));
+ assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet(project.uuid(), project2.uuid())))
+ .extracting("key", "componentUuid").containsOnly(
+ tuple(key, project.uuid()),
+ tuple(key, project2.uuid()),
+ tuple(anotherKey, project2.uuid()));
- assertThat(underTest.selectPropertiesByComponentIds(session, newHashSet(123456789L))).isEmpty();
+ assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet("uuid123456789"))).isEmpty();
}
@Test
@@ -629,21 +621,21 @@ public class PropertiesDaoTest {
newComponentPropertyDto(project2).setKey(anotherKey),
newUserPropertyDto(user).setKey(key));
- assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet(key), newHashSet(project.getId())))
- .extracting("key", "resourceId").containsOnly(tuple(key, project.getId()));
- assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet(key), newHashSet(project.getId(), project2.getId())))
- .extracting("key", "resourceId").containsOnly(
- tuple(key, project.getId()),
- tuple(key, project2.getId()));
- assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet(key, anotherKey), newHashSet(project.getId(), project2.getId())))
- .extracting("key", "resourceId").containsOnly(
- tuple(key, project.getId()),
- tuple(key, project2.getId()),
- tuple(anotherKey, project2.getId()));
-
- assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet("unknown"), newHashSet(project.getId()))).isEmpty();
- assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet("key"), newHashSet(123456789L))).isEmpty();
- assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet("unknown"), newHashSet(123456789L))).isEmpty();
+ assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid())))
+ .extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid()));
+ assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid(), project2.uuid())))
+ .extracting("key", "componentUuid").containsOnly(
+ tuple(key, project.uuid()),
+ tuple(key, project2.uuid()));
+ assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key, anotherKey), newHashSet(project.uuid(), project2.uuid())))
+ .extracting("key", "componentUuid").containsOnly(
+ tuple(key, project.uuid()),
+ tuple(key, project2.uuid()),
+ tuple(anotherKey, project2.uuid()));
+
+ assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("unknown"), newHashSet(project.uuid()))).isEmpty();
+ assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("key"), newHashSet("uuid123456789"))).isEmpty();
+ assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("unknown"), newHashSet("uuid123456789"))).isEmpty();
}
@Test
@@ -657,10 +649,10 @@ public class PropertiesDaoTest {
newComponentPropertyDto("another key", "value", project1));
assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value"))
- .extracting(PropertyDto::getValue, PropertyDto::getResourceId)
+ .extracting(PropertyDto::getValue, PropertyDto::getComponentUuid)
.containsExactlyInAnyOrder(
- tuple("value", project1.getId()),
- tuple("value", project2.getId()),
+ tuple("value", project1.uuid()),
+ tuple("value", project2.uuid()),
tuple("value", null));
}
@@ -695,27 +687,27 @@ public class PropertiesDaoTest {
underTest.saveProperty(new PropertyDto().setKey("global.clob").setValue(VALUE_SIZE_4001));
assertThatPropertiesRow("global.null")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 2);
assertThatPropertiesRow("global.empty")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 3);
assertThatPropertiesRow("global.text")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("some text")
.hasCreatedAt(INITIAL_DATE + 4);
assertThatPropertiesRow("global.4000")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue(VALUE_SIZE_4000)
.hasCreatedAt(INITIAL_DATE + 5);
assertThatPropertiesRow("global.clob")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasClobValue(VALUE_SIZE_4001)
.hasCreatedAt(INITIAL_DATE + 6);
@@ -723,35 +715,35 @@ public class PropertiesDaoTest {
@Test
public void saveProperty_inserts_component_properties_when_they_do_not_exist_in_db() {
- long resourceId = 12;
- underTest.saveProperty(new PropertyDto().setKey("component.null").setResourceId(resourceId).setValue(null));
- underTest.saveProperty(new PropertyDto().setKey("component.empty").setResourceId(resourceId).setValue(""));
- underTest.saveProperty(new PropertyDto().setKey("component.text").setResourceId(resourceId).setValue("some text"));
- underTest.saveProperty(new PropertyDto().setKey("component.4000").setResourceId(resourceId).setValue(VALUE_SIZE_4000));
- underTest.saveProperty(new PropertyDto().setKey("component.clob").setResourceId(resourceId).setValue(VALUE_SIZE_4001));
+ String componentUuid = "uuid12";
+ underTest.saveProperty(new PropertyDto().setKey("component.null").setComponentUuid(componentUuid).setValue(null));
+ underTest.saveProperty(new PropertyDto().setKey("component.empty").setComponentUuid(componentUuid).setValue(""));
+ underTest.saveProperty(new PropertyDto().setKey("component.text").setComponentUuid(componentUuid).setValue("some text"));
+ underTest.saveProperty(new PropertyDto().setKey("component.4000").setComponentUuid(componentUuid).setValue(VALUE_SIZE_4000));
+ underTest.saveProperty(new PropertyDto().setKey("component.clob").setComponentUuid(componentUuid).setValue(VALUE_SIZE_4001));
assertThatPropertiesRow("component.null")
- .hasResourceId(resourceId)
+ .hasComponentUuid(componentUuid)
.hasNoUserId()
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 2);
assertThatPropertiesRow("component.empty")
- .hasResourceId(resourceId)
+ .hasComponentUuid(componentUuid)
.hasNoUserId()
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 3);
assertThatPropertiesRow("component.text")
- .hasResourceId(resourceId)
+ .hasComponentUuid(componentUuid)
.hasNoUserId()
.hasTextValue("some text")
.hasCreatedAt(INITIAL_DATE + 4);
assertThatPropertiesRow("component.4000")
- .hasResourceId(resourceId)
+ .hasComponentUuid(componentUuid)
.hasNoUserId()
.hasTextValue(VALUE_SIZE_4000)
.hasCreatedAt(INITIAL_DATE + 5);
assertThatPropertiesRow("component.clob")
- .hasResourceId(resourceId)
+ .hasComponentUuid(componentUuid)
.hasNoUserId()
.hasClobValue(VALUE_SIZE_4001)
.hasCreatedAt(INITIAL_DATE + 6);
@@ -767,27 +759,27 @@ public class PropertiesDaoTest {
underTest.saveProperty(new PropertyDto().setKey("user.clob").setUserId(userId).setValue(VALUE_SIZE_4001));
assertThatPropertiesRow("user.null")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(userId)
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 2);
assertThatPropertiesRow("user.empty")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(userId)
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 3);
assertThatPropertiesRow("user.text")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(userId)
.hasTextValue("some text")
.hasCreatedAt(INITIAL_DATE + 4);
assertThatPropertiesRow("user.4000")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(userId)
.hasTextValue(VALUE_SIZE_4000)
.hasCreatedAt(INITIAL_DATE + 5);
assertThatPropertiesRow("user.clob")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(userId)
.hasClobValue(VALUE_SIZE_4001)
.hasCreatedAt(INITIAL_DATE + 6);
@@ -804,7 +796,7 @@ public class PropertiesDaoTest {
.doesNotExist();
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasCreatedAt(INITIAL_DATE + 3);
if (newValue == null || newValue.isEmpty()) {
@@ -819,15 +811,15 @@ public class PropertiesDaoTest {
@Test
@UseDataProvider("valueUpdatesDataProvider")
public void saveProperty_deletes_then_inserts_component_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
- long resourceId = 999L;
- long id = insertProperty("global", oldValue, resourceId, null);
+ String componentUuid = "uuid999";
+ long id = insertProperty("global", oldValue, componentUuid, null);
- underTest.saveProperty(new PropertyDto().setKey("global").setResourceId(resourceId).setValue(newValue));
+ underTest.saveProperty(new PropertyDto().setKey("global").setComponentUuid(componentUuid).setValue(newValue));
assertThatPropertiesRow(id)
.doesNotExist();
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global")
- .hasResourceId(resourceId)
+ .hasComponentUuid(componentUuid)
.hasNoUserId()
.hasCreatedAt(INITIAL_DATE + 3);
if (newValue == null || newValue.isEmpty()) {
@@ -851,7 +843,7 @@ public class PropertiesDaoTest {
.doesNotExist();
PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(userId)
.hasCreatedAt(INITIAL_DATE + 3);
if (newValue == null || newValue.isEmpty()) {
@@ -899,62 +891,62 @@ public class PropertiesDaoTest {
@Test
public void delete_project_property() {
- long projectId1 = insertPrivateProject("A").getId();
- long projectId2 = insertPrivateProject("B").getId();
- long projectId3 = insertPrivateProject("C").getId();
+ insertPrivateProject("A");
+ insertPrivateProject("B");
+ insertPrivateProject("C");
long id1 = insertProperty("global.one", "one", null, null);
long id2 = insertProperty("global.two", "two", null, null);
- long id3 = insertProperty("struts.one", "one", projectId1, null);
- long id4 = insertProperty("commonslang.one", "one", projectId2, null);
+ long id3 = insertProperty("struts.one", "one", "project1", null);
+ long id4 = insertProperty("commonslang.one", "one", "project2", null);
long id5 = insertProperty("user.one", "one", null, 100);
long id6 = insertProperty("user.two", "two", null, 100);
- long id7 = insertProperty("other.one", "one", projectId3, null);
+ long id7 = insertProperty("other.one", "one", "project3", null);
- underTest.deleteProjectProperty("struts.one", projectId1);
+ underTest.deleteProjectProperty("struts.one", "project1");
assertThatPropertiesRow(id1)
.hasKey("global.one")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("one");
assertThatPropertiesRow(id2)
.hasKey("global.two")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("two");
assertThatPropertiesRow(id3)
.doesNotExist();
assertThatPropertiesRow(id4)
.hasKey("commonslang.one")
- .hasResourceId(projectId2)
+ .hasComponentUuid("project2")
.hasNoUserId()
.hasTextValue("one");
assertThatPropertiesRow(id5)
.hasKey("user.one")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(100)
.hasTextValue("one");
assertThatPropertiesRow(id6)
.hasKey("user.two")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(100)
.hasTextValue("two");
assertThatPropertiesRow(id7)
.hasKey("other.one")
- .hasResourceId(projectId3)
+ .hasComponentUuid("project3")
.hasNoUserId()
.hasTextValue("one");
}
@Test
public void delete_project_properties() {
- long id1 = insertProperty("sonar.profile.java", "Sonar Way", 1L, null);
- long id2 = insertProperty("sonar.profile.java", "Sonar Way", 2L, null);
+ long id1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null);
+ long id2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null);
long id3 = insertProperty("sonar.profile.java", "Sonar Way", null, null);
- long id4 = insertProperty("sonar.profile.js", "Sonar Way", 1L, null);
- long id5 = insertProperty("sonar.profile.js", "Sonar Way", 2L, null);
+ long id4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null);
+ long id5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null);
long id6 = insertProperty("sonar.profile.js", "Sonar Way", null, null);
underTest.deleteProjectProperties("sonar.profile.java", "Sonar Way");
@@ -965,22 +957,22 @@ public class PropertiesDaoTest {
.doesNotExist();
assertThatPropertiesRow(id3)
.hasKey("sonar.profile.java")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("Sonar Way");
assertThatPropertiesRow(id4)
.hasKey("sonar.profile.js")
- .hasResourceId(1)
+ .hasComponentUuid("uuid1")
.hasNoUserId()
.hasTextValue("Sonar Way");
assertThatPropertiesRow(id5)
.hasKey("sonar.profile.js")
- .hasResourceId(2)
+ .hasComponentUuid("uuid2")
.hasNoUserId()
.hasTextValue("Sonar Way");
assertThatPropertiesRow(id6)
.hasKey("sonar.profile.js")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("Sonar Way");
}
@@ -991,7 +983,7 @@ public class PropertiesDaoTest {
long id1 = insertProperty("global.key", "new_global", null, null);
long id2 = insertProperty("to_be_deleted", "xxx", null, null);
// project - do not delete this project property that has the same key
- long id3 = insertProperty("to_be_deleted", "new_project", 10L, null);
+ long id3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null);
// user
long id4 = insertProperty("user.key", "new_user", null, 100);
@@ -1000,7 +992,7 @@ public class PropertiesDaoTest {
assertThatPropertiesRow(id1)
.hasKey("global.key")
.hasNoUserId()
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasTextValue("new_global");
assertThatPropertiesRow(id2)
.doesNotExist();
@@ -1008,12 +1000,12 @@ public class PropertiesDaoTest {
.doesNotExist();
assertThatPropertiesRow(id3)
.hasKey("to_be_deleted")
- .hasResourceId(10)
+ .hasComponentUuid("to_be_deleted")
.hasNoUserId()
.hasTextValue("new_project");
assertThatPropertiesRow(id4)
.hasKey("user.key")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(100)
.hasTextValue("new_user");
}
@@ -1026,17 +1018,18 @@ public class PropertiesDaoTest {
ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
UserDto user = db.users().insertUser();
UserDto anotherUser = db.users().insertUser();
- insertProperty("KEY_11", "VALUE", project.getId(), user.getId());
- insertProperty("KEY_12", "VALUE", project.getId(), user.getId());
- insertProperty("KEY_11", "VALUE", project.getId(), anotherUser.getId());
- insertProperty("KEY_11", "VALUE", anotherProject.getId(), user.getId());
+ insertProperty("KEY_11", "VALUE", project.uuid(), user.getId());
+ insertProperty("KEY_12", "VALUE", project.uuid(), user.getId());
+ insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getId());
+ insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getId());
underTest.deleteByOrganizationAndUser(session, organization.getUuid(), user.getId());
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).build(), session))
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), session))
.hasSize(1)
.extracting(PropertyDto::getUserId).containsOnly(anotherUser.getId());
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(anotherProject.getId()).build(), session)).extracting(PropertyDto::getUserId)
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), session))
+ .extracting(PropertyDto::getUserId)
.hasSize(1).containsOnly(user.getId());
}
@@ -1048,17 +1041,18 @@ public class PropertiesDaoTest {
ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
UserDto user = db.users().insertUser();
UserDto anotherUser = db.users().insertUser();
- insertProperty("KEY_11", user.getLogin(), project.getId(), null);
- insertProperty("KEY_12", user.getLogin(), project.getId(), null);
- insertProperty("KEY_11", anotherUser.getLogin(), project.getId(), null);
- insertProperty("KEY_11", user.getLogin(), anotherProject.getId(), null);
+ insertProperty("KEY_11", user.getLogin(), project.uuid(), null);
+ insertProperty("KEY_12", user.getLogin(), project.uuid(), null);
+ insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null);
+ insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null);
underTest.deleteByOrganizationAndMatchingLogin(session, organization.getUuid(), user.getLogin(), newArrayList("KEY_11", "KEY_12"));
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).build(), session))
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), session))
.hasSize(1)
.extracting(PropertyDto::getValue).containsOnly(anotherUser.getLogin());
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(anotherProject.getId()).build(), session)).extracting(PropertyDto::getValue)
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), session))
+ .extracting(PropertyDto::getValue)
.hasSize(1).containsOnly(user.getLogin());
}
@@ -1067,20 +1061,20 @@ public class PropertiesDaoTest {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto anotherProject = db.components().insertPrivateProject();
insertProperty("KEY", "VALUE", null, null);
- insertProperty("KEY", "VALUE", project.getId(), null);
+ insertProperty("KEY", "VALUE", project.uuid(), null);
insertProperty("KEY", "VALUE", null, 100);
- insertProperty("KEY", "VALUE", project.getId(), 100);
- insertProperty("KEY", "VALUE", anotherProject.getId(), null);
+ insertProperty("KEY", "VALUE", project.uuid(), 100);
+ insertProperty("KEY", "VALUE", anotherProject.uuid(), null);
// Should not be removed
insertProperty("KEY", "ANOTHER_VALUE", null, null);
- insertProperty("ANOTHER_KEY", "VALUE", project.getId(), 100);
+ insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), 100);
underTest.deleteByKeyAndValue(session, "KEY", "VALUE");
db.commit();
- assertThat(db.select("select prop_key as \"key\", text_value as \"value\", resource_id as \"projectId\", user_id as \"userId\" from properties"))
- .extracting((row) -> row.get("key"), (row) -> row.get("value"), (row) -> row.get("projectId"), (row) -> row.get("userId"))
- .containsOnly(tuple("KEY", "ANOTHER_VALUE", null, null), tuple("ANOTHER_KEY", "VALUE", project.getId(), 100L));
+ assertThat(db.select("select prop_key as \"key\", text_value as \"value\", component_uuid as \"projectUuid\", user_id as \"userId\" from properties"))
+ .extracting((row) -> row.get("key"), (row) -> row.get("value"), (row) -> row.get("projectUuid"), (row) -> row.get("userId"))
+ .containsOnly(tuple("KEY", "ANOTHER_VALUE", null, null), tuple("ANOTHER_KEY", "VALUE", project.uuid(), 100L));
}
@Test
@@ -1093,27 +1087,27 @@ public class PropertiesDaoTest {
"clob_value_property", VALUE_SIZE_4001));
assertThatPropertiesRow("null_value_property")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 2);
assertThatPropertiesRow("empty_value_property")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.isEmpty()
.hasCreatedAt(INITIAL_DATE + 3);
assertThatPropertiesRow("text_value_property")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("dfdsfsd")
.hasCreatedAt(INITIAL_DATE + 4);
assertThatPropertiesRow("4000_char_value_property")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue(VALUE_SIZE_4000)
.hasCreatedAt(INITIAL_DATE + 5);
assertThatPropertiesRow("clob_value_property")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasClobValue(VALUE_SIZE_4001)
.hasCreatedAt(INITIAL_DATE + 6);
@@ -1129,7 +1123,7 @@ public class PropertiesDaoTest {
.doesNotExist();
assertThatPropertiesRow("to_be_updated")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("new value")
.hasCreatedAt(INITIAL_DATE + 3);
@@ -1149,8 +1143,8 @@ public class PropertiesDaoTest {
public void renamePropertyKey_updates_global_component_and_user_properties() {
long id1 = insertProperty("foo", "bar", null, null);
long id2 = insertProperty("old_name", "doc1", null, null);
- long id3 = insertProperty("old_name", "doc2", 15L, null);
- long id4 = insertProperty("old_name", "doc3", 16L, null);
+ long id3 = insertProperty("old_name", "doc2", "15", null);
+ long id4 = insertProperty("old_name", "doc3", "16", null);
long id5 = insertProperty("old_name", "doc4", null, 100);
long id6 = insertProperty("old_name", "doc5", null, 101);
@@ -1159,36 +1153,36 @@ public class PropertiesDaoTest {
assertThatPropertiesRow(id1)
.hasKey("foo")
.hasNoUserId()
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasTextValue("bar")
.hasCreatedAt(INITIAL_DATE + 2);
assertThatPropertiesRow(id2)
.hasKey("new_name")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasNoUserId()
.hasTextValue("doc1")
.hasCreatedAt(INITIAL_DATE + 3);
assertThatPropertiesRow(id3)
.hasKey("new_name")
- .hasResourceId(15)
+ .hasComponentUuid("15")
.hasNoUserId()
.hasTextValue("doc2")
.hasCreatedAt(INITIAL_DATE + 4);
assertThatPropertiesRow(id4)
.hasKey("new_name")
- .hasResourceId(16)
+ .hasComponentUuid("16")
.hasNoUserId()
.hasTextValue("doc3")
.hasCreatedAt(INITIAL_DATE + 5);
assertThatPropertiesRow(id5)
.hasKey("new_name")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(100)
.hasTextValue("doc4")
.hasCreatedAt(INITIAL_DATE + 6);
assertThatPropertiesRow(id6)
.hasKey("new_name")
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasUserId(101)
.hasTextValue("doc5")
.hasCreatedAt(INITIAL_DATE + 7);
@@ -1206,7 +1200,7 @@ public class PropertiesDaoTest {
assertThatPropertiesRow(id)
.hasKey("foo")
.hasNoUserId()
- .hasNoResourceId()
+ .hasNoComponentUuid()
.hasTextValue("bar")
.hasCreatedAt(INITIAL_DATE + 2);
}
@@ -1239,9 +1233,9 @@ public class PropertiesDaoTest {
session.commit();
}
- private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) {
+ private long insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable Integer userId) {
PropertyDto dto = new PropertyDto().setKey(key)
- .setResourceId(resourceId)
+ .setComponentUuid(componentUuid)
.setUserId(userId)
.setValue(value);
db.properties().insertProperty(dto);
@@ -1249,7 +1243,7 @@ public class PropertiesDaoTest {
return (long) db.selectFirst(session, "select id as \"id\" from properties" +
" where prop_key='" + key + "'" +
" and user_id" + (userId == null ? " is null" : "='" + userId + "'") +
- " and resource_id" + (resourceId == null ? " is null" : "='" + resourceId + "'")).get("id");
+ " and component_uuid" + (componentUuid == null ? " is null" : "='" + componentUuid + "'")).get("id");
}
private ComponentDto insertPrivateProject(String projectKey) {
@@ -1272,12 +1266,8 @@ public class PropertiesDaoTest {
return String.format("notification.%s.%s", dispatcherKey, channelKey);
}
- private static PropertyDtoAssert assertThatDto(@Nullable PropertyDto dto) {
- return new PropertyDtoAssert(dto);
- }
-
- private PropertiesRowAssert assertThatPropertiesRow(String key, @Nullable Integer userId, @Nullable Integer componentId) {
- return new PropertiesRowAssert(db, key, userId, componentId);
+ private PropertiesRowAssert assertThatPropertiesRow(String key, @Nullable Integer userId, @Nullable String componentUuid) {
+ return new PropertiesRowAssert(db, key, userId, componentUuid);
}
private PropertiesRowAssert assertThatPropertiesRow(String key) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java
index 00a1963ba65..f1f608b4310 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java
@@ -25,18 +25,18 @@ import javax.annotation.Nullable;
final class PropertiesRow {
private final String key;
private final Integer userId;
- private final Long resourceId;
+ private final String componentUuid;
private final Boolean empty;
private final String textValue;
private final String clobValue;
private final Long createdAt;
- public PropertiesRow(String key, @Nullable Integer userId, @Nullable Long resourceId,
+ public PropertiesRow(String key, @Nullable Integer userId, @Nullable String componentUuid,
@Nullable Boolean empty, @Nullable String textValue, @Nullable String clobValue,
@Nullable Long createdAt) {
this.key = key;
this.userId = userId;
- this.resourceId = resourceId;
+ this.componentUuid = componentUuid;
this.empty = empty;
this.textValue = textValue;
this.clobValue = clobValue;
@@ -51,8 +51,8 @@ final class PropertiesRow {
return userId;
}
- public Long getResourceId() {
- return resourceId;
+ public String getComponentUuid() {
+ return componentUuid;
}
@CheckForNull
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java
index 5ab62b18937..c723b98978a 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java
@@ -35,13 +35,13 @@ import static java.util.Objects.requireNonNull;
final class PropertiesRowAssert extends AbstractAssert<PropertiesRowAssert, PropertiesRow> {
- PropertiesRowAssert(DbTester dbTester, String propertyKey, @Nullable Integer userId, @Nullable Integer componentId) {
+ PropertiesRowAssert(DbTester dbTester, String propertyKey, @Nullable Integer userId, @Nullable String componentUuid) {
super(
asInternalProperty(
dbTester,
() -> " where prop_key='" + propertyKey + "'" +
" and user_id" + (userId == null ? " is null" : "='" + userId + "'") +
- " and resource_id" + (componentId == null ? " is null" : "='" + componentId + "'")),
+ " and component_uuid" + (componentUuid == null ? " is null" : "='" + componentUuid + "'")),
PropertiesRowAssert.class);
}
@@ -58,7 +58,8 @@ final class PropertiesRowAssert extends AbstractAssert<PropertiesRowAssert, Prop
String whereClause = whereClauseSupplier.get();
List<Map<String, Object>> rows = dbTester.select(
"select" +
- " prop_key as \"key\", user_id as \"userId\", resource_id as \"resourceId\", is_empty as \"isEmpty\", text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\""
+ " prop_key as \"key\", user_id as \"userId\", component_uuid as \"componentUuid\", is_empty as \"isEmpty\", "
+ + "text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\""
+
" from properties" +
whereClause);
@@ -71,7 +72,7 @@ final class PropertiesRowAssert extends AbstractAssert<PropertiesRowAssert, Prop
return new PropertiesRow(
(String) row.get("key"),
userId == null ? null : userId.intValue(),
- (Long) row.get("resourceId"),
+ (String) row.get("componentUuid"),
toBoolean(row.get("isEmpty")),
(String) row.get("textValue"),
(String) row.get("clobValue"),
@@ -124,21 +125,21 @@ final class PropertiesRowAssert extends AbstractAssert<PropertiesRowAssert, Prop
return this;
}
- public PropertiesRowAssert hasNoResourceId() {
+ public PropertiesRowAssert hasNoComponentUuid() {
isNotNull();
- if (actual.getResourceId() != null) {
- failWithMessage("Expected PropertiesRow to have column RESOURCE_ID to be null but was <%s>", actual.getResourceId());
+ if (actual.getComponentUuid() != null) {
+ failWithMessage("Expected PropertiesRow to have column COMPONENT_UUID to be null but was <%s>", actual.getComponentUuid());
}
return this;
}
- public PropertiesRowAssert hasResourceId(long expected) {
+ public PropertiesRowAssert hasComponentUuid(String expected) {
isNotNull();
- if (!Objects.equals(actual.getResourceId(), expected)) {
- failWithMessage("Expected PropertiesRow to have column RESOURCE_ID to be <%s> but was <%s>", true, actual.getResourceId());
+ if (!Objects.equals(actual.getComponentUuid(), expected)) {
+ failWithMessage("Expected PropertiesRow to have column COMPONENT_UUID to be <%s> but was <%s>", true, actual.getComponentUuid());
}
return this;
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoAssert.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoAssert.java
deleted file mode 100644
index 14f31c9a3c7..00000000000
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoAssert.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.db.property;
-
-import java.util.Objects;
-import javax.annotation.Nullable;
-import org.assertj.core.api.AbstractAssert;
-
-import static java.util.Objects.requireNonNull;
-
-public class PropertyDtoAssert extends AbstractAssert<PropertyDtoAssert, PropertyDto> {
- protected PropertyDtoAssert(@Nullable PropertyDto actual) {
- super(actual, PropertyDtoAssert.class);
- }
-
- public PropertyDtoAssert hasKey(String expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getKey(), expected)) {
- failWithMessage("Expected PropertyDto to have key to be <%s> but was <%s>", expected, actual.getKey());
- }
-
- return this;
- }
-
- public PropertyDtoAssert hasNoUserId() {
- isNotNull();
-
- if (actual.getUserId() != null) {
- failWithMessage("Expected PropertyDto to have userId to be null but was <%s>", actual.getUserId());
- }
-
- return this;
- }
-
- public PropertyDtoAssert hasUserId(long expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getUserId(), expected)) {
- failWithMessage("Expected PropertyDto to have userId to be <%s> but was <%s>", true, actual.getUserId());
- }
-
- return this;
- }
-
- public PropertyDtoAssert hasNoResourceId() {
- isNotNull();
-
- if (actual.getResourceId() != null) {
- failWithMessage("Expected PropertyDto to have resourceId to be null but was <%s>", actual.getResourceId());
- }
-
- return this;
- }
-
- public PropertyDtoAssert hasResourceId(long expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getResourceId(), expected)) {
- failWithMessage("Expected PropertyDto to have resourceId to be <%s> but was <%s>", true, actual.getResourceId());
- }
-
- return this;
- }
-
- public PropertyDtoAssert hasValue(String expected) {
- requireNonNull(expected);
- isNotNull();
-
- if (!Objects.equals(actual.getValue(), expected)) {
- failWithMessage("Expected PropertyDto to have value to be <%s> but was <%s>", true, actual.getValue());
- }
-
- return this;
- }
-}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java
index b0709725df4..4fd787acb4c 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java
@@ -34,22 +34,22 @@ public class PropertyDtoTest {
@Test
public void testEquals() {
- assertThat(new PropertyDto().setKey("123").setResourceId(123L)).isEqualTo(new PropertyDto().setKey("123").setResourceId(123L));
- assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(new PropertyDto().setKey("123").setResourceId(123L));
- assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(null);
- assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(new Object());
+ assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123")).isEqualTo(new PropertyDto().setKey("123").setComponentUuid("uuid123"));
+ assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotEqualTo(new PropertyDto().setKey("123").setComponentUuid("uuid123"));
+ assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotEqualTo(null);
+ assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotEqualTo(new Object());
}
@Test
public void testHashCode() {
- assertThat(new PropertyDto().setKey("123").setResourceId(123L).hashCode()).isNotNull();
- assertThat(new PropertyDto().setKey("123").setResourceId(123L).hashCode())
- .isEqualTo(new PropertyDto().setKey("123").setResourceId(123L).hashCode());
+ assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123").hashCode()).isNotNull();
+ assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123").hashCode())
+ .isEqualTo(new PropertyDto().setKey("123").setComponentUuid("uuid123").hashCode());
}
@Test
public void testToString() {
- assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setResourceId(123L).setUserId(456).toString()).isEqualTo("PropertyDto{foo:bar, value, 123, 456}");
+ assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setComponentUuid("uuid123").setUserId(456).toString()).isEqualTo("PropertyDto{foo:bar, value, uuid123, 456}");
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
index 864ba5d85fe..b1a8614e683 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.purge;
+import com.google.common.collect.ImmutableList;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
@@ -26,6 +27,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.After;
@@ -54,6 +56,7 @@ import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
@@ -87,7 +90,7 @@ public class PurgeCommandsTest {
*/
@Test
public void should_not_fail_when_deleting_huge_number_of_analyses() {
- new PurgeCommands(dbTester.getSession(), profiler, system2).deleteAnalyses(getHugeNumberOfIdUuidPairs());
+ new PurgeCommands(dbTester.getSession(), profiler, system2).deleteAnalyses(getHugeNumberOfUuids());
// The goal of this test is only to check that the query do no fail, not to check result
}
@@ -103,13 +106,13 @@ public class PurgeCommandsTest {
IntStream.range(0, count).forEach(i -> insertDuplication(project, analysis));
}
- underTest.purgeAnalyses(toIdUuidPairs(analysis1));
+ underTest.purgeAnalyses(ImmutableList.of(analysis1.getUuid()));
assertThat(countDuplications(analysis1)).isZero();
assertThat(countDuplications(analysis2)).isEqualTo(count);
assertThat(countDuplications(analysis3)).isEqualTo(count);
assertThat(countDuplications(analysis4)).isEqualTo(count);
- underTest.purgeAnalyses(toIdUuidPairs(analysis1, analysis3, analysis4));
+ underTest.purgeAnalyses(ImmutableList.of(analysis1.getUuid(), analysis3.getUuid(), analysis4.getUuid()));
assertThat(countDuplications(analysis1)).isZero();
assertThat(countDuplications(analysis2)).isEqualTo(count);
assertThat(countDuplications(analysis3)).isZero();
@@ -121,7 +124,7 @@ public class PurgeCommandsTest {
*/
@Test
public void purgeAnalyses_should_not_fail_when_purging_huge_number_of_analyses() {
- new PurgeCommands(dbTester.getSession(), profiler, system2).purgeAnalyses(getHugeNumberOfIdUuidPairs());
+ new PurgeCommands(dbTester.getSession(), profiler, system2).purgeAnalyses(getHugeNumberOfUuids());
// The goal of this test is only to check that the query do no fail, not to check result
}
@@ -354,15 +357,15 @@ public class PurgeCommandsTest {
.mapToObj(i -> dbTester.components().insertSnapshot(projectOrView, randomLastAndStatus()))
.collect(toList());
- underTest.deleteAnalyses(toIdUuidPairs(analyses.get(0)));
+ underTest.deleteAnalyses(singletonList(analyses.get(0).getUuid()));
assertThat(uuidsOfAnalysesOfRoot(projectOrView))
.containsOnly(analyses.stream().skip(1).map(SnapshotDto::getUuid).toArray(String[]::new));
- underTest.deleteAnalyses(toIdUuidPairs(analyses.stream().skip(1).limit(3)));
+ underTest.deleteAnalyses(analyses.stream().map(SnapshotDto::getUuid).skip(1).limit(3).collect(Collectors.toList()));
assertThat(uuidsOfAnalysesOfRoot(projectOrView))
.containsOnly(analyses.stream().skip(4).map(SnapshotDto::getUuid).toArray(String[]::new));
- underTest.deleteAnalyses(toIdUuidPairs(analyses.stream()));
+ underTest.deleteAnalyses(analyses.stream().map(SnapshotDto::getUuid).collect(Collectors.toList()));
assertThat(uuidsOfAnalysesOfRoot(projectOrView)).isEmpty();
}
@@ -384,7 +387,7 @@ public class PurgeCommandsTest {
insertRandomEventComponentChange(otherAnalysis);
});
- underTest.deleteAnalyses(toIdUuidPairs(analysis));
+ underTest.deleteAnalyses(singletonList(analysis.getUuid()));
assertThat(countEventComponentChangesOf(analysis)).isZero();
assertThat(countEventComponentChangesOf(otherAnalysis)).isEqualTo(count);
@@ -402,7 +405,7 @@ public class PurgeCommandsTest {
dbTester.events().insertEvent(otherAnalysis);
});
- underTest.deleteAnalyses(toIdUuidPairs(analysis));
+ underTest.deleteAnalyses(singletonList(analysis.getUuid()));
assertThat(countEventsOf(analysis)).isZero();
assertThat(countEventsOf(otherAnalysis)).isEqualTo(count);
@@ -425,7 +428,7 @@ public class PurgeCommandsTest {
});
});
- underTest.deleteAnalyses(toIdUuidPairs(analysis));
+ underTest.deleteAnalyses(singletonList(analysis.getUuid()));
assertThat(countMeasuresOf(analysis)).isZero();
assertThat(countMeasuresOf(otherAnalysis)).isEqualTo(count * 2);
@@ -443,7 +446,7 @@ public class PurgeCommandsTest {
insertRandomAnalysisProperty(otherAnalysis);
});
- underTest.deleteAnalyses(toIdUuidPairs(analysis));
+ underTest.deleteAnalyses(singletonList(analysis.getUuid()));
assertThat(countAnalysisPropertiesOf(analysis)).isZero();
assertThat(countAnalysisPropertiesOf(otherAnalysis)).isEqualTo(count);
@@ -500,7 +503,7 @@ public class PurgeCommandsTest {
addPermissions(organization, project);
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
- purgeCommands.deletePermissions(project.getId());
+ purgeCommands.deletePermissions(project.uuid());
assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2);
assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1);
@@ -513,7 +516,7 @@ public class PurgeCommandsTest {
addPermissions(organization, project);
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
- purgeCommands.deletePermissions(project.getId());
+ purgeCommands.deletePermissions(project.uuid());
assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1);
@@ -526,7 +529,7 @@ public class PurgeCommandsTest {
addPermissions(organization, project);
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
- purgeCommands.deletePermissions(project.getId());
+ purgeCommands.deletePermissions(project.uuid());
assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2);
assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1);
@@ -710,22 +713,12 @@ public class PurgeCommandsTest {
return dbTester.countSql("select count(1) from snapshots where component_uuid='" + projectOrView.uuid() + "' and status='" + status + "' and islast=" + bool);
}
- private static List<IdUuidPair> toIdUuidPairs(SnapshotDto... analyses) {
- return toIdUuidPairs(Arrays.stream(analyses));
- }
-
- private static List<IdUuidPair> toIdUuidPairs(Stream<SnapshotDto> analyses) {
- return analyses
- .map(a -> new IdUuidPair(a.getId(), a.getUuid()))
- .collect(toList());
- }
-
- private List<IdUuidPair> getHugeNumberOfIdUuidPairs() {
- List<IdUuidPair> hugeNbOfSnapshotIds = newArrayList();
+ private List<String> getHugeNumberOfUuids() {
+ List<String> hugeNbOfSnapshotUuids = newArrayList();
for (long i = 0; i < 4500; i++) {
- hugeNbOfSnapshotIds.add(new IdUuidPair(i, "uuid_" + i));
+ hugeNbOfSnapshotUuids.add("uuid_" + i);
}
- return hugeNbOfSnapshotIds;
+ return hugeNbOfSnapshotUuids;
}
@DataProvider
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index c9f3a189682..11e9b3e32eb 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -305,11 +305,11 @@ public class PurgeDaoTest {
ComponentDto otherProject = db.components().insertPrivateProject();
SnapshotDto otherAnalysis1 = db.components().insertSnapshot(otherProject);
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(idUuidPairOf(analysis1)));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(analysis1.getUuid()));
assertThat(uuidsIn("snapshots")).containsOnly(analysis2.getUuid(), analysis3.getUuid(), otherAnalysis1.getUuid());
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(idUuidPairOf(analysis1), idUuidPairOf(analysis3), idUuidPairOf(otherAnalysis1)));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(analysis1.getUuid(), analysis3.getUuid(), otherAnalysis1.getUuid()));
assertThat(uuidsIn("snapshots")).containsOnly(analysis2.getUuid());
}
@@ -336,7 +336,7 @@ public class PurgeDaoTest {
// note: projectEvent3 has no component change
// delete non existing analysis has no effect
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "foo")));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), singletonList( "foo"));
assertThat(uuidsIn("event_component_changes", "event_analysis_uuid"))
.containsOnly(projectAnalysis1.getUuid(), projectAnalysis2.getUuid());
assertThat(db.countRowsOfTable("event_component_changes"))
@@ -344,7 +344,7 @@ public class PurgeDaoTest {
assertThat(uuidsIn("events"))
.containsOnly(projectEvent1.getUuid(), projectEvent2.getUuid(), projectEvent3.getUuid());
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(idUuidPairOf(projectAnalysis1)));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), singletonList(projectAnalysis1.getUuid()));
assertThat(uuidsIn("event_component_changes", "event_analysis_uuid"))
.containsOnly(projectAnalysis2.getUuid());
assertThat(db.countRowsOfTable("event_component_changes"))
@@ -352,7 +352,7 @@ public class PurgeDaoTest {
assertThat(uuidsIn("events"))
.containsOnly(projectEvent2.getUuid(), projectEvent3.getUuid());
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(idUuidPairOf(projectAnalysis4)));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), singletonList(projectAnalysis4.getUuid()));
assertThat(uuidsIn("event_component_changes", "event_analysis_uuid"))
.containsOnly(projectAnalysis2.getUuid());
assertThat(db.countRowsOfTable("event_component_changes"))
@@ -360,7 +360,7 @@ public class PurgeDaoTest {
assertThat(uuidsIn("events"))
.containsOnly(projectEvent2.getUuid(), projectEvent3.getUuid());
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(idUuidPairOf(projectAnalysis3)));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), singletonList(projectAnalysis3.getUuid()));
assertThat(uuidsIn("event_component_changes", "event_analysis_uuid"))
.containsOnly(projectAnalysis2.getUuid());
assertThat(db.countRowsOfTable("event_component_changes"))
@@ -368,7 +368,7 @@ public class PurgeDaoTest {
assertThat(uuidsIn("events"))
.containsOnly(projectEvent2.getUuid());
- underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(idUuidPairOf(projectAnalysis2)));
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), singletonList(projectAnalysis2.getUuid()));
assertThat(db.countRowsOfTable("event_component_changes"))
.isZero();
assertThat(db.countRowsOfTable("events"))
@@ -960,50 +960,6 @@ public class PurgeDaoTest {
}
@Test
- public void deleteProject_fails_with_IAE_if_specified_component_is_module() {
- ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Couldn't find root component with uuid " + module.uuid());
-
- underTest.deleteProject(dbSession, module.uuid());
- }
-
- @Test
- public void deleteProject_fails_with_IAE_if_specified_component_is_directory() {
- ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto directory = db.components().insertComponent(newDirectory(privateProject, "A/B"));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Couldn't find root component with uuid " + directory.uuid());
-
- underTest.deleteProject(dbSession, directory.uuid());
- }
-
- @Test
- public void deleteProject_fails_with_IAE_if_specified_component_is_file() {
- ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(privateProject));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Couldn't find root component with uuid " + file.uuid());
-
- underTest.deleteProject(dbSession, file.uuid());
- }
-
- @Test
- public void deleteProject_fails_with_IAE_if_specified_component_is_subview() {
- ComponentDto view = db.components().insertView();
- ComponentDto subview = db.components().insertComponent(newSubView(view));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Couldn't find root component with uuid " + subview.uuid());
-
- underTest.deleteProject(dbSession, subview.uuid());
- }
-
- @Test
public void should_delete_old_closed_issues() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
@@ -1452,15 +1408,15 @@ public class PurgeDaoTest {
ComponentDto subview3 = db.components().insertComponent(newSubView(view));
ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
insertPropertyFor(view, subview1, subview2, subview3, pc);
- assertThat(getResourceIdOfProperties()).containsOnly(view.getId(), subview1.getId(), subview2.getId(), subview3.getId(), pc.getId());
+ assertThat(getResourceIdOfProperties()).containsOnly(view.uuid(), subview1.uuid(), subview2.uuid(), subview3.uuid(), pc.uuid());
underTest.deleteNonRootComponentsInView(dbSession, singletonList(subview1));
assertThat(getResourceIdOfProperties())
- .containsOnly(view.getId(), subview2.getId(), subview3.getId(), pc.getId());
+ .containsOnly(view.uuid(), subview2.uuid(), subview3.uuid(), pc.uuid());
underTest.deleteNonRootComponentsInView(dbSession, asList(subview2, subview3, pc));
assertThat(getResourceIdOfProperties())
- .containsOnly(view.getId(), pc.getId());
+ .containsOnly(view.uuid(), pc.uuid());
}
@Test
@@ -1579,16 +1535,16 @@ public class PurgeDaoTest {
.map(row -> (String) row.get("COMPONENT_UUID"));
}
- private Stream<Long> getResourceIdOfProperties() {
- return db.select("select resource_id as \"ID\" from properties").stream()
- .map(row -> (Long) row.get("ID"));
+ private Stream<String> getResourceIdOfProperties() {
+ return db.select("select component_uuid as \"uuid\" from properties").stream()
+ .map(row -> (String) row.get("uuid"));
}
private void insertPropertyFor(ComponentDto... components) {
Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto()
.setKey(randomAlphabetic(3))
.setValue(randomAlphabetic(3))
- .setResourceId(componentDto.getId())));
+ .setComponentUuid(componentDto.uuid())));
}
private Stream<String> getComponentUuidsOfMeasures() {
@@ -1714,9 +1670,4 @@ public class PurgeDaoTest {
.stream()
.map(t -> (String) t.get("UUID"));
}
-
- private static IdUuidPair idUuidPairOf(SnapshotDto analysis3) {
- return new IdUuidPair(analysis3.getId(), analysis3.getUuid());
- }
-
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
index 33536a670d1..1b400e5e02f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
@@ -63,7 +63,6 @@ public class PurgeMapperTest {
ComponentDto project = randomPublicOrPrivateProject();
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(project.uuid()))
- .extracting(IdUuidPair::getUuid)
.containsOnly(project.uuid());
}
@@ -75,7 +74,6 @@ public class PurgeMapperTest {
ComponentDto module3 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(project.uuid()))
- .extracting(IdUuidPair::getUuid)
.containsOnly(project.uuid(), module1.uuid(), module2.uuid(), module3.uuid());
}
@@ -88,7 +86,6 @@ public class PurgeMapperTest {
ComponentDto view = db.components().insertView();
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
- .extracting(IdUuidPair::getUuid)
.containsOnly(view.uuid());
}
@@ -97,7 +94,6 @@ public class PurgeMapperTest {
ComponentDto view = db.components().insertPublicApplication(db.getDefaultOrganization());
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
- .extracting(IdUuidPair::getUuid)
.containsOnly(view.uuid());
}
@@ -109,7 +105,6 @@ public class PurgeMapperTest {
ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view));
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
- .extracting(IdUuidPair::getUuid)
.containsOnly(view.uuid(), subview1.uuid(), subview2.uuid(), subview3.uuid());
}
@@ -120,7 +115,6 @@ public class PurgeMapperTest {
db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject));
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
- .extracting(IdUuidPair::getUuid)
.containsOnly(view.uuid());
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java
index c5db793747b..0c18f91229e 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java
@@ -28,7 +28,6 @@ import org.mockito.InOrder;
import org.mockito.Mockito;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
-import org.sonar.db.purge.IdUuidPair;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.purge.PurgeProfiler;
import org.sonar.db.purge.PurgeableAnalysisDto;
@@ -58,9 +57,9 @@ public class DefaultPeriodCleanerTest {
InOrder inOrder = Mockito.inOrder(dao, filter1, filter2);
inOrder.verify(filter1).log();
- inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of(new IdUuidPair(999, "u999"))));
+ inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of("u999")));
inOrder.verify(filter2).log();
- inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of(new IdUuidPair(456, "u456"))));
+ inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of( "u456")));
inOrder.verifyNoMoreInteractions();
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
index 00cfb75a2e2..bf51a18a519 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
@@ -57,11 +57,11 @@ public class ProjectQgateAssociationDaoTest {
.build());
assertThat(result)
- .extracting(ProjectQgateAssociationDto::getId, ProjectQgateAssociationDto::getKey, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId)
+ .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getKey, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId)
.containsExactlyInAnyOrder(
- tuple(project1.getId(), project1.getKey(), project1.name(), qualityGate1.getId().toString()),
- tuple(project2.getId(), project2.getKey(), project2.name(), qualityGate1.getId().toString()),
- tuple(project3.getId(), project3.getKey(), project3.name(), null));
+ tuple(project1.uuid(), project1.getKey(), project1.name(), qualityGate1.getId().toString()),
+ tuple(project2.uuid(), project2.getKey(), project2.name(), qualityGate1.getId().toString()),
+ tuple(project3.uuid(), project3.getKey(), project3.name(), null));
}
@Test
@@ -78,17 +78,17 @@ public class ProjectQgateAssociationDaoTest {
.qualityGate(qualityGate)
.membership(ProjectQgateAssociationQuery.IN)
.build()))
- .extracting(ProjectQgateAssociationDto::getId, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId)
+ .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId)
.containsExactlyInAnyOrder(
- tuple(project1.getId(), project1.name(), qualityGate.getId().toString()),
- tuple(project2.getId(), project2.name(), qualityGate.getId().toString()));
+ tuple(project1.uuid(), project1.name(), qualityGate.getId().toString()),
+ tuple(project2.uuid(), project2.name(), qualityGate.getId().toString()));
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.membership(ProjectQgateAssociationQuery.OUT)
.build()))
- .extracting(ProjectQgateAssociationDto::getId, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId)
- .containsExactlyInAnyOrder(tuple(project3.getId(), project3.name(), null));
+ .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId)
+ .containsExactlyInAnyOrder(tuple(project3.uuid(), project3.name(), null));
}
@Test
@@ -105,15 +105,15 @@ public class ProjectQgateAssociationDaoTest {
.qualityGate(qualityGate)
.projectSearch("one")
.build()))
- .extracting(ProjectQgateAssociationDto::getId)
- .containsExactlyInAnyOrder(project1.getId());
+ .extracting(ProjectQgateAssociationDto::getUuid)
+ .containsExactlyInAnyOrder(project1.uuid());
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.projectSearch("project")
.build()))
- .extracting(ProjectQgateAssociationDto::getId)
- .containsExactlyInAnyOrder(project1.getId(), project2.getId(), project3.getId());
+ .extracting(ProjectQgateAssociationDto::getUuid)
+ .containsExactlyInAnyOrder(project1.uuid(), project2.uuid(), project3.uuid());
}
@Test
@@ -127,8 +127,8 @@ public class ProjectQgateAssociationDaoTest {
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.build()))
- .extracting(ProjectQgateAssociationDto::getId)
- .containsExactly(project1.getId(), project3.getId(), project2.getId());
+ .extracting(ProjectQgateAssociationDto::getUuid)
+ .containsExactly(project1.uuid(), project3.uuid(), project2.uuid());
}
@Test
@@ -147,8 +147,8 @@ public class ProjectQgateAssociationDaoTest {
.build());
assertThat(result)
- .extracting(ProjectQgateAssociationDto::getId)
- .containsExactlyInAnyOrder(project.getId());
+ .extracting(ProjectQgateAssociationDto::getUuid)
+ .containsExactlyInAnyOrder(project.uuid());
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
index 7b257ff29b8..f8cf46c71d8 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
@@ -761,10 +761,10 @@ public class QualityProfileDaoTest {
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, null))
- .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
+ .extracting("projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
- tuple(project1.getId(), project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()),
- tuple(project2.getId(), project2.uuid(), project2.getDbKey(), project2.name(), profile1.getKee()));
+ tuple(project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()),
+ tuple(project2.uuid(), project2.getDbKey(), project2.name(), profile1.getKee()));
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, "ect1")).hasSize(1);
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile3, null)).isEmpty();
@@ -789,10 +789,10 @@ public class QualityProfileDaoTest {
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, null))
- .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
+ .extracting("projectUuid", "projectKey", "projectName", "profileKey")
.containsExactly(
- tuple(project2.getId(), project2.uuid(), project2.getDbKey(), project2.name(), null),
- tuple(project3.getId(), project3.uuid(), project3.getDbKey(), project3.name(), null));
+ tuple(project2.uuid(), project2.getDbKey(), project2.name(), null),
+ tuple(project3.uuid(), project3.getDbKey(), project3.name(), null));
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, "ect2")).hasSize(1);
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile3, null)).hasSize(3);
@@ -817,11 +817,11 @@ public class QualityProfileDaoTest {
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, null))
- .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
+ .extracting("projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
- tuple(project1.getId(), project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()),
- tuple(project2.getId(), project2.uuid(), project2.getDbKey(), project2.name(), null),
- tuple(project3.getId(), project3.uuid(), project3.getDbKey(), project3.name(), null));
+ tuple(project1.uuid(), project1.getDbKey(), project1.name(), profile1.getKee()),
+ tuple(project2.uuid(), project2.getDbKey(), project2.name(), null),
+ tuple(project3.uuid(), project3.getDbKey(), project3.name(), null));
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, "ect2")).hasSize(1);
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile3, null)).hasSize(3);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java
index 8cd93c17f5e..94913bb0c5a 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java
@@ -50,7 +50,7 @@ public class RoleDaoTest {
private ComponentDto project2;
@Before
- public void setUp() throws Exception {
+ public void setUp() {
user1 = db.users().insertUser();
user2 = db.users().insertUser();
project1 = db.components().insertPrivateProject();
@@ -58,22 +58,22 @@ public class RoleDaoTest {
}
@Test
- public void selectComponentIdsByPermissionAndUserId_throws_IAR_if_permission_USER_is_specified() {
+ public void selectComponentUuidsByPermissionAndUserId_throws_IAR_if_permission_USER_is_specified() {
expectUnsupportedUserAndCodeViewerPermission();
- underTest.selectComponentIdsByPermissionAndUserId(dbSession, UserRole.USER, new Random().nextInt(55));
+ underTest.selectComponentUuidsByPermissionAndUserId(dbSession, UserRole.USER, new Random().nextInt(55));
}
@Test
- public void selectComponentIdsByPermissionAndUserId_throws_IAR_if_permission_CODEVIEWER_is_specified() {
+ public void selectComponentUuidsByPermissionAndUserId_throws_IAR_if_permission_CODEVIEWER_is_specified() {
expectUnsupportedUserAndCodeViewerPermission();
- underTest.selectComponentIdsByPermissionAndUserId(dbSession, UserRole.CODEVIEWER, new Random().nextInt(55));
+ underTest.selectComponentUuidsByPermissionAndUserId(dbSession, UserRole.CODEVIEWER, new Random().nextInt(55));
}
private void expectUnsupportedUserAndCodeViewerPermission() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Permissions [user, codeviewer] are not supported by selectComponentIdsByPermissionAndUserId");
+ expectedException.expectMessage("Permissions [user, codeviewer] are not supported by selectComponentUuidsByPermissionAndUserId");
}
@Test
@@ -87,9 +87,9 @@ public class RoleDaoTest {
// project permission on another permission - not returned
db.users().insertProjectPermissionOnUser(user1, UserRole.ISSUE_ADMIN, project1);
- List<Long> projectIds = underTest.selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, user1.getId());
+ List<String> projectUuids = underTest.selectComponentUuidsByPermissionAndUserId(dbSession, UserRole.ADMIN, user1.getId());
- assertThat(projectIds).containsExactly(project1.getId(), project2.getId());
+ assertThat(projectUuids).containsExactly(project1.uuid(), project2.uuid());
}
@Test
@@ -108,9 +108,9 @@ public class RoleDaoTest {
// project permission on another permission - not returned
db.users().insertProjectPermissionOnGroup(group1, UserRole.ISSUE_ADMIN, project1);
- List<Long> result = underTest.selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, user1.getId());
+ List<String> result = underTest.selectComponentUuidsByPermissionAndUserId(dbSession, UserRole.ADMIN, user1.getId());
- assertThat(result).containsExactly(project1.getId(), project2.getId());
+ assertThat(result).containsExactly(project1.uuid(), project2.uuid());
}
@Test
@@ -130,9 +130,9 @@ public class RoleDaoTest {
db.getSession().commit();
assertThat(db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group1.getId())).isEmpty();
- assertThat(db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group1.getId(), project.getId())).isEmpty();
+ assertThat(db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group1.getId(), project.uuid())).isEmpty();
assertThat(db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group2.getId())).containsOnly("gateadmin");
- assertThat(db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group2.getId(), project.getId())).containsOnly("admin");
+ assertThat(db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group2.getId(), project.uuid())).containsOnly("admin");
assertThat(db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), null)).containsOnly("scan", "provisioning");
}
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
index bb57f615b1b..6b01d6772f0 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
@@ -28,9 +28,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentDto.BRANCH_KEY_SEPARATOR;
import static org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR;
@@ -156,7 +154,6 @@ public class ComponentTesting {
private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
return new ComponentDto()
- .setId(nextLong())
.setOrganizationUuid(organizationUuid)
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
@@ -208,7 +205,6 @@ public class ComponentTesting {
}
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) {
- checkNotNull(project.getId(), "The project need to be persisted before creating this technical project.");
return newChildComponent(uuid, view, view)
.setDbKey(view.getDbKey() + project.getDbKey())
.setName(project.name())
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
index 6e283061361..9b4427dd171 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
@@ -42,14 +42,14 @@ public class FavoriteDbTester {
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
.setKey(PROP_FAVORITE_KEY)
.setUserId(userId)
- .setResourceId(componentDto.getId()));
+ .setComponentUuid(componentDto.uuid()));
dbSession.commit();
}
public boolean hasFavorite(ComponentDto componentDto, int userId) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(PROP_FAVORITE_KEY)
- .setComponentId(componentDto.getId())
+ .setComponentUuid(componentDto.uuid())
.setUserId(userId)
.build(), dbSession);
@@ -59,7 +59,7 @@ public class FavoriteDbTester {
public boolean hasNoFavorite(ComponentDto componentDto) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(PROP_FAVORITE_KEY)
- .setComponentId(componentDto.getId())
+ .setComponentUuid(componentDto.uuid())
.build(), dbSession);
return result.isEmpty();
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
index 2a51d4661cc..ecbefb5588b 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
@@ -45,10 +45,10 @@ public class NotificationDbTester {
public void assertExists(String channel, String dispatcher, int userId, @Nullable ComponentDto component) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
- .setComponentId(component == null ? null : component.getId())
+ .setComponentUuid(component == null ? null : component.uuid())
.setUserId(userId)
.build(), dbSession).stream()
- .filter(prop -> component == null ? prop.getResourceId() == null : prop.getResourceId() != null)
+ .filter(prop -> component == null ? prop.getComponentUuid() == null : prop.getComponentUuid() != null)
.collect(MoreCollectors.toList());
assertThat(result).hasSize(1);
assertThat(result.get(0).getValue()).isEqualTo("true");
@@ -57,7 +57,7 @@ public class NotificationDbTester {
public void assertDoesNotExist(String channel, String dispatcher, int userId, @Nullable ComponentDto component) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
- .setComponentId(component == null ? null : component.getId())
+ .setComponentUuid(component == null ? null : component.uuid())
.setUserId(userId)
.build(), dbSession);
assertThat(result).isEmpty();
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java
index 192c5daee64..47a7488bcdf 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java
@@ -35,21 +35,21 @@ public class PropertyTesting {
}
public static PropertyDto newGlobalPropertyDto(String key, String value) {
- return newPropertyDto(key, value, (Long) null, null);
+ return newPropertyDto(key, value, (String) null, null);
}
public static PropertyDto newGlobalPropertyDto() {
- return newPropertyDto((Long) null, null);
+ return newPropertyDto((String) null, null);
}
public static PropertyDto newComponentPropertyDto(String key, String value, ComponentDto component) {
- checkNotNull(component.getId());
- return newPropertyDto(key, value, component.getId(), null);
+ checkNotNull(component.uuid());
+ return newPropertyDto(key, value, component.uuid(), null);
}
public static PropertyDto newComponentPropertyDto(ComponentDto component) {
- checkNotNull(component.getId());
- return newPropertyDto(component.getId(), null);
+ checkNotNull(component.uuid());
+ return newPropertyDto(component.uuid(), null);
}
public static PropertyDto newUserPropertyDto(String key, String value, UserDto user) {
@@ -63,31 +63,31 @@ public class PropertyTesting {
}
public static PropertyDto newPropertyDto(String key, String value, ComponentDto component, UserDto user) {
- checkNotNull(component.getId());
+ checkNotNull(component.uuid());
checkNotNull(user.getId());
- return newPropertyDto(key, value, component.getId(), user.getId());
+ return newPropertyDto(key, value, component.uuid(), user.getId());
}
public static PropertyDto newPropertyDto(ComponentDto component, UserDto user) {
- checkNotNull(component.getId());
+ checkNotNull(component.uuid());
checkNotNull(user.getId());
- return newPropertyDto(component.getId(), user.getId());
+ return newPropertyDto(component.uuid(), user.getId());
}
- private static PropertyDto newPropertyDto(@Nullable Long componentId, @Nullable Integer userId) {
+ private static PropertyDto newPropertyDto(@Nullable String componentUuid, @Nullable Integer userId) {
String key = String.valueOf(cursor);
cursor++;
String value = String.valueOf(cursor);
cursor++;
- return newPropertyDto(key, value, componentId, userId);
+ return newPropertyDto(key, value, componentUuid, userId);
}
- private static PropertyDto newPropertyDto(String key, String value, @Nullable Long componentId, @Nullable Integer userId) {
+ private static PropertyDto newPropertyDto(String key, String value, @Nullable String componentUuid, @Nullable Integer userId) {
PropertyDto propertyDto = new PropertyDto()
.setKey(key)
.setValue(value);
- if (componentId != null) {
- propertyDto.setResourceId(componentId);
+ if (componentUuid != null) {
+ propertyDto.setComponentUuid(componentUuid);
}
if (userId != null) {
propertyDto.setUserId(userId);
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
index 98ff4bb4454..826d7d9c073 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
@@ -36,7 +36,6 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.GroupPermissionDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.permission.UserPermissionDto;
-import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
@@ -263,14 +262,14 @@ public class UserDbTester {
.setOrganizationUuid(project.getOrganizationUuid())
.setGroupId(null)
.setRole(permission)
- .setResourceId(project.getId());
+ .setComponentUuid(project.uuid());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
return dto;
}
public void deleteProjectPermissionFromAnyone(ComponentDto project, String permission) {
- db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, project.getOrganizationUuid(), null, project.getId());
+ db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, project.getOrganizationUuid(), null, project.uuid());
db.commit();
}
@@ -283,7 +282,7 @@ public class UserDbTester {
.setOrganizationUuid(group.getOrganizationUuid())
.setGroupId(group.getId())
.setRole(permission)
- .setResourceId(project.getId());
+ .setComponentUuid(project.uuid());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
return dto;
@@ -295,7 +294,7 @@ public class UserDbTester {
group.getOrganizationUuid(), group.getId());
}
return db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(),
- group.getOrganizationUuid(), group.getId(), project.getId());
+ group.getOrganizationUuid(), group.getId(), project.uuid());
}
public List<String> selectAnyonePermissions(OrganizationDto org, @Nullable ComponentDto project) {
@@ -304,7 +303,7 @@ public class UserDbTester {
org.getUuid(), null);
}
checkArgument(org.getUuid().equals(project.getOrganizationUuid()), "Different organizations");
- return db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), org.getUuid(), null, project.getId());
+ return db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), org.getUuid(), null, project.uuid());
}
// USER PERMISSIONS
@@ -341,7 +340,7 @@ public class UserDbTester {
}
public void deletePermissionFromUser(ComponentDto project, UserDto user, String permission) {
- db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getId(), permission, project.getId());
+ db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getId(), permission, project.uuid());
db.commit();
}
@@ -352,7 +351,7 @@ public class UserDbTester {
checkArgument(project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
"%s can't be granted on a public project", permission);
checkArgument(project.getMainBranchProjectUuid() == null, "Permissions can't be granted on branches");
- UserPermissionDto dto = new UserPermissionDto(project.getOrganizationUuid(), permission, user.getId(), project.getId());
+ UserPermissionDto dto = new UserPermissionDto(project.getOrganizationUuid(), permission, user.getId(), project.uuid());
db.getDbClient().userPermissionDao().insert(db.getSession(), dto);
db.commit();
return dto;
@@ -364,7 +363,7 @@ public class UserDbTester {
}
public List<String> selectProjectPermissionsOfUser(UserDto user, ComponentDto project) {
- return db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.getId());
+ return db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.uuid());
}
private static List<OrganizationPermission> toListOfOrganizationPermissions(List<String> keys) {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java
new file mode 100644
index 00000000000..f61fc97eb7d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.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.sql;
+
+import java.util.List;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static java.util.Collections.singletonList;
+import static org.sonar.server.platform.db.migration.def.Validations.validateIndexName;
+import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
+
+public class DropConstraintBuilder {
+
+ private final Dialect dialect;
+ private String tableName;
+ private String constraintName;
+
+ public DropConstraintBuilder(Dialect dialect) {
+ this.dialect = dialect;
+ }
+
+ public DropConstraintBuilder setTable(String s) {
+ this.tableName = s;
+ return this;
+ }
+
+ public DropConstraintBuilder setName(String s) {
+ this.constraintName = s;
+ return this;
+ }
+
+ public List<String> build() {
+ validateTableName(tableName);
+ validateIndexName(constraintName);
+ return singletonList(createSqlStatement());
+ }
+
+ private String createSqlStatement() {
+ switch (dialect.getId()) {
+ case MsSql.ID:
+ case Oracle.ID:
+ case PostgreSql.ID:
+ case H2.ID:
+ return "ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName;
+ default:
+ throw new IllegalStateException("Unsupported dialect for drop of constraint: " + dialect);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRoles.java
new file mode 100644
index 00000000000..34c6149f56c
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRoles.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+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.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddComponentUuidColumnToGroupRoles extends DdlChange {
+ private static final String TABLE = "group_roles";
+ private static final String NEW_COLUMN = "component_uuid";
+ private static final String INDEX1 = "group_roles_component_uuid";
+ private static final String INDEX2 = "group_roles_uniq";
+
+ public AddComponentUuidColumnToGroupRoles(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ VarcharColumnDef column = newVarcharColumnDefBuilder()
+ .setColumnName(NEW_COLUMN)
+ .setLimit(50)
+ .setIsNullable(true)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(column)
+ .build());
+
+ CreateIndexBuilder index1 = new CreateIndexBuilder()
+ .setTable(TABLE)
+ .addColumn(column)
+ .setName(INDEX1)
+ .setUnique(false);
+ context.execute(index1.build());
+
+
+ CreateIndexBuilder index2 = new CreateIndexBuilder()
+ .setTable(TABLE)
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("organization_uuid").setLimit(40).build())
+ .addColumn(newIntegerColumnDefBuilder().setColumnName("group_id").build())
+ .addColumn(column)
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("role").setLimit(64).build())
+ .setName(INDEX2)
+ .setUnique(true);
+ context.execute(index2.build());
+
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToProperties.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToProperties.java
new file mode 100644
index 00000000000..f5e49190ea9
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToProperties.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+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.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddComponentUuidColumnToProperties extends DdlChange {
+ private static final String TABLE = "properties";
+ private static final String NEW_COLUMN = "component_uuid";
+ private static final String INDEX = "properties_component_uuid";
+
+ public AddComponentUuidColumnToProperties(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ VarcharColumnDef column = newVarcharColumnDefBuilder()
+ .setColumnName(NEW_COLUMN)
+ .setLimit(50)
+ .setIsNullable(true)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(column)
+ .build());
+
+ CreateIndexBuilder builder = new CreateIndexBuilder()
+ .setTable(TABLE)
+ .addColumn(column)
+ .setName(INDEX)
+ .setUnique(false);
+
+ context.execute(builder.build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRoles.java
new file mode 100644
index 00000000000..5ce5dcf8869
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRoles.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;
+
+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.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddComponentUuidColumnToUserRoles extends DdlChange {
+ private static final String TABLE = "user_roles";
+ private static final String NEW_COLUMN = "component_uuid";
+ private static final String INDEX = "user_roles_component_uuid";
+
+ public AddComponentUuidColumnToUserRoles(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ VarcharColumnDef column = newVarcharColumnDefBuilder()
+ .setColumnName(NEW_COLUMN)
+ .setLimit(50)
+ .setIsNullable(true)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(column)
+ .build());
+
+ CreateIndexBuilder index1 = new CreateIndexBuilder()
+ .setTable(TABLE)
+ .addColumn(column)
+ .setName(INDEX)
+ .setUnique(false);
+ context.execute(index1.build());
+ }
+}
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 63845bbbd6b..4f105cf4c8f 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
@@ -27,6 +27,18 @@ public class DbVersion83 implements DbVersion {
public void addSteps(MigrationStepRegistry registry) {
registry
.add(3300, "Add 'summary_comment_enabled' boolean column to 'project_alm_settings'", AddSummaryEnabledColumnToAlmSettings.class)
- .add(3301, "Enable 'summary_comment_enabled' for GitHub based projects", PopulateSummaryCommentEnabledColumnForGitHub.class);
+ .add(3301, "Enable 'summary_comment_enabled' for GitHub based projects", PopulateSummaryCommentEnabledColumnForGitHub.class)
+ .add(3302, "Add 'component_uuid' column to 'properties'", AddComponentUuidColumnToProperties.class)
+ .add(3303, "Migrate 'resource_id' to 'component_uuid' in 'properties'", MigrateResourceIdToUuidInProperties.class)
+ .add(3304, "Remove column 'resource_id' in 'properties'", DropResourceIdFromPropertiesTable.class)
+ .add(3305, "Add 'component_uuid' column to 'group_roles'", AddComponentUuidColumnToGroupRoles.class)
+ .add(3306, "Migrate 'resource_id' to 'component_uuid' in 'group_roles'", MigrateResourceIdToUuidInGroupRoles.class)
+ .add(3307, "Remove column 'resource_id' in 'group_roles'", DropResourceIdFromGroupRolesTable.class)
+ .add(3308, "Add 'component_uuid' column to 'user_roles'", AddComponentUuidColumnToUserRoles.class)
+ .add(3309, "Migrate 'resource_id' to 'component_uuid' in 'user_roles'", MigrateResourceIdToUuidInUserRoles.class)
+ .add(3310, "Remove column 'resource_id' in 'user_roles'", DropResourceIdFromUserRolesTable.class)
+ .add(3311, "Remove column 'id' in 'components'", DropIdFromComponentsTable.class)
+
+ ;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTable.java
new file mode 100644
index 00000000000..ba2b778307d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTable.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;
+
+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.sql.DropConstraintBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIdFromComponentsTable extends DdlChange {
+
+ static final String TABLE_NAME = "components";
+ static final String INDEX_NAME = "pk_projects";
+ static final String COLUMN_NAME = "id";
+
+ public DropIdFromComponentsTable(Database db) {
+ super(db);
+ }
+ @Override
+ public void execute(Context context) throws SQLException {
+
+ context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName(INDEX_NAME).build());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, COLUMN_NAME).build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTable.java
new file mode 100644
index 00000000000..3eb61568d48
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTable.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;
+
+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.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropResourceIdFromGroupRolesTable extends DdlChange {
+
+ static final String TABLE = "group_roles";
+ static final String COLUMN = "resource_id";
+
+ public DropResourceIdFromGroupRolesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE).setName("uniq_group_roles").build());
+ context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE).setName("group_roles_resource").build());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE, COLUMN).build());
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPairs.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTable.java
index 66ec298bc10..41b543cbdbd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/IdUuidPairs.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTable.java
@@ -17,23 +17,24 @@
* 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.db.purge;
+package org.sonar.server.platform.db.migration.version.v83;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
+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;
-class IdUuidPairs {
- private IdUuidPairs() {
- // prevents instantiation
- }
+public class DropResourceIdFromPropertiesTable extends DdlChange {
- public static List<Long> ids(List<IdUuidPair> pairs) {
- return pairs.stream().map(IdUuidPair::getId).collect(Collectors.toCollection(() -> new ArrayList<>(pairs.size())));
- }
+ static final String TABLE = "properties";
+ static final String COLUMN = "resource_id";
- public static List<String> uuids(List<IdUuidPair> pairs) {
- return pairs.stream().map(IdUuidPair::getUuid).collect(Collectors.toCollection(() -> new ArrayList<>(pairs.size())));
+ public DropResourceIdFromPropertiesTable(Database db) {
+ super(db);
}
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE, COLUMN).build());
+ }
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTable.java
index ef21caa54d1..75e3cd56da0 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DbIdsRepositoryImpl.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTable.java
@@ -17,25 +17,26 @@
* 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.ce.task.projectanalysis.component;
+package org.sonar.server.platform.db.migration.version.v83;
-import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toComponentUuid;
+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.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
-/**
- * Cache of persisted component (component id and snapshot id) that can be used in the persistence steps
- */
-public class DbIdsRepositoryImpl implements MutableDbIdsRepository {
+public class DropResourceIdFromUserRolesTable extends DdlChange {
- private final MapBasedDbIdsRepository<String> delegate = new MapBasedDbIdsRepository<>(toComponentUuid());
+ static final String TABLE = "user_roles";
+ static final String COLUMN = "resource_id";
- @Override
- public DbIdsRepository setComponentId(Component component, long componentId) {
- return delegate.setComponentId(component, componentId);
+ public DropResourceIdFromUserRolesTable(Database db) {
+ super(db);
}
@Override
- public long getComponentId(Component component) {
- return delegate.getComponentId(component);
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE).setName("user_roles_resource").build());
+ context.execute(new DropColumnsBuilder(getDialect(), TABLE, COLUMN).build());
}
-
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRoles.java
new file mode 100644
index 00000000000..58176d127af
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRoles.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+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 MigrateResourceIdToUuidInGroupRoles extends DataChange {
+ public MigrateResourceIdToUuidInGroupRoles(Database db) {
+ super(db);
+ }
+
+ @Override protected void execute(Context context) throws SQLException {
+ // remove roles associated with invalid resource
+ context.prepareUpsert(
+ "delete from group_roles gp where gp.resource_id is not null "
+ + "and not exists (select 1 from components c where gp.resource_id = c.id)")
+ .execute();
+
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("select gp.id as gp_id, c.uuid as c_uuid from group_roles gp left join components c on gp.resource_id = c.id");
+ massUpdate.update("update group_roles set component_uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ String componentUuid = row.getString(2);
+ if (componentUuid != null) {
+ Long propertyId = row.getLong(1);
+
+ update.setString(1, componentUuid)
+ .setLong(2, propertyId);
+ return true;
+ }
+ return false;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInProperties.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInProperties.java
new file mode 100644
index 00000000000..014a1a3454b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInProperties.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;
+
+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 MigrateResourceIdToUuidInProperties extends DataChange {
+ public MigrateResourceIdToUuidInProperties(Database db) {
+ super(db);
+ }
+
+ @Override protected void execute(Context context) throws SQLException {
+ // remove properties associated with invalid resource
+ context.prepareUpsert(
+ "delete from properties p where p.resource_id is not null "
+ + "and not exists (select 1 from components c where p.resource_id = c.id)")
+ .execute();
+
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select p.id as p_id, c.uuid as c_uuid from properties p left join components c on p.resource_id = c.id");
+ massUpdate.update("update properties set component_uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ String componentUuid = row.getString(2);
+ if (componentUuid != null) {
+ Long propertyId = row.getLong(1);
+
+ update.setString(1, componentUuid)
+ .setLong(2, propertyId);
+ return true;
+ }
+ return false;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRoles.java
new file mode 100644
index 00000000000..71e3daa1b6d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRoles.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;
+
+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 MigrateResourceIdToUuidInUserRoles extends DataChange {
+ public MigrateResourceIdToUuidInUserRoles(Database db) {
+ super(db);
+ }
+
+ @Override protected void execute(Context context) throws SQLException {
+ // remove roles associated with invalid resource
+ context.prepareUpsert(
+ "delete from user_roles ur where ur.resource_id is not null "
+ + "and not exists (select 1 from components c where ur.resource_id = c.id)")
+ .execute();
+
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select ur.id as ur_id, c.uuid as c_uuid from user_roles ur left join components c on ur.resource_id = c.id");
+ massUpdate.update("update user_roles set component_uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ String componentUuid = row.getString(2);
+ if (componentUuid != null) {
+ Long id = row.getLong(1);
+
+ update.setString(1, componentUuid)
+ .setLong(2, id);
+ return true;
+ }
+ return false;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest.java
new file mode 100644
index 00000000000..c010ad2a3eb
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest.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;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class AddComponentUuidColumnToGroupRolesTest {
+ private static final String TABLE_NAME = "group_roles";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(AddComponentUuidColumnToGroupRolesTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private AddComponentUuidColumnToGroupRoles underTest = new AddComponentUuidColumnToGroupRoles(dbTester.database());
+
+ @Test
+ public void column_has_been_created() throws SQLException {
+ underTest.execute();
+ dbTester.assertTableExists(TABLE_NAME);
+ dbTester.assertColumnDefinition(TABLE_NAME, "component_uuid", VARCHAR, 50, true);
+ dbTester.assertUniqueIndex(TABLE_NAME, "group_roles_uniq", "organization_uuid", "group_id", "component_uuid", "role");
+ dbTester.assertIndex(TABLE_NAME, "group_roles_component_uuid", "component_uuid");
+ }
+
+}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/IdUuidPairsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest.java
index b23e5cbf6ad..e6924ea4073 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/IdUuidPairsTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest.java
@@ -17,36 +17,31 @@
* 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.db.purge;
+package org.sonar.server.platform.db.migration.version.v83;
-import com.google.common.collect.Lists;
-import java.util.List;
+import java.sql.SQLException;
+import org.junit.Rule;
import org.junit.Test;
-import org.sonar.test.TestUtils;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
-import static org.assertj.core.api.Assertions.assertThat;
+import static java.sql.Types.VARCHAR;
-public class IdUuidPairsTest {
- @Test
- public void extract_ids() {
- List<IdUuidPair> idUuidPairList = Lists.newArrayList(new IdUuidPair(1L, "ABCD"), new IdUuidPair(2L, "EFGH"));
+public class AddComponentUuidColumnToPropertiesTest {
+ private static final String TABLE_NAME = "properties";
- List<Long> ids = IdUuidPairs.ids(idUuidPairList);
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(AddComponentUuidColumnToPropertiesTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
- assertThat(ids).containsOnly(1L, 2L);
- }
+ private AddComponentUuidColumnToProperties underTest = new AddComponentUuidColumnToProperties(dbTester.database());
@Test
- public void is_non_instantiable() {
- assertThat(TestUtils.hasOnlyPrivateConstructors(IdUuidPairs.class)).isTrue();
+ public void column_has_been_created() throws SQLException {
+ underTest.execute();
+ dbTester.assertTableExists(TABLE_NAME);
+ dbTester.assertColumnDefinition(TABLE_NAME, "component_uuid", VARCHAR, 50, true);
}
- @Test
- public void extract_uuids() {
- List<IdUuidPair> idUuidPairList = Lists.newArrayList(new IdUuidPair(1L, "ABCD"), new IdUuidPair(2L, "EFGH"));
-
- List<String> uuids = IdUuidPairs.uuids(idUuidPairList);
-
- assertThat(uuids).containsOnly("ABCD", "EFGH");
- }
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest.java
new file mode 100644
index 00000000000..824c60e8512
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class AddComponentUuidColumnToUserRolesTest {
+ private static final String TABLE_NAME = "user_roles";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(AddComponentUuidColumnToUserRolesTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private AddComponentUuidColumnToUserRoles underTest = new AddComponentUuidColumnToUserRoles(dbTester.database());
+
+ @Test
+ public void column_has_been_created() throws SQLException {
+ underTest.execute();
+ dbTester.assertTableExists(TABLE_NAME);
+ dbTester.assertColumnDefinition(TABLE_NAME, "component_uuid", VARCHAR, 50, true);
+ dbTester.assertIndex(TABLE_NAME, "user_roles_component_uuid", "component_uuid");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
index 54f2350e6a1..ad946da34cc 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
@@ -36,7 +36,7 @@ public class DbVersion83Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 2);
+ verifyMigrationCount(underTest, 12);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest.java
new file mode 100644
index 00000000000..f4e7c49f8d0
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest.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;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.INTEGER;
+import static org.sonar.server.platform.db.migration.version.v83.DropIdFromComponentsTable.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v83.DropIdFromComponentsTable.INDEX_NAME;
+import static org.sonar.server.platform.db.migration.version.v83.DropIdFromComponentsTable.TABLE_NAME;
+
+public class DropIdFromComponentsTableTest {
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(DropIdFromComponentsTableTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DropIdFromComponentsTable underTest = new DropIdFromComponentsTable(dbTester.database());
+
+ @Test
+ public void column_has_been_dropped() throws SQLException {
+ dbTester.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, INTEGER, null, false);
+ underTest.execute();
+ dbTester.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ dbTester.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest.java
new file mode 100644
index 00000000000..056466792c5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest.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;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.INTEGER;
+
+public class DropResourceIdFromGroupRolesTableTest {
+ private static final String TABLE_NAME = "group_roles";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(DropResourceIdFromGroupRolesTableTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DropResourceIdFromGroupRolesTable underTest = new DropResourceIdFromGroupRolesTable(dbTester.database());
+
+ @Test
+ public void column_has_been_dropped() throws SQLException {
+ dbTester.assertColumnDefinition(TABLE_NAME, "resource_id", INTEGER, null, true);
+ dbTester.assertUniqueIndex(TABLE_NAME, "UNIQ_GROUP_ROLES", "organization_uuid", "group_id", "resource_id", "role");
+ dbTester.assertIndex(TABLE_NAME, "GROUP_ROLES_RESOURCE", "resource_id");
+
+ underTest.execute();
+ dbTester.assertColumnDoesNotExist(TABLE_NAME, "resource_id");
+ dbTester.assertIndexDoesNotExist(TABLE_NAME, "UNIQ_GROUP_ROLES");
+ dbTester.assertIndexDoesNotExist(TABLE_NAME, "GROUP_ROLES_RESOURCE");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest.java
new file mode 100644
index 00000000000..6b62541d795
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.BIGINT;
+
+public class DropResourceIdFromPropertiesTableTest {
+ private static final String TABLE_NAME = "properties";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(DropResourceIdFromPropertiesTableTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DropResourceIdFromPropertiesTable underTest = new DropResourceIdFromPropertiesTable(dbTester.database());
+
+ @Test
+ public void column_has_been_dropped() throws SQLException {
+ dbTester.assertColumnDefinition(TABLE_NAME, "resource_id", BIGINT, null, true);
+ underTest.execute();
+ dbTester.assertColumnDoesNotExist(TABLE_NAME, "resource_id");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest.java
new file mode 100644
index 00000000000..f8d126d1f13
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest.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;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.INTEGER;
+
+public class DropResourceIdFromUserRolesTableTest {
+ private static final String TABLE_NAME = "user_roles";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(DropResourceIdFromUserRolesTableTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DropResourceIdFromUserRolesTable underTest = new DropResourceIdFromUserRolesTable(dbTester.database());
+
+ @Test
+ public void column_has_been_dropped() throws SQLException {
+ dbTester.assertColumnDefinition(TABLE_NAME, "resource_id", INTEGER, null, true);
+ dbTester.assertIndex(TABLE_NAME, "user_roles_resource", "resource_id");
+
+ underTest.execute();
+ dbTester.assertColumnDoesNotExist(TABLE_NAME, "resource_id");
+ dbTester.assertIndexDoesNotExist(TABLE_NAME, "user_roles_resource");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest.java
new file mode 100644
index 00000000000..0b5aca0ca23
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest.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;
+
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MigrateResourceIdToUuidInGroupRolesTest {
+ private static final String TABLE_NAME = "group_roles";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(MigrateResourceIdToUuidInGroupRolesTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MigrateResourceIdToUuidInGroupRoles underTest = new MigrateResourceIdToUuidInGroupRoles(dbTester.database());
+ private int id = 1;
+
+ @Test
+ public void data_has_been_migrated() throws SQLException {
+ insertComponent(1, "uuid1");
+ insertRole(1);
+ insertRole(2);
+ insertRole(null);
+
+ underTest.execute();
+ assertThat(dbTester.select("select ID, RESOURCE_ID, COMPONENT_UUID, GROUP_ID from " + TABLE_NAME).stream()
+ .map(e -> new Tuple(e.get("ID"), e.get("RESOURCE_ID"), e.get("COMPONENT_UUID"), e.get("GROUP_ID")))
+ .collect(Collectors.toList())).containsExactlyInAnyOrder(
+ new Tuple(1L, 1L, "uuid1", 1L),
+ new Tuple(3L, null, null, 1L));
+ }
+
+ private void insertRole(@Nullable Integer resourceId) {
+ dbTester.executeInsert(TABLE_NAME,
+ "id", id++,
+ "organization_uuid", "org",
+ "group_id", 1,
+ "resource_id", resourceId,
+ "role", "role");
+ }
+
+ private void insertComponent(int id, String uuid) {
+ dbTester.executeInsert("COMPONENTS",
+ "ID", id,
+ "NAME", uuid + "-name",
+ "DESCRIPTION", uuid + "-description",
+ "ORGANIZATION_UUID", "default",
+ "CREATED_AT", new Date(1000L),
+ "KEE", uuid + "-key",
+ "UUID", uuid,
+ "PROJECT_UUID", uuid,
+ "MAIN_BRANCH_PROJECT_UUID", "project_uuid",
+ "UUID_PATH", ".",
+ "ROOT_UUID", uuid,
+ "PRIVATE", Boolean.toString(false),
+ "SCOPE", "TRK",
+ "QUALIFIER", "PRJ");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest.java
new file mode 100644
index 00000000000..221f14ad5ca
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MigrateResourceIdToUuidInPropertiesTest {
+ private static final String TABLE_NAME = "properties";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(MigrateResourceIdToUuidInPropertiesTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MigrateResourceIdToUuidInProperties underTest = new MigrateResourceIdToUuidInProperties(dbTester.database());
+ private int id = 1;
+
+ @Test
+ public void data_has_been_migrated() throws SQLException {
+ insertComponent(1, "uuid1");
+ insertProperty(1);
+ insertProperty(2);
+ insertProperty(null);
+
+ underTest.execute();
+ assertThat(dbTester.select("select ID, RESOURCE_ID, COMPONENT_UUID, PROP_KEY, TEXT_VALUE from " + TABLE_NAME).stream()
+ .map(e -> new Tuple(e.get("ID"), e.get("RESOURCE_ID"), e.get("COMPONENT_UUID"), e.get("PROP_KEY"), e.get("TEXT_VALUE")))
+ .collect(Collectors.toList())).containsExactlyInAnyOrder(
+ new Tuple(1L, 1L, "uuid1", "key", "value"),
+ new Tuple(3L, null, null, "key", "value"));
+
+ }
+
+ private void insertProperty(@Nullable Integer resourceId) {
+ dbTester.executeInsert(TABLE_NAME,
+ "id", id++,
+ "prop_key", "key",
+ "resource_id", resourceId,
+ "is_empty", false,
+ "text_value", "value",
+ "created_at", 1000L);
+ }
+
+ private void insertComponent(int id, String uuid) {
+ dbTester.executeInsert("COMPONENTS",
+ "ID", id,
+ "NAME", uuid + "-name",
+ "DESCRIPTION", uuid + "-description",
+ "ORGANIZATION_UUID", "default",
+ "CREATED_AT", new Date(1000L),
+ "KEE", uuid + "-key",
+ "UUID", uuid,
+ "PROJECT_UUID", uuid,
+ "MAIN_BRANCH_PROJECT_UUID", "project_uuid",
+ "UUID_PATH", ".",
+ "ROOT_UUID", uuid,
+ "PRIVATE", Boolean.toString(false),
+ "SCOPE", "TRK",
+ "QUALIFIER", "PRJ");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest.java
new file mode 100644
index 00000000000..9ce948ac4ab
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest.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;
+
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MigrateResourceIdToUuidInUserRolesTest {
+ private static final String TABLE_NAME = "user_roles";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(MigrateResourceIdToUuidInUserRolesTest.class, "schema.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private MigrateResourceIdToUuidInUserRoles underTest = new MigrateResourceIdToUuidInUserRoles(dbTester.database());
+ private int id = 1;
+
+ @Test
+ public void data_has_been_migrated() throws SQLException {
+ insertComponent(1, "uuid1");
+ insertRole(1);
+ insertRole(2);
+ insertRole(null);
+
+ underTest.execute();
+ assertThat(dbTester.select("select ID, RESOURCE_ID, COMPONENT_UUID, USER_ID from " + TABLE_NAME).stream()
+ .map(e -> new Tuple(e.get("ID"), e.get("RESOURCE_ID"), e.get("COMPONENT_UUID"), e.get("USER_ID")))
+ .collect(Collectors.toList())).containsExactlyInAnyOrder(
+ new Tuple(1L, 1L, "uuid1", 1L),
+ new Tuple(3L, null, null, 1L));
+ }
+
+ private void insertRole(@Nullable Integer resourceId) {
+ dbTester.executeInsert(TABLE_NAME,
+ "id", id++,
+ "organization_uuid", "org",
+ "user_id", 1,
+ "resource_id", resourceId,
+ "role", "role");
+ }
+
+ private void insertComponent(int id, String uuid) {
+ dbTester.executeInsert("COMPONENTS",
+ "ID", id,
+ "NAME", uuid + "-name",
+ "DESCRIPTION", uuid + "-description",
+ "ORGANIZATION_UUID", "default",
+ "CREATED_AT", new Date(1000L),
+ "KEE", uuid + "-key",
+ "UUID", uuid,
+ "PROJECT_UUID", uuid,
+ "MAIN_BRANCH_PROJECT_UUID", "project_uuid",
+ "UUID_PATH", ".",
+ "ROOT_UUID", uuid,
+ "PRIVATE", Boolean.toString(false),
+ "SCOPE", "TRK",
+ "QUALIFIER", "PRJ");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql
new file mode 100644
index 00000000000..9373e3f73fc
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql
@@ -0,0 +1,10 @@
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql
new file mode 100644
index 00000000000..2ac16011ffb
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql
@@ -0,0 +1,12 @@
+CREATE TABLE "PROPERTIES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" BIGINT,
+ "USER_ID" BIGINT,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql
new file mode 100644
index 00000000000..b4879f33cab
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql
@@ -0,0 +1,10 @@
+CREATE TABLE "USER_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest/schema.sql
new file mode 100644
index 00000000000..58865e22e82
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest/schema.sql
@@ -0,0 +1,44 @@
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql
new file mode 100644
index 00000000000..c47efe12b36
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql
@@ -0,0 +1,13 @@
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql
new file mode 100644
index 00000000000..d6d9a54731d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql
@@ -0,0 +1,14 @@
+CREATE TABLE "PROPERTIES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" BIGINT,
+ "USER_ID" BIGINT,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+CREATE INDEX "PROPERTIES_COMPONENT_UUID" ON "PROPERTIES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql
new file mode 100644
index 00000000000..62e4238b217
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql
@@ -0,0 +1,12 @@
+CREATE TABLE "USER_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql
new file mode 100644
index 00000000000..04d3cb4b33b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql
@@ -0,0 +1,58 @@
+CREATE TABLE "GROUP_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "GROUP_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql
new file mode 100644
index 00000000000..ad5844e1bc9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql
@@ -0,0 +1,59 @@
+CREATE TABLE "PROPERTIES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "COMPONENT_UUID" VARCHAR(50),
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "RESOURCE_ID" BIGINT,
+ "USER_ID" BIGINT,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "CLOB_VALUE" CLOB(2147483647),
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+CREATE INDEX "PROPERTIES_COMPONENT_UUID" ON "PROPERTIES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql
new file mode 100644
index 00000000000..fb91fd36c54
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql
@@ -0,0 +1,57 @@
+CREATE TABLE "USER_ROLES"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50),
+ "USER_ID" INTEGER,
+ "RESOURCE_ID" INTEGER,
+ "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(50) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "NAME" VARCHAR(2000),
+ "LONG_NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "PATH" VARCHAR(2000),
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" VARCHAR(500),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" VARCHAR(10),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_PATH" VARCHAR(2000),
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java
index 13b781ceafd..4e115b3ae70 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java
@@ -49,7 +49,7 @@ public class FavoriteUpdater {
List<PropertyDto> existingFavoriteOnComponent = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(PROP_FAVORITE_KEY)
.setUserId(userId)
- .setComponentId(componentDto.getId())
+ .setComponentUuid(componentDto.uuid())
.build(), dbSession);
checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getDbKey());
@@ -60,7 +60,7 @@ public class FavoriteUpdater {
}
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
.setKey(PROP_FAVORITE_KEY)
- .setResourceId(componentDto.getId())
+ .setComponentUuid(componentDto.uuid())
.setUserId(userId));
}
@@ -75,7 +75,7 @@ public class FavoriteUpdater {
int result = dbClient.propertiesDao().delete(dbSession, new PropertyDto()
.setKey(PROP_FAVORITE_KEY)
- .setResourceId(component.getId())
+ .setComponentUuid(component.uuid())
.setUserId(userId));
checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey());
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
index f5238e00baa..32ffaa2dcf3 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
@@ -195,7 +195,7 @@ public class ComponentIndexerTest {
indexProject(project, PROJECT_CREATION);
assertThatIndexContainsOnly(project, file);
- db.getDbClient().componentDao().delete(db.getSession(), file.getId());
+ db.getDbClient().componentDao().delete(db.getSession(), file.uuid());
IndexingResult result = indexProject(project, ProjectIndexer.Cause.PROJECT_KEY_UPDATE);
assertThatIndexContainsOnly(project, file);
@@ -223,8 +223,8 @@ public class ComponentIndexerTest {
indexProject(project, PROJECT_CREATION);
assertThatIndexHasSize(2);
- db.getDbClient().componentDao().delete(db.getSession(), project.getId());
- db.getDbClient().componentDao().delete(db.getSession(), file.getId());
+ db.getDbClient().componentDao().delete(db.getSession(), project.uuid());
+ db.getDbClient().componentDao().delete(db.getSession(), file.uuid());
indexProject(project, PROJECT_DELETION);
assertThatIndexHasSize(0);
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java
index 759a5bb0259..e5a3ac80176 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java
@@ -62,7 +62,7 @@ public class FavoriteUpdaterTest {
underTest.add(dbSession, project, null, true);
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
- .setComponentId(project.getId())
+ .setComponentUuid(project.uuid())
.build(), dbSession)).isEmpty();
}
@@ -126,14 +126,14 @@ public class FavoriteUpdaterTest {
private void assertFavorite(ComponentDto project, UserDto user) {
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setUserId(user.getId())
- .setComponentId(project.getId())
+ .setComponentUuid(project.uuid())
.build(), dbSession)).hasSize(1);
}
private void assertNoFavorite(ComponentDto project, UserDto user) {
assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setUserId(user.getId())
- .setComponentId(project.getId())
+ .setComponentUuid(project.uuid())
.build(), dbSession)).isEmpty();
}
}
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 8ae9ac47a20..7fd1df75c65 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
@@ -92,7 +92,7 @@ public class OrganisationSupport {
dbClient.groupPermissionDao().insert(dbSession,
new GroupPermissionDto().setOrganizationUuid(defaultOrganizationUuid).setGroupId(membersGroup.getId())
.setRole(groupPermissionDto.getRole())
- .setResourceId(groupPermissionDto.getResourceId()));
+ .setComponentUuid(groupPermissionDto.getComponentUuid()));
});
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/ProjectId.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/ProjectUuid.java
index eafe095b54e..16b4a0d2d34 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/ProjectId.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/ProjectUuid.java
@@ -25,27 +25,20 @@ import org.sonar.db.component.ComponentDto;
import static java.util.Objects.requireNonNull;
/**
- * Reference to a project by its db id or uuid. The field "id" should
- * be removed as soon as backend is fully based on uuids.
+ * Reference to a project by its db uuid.
*
*/
@Immutable
-public class ProjectId {
+public class ProjectUuid {
- private final long id;
private final String uuid;
private final boolean isPrivate;
- public ProjectId(ComponentDto project) {
- this.id = requireNonNull(project.getId());
+ public ProjectUuid(ComponentDto project) {
this.uuid = requireNonNull(project.uuid());
this.isPrivate = project.isPrivate();
}
- public long getId() {
- return id;
- }
-
public String getUuid() {
return uuid;
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java
index 79eea476638..5ff30743de3 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java
@@ -337,16 +337,16 @@ public class MemberUpdaterTest {
OrganizationDto anotherOrganization = db.organizations().insert();
ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
UserDto anotherUser = db.users().insertUser();
- insertProperty("KEY_11", "VALUE", project.getId(), user.getId());
- insertProperty("KEY_12", "VALUE", project.getId(), user.getId());
- insertProperty("KEY_11", "VALUE", project.getId(), anotherUser.getId());
- insertProperty("KEY_11", "VALUE", anotherProject.getId(), user.getId());
+ insertProperty("KEY_11", "VALUE", project.uuid(), user.getId());
+ insertProperty("KEY_12", "VALUE", project.uuid(), user.getId());
+ insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getId());
+ insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getId());
underTest.removeMember(db.getSession(), organization, user);
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).build(), db.getSession()))
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), db.getSession()))
.hasSize(1).extracting(PropertyDto::getUserId).containsOnly(anotherUser.getId());
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(anotherProject.getId()).build(), db.getSession())).extracting(PropertyDto::getUserId)
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), db.getSession())).extracting(PropertyDto::getUserId)
.hasSize(1).containsOnly(user.getId());
}
@@ -364,17 +364,17 @@ public class MemberUpdaterTest {
OrganizationDto anotherOrganization = db.organizations().insert();
ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
UserDto anotherUser = db.users().insertUser();
- insertProperty(DEFAULT_ISSUE_ASSIGNEE, user.getLogin(), project.getId(), null);
- insertProperty("ANOTHER_KEY", user.getLogin(), project.getId(), null);
- insertProperty(DEFAULT_ISSUE_ASSIGNEE, anotherUser.getLogin(), project.getId(), null);
- insertProperty(DEFAULT_ISSUE_ASSIGNEE, user.getLogin(), anotherProject.getId(), null);
+ insertProperty(DEFAULT_ISSUE_ASSIGNEE, user.getLogin(), project.uuid(), null);
+ insertProperty("ANOTHER_KEY", user.getLogin(), project.uuid(), null);
+ insertProperty(DEFAULT_ISSUE_ASSIGNEE, anotherUser.getLogin(), project.uuid(), null);
+ insertProperty(DEFAULT_ISSUE_ASSIGNEE, user.getLogin(), anotherProject.uuid(), null);
underTest.removeMember(db.getSession(), organization, user);
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).build(), db.getSession()))
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), db.getSession()))
.hasSize(2).extracting(PropertyDto::getKey, PropertyDto::getValue)
.containsOnly(Tuple.tuple("ANOTHER_KEY", user.getLogin()), Tuple.tuple(DEFAULT_ISSUE_ASSIGNEE, anotherUser.getLogin()));
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(anotherProject.getId()).build(), db.getSession())).extracting(PropertyDto::getValue)
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), db.getSession())).extracting(PropertyDto::getValue)
.hasSize(1).containsOnly(user.getLogin());
}
@@ -503,12 +503,12 @@ public class MemberUpdaterTest {
}
private void assertProjectPermissionsOfUser(UserDto user, ComponentDto project, String... permissions) {
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.getId())).containsOnly(permissions);
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.uuid())).containsOnly(permissions);
}
- private void insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) {
+ private void insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable Integer userId) {
PropertyDto dto = new PropertyDto().setKey(key)
- .setResourceId(resourceId)
+ .setComponentUuid(componentUuid)
.setUserId(userId)
.setValue(value);
db.properties().insertProperty(dto);
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 5740b2b485a..234ee7588a4 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
@@ -121,8 +121,8 @@ public class OrganisationSupportTest {
List<GroupPermissionDto> result = new ArrayList<>();
dbTester.getDbClient().groupPermissionDao().selectAllPermissionsByGroupId(dbTester.getSession(), defaultOrganization.getUuid(), defaultGroupId,
context -> result.add((GroupPermissionDto) context.getResultObject()));
- assertThat(result).extracting(GroupPermissionDto::getResourceId, GroupPermissionDto::getRole).containsOnly(
- tuple(null, "user"), tuple(project.getId(), "codeviewer"));
+ assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
+ tuple(null, "user"), tuple(project.uuid(), "codeviewer"));
}
@Test
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java
index 5a3b211e5a9..85e92155ed0 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java
@@ -241,9 +241,9 @@ public class UserUpdaterUpdateTest {
ComponentDto anotherProject = db.components().insertPrivateProject();
db.properties().insertProperties(
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()),
- new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setResourceId(project1.getId()),
- new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setResourceId(project2.getId()),
- new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setResourceId(anotherProject.getId()));
+ new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()),
+ new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()),
+ new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid()));
userIndexer.indexOnStartup(null);
underTest.updateAndCommit(session, oldUser, new UpdateUser()
@@ -251,12 +251,12 @@ public class UserUpdaterUpdateTest {
});
assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setKey(DEFAULT_ISSUE_ASSIGNEE).build(), db.getSession()))
- .extracting(PropertyDto::getValue, PropertyDto::getResourceId)
+ .extracting(PropertyDto::getValue, PropertyDto::getComponentUuid)
.containsOnly(
tuple("new_login", null),
- tuple("new_login", project1.getId()),
- tuple("new_login", project2.getId()),
- tuple("another login", anotherProject.getId()));
+ tuple("new_login", project1.uuid()),
+ tuple("new_login", project2.uuid()),
+ tuple("another login", anotherProject.uuid()));
}
@Test
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/BackendCleanup.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/BackendCleanup.java
index ed33fed8a07..c8b26751aa4 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/BackendCleanup.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/BackendCleanup.java
@@ -54,7 +54,7 @@ public class BackendCleanup {
"notifications", "project_links", "project_measures", "components", "projects",
"snapshots", "file_sources", "webhook_deliveries"
};
- private static final String[] RESOURCE_RELATED_TABLES = {
+ private static final String[] COMPONENT_RELATED_TABLES = {
"group_roles", "user_roles", "properties"
};
private static final Map<String, TableCleaner> TABLE_CLEANERS = ImmutableMap.of(
@@ -137,9 +137,8 @@ public class BackendCleanup {
// commit is useless on some databases
connection.commit();
}
- // Clear resource related tables
- for (String table : RESOURCE_RELATED_TABLES) {
- statement.execute("DELETE FROM " + table + " WHERE resource_id IS NOT NULL");
+ for (String table : COMPONENT_RELATED_TABLES) {
+ statement.execute("DELETE FROM " + table + " WHERE component_uuid IS NOT NULL");
connection.commit();
}
}
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 3d94f332502..0a11cce7034 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
@@ -146,7 +146,7 @@ public class BackendCleanupTest {
dbTester.properties().insertProperty(new PropertyDto()
.setKey("sonar.profile.java")
.setValue("Sonar Way")
- .setResourceId(project.getId())
+ .setComponentUuid(project.uuid())
);
}
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
index 90d7c5e3a5b..c695f67ddbe 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
@@ -60,7 +60,7 @@ public class PermissionIndexerDao {
" user_roles.user_id AS user_id, " +
" NULL AS group_id " +
" FROM components c " +
- " INNER JOIN user_roles ON user_roles.resource_id = c.id AND user_roles.role = 'user' " +
+ " INNER JOIN user_roles ON user_roles.component_uuid = c.uuid AND user_roles.role = 'user' " +
" WHERE " +
" (c.qualifier = 'TRK' " +
" or c.qualifier = 'VW' " +
@@ -77,7 +77,7 @@ public class PermissionIndexerDao {
" NULL AS user_id, " +
" groups.id AS group_id " +
" FROM components c " +
- " INNER JOIN group_roles ON group_roles.resource_id = c.id AND group_roles.role = 'user' " +
+ " INNER JOIN group_roles ON group_roles.component_uuid = c.uuid AND group_roles.role = 'user' " +
" INNER JOIN groups ON groups.id = group_roles.group_id " +
" WHERE " +
" (c.qualifier = 'TRK' " +
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
index 55f31f0795b..b40dd5448f7 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
@@ -175,7 +175,7 @@ public class PermissionIndexerDaoTest {
.setOrganizationUuid(group.getOrganizationUuid())
.setGroupId(group.getId())
.setRole(USER)
- .setResourceId(project.getId());
+ .setComponentUuid(project.uuid());
dbClient.groupPermissionDao().insert(dbSession, dto);
}
dbSession.commit();
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
index be49eeb2254..5a10ece3e7c 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
@@ -85,7 +85,7 @@ public class PermissionIndexerTest {
assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(2);
// Simulate a indexation issue
- db.getDbClient().componentDao().delete(db.getSession(), project1.getId());
+ db.getDbClient().componentDao().delete(db.getSession(), project1.uuid());
underTest.prepareForRecovery(db.getSession(), asList(project1.uuid()), ProjectIndexer.Cause.PROJECT_DELETION);
assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isEqualTo(1);
Collection<EsQueueDto> esQueueDtos = db.getDbClient().esQueueDao().selectForRecovery(db.getSession(), Long.MAX_VALUE, 2);
@@ -304,7 +304,7 @@ public class PermissionIndexerTest {
indexPermissions(project, ProjectIndexer.Cause.PROJECT_CREATION);
verifyAuthorized(project, user);
- db.getDbClient().componentDao().delete(db.getSession(), project.getId());
+ db.getDbClient().componentDao().delete(db.getSession(), project.uuid());
indexPermissions(project, ProjectIndexer.Cause.PROJECT_DELETION);
verifyNotAuthorized(project, user);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
index a6439abda8c..d2fd1fffea3 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
@@ -99,7 +99,7 @@ public class ComponentViewerJsonWriter {
List<PropertyDto> propertyDtos = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey("favourite")
- .setComponentId(component.getId())
+ .setComponentUuid(component.uuid())
.setUserId(userSession.getUserId())
.build(),
session);
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 846b2c3af3d..721071b1f8f 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
@@ -281,11 +281,11 @@ public class SearchProjectsAction implements ComponentsWsAction {
.build(),
dbSession);
- List<Long> favoriteDbIds = props.stream()
- .map(PropertyDto::getResourceId)
- .collect(toList(props.size()));
+ List<String> favoriteDbUuids = props.stream()
+ .map(PropertyDto::getComponentUuid)
+ .collect(MoreCollectors.toList(props.size()));
- return dbClient.componentDao().selectByIds(dbSession, favoriteDbIds).stream()
+ return dbClient.componentDao().selectByUuids(dbSession, favoriteDbUuids).stream()
.filter(ComponentDto::isEnabled)
.filter(f -> f.qualifier().equals(Qualifiers.PROJECT))
.map(ComponentDto::uuid)
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java
index c599edcbf15..3f1b145fff5 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java
@@ -56,9 +56,9 @@ public class FavoriteFinder {
.setKey(PROP_FAVORITE_KEY)
.setUserId(userSession.getUserId())
.build();
- Set<Long> componentIds = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getResourceId).collect(Collectors.toSet());
+ Set<String> componentUuids = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getComponentUuid).collect(Collectors.toSet());
- return dbClient.componentDao().selectByIds(dbSession, componentIds).stream()
+ return dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream()
.sorted(Comparator.comparing(ComponentDto::name))
.collect(toList());
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
index da7fcc654eb..0f0a53b7724 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
@@ -52,9 +52,9 @@ import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.nullsFirst;
import static java.util.Optional.ofNullable;
import static org.sonar.core.util.stream.MoreCollectors.toOneElement;
+import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.notification.ws.NotificationsWsParameters.ACTION_LIST;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN;
-import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
public class ListAction implements NotificationsWsAction {
@@ -122,11 +122,11 @@ public class ListAction implements NotificationsWsAction {
private UnaryOperator<ListResponse.Builder> addNotifications(DbSession dbSession, UserDto user) {
return response -> {
List<PropertyDto> properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession);
- Map<Long, ComponentDto> componentsById = searchProjects(dbSession, properties);
- Map<String, OrganizationDto> organizationsByUuid = getOrganizations(dbSession, componentsById.values());
+ Map<String, ComponentDto> componentsByUuid = searchProjects(dbSession, properties);
+ Map<String, OrganizationDto> organizationsByUuid = getOrganizations(dbSession, componentsByUuid.values());
Predicate<PropertyDto> isNotification = prop -> prop.getKey().startsWith("notification.");
- Predicate<PropertyDto> isComponentInDb = prop -> prop.getResourceId() == null || componentsById.containsKey(prop.getResourceId());
+ Predicate<PropertyDto> isComponentInDb = prop -> prop.getComponentUuid() == null || componentsByUuid.containsKey(prop.getComponentUuid());
Notification.Builder notification = Notification.newBuilder();
@@ -134,7 +134,7 @@ public class ListAction implements NotificationsWsAction {
.filter(isNotification)
.filter(channelAndDispatcherAuthorized())
.filter(isComponentInDb)
- .map(toWsNotification(notification, organizationsByUuid, componentsById))
+ .map(toWsNotification(notification, organizationsByUuid, componentsByUuid))
.sorted(comparing(Notification::getProject, nullsFirst(naturalOrder()))
.thenComparing(Notification::getChannel)
.thenComparing(Notification::getType))
@@ -154,19 +154,19 @@ public class ListAction implements NotificationsWsAction {
}
private boolean isDispatcherAuthorized(PropertyDto prop, String dispatcher) {
- return (prop.getResourceId() != null && dispatchers.getProjectDispatchers().contains(dispatcher)) || dispatchers.getGlobalDispatchers().contains(dispatcher);
+ return (prop.getComponentUuid() != null && dispatchers.getProjectDispatchers().contains(dispatcher)) || dispatchers.getGlobalDispatchers().contains(dispatcher);
}
- private Map<Long, ComponentDto> searchProjects(DbSession dbSession, List<PropertyDto> properties) {
- Set<Long> componentIds = properties.stream()
- .map(PropertyDto::getResourceId)
+ private Map<String, ComponentDto> searchProjects(DbSession dbSession, List<PropertyDto> properties) {
+ Set<String> componentUuids = properties.stream()
+ .map(PropertyDto::getComponentUuid)
.filter(Objects::nonNull)
.collect(MoreCollectors.toSet(properties.size()));
- Set<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(dbSession, componentIds, userSession.getUserId(), UserRole.USER);
- return dbClient.componentDao().selectByIds(dbSession, componentIds)
+ Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedProjectUuids(dbSession, componentUuids, userSession.getUserId(), UserRole.USER);
+ return dbClient.componentDao().selectByUuids(dbSession, componentUuids)
.stream()
- .filter(c -> authorizedProjectIds.contains(c.getId()))
- .collect(MoreCollectors.uniqueIndex(ComponentDto::getId));
+ .filter(c -> authorizedProjectUuids.contains(c.uuid()))
+ .collect(MoreCollectors.uniqueIndex(ComponentDto::uuid));
}
private Map<String, OrganizationDto> getOrganizations(DbSession dbSession, Collection<ComponentDto> values) {
@@ -179,21 +179,21 @@ public class ListAction implements NotificationsWsAction {
}
private static Function<PropertyDto, Notification> toWsNotification(Notification.Builder notification,
- Map<String, OrganizationDto> organizationsByUuid, Map<Long, ComponentDto> projectsById) {
+ Map<String, OrganizationDto> organizationsByUuid, Map<String, ComponentDto> projectsByUuid) {
return property -> {
notification.clear();
List<String> propertyKey = Splitter.on(".").splitToList(property.getKey());
notification.setType(propertyKey.get(1));
notification.setChannel(propertyKey.get(2));
- ofNullable(property.getResourceId()).ifPresent(componentId -> populateProjectFields(notification, componentId, organizationsByUuid, projectsById));
+ ofNullable(property.getComponentUuid()).ifPresent(componentUuid -> populateProjectFields(notification, componentUuid, organizationsByUuid, projectsByUuid));
return notification.build();
};
}
- private static Notification.Builder populateProjectFields(Notification.Builder notification, Long componentId,
- Map<String, OrganizationDto> organizationsByUuid, Map<Long, ComponentDto> projectsById) {
- ComponentDto project = projectsById.get(componentId);
+ private static Notification.Builder populateProjectFields(Notification.Builder notification, String componentUuid,
+ Map<String, OrganizationDto> organizationsByUuid, Map<String, ComponentDto> projectsByUuid) {
+ ComponentDto project = projectsByUuid.get(componentUuid);
String organizationUuid = project.getOrganizationUuid();
OrganizationDto organizationDto = organizationsByUuid.get(organizationUuid);
checkArgument(organizationDto != null, "No organization for uuid '%s'", organizationUuid);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java
index 1309236fcad..ce79c49be02 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java
@@ -47,12 +47,12 @@ public class NotificationUpdater {
*/
public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
- Long projectId = project == null ? null : project.getId();
+ String projectUuid = project == null ? null : project.uuid();
List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
PropertyQuery.builder()
.setKey(key)
- .setComponentId(projectId)
+ .setComponentUuid(projectUuid)
.setUserId(user.getId())
.build(),
dbSession).stream()
@@ -65,7 +65,7 @@ public class NotificationUpdater {
.setKey(key)
.setUserId(user.getId())
.setValue(PROP_NOTIFICATION_VALUE)
- .setResourceId(projectId));
+ .setComponentUuid(projectUuid));
}
/**
@@ -73,12 +73,12 @@ public class NotificationUpdater {
*/
public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
- Long projectId = project == null ? null : project.getId();
+ String projectUuid = project == null ? null : project.uuid();
List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
PropertyQuery.builder()
.setKey(key)
- .setComponentId(projectId)
+ .setComponentUuid(projectUuid)
.setUserId(user.getId())
.build(),
dbSession).stream()
@@ -90,10 +90,10 @@ public class NotificationUpdater {
.setKey(key)
.setUserId(user.getId())
.setValue(PROP_NOTIFICATION_VALUE)
- .setResourceId(projectId));
+ .setComponentUuid(projectUuid));
}
private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) {
- return prop -> project == null ? (prop.getResourceId() == null) : (prop.getResourceId() != null);
+ return prop -> project == null ? (prop.getComponentUuid() == null) : (prop.getComponentUuid() != null);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java
index 207506a62ee..59baccc69ae 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java
@@ -25,9 +25,9 @@ public class GroupPermissionChange extends PermissionChange {
private final GroupIdOrAnyone groupId;
- public GroupPermissionChange(Operation operation, String permission, @Nullable ProjectId projectId,
+ public GroupPermissionChange(Operation operation, String permission, @Nullable ProjectUuid projectUuid,
GroupIdOrAnyone groupId, PermissionService permissionService) {
- super(operation, groupId.getOrganizationUuid(), permission, projectId, permissionService);
+ super(operation, groupId.getOrganizationUuid(), permission, projectUuid, permissionService);
this.groupId = groupId;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
index 228b2d2a46a..e46ba28cc76 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
@@ -20,7 +20,6 @@
package org.sonar.server.permission;
import java.util.List;
-import java.util.Optional;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -57,48 +56,48 @@ public class GroupPermissionChanger {
}
private static boolean isImplicitlyAlreadyDone(GroupPermissionChange change) {
- return change.getProjectId()
- .map(projectId -> isImplicitlyAlreadyDone(projectId, change))
- .orElse(false);
+ if (change.getProject() != null) {
+ return isImplicitlyAlreadyDone(change.getProject(), change);
+ }
+ return false;
}
- private static boolean isImplicitlyAlreadyDone(ProjectId projectId, GroupPermissionChange change) {
- return isAttemptToAddPublicPermissionToPublicComponent(change, projectId)
- || isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(change, projectId);
+ private static boolean isImplicitlyAlreadyDone(ProjectUuid project, GroupPermissionChange change) {
+ return isAttemptToAddPublicPermissionToPublicComponent(change, project)
+ || isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(change, project);
}
- private static boolean isAttemptToAddPublicPermissionToPublicComponent(GroupPermissionChange change, ProjectId projectId) {
- return !projectId.isPrivate()
+ private static boolean isAttemptToAddPublicPermissionToPublicComponent(GroupPermissionChange change, ProjectUuid project) {
+ return !project.isPrivate()
&& change.getOperation() == ADD
&& PUBLIC_PERMISSIONS.contains(change.getPermission());
}
- private static boolean isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectId projectId) {
- return projectId.isPrivate()
+ private static boolean isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectUuid project) {
+ return project.isPrivate()
&& change.getOperation() == REMOVE
&& change.getGroupIdOrAnyone().isAnyone();
}
private static void ensureConsistencyWithVisibility(GroupPermissionChange change) {
- change.getProjectId()
- .ifPresent(projectId -> {
- checkRequest(
- !isAttemptToAddPermissionToAnyoneOnPrivateComponent(change, projectId),
- "No permission can be granted to Anyone on a private component");
- checkRequest(
- !isAttemptToRemovePublicPermissionFromPublicComponent(change, projectId),
- "Permission %s can't be removed from a public component", change.getPermission());
- });
+ if (change.getProject() != null) {
+ checkRequest(
+ !isAttemptToAddPermissionToAnyoneOnPrivateComponent(change, change.getProject()),
+ "No permission can be granted to Anyone on a private component");
+ checkRequest(
+ !isAttemptToRemovePublicPermissionFromPublicComponent(change, change.getProject()),
+ "Permission %s can't be removed from a public component", change.getPermission());
+ }
}
- private static boolean isAttemptToAddPermissionToAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectId projectId) {
- return projectId.isPrivate()
+ private static boolean isAttemptToAddPermissionToAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectUuid project) {
+ return project.isPrivate()
&& change.getOperation() == ADD
&& change.getGroupIdOrAnyone().isAnyone();
}
- private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(GroupPermissionChange change, ProjectId projectId) {
- return !projectId.isPrivate()
+ private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(GroupPermissionChange change, ProjectUuid project) {
+ return !project.isPrivate()
&& change.getOperation() == REMOVE
&& PUBLIC_PERMISSIONS.contains(change.getPermission());
}
@@ -113,7 +112,7 @@ public class GroupPermissionChanger {
.setRole(change.getPermission())
.setOrganizationUuid(change.getOrganizationUuid())
.setGroupId(change.getGroupIdOrAnyone().getId())
- .setResourceId(change.getNullableProjectId());
+ .setComponentUuid(change.getProjectUuid());
dbClient.groupPermissionDao().insert(dbSession, addedDto);
return true;
}
@@ -132,17 +131,17 @@ public class GroupPermissionChanger {
change.getPermission(),
change.getOrganizationUuid(),
change.getGroupIdOrAnyone().getId(),
- change.getNullableProjectId());
+ change.getProjectUuid());
return true;
}
private List<String> loadExistingPermissions(DbSession dbSession, GroupPermissionChange change) {
- Optional<ProjectId> projectId = change.getProjectId();
- if (projectId.isPresent()) {
+ String projectUuid = change.getProjectUuid();
+ if (projectUuid != null) {
return dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession,
change.getOrganizationUuid(),
change.getGroupIdOrAnyone().getId(),
- projectId.get().getId());
+ projectUuid);
}
return dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession,
change.getOrganizationUuid(),
@@ -152,7 +151,7 @@ public class GroupPermissionChanger {
private void checkIfRemainingGlobalAdministrators(DbSession dbSession, GroupPermissionChange change) {
if (SYSTEM_ADMIN.equals(change.getPermission()) &&
!change.getGroupIdOrAnyone().isAnyone() &&
- !change.getProjectId().isPresent()) {
+ change.getProjectUuid() == null) {
// removing global admin permission from group
int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingGroup(dbSession,
change.getOrganizationUuid(), SYSTEM_ADMIN, change.getGroupIdOrAnyone().getId());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java
index 0b12ba7a68f..bf082924d8d 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.permission;
-import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.db.permission.OrganizationPermission;
@@ -37,16 +36,16 @@ public abstract class PermissionChange {
private final Operation operation;
private final String organizationUuid;
private final String permission;
- private final ProjectId projectId;
+ private final ProjectUuid projectUuid;
protected final PermissionService permissionService;
- public PermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectId projectId, PermissionService permissionService) {
+ public PermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectUuid projectUuid, PermissionService permissionService) {
this.operation = requireNonNull(operation);
this.organizationUuid = requireNonNull(organizationUuid);
this.permission = requireNonNull(permission);
- this.projectId = projectId;
+ this.projectUuid = projectUuid;
this.permissionService = permissionService;
- if (projectId == null) {
+ if (projectUuid == null) {
checkRequest(permissionService.getAllOrganizationPermissions().stream().anyMatch(p -> p.getKey().equals(permission)),
"Invalid global permission '%s'. Valid values are %s", permission,
permissionService.getAllOrganizationPermissions().stream().map(OrganizationPermission::getKey).collect(toList()));
@@ -68,23 +67,13 @@ public abstract class PermissionChange {
return permission;
}
- public Optional<ProjectId> getProjectId() {
- return Optional.ofNullable(projectId);
- }
-
- /**
- * Shortcut based on {@link #getProjectId()}
- */
@CheckForNull
- public String getProjectUuid() {
- return projectId == null ? null : projectId.getUuid();
+ public ProjectUuid getProject() {
+ return projectUuid;
}
- /**
- * Shortcut based on {@link #getProjectId()}
- */
@CheckForNull
- public Long getNullableProjectId() {
- return projectId == null ? null : projectId.getId();
+ public String getProjectUuid() {
+ return projectUuid == null ? null : projectUuid.getUuid();
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java
index db471ffeb71..1a3fa00d1e3 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java
@@ -42,15 +42,15 @@ public class PermissionPrivilegeChecker {
* defined.
* @throws org.sonar.server.exceptions.ForbiddenException if user is not administrator
*/
- public static void checkProjectAdmin(UserSession userSession, String organizationUuid, Optional<ProjectId> projectId) {
+ public static void checkProjectAdmin(UserSession userSession, String organizationUuid, Optional<ProjectUuid> projectUuid) {
userSession.checkLoggedIn();
if (userSession.hasPermission(OrganizationPermission.ADMINISTER, organizationUuid)) {
return;
}
- if (projectId.isPresent()) {
- userSession.checkComponentUuidPermission(UserRole.ADMIN, projectId.get().getUuid());
+ if (projectUuid.isPresent()) {
+ userSession.checkComponentUuidPermission(UserRole.ADMIN, projectUuid.get().getUuid());
} else {
throw insufficientPrivilegesException();
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
index 918fc0ba3ec..dca1f7e2e8d 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
@@ -120,8 +120,8 @@ public class PermissionTemplateService {
}
private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Integer projectCreatorUserId) {
- dbClient.groupPermissionDao().deleteByRootComponentId(dbSession, project.getId());
- dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.getId());
+ dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid());
+ dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid());
List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getId());
String organizationUuid = template.getOrganizationUuid();
@@ -129,7 +129,7 @@ public class PermissionTemplateService {
.stream()
.filter(up -> permissionValidForProject(project, up.getPermission()))
.forEach(up -> {
- UserPermissionDto dto = new UserPermissionDto(organizationUuid, up.getPermission(), up.getUserId(), project.getId());
+ UserPermissionDto dto = new UserPermissionDto(organizationUuid, up.getPermission(), up.getUserId(), project.uuid());
dbClient.userPermissionDao().insert(dbSession, dto);
});
@@ -143,7 +143,7 @@ public class PermissionTemplateService {
.setOrganizationUuid(organizationUuid)
.setGroupId(isAnyone(gp.getGroupName()) ? null : gp.getGroupId())
.setRole(gp.getPermission())
- .setResourceId(project.getId());
+ .setComponentUuid(project.uuid());
dbClient.groupPermissionDao().insert(dbSession, dto);
});
@@ -158,7 +158,7 @@ public class PermissionTemplateService {
.filter(up -> permissionValidForProject(project, up.getPermission()))
.filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission()))
.forEach(c -> {
- UserPermissionDto dto = new UserPermissionDto(organizationUuid, c.getPermission(), projectCreatorUserId, project.getId());
+ UserPermissionDto dto = new UserPermissionDto(organizationUuid, c.getPermission(), projectCreatorUserId, project.uuid());
dbClient.userPermissionDao().insert(dbSession, dto);
});
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java
index 076d37f119e..633578eeb95 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java
@@ -22,7 +22,6 @@ package org.sonar.server.permission;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Optional;
import org.sonar.db.DbSession;
import org.sonar.server.es.ProjectIndexer;
import org.sonar.server.es.ProjectIndexers;
@@ -49,9 +48,9 @@ public class PermissionUpdater {
List<String> projectOrViewUuids = new ArrayList<>();
for (PermissionChange change : changes) {
boolean changed = doApply(dbSession, change);
- Optional<ProjectId> projectId = change.getProjectId();
- if (changed && projectId.isPresent()) {
- projectOrViewUuids.add(projectId.get().getUuid());
+ String projectUuid = change.getProjectUuid();
+ if (changed && projectUuid != null) {
+ projectOrViewUuids.add(projectUuid);
}
}
projectIndexers.commitAndIndexByProjectUuids(dbSession, projectOrViewUuids, ProjectIndexer.Cause.PERMISSION_CHANGE);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java
index 69ec60a35c9..6ab895bec2c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java
@@ -27,9 +27,9 @@ public class UserPermissionChange extends PermissionChange {
private final UserId userId;
- public UserPermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectId projectId,
+ public UserPermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectUuid project,
UserId userId, PermissionService permissionService) {
- super(operation, organizationUuid, permission, projectId, permissionService);
+ super(operation, organizationUuid, permission, project, permissionService);
this.userId = requireNonNull(userId);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
index fde70ff828e..747041ac653 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
@@ -20,16 +20,15 @@
package org.sonar.server.permission;
import java.util.List;
-import java.util.Optional;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.UserPermissionDto;
import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
+import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.permission.PermissionChange.Operation.ADD;
import static org.sonar.server.permission.PermissionChange.Operation.REMOVE;
-import static org.sonar.server.exceptions.BadRequestException.checkRequest;
/**
* Adds and removes user permissions. Both global and project scopes are supported.
@@ -58,30 +57,31 @@ public class UserPermissionChanger {
}
private static boolean isImplicitlyAlreadyDone(UserPermissionChange change) {
- return change.getProjectId()
- .map(projectId -> isImplicitlyAlreadyDone(projectId, change))
- .orElse(false);
+ if (change.getProject() != null) {
+ return isImplicitlyAlreadyDone(change.getProject(), change);
+ }
+ return false;
}
- private static boolean isImplicitlyAlreadyDone(ProjectId projectId, UserPermissionChange change) {
- return isAttemptToAddPublicPermissionToPublicComponent(change, projectId);
+ private static boolean isImplicitlyAlreadyDone(ProjectUuid project, UserPermissionChange change) {
+ return isAttemptToAddPublicPermissionToPublicComponent(change, project);
}
- private static boolean isAttemptToAddPublicPermissionToPublicComponent(UserPermissionChange change, ProjectId projectId) {
- return !projectId.isPrivate()
+ private static boolean isAttemptToAddPublicPermissionToPublicComponent(UserPermissionChange change, ProjectUuid project) {
+ return !project.isPrivate()
&& change.getOperation() == ADD
&& PUBLIC_PERMISSIONS.contains(change.getPermission());
}
private static void ensureConsistencyWithVisibility(UserPermissionChange change) {
- change.getProjectId()
- .ifPresent(projectId -> checkRequest(
- !isAttemptToRemovePublicPermissionFromPublicComponent(change, projectId),
- "Permission %s can't be removed from a public component", change.getPermission()));
+ if (change.getProject() != null) {
+ checkRequest(!isAttemptToRemovePublicPermissionFromPublicComponent(change, change.getProject()),
+ "Permission %s can't be removed from a public component", change.getPermission());
+ }
}
- private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(UserPermissionChange change, ProjectId projectId) {
- return !projectId.isPrivate()
+ private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(UserPermissionChange change, ProjectUuid projectUuid) {
+ return !projectUuid.isPrivate()
&& change.getOperation() == REMOVE
&& PUBLIC_PERMISSIONS.contains(change.getPermission());
}
@@ -90,7 +90,7 @@ public class UserPermissionChanger {
if (loadExistingPermissions(dbSession, change).contains(change.getPermission())) {
return false;
}
- UserPermissionDto dto = new UserPermissionDto(change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId(), change.getNullableProjectId());
+ UserPermissionDto dto = new UserPermissionDto(change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId(), change.getProjectUuid());
dbClient.userPermissionDao().insert(dbSession, dto);
return true;
}
@@ -100,9 +100,9 @@ public class UserPermissionChanger {
return false;
}
checkOtherAdminsExist(dbSession, change);
- Optional<ProjectId> projectId = change.getProjectId();
- if (projectId.isPresent()) {
- dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getId(), change.getPermission(), projectId.get().getId());
+ String projectUuid = change.getProjectUuid();
+ if (projectUuid != null) {
+ dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getId(), change.getPermission(), projectUuid);
} else {
dbClient.userPermissionDao().deleteGlobalPermission(dbSession, change.getUserId().getId(), change.getPermission(), change.getOrganizationUuid());
}
@@ -110,11 +110,9 @@ public class UserPermissionChanger {
}
private List<String> loadExistingPermissions(DbSession dbSession, UserPermissionChange change) {
- Optional<ProjectId> projectId = change.getProjectId();
- if (projectId.isPresent()) {
- return dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession,
- change.getUserId().getId(),
- projectId.get().getId());
+ String projectUuid = change.getProjectUuid();
+ if (projectUuid != null) {
+ return dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, change.getUserId().getId(), projectUuid);
}
return dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession,
change.getUserId().getId(),
@@ -122,7 +120,7 @@ public class UserPermissionChanger {
}
private void checkOtherAdminsExist(DbSession dbSession, UserPermissionChange change) {
- if (SYSTEM_ADMIN.equals(change.getPermission()) && !change.getProjectId().isPresent()) {
+ if (SYSTEM_ADMIN.equals(change.getPermission()) && change.getProjectUuid() == null) {
int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingUserPermission(dbSession,
change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId());
checkRequest(remaining > 0, "Last user with permission '%s'. Permission cannot be removed.", SYSTEM_ADMIN);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
index f26a7cf4d0a..f2213faaa7a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
@@ -26,13 +26,13 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.server.permission.GroupIdOrAnyone;
import org.sonar.server.permission.GroupPermissionChange;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.user.UserSession;
-import org.sonar.server.permission.GroupIdOrAnyone;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.WsParameters.createGroupIdParameter;
@@ -88,14 +88,14 @@ public class AddGroupAction implements PermissionsWsAction {
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
GroupIdOrAnyone group = wsSupport.findGroup(dbSession, request);
- Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request);
+ Optional<ProjectUuid> projectUuid = wsSupport.findProjectUuid(dbSession, request);
- checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId);
+ checkProjectAdmin(userSession, group.getOrganizationUuid(), projectUuid);
PermissionChange change = new GroupPermissionChange(
PermissionChange.Operation.ADD,
request.mandatoryParam(PARAM_PERMISSION),
- projectId.orElse(null),
+ projectUuid.orElse(null),
group, permissionService);
permissionUpdater.apply(dbSession, ImmutableList.of(change));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java
index c2984e40c04..0e51f3af6d4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java
@@ -32,7 +32,7 @@ import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.permission.UserId;
import org.sonar.server.permission.UserPermissionChange;
import org.sonar.server.user.UserSession;
@@ -104,14 +104,14 @@ public class AddUserAction implements PermissionsWsAction {
checkArgument(organizationKey == null || org.getKey().equals(organizationKey), "Organization key is incorrect.");
wsSupport.checkMembership(dbSession, org, user);
- Optional<ProjectId> projectId = project.map(ProjectId::new);
- checkProjectAdmin(userSession, org.getUuid(), projectId);
+ Optional<ProjectUuid> projectUuid = project.map(ProjectUuid::new);
+ checkProjectAdmin(userSession, org.getUuid(), projectUuid);
PermissionChange change = new UserPermissionChange(
PermissionChange.Operation.ADD,
org.getUuid(),
request.mandatoryParam(PARAM_PERMISSION),
- projectId.orElse(null),
+ projectUuid.orElse(null),
user, permissionService);
permissionUpdater.apply(dbSession, singletonList(change));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
index de58e0440b6..b6b8eeff9dd 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
@@ -39,7 +39,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.GroupPermissionDto;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.user.GroupDto;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Permissions.Group;
import org.sonarqube.ws.Permissions.WsGroupsResponse;
@@ -101,21 +101,21 @@ public class GroupsAction implements PermissionsWsAction {
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
- Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request);
- checkProjectAdmin(userSession, org.getUuid(), projectId);
+ Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request);
+ checkProjectAdmin(userSession, org.getUuid(), project);
- PermissionQuery query = buildPermissionQuery(request, org, projectId);
+ PermissionQuery query = buildPermissionQuery(request, org, project);
// TODO validatePermission(groupsRequest.getPermission(), wsProjectRef);
List<GroupDto> groups = findGroups(dbSession, org, query);
int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, query);
- List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, projectId);
+ List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, project);
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging);
writeProtobuf(groupsResponse, request, response);
}
}
- private static PermissionQuery buildPermissionQuery(Request request, OrganizationDto org, Optional<ProjectId> project) {
+ private static PermissionQuery buildPermissionQuery(Request request, OrganizationDto org, Optional<ProjectUuid> project) {
String textQuery = request.param(Param.TEXT_QUERY);
PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
.setOrganizationUuid(org.getUuid())
@@ -123,7 +123,7 @@ public class GroupsAction implements PermissionsWsAction {
.setPageIndex(request.mandatoryParamAsInt(Param.PAGE))
.setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
.setSearchQuery(textQuery);
- project.ifPresent(projectId -> permissionQuery.setComponent(projectId.getUuid(), projectId.getId()));
+ project.ifPresent(projectUuid -> permissionQuery.setComponent(projectUuid.getUuid()));
return permissionQuery.build();
}
@@ -159,11 +159,11 @@ public class GroupsAction implements PermissionsWsAction {
return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups);
}
- private List<GroupPermissionDto> findGroupPermissions(DbSession dbSession, OrganizationDto org, List<GroupDto> groups, Optional<ProjectId> project) {
+ private List<GroupPermissionDto> findGroupPermissions(DbSession dbSession, OrganizationDto org, List<GroupDto> groups, Optional<ProjectUuid> project) {
if (groups.isEmpty()) {
return emptyList();
}
List<Integer> ids = groups.stream().map(GroupDto::getId).collect(MoreCollectors.toList(groups.size()));
- return dbClient.groupPermissionDao().selectByGroupIds(dbSession, org.getUuid(), ids, project.isPresent() ? project.get().getId() : null);
+ return dbClient.groupPermissionDao().selectByGroupIds(dbSession, org.getUuid(), ids, project.map(ProjectUuid::getUuid).orElse(null));
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java
index 7be93754d3d..721e4f9dc45 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java
@@ -29,10 +29,10 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.GroupIdOrAnyone;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.permission.UserId;
import org.sonar.server.permission.ws.template.WsTemplateRef;
-import org.sonar.server.permission.GroupIdOrAnyone;
import org.sonar.server.usergroups.ws.GroupWsRef;
import org.sonar.server.usergroups.ws.GroupWsSupport;
import org.sonarqube.ws.client.permission.PermissionsWsParameters;
@@ -59,9 +59,9 @@ public class PermissionWsSupport {
return groupWsSupport.findOrganizationByKey(dbSession, organizationKey);
}
- public Optional<ProjectId> findProjectId(DbSession dbSession, Request request) {
+ public Optional<ProjectUuid> findProjectUuid(DbSession dbSession, Request request) {
return findProject(dbSession, request)
- .map(ProjectId::new);
+ .map(ProjectUuid::new);
}
public Optional<ComponentDto> findProject(DbSession dbSession, Request request) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java
index 0f9e1eae23f..abc7a494723 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java
@@ -25,13 +25,13 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.server.permission.GroupIdOrAnyone;
import org.sonar.server.permission.GroupPermissionChange;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.user.UserSession;
-import org.sonar.server.permission.GroupIdOrAnyone;
import static java.util.Arrays.asList;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
@@ -88,14 +88,14 @@ public class RemoveGroupAction implements PermissionsWsAction {
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
GroupIdOrAnyone group = wsSupport.findGroup(dbSession, request);
- Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request);
+ Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request);
- checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId);
+ checkProjectAdmin(userSession, group.getOrganizationUuid(), project);
PermissionChange change = new GroupPermissionChange(
PermissionChange.Operation.REMOVE,
request.mandatoryParam(PARAM_PERMISSION),
- projectId.orElse(null),
+ project.orElse(null),
group, permissionService);
permissionUpdater.apply(dbSession, asList(change));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
index bc0bffa6203..535444fc6d7 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
@@ -29,7 +29,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.permission.UserId;
import org.sonar.server.permission.UserPermissionChange;
import org.sonar.server.user.UserSession;
@@ -88,16 +88,16 @@ public class RemoveUserAction implements PermissionsWsAction {
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
UserId user = wsSupport.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
- Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request);
+ Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request);
OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
- checkProjectAdmin(userSession, org.getUuid(), projectId);
+ checkProjectAdmin(userSession, org.getUuid(), project);
PermissionChange change = new UserPermissionChange(
PermissionChange.Operation.REMOVE,
org.getUuid(),
request.mandatoryParam(PARAM_PERMISSION),
- projectId.orElse(null),
+ project.orElse(null),
user, permissionService);
permissionUpdater.apply(dbSession, singletonList(change));
response.noContent();
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java
index f6c1e43bd8c..a6f992aec73 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java
@@ -43,7 +43,7 @@ import org.sonar.db.component.ComponentQuery;
import org.sonar.db.permission.CountPerProjectPermission;
import org.sonar.server.permission.PermissionPrivilegeChecker;
import org.sonar.server.permission.PermissionService;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.permission.RequestValidator;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Common;
@@ -56,8 +56,8 @@ import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.server.permission.ws.ProjectWsRef.newOptionalWsProjectRef;
import static org.sonar.server.permission.ws.SearchProjectPermissionsData.newBuilder;
import static org.sonar.server.permission.ws.WsParameters.createProjectParameters;
-import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter;
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
+import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
@@ -141,7 +141,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
com.google.common.base.Optional<ProjectWsRef> projectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
if (projectRef.isPresent()) {
ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, projectRef.get());
- PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectId(project)));
+ PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectUuid(project)));
} else {
userSession.checkLoggedIn().checkIsSystemAdministrator();
}
@@ -159,13 +159,13 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
.setKey(rootComponent.getDbKey())
.setQualifier(rootComponent.qualifier())
.setName(rootComponent.name());
- for (String permission : data.permissions(rootComponent.getId())) {
+ for (String permission : data.permissions(rootComponent.uuid())) {
rootComponentBuilder.addPermissions(
permissionResponse
.clear()
.setKey(permission)
- .setUsersCount(data.userCount(rootComponent.getId(), permission))
- .setGroupsCount(data.groupCount(rootComponent.getId(), permission)));
+ .setUsersCount(data.userCount(rootComponent.uuid(), permission))
+ .setGroupsCount(data.groupCount(rootComponent.uuid(), permission)));
}
response.addProjects(rootComponentBuilder);
}
@@ -201,12 +201,12 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
SearchProjectPermissionsData.Builder data = newBuilder();
int countRootComponents = countRootComponents(dbSession, request);
List<ComponentDto> rootComponents = searchRootComponents(dbSession, request, paging(request, countRootComponents));
- List<Long> rootComponentIds = Lists.transform(rootComponents, ComponentDto::getId);
+ List<String> rootComponentUuids = Lists.transform(rootComponents, ComponentDto::uuid);
data.rootComponents(rootComponents)
.paging(paging(request, countRootComponents))
- .userCountByProjectIdAndPermission(userCountByRootComponentIdAndPermission(dbSession, rootComponentIds))
- .groupCountByProjectIdAndPermission(groupCountByRootComponentIdAndPermission(dbSession, rootComponentIds));
+ .userCountByProjectIdAndPermission(userCountByRootComponentUuidAndPermission(dbSession, rootComponentUuids))
+ .groupCountByProjectIdAndPermission(groupCountByRootComponentIdAndPermission(dbSession, rootComponentUuids));
return data.build();
}
@@ -244,24 +244,24 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
: (new String[] {requestQualifier});
}
- private Table<Long, String, Integer> userCountByRootComponentIdAndPermission(DbSession dbSession, List<Long> rootComponentIds) {
- final Table<Long, String, Integer> userCountByRootComponentIdAndPermission = TreeBasedTable.create();
+ private Table<String, String, Integer> userCountByRootComponentUuidAndPermission(DbSession dbSession, List<String> rootComponentUuids) {
+ final Table<String, String, Integer> userCountByRootComponentUuidAndPermission = TreeBasedTable.create();
- dbClient.userPermissionDao().countUsersByProjectPermission(dbSession, rootComponentIds).forEach(
- row -> userCountByRootComponentIdAndPermission.put(row.getComponentId(), row.getPermission(), row.getCount()));
+ dbClient.userPermissionDao().countUsersByProjectPermission(dbSession, rootComponentUuids).forEach(
+ row -> userCountByRootComponentUuidAndPermission.put(row.getComponentUuid(), row.getPermission(), row.getCount()));
- return userCountByRootComponentIdAndPermission;
+ return userCountByRootComponentUuidAndPermission;
}
- private Table<Long, String, Integer> groupCountByRootComponentIdAndPermission(DbSession dbSession, List<Long> rootComponentIds) {
- final Table<Long, String, Integer> userCountByRootComponentIdAndPermission = TreeBasedTable.create();
+ private Table<String, String, Integer> groupCountByRootComponentIdAndPermission(DbSession dbSession, List<String> rootComponentUuids) {
+ final Table<String, String, Integer> userCountByRootComponentUuidAndPermission = TreeBasedTable.create();
- dbClient.groupPermissionDao().groupsCountByComponentIdAndPermission(dbSession, rootComponentIds, context -> {
+ dbClient.groupPermissionDao().groupsCountByComponentUuidAndPermission(dbSession, rootComponentUuids, context -> {
CountPerProjectPermission row = (CountPerProjectPermission) context.getResultObject();
- userCountByRootComponentIdAndPermission.put(row.getComponentId(), row.getPermission(), row.getCount());
+ userCountByRootComponentUuidAndPermission.put(row.getComponentUuid(), row.getPermission(), row.getCount());
});
- return userCountByRootComponentIdAndPermission;
+ return userCountByRootComponentUuidAndPermission;
}
private static class SearchProjectPermissionsRequest {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java
index c075269ef87..3451dafc463 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java
@@ -36,14 +36,14 @@ import static com.google.common.collect.ImmutableTable.copyOf;
class SearchProjectPermissionsData {
private final List<ComponentDto> rootComponents;
private final Paging paging;
- private final Table<Long, String, Integer> userCountByProjectIdAndPermission;
- private final Table<Long, String, Integer> groupCountByProjectIdAndPermission;
+ private final Table<String, String, Integer> userCountByProjectUuidAndPermission;
+ private final Table<String, String, Integer> groupCountByProjectUuidAndPermission;
private SearchProjectPermissionsData(Builder builder) {
this.rootComponents = copyOf(builder.projects);
this.paging = builder.paging;
- this.userCountByProjectIdAndPermission = copyOf(builder.userCountByProjectIdAndPermission);
- this.groupCountByProjectIdAndPermission = copyOf(builder.groupCountByProjectIdAndPermission);
+ this.userCountByProjectUuidAndPermission = copyOf(builder.userCountByProjectUuidAndPermission);
+ this.groupCountByProjectUuidAndPermission = copyOf(builder.groupCountByProjectUuidAndPermission);
}
static Builder newBuilder() {
@@ -58,27 +58,27 @@ class SearchProjectPermissionsData {
return paging;
}
- int userCount(long rootComponentId, String permission) {
- return firstNonNull(userCountByProjectIdAndPermission.get(rootComponentId, permission), 0);
+ int userCount(String rootComponentUuid, String permission) {
+ return firstNonNull(userCountByProjectUuidAndPermission.get(rootComponentUuid, permission), 0);
}
- int groupCount(long rootComponentId, String permission) {
- return firstNonNull(groupCountByProjectIdAndPermission.get(rootComponentId, permission), 0);
+ int groupCount(String rootComponentUuid, String permission) {
+ return firstNonNull(groupCountByProjectUuidAndPermission.get(rootComponentUuid, permission), 0);
}
- Set<String> permissions(long rootComponentId) {
+ Set<String> permissions(String rootComponentUuid) {
return FluentIterable.from(
Iterables.concat(
- userCountByProjectIdAndPermission.row(rootComponentId).keySet(),
- groupCountByProjectIdAndPermission.row(rootComponentId).keySet()))
+ userCountByProjectUuidAndPermission.row(rootComponentUuid).keySet(),
+ groupCountByProjectUuidAndPermission.row(rootComponentUuid).keySet()))
.toSortedSet(Ordering.natural());
}
static class Builder {
private List<ComponentDto> projects;
private Paging paging;
- private Table<Long, String, Integer> userCountByProjectIdAndPermission;
- private Table<Long, String, Integer> groupCountByProjectIdAndPermission;
+ private Table<String, String, Integer> userCountByProjectUuidAndPermission;
+ private Table<String, String, Integer> groupCountByProjectUuidAndPermission;
private Builder() {
// prevents instantiation outside main class
@@ -86,8 +86,8 @@ class SearchProjectPermissionsData {
SearchProjectPermissionsData build() {
checkState(projects != null);
- checkState(userCountByProjectIdAndPermission != null);
- checkState(groupCountByProjectIdAndPermission != null);
+ checkState(userCountByProjectUuidAndPermission != null);
+ checkState(groupCountByProjectUuidAndPermission != null);
return new SearchProjectPermissionsData(this);
}
@@ -102,13 +102,13 @@ class SearchProjectPermissionsData {
return this;
}
- Builder userCountByProjectIdAndPermission(Table<Long, String, Integer> userCountByProjectIdAndPermission) {
- this.userCountByProjectIdAndPermission = userCountByProjectIdAndPermission;
+ Builder userCountByProjectIdAndPermission(Table<String, String, Integer> userCountByProjectIdAndPermission) {
+ this.userCountByProjectUuidAndPermission = userCountByProjectIdAndPermission;
return this;
}
- Builder groupCountByProjectIdAndPermission(Table<Long, String, Integer> groupCountByProjectIdAndPermission) {
- this.groupCountByProjectIdAndPermission = groupCountByProjectIdAndPermission;
+ Builder groupCountByProjectIdAndPermission(Table<String, String, Integer> groupCountByProjectIdAndPermission) {
+ this.groupCountByProjectUuidAndPermission = groupCountByProjectIdAndPermission;
return this;
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java
index 44d8b9acd65..76450b7c3dc 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java
@@ -38,7 +38,7 @@ import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.UserPermissionDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.issue.AvatarResolver;
-import org.sonar.server.permission.ProjectId;
+import org.sonar.server.permission.ProjectUuid;
import org.sonar.server.permission.RequestValidator;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Permissions;
@@ -110,20 +110,20 @@ public class UsersAction implements PermissionsWsAction {
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
- Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request);
- checkProjectAdmin(userSession, org.getUuid(), projectId);
+ Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request);
+ checkProjectAdmin(userSession, org.getUuid(), project);
- PermissionQuery query = buildPermissionQuery(request, org, projectId);
+ PermissionQuery query = buildPermissionQuery(request, org, project);
List<UserDto> users = findUsers(dbSession, query);
int total = dbClient.userPermissionDao().countUsersByQuery(dbSession, query);
- List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId);
+ List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, project);
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging);
writeProtobuf(usersWsResponse, request, response);
}
}
- private PermissionQuery buildPermissionQuery(Request request, OrganizationDto organization, Optional<ProjectId> project) {
+ private PermissionQuery buildPermissionQuery(Request request, OrganizationDto organization, Optional<ProjectUuid> project) {
String textQuery = request.param(Param.TEXT_QUERY);
String permission = request.param(PARAM_PERMISSION);
PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
@@ -132,7 +132,7 @@ public class UsersAction implements PermissionsWsAction {
.setPageIndex(request.mandatoryParamAsInt(Param.PAGE))
.setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
.setSearchQuery(textQuery);
- project.ifPresent(projectId -> permissionQuery.setComponent(projectId.getUuid(), projectId.getId()));
+ project.ifPresent(projectId -> permissionQuery.setComponent(projectId.getUuid()));
if (permission != null) {
if (project.isPresent()) {
requestValidator.validateProjectPermission(permission);
@@ -172,7 +172,7 @@ public class UsersAction implements PermissionsWsAction {
return Ordering.explicit(orderedIds).onResultOf(UserDto::getId).immutableSortedCopy(dbClient.userDao().selectByIds(dbSession, orderedIds));
}
- private List<UserPermissionDto> findUserPermissions(DbSession dbSession, OrganizationDto org, List<UserDto> users, Optional<ProjectId> project) {
+ private List<UserPermissionDto> findUserPermissions(DbSession dbSession, OrganizationDto org, List<UserDto> users, Optional<ProjectUuid> project) {
if (users.isEmpty()) {
return emptyList();
}
@@ -180,7 +180,7 @@ public class UsersAction implements PermissionsWsAction {
PermissionQuery.Builder queryBuilder = PermissionQuery.builder()
.setOrganizationUuid(org.getUuid())
.withAtLeastOnePermission();
- project.ifPresent(p -> queryBuilder.setComponent(p.getUuid(), p.getId()));
+ project.ifPresent(p -> queryBuilder.setComponent(p.getUuid()));
return dbClient.userPermissionDao().selectUserPermissionsByQuery(dbSession, queryBuilder.build(), userIds);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
index 09ad3ee95ce..b39a1f4eda4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
@@ -190,10 +190,10 @@ public class SearchMyProjectsAction implements ProjectsWsAction {
private ProjectsResult searchProjects(DbSession dbSession, SearchMyProjectsRequest request) {
int userId = requireNonNull(userSession.getUserId(), "Current user must be authenticated");
- List<Long> componentIds = dbClient.roleDao().selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, userId);
+ List<String> componentUuids = dbClient.roleDao().selectComponentUuidsByPermissionAndUserId(dbSession, UserRole.ADMIN, userId);
ComponentQuery dbQuery = ComponentQuery.builder()
.setQualifiers(Qualifiers.PROJECT)
- .setComponentIds(ImmutableSet.copyOf(componentIds.subList(0, Math.min(componentIds.size(), DatabaseUtils.PARTITION_SIZE_FOR_ORACLE))))
+ .setComponentUuids(ImmutableSet.copyOf(componentUuids.subList(0, Math.min(componentUuids.size(), DatabaseUtils.PARTITION_SIZE_FOR_ORACLE))))
.build();
return new ProjectsResult(
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
index 9b8f7075808..d7047a6e379 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
@@ -137,24 +137,24 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
private void updatePermissionsToPrivate(DbSession dbSession, ComponentDto component) {
// delete project permissions for group AnyOne
- dbClient.groupPermissionDao().deleteByRootComponentIdAndGroupId(dbSession, component.getId(), null);
+ dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupId(dbSession, component.uuid(), null);
// grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project
PUBLIC_PERMISSIONS.forEach(permission -> {
- dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission)
+ dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission)
.forEach(groupId -> insertProjectPermissionOnGroup(dbSession, component, permission, groupId));
- dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission)
+ dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission)
.forEach(userId -> insertProjectPermissionOnUser(dbSession, component, permission, userId));
});
}
private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, Integer userId) {
- dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(component.getOrganizationUuid(), permission, userId, component.getId()));
+ dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(component.getOrganizationUuid(), permission, userId, component.uuid()));
}
private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, Integer groupId) {
dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto()
.setOrganizationUuid(component.getOrganizationUuid())
- .setResourceId(component.getId())
+ .setComponentUuid(component.uuid())
.setGroupId(groupId)
.setRole(permission));
}
@@ -162,9 +162,9 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
private void updatePermissionsToPublic(DbSession dbSession, ComponentDto component) {
PUBLIC_PERMISSIONS.forEach(permission -> {
// delete project group permission for UserRole.CODEVIEWER and UserRole.USER
- dbClient.groupPermissionDao().deleteByRootComponentIdAndPermission(dbSession, component.getId(), permission);
+ dbClient.groupPermissionDao().deleteByRootComponentUuidAndPermission(dbSession, component.uuid(), permission);
// delete project user permission for UserRole.CODEVIEWER and UserRole.USER
- dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.getId(), permission);
+ dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.uuid(), permission);
});
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
index 2285db6964e..0a878750e82 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
@@ -23,13 +23,11 @@ import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
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.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID;
import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
@@ -55,14 +53,11 @@ public class DeselectAction implements QualityGatesWsAction {
.setPost(true)
.setSince("4.3")
.setHandler(this)
- .setChangelog(new Change("6.6", "The parameter 'gateId' was removed"));
-
- action.createParam(PARAM_PROJECT_ID)
- .setDescription("Project id")
- .setDeprecatedSince("6.1")
- .setExampleValue(Uuids.UUID_EXAMPLE_01);
+ .setChangelog(new Change("6.6", "The parameter 'gateId' was removed"),
+ new Change("8.3", "The parameter 'projectId' was removed"));
action.createParam(PARAM_PROJECT_KEY)
+ .setRequired(true)
.setDescription("Project key")
.setExampleValue(KEY_PROJECT_EXAMPLE_001)
.setSince("6.1");
@@ -74,7 +69,7 @@ public class DeselectAction implements QualityGatesWsAction {
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
- ProjectDto project = wsSupport.getProject(dbSession, organization, request.param(PARAM_PROJECT_KEY), request.param(PARAM_PROJECT_ID));
+ ProjectDto project = wsSupport.getProject(dbSession, organization, request.mandatoryParam(PARAM_PROJECT_KEY));
dissociateProject(dbSession, organization, project);
response.noContent();
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
index 55fdd97c354..d1d867f5661 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
@@ -45,8 +45,6 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_
import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
public class QualityGatesWsSupport {
@@ -124,31 +122,12 @@ public class QualityGatesWsSupport {
throw insufficientPrivilegesException();
}
- ProjectDto getProject(DbSession dbSession, OrganizationDto organization, @Nullable String projectKey, @Nullable String projectId) {
- ProjectDto project;
- if (projectId != null) {
- project = getProjectById(dbSession, projectId);
- } else if (projectKey != null) {
- project = componentFinder.getProjectByKey(dbSession, projectKey);
- } else {
- throw new IllegalArgumentException(String.format("Must specify %s or %s", PARAM_PROJECT_KEY, PARAM_PROJECT_ID));
- }
-
+ ProjectDto getProject(DbSession dbSession, OrganizationDto organization, String projectKey) {
+ ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
checkProjectBelongsToOrganization(organization, project);
return project;
}
- ProjectDto getProjectById(DbSession dbSession, String projectId) {
- try {
- long dbId = Long.parseLong(projectId);
- return dbClient.componentDao().selectById(dbSession, dbId)
- .flatMap(c -> dbClient.projectDao().selectByUuid(dbSession, c.uuid()))
- .orElseThrow(() -> new NotFoundException(String.format("Project '%s' not found", projectId)));
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Invalid id: " + projectId);
- }
- }
-
void checkProjectBelongsToOrganization(OrganizationDto organization, ProjectDto project) {
if (project.getOrganizationUuid().equals(organization.getUuid())) {
return;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java
index 5fba0af7cd0..8316e65bf6b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java
@@ -126,7 +126,6 @@ public class SearchAction implements QualityGatesWsAction {
for (ProjectQgateAssociationDto project : paginatedProjects) {
createResponse.addResultsBuilder()
- .setId(project.getId())
.setName(project.getName())
.setKey(project.getKey())
.setSelected(project.getGateId() != null);
@@ -147,8 +146,8 @@ public class SearchAction implements QualityGatesWsAction {
// Meanwhile root is explicitly handled.
return projects;
}
- List<Long> projectIds = projects.stream().map(ProjectQgateAssociationDto::getId).collect(MoreCollectors.toList());
- Collection<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(dbSession, projectIds, userSession.getUserId(), UserRole.USER);
- return projects.stream().filter(project -> authorizedProjectIds.contains(project.getId())).collect(MoreCollectors.toList());
+ List<String> projectUuids = projects.stream().map(ProjectQgateAssociationDto::getUuid).collect(MoreCollectors.toList());
+ Collection<String> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectUuids(dbSession, projectUuids, userSession.getUserId(), UserRole.USER);
+ return projects.stream().filter(project -> authorizedProjectIds.contains(project.getUuid())).collect(MoreCollectors.toList());
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java
index b1ed5c3b8a2..6d96aa4e49f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java
@@ -19,10 +19,10 @@
*/
package org.sonar.server.qualitygate.ws;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
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.organization.OrganizationDto;
@@ -32,7 +32,6 @@ import org.sonar.db.qualitygate.QualityGateDto;
import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_SELECT;
import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_ID;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID;
import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
@@ -49,29 +48,23 @@ public class SelectAction implements QualityGatesWsAction {
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction(ACTION_SELECT)
.setDescription("Associate a project to a quality gate.<br>" +
- "The '%s' or '%s' must be provided.<br>" +
- "Project id as a numeric value is deprecated since 6.1. Please use the id similar to '%s'.<br>" +
- "Requires one of the following permissions:" +
- "<ul>" +
- " <li>'Administer Quality Gates'</li>" +
- " <li>'Administer' right on the specified project</li>" +
- "</ul>",
- PARAM_PROJECT_ID, PARAM_PROJECT_KEY,
- Uuids.UUID_EXAMPLE_02)
+ "Requires one of the following permissions:" +
+ "<ul>" +
+ " <li>'Administer Quality Gates'</li>" +
+ " <li>'Administer' right on the specified project</li>" +
+ "</ul>")
.setPost(true)
.setSince("4.3")
- .setHandler(this);
+ .setHandler(this)
+ .setChangelog(new Change("8.3", "The parameter 'projectId' was removed"));
action.createParam(PARAM_GATE_ID)
.setDescription("Quality gate id")
.setRequired(true)
.setExampleValue("1");
- action.createParam(PARAM_PROJECT_ID)
- .setDescription("Project id. Project id as an numeric value is deprecated since 6.1")
- .setExampleValue(Uuids.UUID_EXAMPLE_01);
-
action.createParam(PARAM_PROJECT_KEY)
+ .setRequired(true)
.setDescription("Project key")
.setExampleValue(KEY_PROJECT_EXAMPLE_001)
.setSince("6.1");
@@ -82,13 +75,12 @@ public class SelectAction implements QualityGatesWsAction {
@Override
public void handle(Request request, Response response) {
long gateId = request.mandatoryParamAsLong(PARAM_GATE_ID);
- String projectKey = request.param(PARAM_PROJECT_KEY);
- String projectId = request.param(PARAM_PROJECT_ID);
+ String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, gateId);
- ProjectDto project = wsSupport.getProject(dbSession, organization, projectKey, projectId);
+ ProjectDto project = wsSupport.getProject(dbSession, organization, projectKey);
wsSupport.checkCanAdminProject(organization, project);
QualityGateDto currentQualityGate = dbClient.qualityGateDao().selectByProjectUuid(dbSession, project.getUuid());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
index f3ce6aa089a..fbc75675971 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
@@ -175,16 +175,16 @@ public class SetAction implements SettingsWsAction {
int[] fieldIds = IntStream.rangeClosed(1, request.getFieldValues().size()).toArray();
String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER);
String key = persistedKey(request);
- Long componentId = component.isPresent() ? component.get().getId() : null;
+ String componentUuid = component.isPresent() ? component.get().uuid() : null;
deleteSettings(dbSession, component, key);
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setResourceId(componentId));
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setComponentUuid(componentUuid));
List<String> fieldValues = request.getFieldValues();
IntStream.of(fieldIds).boxed()
.flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream()
.map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue())))
- .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentId)));
+ .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid)));
return inlinedFieldKeys;
}
@@ -321,14 +321,14 @@ public class SetAction implements SettingsWsAction {
.setValue(value);
if (component.isPresent()) {
- property.setResourceId(component.get().getId());
+ property.setComponentUuid(component.get().uuid());
}
return property;
}
- private static PropertyDto toFieldProperty(KeyValue keyValue, @Nullable Long componentId) {
- return new PropertyDto().setKey(keyValue.key).setValue(keyValue.value).setResourceId(componentId);
+ private static PropertyDto toFieldProperty(KeyValue keyValue, @Nullable String componentUuid) {
+ return new PropertyDto().setKey(keyValue.key).setValue(keyValue.value).setComponentUuid(componentUuid);
}
private static class KeyValue {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java
index 777c9cdaaa4..3341172148e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java
@@ -35,7 +35,7 @@ public class Setting {
private static final Splitter DOT_SPLITTER = Splitter.on(".").omitEmptyStrings();
private final String key;
- private final Long componentId;
+ private final String componentUuid;
private final String value;
private final PropertyDefinition definition;
private final List<Map<String, String>> propertySets;
@@ -44,7 +44,7 @@ public class Setting {
private Setting(PropertyDto propertyDto, List<PropertyDto> propertyDtoSetValues, @Nullable PropertyDefinition definition) {
this.key = propertyDto.getKey();
this.value = propertyDto.getValue();
- this.componentId = propertyDto.getResourceId();
+ this.componentUuid = propertyDto.getComponentUuid();
this.definition = definition;
this.propertySets = buildPropertySetValuesAsMap(key, propertyDtoSetValues);
this.isDefault = false;
@@ -53,7 +53,7 @@ public class Setting {
private Setting(PropertyDefinition definition) {
this.key = definition.key();
this.value = definition.defaultValue();
- this.componentId = null;
+ this.componentUuid = null;
this.definition = definition;
this.propertySets = Collections.emptyList();
this.isDefault = true;
@@ -72,8 +72,8 @@ public class Setting {
}
@CheckForNull
- public Long getComponentId() {
- return componentId;
+ public String getComponentUuid() {
+ return componentUuid;
}
@CheckForNull
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java
index 3b9ebef289e..7ee450d8007 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java
@@ -75,7 +75,7 @@ public class SettingsUpdater {
private void deleteSetting(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) {
if (componentDto.isPresent()) {
- dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().getId(), dbSession);
+ dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().uuid(), dbSession);
} else {
dbClient.propertiesDao().deleteGlobalProperty(settingKey, dbSession);
}
@@ -96,7 +96,7 @@ public class SettingsUpdater {
private Optional<PropertyDto> selectPropertyDto(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) {
if (componentDto.isPresent()) {
- return Optional.ofNullable(dbClient.propertiesDao().selectProjectProperty(dbSession, componentDto.get().getId(), settingKey));
+ return Optional.ofNullable(dbClient.propertiesDao().selectProjectProperty(dbSession, componentDto.get().uuid(), settingKey));
} else {
return Optional.ofNullable(dbClient.propertiesDao().selectGlobalProperty(dbSession, settingKey));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
index 491f1378b1d..b67461aad13 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
@@ -85,7 +85,7 @@ public class ValuesAction implements SettingsWsAction {
private final boolean isSonarCloud;
public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions,
- SettingsWsSupport settingsWsSupport, Configuration configuration) {
+ SettingsWsSupport settingsWsSupport, Configuration configuration) {
this.dbClient = dbClient;
this.componentFinder = componentFinder;
this.userSession = userSession;
@@ -215,19 +215,15 @@ public class ValuesAction implements SettingsWsAction {
*/
private Multimap<String, Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, ComponentDto component) {
List<String> componentUuids = DOT_SPLITTER.splitToList(component.moduleUuidPath());
- List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids);
- Set<Long> componentIds = componentDtos.stream().map(ComponentDto::getId).collect(Collectors.toSet());
- Map<Long, String> uuidsById = componentDtos.stream().collect(Collectors.toMap(ComponentDto::getId, ComponentDto::uuid));
- List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, keys, componentIds);
- List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, getPropertySetKeys(properties), componentIds);
+ List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, keys, componentUuids);
+ List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, getPropertySetKeys(properties), componentUuids);
Multimap<String, Setting> settingsByUuid = TreeMultimap.create(Ordering.explicit(componentUuids), Ordering.arbitrary());
for (PropertyDto propertyDto : properties) {
- Long componentId = propertyDto.getResourceId();
- String componentUuid = uuidsById.get(componentId);
+ String componentUuid = propertyDto.getComponentUuid();
String propertyKey = propertyDto.getKey();
settingsByUuid.put(componentUuid,
- Setting.createFromDto(propertyDto, getPropertySets(propertyKey, propertySets, componentId), propertyDefinitions.get(propertyKey)));
+ Setting.createFromDto(propertyDto, getPropertySets(propertyKey, propertySets, componentUuid), propertyDefinitions.get(propertyKey)));
}
return settingsByUuid;
}
@@ -240,9 +236,9 @@ public class ValuesAction implements SettingsWsAction {
.collect(Collectors.toSet());
}
- private static List<PropertyDto> getPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable Long componentId) {
+ private static List<PropertyDto> getPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable String componentUuid) {
return propertySets.stream()
- .filter(propertyDto -> Objects.equals(propertyDto.getResourceId(), componentId))
+ .filter(propertyDto -> Objects.equals(propertyDto.getComponentUuid(), componentUuid))
.filter(propertyDto -> propertyDto.getKey().startsWith(propertyKey + "."))
.collect(Collectors.toList());
}
@@ -284,7 +280,7 @@ public class ValuesAction implements SettingsWsAction {
private void setInherited(Setting setting, Settings.Setting.Builder valueBuilder) {
boolean isDefault = setting.isDefault();
boolean isGlobal = !requestedComponent.isPresent();
- boolean isOnComponent = requestedComponent.isPresent() && Objects.equals(setting.getComponentId(), requestedComponent.get().getId());
+ boolean isOnComponent = requestedComponent.isPresent() && Objects.equals(setting.getComponentUuid(), requestedComponent.get().uuid());
boolean isSet = isGlobal || isOnComponent;
valueBuilder.setInherited(isDefault || !isSet);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
index 933847203ef..83011027ea9 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
@@ -245,7 +245,7 @@ public class ComponentAction implements NavigationWsAction {
PropertyQuery propertyQuery = PropertyQuery.builder()
.setUserId(userSession.getUserId())
.setKey("favourite")
- .setComponentId(component.getId())
+ .setComponentUuid(component.uuid())
.build();
List<PropertyDto> componentFavourites = dbClient.propertiesDao().selectByQuery(propertyQuery, session);
return componentFavourites.size() == 1;
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json
index 97332a0480b..97637865c4e 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json
@@ -6,13 +6,11 @@
},
"results": [
{
- "id": 1,
"name": "Simple Java project analyzed with the SonarQube Runner",
"key": "somple-java",
"selected": true
},
{
- "id": 4,
"name": "My Project",
"key": "my-project",
"selected": false
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
index 642565c60c1..ec39c563d4e 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
@@ -1180,7 +1180,7 @@ public class SearchProjectsActionTest {
}
private void addFavourite(ComponentDto project) {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(userSession.getUserId()));
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(userSession.getUserId()));
dbSession.commit();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
index 67729fcf944..8f1238b4d5d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
@@ -399,7 +399,7 @@ public class SuggestionsActionTest {
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
- db.getDbClient().componentDao().delete(db.getSession(), project.getId());
+ db.getDbClient().componentDao().delete(db.getSession(), project.uuid());
db.commit();
SuggestionsWsResponse response = ws.newRequest()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java
index fe01076c628..57c97bb768a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java
@@ -84,8 +84,8 @@ public class AddActionTest {
assertThat(favorites).hasSize(1);
PropertyDto favorite = favorites.get(0);
assertThat(favorite)
- .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey)
- .containsOnly(project.getId(), user.getId(), "favourite");
+ .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getKey)
+ .containsOnly(project.uuid(), user.getId(), "favourite");
}
@Test
@@ -104,8 +104,8 @@ public class AddActionTest {
assertThat(favorites).hasSize(1);
PropertyDto favorite = favorites.get(0);
assertThat(favorite)
- .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey)
- .containsOnly(file.getId(), user.getId(), "favourite");
+ .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getKey)
+ .containsOnly(file.uuid(), user.getId(), "favourite");
}
@Test
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 7b1b0a68cc4..818684e3b97 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
@@ -70,9 +70,9 @@ public class WebIssueStorageTest {
ComponentDto project = db.components().insertPrivateProject(organizationDto);
ComponentDto file = db.components().insertComponent(newFileDto(project));
- long componentId = underTest.component(db.getSession(), new DefaultIssue().setComponentUuid(file.uuid())).getId();
+ String componentUuid = underTest.component(db.getSession(), new DefaultIssue().setComponentUuid(file.uuid())).uuid();
- assertThat(componentId).isEqualTo(file.getId());
+ assertThat(componentUuid).isEqualTo(file.uuid());
}
@Test
@@ -81,9 +81,9 @@ public class WebIssueStorageTest {
ComponentDto project = db.components().insertPrivateProject(organizationDto);
ComponentDto file = db.components().insertComponent(newFileDto(project));
- long projectId = underTest.project(db.getSession(), new DefaultIssue().setProjectUuid(project.uuid())).getId();
+ String projectUuid = underTest.project(db.getSession(), new DefaultIssue().setProjectUuid(project.uuid())).uuid();
- assertThat(projectId).isEqualTo(project.getId());
+ assertThat(projectUuid).isEqualTo(project.uuid());
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
index 396b09db19b..68ba8cc8037 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
@@ -1023,7 +1023,7 @@ public class SearchActionTest {
new GroupPermissionDto()
.setOrganizationUuid(project.getOrganizationUuid())
.setGroupId(null)
- .setResourceId(project.getId())
+ .setComponentUuid(project.uuid())
.setRole(permission));
session.commit();
userSession.logIn().addProjectPermission(permission, project);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
index 81f2368c762..a6cd4be7af0 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
@@ -92,7 +92,7 @@ public class GroupPermissionChangerTest {
permissionService.getAllProjectPermissions()
.forEach(perm -> {
try {
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectId(privateProject), anyOneGroupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService));
fail("a BadRequestException should have been thrown");
} catch (BadRequestException e) {
assertThat(e).hasMessage("No permission can be granted to Anyone on a private component");
@@ -108,7 +108,7 @@ public class GroupPermissionChangerTest {
GroupIdOrAnyone anyOneGroupId = GroupIdOrAnyone.forAnyone(org.getUuid());
permissionService.getAllProjectPermissions()
.forEach(perm -> {
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectId(privateProject), anyOneGroupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService));
assertThat(db.users().selectAnyonePermissions(org, privateProject)).contains(perm);
});
@@ -142,7 +142,7 @@ public class GroupPermissionChangerTest {
private void applyAddsPermissionToGroupOnPrivateProject(String permission) {
GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group);
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(privateProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService));
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty();
assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(permission);
@@ -177,7 +177,7 @@ public class GroupPermissionChangerTest {
GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group);
db.users().insertProjectPermissionOnGroup(group, permission, privateProject);
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(privateProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService));
assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(permission);
}
@@ -186,7 +186,7 @@ public class GroupPermissionChangerTest {
public void apply_has_no_effect_when_adding_USER_permission_to_group_AnyOne_on_a_public_project() {
GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid());
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService));
assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty();
}
@@ -195,7 +195,7 @@ public class GroupPermissionChangerTest {
public void apply_has_no_effect_when_adding_CODEVIEWER_permission_to_group_AnyOne_on_a_public_project() {
GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid());
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService));
assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty();
}
@@ -207,14 +207,14 @@ public class GroupPermissionChangerTest {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("It is not possible to add the 'admin' permission to group 'Anyone'");
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ADMIN, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ADMIN, new ProjectUuid(publicProject), groupId, permissionService));
}
@Test
public void apply_adds_permission_ISSUE_ADMIN_to_group_AnyOne_on_a_public_project() {
GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid());
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectUuid(publicProject), groupId, permissionService));
assertThat(db.users().selectAnyonePermissions(org, publicProject)).containsOnly(UserRole.ISSUE_ADMIN);
}
@@ -223,7 +223,7 @@ public class GroupPermissionChangerTest {
public void apply_adds_permission_SCAN_EXECUTION_to_group_AnyOne_on_a_public_project() {
GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid());
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectUuid(publicProject), groupId, permissionService));
assertThat(db.users().selectAnyonePermissions(org, publicProject)).containsOnly(GlobalPermissions.SCAN_EXECUTION);
}
@@ -235,7 +235,7 @@ public class GroupPermissionChangerTest {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Permission user can't be removed from a public component");
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService));
}
@Test
@@ -245,7 +245,7 @@ public class GroupPermissionChangerTest {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Permission codeviewer can't be removed from a public component");
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService));
}
@Test
@@ -267,7 +267,7 @@ public class GroupPermissionChangerTest {
GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid());
db.users().insertProjectPermissionOnAnyone(permission, publicProject);
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectUuid(publicProject), groupId, permissionService));
assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty();
}
@@ -279,7 +279,7 @@ public class GroupPermissionChangerTest {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Permission user can't be removed from a public component");
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService));
}
@Test
@@ -289,7 +289,7 @@ public class GroupPermissionChangerTest {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Permission codeviewer can't be removed from a public component");
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService));
}
@Test
@@ -322,7 +322,7 @@ public class GroupPermissionChangerTest {
.filter(perm -> !UserRole.ADMIN.equals(perm) && !GlobalPermissions.SCAN_EXECUTION.equals(perm))
.forEach(perm -> {
try {
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectId(privateProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), groupId, permissionService));
fail("a BadRequestException should have been thrown for permission " + perm);
} catch (BadRequestException e) {
assertThat(e).hasMessage("Invalid project permission '" + perm +
@@ -340,7 +340,7 @@ public class GroupPermissionChangerTest {
.filter(perm -> !UserRole.ADMIN.equals(perm) && !GlobalPermissions.SCAN_EXECUTION.equals(perm))
.forEach(perm -> {
try {
- apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectId(publicProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(publicProject), groupId, permissionService));
fail("a BadRequestException should have been thrown for permission " + perm);
} catch (BadRequestException e) {
assertThat(e).hasMessage("Invalid project permission '" + perm +
@@ -384,7 +384,7 @@ public class GroupPermissionChangerTest {
db.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, privateProject);
db.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, privateProject);
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectId(privateProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService));
assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(ADMINISTER_QUALITY_GATES.getKey());
assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(UserRole.CODEVIEWER);
@@ -394,7 +394,7 @@ public class GroupPermissionChangerTest {
public void do_not_fail_if_removing_a_permission_that_does_not_exist() {
GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group);
- apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectId(privateProject), groupId, permissionService));
+ apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService));
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty();
assertThat(db.users().selectGroupPermissions(group, privateProject)).isEmpty();
@@ -433,7 +433,7 @@ public class GroupPermissionChangerTest {
.setOrganizationUuid(privateProject.getOrganizationUuid())
.setGroupId(null)
.setRole(perm)
- .setResourceId(privateProject.getId());
+ .setComponentUuid(privateProject.uuid());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
index ebab1802102..47b4464b759 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
@@ -435,12 +435,12 @@ public class PermissionTemplateServiceTest {
private List<String> selectProjectPermissionsOfGroup(OrganizationDto organizationDto, @Nullable GroupDto groupDto, ComponentDto project) {
return dbTester.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(session,
- organizationDto.getUuid(), groupDto != null ? groupDto.getId() : null, project.getId());
+ organizationDto.getUuid(), groupDto != null ? groupDto.getId() : null, project.uuid());
}
private List<String> selectProjectPermissionsOfUser(UserDto userDto, ComponentDto project) {
return dbTester.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(session,
- userDto.getId(), project.getId());
+ userDto.getId(), project.uuid());
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
index 7b25434bf9d..debbf6a23e3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
@@ -110,7 +110,7 @@ public class UserPermissionChangerTest {
@Test
public void apply_has_no_effect_when_adding_permission_USER_on_a_public_project() {
- UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), USER, new ProjectId(publicProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), USER, new ProjectUuid(publicProject), UserId.from(user1), permissionService);
apply(change);
@@ -119,7 +119,7 @@ public class UserPermissionChangerTest {
@Test
public void apply_has_no_effect_when_adding_permission_CODEVIEWER_on_a_public_project() {
- UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), CODEVIEWER, new ProjectId(publicProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), CODEVIEWER, new ProjectUuid(publicProject), UserId.from(user1), permissionService);
apply(change);
@@ -142,7 +142,7 @@ public class UserPermissionChangerTest {
}
private void applyAddsPermissionOnAPublicProject(String permission) {
- UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectId(publicProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectUuid(publicProject), UserId.from(user1), permissionService);
apply(change);
@@ -151,7 +151,7 @@ public class UserPermissionChangerTest {
@Test
public void apply_fails_with_BadRequestException_when_removing_permission_USER_from_a_public_project() {
- UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), USER, new ProjectId(publicProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), USER, new ProjectUuid(publicProject), UserId.from(user1), permissionService);
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Permission user can't be removed from a public component");
@@ -161,7 +161,7 @@ public class UserPermissionChangerTest {
@Test
public void apply_fails_with_BadRequestException_when_removing_permission_CODEVIEWER_from_a_public_project() {
- UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), CODEVIEWER, new ProjectId(publicProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), CODEVIEWER, new ProjectUuid(publicProject), UserId.from(user1), permissionService);
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Permission codeviewer can't be removed from a public component");
@@ -186,7 +186,7 @@ public class UserPermissionChangerTest {
private void applyRemovesPermissionFromPublicProject(String permission) {
db.users().insertProjectPermissionOnUser(user1, permission, publicProject);
- UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectId(publicProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectUuid(publicProject), UserId.from(user1), permissionService);
apply(change);
@@ -197,7 +197,7 @@ public class UserPermissionChangerTest {
public void apply_adds_any_permission_to_a_private_project() {
permissionService.getAllProjectPermissions()
.forEach(permission -> {
- UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectId(privateProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectUuid(privateProject), UserId.from(user1), permissionService);
apply(change);
@@ -212,7 +212,7 @@ public class UserPermissionChangerTest {
permissionService.getAllProjectPermissions()
.forEach(permission -> {
- UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectId(privateProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectUuid(privateProject), UserId.from(user1), permissionService);
apply(change);
@@ -235,7 +235,7 @@ public class UserPermissionChangerTest {
@Test
public void add_project_permission_to_user() {
- UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), ISSUE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), ISSUE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService);
apply(change);
assertThat(db.users().selectPermissionsOfUser(user1, org1)).isEmpty();
@@ -259,7 +259,7 @@ public class UserPermissionChangerTest {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Invalid project permission 'gateadmin'. Valid values are [" + StringUtils.join(permissionService.getAllProjectPermissions(), ", ") + "]");
- UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), QUALITY_GATE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), QUALITY_GATE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService);
apply(change);
}
@@ -298,7 +298,7 @@ public class UserPermissionChangerTest {
db.users().insertProjectPermissionOnUser(user2, ISSUE_ADMIN, privateProject);
db.users().insertProjectPermissionOnUser(user1, ISSUE_ADMIN, project2);
- UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService);
apply(change);
assertThat(db.users().selectProjectPermissionsOfUser(user1, privateProject)).containsOnly(USER);
@@ -316,7 +316,7 @@ public class UserPermissionChangerTest {
@Test
public void do_not_fail_if_removing_a_project_permission_that_does_not_exist() {
- UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService);
+ UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService);
apply(change);
assertThat(db.users().selectProjectPermissionsOfUser(user1, privateProject)).isEmpty();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
index 3af904b1416..36a2b9e980e 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
@@ -476,7 +476,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
.setOrganizationUuid(project.getOrganizationUuid())
.setGroupId(null)
.setRole(perm)
- .setResourceId(project.getId());
+ .setComponentUuid(project.uuid());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
index 3eb08cff46b..36247e218b3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
@@ -468,11 +468,11 @@ public class UpdateVisibilityActionTest {
.setParam(PARAM_VISIBILITY, PRIVATE)
.execute();
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user1.getId(), project.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user1.getId(), project.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p1", "p2");
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user2.getId(), project.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user2.getId(), project.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p2");
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user3.getId(), project.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user3.getId(), project.uuid()))
.isEmpty();
}
@@ -492,11 +492,11 @@ public class UpdateVisibilityActionTest {
.setParam(PARAM_VISIBILITY, PRIVATE)
.execute();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p1", "p2");
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p2");
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group3.getId(), project.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group3.getId(), project.uuid()))
.isEmpty();
}
@@ -515,9 +515,9 @@ public class UpdateVisibilityActionTest {
.execute();
assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isTrue();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN);
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN);
}
@@ -540,9 +540,9 @@ public class UpdateVisibilityActionTest {
.execute();
assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid()))
.containsOnly(UserRole.ISSUE_ADMIN);
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid()))
.containsOnly(UserRole.ADMIN);
}
@@ -561,9 +561,9 @@ public class UpdateVisibilityActionTest {
.execute();
assertThat(dbClient.componentDao().selectByUuid(dbSession, application.uuid()).get().isPrivate()).isTrue();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), application.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), application.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN);
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), application.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), application.uuid()))
.containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN);
}
@@ -586,9 +586,9 @@ public class UpdateVisibilityActionTest {
.execute();
assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid()))
.containsOnly(UserRole.ISSUE_ADMIN);
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid()))
.containsOnly(UserRole.ADMIN);
}
@@ -658,7 +658,7 @@ public class UpdateVisibilityActionTest {
.setOrganizationUuid(component.getOrganizationUuid())
.setGroupId(null)
.setRole(permission)
- .setResourceId(component.getId());
+ .setComponentUuid(component.uuid());
dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto);
dbTester.commit();
}
@@ -668,13 +668,13 @@ public class UpdateVisibilityActionTest {
.setOrganizationUuid(group.getOrganizationUuid())
.setGroupId(group.getId())
.setRole(permission)
- .setResourceId(component.getId());
+ .setComponentUuid(component.uuid());
dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto);
dbTester.commit();
}
private void unsafeInsertProjectPermissionOnUser(ComponentDto component, UserDto user, String permission) {
- UserPermissionDto dto = new UserPermissionDto(component.getOrganizationUuid(), permission, user.getId(), component.getId());
+ UserPermissionDto dto = new UserPermissionDto(component.getOrganizationUuid(), permission, user.getId(), component.uuid());
dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto);
dbTester.commit();
}
@@ -686,11 +686,11 @@ public class UpdateVisibilityActionTest {
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET);
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid()))
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET);
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid()))
.isEmpty();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid()))
.containsAll(permissionService.getAllProjectPermissions());
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid()))
.containsAll(permissionService.getAllProjectPermissions());
}
@@ -701,15 +701,15 @@ public class UpdateVisibilityActionTest {
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET);
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid()))
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET);
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid()))
.doesNotContain(UserRole.USER)
.doesNotContain(UserRole.CODEVIEWER)
.containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER);
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid()))
.doesNotContain(UserRole.USER)
.doesNotContain(UserRole.CODEVIEWER)
.containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER);
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid()))
.doesNotContain(UserRole.USER)
.doesNotContain(UserRole.CODEVIEWER)
.containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER);
@@ -722,11 +722,11 @@ public class UpdateVisibilityActionTest {
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET);
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid()))
.containsAll(ORGANIZATION_PERMISSIONS_NAME_SET);
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid()))
.containsAll(permissionService.getAllProjectPermissions());
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.getId()))
+ assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid()))
.containsAll(permissionService.getAllProjectPermissions());
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.getId()))
+ assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid()))
.containsAll(permissionService.getAllProjectPermissions());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
index a52af6442d3..a9c76ab314a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
@@ -42,7 +42,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.assertj.core.api.Assertions.tuple;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES;
@@ -147,19 +146,6 @@ public class DeselectActionTest {
}
@Test
- public void fail_when_no_project_id() {
- OrganizationDto organization = db.organizations().insert();
- userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
-
- expectedException.expect(NotFoundException.class);
-
- ws.newRequest()
- .setParam("projectId", valueOf((Long) 1L))
- .setParam("organization", organization.getKey())
- .execute();
- }
-
- @Test
public void fail_when_no_project_key() {
OrganizationDto organization = db.organizations().insert();
userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
@@ -232,22 +218,6 @@ public class DeselectActionTest {
}
@Test
- public void fail_when_using_branch_id() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
- userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
-
- expectedException.expect(NotFoundException.class);
- expectedException.expectMessage(format("Project '%s' not found", branch.getId()));
-
- ws.newRequest()
- .setParam("projectId", String.valueOf(branch.getId()))
- .setParam("organization", organization.getKey())
- .execute();
- }
-
- @Test
public void definition() {
WebService.Action def = ws.getDef();
@@ -255,13 +225,13 @@ public class DeselectActionTest {
assertThat(def.isPost()).isTrue();
assertThat(def.since()).isEqualTo("4.3");
assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactly(
- tuple("6.6", "The parameter 'gateId' was removed"));
+ tuple("6.6", "The parameter 'gateId' was removed"),
+ tuple("8.3", "The parameter 'projectId' was removed"));
assertThat(def.params())
.extracting(WebService.Param::key, WebService.Param::isRequired)
.containsExactlyInAnyOrder(
- tuple("projectKey", false),
- tuple("projectId", false),
+ tuple("projectKey", true),
tuple("organization", false));
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java
index 7b718f573f0..b3a569d29f4 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java
@@ -84,8 +84,8 @@ public class SearchActionTest {
.executeProtobuf(SearchResponse.class);
assertThat(response.getResultsList())
- .extracting(Result::getId, Result::getKey, Result::getName)
- .containsExactlyInAnyOrder(tuple(project.getId(), project.getKey(), project.name()));
+ .extracting(Result::getKey, Result::getName)
+ .containsExactlyInAnyOrder(tuple(project.getKey(), project.name()));
}
@Test
@@ -100,8 +100,8 @@ public class SearchActionTest {
.executeProtobuf(SearchResponse.class);
assertThat(response.getResultsList())
- .extracting(Result::getId, Result::getName)
- .containsExactlyInAnyOrder(tuple(project.getId(), project.name()));
+ .extracting(Result::getKey, Result::getName)
+ .containsExactlyInAnyOrder(tuple(project.getKey(), project.name()));
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java
index 6fc1b274231..30a51c956e5 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java
@@ -481,7 +481,7 @@ public class ResetActionTest {
}
private void assertProjectPropertyDoesNotExist(ComponentDto component, String key) {
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(component.getId()).setKey(key).build(), dbSession)).isEmpty();
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(component.uuid()).setKey(key).build(), dbSession)).isEmpty();
}
private void assertProjectPropertyDoesNotExist(String key) {
@@ -489,7 +489,7 @@ public class ResetActionTest {
}
private void assertProjectPropertyExists(String key) {
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isNotEmpty();
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).setKey(key).build(), dbSession)).isNotEmpty();
}
private void assertUserPropertyExists(String key, UserDto user) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
index 734869d66f9..ac26830ad8c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
@@ -145,7 +145,7 @@ public class SetActionTest {
callForProjectSettingByKey("my.key", "my project value", project.getDbKey());
assertGlobalSetting("my.key", "my global value");
- assertComponentSetting("my.key", "my project value", project.getId());
+ assertComponentSetting("my.key", "my project value", project.uuid());
assertThat(settingsChangeNotifier.wasCalled).isFalse();
}
@@ -156,7 +156,7 @@ public class SetActionTest {
callForProjectSettingByKey("my.key", "my value", project.getDbKey());
- assertComponentSetting("my.key", "my value", project.getId());
+ assertComponentSetting("my.key", "my value", project.uuid());
}
@Test
@@ -164,12 +164,12 @@ public class SetActionTest {
propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
ComponentDto project = db.components().insertPrivateProject();
propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project));
- assertComponentSetting("my.key", "my project value", project.getId());
+ assertComponentSetting("my.key", "my project value", project.uuid());
logInAsProjectAdministrator(project);
callForProjectSettingByKey("my.key", "my new project value", project.getDbKey());
- assertComponentSetting("my.key", "my new project value", project.getId());
+ assertComponentSetting("my.key", "my new project value", project.uuid());
}
@Test
@@ -313,12 +313,12 @@ public class SetActionTest {
assertGlobalSetting("my.key", "1");
assertGlobalSetting("my.key.1.firstField", "oldFirstValue");
assertGlobalSetting("my.key.1.secondField", "oldSecondValue");
- Long projectId = project.getId();
- assertComponentSetting("my.key", "1,2", projectId);
- assertComponentSetting("my.key.1.firstField", "firstValue", projectId);
- assertComponentSetting("my.key.1.secondField", "secondValue", projectId);
- assertComponentSetting("my.key.2.firstField", "anotherFirstValue", projectId);
- assertComponentSetting("my.key.2.secondField", "anotherSecondValue", projectId);
+ String projectUuid = project.uuid();
+ assertComponentSetting("my.key", "1,2", projectUuid);
+ assertComponentSetting("my.key.1.firstField", "firstValue", projectUuid);
+ assertComponentSetting("my.key.1.secondField", "secondValue", projectUuid);
+ assertComponentSetting("my.key.2.firstField", "anotherFirstValue", projectUuid);
+ assertComponentSetting("my.key.2.secondField", "anotherSecondValue", projectUuid);
assertThat(settingsChangeNotifier.wasCalled).isFalse();
}
@@ -643,7 +643,7 @@ public class SetActionTest {
callForProjectSettingByKey("my.key", "My Value", module.getDbKey());
- assertComponentSetting("my.key", "My Value", module.getId());
+ assertComponentSetting("my.key", "My Value", module.uuid());
}
private void failForPropertyWithoutDefinitionOnUnsupportedComponent(ComponentDto root, ComponentDto component) {
@@ -962,7 +962,7 @@ public class SetActionTest {
PropertyDto result = dbClient.propertiesDao().selectGlobalProperty(key);
assertThat(result)
- .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getResourceId)
+ .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getComponentUuid)
.containsExactly(key, value, null);
}
@@ -974,13 +974,13 @@ public class SetActionTest {
.containsExactly(tuple(key, value, userId));
}
- private void assertComponentSetting(String key, String value, long componentId) {
- PropertyDto result = dbClient.propertiesDao().selectProjectProperty(componentId, key);
+ private void assertComponentSetting(String key, String value, String componentUuid) {
+ PropertyDto result = dbClient.propertiesDao().selectProjectProperty(componentUuid, key);
assertThat(result)
.isNotNull()
- .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getResourceId)
- .containsExactly(key, value, componentId);
+ .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getComponentUuid)
+ .containsExactly(key, value, componentUuid);
}
private void callForGlobalSetting(@Nullable String key, @Nullable String value) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java
index f41c559f670..6c04d4f67f0 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java
@@ -206,11 +206,11 @@ public class SettingsUpdaterTest {
}
private void assertProjectPropertyDoesNotExist(String key) {
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isEmpty();
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).setKey(key).build(), dbSession)).isEmpty();
}
private void assertProjectPropertyExists(String key) {
- assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isNotEmpty();
+ assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).setKey(key).build(), dbSession)).isNotEmpty();
}
private void assertUserPropertyExists(String key, UserDto user) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
index 0583bd29652..83d45a54bd5 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
@@ -147,7 +147,7 @@ public class ComponentActionTest {
public void return_component_info_with_favourite() {
ComponentDto project = insertOrganizationAndProject();
UserDto user = db.users().insertUser("obiwan");
- propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId()));
userSession.logIn(user).addProjectPermission(UserRole.USER, project);
init();
@@ -159,7 +159,7 @@ public class ComponentActionTest {
ComponentDto project = insertOrganizationAndProject();
ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz"));
UserDto user = db.users().insertUser("obiwan");
- propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId()));
userSession.logIn(user).addProjectPermission(UserRole.USER, project);
init();
@@ -606,7 +606,7 @@ public class ComponentActionTest {
componentDbTester.insertSnapshot(analysis);
when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType());
UserDto user = db.users().insertUser("obiwan");
- propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId()));
addQualityProfiles(project,
createQProfile("qp1", "Sonar Way Java", "java"),
createQProfile("qp2", "Sonar Way Xoo", "xoo"));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
index c2a5b06183a..d86d6bea0b3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
@@ -143,12 +143,12 @@ public class DeactivateActionTest {
ComponentDto project = db.components().insertPrivateProject();
db.properties().insertProperty(newUserPropertyDto(user));
db.properties().insertProperty(newUserPropertyDto(user));
- db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId()));
+ db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()));
deactivate(user.getLogin());
assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty();
- assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentId(project.getId()).build(), dbSession)).isEmpty();
+ assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentUuid(project.uuid()).build(), dbSession)).isEmpty();
}
@Test
@@ -164,7 +164,7 @@ public class DeactivateActionTest {
deactivate(user.getLogin());
assertThat(db.getDbClient().userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), db.getDefaultOrganization().getUuid())).isEmpty();
- assertThat(db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), project.getId())).isEmpty();
+ assertThat(db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).isEmpty();
}
@Test
@@ -201,9 +201,9 @@ public class DeactivateActionTest {
UserDto user = db.users().insertUser();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto anotherProject = db.components().insertPrivateProject();
- db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(project.getId()));
- db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(anotherProject.getId()));
- db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setResourceId(anotherProject.getId()));
+ db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(project.uuid()));
+ db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid()));
+ db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid()));
deactivate(user.getLogin());
diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
index a904acba911..9bddea9ed6b 100644
--- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto
+++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
@@ -140,7 +140,6 @@ message SearchResponse {
optional sonarqube.ws.commons.Paging paging = 3;
message Result {
- optional int64 id = 1;
optional string name = 2;
optional bool selected = 3;
optional string key = 4;