Explorar el Código

SONAR-13221 change PK of GROUPS and update FKs

tags/8.4.0.35506
Duarte Meneses hace 4 años
padre
commit
85b940dd93
Se han modificado 100 ficheros con 2470 adiciones y 641 borrados
  1. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
  2. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java
  3. 3
    3
      server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
  4. 6
    6
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java
  5. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java
  6. 22
    22
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
  7. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
  8. 10
    10
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
  9. 10
    10
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java
  10. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java
  11. 3
    3
      server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java
  12. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/GroupMembershipDto.java
  13. 4
    4
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java
  14. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDto.java
  15. 4
    4
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java
  16. 6
    6
      server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java
  17. 6
    6
      server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java
  18. 4
    4
      server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java
  19. 6
    6
      server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java
  20. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java
  21. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java
  22. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
  23. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
  24. 4
    4
      server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java
  25. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java
  26. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java
  27. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java
  28. 8
    8
      server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java
  29. 5
    5
      server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
  30. 25
    25
      server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
  31. 42
    42
      server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
  32. 33
    33
      server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
  33. 13
    13
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml
  34. 16
    14
      server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml
  35. 15
    15
      server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml
  36. 3
    3
      server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
  37. 6
    6
      server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserGroupMapper.xml
  38. 22
    14
      server/sonar-db-dao/src/schema/schema-sq.ddl
  39. 15
    15
      server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
  40. 11
    10
      server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
  41. 124
    124
      server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
  42. 3
    3
      server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java
  43. 31
    31
      server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java
  44. 22
    22
      server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java
  45. 21
    21
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java
  46. 16
    15
      server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java
  47. 27
    27
      server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java
  48. 6
    6
      server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java
  49. 1
    2
      server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
  50. 12
    12
      server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoTest.java
  51. 1
    1
      server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueDaoTest/shared.xml
  52. 1
    1
      server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueStatsDaoTest/should_select_assignees.xml
  53. 2
    2
      server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml
  54. 2
    2
      server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml
  55. 2
    2
      server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml
  56. 3
    3
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java
  57. 3
    3
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java
  58. 1
    1
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
  59. 1
    2
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/GroupTesting.java
  60. 16
    16
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
  61. 73
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
  62. 38
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTable.java
  63. 38
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfMetricsTable.java
  64. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTable.java
  65. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToMetricsTable.java
  66. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTable.java
  67. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfMetricsTable.java
  68. 32
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTable.java
  69. 32
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfMetricsTable.java
  70. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullable.java
  71. 31
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeMetricsUuidColumnNotNullable.java
  72. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuid.java
  73. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateMetricsUuid.java
  74. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRoles.java
  75. 76
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java
  76. 36
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTable.java
  77. 52
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java
  78. 49
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuid.java
  79. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsers.java
  80. 76
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java
  81. 36
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTable.java
  82. 59
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java
  83. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullable.java
  84. 51
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuid.java
  85. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizations.java
  86. 36
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTable.java
  87. 49
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuid.java
  88. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroups.java
  89. 36
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTable.java
  90. 49
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuid.java
  91. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroups.java
  92. 66
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java
  93. 36
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTable.java
  94. 52
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java
  95. 50
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullable.java
  96. 49
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuid.java
  97. 50
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest.java
  98. 61
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest.java
  99. 51
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest.java
  100. 0
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java Ver fichero

@@ -109,15 +109,15 @@ public class OrganizationDao implements Dao {
getMapper(dbSession).updateDefaultTemplates(uuid, defaultTemplates, now);
}

public Optional<Integer> getDefaultGroupId(DbSession dbSession, String organizationUuid) {
public Optional<String> getDefaultGroupUuid(DbSession dbSession, String organizationUuid) {
checkUuid(organizationUuid);
return Optional.ofNullable(getMapper(dbSession).selectDefaultGroupIdByUuid(organizationUuid));
return Optional.ofNullable(getMapper(dbSession).selectDefaultGroupUuidByUuid(organizationUuid));
}

public void setDefaultGroupId(DbSession dbSession, String uuid, GroupDto defaultGroup) {
public void setDefaultGroupUuid(DbSession dbSession, String uuid, GroupDto defaultGroup) {
checkUuid(uuid);
Integer defaultGroupId = requireNonNull(defaultGroup, "Default group cannot be null").getId();
getMapper(dbSession).updateDefaultGroupId(uuid, requireNonNull(defaultGroupId, "Default group id cannot be null"), system2.now());
String defaultGroupUuid = requireNonNull(defaultGroup, "Default group cannot be null").getUuid();
getMapper(dbSession).updateDefaultGroupUuid(uuid, requireNonNull(defaultGroupUuid, "Default group uuid cannot be null"), system2.now());
}

public void setDefaultQualityGate(DbSession dbSession, OrganizationDto organization, QGateWithOrgDto qualityGate) {

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java Ver fichero

@@ -73,7 +73,7 @@ public class OrganizationDto {

private Subscription subscription;

private Integer defaultGroupId;
private String defaultGroupUuid;
private String defaultQualityGateUuid;
private long createdAt;
private long updatedAt;
@@ -136,12 +136,12 @@ public class OrganizationDto {
}

@CheckForNull
public Integer getDefaultGroupId() {
return defaultGroupId;
public String getDefaultGroupUuid() {
return defaultGroupUuid;
}

public OrganizationDto setDefaultGroupId(@Nullable Integer defaultGroupId) {
this.defaultGroupId = defaultGroupId;
public OrganizationDto setDefaultGroupUuid(@Nullable String defaultGroupUuid) {
this.defaultGroupUuid = defaultGroupUuid;
return this;
}


+ 3
- 3
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java Ver fichero

@@ -51,7 +51,7 @@ public interface OrganizationMapper {

DefaultTemplates selectDefaultTemplatesByUuid(@Param("uuid") String uuid);

Integer selectDefaultGroupIdByUuid(@Param("uuid") String uuid);
String selectDefaultGroupUuidByUuid(@Param("uuid") String uuid);

boolean selectNewProjectPrivateByUuid(@Param("uuid") String uuid);

@@ -67,8 +67,8 @@ public interface OrganizationMapper {
void updateDefaultTemplates(@Param("organizationUuid") String organizationUuid,
@Param("defaultTemplates") DefaultTemplates defaultTemplates, @Param("now") long now);

void updateDefaultGroupId(@Param("organizationUuid") String organizationUuid,
@Param("defaultGroupId") int defaultGroupId, @Param("now") long now);
void updateDefaultGroupUuid(@Param("organizationUuid") String organizationUuid,
@Param("defaultGroupUuid") String defaultGroupUuid, @Param("now") long now);

void updateDefaultQualityGate(@Param("organizationUuid") String organizationUuid,
@Param("defaultQualityGateUuid") String defaultQualityGateUuid, @Param("now") long now);

+ 6
- 6
server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java Ver fichero

@@ -78,12 +78,12 @@ public class AuthorizationDao implements Dao {
}

/**
* The number of users who will still have the permission if the group {@code excludedGroupId}
* The number of users who will still have the permission if the group {@code excludedGroupUuid}
* is deleted. The anyone virtual group is not taken into account.
*/
public int countUsersWithGlobalPermissionExcludingGroup(DbSession dbSession, String organizationUuid,
String permission, int excludedGroupId) {
return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroup(organizationUuid, permission, excludedGroupId);
String permission, String excludedGroupUuid) {
return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroup(organizationUuid, permission, excludedGroupUuid);
}

/**
@@ -105,13 +105,13 @@ public class AuthorizationDao implements Dao {

/**
* The number of users who will still have the permission if the user {@code userId}
* is removed from group {@code groupId}. The anyone virtual group is not taken into account.
* is removed from group {@code groupUuid}. The anyone virtual group is not taken into account.
* Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, int)}, user
* still exists and may have the permission directly or through other groups.
*/
public int countUsersWithGlobalPermissionExcludingGroupMember(DbSession dbSession, String organizationUuid,
String permission, int groupId, int userId) {
return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroupMember(organizationUuid, permission, groupId, userId);
String permission, String groupUuid, int userId) {
return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroupMember(organizationUuid, permission, groupUuid, userId);
}

/**

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java Ver fichero

@@ -35,7 +35,7 @@ public interface AuthorizationMapper {
Set<String> selectOrganizationPermissionsOfAnonymous(@Param("organizationUuid") String organizationUuid);

int countUsersWithGlobalPermissionExcludingGroup(@Param("organizationUuid") String organizationUuid,
@Param("permission") String permission, @Param("excludedGroupId") int excludedGroupId);
@Param("permission") String permission, @Param("excludedGroupUuid") String excludedGroupUuid);

int countUsersWithGlobalPermissionExcludingUser(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission,
@Param("excludedUserId") int excludedUserId);
@@ -43,7 +43,7 @@ public interface AuthorizationMapper {
List<Integer> selectUserIdsWithGlobalPermission(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission);

int countUsersWithGlobalPermissionExcludingGroupMember(@Param("organizationUuid") String organizationUuid,
@Param("permission") String permission, @Param("groupId") int groupId, @Param("userId") int userId);
@Param("permission") String permission, @Param("groupUuid") String groupUuid, @Param("userId") int userId);

int countUsersWithGlobalPermissionExcludingUserPermission(@Param("organizationUuid") String organizationUuid,
@Param("permission") String permission, @Param("userId") int userId);

+ 22
- 22
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java Ver fichero

@@ -59,18 +59,18 @@ 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}.
* through the value "zero" (0L) in {@code groupUuids}.
*/
public List<GroupPermissionDto> selectByGroupIds(DbSession dbSession, String organizationUuid, List<Integer> groupIds, @Nullable String projectUuid) {
return executeLargeInputs(groupIds, groups -> mapper(dbSession).selectByGroupIds(organizationUuid, groups, projectUuid));
public List<GroupPermissionDto> selectByGroupUuids(DbSession dbSession, String organizationUuid, List<String> groupUuids, @Nullable String projectUuid) {
return executeLargeInputs(groupUuids, groups -> mapper(dbSession).selectByGroupUuids(organizationUuid, groups, projectUuid));
}

/**
* Select global and project permissions of a given group (Anyone group is NOT supported)
* Each row returns a {@link GroupPermissionDto}
*/
public void selectAllPermissionsByGroupId(DbSession dbSession, String organizationUuid, Integer groupId, ResultHandler resultHandler) {
mapper(dbSession).selectAllPermissionsByGroupId(organizationUuid, groupId, resultHandler);
public void selectAllPermissionsByGroupUuid(DbSession dbSession, String organizationUuid, String groupUuid, ResultHandler resultHandler) {
mapper(dbSession).selectAllPermissionsByGroupUuid(organizationUuid, groupUuid, resultHandler);
}

/**
@@ -92,25 +92,25 @@ public class GroupPermissionDao implements Dao {
* Selects the global permissions granted to group. An empty list is returned if the
* group does not exist.
*/
public List<String> selectGlobalPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId) {
return mapper(session).selectGlobalPermissionsOfGroup(organizationUuid, groupId);
public List<String> selectGlobalPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable String groupUuid) {
return mapper(session).selectGlobalPermissionsOfGroup(organizationUuid, groupUuid);
}

/**
* 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, String projectUuid) {
return mapper(session).selectProjectPermissionsOfGroup(organizationUuid, groupId, projectUuid);
public List<String> selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable String groupUuid, String projectUuid) {
return mapper(session).selectProjectPermissionsOfGroup(organizationUuid, groupUuid, projectUuid);
}

/**
* Lists id of groups with at least one permission on the specified root component but which do not have the specified
* Lists uuid of groups with at least one permission on the specified root component but which do not have the specified
* permission, <strong>excluding group "AnyOne"</strong> (which implies the returned {@code Sett} can't contain
* {@code null}).
*/
public Set<Integer> selectGroupIdsWithPermissionOnProjectBut(DbSession session, String projectUuid, String permission) {
return mapper(session).selectGroupIdsWithPermissionOnProjectBut(projectUuid, permission);
public Set<String> selectGroupUuidsWithPermissionOnProjectBut(DbSession session, String projectUuid, String permission) {
return mapper(session).selectGroupUuidsWithPermissionOnProjectBut(projectUuid, permission);
}

public void insert(DbSession dbSession, GroupPermissionDto dto) {
@@ -131,14 +131,14 @@ public class GroupPermissionDao implements Dao {
}

private static void ensureGroupPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) {
if (dto.getGroupId() == null) {
if (dto.getGroupUuid() == null) {
return;
}
GroupMapper groupMapper = dbSession.getMapper(GroupMapper.class);
checkArgument(
groupMapper.countGroupByOrganizationAndId(dto.getOrganizationUuid(), dto.getGroupId()) == 1,
groupMapper.countGroupByOrganizationAndUuid(dto.getOrganizationUuid(), dto.getGroupUuid()) == 1,
"Can't insert permission '%s' for group with id '%s' in organization with uuid '%s' because this group does not belong to organization with uuid '%s'",
dto.getRole(), dto.getGroupId(), dto.getOrganizationUuid(), dto.getOrganizationUuid());
dto.getRole(), dto.getGroupUuid(), dto.getOrganizationUuid(), dto.getOrganizationUuid());
}

/**
@@ -149,11 +149,11 @@ public class GroupPermissionDao implements Dao {
}

/**
* Delete all permissions of the specified group (group "AnyOne" if {@code groupId} is {@code null}) for the specified
* Delete all permissions of the specified group (group "AnyOne" if {@code groupUuid} is {@code null}) for the specified
* component.
*/
public int deleteByRootComponentUuidAndGroupId(DbSession dbSession, String rootComponentUuid, @Nullable Integer groupId) {
return mapper(dbSession).deleteByRootComponentUuidAndGroupId(rootComponentUuid, groupId);
public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, String rootComponentUuid, @Nullable String groupUuid) {
return mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(rootComponentUuid, groupUuid);
}

/**
@@ -173,12 +173,12 @@ public class GroupPermissionDao implements Dao {
* </ul>
* @param dbSession
* @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 organizationUuid UUID of organization, even if parameter {@code groupUuid} is not null
* @param groupUuid if null, then anyone, else uuid of group
* @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 String rootComponentUuid) {
mapper(dbSession).delete(permission, organizationUuid, groupId, rootComponentUuid);
public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable String groupUuid, @Nullable String rootComponentUuid) {
mapper(dbSession).delete(permission, organizationUuid, groupUuid, rootComponentUuid);
}

public void deleteByOrganization(DbSession dbSession, String organizationUuid) {

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java Ver fichero

@@ -24,7 +24,7 @@ import javax.annotation.Nullable;
public class GroupPermissionDto {
private String uuid;
private String organizationUuid;
private Integer groupId;
private String groupUuid;
private String componentUuid;
private String role;

@@ -37,8 +37,8 @@ public class GroupPermissionDto {
return this;
}

public Integer getGroupId() {
return groupId;
public String getGroupUuid() {
return groupUuid;
}

public String getOrganizationUuid() {
@@ -53,8 +53,8 @@ public class GroupPermissionDto {
/**
* Null when Anyone
*/
public GroupPermissionDto setGroupId(@Nullable Integer groupId) {
this.groupId = groupId;
public GroupPermissionDto setGroupUuid(@Nullable String groupUuid) {
this.groupUuid = groupUuid;
return this;
}


+ 10
- 10
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java Ver fichero

@@ -33,37 +33,37 @@ public interface GroupPermissionMapper {

int countGroupsByQuery(@Param("query") PermissionQuery query);

List<GroupPermissionDto> selectByGroupIds(@Param("organizationUuid") String organizationUuid,
@Param("groupIds") List<Integer> groupIds, @Nullable @Param("projectUuid") String projectUuid);
List<GroupPermissionDto> selectByGroupUuids(@Param("organizationUuid") String organizationUuid,
@Param("groupUuids") List<String> groupUuids, @Nullable @Param("projectUuid") String projectUuid);

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("rootComponentUuid") String rootComponentUuid);
@Nullable @Param("groupUuid") String groupUuid, @Nullable @Param("rootComponentUuid") String rootComponentUuid);

List<String> selectGlobalPermissionsOfGroup(@Param("organizationUuid") String organizationUuid,
@Nullable @Param("groupId") Integer groupId);
@Nullable @Param("groupUuid") String groupUuid);

List<String> selectProjectPermissionsOfGroup(@Param("organizationUuid") String organizationUuid,
@Nullable @Param("groupId") Integer groupId, @Param("projectUuid") String projectUuid);
@Nullable @Param("groupUuid") String groupUuid, @Param("projectUuid") String projectUuid);

void selectAllPermissionsByGroupId(@Param("organizationUuid") String organizationUuid,
@Param("groupId") Integer groupId, ResultHandler resultHandler);
void selectAllPermissionsByGroupUuid(@Param("organizationUuid") String organizationUuid,
@Param("groupUuid") String groupUuid, ResultHandler resultHandler);

/**
* Lists id of groups with at least one permission on the specified root component but which do not have the specified
* Lists uuid of groups with at least one permission on the specified root component but which do not have the specified
* permission, <strong>excluding group "AnyOne"</strong> (which implies the returned {@code Set} can't contain
* {@code null}).
*/
Set<Integer> selectGroupIdsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("role") String permission);
Set<String> selectGroupUuidsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("role") String permission);

void deleteByOrganization(@Param("organizationUuid") String organizationUuid);

void deleteByRootComponentUuid(@Param("rootComponentUuid") String rootComponentUuid);

int deleteByRootComponentUuidAndGroupId(@Param("rootComponentUuid") String rootComponentUuid, @Nullable @Param("groupId") Integer groupId);
int deleteByRootComponentUuidAndGroupUuid(@Param("rootComponentUuid") String rootComponentUuid, @Nullable @Param("groupUuid") String groupUuid);

int deleteByRootComponentUuidAndPermission(@Param("rootComponentUuid") String rootComponentUuid, @Param("permission") String permission);
}

+ 10
- 10
server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java Ver fichero

@@ -91,8 +91,8 @@ public class PermissionTemplateDao implements Dao {
/**
* @return {@code true} if template contains groups that are granted with {@code permission}, else {@code false}
*/
public boolean hasGroupsWithPermission(DbSession dbSession, String templateUuid, String permission, @Nullable Integer groupId) {
return mapper(dbSession).countGroupsWithPermission(templateUuid, permission, groupId) > 0;
public boolean hasGroupsWithPermission(DbSession dbSession, String templateUuid, String permission, @Nullable String groupUuid) {
return mapper(dbSession).countGroupsWithPermission(templateUuid, permission, groupUuid) > 0;
}

@CheckForNull
@@ -147,8 +147,8 @@ public class PermissionTemplateDao implements Dao {
});
}

public List<PermissionTemplateGroupDto> selectAllGroupPermissionTemplatesByGroupId(DbSession dbSession, long groupId) {
return mapper(dbSession).selectAllGroupPermissionTemplatesByGroupId(groupId);
public List<PermissionTemplateGroupDto> selectAllGroupPermissionTemplatesByGroupUuid(DbSession dbSession, String groupUuid) {
return mapper(dbSession).selectAllGroupPermissionTemplatesByGroupUuid(groupUuid);
}

public void deleteByUuid(DbSession session, String templateUuid) {
@@ -194,12 +194,12 @@ public class PermissionTemplateDao implements Dao {
mapper(dbSession).deleteUserPermissionsByUserId(userId);
}

public void insertGroupPermission(DbSession session, String templateUuid, @Nullable Integer groupId, String permission) {
public void insertGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission) {
PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
.setUuid(uuidFactory.create())
.setTemplateUuid(templateUuid)
.setPermission(permission)
.setGroupId(groupId)
.setGroupUuid(groupUuid)
.setCreatedAt(now())
.setUpdatedAt(now());
mapper(session).insertGroupPermission(permissionTemplateGroup);
@@ -209,11 +209,11 @@ public class PermissionTemplateDao implements Dao {
mapper(session).insertGroupPermission(permissionTemplateGroup);
}

public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable Integer groupId, String permission) {
public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission) {
PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
.setTemplateUuid(templateUuid)
.setPermission(permission)
.setGroupId(groupId);
.setGroupUuid(groupUuid);
mapper(session).deleteGroupPermission(permissionTemplateGroup);
session.commit();
}
@@ -229,8 +229,8 @@ public class PermissionTemplateDao implements Dao {
/**
* Remove a group from all templates (used when removing a group)
*/
public void deleteByGroup(DbSession session, int groupId) {
session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId);
public void deleteByGroup(DbSession session, String groupUuid) {
session.getMapper(PermissionTemplateMapper.class).deleteByGroupUuid(groupUuid);
}

private Date now() {

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java Ver fichero

@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
public class PermissionTemplateGroupDto {
private String uuid;
private String templateUuid;
private Integer groupId;
private String groupUuid;
private String permission;
private String groupName;
private Date createdAt;
@@ -49,12 +49,12 @@ public class PermissionTemplateGroupDto {
return this;
}

public Integer getGroupId() {
return groupId;
public String getGroupUuid() {
return groupUuid;
}

public PermissionTemplateGroupDto setGroupId(@Nullable Integer groupId) {
this.groupId = groupId;
public PermissionTemplateGroupDto setGroupUuid(@Nullable String groupUuid) {
this.groupUuid = groupUuid;
return this;
}


+ 3
- 3
server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java Ver fichero

@@ -66,7 +66,7 @@ public interface PermissionTemplateMapper {

void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);

void deleteByGroupId(int groupId);
void deleteByGroupUuid(String groupUuid);

PermissionTemplateDto selectByName(@Param("organizationUuid") String organizationUuid, @Param("name") String name);

@@ -86,10 +86,10 @@ public interface PermissionTemplateMapper {

List<String> selectPotentialPermissionsByUserIdAndTemplateUuid(@Param("userId") @Nullable Integer currentUserId, @Param("templateUuid") String templateUuid);

int countGroupsWithPermission(@Param("templateUuid") String templateUuid, @Param("permission") String permission, @Nullable @Param("groupId") Integer groupId);
int countGroupsWithPermission(@Param("templateUuid") String templateUuid, @Param("permission") String permission, @Nullable @Param("groupUuid") String groupUuid);

List<String> selectTemplateUuidsByOrganization(@Param("organizationUuid") String organizationUuid);

List<PermissionTemplateGroupDto> selectAllGroupPermissionTemplatesByGroupId(@Param("groupId") Long groupId);
List<PermissionTemplateGroupDto> selectAllGroupPermissionTemplatesByGroupUuid(@Param("groupUuid") String groupUuid);

}

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/GroupMembershipDto.java Ver fichero

@@ -21,16 +21,16 @@ package org.sonar.db.qualityprofile;

public class GroupMembershipDto {

private int groupId;
private String groupUuid;
// Set by MyBatis
private String uuid;

public int getGroupId() {
return groupId;
public String getGroupUuid() {
return groupUuid;
}

public GroupMembershipDto setGroupId(int groupId) {
this.groupId = groupId;
public GroupMembershipDto setGroupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}


+ 4
- 4
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java Ver fichero

@@ -47,7 +47,7 @@ public class QProfileEditGroupsDao implements Dao {
}

public boolean exists(DbSession dbSession, QProfileDto profile, Collection<GroupDto> groups) {
return !executeLargeInputs(groups.stream().map(GroupDto::getId).collect(toList()), partition -> mapper(dbSession).selectByQProfileAndGroups(profile.getKee(), partition))
return !executeLargeInputs(groups.stream().map(GroupDto::getUuid).collect(toList()), partition -> mapper(dbSession).selectByQProfileAndGroups(profile.getKee(), partition))
.isEmpty();
}

@@ -60,7 +60,7 @@ public class QProfileEditGroupsDao implements Dao {
}

public List<String> selectQProfileUuidsByOrganizationAndGroups(DbSession dbSession, OrganizationDto organization, Collection<GroupDto> groups) {
return DatabaseUtils.executeLargeInputs(groups.stream().map(GroupDto::getId).collect(toList()),
return DatabaseUtils.executeLargeInputs(groups.stream().map(GroupDto::getUuid).collect(toList()),
g -> mapper(dbSession).selectQProfileUuidsByOrganizationAndGroups(organization.getUuid(), g));
}

@@ -69,7 +69,7 @@ public class QProfileEditGroupsDao implements Dao {
}

public void deleteByQProfileAndGroup(DbSession dbSession, QProfileDto profile, GroupDto group) {
mapper(dbSession).delete(profile.getKee(), group.getId());
mapper(dbSession).delete(profile.getKee(), group.getUuid());
}

public void deleteByQProfiles(DbSession dbSession, List<QProfileDto> qProfiles) {
@@ -77,7 +77,7 @@ public class QProfileEditGroupsDao implements Dao {
}

public void deleteByGroup(DbSession dbSession, GroupDto group) {
mapper(dbSession).deleteByGroup(group.getId());
mapper(dbSession).deleteByGroup(group.getUuid());
}

private static QProfileEditGroupsMapper mapper(DbSession dbSession) {

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDto.java Ver fichero

@@ -22,7 +22,7 @@ package org.sonar.db.qualityprofile;
public class QProfileEditGroupsDto {

private String uuid;
private int groupId;
private String groupUuid;
private String qProfileUuid;

public String getUuid() {
@@ -34,12 +34,12 @@ public class QProfileEditGroupsDto {
return this;
}

public int getGroupId() {
return groupId;
public String getGroupUuid() {
return groupUuid;
}

public QProfileEditGroupsDto setGroupId(int groupId) {
this.groupId = groupId;
public QProfileEditGroupsDto setGroupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}


+ 4
- 4
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java Ver fichero

@@ -26,20 +26,20 @@ import org.sonar.db.Pagination;

public interface QProfileEditGroupsMapper {

List<QProfileEditGroupsDto> selectByQProfileAndGroups(@Param("qProfileUuid") String qProfileUuid, @Param("groupIds") List<Integer> groupIds);
List<QProfileEditGroupsDto> selectByQProfileAndGroups(@Param("qProfileUuid") String qProfileUuid, @Param("groupUuids") List<String> groupUuids);

int countByQuery(@Param("query") SearchGroupsQuery query);

List<GroupMembershipDto> selectByQuery(@Param("query") SearchGroupsQuery query, @Param("pagination") Pagination pagination);

List<String> selectQProfileUuidsByOrganizationAndGroups(@Param("organizationUuid") String organizationUuid, @Param("groupIds") List<Integer> groupIds);
List<String> selectQProfileUuidsByOrganizationAndGroups(@Param("organizationUuid") String organizationUuid, @Param("groupUuids") List<String> groupUuids);

void insert(@Param("dto") QProfileEditGroupsDto dto, @Param("now") long now);

void delete(@Param("qProfileUuid") String qProfileUuid, @Param("groupId") int groupId);
void delete(@Param("qProfileUuid") String qProfileUuid, @Param("groupUuid") String groupUuid);

void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);

void deleteByGroup(@Param("groupId") int groupId);
void deleteByGroup(@Param("groupUuid") String groupUuid);

}

+ 6
- 6
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java Ver fichero

@@ -59,16 +59,16 @@ public class GroupDao implements Dao {
}

@CheckForNull
public GroupDto selectById(DbSession dbSession, int groupId) {
return mapper(dbSession).selectById(groupId);
public GroupDto selectByUuid(DbSession dbSession, String groupUuid) {
return mapper(dbSession).selectByUuid(groupUuid);
}

public List<GroupDto> selectByIds(DbSession dbSession, List<Integer> ids) {
return executeLargeInputs(ids, mapper(dbSession)::selectByIds);
public List<GroupDto> selectByUuids(DbSession dbSession, List<String> uuids) {
return executeLargeInputs(uuids, mapper(dbSession)::selectByUuids);
}

public void deleteById(DbSession dbSession, int groupId) {
mapper(dbSession).deleteById(groupId);
public void deleteByUuid(DbSession dbSession, String groupUuid) {
mapper(dbSession).deleteByUuid(groupUuid);
}

public void deleteByOrganization(DbSession dbSession, String organizationUuid) {

+ 6
- 6
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java Ver fichero

@@ -25,19 +25,19 @@ import javax.annotation.Nullable;

public class GroupDto {

private Integer id;
private String uuid;
private String name;
private String description;
private String organizationUuid;
private Date createdAt;
private Date updatedAt;

public Integer getId() {
return id;
public String getUuid() {
return uuid;
}

public GroupDto setId(Integer id) {
this.id = id;
public GroupDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}

@@ -90,7 +90,7 @@ public class GroupDto {
@Override
public String toString() {
StringBuilder sb = new StringBuilder("GroupDto{");
sb.append("id=").append(id);
sb.append("id=").append(uuid);
sb.append(", name='").append(name).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", organizationUuid='").append(organizationUuid).append('\'');

+ 4
- 4
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java Ver fichero

@@ -28,7 +28,7 @@ import org.apache.ibatis.session.RowBounds;
public interface GroupMapper {

@CheckForNull
GroupDto selectById(int groupId);
GroupDto selectByUuid(String groupUuid);

List<GroupDto> selectByUserLogin(String userLogin);

@@ -47,9 +47,9 @@ public interface GroupMapper {
*
* @return 1 or 0. Either because the organization uuid is not the one of the group or because the group does not exist
*/
int countGroupByOrganizationAndId(@Param("organizationUuid") String organizationUuid, @Param("groupId") int groupId);
int countGroupByOrganizationAndUuid(@Param("organizationUuid") String organizationUuid, @Param("groupUuid") String groupUuid);

void deleteById(int groupId);
void deleteByUuid(String groupUuid);

void deleteByOrganization(@Param("organizationUuid") String organizationUuid);

@@ -58,5 +58,5 @@ public interface GroupMapper {

List<GroupDto> selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid);

List<GroupDto> selectByIds(@Param("ids") List<Integer> ids);
List<GroupDto> selectByUuids(@Param("uuids") List<String> uuids);
}

+ 6
- 6
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java Ver fichero

@@ -46,19 +46,19 @@ public class GroupMembershipDao implements Dao {
}

public List<UserMembershipDto> selectMembers(DbSession session, UserMembershipQuery query, int offset, int limit) {
Map<String, Object> params = ImmutableMap.of("query", query, "groupId", query.groupId(), "organizationUuid", query.organizationUuid());
Map<String, Object> params = ImmutableMap.of("query", query, "groupUuid", query.groupUuid(), "organizationUuid", query.organizationUuid());
return mapper(session).selectMembers(params, new RowBounds(offset, limit));
}

public int countMembers(DbSession session, UserMembershipQuery query) {
Map<String, Object> params = ImmutableMap.of("query", query, "groupId", query.groupId(), "organizationUuid", query.organizationUuid());
Map<String, Object> params = ImmutableMap.of("query", query, "groupUuid", query.groupUuid(), "organizationUuid", query.organizationUuid());
return mapper(session).countMembers(params);
}

public Map<String, Integer> countUsersByGroups(DbSession session, Collection<Integer> groupIds) {
public Map<String, Integer> countUsersByGroups(DbSession session, Collection<String> groupUuids) {
Map<String, Integer> result = new HashMap<>();
executeLargeInputs(
groupIds,
groupUuids,
input -> {
List<GroupUserCount> userCounts = mapper(session).countUsersByGroup(input);
for (GroupUserCount count : userCounts) {
@@ -70,8 +70,8 @@ public class GroupMembershipDao implements Dao {
return result;
}

public List<Integer> selectGroupIdsByUserId(DbSession dbSession, int userId) {
return mapper(dbSession).selectGroupIdsByUserId(userId);
public List<String> selectGroupUuidsByUserId(DbSession dbSession, int userId) {
return mapper(dbSession).selectGroupUuidsByUserId(userId);
}

public Multiset<String> countGroupByLoginsAndOrganization(DbSession dbSession, Collection<String> logins, String organizationUuid) {

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java Ver fichero

@@ -27,17 +27,17 @@ import javax.annotation.Nullable;
*/
public class GroupMembershipDto {

private Long id;
private String uuid;
private String name;
private String description;
private Integer userId;

public Long getId() {
return id;
public String getUuid() {
return uuid;
}

public GroupMembershipDto setId(Long id) {
this.id = id;
public GroupMembershipDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}


+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java Ver fichero

@@ -34,11 +34,11 @@ public interface GroupMembershipMapper {

int countMembers(Map<String, Object> params);

List<GroupUserCount> countUsersByGroup(@Param("groupIds") List<Integer> groupIds);
List<GroupUserCount> countUsersByGroup(@Param("groupUuids") List<String> groupUuids);

List<LoginGroup> selectGroupsByLogins(@Param("logins") List<String> logins);

List<LoginGroup> selectGroupsByLoginsAndOrganization(@Param("logins") List<String> logins, @Param("organizationUuid") String organizationUuid);

List<Integer> selectGroupIdsByUserId(@Param("userId") int userId);
List<String> selectGroupUuidsByUserId(@Param("userId") int userId);
}

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java Ver fichero

@@ -47,8 +47,8 @@ public class RoleDao implements Dao {
return mapper(dbSession).selectComponentUuidsByPermissionAndUserId(permission, userId);
}

public void deleteGroupRolesByGroupId(DbSession session, int groupId) {
mapper(session).deleteGroupRolesByGroupId(groupId);
public void deleteGroupRolesByGroupUuid(DbSession session, String groupUuid) {
mapper(session).deleteGroupRolesByGroupUuid(groupUuid);
}

private static RoleMapper mapper(DbSession session) {

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java Ver fichero

@@ -26,6 +26,6 @@ public interface RoleMapper {

List<String> selectComponentUuidsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") int userId);

void deleteGroupRolesByGroupId(int groupId);
void deleteGroupRolesByGroupUuid(String groupUuid);

}

+ 4
- 4
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java Ver fichero

@@ -29,12 +29,12 @@ public class UserGroupDao implements Dao {
return dto;
}

public void delete(DbSession session, int groupId, int userId) {
mapper(session).delete(groupId, userId);
public void delete(DbSession session, String groupUuid, int userId) {
mapper(session).delete(groupUuid, userId);
}

public void deleteByGroupId(DbSession session, int groupId) {
mapper(session).deleteByGroupId(groupId);
public void deleteByGroupUuid(DbSession session, String groupUuid) {
mapper(session).deleteByGroupUuid(groupUuid);
}

public void deleteByOrganizationAndUser(DbSession dbSession, String organizationUuid, int userId) {

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java Ver fichero

@@ -22,7 +22,7 @@ package org.sonar.db.user;
public class UserGroupDto {

private int userId;
private int groupId;
private String groupUuid;

public int getUserId() {
return userId;
@@ -33,12 +33,12 @@ public class UserGroupDto {
return this;
}

public int getGroupId() {
return groupId;
public String getGroupUuid() {
return groupUuid;
}

public UserGroupDto setGroupId(int groupId) {
this.groupId = groupId;
public UserGroupDto setGroupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
}

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java Ver fichero

@@ -25,9 +25,9 @@ public interface UserGroupMapper {

void insert(UserGroupDto dto);

void delete(@Param("groupId") int groupId, @Param("userId") int userId);
void delete(@Param("groupUuid") String groupUuid, @Param("userId") int userId);

void deleteByGroupId(@Param("groupId") int groupId);
void deleteByGroupUuid(@Param("groupUuid") String groupUuid);

void deleteByOrganizationAndUser(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId);


+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java Ver fichero

@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
public class UserMembershipDto {

private Long id;
private Integer groupId;
private String groupUuid;
private String login;
private String name;

@@ -58,12 +58,12 @@ public class UserMembershipDto {
}

@CheckForNull
public Integer getGroupId() {
return groupId;
public String getGroupUuid() {
return groupUuid;
}

public UserMembershipDto setGroupId(@Nullable Integer groupId) {
this.groupId = groupId;
public UserMembershipDto setGroupUuid(@Nullable String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
}

+ 8
- 8
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java Ver fichero

@@ -42,7 +42,7 @@ public class UserMembershipQuery {
public static final String OUT = "OUT";
public static final Set<String> AVAILABLE_MEMBERSHIPS = ImmutableSet.of(ANY, IN, OUT);

private final int groupId;
private final String groupUuid;
private final String organizationUuid;
private final String membership;

@@ -59,7 +59,7 @@ public class UserMembershipQuery {
private final int pageIndex;

private UserMembershipQuery(Builder builder) {
this.groupId = builder.groupId;
this.groupUuid = builder.groupUuid;
this.organizationUuid = builder.organizationUuid;
this.membership = builder.membership;
this.memberSearch = builder.memberSearch;
@@ -69,8 +69,8 @@ public class UserMembershipQuery {
this.pageIndex = builder.pageIndex;
}

public int groupId() {
return groupId;
public String groupUuid() {
return groupUuid;
}

public String organizationUuid() {
@@ -103,7 +103,7 @@ public class UserMembershipQuery {
}

public static class Builder {
private Integer groupId;
private String groupUuid;
private String organizationUuid;
private String membership;
private String memberSearch;
@@ -114,8 +114,8 @@ public class UserMembershipQuery {
private Builder() {
}

public Builder groupId(Integer groupId) {
this.groupId = groupId;
public Builder groupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}

@@ -160,7 +160,7 @@ public class UserMembershipQuery {
}

public UserMembershipQuery build() {
requireNonNull(groupId, "Group ID cant be null.");
requireNonNull(groupUuid, "Group ID cant be null.");
requireNonNull(organizationUuid, "Organization UUID cannot be null");
initMembership();
initPageIndex();

+ 5
- 5
server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml Ver fichero

@@ -162,7 +162,7 @@
and g.component_uuid is null
and g.role = #{permission,jdbcType=VARCHAR}
inner join groups_users gu on
gu.group_id = g.group_id
gu.group_uuid = g.group_uuid
and gu.user_id = #{userId,jdbcType=INTEGER}
</select>

@@ -170,8 +170,8 @@
select uuid from organizations
</select>

<select id="selectDefaultGroupIdByUuid" resultType="Integer">
select org.default_group_id
<select id="selectDefaultGroupUuidByUuid" resultType="string">
select org.default_group_uuid
from organizations org
where
org.uuid = #{uuid, jdbcType=VARCHAR}
@@ -269,10 +269,10 @@
uuid = #{organizationUuid, jdbcType=VARCHAR}
</update>

<update id="updateDefaultGroupId">
<update id="updateDefaultGroupUuid">
update organizations
set
default_group_id = #{defaultGroupId, jdbcType=INTEGER},
default_group_uuid = #{defaultGroupUuid, jdbcType=VARCHAR},
updated_at = #{now, jdbcType=BIGINT}
where
uuid = #{organizationUuid, jdbcType=VARCHAR}

+ 25
- 25
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml Ver fichero

@@ -6,7 +6,7 @@
<select id="selectOrganizationPermissions" parameterType="map" resultType="string">
select gr.role
from group_roles gr
inner join groups_users gu on gr.group_id=gu.group_id
inner join groups_users gu on gr.group_uuid=gu.group_uuid
where
gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
gr.component_uuid is null and
@@ -18,7 +18,7 @@
from group_roles gr
where
gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
gr.group_id is null and
gr.group_uuid is null and
gr.component_uuid is null

union
@@ -37,7 +37,7 @@
where
gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and
gr.component_uuid is null and
gr.group_id is null
gr.group_uuid is null
</select>

<select id="countUsersWithGlobalPermissionExcludingGroup" parameterType="map" resultType="int">
@@ -45,13 +45,13 @@
(
select gu.user_id
from groups_users gu
inner join group_roles gr on gr.group_id = gu.group_id
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
gr.component_uuid is null and
gr.group_id is not null and
gr.group_id != #{excludedGroupId, jdbcType=INTEGER}
gr.group_uuid is not null and
gr.group_uuid != #{excludedGroupUuid, jdbcType=VARCHAR}

union

@@ -69,12 +69,12 @@
(
select gu.user_id
from groups_users gu
inner join group_roles gr on gr.group_id = gu.group_id
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
gr.component_uuid is null and
gr.group_id is not null and
gr.group_uuid is not null and
gu.user_id != #{excludedUserId, jdbcType=INTEGER}

union
@@ -92,12 +92,12 @@
<select id="selectUserIdsWithGlobalPermission" parameterType="map" resultType="int">
select gu.user_id
from groups_users gu
inner join group_roles gr on gr.group_id = gu.group_id
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
gr.component_uuid is null and
gr.group_id is not null
gr.group_uuid is not null

union

@@ -114,13 +114,13 @@
(
select gu.user_id
from groups_users gu
inner join group_roles gr on gr.group_id = gu.group_id
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} 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})
gr.group_uuid is not null and
(gu.group_uuid != #{groupUuid, jdbcType=VARCHAR} or gu.user_id != #{userId, jdbcType=INTEGER})

union

@@ -138,12 +138,12 @@
(
select gu.user_id
from groups_users gu
inner join group_roles gr on gr.group_id = gu.group_id
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and
gr.role = #{permission, jdbcType=VARCHAR} and
gr.component_uuid is null and
gr.group_id is not null
gr.group_uuid is not null

union

@@ -160,11 +160,11 @@
<select id="selectOrganizationUuidsOfUserWithGlobalPermission" parameterType="map" resultType="String">
select gr.organization_uuid
from group_roles gr
inner join groups_users gu on gr.group_id = gu.group_id
inner join groups_users gu on gr.group_uuid = gu.group_uuid
where
gr.role = #{permission, jdbcType=VARCHAR} and
gr.component_uuid is null and
gr.group_id is not null and
gr.group_uuid is not null and
gu.user_id = #{userId, jdbcType=INTEGER}

union
@@ -185,7 +185,7 @@
where
gr.role=#{role, jdbcType=VARCHAR}
and (
gr.group_id is null
gr.group_uuid is null
or exists (
select
1
@@ -193,7 +193,7 @@
groups_users gu
where
gu.user_id = #{userId, jdbcType=INTEGER}
and gr.group_id = gu.group_id
and gr.group_uuid = gu.group_uuid
)
)
and <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or ">
@@ -240,7 +240,7 @@
group_roles gr
where
gr.role=#{role, jdbcType=VARCHAR}
and gr.group_id is null
and gr.group_uuid is null
and <foreach collection="projectUuids" open="(" close=")" item="element" index="index" separator=" or ">
gr.component_uuid=#{element, jdbcType=VARCHAR}
</foreach>
@@ -256,7 +256,7 @@
from
groups_users gu
inner join group_roles gr on
gr.group_id=gu.group_id
gr.group_uuid=gu.group_uuid
where
gr.component_uuid=#{componentUuid, jdbcType=VARCHAR}
and gr.role=#{role, jdbcType=VARCHAR}
@@ -315,7 +315,7 @@

select gr.role
from group_roles gr
inner join groups_users gu on gr.group_id = gu.group_id
inner join groups_users gu on gr.group_uuid = gu.group_uuid
inner join components p on p.uuid = gr.component_uuid
where
p.uuid = #{projectUuid, jdbcType=VARCHAR} and
@@ -341,7 +341,7 @@
where
p.uuid = #{projectUuid, jdbcType=VARCHAR}
and p.organization_uuid = gr.organization_uuid
and gr.group_id is null
and gr.group_uuid is null
</sql>

<select id="selectEmailSubscribersWithGlobalPermission" parameterType="map" resultType="org.sonar.db.EmailSubscriberDto">
@@ -368,7 +368,7 @@
inner join groups_users gu on
u.id=gu.user_id
inner join group_roles gr on
gr.group_id = gu.group_id
gr.group_uuid = gu.group_uuid
and gr.role = #{permission, jdbcType=VARCHAR}
and gr.component_uuid is null
where
@@ -394,7 +394,7 @@
select 1
from components p
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
inner join groups_users gu on gu.group_uuid = gr.group_uuid
where
p.kee = #{projectKey, jdbcType=VARCHAR}
and gu.user_id = u.id

+ 42
- 42
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml Ver fichero

@@ -17,7 +17,7 @@
FROM
groups g
INNER JOIN group_roles group_role ON
group_role.group_id=g.id
group_role.group_uuid=g.uuid
UNION
-- Add Anyone group permission
SELECT
@@ -27,7 +27,7 @@
FROM
group_roles group_role
where
group_role.group_id IS NULL
group_role.group_uuid IS NULL
) groups
where
groups.componentUuid in
@@ -40,24 +40,24 @@
</select>

<select id="selectGroupNamesByQuery" parameterType="map" resultType="string">
select sub.name, lower(sub.name), sub.groupId
select sub.name, lower(sub.name), sub.groupUuid
<include refid="groupsByQuery" />
group by sub.name, lower(sub.name), sub.groupId
order by case when (count(sub.permission) > 0) then 1 else 2 end asc, lower(sub.name), sub.name, sub.groupId
group by sub.name, lower(sub.name), sub.groupUuid
order by case when (count(sub.permission) > 0) then 1 else 2 end asc, lower(sub.name), sub.name, sub.groupUuid
</select>

<select id="countGroupsByQuery" parameterType="map" resultType="int">
select count(1)
from (
select distinct sub.groupId
select distinct sub.groupUuid
<include refid="groupsByQuery" />) g
</select>

<sql id="groupsByQuery">
from (
select g.id as groupId, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
select g.uuid as groupUuid, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
from groups g
left join group_roles gr on g.id = gr.group_id
left join group_roles gr on g.uuid = gr.group_uuid
<if test="query.componentUuid == null">
and gr.component_uuid is null
</if>
@@ -69,7 +69,7 @@

union all

select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
select 'Anyone' as groupUuid, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
from group_roles gr
<where>
<if test="query.componentUuid == null">
@@ -80,7 +80,7 @@
</if>
<if test="query.withAtLeastOnePermission()">
and gr.organization_uuid = #{query.organizationUuid,jdbcType=VARCHAR} and
gr.group_id is null
gr.group_uuid is null
</if>
</where>

@@ -106,28 +106,28 @@
</where>
</sql>

<select id="selectByGroupIds" parameterType="map" resultType="GroupPermission">
select sub.groupId as groupId, sub.componentUuid as componentUuid, sub.permission as role, sub.organizationUuid as organizationUuid
<select id="selectByGroupUuids" parameterType="map" resultType="GroupPermission">
select sub.groupUuid as groupUuid, sub.componentUuid as componentUuid, sub.permission as role, sub.organizationUuid as organizationUuid
from
(
select gr.group_id as groupId, gr.component_uuid as componentUuid, gr.role as permission, g.name as name, gr.organization_uuid as organizationUuid
select gr.group_uuid as groupUuid, 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
inner join groups g ON g.uuid = gr.group_uuid
where gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
gr.group_id is not null
gr.group_uuid is not null

union all

select 0 as groupId, gr.component_uuid as componentUuid, gr.role as permission, 'Anyone' as name, gr.organization_uuid as organizationUuid
select 'Anyone' as groupUuid, 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
gr.group_uuid is null and
gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
) sub
where
sub.groupId in
<foreach collection="groupIds" open="(" close=")" item="groupId" separator=",">
#{groupId,jdbcType=INTEGER}
sub.groupUuid in
<foreach collection="groupUuids" open="(" close=")" item="groupUuid" separator=",">
#{groupUuid,jdbcType=VARCHAR}
</foreach>
<if test="projectUuid != null">
and sub.componentUuid=#{projectUuid,jdbcType=VARCHAR}
@@ -144,11 +144,11 @@
gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
gr.component_uuid is null and
<choose>
<when test="groupId != null">
gr.group_id = #{groupId,jdbcType=INTEGER}
<when test="groupUuid != null">
gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
</when>
<otherwise>
gr.group_id is null
gr.group_uuid is null
</otherwise>
</choose>
</select>
@@ -160,30 +160,30 @@
gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and
gr.component_uuid = #{projectUuid,jdbcType=VARCHAR} and
<choose>
<when test="groupId != null">
gr.group_id = #{groupId,jdbcType=INTEGER}
<when test="groupUuid != null">
gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
</when>
<otherwise>
gr.group_id is null
gr.group_uuid is null
</otherwise>
</choose>
</select>

<select id="selectAllPermissionsByGroupId" parameterType="map" resultType="GroupPermission">
select gr.group_id as groupId, gr.component_uuid as componentUuid, gr.role as role, gr.organization_uuid as organizationUuid
<select id="selectAllPermissionsByGroupUuid" parameterType="map" resultType="GroupPermission">
select gr.group_uuid as groupUuid, 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}
and gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
</select>

<select id="selectGroupIdsWithPermissionOnProjectBut" resultType="Integer">
<select id="selectGroupUuidsWithPermissionOnProjectBut" resultType="string">
select
distinct gr1.group_id
distinct gr1.group_uuid
from
group_roles gr1
where
gr1.component_uuid = #{projectUuid,jdbcType=VARCHAR}
and gr1.group_id is not null
and gr1.group_uuid is not null
and not exists (
select
1
@@ -191,7 +191,7 @@
group_roles gr2
where
gr2.component_uuid = gr1.component_uuid
and gr2.group_id = gr1.group_id
and gr2.group_uuid = gr1.group_uuid
and gr2.role = #{role,jdbcType=VARCHAR}
)
</select>
@@ -200,13 +200,13 @@
insert into group_roles (
uuid,
organization_uuid,
group_id,
group_uuid,
component_uuid,
role
) values (
#{uuid,jdbcType=VARCHAR},
#{organizationUuid,jdbcType=VARCHAR},
#{groupId,jdbcType=INTEGER},
#{groupUuid,jdbcType=VARCHAR},
#{componentUuid,jdbcType=BIGINT},
#{role,jdbcType=VARCHAR}
)
@@ -217,17 +217,17 @@
where component_uuid=#{rootComponentUuid,jdbcType=VARCHAR}
</delete>

<delete id="deleteByRootComponentUuidAndGroupId">
<delete id="deleteByRootComponentUuidAndGroupUuid">
delete from
group_roles
where
component_uuid=#{rootComponentUuid,jdbcType=VARCHAR}
<choose>
<when test="groupId != null">
and group_id = #{groupId,jdbcType=INTEGER}
<when test="groupUuid != null">
and group_uuid = #{groupUuid,jdbcType=VARCHAR}
</when>
<otherwise>
and group_id is null
and group_uuid is null
</otherwise>
</choose>
</delete>
@@ -255,11 +255,11 @@
</choose>
and
<choose>
<when test="groupId != null">
group_id=#{groupId,jdbcType=INTEGER}
<when test="groupUuid != null">
group_uuid=#{groupUuid,jdbcType=VARCHAR}
</when>
<otherwise>
group_id is null
group_uuid is null
</otherwise>
</choose>
</delete>

+ 33
- 33
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml Ver fichero

@@ -93,11 +93,11 @@
AND permission_reference = #{permission}
AND
<choose>
<when test="groupId != null">
group_id = #{groupId}
<when test="groupUuid != null">
group_uuid = #{groupUuid}
</when>
<otherwise>
group_id IS NULL
group_uuid IS NULL
</otherwise>
</choose>
</delete>
@@ -108,20 +108,20 @@
</insert>

<insert id="insertGroupPermission" parameterType="PermissionTemplateGroup">
INSERT INTO perm_templates_groups (uuid, template_uuid, group_id, permission_reference, created_at, updated_at)
INSERT INTO perm_templates_groups (uuid, template_uuid, group_uuid, permission_reference, created_at, updated_at)
VALUES (
#{uuid,jdbcType=VARCHAR},
#{templateUuid,jdbcType=VARCHAR},
#{groupId,jdbcType=INTEGER},
#{groupUuid,jdbcType=VARCHAR},
#{permission,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP},
#{updatedAt,jdbcType=TIMESTAMP}
)
</insert>

<delete id="deleteByGroupId" parameterType="int">
<delete id="deleteByGroupUuid" parameterType="string">
delete from perm_templates_groups
where group_id = #{groupId,jdbcType=INTEGER}
where group_uuid = #{groupUuid,jdbcType=VARCHAR}
</delete>

<select id="selectUserLoginsByQueryAndTemplate" parameterType="map" resultType="string">
@@ -159,35 +159,35 @@
</sql>

<select id="selectGroupNamesByQueryAndTemplate" parameterType="map" resultType="string">
select groups.name, lower(groups.name), groups.group_id
select groups.name, lower(groups.name), groups.group_uuid
<include refid="groupNamesByQueryAndTemplate" />
group by groups.name, lower(groups.name), groups.group_id
order by case when (count(groups.permission) > 0) then 1 else 2 end asc, lower(groups.name), groups.name, groups.group_id
group by groups.name, lower(groups.name), groups.group_uuid
order by case when (count(groups.permission) > 0) then 1 else 2 end asc, lower(groups.name), groups.name, groups.group_uuid
</select>

<select id="countGroupNamesByQueryAndTemplate" parameterType="map" resultType="int">
SELECT COUNT(1)
FROM (
SELECT DISTINCT group_id
SELECT DISTINCT group_uuid
<include refid="groupNamesByQueryAndTemplate" />) g
</select>

<sql id="groupNamesByQueryAndTemplate">
FROM
(SELECT
g.id AS group_id,
g.uuid AS group_uuid,
g.name AS name,
ptg.permission_reference AS permission,
ptg.template_uuid AS templateUuid
FROM groups g
LEFT JOIN perm_templates_groups ptg ON
ptg.group_id=g.id
ptg.group_uuid=g.uuid
AND ptg.template_uuid=#{templateUuid}
where
g.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
UNION ALL
SELECT
0 AS group_id,
'Anyone' AS group_uuid,
'Anyone' AS name,
ptg.permission_reference AS permission,
ptg.template_uuid AS templateUuid
@@ -197,7 +197,7 @@
<where>
g.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
<if test="query.withAtLeastOnePermission()">
AND ptg.group_id IS NULL
AND ptg.group_uuid IS NULL
</if>
</where>
) groups
@@ -278,7 +278,7 @@
sub.uuid,
sub.templateUuid,
sub.permission,
sub.groupId,
sub.groupUuid,
sub.groupName,
sub.createdAt,
sub.updatedAt
@@ -287,30 +287,30 @@
ptg.uuid,
ptg.template_uuid as templateUuid,
ptg.permission_reference AS permission,
ptg.group_id AS groupId,
ptg.group_uuid AS groupUuid,
g.name AS groupName,
ptg.created_at as createdAt,
ptg.updated_at as updatedAt
FROM perm_templates_groups ptg
INNER JOIN groups g ON
g.id=ptg.group_id
g.uuid=ptg.group_uuid
UNION ALL
SELECT
ptg.uuid,
ptg.template_uuid as templateUuid,
ptg.permission_reference AS permission,
0 AS groupId,
'Anyone' AS groupUuid,
'Anyone' AS groupName,
ptg.created_at as createdAt,
ptg.updated_at as updatedAt
FROM perm_templates_groups ptg
WHERE ptg.group_id IS NULL
WHERE ptg.group_uuid IS NULL
) sub
<where>
sub.templateUuid=#{templateUuid}
<if test="!groups.isEmpty()">
AND sub.groupName IN <foreach collection="groups" open="(" close=")" item="group" separator=",">
#{group}
#{group,jdbcType=VARCHAR}
</foreach>
</if>
</where>
@@ -329,7 +329,7 @@
-- from template groups except anyone group
select ptg.permission_reference as permission_key
from perm_templates_groups ptg
inner join groups_users gu on ptg.group_id = gu.group_id
inner join groups_users gu on ptg.group_uuid = gu.group_uuid
<where>
and gu.user_id=#{userId}
and ptg.template_uuid=#{templateUuid}
@@ -348,7 +348,7 @@
select ptg.permission_reference as permission_key
from perm_templates_groups ptg
where ptg.template_uuid=#{templateUuid}
and ptg.group_id IS NULL
and ptg.group_uuid IS NULL
</select>

<select id="usersCountByTemplateUuidAndPermission" parameterType="map"
@@ -372,13 +372,13 @@
FROM
(SELECT g.name as name, ptg.permission_reference as permission, ptg.template_uuid as templateUuid
FROM groups g
INNER JOIN perm_templates_groups ptg ON ptg.group_id=g.id
INNER JOIN perm_templates_groups ptg ON ptg.group_uuid=g.uuid
UNION
-- Add Anyone group permission
SELECT #{anyoneGroup} as name, ptg.permission_reference as permission, ptg.template_uuid as templateUuid
FROM perm_templates_groups ptg
<where>
AND ptg.group_id IS NULL
AND ptg.group_uuid IS NULL
</where>
) groups
<where>
@@ -396,11 +396,11 @@
where ptg.template_uuid = #{templateUuid}
and ptg.permission_reference = #{permission}
and
<if test="groupId == null">
ptg.group_id is null
<if test="groupUuid == null">
ptg.group_uuid is null
</if>
<if test="groupId != null">
ptg.group_id = #{groupId}
<if test="groupUuid != null">
ptg.group_uuid = #{groupUuid}
</if>
</select>

@@ -413,19 +413,19 @@
organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
</select>

<select id="selectAllGroupPermissionTemplatesByGroupId" parameterType="Long" resultType="PermissionTemplateGroup">
<select id="selectAllGroupPermissionTemplatesByGroupUuid" parameterType="string" resultType="PermissionTemplateGroup">
SELECT
ptg.uuid,
ptg.template_uuid as templateUuid,
ptg.permission_reference AS permission,
ptg.group_id AS groupId,
ptg.group_uuid AS groupUuid,
g.name AS groupName,
ptg.created_at as createdAt,
ptg.updated_at as updatedAt
FROM perm_templates_groups ptg
INNER JOIN groups g ON g.id=ptg.group_id
INNER JOIN groups g ON g.uuid=ptg.group_uuid
<where>
ptg.group_id=#{groupId,jdbcType=INTEGER}
ptg.group_uuid=#{groupUuid,jdbcType=VARCHAR}
</where>
</select>
</mapper>

+ 13
- 13
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml Ver fichero

@@ -5,7 +5,7 @@

<sql id="sqlColumns">
qeg.uuid as "uuid",
qeg.group_id as "groupId",
qeg.group_uuid as "groupUuid",
qeg.qprofile_uuid as "qProfileUuid"
</sql>

@@ -14,19 +14,19 @@
<include refid="sqlColumns"/>
from qprofile_edit_groups qeg
where
<foreach collection="groupIds" open="(" close=")" item="groupId" separator=" or ">
qeg.group_id = #{groupId, jdbcType=INTEGER}
<foreach collection="groupUuids" open="(" close=")" item="groupUuid" separator=" or ">
qeg.group_uuid = #{groupUuid, jdbcType=VARCHAR}
</foreach>
and qeg.qprofile_uuid = #{qProfileUuid, jdbcType=VARCHAR}
</select>

<select id="countByQuery" resultType="int">
select count(g.id)
select count(g.uuid)
<include refid="sqlSelectByQuery" />
</select>

<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.qualityprofile.GroupMembershipDto">
SELECT g.id as groupId, g.name as name, qeg.uuid as uuid
SELECT g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
<include refid="sqlSelectByQuery"/>
ORDER BY g.name ASC
LIMIT #{pagination.pageSize,jdbcType=INTEGER}
@@ -36,7 +36,7 @@
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.qualityprofile.GroupMembershipDto" databaseId="mssql">
select * from (
select row_number() over(order by g.name asc) as number,
g.id as groupId, g.name as name, qeg.uuid as uuid
g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
<include refid="sqlSelectByQuery" />
) as query
where
@@ -47,7 +47,7 @@
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.qualityprofile.GroupMembershipDto" databaseId="oracle">
select * from (
select rownum as rn, t.* from (
select g.id as groupId, g.name as name, qeg.uuid as uuid
select g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
<include refid="sqlSelectByQuery"/>
order by g.name ASC
) t
@@ -58,7 +58,7 @@

<sql id="sqlSelectByQuery">
FROM groups g
LEFT JOIN qprofile_edit_groups qeg ON qeg.group_id=g.id AND qeg.qprofile_uuid=#{query.qProfileUuid, jdbcType=VARCHAR}
LEFT JOIN qprofile_edit_groups qeg ON qeg.group_uuid=g.uuid AND qeg.qprofile_uuid=#{query.qProfileUuid, jdbcType=VARCHAR}
<where>
AND g.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
<choose>
@@ -80,19 +80,19 @@
from qprofile_edit_groups qeg
inner join org_qprofiles oq on qeg.qprofile_uuid=oq.uuid and oq.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
<where>
qeg.group_id in <foreach collection="groupIds" open="(" close=")" item="groupId" separator=",">#{groupId, jdbcType=INTEGER}</foreach>
qeg.group_uuid in <foreach collection="groupUuids" open="(" close=")" item="groupUuid" separator=",">#{groupUuid, jdbcType=VARCHAR}</foreach>
</where>
</select>

<insert id="insert" useGeneratedKeys="false" parameterType="map">
insert into qprofile_edit_groups(
uuid,
group_id,
group_uuid,
qprofile_uuid,
created_at
) values (
#{dto.uuid, jdbcType=VARCHAR},
#{dto.groupId, jdbcType=INTEGER},
#{dto.groupUuid, jdbcType=VARCHAR},
#{dto.qProfileUuid, jdbcType=VARCHAR},
#{now, jdbcType=BIGINT}
)
@@ -101,7 +101,7 @@
<delete id="delete" parameterType="map">
delete from qprofile_edit_groups
where qprofile_uuid = #{qProfileUuid, jdbcType=VARCHAR}
and group_id = #{groupId, jdbcType=INTEGER}
and group_uuid = #{groupUuid, jdbcType=VARCHAR}
</delete>

<delete id="deleteByQProfiles" parameterType="map">
@@ -111,7 +111,7 @@

<delete id="deleteByGroup" parameterType="map">
delete from qprofile_edit_groups
where group_id = #{groupId, jdbcType=INTEGER}
where group_uuid = #{groupUuid, jdbcType=VARCHAR}
</delete>

</mapper>

+ 16
- 14
server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml Ver fichero

@@ -5,7 +5,7 @@
<mapper namespace="org.sonar.db.user.GroupMapper">

<sql id="groupColumns">
g.id as id,
g.uuid as uuid,
g.name as name,
g.description as description,
g.organization_uuid as organizationUuid,
@@ -20,29 +20,29 @@
where g.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and g.name = #{name,jdbcType=VARCHAR}
</select>

<select id="selectByIds" parameterType="int" resultType="Group">
<select id="selectByUuids" parameterType="String" resultType="Group">
select
<include refid="groupColumns"/>
from groups g
where g.id in
<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
#{id,jdbcType=BIGINT}
where g.uuid in
<foreach item="uuid" index="index" collection="uuids" open="(" separator="," close=")">
#{uuid,jdbcType=VARCHAR}
</foreach>
</select>

<select id="selectById" parameterType="int" resultType="Group">
<select id="selectByUuid" parameterType="String" resultType="Group">
SELECT
<include refid="groupColumns"/>
FROM groups g
<where>
g.id=#{id,jdbcType=BIGINT}
g.uuid=#{uuid,jdbcType=VARCHAR}
</where>
</select>

<delete id="deleteById" parameterType="int">
<delete id="deleteByUuid" parameterType="String">
DELETE FROM groups
<where>
id=#{id,jdbcType=BIGINT}
uuid=#{uuid,jdbcType=VARCHAR}
</where>
</delete>

@@ -57,7 +57,7 @@
select
<include refid="groupColumns"/>
from groups g
inner join groups_users gu on gu.group_id = g.id
inner join groups_users gu on gu.group_uuid = g.uuid
inner join users u on u.id = gu.user_id
where u.login=#{login,jdbcType=VARCHAR}
</select>
@@ -74,14 +74,16 @@
</foreach>
</select>

<insert id="insert" parameterType="Group" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
<insert id="insert" parameterType="Group" useGeneratedKeys="false">
insert into groups (
uuid,
organization_uuid,
name,
description,
created_at,
updated_at
) values (
#{uuid,jdbcType=VARCHAR},
#{organizationUuid,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR},
@@ -95,7 +97,7 @@
name=#{name,jdbcType=VARCHAR},
description=#{description,jdbcType=VARCHAR},
updated_at=#{updatedAt,jdbcType=TIMESTAMP}
WHERE id=#{id}
WHERE uuid=#{uuid}
</update>

<select id="selectByQuery" parameterType="map" resultType="Group">
@@ -120,13 +122,13 @@
</if>
</select>

<select id="countGroupByOrganizationAndId" parameterType="map" resultType="int">
<select id="countGroupByOrganizationAndUuid" parameterType="map" resultType="int">
select
count(1)
from groups g
where
g.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
and g.id = #{groupId,jdbcType=INTEGER}
and g.uuid = #{groupUuid,jdbcType=VARCHAR}
</select>

<select id="selectByOrganizationUuid" parameterType="map" resultType="Group">

+ 15
- 15
server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml Ver fichero

@@ -5,7 +5,7 @@

<sql id="commonClauses">
FROM groups g
LEFT JOIN groups_users gu ON gu.group_id=g.id AND gu.user_id=#{userId}
LEFT JOIN groups_users gu ON gu.group_uuid=g.uuid AND gu.user_id=#{userId}
<where>
AND g.organization_uuid=#{organizationUuid}
<choose>
@@ -23,24 +23,24 @@
</sql>

<select id="selectGroups" parameterType="map" resultType="GroupMembership">
SELECT g.id as id, g.name as name, g.description as description, gu.user_id as userId
SELECT g.uuid as uuid, g.name as name, g.description as description, gu.user_id as userId
<include refid="commonClauses"/>
ORDER BY g.name
</select>

<select id="countGroups" parameterType="map" resultType="int">
SELECT COUNT(g.id)
SELECT COUNT(g.uuid)
<include refid="commonClauses"/>
</select>

<select id="countUsersByGroup" parameterType="int" resultType="org.sonar.db.user.GroupUserCount">
SELECT g.name as groupName, count(gu.user_id) as userCount
FROM groups g
LEFT JOIN groups_users gu ON gu.group_id=g.id
LEFT JOIN groups_users gu ON gu.group_uuid=g.uuid
<where>
g.id in
<foreach collection="groupIds" open="(" close=")" item="id" separator=",">
#{id}
g.uuid in
<foreach collection="groupUuids" open="(" close=")" item="uuid" separator=",">
#{uuid}
</foreach>
</where>
GROUP BY g.name
@@ -50,7 +50,7 @@
SELECT u.login as login, g.name as groupName
FROM users u
LEFT JOIN groups_users gu ON gu.user_id=u.id
INNER JOIN groups g ON gu.group_id=g.id
INNER JOIN groups g ON gu.group_uuid=g.uuid
<where>
u.login in
<foreach collection="logins" open="(" close=")" item="login" separator=",">
@@ -64,7 +64,7 @@
SELECT u.login as login, g.name as groupName
FROM users u
LEFT JOIN groups_users gu ON gu.user_id=u.id
INNER JOIN groups g ON gu.group_id=g.id
INNER JOIN groups g ON gu.group_uuid=g.uuid
<where>
u.login in
<foreach collection="logins" open="(" close=")" item="login" separator=",">
@@ -77,15 +77,15 @@

<sql id="userCommonClauses">
FROM users u
LEFT JOIN groups_users gu ON gu.user_id=u.id AND gu.group_id=#{groupId}
LEFT JOIN groups_users gu ON gu.user_id=u.id AND gu.group_uuid=#{groupUuid}
INNER JOIN organization_members om ON u.id=om.user_id AND om.organization_uuid=#{organizationUuid}
<where>
<choose>
<when test="query.membership() == 'IN'">
AND gu.group_id IS NOT NULL
AND gu.group_uuid IS NOT NULL
</when>
<when test="query.membership() == 'OUT'">
AND gu.group_id IS NULL
AND gu.group_uuid IS NULL
</when>
</choose>
<if test="query.memberSearch() != null">
@@ -99,7 +99,7 @@
</sql>

<select id="selectMembers" parameterType="map" resultType="org.sonar.db.user.UserMembershipDto">
SELECT u.id as id, u.login as login, u.name as name, gu.group_id as groupId
SELECT u.id as id, u.login as login, u.name as name, gu.group_uuid as groupUuid
<include refid="userCommonClauses"/>
ORDER BY u.name ASC
</select>
@@ -109,8 +109,8 @@
<include refid="userCommonClauses"/>
</select>

<select id="selectGroupIdsByUserId" parameterType="map" resultType="int">
select group_id
<select id="selectGroupUuidsByUserId" parameterType="map" resultType="string">
select group_uuid
from groups_users
where user_id = #{userId}
</select>

+ 3
- 3
server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml Ver fichero

@@ -18,7 +18,7 @@
from
group_roles gr
inner join groups_users gu on
gr.group_id=gu.group_id
gr.group_uuid=gu.group_uuid
where
gr.role = #{permission,jdbcType=VARCHAR}
and gr.component_uuid is not null
@@ -27,10 +27,10 @@
component_uuid
</select>

<delete id="deleteGroupRolesByGroupId" parameterType="int">
<delete id="deleteGroupRolesByGroupUuid" parameterType="String">
delete from
group_roles
where
group_id=#{id,jdbcType=INTEGER}
group_uuid=#{uuid,jdbcType=VARCHAR}
</delete>
</mapper>

+ 6
- 6
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserGroupMapper.xml Ver fichero

@@ -6,28 +6,28 @@
<insert id="insert" parameterType="UserGroup" useGeneratedKeys="false">
insert into groups_users (
user_id,
group_id
group_uuid
) values (
#{userId,jdbcType=INTEGER},
#{groupId,jdbcType=INTEGER}
#{groupUuid,jdbcType=VARCHAR}
)
</insert>

<delete id="delete" parameterType="map">
delete from groups_users
where user_id = #{userId,jdbcType=INTEGER} and
group_id = #{groupId,jdbcType=INTEGER}
group_uuid = #{groupUuid,jdbcType=VARCHAR}
</delete>

<delete id="deleteByGroupId" parameterType="int">
<delete id="deleteByGroupUuid" parameterType="string">
delete from groups_users
where group_id = #{groupId,jdbcType=INTEGER}
where group_uuid = #{groupUuid,jdbcType=VARCHAR}
</delete>

<delete id="deleteByOrganizationAndUser" parameterType="map">
delete from groups_users
where user_id = #{userId,jdbcType=INTEGER} and
group_id in (select id from groups where organization_uuid=#{organizationUuid,jdbcType=VARCHAR})
group_uuid in (select uuid from groups where organization_uuid=#{organizationUuid,jdbcType=VARCHAR})
</delete>

<delete id="deleteByUserId" parameterType="int">

+ 22
- 14
server/sonar-db-dao/src/schema/schema-sq.ddl Ver fichero

@@ -313,32 +313,32 @@ CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES"("UPDATED_AT");

CREATE TABLE "GROUP_ROLES"(
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"GROUP_ID" INTEGER,
"ROLE" VARCHAR(64) NOT NULL,
"COMPONENT_UUID" VARCHAR(40),
"UUID" VARCHAR(40) NOT NULL
"UUID" VARCHAR(40) NOT NULL,
"GROUP_UUID" VARCHAR(40)
);
ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID");
CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_UUID", "COMPONENT_UUID", "ROLE");

CREATE TABLE "GROUPS"(
"ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(500),
"DESCRIPTION" VARCHAR(200),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
"UPDATED_AT" TIMESTAMP,
"UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID");
ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("UUID");

CREATE TABLE "GROUPS_USERS"(
"USER_ID" BIGINT,
"GROUP_ID" BIGINT
"GROUP_UUID" VARCHAR(40) NOT NULL
);
CREATE INDEX "INDEX_GROUPS_USERS_ON_USER_ID" ON "GROUPS_USERS"("USER_ID");
CREATE INDEX "INDEX_GROUPS_USERS_ON_GROUP_ID" ON "GROUPS_USERS"("GROUP_ID");
CREATE UNIQUE INDEX "GROUPS_USERS_UNIQUE" ON "GROUPS_USERS"("GROUP_ID", "USER_ID");
CREATE INDEX "INDEX_GROUPS_USERS_GROUP_UUID" ON "GROUPS_USERS"("GROUP_UUID");
CREATE UNIQUE INDEX "GROUPS_USERS_UNIQUE" ON "GROUPS_USERS"("GROUP_UUID", "USER_ID");

CREATE TABLE "INTERNAL_COMPONENT_PROPS"(
"UUID" VARCHAR(40) NOT NULL,
@@ -537,7 +537,6 @@ CREATE TABLE "ORGANIZATIONS"(
"URL" VARCHAR(256),
"AVATAR_URL" VARCHAR(256),
"GUARDED" BOOLEAN,
"DEFAULT_GROUP_ID" INTEGER,
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
"DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
"DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40),
@@ -545,18 +544,27 @@ CREATE TABLE "ORGANIZATIONS"(
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
"SUBSCRIPTION" VARCHAR(40) NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
"UPDATED_AT" BIGINT NOT NULL,
"DEFAULT_GROUP_UUID" VARCHAR(40)
);
ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE");

CREATE TABLE "PERM_TEMPLATES_GROUPS"(
<<<<<<< HEAD
"GROUP_ID" INTEGER,
=======
"TEMPLATE_ID" INTEGER NOT NULL,
>>>>>>> SONAR-13221 change PK of GROUPS and update FKs
"PERMISSION_REFERENCE" VARCHAR(64) NOT NULL,
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"UUID" VARCHAR(40) NOT NULL,
<<<<<<< HEAD
"TEMPLATE_UUID" VARCHAR(40) NOT NULL
=======
"GROUP_UUID" VARCHAR(40)
>>>>>>> SONAR-13221 change PK of GROUPS and update FKs
);
ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("UUID");

@@ -750,13 +758,13 @@ CREATE INDEX "QP_CHANGES_RULES_PROFILE_UUID" ON "QPROFILE_CHANGES"("RULES_PROFIL

CREATE TABLE "QPROFILE_EDIT_GROUPS"(
"UUID" VARCHAR(40) NOT NULL,
"GROUP_ID" INTEGER NOT NULL,
"QPROFILE_UUID" VARCHAR(255) NOT NULL,
"CREATED_AT" BIGINT NOT NULL
"CREATED_AT" BIGINT NOT NULL,
"GROUP_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "QPROFILE_EDIT_GROUPS" ADD CONSTRAINT "PK_QPROFILE_EDIT_GROUPS" PRIMARY KEY("UUID");
CREATE INDEX "QPROFILE_EDIT_GROUPS_QPROFILE" ON "QPROFILE_EDIT_GROUPS"("QPROFILE_UUID");
CREATE UNIQUE INDEX "QPROFILE_EDIT_GROUPS_UNIQUE" ON "QPROFILE_EDIT_GROUPS"("GROUP_ID", "QPROFILE_UUID");
CREATE UNIQUE INDEX "QPROFILE_EDIT_GROUPS_UNIQUE" ON "QPROFILE_EDIT_GROUPS"("GROUP_UUID", "QPROFILE_UUID");

CREATE TABLE "QPROFILE_EDIT_USERS"(
"UUID" VARCHAR(40) NOT NULL,

+ 15
- 15
server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java Ver fichero

@@ -679,46 +679,46 @@ public class OrganizationDaoTest {
}

@Test
public void getDefaultGroupId_returns_empty_when_default_group_id_is_null() {
insertOrganization(ORGANIZATION_DTO_1.setDefaultGroupId(null));
public void getDefaultGroupUuid_returns_empty_when_default_group_uuid_is_null() {
insertOrganization(ORGANIZATION_DTO_1.setDefaultGroupUuid(null));

assertThat(underTest.getDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid())).isEmpty();
assertThat(underTest.getDefaultGroupUuid(dbSession, ORGANIZATION_DTO_1.getUuid())).isEmpty();
}

@Test
public void getDefaultGroupId_returns_data_when_default_group_id_is_not_null() {
public void getDefaultGroupUuid_returns_data_when_default_group_uuid_is_not_null() {
when(system2.now()).thenReturn(DATE_3);
insertOrganization(ORGANIZATION_DTO_1);
underTest.setDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid(), GroupTesting.newGroupDto().setId(10));
underTest.setDefaultGroupUuid(dbSession, ORGANIZATION_DTO_1.getUuid(), GroupTesting.newGroupDto().setUuid("10"));

Optional<Integer> optional = underTest.getDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid());
Optional<String> optional = underTest.getDefaultGroupUuid(dbSession, ORGANIZATION_DTO_1.getUuid());
assertThat(optional).isNotEmpty();
assertThat(optional.get()).isEqualTo(10);
assertThat(optional.get()).isEqualTo("10");
verifyOrganizationUpdatedAt(ORGANIZATION_DTO_1.getUuid(), DATE_3);
}

@Test
public void setDefaultGroupId_throws_NPE_when_uuid_is_null() {
public void setDefaultGroupUuid_throws_NPE_when_uuid_is_null() {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("uuid can't be null");

underTest.setDefaultGroupId(dbSession, null, GroupTesting.newGroupDto().setId(10));
underTest.setDefaultGroupUuid(dbSession, null, GroupTesting.newGroupDto().setUuid("10"));
}

@Test
public void setDefaultGroupId_throws_NPE_when_default_group_is_null() {
public void setDefaultGroupUuid_throws_NPE_when_default_group_is_null() {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("Default group cannot be null");

underTest.setDefaultGroupId(dbSession, "uuid", null);
underTest.setDefaultGroupUuid(dbSession, "uuid", null);
}

@Test
public void setDefaultGroupId_throws_NPE_when_default_group_id_is_null() {
public void setDefaultGroupUuid_throws_NPE_when_default_group_uuid_is_null() {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("Default group id cannot be null");
expectedException.expectMessage("Default group uuid cannot be null");

underTest.setDefaultGroupId(dbSession, "uuid", GroupTesting.newGroupDto().setId(null));
underTest.setDefaultGroupUuid(dbSession, "uuid", GroupTesting.newGroupDto().setUuid(null));
}

@Test
@@ -801,7 +801,7 @@ public class OrganizationDaoTest {
.setName("new_name")
.setDescription("new_desc")
.setAvatarUrl("new_avatar")
.setDefaultGroupId(11)
.setDefaultGroupUuid("11")
.setSubscription(PAID)
.setUrl("new_url")
.setCreatedAt(2_000L)

+ 11
- 10
server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java Ver fichero

@@ -58,6 +58,7 @@ public class AuthorizationDaoTest {

private static final String PROJECT_UUID = "uuid";
private static final int MISSING_ID = -1;
private static final String MISSING_UUID = "unkown";
private static final String A_PERMISSION = "a-permission";
private static final String DOES_NOT_EXIST = "does-not-exist";

@@ -174,19 +175,19 @@ public class AuthorizationDaoTest {

// excluding group "g1" -> remain u1, u3 and u4
assertThat(underTest.countUsersWithGlobalPermissionExcludingGroup(db.getSession(),
organization.getUuid(), "perm1", group1.getId())).isEqualTo(3);
organization.getUuid(), "perm1", group1.getUuid())).isEqualTo(3);

// excluding group "g2" -> remain u1, u2 and u4
assertThat(underTest.countUsersWithGlobalPermissionExcludingGroup(db.getSession(),
organization.getUuid(), "perm1", group2.getId())).isEqualTo(3);
organization.getUuid(), "perm1", group2.getUuid())).isEqualTo(3);

// excluding group "g3" -> remain u1, u2, u3 and u4
assertThat(underTest.countUsersWithGlobalPermissionExcludingGroup(db.getSession(),
organization.getUuid(), "perm1", group3.getId())).isEqualTo(4);
organization.getUuid(), "perm1", group3.getUuid())).isEqualTo(4);

// nobody has the permission
assertThat(underTest.countUsersWithGlobalPermissionExcludingGroup(db.getSession(),
organization.getUuid(), "missingPermission", group1.getId())).isEqualTo(0);
organization.getUuid(), "missingPermission", group1.getUuid())).isEqualTo(0);
}

@Test
@@ -224,7 +225,7 @@ public class AuthorizationDaoTest {

// nobody has the permission
assertThat(underTest.countUsersWithGlobalPermissionExcludingUser(db.getSession(),
organization.getUuid(), "missingPermission", group1.getId())).isEqualTo(0);
organization.getUuid(), "missingPermission", 123)).isEqualTo(0);
}

@Test
@@ -726,21 +727,21 @@ public class AuthorizationDaoTest {
db.users().insertMember(group1, u3);

// excluding u2 membership --> remain u1 and u3
int count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), A_PERMISSION, group1.getId(), u2.getId());
int count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), A_PERMISSION, group1.getUuid(), u2.getId());
assertThat(count).isEqualTo(2);

// excluding unknown memberships
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), A_PERMISSION, group1.getId(), MISSING_ID);
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), A_PERMISSION, group1.getUuid(), MISSING_ID);
assertThat(count).isEqualTo(3);
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), A_PERMISSION, MISSING_ID, u2.getId());
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), A_PERMISSION, MISSING_UUID, u2.getId());
assertThat(count).isEqualTo(3);

// another organization
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, DOES_NOT_EXIST, A_PERMISSION, group1.getId(), u2.getId());
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, DOES_NOT_EXIST, A_PERMISSION, group1.getUuid(), u2.getId());
assertThat(count).isEqualTo(0);

// another permission
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), DOES_NOT_EXIST, group1.getId(), u2.getId());
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, organization.getUuid(), DOES_NOT_EXIST, group1.getUuid(), u2.getId());
assertThat(count).isEqualTo(0);
}


+ 124
- 124
server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java Ver fichero

@@ -55,8 +55,8 @@ import static org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE;

public class GroupPermissionDaoTest {

private static final int ANYONE_ID = 0;
private static final int MISSING_ID = -1;
private static final String ANYONE_UUID = "Anyone";
private static final String MISSING_UUID = "-1";

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
@@ -305,7 +305,7 @@ public class GroupPermissionDaoTest {
}

@Test
public void selectByGroupIds_on_global_permissions() {
public void selectByGroupUuids_on_global_permissions() {
OrganizationDto organizationDto = db.organizations().insert();

GroupDto group1 = db.users().insertGroup(organizationDto, "Group-1");
@@ -322,29 +322,29 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(organizationDto, SCAN);
db.users().insertPermissionOnAnyone(organizationDto, PROVISION_PROJECTS);

assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group1.getId()), null))
.extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group1.getId(), SCAN_EXECUTION, null));
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), asList(group1.getUuid()), null))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group1.getUuid(), SCAN_EXECUTION, null));

assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group2.getId()), null)).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), asList(group2.getUuid()), null)).isEmpty();

assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group3.getId()), null))
.extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group3.getId(), ADMINISTER.getKey(), null));
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), asList(group3.getUuid()), null))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group3.getUuid(), ADMINISTER.getKey(), null));

assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(ANYONE_ID), null))
.extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), asList(ANYONE_UUID), null))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(
tuple(0, SCAN.getKey(), null),
tuple(0, PROVISION_PROJECTS.getKey(), null));
tuple(ANYONE_UUID, SCAN.getKey(), null),
tuple(ANYONE_UUID, PROVISION_PROJECTS.getKey(), null));

assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), null)).hasSize(3);
assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(MISSING_ID), null)).isEmpty();
assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), Collections.emptyList(), null)).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), asList(group1.getUuid(), group2.getUuid(), ANYONE_UUID), null)).hasSize(3);
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), asList(MISSING_UUID), null)).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, organizationDto.getUuid(), Collections.emptyList(), null)).isEmpty();
}

@Test
public void selectByGroupIds_on_public_projects() {
public void selectByGroupUuids_on_public_projects() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org, "Group-1");
db.users().insertPermissionOnGroup(group1, "p1");
@@ -360,28 +360,28 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(org, "p3");
db.users().insertProjectPermissionOnAnyone("p4", project);

assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.uuid())).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, defaultOrganizationUuid, singletonList(group1.getUuid()), project.uuid())).isEmpty();

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.selectByGroupUuids(dbSession, org.getUuid(), singletonList(group2.getUuid()), project.uuid()))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group2.getUuid(), "p2", project.uuid()));

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.selectByGroupUuids(dbSession, org.getUuid(), singletonList(group3.getUuid()), project.uuid()))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group3.getUuid(), "p2", project.uuid()));

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.selectByGroupUuids(dbSession, org.getUuid(), singletonList(ANYONE_UUID), project.uuid()))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(ANYONE_UUID, "p4", project.uuid()));

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();
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), asList(group1.getUuid(), group2.getUuid(), ANYONE_UUID), project.uuid())).hasSize(2);
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), singletonList(MISSING_UUID), project.uuid())).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), singletonList(group1.getUuid()), "123")).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), Collections.emptyList(), project.uuid())).isEmpty();
}

@Test
public void selectByGroupIds_on_private_projects() {
public void selectByGroupUuids_on_private_projects() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org, "Group-1");
db.users().insertPermissionOnGroup(group1, PROVISION_PROJECTS);
@@ -396,23 +396,23 @@ public class GroupPermissionDaoTest {
// Anyone group
db.users().insertPermissionOnAnyone(org, SCAN);

assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.uuid())).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, defaultOrganizationUuid, singletonList(group1.getUuid()), project.uuid())).isEmpty();

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.selectByGroupUuids(dbSession, org.getUuid(), singletonList(group2.getUuid()), project.uuid()))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group2.getUuid(), USER, project.uuid()));

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.selectByGroupUuids(dbSession, org.getUuid(), singletonList(group3.getUuid()), project.uuid()))
.extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
.containsOnly(tuple(group3.getUuid(), USER, project.uuid()));

assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.uuid()))
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), singletonList(ANYONE_UUID), project.uuid()))
.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();
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), asList(group1.getUuid(), group2.getUuid(), ANYONE_UUID), project.uuid())).hasSize(1);
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), singletonList(MISSING_UUID), project.uuid())).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), singletonList(group1.getUuid()), "123")).isEmpty();
assertThat(underTest.selectByGroupUuids(dbSession, org.getUuid(), Collections.emptyList(), project.uuid())).isEmpty();
}

@Test
@@ -430,12 +430,12 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm5", project);
db.users().insertProjectPermissionOnAnyone("perm6", project);

assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId())).containsOnly("perm2", "perm3");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), group2.getId())).containsOnly("perm4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org1.getUuid(), group1.getUuid())).containsOnly("perm2", "perm3");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), group2.getUuid())).containsOnly("perm4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org1.getUuid(), null)).containsOnly("perm1");

// group1 is not in org2
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), group1.getId())).isEmpty();
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), group1.getUuid())).isEmpty();
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), null)).isEmpty();
}

@@ -453,9 +453,9 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
db.users().insertProjectPermissionOnAnyone("perm6", project1);

assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getUuid(), project1.uuid()))
.containsOnly("perm3", "perm4");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getUuid(), project2.uuid()))
.containsOnly("perm5");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.uuid()))
.containsOnly("perm6");
@@ -476,9 +476,9 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm4", project1);
db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);

assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getUuid(), project1.uuid()))
.containsOnly("perm3", "perm4");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getUuid(), project2.uuid()))
.containsOnly("perm5");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.uuid()))
.isEmpty();
@@ -487,7 +487,7 @@ public class GroupPermissionDaoTest {
}

@Test
public void selectAllPermissionsByGroupId_on_public_project() {
public void selectAllPermissionsByGroupUuid_on_public_project() {
OrganizationDto org1 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
ComponentDto project1 = db.components().insertPublicProject(org1);
@@ -500,14 +500,14 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnAnyone("perm6", project1);

List<GroupPermissionDto> result = new ArrayList<>();
underTest.selectAllPermissionsByGroupId(dbSession, org1.getUuid(), group1.getId(), context -> result.add((GroupPermissionDto) context.getResultObject()));
underTest.selectAllPermissionsByGroupUuid(dbSession, org1.getUuid(), group1.getUuid(), context -> result.add((GroupPermissionDto) context.getResultObject()));
assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
tuple(null, "perm2"),
tuple(project1.uuid(), "perm3"), tuple(project1.uuid(), "perm4"), tuple(project2.uuid(), "perm5"));
}

@Test
public void selectAllPermissionsByGroupId_on_private_project() {
public void selectAllPermissionsByGroupUuid_on_private_project() {
OrganizationDto org1 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
ComponentDto project1 = db.components().insertPrivateProject(org1);
@@ -519,25 +519,25 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);

List<GroupPermissionDto> result = new ArrayList<>();
underTest.selectAllPermissionsByGroupId(dbSession, org1.getUuid(), group1.getId(), context -> result.add((GroupPermissionDto) context.getResultObject()));
underTest.selectAllPermissionsByGroupUuid(dbSession, org1.getUuid(), group1.getUuid(), context -> result.add((GroupPermissionDto) context.getResultObject()));
assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
tuple(null, "perm2"),
tuple(project1.uuid(), "perm3"), tuple(project1.uuid(), "perm4"), tuple(project2.uuid(), "perm5"));
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_returns_empty_if_project_does_not_exist() {
public void selectGroupUuidsWithPermissionOnProjectBut_returns_empty_if_project_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
GroupDto group = db.users().insertGroup(organization);
db.users().insertProjectPermissionOnGroup(group, "foo", project);

assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER))
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER))
.isEmpty();
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_returns_only_groups_of_project_which_do_not_have_permission() {
public void selectGroupUuidsWithPermissionOnProjectBut_returns_only_groups_of_project_which_do_not_have_permission() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
@@ -545,16 +545,16 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "p1", project);
db.users().insertProjectPermissionOnGroup(group2, "p2", project);

assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getId());
assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getId());
assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p3"))
.containsOnly(group1.getId(), group2.getId());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getUuid());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getUuid());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p3"))
.containsOnly(group1.getUuid(), group2.getUuid());
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_does_not_returns_group_AnyOne_of_project_when_it_does_not_have_permission() {
public void selectGroupUuidsWithPermissionOnProjectBut_does_not_returns_group_AnyOne_of_project_when_it_does_not_have_permission() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
@@ -563,14 +563,14 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group2, "p2", project);
db.users().insertProjectPermissionOnAnyone("p2", project);

assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getId());
assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getId());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getUuid());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getUuid());
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_does_not_return_groups_which_have_no_permission_at_all_on_specified_project() {
public void selectGroupUuidsWithPermissionOnProjectBut_does_not_return_groups_which_have_no_permission_at_all_on_specified_project() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
@@ -579,10 +579,10 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "p1", project);
db.users().insertProjectPermissionOnGroup(group2, "p2", project);

assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getId());
assertThat(underTest.selectGroupIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getId());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2"))
.containsOnly(group1.getUuid());
assertThat(underTest.selectGroupUuidsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1"))
.containsOnly(group2.getUuid());
}

@Test
@@ -633,7 +633,7 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);

underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getUuid(), null);
dbSession.commit();

assertThatNoPermission("perm2");
@@ -649,7 +649,7 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);

underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getUuid(), null);
dbSession.commit();

assertThatNoPermission("perm2");
@@ -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.uuid());
underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getUuid(), 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.uuid());
underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getUuid(), project1.uuid());
dbSession.commit();

assertThatNoPermission("perm3");
@@ -765,7 +765,7 @@ public class GroupPermissionDaoTest {
}

@Test
public void deleteByRootComponentUuidAndGroupId_deletes_all_permissions_of_group_AnyOne_of_specified_component_if_groupId_is_null() {
public void deleteByRootComponentUuidAndGroupUuid_deletes_all_permissions_of_group_AnyOne_of_specified_component_if_groupUuid_is_null() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group = db.users().insertGroup(organization);
@@ -775,28 +775,28 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnGroup(group, "p4");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), project.uuid()))
.containsOnly("p2");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p3");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid()))
.containsOnly("p4");

int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), null);
int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null);

assertThat(deletedCount).isEqualTo(1);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.isEmpty();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), project.uuid()))
.containsOnly("p2");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p3");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid()))
.containsOnly("p4");
}

@Test
public void deleteByRootComponentUuidAndGroupId_deletes_all_permissions_of_specified_group_of_specified_component_if_groupId_is_non_null() {
public void deleteByRootComponentUuidAndGroupUuid_deletes_all_permissions_of_specified_group_of_specified_component_if_groupUuid_is_non_null() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(organization);
GroupDto group1 = db.users().insertGroup(organization);
@@ -810,101 +810,101 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnGroup(group2, "p7");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid()))
.containsOnly("p2");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid(), project.uuid()))
.containsOnly("p3", "p4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p5");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid()))
.containsOnly("p6");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid()))
.containsOnly("p7");

int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group1.getId());
int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group1.getUuid());

assertThat(deletedCount).isEqualTo(1);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid()))
.isEmpty();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid(), project.uuid()))
.containsOnly("p3", "p4");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid()))
.containsOnly("p6");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid()))
.containsOnly("p7");

deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group2.getId());
deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid());

assertThat(deletedCount).isEqualTo(2);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid()))
.isEmpty();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid(), project.uuid()))
.isEmpty();
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid()))
.containsOnly("p6");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid()))
.containsOnly("p7");
}

@Test
public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_does_not_exist() {
public void deleteByRootComponentUuidAndGroupUuid_has_no_effect_if_component_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
GroupDto group = db.users().insertGroup(organization);

assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, "1234", null)).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, "1234", group.getId())).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", null)).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", group.getUuid())).isEqualTo(0);
}

@Test
public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_has_no_group_permission_at_all() {
public void deleteByRootComponentUuidAndGroupUuid_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.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), null)).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group.getId())).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null)).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid())).isEqualTo(0);
}

@Test
public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_group_does_not_exist() {
public void deleteByRootComponentUuidAndGroupUuid_has_no_effect_if_group_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);

assertThat(underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), 5678)).isEqualTo(0);
assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), "5678")).isEqualTo(0);
}

@Test
public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_has_no_group_permission_for_group_AnyOne() {
public void deleteByRootComponentUuidAndGroupUuid_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.uuid()))
.isEmpty();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid()))
.containsOnly("p1");
db.users().insertPermissionOnAnyone(organization, "p2");
db.users().insertPermissionOnGroup(group1, "p3");

int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), null);
int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null);

assertThat(deletedCount).isEqualTo(0);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), null, project.uuid()))
.isEmpty();
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p2");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid()))
.containsOnly("p3");
}

@Test
public void deleteByRootComponentUuidAndGroupId_has_no_effect_if_component_has_no_group_permission_for_specified_group() {
public void deleteByRootComponentUuidAndGroupUuid_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,16 +913,16 @@ public class GroupPermissionDaoTest {
db.users().insertPermissionOnAnyone(organization, "p2");
db.users().insertPermissionOnGroup(group1, "p3");

int deletedCount = underTest.deleteByRootComponentUuidAndGroupId(dbSession, project.uuid(), group2.getId());
int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid());

assertThat(deletedCount).isEqualTo(0);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid()))
.containsOnly("p1");
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid()))
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid(), project.uuid()))
.isEmpty();
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), null))
.containsOnly("p2");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId()))
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid()))
.containsOnly("p3");
}

@@ -1005,22 +1005,22 @@ public class GroupPermissionDaoTest {
}

private Collection<String> getGlobalPermissionsForAnyone(OrganizationDto organization) {
return getPermissions("organization_uuid = '" + organization.getUuid() + "' and group_id is null and component_uuid is null");
return getPermissions("organization_uuid = '" + organization.getUuid() + "' and group_uuid 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 component_uuid is null");
"' and group_uuid = '" + groupDto.getUuid() + "' and component_uuid is null");
}

private Collection<String> getProjectPermissionsForAnyOne(ComponentDto project) {
return getPermissions("organization_uuid = '" + project.getOrganizationUuid() +
"' and group_id is null and component_uuid = '" + project.uuid() + "'");
"' and group_uuid 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 component_uuid = '" + project.uuid() + "'");
"' and group_uuid = '" + group.getUuid() + "' and component_uuid = '" + project.uuid() + "'");
}

private Collection<String> getPermissions(String whereClauses) {
@@ -1046,12 +1046,12 @@ public class GroupPermissionDaoTest {
.containsOnly(organizationUuids);
}

private int insertGroupWithPermissions(OrganizationDto organization1) {
private String insertGroupWithPermissions(OrganizationDto organization1) {
GroupDto group = db.users().insertGroup(organization1);
db.users().insertPermissionOnGroup(group, "foo");
db.users().insertPermissionOnGroup(group, "bar");
db.users().insertPermissionOnGroup(group, "doh");
return group.getId();
return group.getUuid();
}

private void assertThatNoPermission(String permission) {

+ 3
- 3
server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java Ver fichero

@@ -496,7 +496,7 @@ public class UserPermissionDaoTest {
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_returns_empty_if_project_does_not_exist() {
public void selectGroupUuidsWithPermissionOnProjectBut_returns_empty_if_project_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
UserDto user = insertUser(organization);
@@ -507,7 +507,7 @@ public class UserPermissionDaoTest {
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_returns_only_users_of_projects_which_do_not_have_permission() {
public void selectGroupUuidsWithPermissionOnProjectBut_returns_only_users_of_projects_which_do_not_have_permission() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
UserDto user1 = insertUser(organization);
@@ -524,7 +524,7 @@ public class UserPermissionDaoTest {
}

@Test
public void selectGroupIdsWithPermissionOnProjectBut_does_not_return_groups_which_have_no_permission_at_all_on_specified_project() {
public void selectGroupUuidsWithPermissionOnProjectBut_does_not_return_groups_which_have_no_permission_at_all_on_specified_project() {
OrganizationDto organization = db.organizations().insert();
ComponentDto project = randomPublicOrPrivateProject(organization);
UserDto user1 = insertUser(organization);

+ 31
- 31
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java Ver fichero

@@ -59,13 +59,13 @@ public class GroupWithPermissionTemplateDaoTest {
GroupDto group3 = db.users().insertGroup(organization, "Group-3");

PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate(organization);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);

PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate(organization);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);

assertThat(selectGroupNamesByQueryAndTemplate(builder(), organization, template))
.containsOnly("Group-1", "Group-2", "Group-3", "Anyone");
@@ -159,7 +159,7 @@ public class GroupWithPermissionTemplateDaoTest {

GroupDto group = db.users().insertGroup(organization, "Group");
PermissionTemplateDto otherTemplate = permissionTemplateDbTester.insertTemplate(organization);
permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getUuid(), group.getId(), USER);
permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getUuid(), group.getUuid(), USER);

assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("nyo"), organization, template))
.containsExactly("Anyone");
@@ -173,13 +173,13 @@ public class GroupWithPermissionTemplateDaoTest {
GroupDto group3 = db.users().insertGroup(organization, "Group-3");

PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate(organization);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);

PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate(organization);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);

assertThat(countGroupNamesByQueryAndTemplate(builder().setOrganizationUuid(organization.getUuid()), organization, template))
.isEqualTo(4);
@@ -208,29 +208,29 @@ public class GroupWithPermissionTemplateDaoTest {
GroupDto group3 = db.users().insertGroup(newGroupDto().setName("Group-3"));

PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);

PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);

assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getUuid(), asList("Group-1")))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.containsOnly(
tuple(group1.getId(), "Group-1", USER),
tuple(group1.getId(), "Group-1", ADMIN));
tuple(group1.getUuid(), "Group-1", USER),
tuple(group1.getUuid(), "Group-1", ADMIN));

assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, anotherTemplate.getUuid(), asList("Group-1")))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.containsOnly(
tuple(group1.getId(), "Group-1", PROVISIONING));
tuple(group1.getUuid(), "Group-1", PROVISIONING));

assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, anotherTemplate.getUuid(), asList("Anyone")))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.containsOnly(
tuple(0, "Anyone", USER));
tuple("Anyone", "Anyone", USER));

assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getUuid(), asList("Group-1", "Group-2", "Anyone"))).hasSize(3);
assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getUuid(), asList("Unknown"))).isEmpty();
@@ -244,25 +244,25 @@ public class GroupWithPermissionTemplateDaoTest {
GroupDto group3 = db.users().insertGroup(newGroupDto().setName("Group-3"));

PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getId(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);

PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getId(), PROVISIONING);
permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);

assertThat(underTest.selectGroupPermissionsByTemplateUuid(session, template.getUuid()))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.containsOnly(
tuple(group1.getId(), "Group-1", USER),
tuple(group1.getId(), "Group-1", ADMIN),
tuple(group2.getId(), "Group-2", PROVISIONING));
tuple(group1.getUuid(), "Group-1", USER),
tuple(group1.getUuid(), "Group-1", ADMIN),
tuple(group2.getUuid(), "Group-2", PROVISIONING));
assertThat(underTest.selectGroupPermissionsByTemplateUuid(session, anotherTemplate.getUuid()))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
.containsOnly(
tuple(group1.getId(), "Group-1", PROVISIONING),
tuple(0, "Anyone", USER));
tuple(group1.getUuid(), "Group-1", PROVISIONING),
tuple("Anyone", "Anyone", USER));

assertThat(underTest.selectGroupPermissionsByTemplateUuid(session, "321")).isEmpty();
}

+ 22
- 22
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java Ver fichero

@@ -239,14 +239,14 @@ public class PermissionTemplateDaoTest {
PermissionTemplateDto permissionTemplate = templateDb.insertTemplate(db.getDefaultOrganization());
GroupDto group = db.users().insertGroup();

underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getId(), "user");
underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getUuid(), "user");
dbSession.commit();

assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
.extracting(PermissionTemplateGroupDto::getTemplateUuid, PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission,
.extracting(PermissionTemplateGroupDto::getTemplateUuid, PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission,
PermissionTemplateGroupDto::getCreatedAt,
PermissionTemplateGroupDto::getUpdatedAt)
.containsOnly(tuple(permissionTemplate.getUuid(), group.getId(), "user", NOW, NOW));
.containsOnly(tuple(permissionTemplate.getUuid(), group.getUuid(), "user", NOW, NOW));
}

@Test
@@ -258,12 +258,12 @@ public class PermissionTemplateDaoTest {
templateDb.addGroupToTemplate(permissionTemplate, group1, "admin");
templateDb.addGroupToTemplate(permissionTemplate, group2, "user");

underTest.deleteByGroup(db.getSession(), group1.getId());
underTest.deleteByGroup(db.getSession(), group1.getUuid());
db.getSession().commit();

assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission)
.containsOnly(tuple(group2.getId(), "user"));
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission)
.containsOnly(tuple(group2.getUuid(), "user"));
}

@Test
@@ -274,9 +274,9 @@ public class PermissionTemplateDaoTest {
dbSession.commit();

assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
.extracting(PermissionTemplateGroupDto::getTemplateUuid, PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName,
.extracting(PermissionTemplateGroupDto::getTemplateUuid, PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName,
PermissionTemplateGroupDto::getPermission)
.containsOnly(tuple(permissionTemplate.getUuid(), 0, "Anyone", "user"));
.containsOnly(tuple(permissionTemplate.getUuid(), "Anyone", "Anyone", "user"));
}

@Test
@@ -288,13 +288,13 @@ public class PermissionTemplateDaoTest {
GroupDto group1 = db.users().insertGroup(newGroupDto());
GroupDto group2 = db.users().insertGroup(newGroupDto());
GroupDto group3 = db.users().insertGroup(newGroupDto());
templateDb.addGroupToTemplate(template1.getUuid(), group1.getId(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), group2.getId(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), group3.getId(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), group2.getUuid(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), group3.getUuid(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), null, CODEVIEWER);
templateDb.addGroupToTemplate(template1.getUuid(), group1.getId(), ADMIN);
templateDb.addGroupToTemplate(template2.getUuid(), group1.getId(), ADMIN);
templateDb.addGroupToTemplate(template4.getUuid(), group1.getId(), ISSUE_ADMIN);
templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), ADMIN);
templateDb.addGroupToTemplate(template2.getUuid(), group1.getUuid(), ADMIN);
templateDb.addGroupToTemplate(template4.getUuid(), group1.getUuid(), ISSUE_ADMIN);

final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
underTest.groupsCountByTemplateUuidAndPermission(dbSession, asList(template1.getUuid(), template2.getUuid(), template3.getUuid()),
@@ -360,8 +360,8 @@ public class PermissionTemplateDaoTest {
templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN);
templateDb.addUserToTemplate(template.getUuid(), user.getId(), UserRole.USER);
templateDb.addUserToTemplate(template.getUuid(), user.getId(), UserRole.ADMIN);
templateDb.addGroupToTemplate(template.getUuid(), group.getId(), UserRole.CODEVIEWER);
templateDb.addGroupToTemplate(template.getUuid(), group.getId(), UserRole.ADMIN);
templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN);
templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN);

List<String> resultWithUser = underTest.selectPotentialPermissionsByUserIdAndTemplateUuid(dbSession, user.getId(), template.getUuid());
@@ -373,7 +373,7 @@ public class PermissionTemplateDaoTest {
}

@Test
public void selectAllGroupPermissionTemplatesByGroupId() {
public void selectAllGroupPermissionTemplatesByGroupUuid() {
PermissionTemplateDto permissionTemplate = templateDb.insertTemplate(db.getDefaultOrganization());
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
@@ -381,9 +381,9 @@ public class PermissionTemplateDaoTest {
templateDb.addGroupToTemplate(permissionTemplate, group1, "admin");
templateDb.addGroupToTemplate(permissionTemplate, group2, "user");

assertThat(db.getDbClient().permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupId(db.getSession(), group1.getId()))
.extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission)
.containsOnly(tuple(group1.getId(), "user"), tuple(group1.getId(), "admin"));
assertThat(db.getDbClient().permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupUuid(db.getSession(), group1.getUuid()))
.extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission)
.containsOnly(tuple(group1.getUuid(), "user"), tuple(group1.getUuid(), "admin"));
}

@Test
@@ -478,8 +478,8 @@ public class PermissionTemplateDaoTest {
templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN);
templateDb.addUserToTemplate(template.getUuid(), user.getId(), UserRole.USER);
templateDb.addUserToTemplate(template.getUuid(), user.getId(), UserRole.ADMIN);
templateDb.addGroupToTemplate(template.getUuid(), group.getId(), UserRole.CODEVIEWER);
templateDb.addGroupToTemplate(template.getUuid(), group.getId(), UserRole.ADMIN);
templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN);
templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN);
return template;
}

+ 21
- 21
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java Ver fichero

@@ -111,27 +111,27 @@ public class QProfileEditGroupsDaoTest {
.setOrganization(organization)
.setProfile(profile)
.setMembership(ANY).build(), Pagination.all()))
.extracting(GroupMembershipDto::getGroupId, GroupMembershipDto::isSelected)
.extracting(GroupMembershipDto::getGroupUuid, GroupMembershipDto::isSelected)
.containsExactlyInAnyOrder(
tuple(group1.getId(), true),
tuple(group2.getId(), true),
tuple(group3.getId(), false));
tuple(group1.getUuid(), true),
tuple(group2.getUuid(), true),
tuple(group3.getUuid(), false));

assertThat(underTest.selectByQuery(db.getSession(), builder()
.setOrganization(organization)
.setProfile(profile)
.setMembership(IN).build(),
Pagination.all()))
.extracting(GroupMembershipDto::getGroupId, GroupMembershipDto::isSelected)
.containsExactlyInAnyOrder(tuple(group1.getId(), true), tuple(group2.getId(), true));
.extracting(GroupMembershipDto::getGroupUuid, GroupMembershipDto::isSelected)
.containsExactlyInAnyOrder(tuple(group1.getUuid(), true), tuple(group2.getUuid(), true));

assertThat(underTest.selectByQuery(db.getSession(), builder()
.setOrganization(organization)
.setProfile(profile)
.setMembership(OUT).build(),
Pagination.all()))
.extracting(GroupMembershipDto::getGroupId, GroupMembershipDto::isSelected)
.containsExactlyInAnyOrder(tuple(group3.getId(), false));
.extracting(GroupMembershipDto::getGroupUuid, GroupMembershipDto::isSelected)
.containsExactlyInAnyOrder(tuple(group3.getUuid(), false));
}

@Test
@@ -151,8 +151,8 @@ public class QProfileEditGroupsDaoTest {
.setMembership(IN)
.setQuery("project").build(),
Pagination.all()))
.extracting(GroupMembershipDto::getGroupId)
.containsExactlyInAnyOrder(group1.getId());
.extracting(GroupMembershipDto::getGroupUuid)
.containsExactlyInAnyOrder(group1.getUuid());

assertThat(underTest.selectByQuery(db.getSession(), builder()
.setOrganization(organization)
@@ -160,8 +160,8 @@ public class QProfileEditGroupsDaoTest {
.setMembership(IN)
.setQuery("UserS").build(),
Pagination.all()))
.extracting(GroupMembershipDto::getGroupId)
.containsExactlyInAnyOrder(group1.getId(), group2.getId());
.extracting(GroupMembershipDto::getGroupUuid)
.containsExactlyInAnyOrder(group1.getUuid(), group2.getUuid());
}

@Test
@@ -180,8 +180,8 @@ public class QProfileEditGroupsDaoTest {
.setMembership(ANY)
.build(),
Pagination.forPage(1).andSize(1)))
.extracting(GroupMembershipDto::getGroupId)
.containsExactly(group1.getId());
.extracting(GroupMembershipDto::getGroupUuid)
.containsExactly(group1.getUuid());

assertThat(underTest.selectByQuery(db.getSession(), builder()
.setOrganization(organization)
@@ -189,8 +189,8 @@ public class QProfileEditGroupsDaoTest {
.setMembership(ANY)
.build(),
Pagination.forPage(3).andSize(1)))
.extracting(GroupMembershipDto::getGroupId)
.containsExactly(group3.getId());
.extracting(GroupMembershipDto::getGroupUuid)
.containsExactly(group3.getUuid());

assertThat(underTest.selectByQuery(db.getSession(), builder()
.setOrganization(organization)
@@ -198,8 +198,8 @@ public class QProfileEditGroupsDaoTest {
.setMembership(ANY)
.build(),
Pagination.forPage(1).andSize(10)))
.extracting(GroupMembershipDto::getGroupId)
.containsExactly(group1.getId(), group2.getId(), group3.getId());
.extracting(GroupMembershipDto::getGroupUuid)
.containsExactly(group1.getUuid(), group2.getUuid(), group3.getUuid());
}

@Test
@@ -230,13 +230,13 @@ public class QProfileEditGroupsDaoTest {
public void insert() {
underTest.insert(db.getSession(), new QProfileEditGroupsDto()
.setUuid("ABCD")
.setGroupId(100)
.setGroupUuid("100")
.setQProfileUuid("QPROFILE")
);

assertThat(db.selectFirst(db.getSession(), "select uuid as \"uuid\", group_id as \"groupId\", qprofile_uuid as \"qProfileUuid\", created_at as \"createdAt\" from qprofile_edit_groups")).contains(
assertThat(db.selectFirst(db.getSession(), "select uuid as \"uuid\", group_uuid as \"groupUuid\", qprofile_uuid as \"qProfileUuid\", created_at as \"createdAt\" from qprofile_edit_groups")).contains(
entry("uuid", "ABCD"),
entry("groupId", 100L),
entry("groupUuid", "100"),
entry("qProfileUuid", "QPROFILE"),
entry("createdAt", NOW));
}

+ 16
- 15
server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java Ver fichero

@@ -41,7 +41,7 @@ import static org.sonar.db.user.GroupTesting.newGroupDto;
public class GroupDaoTest {

private static final long NOW = 1_500_000L;
private static final int MISSING_ID = -1;
private static final String MISSING_UUID = "unknown";
private static final OrganizationDto AN_ORGANIZATION = new OrganizationDto()
.setKey("an-org")
.setName("An Org")
@@ -56,8 +56,9 @@ public class GroupDaoTest {
private DbSession dbSession = db.getSession();
private GroupDao underTest = db.getDbClient().groupDao();

// not static as group id is changed in each test
// not static as group uuid is changed in each test
private final GroupDto aGroup = new GroupDto()
.setUuid("uuid")
.setName("the-name")
.setDescription("the description")
.setOrganizationUuid(AN_ORGANIZATION.getUuid());
@@ -74,7 +75,7 @@ public class GroupDaoTest {

GroupDto group = underTest.selectByName(dbSession, AN_ORGANIZATION.getUuid(), aGroup.getName()).get();

assertThat(group.getId()).isNotNull();
assertThat(group.getUuid()).isNotNull();
assertThat(group.getOrganizationUuid()).isEqualTo(aGroup.getOrganizationUuid());
assertThat(group.getName()).isEqualTo(aGroup.getName());
assertThat(group.getDescription()).isEqualTo(aGroup.getDescription());
@@ -110,33 +111,33 @@ public class GroupDaoTest {
GroupDto group3InOrg2 = underTest.insert(dbSession, newGroupDto().setName("group3").setOrganizationUuid("org2"));
dbSession.commit();

assertThat(underTest.selectByNames(dbSession, "org1", asList("group1", "group2", "group3", "missingGroup"))).extracting(GroupDto::getId)
.containsOnly(group1InOrg1.getId(), group2InOrg1.getId());
assertThat(underTest.selectByNames(dbSession, "org1", asList("group1", "group2", "group3", "missingGroup"))).extracting(GroupDto::getUuid)
.containsOnly(group1InOrg1.getUuid(), group2InOrg1.getUuid());

assertThat(underTest.selectByNames(dbSession, "org1", Collections.emptyList())).isEmpty();
assertThat(underTest.selectByNames(dbSession, "missingOrg", asList("group1"))).isEmpty();
}

@Test
public void selectByIds() {
public void selectByUuids() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();

assertThat(underTest.selectByIds(dbSession, asList(group1.getId(), group2.getId())))
.extracting(GroupDto::getId).containsOnly(group1.getId(), group2.getId());
assertThat(underTest.selectByUuids(dbSession, asList(group1.getUuid(), group2.getUuid())))
.extracting(GroupDto::getUuid).containsOnly(group1.getUuid(), group2.getUuid());

assertThat(underTest.selectByIds(dbSession, asList(group1.getId(), MISSING_ID)))
.extracting(GroupDto::getId).containsOnly(group1.getId());
assertThat(underTest.selectByUuids(dbSession, asList(group1.getUuid(), MISSING_UUID)))
.extracting(GroupDto::getUuid).containsOnly(group1.getUuid());

assertThat(underTest.selectByIds(dbSession, Collections.emptyList())).isEmpty();
assertThat(underTest.selectByUuids(dbSession, Collections.emptyList())).isEmpty();
}

@Test
public void update() {
db.getDbClient().groupDao().insert(dbSession, aGroup);
GroupDto dto = new GroupDto()
.setId(aGroup.getId())
.setUuid(aGroup.getUuid())
.setName("new-name")
.setDescription("New description")
.setOrganizationUuid("another-org")
@@ -144,7 +145,7 @@ public class GroupDaoTest {

underTest.update(dbSession, dto);

GroupDto reloaded = underTest.selectById(dbSession, aGroup.getId());
GroupDto reloaded = underTest.selectByUuid(dbSession, aGroup.getUuid());

// verify mutable fields
assertThat(reloaded.getName()).isEqualTo("new-name");
@@ -234,10 +235,10 @@ public class GroupDaoTest {
}

@Test
public void deleteById() {
public void deleteByUuid() {
db.getDbClient().groupDao().insert(dbSession, aGroup);

underTest.deleteById(dbSession, aGroup.getId());
underTest.deleteByUuid(dbSession, aGroup.getUuid());

assertThat(db.countRowsOfTable(dbSession, "groups")).isEqualTo(0);
}

+ 27
- 27
server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java Ver fichero

@@ -133,9 +133,9 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group3, user1);
db.users().insertMember(group2, user2);

assertThat(underTest.countUsersByGroups(db.getSession(), asList(group1.getId(), group2.getId(), group3.getId(), emptyGroup.getId())))
assertThat(underTest.countUsersByGroups(db.getSession(), asList(group1.getUuid(), group2.getUuid(), group3.getUuid(), emptyGroup.getUuid())))
.containsOnly(entry(group1.getName(), 1), entry(group2.getName(), 2), entry(group3.getName(), 1), entry(emptyGroup.getName(), 0));
assertThat(underTest.countUsersByGroups(db.getSession(), asList(group1.getId(), emptyGroup.getId())))
assertThat(underTest.countUsersByGroups(db.getSession(), asList(group1.getUuid(), emptyGroup.getUuid())))
.containsOnly(entry(group1.getName(), 1), entry(emptyGroup.getName(), 0));
}

@@ -162,17 +162,17 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group2, user2);

// 100 has 1 member and 1 non member
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(group1.getId()).membership(UserMembershipQuery.IN).build())).isEqualTo(1);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(group1.getId()).membership(UserMembershipQuery.OUT).build())).isEqualTo(1);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.IN).build())).isEqualTo(1);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.OUT).build())).isEqualTo(1);
// 101 has 2 members
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(group2.getId()).membership(UserMembershipQuery.IN).build())).isEqualTo(2);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(group2.getId()).membership(UserMembershipQuery.OUT).build())).isZero();
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group2.getUuid()).membership(UserMembershipQuery.IN).build())).isEqualTo(2);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group2.getUuid()).membership(UserMembershipQuery.OUT).build())).isZero();
// 102 has 1 member and 1 non member
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(group3.getId()).membership(UserMembershipQuery.IN).build())).isEqualTo(1);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(group3.getId()).membership(UserMembershipQuery.OUT).build())).isEqualTo(1);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.IN).build())).isEqualTo(1);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.OUT).build())).isEqualTo(1);
// 103 has no member
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(emptyGroup.getId()).membership(UserMembershipQuery.IN).build())).isZero();
assertThat(underTest.countMembers(db.getSession(), newQuery().groupId(emptyGroup.getId()).membership(UserMembershipQuery.OUT).build())).isEqualTo(2);
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(emptyGroup.getUuid()).membership(UserMembershipQuery.IN).build())).isZero();
assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(emptyGroup.getUuid()).membership(UserMembershipQuery.OUT).build())).isEqualTo(2);
}

@Test
@@ -184,13 +184,13 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group2, user2);

// 100 has 1 member
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1);
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1);
// 101 has 2 members
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(group2.getId()).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(2);
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(group2.getUuid()).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(2);
// 102 has 1 member
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(group3.getId()).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1);
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.IN).build(), 0, 10)).hasSize(1);
// 103 has no member
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(emptyGroup.getId()).membership(UserMembershipQuery.IN).build(), 0, 10)).isEmpty();
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(emptyGroup.getUuid()).membership(UserMembershipQuery.IN).build(), 0, 10)).isEmpty();
}

@Test
@@ -202,13 +202,13 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group2, user2);

// 100 has 1 member
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1);
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1);
// 101 has 2 members
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(group2.getId()).membership(UserMembershipQuery.OUT).build(), 0, 10)).isEmpty();
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(group2.getUuid()).membership(UserMembershipQuery.OUT).build(), 0, 10)).isEmpty();
// 102 has 1 member
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(group3.getId()).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1);
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(1);
// 103 has no member
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupId(emptyGroup.getId()).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(2);
assertThat(underTest.selectMembers(db.getSession(), newQuery().groupUuid(emptyGroup.getUuid()).membership(UserMembershipQuery.OUT).build(), 0, 10)).hasSize(2);
}

@Test
@@ -218,13 +218,13 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group3, user1);
db.users().insertMember(group2, user2);

List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).memberSearch("admin").build(), 0, 10);
List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).memberSearch("admin").build(), 0, 10);
assertThat(result).hasSize(2);

assertThat(result.get(0).getName()).isEqualTo("Admin name");
assertThat(result.get(1).getName()).isEqualTo("Not Admin");

result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).memberSearch("not").build(), 0, 10);
result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).memberSearch("not").build(), 0, 10);
assertThat(result).hasSize(1);
}

@@ -236,13 +236,13 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group2, user2);

// search is case insensitive only on name
List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).memberSearch("NaMe").build(), 0, 10);
List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).memberSearch("NaMe").build(), 0, 10);
assertThat(result).hasSize(1);

result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).memberSearch("login").build(), 0, 10);
result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).memberSearch("login").build(), 0, 10);
assertThat(result).hasSize(1);

result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).memberSearch("email").build(), 0, 10);
result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).memberSearch("email").build(), 0, 10);
assertThat(result).hasSize(1);
}

@@ -253,7 +253,7 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group3, user1);
db.users().insertMember(group2, user2);

List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).build(), 0, 10);
List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).build(), 0, 10);
assertThat(result).hasSize(2);
assertThat(result.get(0).getName()).isEqualTo("Admin name");
assertThat(result.get(1).getName()).isEqualTo("Not Admin");
@@ -266,16 +266,16 @@ public class GroupMembershipDaoTest {
db.users().insertMember(group3, user1);
db.users().insertMember(group2, user2);

List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupId(group1.getId()).build(), 0, 2);
List<UserMembershipDto> result = underTest.selectMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).build(), 0, 2);
assertThat(result).hasSize(2);
assertThat(result.get(0).getName()).isEqualTo("Admin name");
assertThat(result.get(1).getName()).isEqualTo("Not Admin");

result = underTest.selectMembers(db.getSession(), newQuery().groupId(100).build(), 1, 2);
result = underTest.selectMembers(db.getSession(), newQuery().groupUuid("100").build(), 1, 2);
assertThat(result).hasSize(1);
assertThat(result.get(0).getName()).isEqualTo("Not Admin");

result = underTest.selectMembers(db.getSession(), newQuery().groupId(100).build(), 2, 1);
result = underTest.selectMembers(db.getSession(), newQuery().groupUuid("100").build(), 2, 1);
assertThat(result).isEmpty();
}


+ 6
- 6
server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java Ver fichero

@@ -114,7 +114,7 @@ public class RoleDaoTest {
}

@Test
public void delete_all_group_permissions_by_group_id() {
public void delete_all_group_permissions_by_group_uuid() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
ComponentDto project = db.components().insertPrivateProject();
@@ -126,13 +126,13 @@ public class RoleDaoTest {
db.users().insertPermissionOnAnyone(db.getDefaultOrganization(), "scan");
db.users().insertPermissionOnAnyone(db.getDefaultOrganization(), "provisioning");

underTest.deleteGroupRolesByGroupId(db.getSession(), group1.getId());
underTest.deleteGroupRolesByGroupUuid(db.getSession(), group1.getUuid());
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.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.uuid())).containsOnly("admin");
assertThat(db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group1.getUuid())).isEmpty();
assertThat(db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group1.getUuid(), project.uuid())).isEmpty();
assertThat(db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group2.getUuid())).containsOnly("gateadmin");
assertThat(db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), group2.getUuid(), project.uuid())).containsOnly("admin");
assertThat(db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(), db.getDefaultOrganization().getUuid(), null)).containsOnly("scan", "provisioning");
}
}

+ 1
- 2
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java Ver fichero

@@ -34,7 +34,6 @@ import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;

@@ -760,7 +759,7 @@ public class UserDaoTest {
GroupDto group = newGroupDto().setName(randomAlphanumeric(30));
dbClient.groupDao().insert(session, group);

UserGroupDto dto = new UserGroupDto().setUserId(user.getId()).setGroupId(group.getId());
UserGroupDto dto = new UserGroupDto().setUserId(user.getId()).setGroupUuid(group.getUuid());
dbClient.userGroupDao().insert(session, dto);
return dto;
}

+ 12
- 12
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoTest.java Ver fichero

@@ -42,16 +42,16 @@ public class UserGroupDaoTest {
public void insert() {
UserDto user = dbTester.users().insertUser();
GroupDto group = dbTester.users().insertGroup();
UserGroupDto userGroupDto = new UserGroupDto().setUserId(user.getId()).setGroupId(group.getId());
UserGroupDto userGroupDto = new UserGroupDto().setUserId(user.getId()).setGroupUuid(group.getUuid());

underTest.insert(dbTester.getSession(), userGroupDto);
dbTester.getSession().commit();

assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user.getId())).containsOnly(group.getId());
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user.getId())).containsOnly(group.getUuid());
}

@Test
public void delete_members_by_group_id() {
public void delete_members_by_group_uuid() {
UserDto user1 = dbTester.users().insertUser();
UserDto user2 = dbTester.users().insertUser();
GroupDto group1 = dbTester.users().insertGroup();
@@ -61,11 +61,11 @@ public class UserGroupDaoTest {
dbTester.users().insertMember(group2, user1);
dbTester.users().insertMember(group2, user2);

underTest.deleteByGroupId(dbTester.getSession(), group1.getId());
underTest.deleteByGroupUuid(dbTester.getSession(), group1.getUuid());
dbTester.getSession().commit();

assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user1.getId())).containsOnly(group2.getId());
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user2.getId())).containsOnly(group2.getId());
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user1.getId())).containsOnly(group2.getUuid());
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user2.getId())).containsOnly(group2.getUuid());
}

@Test
@@ -81,10 +81,10 @@ public class UserGroupDaoTest {

underTest.deleteByOrganizationAndUser(dbSession, organization.getUuid(), user.getId());

assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(dbSession, user.getId()))
.containsOnly(anotherGroup.getId());
assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(dbSession, anotherUser.getId()))
.containsOnly(group.getId(), anotherGroup.getId());
assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(dbSession, user.getId()))
.containsOnly(anotherGroup.getUuid());
assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(dbSession, anotherUser.getId()))
.containsOnly(group.getUuid(), anotherGroup.getUuid());
}

@Test
@@ -101,7 +101,7 @@ public class UserGroupDaoTest {
underTest.deleteByUserId(dbTester.getSession(), user1.getId());
dbTester.getSession().commit();

assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user1.getId())).isEmpty();
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user2.getId())).containsOnly(group1.getId(), group2.getId());
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user1.getId())).isEmpty();
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user2.getId())).containsOnly(group1.getUuid(), group2.getUuid());
}
}

+ 1
- 1
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueDaoTest/shared.xml Ver fichero

@@ -1,7 +1,7 @@
<dataset>

<group_roles id="1"
group_id="[null]"
group_uuid="[null]"
resource_id="399"
role="user"
organization_uuid="org1"/>

+ 1
- 1
server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueStatsDaoTest/should_select_assignees.xml Ver fichero

@@ -1,7 +1,7 @@
<dataset>

<group_roles id="1"
group_id="[null]"
group_uuid="[null]"
resource_id="399"
role="user"
organization_uuid="org1"/>

+ 2
- 2
server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml Ver fichero

@@ -6,9 +6,9 @@
role="user"
organization_uuid="org1"/>
<groups_users user_id="100"
group_id="200"/>
group_uuid="200"/>
<group_roles id="1"
group_id="[null]"
group_uuid="[null]"
resource_id="300"
role="user"
organization_uuid="org1"/>

+ 2
- 2
server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml Ver fichero

@@ -8,9 +8,9 @@
role="user"
organization_uuid="org1"/>
<groups_users user_id="100"
group_id="200"/>
group_uuid="200"/>
<group_roles id="1"
group_id="200"
group_uuid="200"
resource_id="300"
role="user"
organization_uuid="org1"/>

+ 2
- 2
server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml Ver fichero

@@ -7,9 +7,9 @@
role="user"
organization_uuid="org1"/>
<groups_users user_id="100"
group_id="200"/>
group_uuid="200"/>
<group_roles id="1"
group_id="200"
group_uuid="200"
resource_id="999"
role="user"
organization_uuid="org1"/>

+ 3
- 3
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java Ver fichero

@@ -117,14 +117,14 @@ public class OrganizationDbTester {

public void assertUserIsMemberOfOrganization(OrganizationDto organization, UserDto user) {
assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getId())).as("User is not member of the organization").isPresent();
Integer defaultGroupId = db.getDbClient().organizationDao().getDefaultGroupId(db.getSession(), organization.getUuid()).get();
String defaultGroupUuid = db.getDbClient().organizationDao().getDefaultGroupUuid(db.getSession(), organization.getUuid()).get();
assertThat(db.getDbClient().groupMembershipDao().selectGroups(
db.getSession(),
GroupMembershipQuery.builder().membership(IN).organizationUuid(organization.getUuid()).build(),
user.getId(), 0, 10))
.extracting(GroupMembershipDto::getId)
.extracting(GroupMembershipDto::getUuid)
.as("User is not member of the default group of the organization")
.containsOnly(defaultGroupId.longValue());
.containsOnly(defaultGroupUuid);
}

public void assertUserIsNotMemberOfOrganization(OrganizationDto organization, UserDto user) {

+ 3
- 3
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java Ver fichero

@@ -57,11 +57,11 @@ public class PermissionTemplateDbTester {
}

public void addGroupToTemplate(PermissionTemplateDto permissionTemplate, GroupDto group, String permission) {
addGroupToTemplate(permissionTemplate.getUuid(), group.getId(), permission);
addGroupToTemplate(permissionTemplate.getUuid(), group.getUuid(), permission);
}

public void addGroupToTemplate(String templateUuid, @Nullable Integer groupId, String permission) {
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupId, permission);
public void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission) {
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupUuid, permission);
db.commit();
}


+ 1
- 1
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java Ver fichero

@@ -127,7 +127,7 @@ public class QualityProfileDbTester {
checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
dbClient.qProfileEditGroupsDao().insert(dbSession, new QProfileEditGroupsDto()
.setUuid(Uuids.createFast())
.setGroupId(group.getId())
.setGroupUuid(group.getUuid())
.setQProfileUuid(profile.getKee())
);
dbSession.commit();

+ 1
- 2
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/GroupTesting.java Ver fichero

@@ -22,7 +22,6 @@ package org.sonar.db.user;
import java.util.Date;

import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.apache.commons.lang.math.RandomUtils.nextLong;

public class GroupTesting {
@@ -33,7 +32,7 @@ public class GroupTesting {

public static GroupDto newGroupDto() {
return new GroupDto()
.setId(nextInt())
.setUuid(randomAlphanumeric(40))
.setOrganizationUuid(randomAlphanumeric(40))
.setName(randomAlphanumeric(255))
.setDescription(randomAlphanumeric(200))

+ 16
- 16
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java Ver fichero

@@ -167,12 +167,12 @@ public class UserDbTester {

public GroupDto insertDefaultGroup(GroupDto dto) {
String organizationUuid = dto.getOrganizationUuid();
db.getDbClient().organizationDao().getDefaultGroupId(db.getSession(), organizationUuid)
.ifPresent(groupId -> {
db.getDbClient().organizationDao().getDefaultGroupUuid(db.getSession(), organizationUuid)
.ifPresent(groupUuid -> {
throw new IllegalArgumentException(format("Organization '%s' has already a default group", organizationUuid));
});
db.getDbClient().groupDao().insert(db.getSession(), dto);
db.getDbClient().organizationDao().setDefaultGroupId(db.getSession(), organizationUuid, dto);
db.getDbClient().organizationDao().setDefaultGroupUuid(db.getSession(), organizationUuid, dto);
db.commit();
return dto;
}
@@ -186,8 +186,8 @@ public class UserDbTester {
}

@CheckForNull
public GroupDto selectGroupById(int groupId) {
return db.getDbClient().groupDao().selectById(db.getSession(), groupId);
public GroupDto selectGroupByUuid(String groupUuid) {
return db.getDbClient().groupDao().selectByUuid(db.getSession(), groupUuid);
}

public Optional<GroupDto> selectGroup(OrganizationDto org, String name) {
@@ -201,7 +201,7 @@ public class UserDbTester {
// GROUP MEMBERSHIP

public UserGroupDto insertMember(GroupDto group, UserDto user) {
UserGroupDto dto = new UserGroupDto().setGroupId(group.getId()).setUserId(user.getId());
UserGroupDto dto = new UserGroupDto().setGroupUuid(group.getUuid()).setUserId(user.getId());
db.getDbClient().userGroupDao().insert(db.getSession(), dto);
db.commit();
return dto;
@@ -209,14 +209,14 @@ public class UserDbTester {

public void insertMembers(GroupDto group, UserDto... users) {
Arrays.stream(users).forEach(user -> {
UserGroupDto dto = new UserGroupDto().setGroupId(group.getId()).setUserId(user.getId());
UserGroupDto dto = new UserGroupDto().setGroupUuid(group.getUuid()).setUserId(user.getId());
db.getDbClient().userGroupDao().insert(db.getSession(), dto);
});
db.commit();
}

public List<Integer> selectGroupIdsOfUser(UserDto user) {
return db.getDbClient().groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId());
public List<String> selectGroupUuidsOfUser(UserDto user) {
return db.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), user.getId());
}

// GROUP PERMISSIONS
@@ -225,7 +225,7 @@ public class UserDbTester {
GroupPermissionDto dto = new GroupPermissionDto()
.setUuid(Uuids.createFast())
.setOrganizationUuid(org.getUuid())
.setGroupId(null)
.setGroupUuid(null)
.setRole(permission);
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
@@ -240,7 +240,7 @@ public class UserDbTester {
GroupPermissionDto dto = new GroupPermissionDto()
.setUuid(Uuids.createFast())
.setOrganizationUuid(group.getOrganizationUuid())
.setGroupId(group.getId())
.setGroupUuid(group.getUuid())
.setRole(permission);
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
@@ -252,7 +252,7 @@ public class UserDbTester {
}

public void deletePermissionFromGroup(GroupDto group, String permission) {
db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, group.getOrganizationUuid(), group.getId(), null);
db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, group.getOrganizationUuid(), group.getUuid(), null);
db.commit();
}

@@ -264,7 +264,7 @@ public class UserDbTester {
GroupPermissionDto dto = new GroupPermissionDto()
.setUuid(Uuids.createFast())
.setOrganizationUuid(project.getOrganizationUuid())
.setGroupId(null)
.setGroupUuid(null)
.setRole(permission)
.setComponentUuid(project.uuid());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
@@ -285,7 +285,7 @@ public class UserDbTester {
GroupPermissionDto dto = new GroupPermissionDto()
.setUuid(Uuids.createFast())
.setOrganizationUuid(group.getOrganizationUuid())
.setGroupId(group.getId())
.setGroupUuid(group.getUuid())
.setRole(permission)
.setComponentUuid(project.uuid());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
@@ -296,10 +296,10 @@ public class UserDbTester {
public List<String> selectGroupPermissions(GroupDto group, @Nullable ComponentDto project) {
if (project == null) {
return db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(),
group.getOrganizationUuid(), group.getId());
group.getOrganizationUuid(), group.getUuid());
}
return db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(),
group.getOrganizationUuid(), group.getId(), project.uuid());
group.getOrganizationUuid(), group.getUuid(), project.uuid());
}

public List<String> selectAnyonePermissions(OrganizationDto org, @Nullable ComponentDto project) {

+ 73
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java Ver fichero

@@ -70,6 +70,35 @@ import org.sonar.server.platform.db.migration.version.v83.grouproles.DropResourc
import org.sonar.server.platform.db.migration.version.v83.grouproles.MakeGroupRolesUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.grouproles.MigrateResourceIdToUuidInGroupRoles;
import org.sonar.server.platform.db.migration.version.v83.grouproles.PopulateGroupRolesUuid;
import org.sonar.server.platform.db.migration.version.v83.groups.AddPrimaryKeyOnUuidColumnOfGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.AddUuidColumnToGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.DropIdColumnOfGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.DropPrimaryKeyOnIdColumnOfGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.MakeGroupsUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.groups.PopulateGroupsUuid;
import org.sonar.server.platform.db.migration.version.v83.groups.grouproles.AddGroupUuidColumnToGroupRoles;
import org.sonar.server.platform.db.migration.version.v83.groups.grouproles.AddIndexOnGroupUuidOfGroupRolesTable;
import org.sonar.server.platform.db.migration.version.v83.groups.grouproles.DropGroupIdColumnOfGroupRolesTable;
import org.sonar.server.platform.db.migration.version.v83.groups.grouproles.DropIndexOnGroupIdOfGroupRolesTable;
import org.sonar.server.platform.db.migration.version.v83.groups.grouproles.PopulateGroupRolesGroupUuid;
import org.sonar.server.platform.db.migration.version.v83.groups.groupsusers.AddGroupUuidColumnToGroupsUsers;
import org.sonar.server.platform.db.migration.version.v83.groups.groupsusers.AddIndexOnGroupUuidOfGroupsUsersTable;
import org.sonar.server.platform.db.migration.version.v83.groups.groupsusers.DropGroupIdColumnOfGroupsUsersTable;
import org.sonar.server.platform.db.migration.version.v83.groups.groupsusers.DropIndexOnGroupIdOfGroupsUsersTable;
import org.sonar.server.platform.db.migration.version.v83.groups.groupsusers.MakeGroupsUsersGroupUuidNotNullable;
import org.sonar.server.platform.db.migration.version.v83.groups.groupsusers.PopulateGroupsUsersGroupUuid;
import org.sonar.server.platform.db.migration.version.v83.groups.organizations.AddDefaultGroupUuidColumnToOrganizations;
import org.sonar.server.platform.db.migration.version.v83.groups.organizations.DropDefaultGroupIdColumnOfOrganizationsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.organizations.PopulateOrganizationsDefaultGroupUuid;
import org.sonar.server.platform.db.migration.version.v83.groups.permtemplatesgroups.AddGroupUuidColumnToPermTemplatesGroups;
import org.sonar.server.platform.db.migration.version.v83.groups.permtemplatesgroups.DropGroupIdColumnOfPermTemplatesGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.permtemplatesgroups.PopulatePermTemplatesGroupsGroupUuid;
import org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups.AddGroupUuidColumnToQProfileEditGroups;
import org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups.AddIndexOnGroupUuidOfQProfileEditGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups.DropGroupIdColumnOfQProfileEditGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups.DropIndexOnGroupIdOfQProfileEditGroupsTable;
import org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups.MakeQProfileEditGroupsGroupUuidNotNullable;
import org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups.PopulateQProfileEditGroupsGroupUuid;
import org.sonar.server.platform.db.migration.version.v83.issuechanges.AddPrimaryKeyOnUuidColumnOfIssueChangesTable;
import org.sonar.server.platform.db.migration.version.v83.issuechanges.AddUuidColumnToIssueChangesTable;
import org.sonar.server.platform.db.migration.version.v83.issuechanges.DropIdColumnOfIssueChangesTable;
@@ -533,6 +562,50 @@ public class DbVersion83 implements DbVersion {
.add(3595, "Add primary key on 'UUID' column of 'PROPERTIES' table", AddPrimaryKeyOnUuidColumnOfPropertiesTable.class)
.add(3596, "Drop column 'ID' of 'PROPERTIES' table", DropIdColumnOfPropertiesTable.class)

// Migration of GROUPS table
.add(3597, "Add 'UUID' column on 'GROUPS' table", AddUuidColumnToGroupsTable.class)
.add(3598, "Populate 'uuid' for 'GROUPS'", PopulateGroupsUuid.class)
.add(3599, "Make 'uuid' column not nullable for 'GROUPS'", MakeGroupsUuidColumnNotNullable.class)

// Migration of FK in GROUP_ROLES to GROUPS
.add(3600, "Add 'group_uuid' column on 'GROUP_ROLES' table", AddGroupUuidColumnToGroupRoles.class)
.add(3601, "Populate 'group_uuid' for 'GROUP_ROLES'", PopulateGroupRolesGroupUuid.class)
.add(3602, "Drop index on 'group_id' column of 'GROUP_ROLES' table", DropIndexOnGroupIdOfGroupRolesTable.class)
.add(3603,"Add index on 'group_uuid' column of 'GROUP_ROLES' table", AddIndexOnGroupUuidOfGroupRolesTable.class)

// Migration of FK in GROUPS_USERS to GROUPS
.add(3604, "Add 'group_uuid' column on 'GROUPS_USERS' table", AddGroupUuidColumnToGroupsUsers.class)
.add(3605, "Populate 'group_uuid' for 'GROUPS_USERS'", PopulateGroupsUsersGroupUuid.class)
.add(3606, "Make 'group_uuid' column not nullable for 'GROUPS_USERS'", MakeGroupsUsersGroupUuidNotNullable.class)
.add(3607, "Drop index on 'group_id' column of 'GROUPS_USERS' table", DropIndexOnGroupIdOfGroupsUsersTable.class)
.add(3608, "Add index on 'group_uuid' column of 'GROUPS_USERS' table", AddIndexOnGroupUuidOfGroupsUsersTable.class)

// Migration of FK in ORGANIZATIONS to GROUPS
.add(3609, "Add 'default_group_uuid' column on 'ORGANIZATIONS' table", AddDefaultGroupUuidColumnToOrganizations.class)
.add(3610, "Populate 'default_group_uuid' for 'ORGANIZATIONS'", PopulateOrganizationsDefaultGroupUuid.class)

// Migration of FK in PERM_TEMPLATES_GROUPS to GROUPS
.add(3611, "Add 'group_uuid' column on 'PERM_TEMPLATES_GROUPS' table", AddGroupUuidColumnToPermTemplatesGroups.class)
.add(3612, "Populate 'group_uuid' for 'PERM_TEMPLATES_GROUPS'", PopulatePermTemplatesGroupsGroupUuid.class)

// Migration of FK in QPROFILE_EDIT_GROUPS to GROUPS
.add(3613, "Add 'group_uuid' column on 'QPROFILE_EDIT_GROUPS' table", AddGroupUuidColumnToQProfileEditGroups.class)
.add(3614, "Populate 'group_uuid' for 'QPROFILE_EDIT_GROUPS'", PopulateQProfileEditGroupsGroupUuid.class)
.add(3615, "Make 'group_uuid' column not nullable for 'QPROFILE_EDIT_GROUPS'", MakeQProfileEditGroupsGroupUuidNotNullable.class)
.add(3616, "Drop index on 'group_id' column of 'QPROFILE_EDIT_GROUPS' table", DropIndexOnGroupIdOfQProfileEditGroupsTable.class)
.add(3617, "Add index on 'group_uuid' column of 'QPROFILE_EDIT_GROUPS' table", AddIndexOnGroupUuidOfQProfileEditGroupsTable.class)

// Finish migration of Groups
.add(3618, "Drop primary key on 'ID' column of 'GROUPS' table", DropPrimaryKeyOnIdColumnOfGroupsTable.class)
.add(3619, "Add primary key on 'UUID' column of 'GROUPS' table", AddPrimaryKeyOnUuidColumnOfGroupsTable.class)

.add(3620, "Drop column 'group_id' of 'GROUP_ROLES' table", DropGroupIdColumnOfGroupRolesTable.class)
.add(3621, "Drop column 'group_id' of 'GROUPS_USERS' table", DropGroupIdColumnOfGroupsUsersTable.class)
.add(3622, "Drop column 'group_id' of 'ORGANIZATIONS' table", DropDefaultGroupIdColumnOfOrganizationsTable.class)
.add(3623, "Drop column 'group_id' of 'PERM_TEMPLATES_GROUPS' table", DropGroupIdColumnOfPermTemplatesGroupsTable.class)
.add(3624, "Drop column 'group_id' of 'QPROFILE_EDIT_GROUPS' table", DropGroupIdColumnOfQProfileEditGroupsTable.class)
.add(3625, "Drop column 'ID' of 'GROUPS' table", DropIdColumnOfGroupsTable.class)

;
}
}

+ 38
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTable.java Ver fichero

@@ -0,0 +1,38 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DdlChange;
import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;

public class AddPrimaryKeyOnUuidColumnOfGroupsTable extends DdlChange {

public AddPrimaryKeyOnUuidColumnOfGroupsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddPrimaryKeyBuilder("groups", "uuid").build());
}

}

+ 38
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfMetricsTable.java Ver fichero

@@ -0,0 +1,38 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DdlChange;
import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;

public class AddPrimaryKeyOnUuidColumnOfMetricsTable extends DdlChange {

public AddPrimaryKeyOnUuidColumnOfMetricsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddPrimaryKeyBuilder("metrics", "uuid").build());
}

}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTable.java Ver fichero

@@ -0,0 +1,31 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;

public class AddUuidColumnToGroupsTable extends AddUuidColumnToTable {
private static final String TABLE = "groups";

public AddUuidColumnToGroupsTable(Database db) {
super(db, TABLE);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToMetricsTable.java Ver fichero

@@ -0,0 +1,31 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;

public class AddUuidColumnToMetricsTable extends AddUuidColumnToTable {
private static final String TABLE = "metrics";

public AddUuidColumnToMetricsTable(Database db) {
super(db, TABLE);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTable.java Ver fichero

@@ -0,0 +1,31 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;

public class DropIdColumnOfGroupsTable extends DropIdColumn {
private static final String TABLE = "groups";

public DropIdColumnOfGroupsTable(Database db) {
super(db, TABLE);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfMetricsTable.java Ver fichero

@@ -0,0 +1,31 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;

public class DropIdColumnOfMetricsTable extends DropIdColumn {
private static final String TABLE = "metrics";

public DropIdColumnOfMetricsTable(Database db) {
super(db, TABLE);
}
}

+ 32
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTable.java Ver fichero

@@ -0,0 +1,32 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;

public class DropPrimaryKeyOnIdColumnOfGroupsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "groups";

public DropPrimaryKeyOnIdColumnOfGroupsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
}
}

+ 32
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfMetricsTable.java Ver fichero

@@ -0,0 +1,32 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;

public class DropPrimaryKeyOnIdColumnOfMetricsTable extends DropPrimaryKeyOnIdColumn {
private static final String TABLE_NAME = "metrics";

public DropPrimaryKeyOnIdColumnOfMetricsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullable.java Ver fichero

@@ -0,0 +1,31 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;

public class MakeGroupsUuidColumnNotNullable extends MakeUuidColumnNotNullable {
private static final String TABLE = "groups";

public MakeGroupsUuidColumnNotNullable(Database db) {
super(db, TABLE);
}
}

+ 31
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeMetricsUuidColumnNotNullable.java Ver fichero

@@ -0,0 +1,31 @@
/*
* 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.groups;

import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;

public class MakeMetricsUuidColumnNotNullable extends MakeUuidColumnNotNullable {
private static final String TABLE = "metrics";

public MakeMetricsUuidColumnNotNullable(Database db) {
super(db, TABLE);
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuid.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups;

import java.sql.SQLException;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;

public class PopulateGroupsUuid extends DataChange {

private final UuidFactory uuidFactory;

public PopulateGroupsUuid(Database db, UuidFactory uuidFactory) {
super(db);
this.uuidFactory = uuidFactory;
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select id from groups where uuid is null order by id asc");
massUpdate.update("update groups set uuid = ? where id = ?");

massUpdate.execute((row, update) -> {
update.setString(1, uuidFactory.create());
update.setLong(2, row.getLong(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateMetricsUuid.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups;

import java.sql.SQLException;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;

public class PopulateMetricsUuid extends DataChange {

private final UuidFactory uuidFactory;

public PopulateMetricsUuid(Database db, UuidFactory uuidFactory) {
super(db);
this.uuidFactory = uuidFactory;
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select id from metrics where uuid is null order by id asc");
massUpdate.update("update metrics set uuid = ? where id = ?");

massUpdate.execute((row, update) -> {
update.setString(1, uuidFactory.create());
update.setLong(2, row.getLong(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRoles.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.grouproles;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddGroupUuidColumnToGroupRoles extends DdlChange {
private static final String TABLE = "group_roles";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(true)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public AddGroupUuidColumnToGroupRoles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
.addColumn(uuidColumnDefinition)
.build());
}
}

+ 76
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java Ver fichero

@@ -0,0 +1,76 @@
/*
* 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.groups.grouproles;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddIndexOnGroupUuidOfGroupRolesTable extends DdlChange {
private static final String TABLE_NAME = "group_roles";
private static final String INDEX_NAME = "uniq_group_roles";

public AddIndexOnGroupUuidOfGroupRolesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (!indexExists()) {
context.execute(new CreateIndexBuilder()
.setUnique(true)
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("organization_uuid")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("component_uuid")
.setIsNullable(true)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("role")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.build());
}
}

private boolean indexExists() throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
}
}
}

+ 36
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTable.java Ver fichero

@@ -0,0 +1,36 @@
/*
* 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.groups.grouproles;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropGroupIdColumnOfGroupRolesTable extends DdlChange {
public DropGroupIdColumnOfGroupRolesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), "group_roles", "group_id").build());
}
}

+ 52
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java Ver fichero

@@ -0,0 +1,52 @@
/*
* 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.groups.grouproles;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexOnGroupIdOfGroupRolesTable extends DdlChange {
private static final String TABLE_NAME = "group_roles";
private static final String INDEX_NAME = "uniq_group_roles";

public DropIndexOnGroupIdOfGroupRolesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (indexExists()) {
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.build());
}
}

private boolean indexExists() throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
}
}
}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuid.java Ver fichero

@@ -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.groups.grouproles;

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 PopulateGroupRolesGroupUuid extends DataChange {

public PopulateGroupRolesGroupUuid(Database db) {
super(db);
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select gr.uuid, g.uuid " +
"from group_roles gr " +
"join groups g on gr.group_id = g.id");

massUpdate.update("update group_roles set group_uuid = ? where uuid = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsers.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.groupsusers;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddGroupUuidColumnToGroupsUsers extends DdlChange {
private static final String TABLE = "groups_users";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(true)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public AddGroupUuidColumnToGroupsUsers(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
.addColumn(uuidColumnDefinition)
.build());
}
}

+ 76
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java Ver fichero

@@ -0,0 +1,76 @@
/*
* 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.groups.groupsusers;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddIndexOnGroupUuidOfGroupsUsersTable extends DdlChange {
private static final String TABLE_NAME = "groups_users";
private static final String INDEX_NAME1 = "index_groups_users_group_uuid";
private static final String INDEX_NAME2 = "groups_users_unique";

public AddIndexOnGroupUuidOfGroupsUsersTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef groupUuid = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();
if (!indexExists(INDEX_NAME1)) {
context.execute(new CreateIndexBuilder()
.setUnique(false)
.setTable(TABLE_NAME)
.setName(INDEX_NAME1)
.addColumn(groupUuid)
.build());
}
if (!indexExists(INDEX_NAME2)) {
context.execute(new CreateIndexBuilder()
.setUnique(true)
.setTable(TABLE_NAME)
.setName(INDEX_NAME2)
.addColumn(groupUuid)
.addColumn(newBigIntegerColumnDefBuilder()
.setColumnName("user_id")
.setIsNullable(true)
.build())
.build());
}
}

private boolean indexExists(String name) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, name, connection);
}
}
}

+ 36
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTable.java Ver fichero

@@ -0,0 +1,36 @@
/*
* 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.groups.groupsusers;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropGroupIdColumnOfGroupsUsersTable extends DdlChange {
public DropGroupIdColumnOfGroupsUsersTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), "groups_users", "group_id").build());
}
}

+ 59
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java Ver fichero

@@ -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.groups.groupsusers;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexOnGroupIdOfGroupsUsersTable extends DdlChange {
private static final String TABLE_NAME = "groups_users";
private static final String INDEX_NAME1 = "index_groups_users_on_group_id";
private static final String INDEX_NAME2 = "groups_users_unique";

public DropIndexOnGroupIdOfGroupsUsersTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (indexExists(INDEX_NAME1)) {
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_NAME)
.setName(INDEX_NAME1)
.build());
}
if (indexExists(INDEX_NAME2)) {
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_NAME)
.setName(INDEX_NAME2)
.build());
}
}

private boolean indexExists(String name) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, name, connection);
}
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullable.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.groupsusers;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeGroupsUsersGroupUuidNotNullable extends DdlChange {
private static final String TABLE = "groups_users";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(false)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public MakeGroupsUsersGroupUuidNotNullable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
.updateColumn(uuidColumnDefinition)
.build());
}
}

+ 51
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuid.java Ver fichero

@@ -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.groups.groupsusers;

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 PopulateGroupsUsersGroupUuid extends DataChange {

public PopulateGroupsUsersGroupUuid(Database db) {
super(db);
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select gu.user_id, gu.group_id, g.uuid " +
"from groups_users gu " +
"join groups g on gu.group_id = g.id");

massUpdate.update("update groups_users set group_uuid = ? where user_id = ? and group_id = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(3));
update.setLong(2, row.getLong(1));
update.setLong(3, row.getLong(2));

return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizations.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.organizations;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddDefaultGroupUuidColumnToOrganizations extends DdlChange {
private static final String TABLE = "organizations";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("default_group_uuid")
.setIsNullable(true)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public AddDefaultGroupUuidColumnToOrganizations(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
.addColumn(uuidColumnDefinition)
.build());
}
}

+ 36
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTable.java Ver fichero

@@ -0,0 +1,36 @@
/*
* 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.groups.organizations;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropDefaultGroupIdColumnOfOrganizationsTable extends DdlChange {
public DropDefaultGroupIdColumnOfOrganizationsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), "organizations", "default_group_id").build());
}
}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuid.java Ver fichero

@@ -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.groups.organizations;

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 PopulateOrganizationsDefaultGroupUuid extends DataChange {

public PopulateOrganizationsDefaultGroupUuid(Database db) {
super(db);
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select o.uuid, g.uuid " +
"from organizations o " +
"join groups g on o.default_group_id = g.id");

massUpdate.update("update organizations set default_group_uuid = ? where uuid = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroups.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.permtemplatesgroups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddGroupUuidColumnToPermTemplatesGroups extends DdlChange {
private static final String TABLE = "perm_templates_groups";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(true)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public AddGroupUuidColumnToPermTemplatesGroups(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
.addColumn(uuidColumnDefinition)
.build());
}
}

+ 36
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTable.java Ver fichero

@@ -0,0 +1,36 @@
/*
* 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.groups.permtemplatesgroups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropGroupIdColumnOfPermTemplatesGroupsTable extends DdlChange {
public DropGroupIdColumnOfPermTemplatesGroupsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), "perm_templates_groups", "group_id").build());
}
}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuid.java Ver fichero

@@ -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.groups.permtemplatesgroups;

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 PopulatePermTemplatesGroupsGroupUuid extends DataChange {

public PopulatePermTemplatesGroupsGroupUuid(Database db) {
super(db);
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select ptg.uuid, g.uuid " +
"from perm_templates_groups ptg " +
"join groups g on ptg.group_id = g.id");

massUpdate.update("update perm_templates_groups set group_uuid = ? where uuid = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroups.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddGroupUuidColumnToQProfileEditGroups extends DdlChange {
private static final String TABLE = "qprofile_edit_groups";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(true)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public AddGroupUuidColumnToQProfileEditGroups(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
.addColumn(uuidColumnDefinition)
.build());
}
}

+ 66
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java Ver fichero

@@ -0,0 +1,66 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class AddIndexOnGroupUuidOfQProfileEditGroupsTable extends DdlChange {
private static final String TABLE_NAME = "qprofile_edit_groups";
private static final String INDEX_NAME = "qprofile_edit_groups_unique";

public AddIndexOnGroupUuidOfQProfileEditGroupsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (!indexExists()) {
context.execute(new CreateIndexBuilder()
.setUnique(true)
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("qprofile_uuid")
.setIsNullable(false)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build())
.build());
}
}

private boolean indexExists() throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
}
}
}

+ 36
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTable.java Ver fichero

@@ -0,0 +1,36 @@
/*
* 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.groups.qprofileeditgroups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropGroupIdColumnOfQProfileEditGroupsTable extends DdlChange {
public DropGroupIdColumnOfQProfileEditGroupsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), "qprofile_edit_groups", "group_id").build());
}
}

+ 52
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java Ver fichero

@@ -0,0 +1,52 @@
/*
* 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.groups.qprofileeditgroups;

import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropIndexOnGroupIdOfQProfileEditGroupsTable extends DdlChange {
private static final String TABLE_NAME = "qprofile_edit_groups";
private static final String INDEX_NAME = "qprofile_edit_groups_unique";

public DropIndexOnGroupIdOfQProfileEditGroupsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (indexExists(INDEX_NAME)) {
context.execute(new DropIndexBuilder(getDialect())
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.build());
}
}

private boolean indexExists(String name) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
return DatabaseUtils.indexExists(TABLE_NAME, name, connection);
}
}
}

+ 50
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullable.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class MakeQProfileEditGroupsGroupUuidNotNullable extends DdlChange {
private static final String TABLE = "qprofile_edit_groups";

private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
.setColumnName("group_uuid")
.setIsNullable(false)
.setDefaultValue(null)
.setLimit(VarcharColumnDef.UUID_SIZE)
.build();

public MakeQProfileEditGroupsGroupUuidNotNullable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
.updateColumn(uuidColumnDefinition)
.build());
}
}

+ 49
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuid.java Ver fichero

@@ -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.groups.qprofileeditgroups;

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 PopulateQProfileEditGroupsGroupUuid extends DataChange {

public PopulateQProfileEditGroupsGroupUuid(Database db) {
super(db);
}

@Override
protected void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();

massUpdate.select("select qeg.uuid, g.uuid " +
"from qprofile_edit_groups qeg " +
"join groups g on qeg.group_id = g.id");

massUpdate.update("update qprofile_edit_groups set group_uuid = ? where uuid = ?");

massUpdate.execute((row, update) -> {
update.setString(1, row.getString(2));
update.setString(2, row.getString(1));
return true;
});
}
}

+ 50
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest.java Ver fichero

@@ -0,0 +1,50 @@
/*
* SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v83.groups;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class AddPrimaryKeyOnUuidColumnOfGroupsTableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfGroupsTableTest.class, "schema.sql");

private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfGroupsTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertPrimaryKey("groups", "pk_groups", "uuid");
}

@Test
public void migration_is_not_re_entrant() throws SQLException {
underTest.execute();

assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
}
}

+ 61
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest.java Ver fichero

@@ -0,0 +1,61 @@
/*
* 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.groups;

import java.sql.SQLException;
import java.sql.Types;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.assertj.core.api.Assertions.assertThat;

public class AddUuidColumnToGroupsTableTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToGroupsTableTest.class, "schema.sql");
private DdlChange underTest = new AddUuidColumnToGroupsTable(db.database());

@Before
public void setup() {
insertGroups(1L);
insertGroups(2L);
insertGroups(3L);
}

@Test
public void add_uuid_column() throws SQLException {
underTest.execute();

db.assertColumnDefinition("groups", "uuid", Types.VARCHAR, 40, true);

assertThat(db.countRowsOfTable("groups"))
.isEqualTo(3);
}

private void insertGroups(Long id) {
db.executeInsert("groups",
"id", id,
"organization_uuid", "org" + id,
"name", "name" + id);
}

}

+ 51
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest.java Ver fichero

@@ -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.groups;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class DropIdColumnOfGroupsTableTest {

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfGroupsTableTest.class, "schema.sql");

private DdlChange underTest = new DropIdColumnOfGroupsTable(db.database());

@Test
public void execute() throws SQLException {
underTest.execute();

db.assertColumnDoesNotExist("groups", "id");
}

@Test
public void migration_is_not_re_entrant() throws SQLException {
underTest.execute();

assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
}

}

+ 0
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java Ver fichero


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio

Cargando…
Cancelar
Guardar