diff options
Diffstat (limited to 'server')
238 files changed, 5028 insertions, 1142 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java index fb937c9f934..a6d45e63dca 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java index 4c482018b6c..9b9c10ad1a3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java index 46276f62ac8..d5de60c4dda 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java @@ -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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java index 13fcc11397f..5306fcb3c2f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java @@ -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); } /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java index 8712e4bb5f4..462c2fc4b78 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java @@ -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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 6d4ee373de6..06f360c16a3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java index eb7bf2f8e7f..687e01848c2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index 7d0c9122262..74e95b0d286 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java index e5c621d8493..48b0447f042 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java @@ -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() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java index 4c3e5acf6d0..6a9f3f86bbd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java index d5c6383890d..ce1d821b3fa 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/GroupMembershipDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/GroupMembershipDto.java index 63cb4f29c8d..21b6947ff24 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/GroupMembershipDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/GroupMembershipDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java index 02f75e20479..1861da0c493 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDto.java index e0bd0f40f48..37672d86c26 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java index b963c0f8210..fbc41a420ae 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java index 01f75de542e..5aa0a065ba8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java index 262d1994125..42dea6966af 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java @@ -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('\''); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java index 8de8574077a..34f4d792d41 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java index fd862ae048f..ea5b0597f2b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java index 75934d1ceed..420c97989a9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java index 4416392e231..e125cac211e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java index 4cc86238ccf..e36dc1b2f4f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java index 01dd4f2f6c2..0eab0fa9ba6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java @@ -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); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java index 18a7c334830..2dc128b1fdc 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java @@ -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) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java index a2e5a9ccd89..4631d66a242 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java @@ -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; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java index 76fd4b99338..072fd40466a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java @@ -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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java index 3ea70da9825..ea421573722 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java @@ -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; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java index 4170fa12709..76e65ba0584 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java @@ -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(); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml index e8bda0081ec..ad1342ad8d1 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml @@ -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} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml index 32c918d3135..4e82b22be56 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml @@ -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 diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index c74ed2c7133..a36f6b98883 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -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> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml index 6c3707b102a..efaf0721354 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml @@ -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> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml index 9a023f45047..ccd81869b94 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml @@ -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> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml index d9d5850eb24..fe8ad8de0f2 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml @@ -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"> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml index a16cbdf73d0..c22763782f3 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml @@ -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> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml index abd64ce07f0..2350b9700db 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml @@ -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> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserGroupMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserGroupMapper.xml index 1f7a7ac7d41..2cf7f6530f4 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserGroupMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserGroupMapper.xml @@ -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"> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 9f21471b46c..2f90adf0194 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -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, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java index d6fa90971d9..648fd9bfd32 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java @@ -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) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java index 00ca9b3c9ed..fde6aab7ac8 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java @@ -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); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java index 443b3b7374c..2dbd6112ecc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java @@ -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) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java index 578abc4641d..77cf00ff9c1 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java @@ -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); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java index 1266bad5aa3..1563af9d5a0 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java @@ -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(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java index 70677469e13..ae128046ab0 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java @@ -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; } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java index d3e0a00f77c..0ccd071dc06 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java @@ -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)); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java index ca5428cf9ce..a6fd8238075 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java @@ -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); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java index 6a7a7d2af5e..35c8b69b737 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java @@ -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(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java index 94913bb0c5a..94fe7b9ddf5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/RoleDaoTest.java @@ -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"); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java index 4dd8cbd122c..5936ec55676 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -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; } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoTest.java index 7dfcb565005..f226aba8362 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoTest.java @@ -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()); } } diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueDaoTest/shared.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueDaoTest/shared.xml index 7ecb9987931..32a278ac094 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueDaoTest/shared.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueDaoTest/shared.xml @@ -1,7 +1,7 @@ <dataset> <group_roles id="1" - group_id="[null]" + group_uuid="[null]" resource_id="399" role="user" organization_uuid="org1"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueStatsDaoTest/should_select_assignees.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueStatsDaoTest/should_select_assignees.xml index 80787f7a14b..8b14a83d2a9 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueStatsDaoTest/should_select_assignees.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/issue/IssueStatsDaoTest/should_select_assignees.xml @@ -1,7 +1,7 @@ <dataset> <group_roles id="1" - group_id="[null]" + group_uuid="[null]" resource_id="399" role="user" organization_uuid="org1"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml index 5b4a68f376e..811a4ec4fe3 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_anonymous.xml @@ -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"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml index 4c3775cc298..92784c88940 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_group.xml @@ -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"/> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml index a4e80e5265a..58270a7655b 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/AuthorizationDaoTest/should_return_root_project_keys_for_user.xml @@ -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"/> diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java index e2bd1f5f9e1..9c5906f6b60 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java @@ -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) { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java index f7c44f61a61..97ee6e56f74 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java @@ -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(); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java index e50bba618d7..349b319e7da 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java @@ -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(); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/GroupTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/GroupTesting.java index 2bbdbef5142..2f904eadc74 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/GroupTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/GroupTesting.java @@ -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)) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java index 3aec11d801f..5d8cb40ac21 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java @@ -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) { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index 840da75e1d4..61d4f7c48a6 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -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) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTable.java new file mode 100644 index 00000000000..0c1d518061d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfMetricsTable.java new file mode 100644 index 00000000000..ac7307dab17 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfMetricsTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTable.java new file mode 100644 index 00000000000..fb7c38f0ad6 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToMetricsTable.java new file mode 100644 index 00000000000..76c2ae9ebcd --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToMetricsTable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTable.java new file mode 100644 index 00000000000..b473a7fe200 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfMetricsTable.java new file mode 100644 index 00000000000..84521e8fa94 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfMetricsTable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTable.java new file mode 100644 index 00000000000..3e1386bb56f --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfMetricsTable.java new file mode 100644 index 00000000000..3e84e48820b --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfMetricsTable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullable.java new file mode 100644 index 00000000000..187d515fa44 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeMetricsUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeMetricsUuidColumnNotNullable.java new file mode 100644 index 00000000000..cf3fda69fdb --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeMetricsUuidColumnNotNullable.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuid.java new file mode 100644 index 00000000000..54044e6fcc4 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuid.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateMetricsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateMetricsUuid.java new file mode 100644 index 00000000000..6617b5cfb30 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateMetricsUuid.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRoles.java new file mode 100644 index 00000000000..efcef0cbfb6 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRoles.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java new file mode 100644 index 00000000000..639b0616382 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTable.java @@ -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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTable.java new file mode 100644 index 00000000000..c5877817dd7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTable.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java new file mode 100644 index 00000000000..ab3238ee0f2 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTable.java @@ -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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuid.java new file mode 100644 index 00000000000..99757c5b7e3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuid.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsers.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsers.java new file mode 100644 index 00000000000..7895606e694 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsers.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java new file mode 100644 index 00000000000..67d2474970e --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTable.java @@ -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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTable.java new file mode 100644 index 00000000000..bbe2c267f3a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTable.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java new file mode 100644 index 00000000000..155265d8825 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTable.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullable.java new file mode 100644 index 00000000000..4a2a4a2afc3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullable.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuid.java new file mode 100644 index 00000000000..616ce20dc1c --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuid.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizations.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizations.java new file mode 100644 index 00000000000..1bbd8598197 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizations.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTable.java new file mode 100644 index 00000000000..37bab29449d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTable.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuid.java new file mode 100644 index 00000000000..597b8e04bcd --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuid.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroups.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroups.java new file mode 100644 index 00000000000..afccbca8a25 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroups.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTable.java new file mode 100644 index 00000000000..6c208b52663 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTable.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuid.java new file mode 100644 index 00000000000..86ded7b3127 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuid.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroups.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroups.java new file mode 100644 index 00000000000..10b33fe77f7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroups.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java new file mode 100644 index 00000000000..b26880a6d9f --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTable.java @@ -0,0 +1,66 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTable.java new file mode 100644 index 00000000000..79af277283c --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTable.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java new file mode 100644 index 00000000000..24710c8e1a7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTable.java @@ -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); + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullable.java new file mode 100644 index 00000000000..80f625838f9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullable.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuid.java new file mode 100644 index 00000000000..e513ad84d12 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuid.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest.java new file mode 100644 index 00000000000..59580c6e136 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest.java new file mode 100644 index 00000000000..faba17b1d66 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest.java @@ -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); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest.java new file mode 100644 index 00000000000..99b7379f9c5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.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); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java new file mode 100644 index 00000000000..9526f9f5261 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.platform.db.migration.version.v83.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 org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; +import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropPrimaryKeyOnIdColumnOfGroupsTableTest { + + private static final String TABLE_NAME = "groups"; + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupsTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())); + + private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfGroupsTable(db.database(), dropPrimaryKeySqlGenerator); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertNoPrimaryKey(TABLE_NAME); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..7f381630b7f --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullableTest.java @@ -0,0 +1,42 @@ +/* + * 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.MigrationStep; + +import static java.sql.Types.VARCHAR; + +public class MakeGroupsUuidColumnNotNullableTest { + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakeGroupsUuidColumnNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakeGroupsUuidColumnNotNullable(db.database()); + + @Test + public void uuid_column_is_not_nullable() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("groups", "uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuidTest.java new file mode 100644 index 00000000000..5d0839adc6f --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuidTest.java @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups; + +import java.sql.SQLException; +import java.util.Objects; +import java.util.stream.Collectors; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateGroupsUuidTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateGroupsUuidTest.class, "schema.sql"); + + private UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private DataChange underTest = new PopulateGroupsUuid(db.database(), uuidFactory); + + @Test + public void populate_uuids() throws SQLException { + insertGroups(1L); + insertGroups(2L); + insertGroups(3L); + + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertGroups(1L); + insertGroups(2L); + insertGroups(3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + private void verifyUuidsAreNotNull() { + assertThat(db.select("select uuid from groups") + .stream() + .map(row -> row.get("UUID")) + .filter(Objects::isNull) + .collect(Collectors.toList())).isEmpty(); + } + + private void insertGroups(Long id) { + db.executeInsert("groups", + "id", id, + "organization_uuid", "org" + id, + "name", "name" + id); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRolesTest.java new file mode 100644 index 00000000000..ededdb1e326 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRolesTest.java @@ -0,0 +1,64 @@ +/* + * 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 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 AddGroupUuidColumnToGroupRolesTest { + private static final String TABLE_NAME = "group_roles"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddGroupUuidColumnToGroupRolesTest.class, "schema.sql"); + private DdlChange underTest = new AddGroupUuidColumnToGroupRoles(db.database()); + + @Before + public void setup() { + insertGroupRole(1L); + insertGroupRole(2L); + insertGroupRole(3L); + } + + @Test + public void add_active_rule_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "group_uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable(TABLE_NAME)) + .isEqualTo(3); + } + + private void insertGroupRole(Long id) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "group_id", id + 1, + "role", "role" + id, + "organization_uuid", "org" + id + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTableTest.java new file mode 100644 index 00000000000..56c0530bb5a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTableTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.grouproles; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class AddIndexOnGroupUuidOfGroupRolesTableTest { + private static final String TABLE_NAME = "group_roles"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnGroupUuidOfGroupRolesTableTest.class, "schema.sql"); + + private MigrationStep underTest = new AddIndexOnGroupUuidOfGroupRolesTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertUniqueIndex(TABLE_NAME, "uniq_group_roles", "organization_uuid", "group_uuid", + "component_uuid", "role"); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + + // re-entrant + underTest.execute(); + + db.assertUniqueIndex(TABLE_NAME, "uniq_group_roles", "organization_uuid", "group_uuid", + "component_uuid", "role"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTableTest.java new file mode 100644 index 00000000000..e2131596aee --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTableTest.java @@ -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.SQLException; +import java.sql.Types; +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 DropGroupIdColumnOfGroupRolesTableTest { + private static final String TABLE_NAME = "group_roles"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropGroupIdColumnOfGroupRolesTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropGroupIdColumnOfGroupRolesTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, "group_id", Types.INTEGER, null, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, "group_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTableTest.java new file mode 100644 index 00000000000..fa93afa0118 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTableTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.grouproles; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class DropIndexOnGroupIdOfGroupRolesTableTest { + private static final String TABLE_NAME = "group_roles"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnGroupIdOfGroupRolesTableTest.class, "schema.sql"); + + private MigrationStep underTest = new DropIndexOnGroupIdOfGroupRolesTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertTableExists(TABLE_NAME); + db.assertUniqueIndex(TABLE_NAME, "uniq_group_roles", "organization_uuid", "group_id", + "component_uuid", "role"); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, "uniq_group_roles"); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + + // re-entrant + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, "uniq_group_roles"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuidTest.java new file mode 100644 index 00000000000..6511f7c1bb6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuidTest.java @@ -0,0 +1,104 @@ +/* + * 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 java.util.List; +import java.util.Map; +import org.assertj.core.groups.Tuple; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulateGroupRolesGroupUuidTest { + private static final String TABLE_NAME = "group_roles"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateGroupRolesGroupUuidTest.class, "schema.sql"); + + private DataChange underTest = new PopulateGroupRolesGroupUuid(db.database()); + + @Test + public void populate_uuids() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertGroupRole(4L, 1L); + insertGroupRole(5L, 2L); + insertGroupRole(6L, 3L); + + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertGroupRole(4L, 1L); + insertGroupRole(5L, 2L); + insertGroupRole(6L, 3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + private void assertThatTableContains(Tuple... tuples) { + List<Map<String, Object>> select = db.select("select uuid, group_id, group_uuid from " + TABLE_NAME); + assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("GROUP_ID"), m -> m.get("GROUP_UUID")) + .containsExactlyInAnyOrder(tuples); + } + + private void insertGroup(Long id) { + db.executeInsert("groups", + "id", id, + "uuid", "uuid" + id, + "organization_uuid", "org" + id, + "name", "name" + id); + } + + private void insertGroupRole(Long id, Long groupId) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "group_id", groupId, + "role", "role" + id, + "organization_uuid", "org" + id + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsersTest.java new file mode 100644 index 00000000000..2a1fe79311c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsersTest.java @@ -0,0 +1,62 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.groupsusers; + +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 AddGroupUuidColumnToGroupsUsersTest { + private static final String TABLE_NAME = "groups_users"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddGroupUuidColumnToGroupsUsersTest.class, "schema.sql"); + private DdlChange underTest = new AddGroupUuidColumnToGroupsUsers(db.database()); + + @Before + public void setup() { + insertGroupsUser(1L); + insertGroupsUser(2L); + insertGroupsUser(3L); + } + + @Test + public void add_active_rule_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "group_uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable(TABLE_NAME)) + .isEqualTo(3); + } + + private void insertGroupsUser(Long id) { + db.executeInsert(TABLE_NAME, + "user_id", id, + "group_id", id + 1 + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTableTest.java new file mode 100644 index 00000000000..329ea7e1765 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTableTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.groupsusers; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class AddIndexOnGroupUuidOfGroupsUsersTableTest { + private static final String TABLE_NAME = "groups_users"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnGroupUuidOfGroupsUsersTableTest.class, "schema.sql"); + + private MigrationStep underTest = new AddIndexOnGroupUuidOfGroupsUsersTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertIndex(TABLE_NAME, "index_groups_users_group_uuid", "group_uuid"); + db.assertUniqueIndex(TABLE_NAME, "groups_users_unique", "group_uuid", "user_id"); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + + // re-entrant + underTest.execute(); + + db.assertIndex(TABLE_NAME, "index_groups_users_group_uuid", "group_uuid"); + db.assertUniqueIndex(TABLE_NAME, "groups_users_unique", "group_uuid", "user_id"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTableTest.java new file mode 100644 index 00000000000..9311b335825 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTableTest.java @@ -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.groupsusers; + +import java.sql.SQLException; +import java.sql.Types; +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 DropGroupIdColumnOfGroupsUsersTableTest { + private static final String TABLE_NAME = "groups_users"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropGroupIdColumnOfGroupsUsersTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropGroupIdColumnOfGroupsUsersTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, "group_id", Types.BIGINT, null, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, "group_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTableTest.java new file mode 100644 index 00000000000..825d4132213 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTableTest.java @@ -0,0 +1,60 @@ +/* + * 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.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class DropIndexOnGroupIdOfGroupsUsersTableTest { + private static final String TABLE_NAME = "groups_users"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnGroupIdOfGroupsUsersTableTest.class, "schema.sql"); + + private MigrationStep underTest = new DropIndexOnGroupIdOfGroupsUsersTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertTableExists(TABLE_NAME); + db.assertIndex(TABLE_NAME, "index_groups_users_on_group_id", "group_id"); + db.assertUniqueIndex(TABLE_NAME, "groups_users_unique", "group_id", "user_id"); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, "index_groups_users_on_group_id"); + db.assertIndexDoesNotExist(TABLE_NAME, "groups_users_unique"); + + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + + // re-entrant + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, "index_groups_users_on_group_id"); + db.assertIndexDoesNotExist(TABLE_NAME, "groups_users_unique"); + + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullableTest.java new file mode 100644 index 00000000000..3afcc2bd638 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullableTest.java @@ -0,0 +1,44 @@ +/* + * 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.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static java.sql.Types.VARCHAR; + +public class MakeGroupsUsersGroupUuidNotNullableTest { + private static final String TABLE_NAME = "groups_users"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakeGroupsUsersGroupUuidNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakeGroupsUsersGroupUuidNotNullable(db.database()); + + @Test + public void uuid_column_is_not_null() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "group_uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuidTest.java new file mode 100644 index 00000000000..9196b14f2e5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuidTest.java @@ -0,0 +1,101 @@ +/* + * 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 java.util.List; +import java.util.Map; +import org.assertj.core.groups.Tuple; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulateGroupsUsersGroupUuidTest { + private static final String TABLE_NAME = "groups_users"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateGroupsUsersGroupUuidTest.class, "schema.sql"); + + private DataChange underTest = new PopulateGroupsUsersGroupUuid(db.database()); + + @Test + public void populate_uuids() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertGroupsUser(4L, 1L); + insertGroupsUser(5L, 2L); + insertGroupsUser(6L, 3L); + + underTest.execute(); + + assertThatTableContains( + tuple(1L, "uuid1"), + tuple(2L, "uuid2"), + tuple(3L, "uuid3") + ); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertGroupsUser(4L, 1L); + insertGroupsUser(5L, 2L); + insertGroupsUser(6L, 3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertThatTableContains( + tuple( 1L, "uuid1"), + tuple(2L, "uuid2"), + tuple(3L, "uuid3") + ); + } + + private void assertThatTableContains(Tuple... tuples) { + List<Map<String, Object>> select = db.select("select group_id, group_uuid from " + TABLE_NAME); + assertThat(select).extracting( m -> m.get("GROUP_ID"), m -> m.get("GROUP_UUID")) + .containsExactlyInAnyOrder(tuples); + } + + private void insertGroup(Long id) { + db.executeInsert("groups", + "id", id, + "uuid", "uuid" + id, + "organization_uuid", "org" + id); + } + + private void insertGroupsUser(Long id, Long group) { + db.executeInsert(TABLE_NAME, + "user_id", id, + "group_id", group + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizationsTest.java new file mode 100644 index 00000000000..a054c1f88bf --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizationsTest.java @@ -0,0 +1,68 @@ +/* + * 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 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 AddDefaultGroupUuidColumnToOrganizationsTest { + private static final String TABLE_NAME = "organizations"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddDefaultGroupUuidColumnToOrganizationsTest.class, "schema.sql"); + private DdlChange underTest = new AddDefaultGroupUuidColumnToOrganizations(db.database()); + + @Before + public void setup() { + insertOrganization(1L); + insertOrganization(2L); + insertOrganization(3L); + } + + @Test + public void add_active_rule_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "default_group_uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable(TABLE_NAME)) + .isEqualTo(3); + } + + private void insertOrganization(Long id) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "kee", "kee" + id, + "name", "name" + id, + "default_quality_gate_uuid", "default_quality_gate_uuid" + id, + "new_project_private", true, + "subscription", "subscription" + id, + "created_at", id + 1, + "updated_at", id + 2 + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTableTest.java new file mode 100644 index 00000000000..223df954b44 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTableTest.java @@ -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.organizations; + +import java.sql.SQLException; +import java.sql.Types; +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 DropDefaultGroupIdColumnOfOrganizationsTableTest { + private static final String TABLE_NAME = "organizations"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropDefaultGroupIdColumnOfOrganizationsTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropDefaultGroupIdColumnOfOrganizationsTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, "default_group_id", Types.INTEGER, null, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, "default_group_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuidTest.java new file mode 100644 index 00000000000..ec40df3d29d --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuidTest.java @@ -0,0 +1,108 @@ +/* + * 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 java.util.List; +import java.util.Map; +import org.assertj.core.groups.Tuple; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulateOrganizationsDefaultGroupUuidTest { + private static final String TABLE_NAME = "organizations"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateOrganizationsDefaultGroupUuidTest.class, "schema.sql"); + + private DataChange underTest = new PopulateOrganizationsDefaultGroupUuid(db.database()); + + @Test + public void populate_uuids() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertOrganization(4L, 1L); + insertOrganization(5L, 2L); + insertOrganization(6L, 3L); + + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertOrganization(4L, 1L); + insertOrganization(5L, 2L); + insertOrganization(6L, 3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + private void assertThatTableContains(Tuple... tuples) { + List<Map<String, Object>> select = db.select("select uuid, default_group_id, default_group_uuid from " + TABLE_NAME); + assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("DEFAULT_GROUP_ID"), m -> m.get("DEFAULT_GROUP_UUID")) + .containsExactlyInAnyOrder(tuples); + } + + private void insertGroup(Long id) { + db.executeInsert("groups", + "id", id, + "uuid", "uuid" + id, + "organization_uuid", "org" + id); + } + + private void insertOrganization(Long id, Long groupId) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "kee", "kee" + id, + "name", "name" + id, + "default_group_id", groupId, + "default_quality_gate_uuid", "default_quality_gate_uuid" + id, + "new_project_private", true, + "subscription", "subscription" + id, + "created_at", id + 1, + "updated_at", id + 2 + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroupsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroupsTest.java new file mode 100644 index 00000000000..58864e4498f --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroupsTest.java @@ -0,0 +1,64 @@ +/* + * 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 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 AddGroupUuidColumnToPermTemplatesGroupsTest { + private static final String TABLE_NAME = "perm_templates_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddGroupUuidColumnToPermTemplatesGroupsTest.class, "schema.sql"); + private DdlChange underTest = new AddGroupUuidColumnToPermTemplatesGroups(db.database()); + + @Before + public void setup() { + insertPermTemplatesGroup(1L); + insertPermTemplatesGroup(2L); + insertPermTemplatesGroup(3L); + } + + @Test + public void add_active_rule_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "group_uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable(TABLE_NAME)) + .isEqualTo(3); + } + + private void insertPermTemplatesGroup(Long id) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "group_id", id + 1, + "permission_reference", "permission_reference" + id, + "template_id", id + 2 + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTableTest.java new file mode 100644 index 00000000000..72b4996b314 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTableTest.java @@ -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.permtemplatesgroups; + +import java.sql.SQLException; +import java.sql.Types; +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 DropGroupIdColumnOfPermTemplatesGroupsTableTest { + private static final String TABLE_NAME = "perm_templates_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropGroupIdColumnOfPermTemplatesGroupsTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropGroupIdColumnOfPermTemplatesGroupsTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, "group_id", Types.INTEGER, null, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, "group_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuidTest.java new file mode 100644 index 00000000000..2991b9f8044 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuidTest.java @@ -0,0 +1,103 @@ +/* + * 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 java.util.List; +import java.util.Map; +import org.assertj.core.groups.Tuple; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulatePermTemplatesGroupsGroupUuidTest { + private static final String TABLE_NAME = "perm_templates_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulatePermTemplatesGroupsGroupUuidTest.class, "schema.sql"); + + private DataChange underTest = new PopulatePermTemplatesGroupsGroupUuid(db.database()); + + @Test + public void populate_uuids() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertPermTemplatesGroup(4L, 1L); + insertPermTemplatesGroup(5L, 2L); + insertPermTemplatesGroup(6L, 3L); + + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertPermTemplatesGroup(4L, 1L); + insertPermTemplatesGroup(5L, 2L); + insertPermTemplatesGroup(6L, 3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + private void assertThatTableContains(Tuple... tuples) { + List<Map<String, Object>> select = db.select("select uuid, group_id, group_uuid from " + TABLE_NAME); + assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("GROUP_ID"), m -> m.get("GROUP_UUID")) + .containsExactlyInAnyOrder(tuples); + } + + private void insertGroup(Long id) { + db.executeInsert("groups", + "id", id, + "uuid", "uuid" + id, + "organization_uuid", "org" + id); + } + + private void insertPermTemplatesGroup(Long id, Long groupId) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "group_id", groupId, + "permission_reference", "permission_reference" + id, + "template_id", id + 2 + ); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroupsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroupsTest.java new file mode 100644 index 00000000000..9c1e09cf940 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroupsTest.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups; + +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 AddGroupUuidColumnToQProfileEditGroupsTest { + private static final String TABLE_NAME = "qprofile_edit_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddGroupUuidColumnToQProfileEditGroupsTest.class, "schema.sql"); + private DdlChange underTest = new AddGroupUuidColumnToQProfileEditGroups(db.database()); + + @Before + public void setup() { + insertQProfileEditGroup(1L); + insertQProfileEditGroup(2L); + insertQProfileEditGroup(3L); + } + + @Test + public void add_active_rule_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "group_uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable(TABLE_NAME)) + .isEqualTo(3); + } + + private void insertQProfileEditGroup(Long id) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "group_id", id + 1, + "qprofile_uuid", "qprofile_uuid" + id, + "created_at", id + 3); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTableTest.java new file mode 100644 index 00000000000..f389702a1f5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTableTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class AddIndexOnGroupUuidOfQProfileEditGroupsTableTest { + private static final String TABLE_NAME = "qprofile_edit_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnGroupUuidOfQProfileEditGroupsTableTest.class, "schema.sql"); + + private MigrationStep underTest = new AddIndexOnGroupUuidOfQProfileEditGroupsTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertUniqueIndex(TABLE_NAME, "qprofile_edit_groups_unique", "group_uuid", "qprofile_uuid"); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + + // re-entrant + underTest.execute(); + + db.assertUniqueIndex(TABLE_NAME, "qprofile_edit_groups_unique", "group_uuid", "qprofile_uuid"); + + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTableTest.java new file mode 100644 index 00000000000..b9e955e4ebd --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTableTest.java @@ -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.SQLException; +import java.sql.Types; +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 DropGroupIdColumnOfQProfileEditGroupsTableTest { + private static final String TABLE_NAME = "qprofile_edit_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropGroupIdColumnOfQProfileEditGroupsTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropGroupIdColumnOfQProfileEditGroupsTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, "group_id", Types.INTEGER, null, false); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, "group_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTableTest.java new file mode 100644 index 00000000000..b51674cee11 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTableTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.groups.qprofileeditgroups; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class DropIndexOnGroupIdOfQProfileEditGroupsTableTest { + private static final String TABLE_NAME = "qprofile_edit_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnGroupIdOfQProfileEditGroupsTableTest.class, "schema.sql"); + + private MigrationStep underTest = new DropIndexOnGroupIdOfQProfileEditGroupsTable(db.database()); + + @Test + public void execute() throws SQLException { + db.assertTableExists(TABLE_NAME); + db.assertUniqueIndex(TABLE_NAME, "qprofile_edit_groups_unique", "group_id", "qprofile_uuid"); + + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, "qprofile_edit_groups_unique"); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + + // re-entrant + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, "qprofile_edit_groups_unique"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullableTest.java new file mode 100644 index 00000000000..2387bce3311 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullableTest.java @@ -0,0 +1,44 @@ +/* + * 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.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static java.sql.Types.VARCHAR; + +public class MakeQProfileEditGroupsGroupUuidNotNullableTest { + private static final String TABLE_NAME = "qprofile_edit_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakeQProfileEditGroupsGroupUuidNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakeQProfileEditGroupsGroupUuidNotNullable(db.database()); + + @Test + public void uuid_column_is_not_null() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, "group_uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuidTest.java new file mode 100644 index 00000000000..d0aa1b04141 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuidTest.java @@ -0,0 +1,102 @@ +/* + * 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 java.util.List; +import java.util.Map; +import org.assertj.core.groups.Tuple; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulateQProfileEditGroupsGroupUuidTest { + private static final String TABLE_NAME = "qprofile_edit_groups"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateQProfileEditGroupsGroupUuidTest.class, "schema.sql"); + + private DataChange underTest = new PopulateQProfileEditGroupsGroupUuid(db.database()); + + @Test + public void populate_uuids() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertQProfileEditGroup(4L, 1L); + insertQProfileEditGroup(5L, 2L); + insertQProfileEditGroup(6L, 3L); + + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertGroup(1L); + insertGroup(2L); + insertGroup(3L); + + insertQProfileEditGroup(4L, 1L); + insertQProfileEditGroup(5L, 2L); + insertQProfileEditGroup(6L, 3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertThatTableContains( + tuple("uuid4", 1L, "uuid1"), + tuple("uuid5", 2L, "uuid2"), + tuple("uuid6", 3L, "uuid3") + ); + } + + private void assertThatTableContains(Tuple... tuples) { + List<Map<String, Object>> select = db.select("select uuid, group_id, group_uuid from " + TABLE_NAME); + assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("GROUP_ID"), m -> m.get("GROUP_UUID")) + .containsExactlyInAnyOrder(tuples); + } + + private void insertGroup(Long id) { + db.executeInsert("groups", + "id", id, + "uuid", "uuid" + id, + "organization_uuid", "org" + id); + } + + private void insertQProfileEditGroup(Long id, Long groupId) { + db.executeInsert(TABLE_NAME, + "uuid", "uuid" + id, + "group_id", groupId, + "qprofile_uuid", "qprofile_uuid" + id, + "created_at", id + 3); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest/schema.sql new file mode 100644 index 00000000000..8b2000be3e9 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/AddPrimaryKeyOnUuidColumnOfGroupsTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest/schema.sql new file mode 100644 index 00000000000..a20ddd6ac66 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/AddUuidColumnToGroupsTableTest/schema.sql @@ -0,0 +1,9 @@ +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 +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest/schema.sql new file mode 100644 index 00000000000..963af911d8a --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/DropIdColumnOfGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest/schema.sql new file mode 100644 index 00000000000..3b127b99e7a --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..5c6c10fce76 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/MakeGroupsUuidColumnNotNullableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuidTest/schema.sql new file mode 100644 index 00000000000..5c6c10fce76 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/PopulateGroupsUuidTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40), + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRolesTest/schema.sql new file mode 100644 index 00000000000..3395ab556f2 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddGroupUuidColumnToGroupRolesTest/schema.sql @@ -0,0 +1,10 @@ +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 +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTableTest/schema.sql new file mode 100644 index 00000000000..f1f49219014 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/AddIndexOnGroupUuidOfGroupRolesTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "GROUP_ROLES"( + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "ROLE" VARCHAR(64) NOT NULL, + "COMPONENT_UUID" VARCHAR(40), + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID"); +CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTableTest/schema.sql new file mode 100644 index 00000000000..2e809ae1a2e --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropGroupIdColumnOfGroupRolesTableTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "GROUP_ROLES"( + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "ROLE" VARCHAR(64) NOT NULL, + "COMPONENT_UUID" VARCHAR(40), + "UUID" VARCHAR(40) NOT NULL +); +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_UUID", "COMPONENT_UUID", "ROLE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTableTest/schema.sql new file mode 100644 index 00000000000..a17d5208a43 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/DropIndexOnGroupIdOfGroupRolesTableTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "GROUP_ROLES"( + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "ROLE" VARCHAR(64) NOT NULL, + "COMPONENT_UUID" VARCHAR(40), + "UUID" VARCHAR(40) NOT NULL +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuidTest/schema.sql new file mode 100644 index 00000000000..dbed7d09f4f --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/grouproles/PopulateGroupRolesGroupUuidTest/schema.sql @@ -0,0 +1,22 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); + +CREATE TABLE "GROUP_ROLES"( + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER, + "GROUP_UUID" VARCHAR(40), + "ROLE" VARCHAR(64) NOT NULL, + "COMPONENT_UUID" VARCHAR(40), + "UUID" VARCHAR(40) NOT NULL +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsersTest/schema.sql new file mode 100644 index 00000000000..0d7bb6e917a --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddGroupUuidColumnToGroupsUsersTest/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE "GROUPS_USERS"( + "USER_ID" BIGINT, + "GROUP_ID" BIGINT +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTableTest/schema.sql new file mode 100644 index 00000000000..4f926b037ad --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/AddIndexOnGroupUuidOfGroupsUsersTableTest/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE "GROUPS_USERS"( + "USER_ID" BIGINT, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" BIGINT +); +CREATE INDEX "INDEX_GROUPS_USERS_ON_USER_ID" ON "GROUPS_USERS"("USER_ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTableTest/schema.sql new file mode 100644 index 00000000000..6f1ef46cb30 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropGroupIdColumnOfGroupsUsersTableTest/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE "GROUPS_USERS"( + "USER_ID" BIGINT, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" BIGINT +); +CREATE INDEX "INDEX_GROUPS_USERS_ON_USER_ID" ON "GROUPS_USERS"("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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTableTest/schema.sql new file mode 100644 index 00000000000..214ddd1af92 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/DropIndexOnGroupIdOfGroupsUsersTableTest/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE "GROUPS_USERS"( + "USER_ID" BIGINT, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" BIGINT +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullableTest/schema.sql new file mode 100644 index 00000000000..4614b88b6f9 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/MakeGroupsUsersGroupUuidNotNullableTest/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE "GROUPS_USERS"( + "USER_ID" BIGINT, + "GROUP_UUID" VARCHAR(40), + "GROUP_ID" BIGINT +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuidTest/schema.sql new file mode 100644 index 00000000000..f3c7d7266a8 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/groupsusers/PopulateGroupsUsersGroupUuidTest/schema.sql @@ -0,0 +1,19 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); + +CREATE TABLE "GROUPS_USERS"( + "USER_ID" BIGINT, + "GROUP_UUID" VARCHAR(40), + "GROUP_ID" BIGINT +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizationsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizationsTest/schema.sql new file mode 100644 index 00000000000..169cf356975 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/AddDefaultGroupUuidColumnToOrganizationsTest/schema.sql @@ -0,0 +1,20 @@ +CREATE TABLE "ORGANIZATIONS"( + "UUID" VARCHAR(40) NOT NULL, + "KEE" VARCHAR(255) NOT NULL, + "NAME" VARCHAR(255) NOT NULL, + "DESCRIPTION" VARCHAR(256), + "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), + "DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), + "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, + "SUBSCRIPTION" VARCHAR(40) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); +ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); +CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTableTest/schema.sql new file mode 100644 index 00000000000..65e6acd5661 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/DropDefaultGroupIdColumnOfOrganizationsTableTest/schema.sql @@ -0,0 +1,21 @@ +CREATE TABLE "ORGANIZATIONS"( + "UUID" VARCHAR(40) NOT NULL, + "KEE" VARCHAR(255) NOT NULL, + "NAME" VARCHAR(255) NOT NULL, + "DESCRIPTION" VARCHAR(256), + "URL" VARCHAR(256), + "AVATAR_URL" VARCHAR(256), + "GUARDED" BOOLEAN, + "DEFAULT_GROUP_ID" INTEGER, + "DEFAULT_GROUP_UUID" VARCHAR(40), + "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, + "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), + "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, + "SUBSCRIPTION" VARCHAR(40) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); +ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); +CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuidTest/schema.sql new file mode 100644 index 00000000000..6ecb376b33b --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/organizations/PopulateOrganizationsDefaultGroupUuidTest/schema.sql @@ -0,0 +1,32 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); + +CREATE TABLE "ORGANIZATIONS"( + "UUID" VARCHAR(40) NOT NULL, + "KEE" VARCHAR(255) NOT NULL, + "NAME" VARCHAR(255) NOT NULL, + "DESCRIPTION" VARCHAR(256), + "URL" VARCHAR(256), + "AVATAR_URL" VARCHAR(256), + "GUARDED" BOOLEAN, + "DEFAULT_GROUP_ID" INTEGER, + "DEFAULT_GROUP_UUID" VARCHAR(40), + "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, + "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), + "DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), + "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, + "SUBSCRIPTION" VARCHAR(40) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL +); +ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID"); +CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroupsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroupsTest/schema.sql new file mode 100644 index 00000000000..f8f880ba7d6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/AddGroupUuidColumnToPermTemplatesGroupsTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "GROUP_ID" INTEGER, + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTableTest/schema.sql new file mode 100644 index 00000000000..fa92bad8669 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/DropGroupIdColumnOfPermTemplatesGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "GROUP_ID" INTEGER, + "GROUP_UUID" VARCHAR(40), + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuidTest/schema.sql new file mode 100644 index 00000000000..d7f1b662726 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/permtemplatesgroups/PopulatePermTemplatesGroupsGroupUuidTest/schema.sql @@ -0,0 +1,21 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); + +CREATE TABLE "PERM_TEMPLATES_GROUPS"( + "GROUP_ID" INTEGER, + "GROUP_UUID" VARCHAR(40), + "TEMPLATE_ID" INTEGER NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "PERM_TEMPLATES_GROUPS" ADD CONSTRAINT "PK_PERM_TEMPLATES_GROUPS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroupsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroupsTest/schema.sql new file mode 100644 index 00000000000..b375127ef24 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddGroupUuidColumnToQProfileEditGroupsTest/schema.sql @@ -0,0 +1,9 @@ +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 +); +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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTableTest/schema.sql new file mode 100644 index 00000000000..d7d22ae97b6 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/AddIndexOnGroupUuidOfQProfileEditGroupsTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "QPROFILE_EDIT_GROUPS"( + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER NOT NULL, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "QPROFILE_UUID" VARCHAR(255) NOT NULL, + "CREATED_AT" BIGINT 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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTableTest/schema.sql new file mode 100644 index 00000000000..3a866c066ab --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropGroupIdColumnOfQProfileEditGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "QPROFILE_EDIT_GROUPS"( + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER NOT NULL, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "QPROFILE_UUID" VARCHAR(255) NOT NULL, + "CREATED_AT" BIGINT 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_UUID", "QPROFILE_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTableTest/schema.sql new file mode 100644 index 00000000000..e4deaa55ba0 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/DropIndexOnGroupIdOfQProfileEditGroupsTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "QPROFILE_EDIT_GROUPS"( + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER NOT NULL, + "GROUP_UUID" VARCHAR(40) NOT NULL, + "QPROFILE_UUID" VARCHAR(255) NOT NULL, + "CREATED_AT" BIGINT 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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullableTest/schema.sql new file mode 100644 index 00000000000..f30b909de2e --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/MakeQProfileEditGroupsGroupUuidNotNullableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "QPROFILE_EDIT_GROUPS"( + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER NOT NULL, + "GROUP_UUID" VARCHAR(40), + "QPROFILE_UUID" VARCHAR(255) NOT NULL, + "CREATED_AT" BIGINT 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"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuidTest/schema.sql new file mode 100644 index 00000000000..05b4a34f279 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/groups/qprofileeditgroups/PopulateQProfileEditGroupsGroupUuidTest/schema.sql @@ -0,0 +1,21 @@ +CREATE TABLE "GROUPS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(500), + "DESCRIPTION" VARCHAR(200), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "GROUPS" ADD CONSTRAINT "PK_GROUPS" PRIMARY KEY("ID"); + +CREATE TABLE "QPROFILE_EDIT_GROUPS"( + "UUID" VARCHAR(40) NOT NULL, + "GROUP_ID" INTEGER NOT NULL, + "GROUP_UUID" VARCHAR(40), + "QPROFILE_UUID" VARCHAR(255) NOT NULL, + "CREATED_AT" BIGINT 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"); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewAuthorizedIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewAuthorizedIndex.java index 0576a5c2611..289111f4af0 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewAuthorizedIndex.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewAuthorizedIndex.java @@ -39,7 +39,7 @@ public class NewAuthorizedIndex extends NewIndex<NewAuthorizedIndex> { this.mainType = IndexType.main(index, TYPE_AUTHORIZATION); super.createTypeMapping(mainType) - .createLongField(FIELD_GROUP_IDS) + .keywordFieldBuilder(FIELD_GROUP_IDS).build() .createLongField(FIELD_USER_IDS) .createBooleanField(FIELD_ALLOW_ANYONE); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/AuthorizationDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/AuthorizationDoc.java index 281186fd4d1..64fbb797dce 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/AuthorizationDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/AuthorizationDoc.java @@ -43,7 +43,7 @@ public class AuthorizationDoc extends BaseDoc { if (dto.isAllowAnyone()) { return res.setAllowAnyone(); } - return res.setRestricted(dto.getGroupIds(), dto.getUserIds()); + return res.setRestricted(dto.getGroupUuids(), dto.getUserIds()); } @Override @@ -73,9 +73,9 @@ public class AuthorizationDoc extends BaseDoc { return this; } - private AuthorizationDoc setRestricted(List<Integer> groupIds, List<Integer> userIds) { + private AuthorizationDoc setRestricted(List<String> groupUuids, List<Integer> userIds) { setField(FIELD_ALLOW_ANYONE, false); - setField(FIELD_GROUP_IDS, groupIds); + setField(FIELD_GROUP_IDS, groupUuids); setField(FIELD_USER_IDS, userIds); return this; } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/IndexPermissions.java b/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/IndexPermissions.java index 3e4b661cd31..a19e992f576 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/IndexPermissions.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/permission/index/IndexPermissions.java @@ -26,7 +26,7 @@ public final class IndexPermissions { private final String projectUuid; private final String qualifier; private final List<Integer> userIds = new ArrayList<>(); - private final List<Integer> groupIds = new ArrayList<>(); + private final List<String> groupUuids = new ArrayList<>(); private boolean allowAnyone = false; public IndexPermissions(String projectUuid, String qualifier) { @@ -51,13 +51,13 @@ public final class IndexPermissions { return this; } - public IndexPermissions addGroupId(int id) { - groupIds.add(id); + public IndexPermissions addGroupUuid(String uuid) { + groupUuids.add(uuid); return this; } - public List<Integer> getGroupIds() { - return groupIds; + public List<String> getGroupUuids() { + return groupUuids; } public IndexPermissions allowAnyone() { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewAuthorizedIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewAuthorizedIndexTest.java index c0c2fbf11c3..25d162ca4ca 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewAuthorizedIndexTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewAuthorizedIndexTest.java @@ -106,7 +106,7 @@ public class NewAuthorizedIndexTest { Map<String, Object> properties = getProperties(builtIndex); assertThat(getFieldAsMap(properties, "auth_groupIds")) - .containsOnly(entry("type", "long")); + .contains(entry("type", "keyword")); assertThat(getFieldAsMap(properties, "auth_userIds")) .containsOnly(entry("type", "long")); assertThat(getFieldAsMap(properties, "auth_allowAnyone")) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java index 390ffe7a8dc..d44447752e5 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java @@ -124,7 +124,7 @@ public class AuthorizationDocTest { public void fromDto_defines_userIds_and_groupIds_if_allowAnyone_is_false() { IndexPermissions underTest = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); IntStream.range(0, 1 + new Random().nextInt(5)).forEach(underTest::addUserId); - IntStream.range(0, 1 + new Random().nextInt(5)).forEach(underTest::addGroupId); + IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(underTest::addGroupUuid); AuthorizationDoc doc = AuthorizationDoc.fromDto(IndexType.main(Index.simple("foo"), "bar"), underTest); @@ -132,15 +132,15 @@ public class AuthorizationDocTest { assertThat(auth_allowAnyone).isFalse(); List<Integer> userIds = doc.getField("auth_userIds"); assertThat(userIds).isEqualTo(underTest.getUserIds()); - List<Integer> groupIds = doc.getField("auth_groupIds"); - assertThat(groupIds).isEqualTo(underTest.getGroupIds()); + List<String> groupUuids = doc.getField("auth_groupIds"); + assertThat(groupUuids).isEqualTo(underTest.getGroupUuids()); } @Test - public void fromDto_ignores_userIds_and_groupIds_if_allowAnyone_is_true() { + public void fromDto_ignores_userIds_and_groupUuids_if_allowAnyone_is_true() { IndexPermissions underTest = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); IntStream.range(0, 1 + new Random().nextInt(5)).forEach(underTest::addUserId); - IntStream.range(0, 1 + new Random().nextInt(5)).forEach(underTest::addGroupId); + IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(underTest::addGroupUuid); underTest.allowAnyone(); AuthorizationDoc doc = AuthorizationDoc.fromDto(IndexType.main(Index.simple("foo"), "bar"), underTest); @@ -154,10 +154,10 @@ public class AuthorizationDocTest { assertThat(e).hasMessage("Field auth_userIds not specified in query options"); } try { - doc.getField("auth_groupIds"); + doc.getField("auth_groupUuids"); fail("should have thrown IllegalStateException"); } catch (IllegalStateException e) { - assertThat(e).hasMessage("Field auth_groupIds not specified in query options"); + assertThat(e).hasMessage("Field auth_groupUuids not specified in query options"); } } @@ -167,16 +167,16 @@ public class AuthorizationDocTest { allowAnyone.allowAnyone(); IndexPermissions someUserIds = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someUserIds::addUserId); - IndexPermissions someGroupIds = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); - IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someGroupIds::addGroupId); - IndexPermissions someGroupIdAndUserIs = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); - IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someGroupIdAndUserIs::addUserId); - IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someGroupIdAndUserIs::addGroupId); + IndexPermissions someGroupUuids = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); + IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(someGroupUuids::addGroupUuid); + IndexPermissions someGroupUuidAndUserIs = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4)); + IntStream.range(0, 1 + new Random().nextInt(5)).forEach(someGroupUuidAndUserIs::addUserId); + IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(someGroupUuidAndUserIs::addGroupUuid); return new Object[][] { {allowAnyone}, {someUserIds}, - {someGroupIds}, - {someGroupIdAndUserIs} + {someGroupUuids}, + {someGroupUuidAndUserIs} }; } } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java index 6a73311ad64..153024902f8 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java @@ -200,7 +200,7 @@ public class UserRegistrarImpl implements UserRegistrar { groupsToAdd.stream().map(groupsByName::get).filter(Objects::nonNull).forEach( groupDto -> { LOGGER.debug("Adding group '{}' to user '{}'", groupDto.getName(), userDto.getLogin()); - dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(groupDto.getId()).setUserId(userDto.getId())); + dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupUuid(groupDto.getUuid()).setUserId(userDto.getId())); }); } @@ -210,10 +210,10 @@ public class UserRegistrarImpl implements UserRegistrar { .filter(Objects::nonNull) // user should be member of default group only when organizations are disabled, as the IdentityProvider API doesn't handle yet // organizations - .filter(group -> !defaultGroup.isPresent() || !group.getId().equals(defaultGroup.get().getId())) + .filter(group -> !defaultGroup.isPresent() || !group.getUuid().equals(defaultGroup.get().getUuid())) .forEach(groupDto -> { LOGGER.debug("Removing group '{}' from user '{}'", groupDto.getName(), userDto.getLogin()); - dbClient.userGroupDao().delete(dbSession, groupDto.getId(), userDto.getId()); + dbClient.userGroupDao().delete(dbSession, groupDto.getUuid(), userDto.getId()); }); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java index fcf6154a232..e0cd0a54266 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java @@ -78,7 +78,7 @@ public class MemberUpdater { .setOrganizationUuid(organization.getUuid()) .setUserId(user.getId())); dbClient.userGroupDao().insert(dbSession, - new UserGroupDto().setGroupId(defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()).getId()).setUserId(user.getId())); + new UserGroupDto().setGroupUuid(defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()).getUuid()).setUserId(user.getId())); } public void removeMember(DbSession dbSession, OrganizationDto organization, UserDto user) { diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java index 720a2ba1be0..bd9fe0a571b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java @@ -85,28 +85,28 @@ public class OrganisationSupport { private void associateMembersOfDefaultOrganizationToGroup(DbSession dbSession, String defaultOrganizationUuid, GroupDto membersGroup) { List<Integer> organizationMembers = dbClient.organizationMemberDao().selectUserIdsByOrganizationUuid(dbSession, defaultOrganizationUuid); - organizationMembers.forEach(member -> dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(membersGroup.getId()).setUserId(member))); + organizationMembers.forEach(member -> dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupUuid(membersGroup.getUuid()).setUserId(member))); } private void copySonarUsersGroupPermissionsToMembersGroup(DbSession dbSession, String defaultOrganizationUuid, GroupDto sonarUsersGroup, GroupDto membersGroup) { - dbClient.groupPermissionDao().selectAllPermissionsByGroupId(dbSession, defaultOrganizationUuid, sonarUsersGroup.getId(), + dbClient.groupPermissionDao().selectAllPermissionsByGroupUuid(dbSession, defaultOrganizationUuid, sonarUsersGroup.getUuid(), context -> { GroupPermissionDto groupPermissionDto = (GroupPermissionDto) context.getResultObject(); dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto() .setUuid(uuidFactory.create()) .setOrganizationUuid(defaultOrganizationUuid) - .setGroupId(membersGroup.getId()) + .setGroupUuid(membersGroup.getUuid()) .setRole(groupPermissionDto.getRole()) .setComponentUuid(groupPermissionDto.getComponentUuid())); }); } private void copySonarUsersGroupPermissionTemplatesToMembersGroup(DbSession dbSession, GroupDto sonarUsersGroup, GroupDto membersGroup) { - List<PermissionTemplateGroupDto> sonarUsersPermissionTemplates = dbClient.permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupId(dbSession, - sonarUsersGroup.getId()); + List<PermissionTemplateGroupDto> sonarUsersPermissionTemplates = dbClient.permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupUuid(dbSession, + sonarUsersGroup.getUuid()); sonarUsersPermissionTemplates.forEach(permissionTemplateGroup -> dbClient.permissionTemplateDao().insertGroupPermission(dbSession, - permissionTemplateGroup.getTemplateUuid(), membersGroup.getId(), permissionTemplateGroup.getPermission())); + permissionTemplateGroup.getTemplateUuid(), membersGroup.getUuid(), permissionTemplateGroup.getPermission())); } private List<Integer> disableTemplateRulesAndCustomRules(DbSession dbSession) { diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java index beb8569be39..ce7f4f9ebe6 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java @@ -183,7 +183,7 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater { } private void insertGroupPermission(DbSession dbSession, PermissionTemplateDto template, String permission, @Nullable GroupDto group) { - dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group == null ? null : group.getId(), permission); + dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group == null ? null : group.getUuid(), permission); } private void insertQualityProfiles(DbSession dbSession, DbSession batchDbSession, OrganizationDto organization) { @@ -220,6 +220,7 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater { */ private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) { GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto() + .setUuid(uuidFactory.create()) .setOrganizationUuid(organization.getUuid()) .setName(OWNERS_GROUP_NAME) .setDescription(OWNERS_GROUP_DESCRIPTION)); @@ -233,14 +234,14 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater { new GroupPermissionDto() .setUuid(uuidFactory.create()) .setOrganizationUuid(group.getOrganizationUuid()) - .setGroupId(group.getId()) + .setGroupUuid(group.getUuid()) .setRole(permission.getKey())); } private void addCurrentUserToGroup(DbSession dbSession, GroupDto group, int createUserId) { dbClient.userGroupDao().insert( dbSession, - new UserGroupDto().setGroupId(group.getId()).setUserId(createUserId)); + new UserGroupDto().setGroupUuid(group.getUuid()).setUserId(createUserId)); } private void insertOrganizationMember(DbSession dbSession, OrganizationDto organizationDto, int userId) { diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupId.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuid.java index 227b309ad42..e3695d6b39b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupId.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuid.java @@ -28,28 +28,28 @@ import static java.util.Objects.requireNonNull; * Reference to a user group, as used internally by the backend. It does * not support reference to virtual groups "anyone". * - * @see GroupIdOrAnyone + * @see GroupUuidOrAnyone */ @Immutable -public class GroupId { +public class GroupUuid { - private final int id; + private final String uuid; private final String organizationUuid; - private GroupId(String organizationUuid, int id) { - this.id = id; + private GroupUuid(String organizationUuid, String uuid) { + this.uuid = uuid; this.organizationUuid = requireNonNull(organizationUuid); } - public int getId() { - return id; + public String getUuid() { + return uuid; } public String getOrganizationUuid() { return organizationUuid; } - public static GroupId from(GroupDto dto) { - return new GroupId(dto.getOrganizationUuid(), dto.getId()); + public static GroupUuid from(GroupDto dto) { + return new GroupUuid(dto.getOrganizationUuid(), dto.getUuid()); } } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupIdOrAnyone.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuidOrAnyone.java index 1e975472a7b..bd6e5dd6ba9 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupIdOrAnyone.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuidOrAnyone.java @@ -28,40 +28,40 @@ import static java.util.Objects.requireNonNull; /** * Reference to a user group, as used internally by the backend. Contrary to - * {@link GroupId}, it supports reference to virtual groups "anyone". In these - * cases {@link #getId()} returns {@code null} + * {@link GroupUuid}, it supports reference to virtual groups "anyone". In these + * cases {@link #getUuid()} returns {@code null} * - * @see GroupId + * @see GroupUuid */ @Immutable -public class GroupIdOrAnyone { +public class GroupUuidOrAnyone { - private final Integer id; + private final String uuid; private final String organizationUuid; - private GroupIdOrAnyone(String organizationUuid, @Nullable Integer id) { - this.id = id; + private GroupUuidOrAnyone(String organizationUuid, @Nullable String uuid) { + this.uuid = uuid; this.organizationUuid = requireNonNull(organizationUuid, "organizationUuid can't be null"); } public boolean isAnyone() { - return id == null; + return uuid == null; } @CheckForNull - public Integer getId() { - return id; + public String getUuid() { + return uuid; } public String getOrganizationUuid() { return organizationUuid; } - public static GroupIdOrAnyone from(GroupDto dto) { - return new GroupIdOrAnyone(dto.getOrganizationUuid(), dto.getId()); + public static GroupUuidOrAnyone from(GroupDto dto) { + return new GroupUuidOrAnyone(dto.getOrganizationUuid(), dto.getUuid()); } - public static GroupIdOrAnyone forAnyone(String organizationUuid) { - return new GroupIdOrAnyone(organizationUuid, null); + public static GroupUuidOrAnyone forAnyone(String organizationUuid) { + return new GroupUuidOrAnyone(organizationUuid, null); } } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java index 41c23d9f3ac..d608545b54a 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java @@ -453,7 +453,7 @@ public class UserUpdater { } private static boolean isUserAlreadyMemberOfDefaultGroup(GroupDto defaultGroup, List<GroupDto> userGroups) { - return userGroups.stream().anyMatch(group -> defaultGroup.getId().equals(group.getId())); + return userGroups.stream().anyMatch(group -> defaultGroup.getUuid().equals(group.getUuid())); } private void addUserToDefaultOrganizationAndDefaultGroup(DbSession dbSession, UserDto userDto) { @@ -473,7 +473,7 @@ public class UserUpdater { if (isUserAlreadyMemberOfDefaultGroup(defaultGroup, userGroups)) { return; } - dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(defaultGroup.getId())); + dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupUuid(defaultGroup.getUuid())); } private void setNotificationsReadDate(DbSession dbSession, UserDto user) { diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java index 86379dde770..4a1f68e92b2 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java @@ -20,6 +20,7 @@ package org.sonar.server.usergroups; import java.util.Optional; +import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.user.GroupDto; @@ -30,9 +31,11 @@ public class DefaultGroupCreatorImpl implements DefaultGroupCreator { public static final String DEFAULT_GROUP_NAME = "Members"; private final DbClient dbClient; + private final UuidFactory uuidFactory; - public DefaultGroupCreatorImpl(DbClient dbClient) { + public DefaultGroupCreatorImpl(DbClient dbClient, UuidFactory uuidFactory) { this.dbClient = dbClient; + this.uuidFactory = uuidFactory; } public GroupDto create(DbSession dbSession, String organizationUuid) { @@ -40,11 +43,12 @@ public class DefaultGroupCreatorImpl implements DefaultGroupCreator { checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); GroupDto defaultGroup = new GroupDto() + .setUuid(uuidFactory.create()) .setName(DEFAULT_GROUP_NAME) .setDescription("All members of the organization") .setOrganizationUuid(organizationUuid); dbClient.groupDao().insert(dbSession, defaultGroup); - dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); + dbClient.organizationDao().setDefaultGroupUuid(dbSession, organizationUuid, defaultGroup); return defaultGroup; } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java index 993075bb321..4ad43db1d07 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java @@ -35,9 +35,9 @@ public class DefaultGroupFinder { } public GroupDto findDefaultGroup(DbSession dbSession, String organizationUuid) { - int defaultGroupId = dbClient.organizationDao().getDefaultGroupId(dbSession, organizationUuid) + String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organizationUuid) .orElseThrow(() -> new IllegalStateException(format("Default group cannot be found on organization '%s'", organizationUuid))); - return requireNonNull(dbClient.groupDao().selectById(dbSession, defaultGroupId), format("Group '%s' cannot be found", defaultGroupId)); + return requireNonNull(dbClient.groupDao().selectByUuid(dbSession, defaultGroupUuid), format("Group '%s' cannot be found", defaultGroupUuid)); } } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java index df984ddba95..f0f63a56bfe 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java @@ -431,9 +431,9 @@ public class HttpHeadersAuthenticationTest { private void verityUserGroups(String login, GroupDto... expectedGroups) { UserDto userDto = db.users().selectUserByLogin(login).get(); if (expectedGroups.length == 0) { - assertThat(db.users().selectGroupIdsOfUser(userDto)).isEmpty(); + assertThat(db.users().selectGroupUuidsOfUser(userDto)).isEmpty(); } else { - assertThat(db.users().selectGroupIdsOfUser(userDto)).containsOnly(stream(expectedGroups).map(GroupDto::getId).collect(MoreCollectors.toList()).toArray(new Integer[] {})); + assertThat(db.users().selectGroupUuidsOfUser(userDto)).containsOnly(stream(expectedGroups).map(GroupDto::getUuid).collect(MoreCollectors.toList()).toArray(new String[] {})); } } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java index 27b16482f47..6229476c2d9 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java @@ -790,7 +790,7 @@ public class UserRegistrarImplTest { } private void checkGroupMembership(UserDto user, GroupDto... expectedGroups) { - assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(stream(expectedGroups).map(GroupDto::getId).collect(Collectors.toList()).toArray(new Integer[]{})); + assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(stream(expectedGroups).map(GroupDto::getUuid).collect(Collectors.toList()).toArray(new String[]{})); } private GroupDto insertDefaultGroup() { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java index 885d96c0016..8735ba7f177 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java @@ -302,10 +302,10 @@ public class MemberUpdaterTest { underTest.removeMember(db.getSession(), organization, user); - assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId())) - .containsOnly(anotherGroup.getId()); - assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(db.getSession(), anotherUser.getId())) - .containsOnly(group.getId(), anotherGroup.getId()); + assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), user.getId())) + .containsOnly(anotherGroup.getUuid()); + assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), anotherUser.getId())) + .containsOnly(group.getUuid(), anotherGroup.getUuid()); } @Test @@ -320,7 +320,7 @@ public class MemberUpdaterTest { underTest.removeMember(db.getSession(), organization, user); - assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId())).isEmpty(); + assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), user.getId())).isEmpty(); } @Test diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java index 6bf13f57a97..fc830f021a4 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java @@ -61,7 +61,7 @@ public class OrganisationSupportTest { private OrganizationFlags organizationFlags = new OrganizationFlagsImpl(dbTester.getDbClient()); private RuleIndexer ruleIndexer = spy(new RuleIndexer(es.client(), dbTester.getDbClient())); private OrganisationSupport underTest = new OrganisationSupport(dbTester.getDbClient(), defaultOrganizationProvider, organizationFlags, - new DefaultGroupCreatorImpl(dbTester.getDbClient()), new DefaultGroupFinder(dbTester.getDbClient()), ruleIndexer, new SequenceUuidFactory()); + new DefaultGroupCreatorImpl(dbTester.getDbClient(), new SequenceUuidFactory()), new DefaultGroupFinder(dbTester.getDbClient()), ruleIndexer, new SequenceUuidFactory()); @Test public void enabling_support_saves_internal_property_and_flags_caller_as_root() { @@ -93,14 +93,14 @@ public class OrganisationSupportTest { call(user1.getLogin()); - Optional<Integer> defaultGroupId = dbTester.getDbClient().organizationDao().getDefaultGroupId(dbTester.getSession(), defaultOrganization.getUuid()); - assertThat(defaultGroupId).isPresent(); - GroupDto membersGroup = dbTester.getDbClient().groupDao().selectById(dbTester.getSession(), defaultGroupId.get()); + Optional<String> defaultGroupUuid = dbTester.getDbClient().organizationDao().getDefaultGroupUuid(dbTester.getSession(), defaultOrganization.getUuid()); + assertThat(defaultGroupUuid).isPresent(); + GroupDto membersGroup = dbTester.getDbClient().groupDao().selectByUuid(dbTester.getSession(), defaultGroupUuid.get()); assertThat(membersGroup).isNotNull(); assertThat(membersGroup.getName()).isEqualTo("Members"); - assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user1.getId())).containsOnly(defaultGroupId.get()); - assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user2.getId())).containsOnly(defaultGroupId.get()); - assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), userInAnotherOrganization.getId())).isEmpty(); + assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user1.getId())).containsOnly(defaultGroupUuid.get()); + assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user2.getId())).containsOnly(defaultGroupUuid.get()); + assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), userInAnotherOrganization.getId())).isEmpty(); } @Test @@ -117,10 +117,10 @@ public class OrganisationSupportTest { call(user.getLogin()); - int defaultGroupId = dbTester.getDbClient().organizationDao().getDefaultGroupId(dbTester.getSession(), defaultOrganization.getUuid()).get(); - assertThat(defaultGroupId).isNotEqualTo(sonarUsersGroup.getId()); + String defaultGroupUuid = dbTester.getDbClient().organizationDao().getDefaultGroupUuid(dbTester.getSession(), defaultOrganization.getUuid()).get(); + assertThat(defaultGroupUuid).isNotEqualTo(sonarUsersGroup.getUuid()); List<GroupPermissionDto> result = new ArrayList<>(); - dbTester.getDbClient().groupPermissionDao().selectAllPermissionsByGroupId(dbTester.getSession(), defaultOrganization.getUuid(), defaultGroupId, + dbTester.getDbClient().groupPermissionDao().selectAllPermissionsByGroupUuid(dbTester.getSession(), defaultOrganization.getUuid(), defaultGroupUuid, context -> result.add((GroupPermissionDto) context.getResultObject())); assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly( tuple(null, "user"), tuple(project.uuid(), "codeviewer")); @@ -140,10 +140,10 @@ public class OrganisationSupportTest { call(user.getLogin()); - int defaultGroupId = dbTester.getDbClient().organizationDao().getDefaultGroupId(dbTester.getSession(), defaultOrganization.getUuid()).get(); - assertThat(dbTester.getDbClient().permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupId(dbTester.getSession(), defaultGroupId)) - .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission) - .containsOnly(tuple(defaultGroupId, "user"), tuple(defaultGroupId, "admin")); + String defaultGroupUuid = dbTester.getDbClient().organizationDao().getDefaultGroupUuid(dbTester.getSession(), defaultOrganization.getUuid()).get(); + assertThat(dbTester.getDbClient().permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupUuid(dbTester.getSession(), defaultGroupUuid)) + .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission) + .containsOnly(tuple(defaultGroupUuid, "user"), tuple(defaultGroupUuid, "admin")); } @Test diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java index bcf48f97ca8..e6523acd80b 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java @@ -104,7 +104,7 @@ public class OrganizationUpdaterImplTest { private OrganizationValidation organizationValidation = mock(OrganizationValidation.class); private UserIndexer userIndexer = new UserIndexer(dbClient, es.client()); private UserIndex userIndex = new UserIndex(es.client(), system2); - private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient); + private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient, uuidFactory); private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT); private PermissionService permissionService = new PermissionServiceImpl(resourceTypes); @@ -183,7 +183,7 @@ public class OrganizationUpdaterImplTest { OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, FULL_POPULATED_NEW_ORGANIZATION.getKey()).get(); GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get(); - int defaultGroupId = dbClient.organizationDao().getDefaultGroupId(dbSession, organization.getUuid()).get(); + String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organization.getUuid()).get(); PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template"); assertThat(defaultTemplate.getName()).isEqualTo("Default template"); assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization " + FULL_POPULATED_NEW_ORGANIZATION.getName()); @@ -191,14 +191,14 @@ public class OrganizationUpdaterImplTest { assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid()); assertThat(defaultTemplates.getApplicationsUuid()).isNull(); assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateUuid(dbSession, defaultTemplate.getUuid())) - .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission) + .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission) .containsOnly( - tuple(ownersGroup.getId(), UserRole.ADMIN), - tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), - tuple(defaultGroupId, UserRole.USER), - tuple(defaultGroupId, UserRole.CODEVIEWER), - tuple(defaultGroupId, UserRole.ISSUE_ADMIN), - tuple(defaultGroupId, UserRole.SECURITYHOTSPOT_ADMIN)); + tuple(ownersGroup.getUuid(), UserRole.ADMIN), + tuple(ownersGroup.getUuid(), GlobalPermissions.SCAN_EXECUTION), + tuple(defaultGroupUuid, UserRole.USER), + tuple(defaultGroupUuid, UserRole.CODEVIEWER), + tuple(defaultGroupUuid, UserRole.ISSUE_ADMIN), + tuple(defaultGroupUuid, UserRole.SECURITYHOTSPOT_ADMIN)); } @Test @@ -378,13 +378,13 @@ public class OrganizationUpdaterImplTest { GroupDto groupDto = groupOpt.get(); assertThat(groupDto.getDescription()).isEqualTo("Owners of organization"); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())) + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getUuid())) .containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()])); List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers( dbSession, UserMembershipQuery.builder() .organizationUuid(organization.getUuid()) - .groupId(groupDto.getId()) + .groupUuid(groupDto.getUuid()) .membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE); assertThat(members) @@ -399,12 +399,12 @@ public class OrganizationUpdaterImplTest { GroupDto groupDto = groupOpt.get(); assertThat(groupDto.getDescription()).isEqualTo("All members of the organization"); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).isEmpty(); + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getUuid())).isEmpty(); List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers( dbSession, UserMembershipQuery.builder() .organizationUuid(organization.getUuid()) - .groupId(groupDto.getId()) + .groupUuid(groupDto.getUuid()) .membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE); assertThat(members) diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupIdOrAnyoneTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupUuidOrAnyoneTest.java index 73612c5ec78..7024a9b3416 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupIdOrAnyoneTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupUuidOrAnyoneTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.permission; -import java.util.Random; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -28,7 +27,7 @@ import org.sonar.db.user.GroupDto; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; -public class GroupIdOrAnyoneTest { +public class GroupUuidOrAnyoneTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -38,7 +37,7 @@ public class GroupIdOrAnyoneTest { expectOrganizationUuidNPE(); - GroupIdOrAnyone.from(dto); + GroupUuidOrAnyone.from(dto); } @Test @@ -47,44 +46,44 @@ public class GroupIdOrAnyoneTest { GroupDto dto = new GroupDto(); dto.setOrganizationUuid(organizationUuid); - GroupIdOrAnyone underTest = GroupIdOrAnyone.from(dto); + GroupUuidOrAnyone underTest = GroupUuidOrAnyone.from(dto); assertThat(underTest.getOrganizationUuid()).isEqualTo(organizationUuid); assertThat(underTest.isAnyone()).isTrue(); - assertThat(underTest.getId()).isNull(); + assertThat(underTest.getUuid()).isNull(); } @Test public void for_returns_isAnyone_false_if_id_is_not_null() { - int id = new Random().nextInt(199); + String uuid = randomAlphabetic(10); String organizationUuid = randomAlphabetic(10); GroupDto dto = new GroupDto(); dto.setOrganizationUuid(organizationUuid); - dto.setId(id); + dto.setUuid(uuid); - GroupIdOrAnyone underTest = GroupIdOrAnyone.from(dto); + GroupUuidOrAnyone underTest = GroupUuidOrAnyone.from(dto); assertThat(underTest.getOrganizationUuid()).isEqualTo(organizationUuid); assertThat(underTest.isAnyone()).isFalse(); - assertThat(underTest.getId()).isEqualTo(id); + assertThat(underTest.getUuid()).isEqualTo(uuid); } @Test public void forAnyone_fails_with_NPE_if_arg_is_null() { expectOrganizationUuidNPE(); - GroupIdOrAnyone.forAnyone(null); + GroupUuidOrAnyone.forAnyone(null); } @Test public void forAnyone_returns_isAnyone_true() { String organizationUuid = randomAlphabetic(12); - GroupIdOrAnyone underTest = GroupIdOrAnyone.forAnyone(organizationUuid); + GroupUuidOrAnyone underTest = GroupUuidOrAnyone.forAnyone(organizationUuid); assertThat(underTest.isAnyone()).isTrue(); assertThat(underTest.getOrganizationUuid()).isEqualTo(organizationUuid); - assertThat(underTest.getId()).isNull(); + assertThat(underTest.getUuid()).isNull(); } private void expectOrganizationUuidNPE() { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java index 86bd343e21b..0eeb5feeddb 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java @@ -33,7 +33,7 @@ public class MockUserSessionTest { assertThat(mock.getLogin()).isEqualTo("foo"); assertThat(mock.getUuid()).isEqualTo("foouuid"); - assertThat(mock.getGroups()).extracting(GroupDto::getId).containsOnly(group.getId()); + assertThat(mock.getGroups()).extracting(GroupDto::getUuid).containsOnly(group.getUuid()); assertThat(mock.isLoggedIn()).isTrue(); } } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java index e1ccb4343d4..469a34ba93e 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java @@ -85,7 +85,7 @@ public class ServerUserSessionTest { db.users().insertMember(group1, user); db.users().insertMember(group2, user); - assertThat(newUserSession(user).getGroups()).extracting(GroupDto::getId).containsOnly(group1.getId(), group2.getId()); + assertThat(newUserSession(user).getGroups()).extracting(GroupDto::getUuid).containsOnly(group1.getUuid(), group2.getUuid()); } @Test @@ -96,11 +96,11 @@ public class ServerUserSessionTest { db.users().insertMember(group1, user); ServerUserSession session = newUserSession(user); - assertThat(session.getGroups()).extracting(GroupDto::getId).containsOnly(group1.getId()); + assertThat(session.getGroups()).extracting(GroupDto::getUuid).containsOnly(group1.getUuid()); // membership updated but not cache db.users().insertMember(group2, user); - assertThat(session.getGroups()).extracting(GroupDto::getId).containsOnly(group1.getId()); + assertThat(session.getGroups()).extracting(GroupDto::getUuid).containsOnly(group1.getUuid()); } @Test diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java index d76f44355cd..682a12a9844 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java @@ -66,7 +66,7 @@ public class ThreadLocalUserSessionTest { assertThat(threadLocalUserSession.getLogin()).isEqualTo("karadoc"); assertThat(threadLocalUserSession.getUuid()).isEqualTo("karadoc-uuid"); assertThat(threadLocalUserSession.isLoggedIn()).isTrue(); - assertThat(threadLocalUserSession.getGroups()).extracting(GroupDto::getId).containsOnly(group.getId()); + assertThat(threadLocalUserSession.getGroups()).extracting(GroupDto::getUuid).containsOnly(group.getUuid()); } @Test diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java index 330d99933c5..ef10c608f89 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java @@ -23,6 +23,7 @@ import java.util.Optional; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.sonar.core.util.SequenceUuidFactory; import org.sonar.db.DbTester; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.template.PermissionTemplateDto; @@ -38,7 +39,7 @@ public class DefaultGroupCreatorImplTest { @Rule public DbTester db = DbTester.create(); - private DefaultGroupCreator underTest = new DefaultGroupCreatorImpl(db.getDbClient()); + private DefaultGroupCreator underTest = new DefaultGroupCreatorImpl(db.getDbClient(), new SequenceUuidFactory()); @Test public void create_default_group() { @@ -46,9 +47,9 @@ public class DefaultGroupCreatorImplTest { underTest.create(db.getSession(), organizationDto.getUuid()); - Optional<Integer> defaultGroupId = db.getDbClient().organizationDao().getDefaultGroupId(db.getSession(), organizationDto.getUuid()); - assertThat(defaultGroupId).isPresent(); - assertThat(db.getDbClient().groupDao().selectById(db.getSession(), defaultGroupId.get())) + Optional<String> defaultGroupUuid = db.getDbClient().organizationDao().getDefaultGroupUuid(db.getSession(), organizationDto.getUuid()); + assertThat(defaultGroupUuid).isPresent(); + assertThat(db.getDbClient().groupDao().selectByUuid(db.getSession(), defaultGroupUuid.get())) .extracting(GroupDto::getName, GroupDto::getDescription) .containsOnly("Members", "All members of the organization"); } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java index cbdf4e94187..0953963ae3c 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java @@ -46,7 +46,7 @@ public class DefaultGroupFinderTest { GroupDto result = underTest.findDefaultGroup(db.getSession(), organization.getUuid()); - assertThat(result.getId()).isEqualTo(defaultGroup.getId()); + assertThat(result.getUuid()).isEqualTo(defaultGroup.getUuid()); assertThat(result.getName()).isEqualTo("default"); } @@ -65,10 +65,10 @@ public class DefaultGroupFinderTest { public void fail_with_NPE_when_default_group_does_not_exist() { OrganizationDto organization = db.organizations().insert(); GroupDto defaultGroup = db.users().insertDefaultGroup(organization, "default"); - db.getDbClient().groupDao().deleteById(db.getSession(), defaultGroup.getId()); + db.getDbClient().groupDao().deleteByUuid(db.getSession(), defaultGroup.getUuid()); expectedException.expect(NullPointerException.class); - expectedException.expectMessage(format("Group '%s' cannot be found", defaultGroup.getId())); + expectedException.expectMessage(format("Group '%s' cannot be found", defaultGroup.getUuid())); underTest.findDefaultGroup(db.getSession(), organization.getUuid()); } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java index 9ab85eaddd3..dbaaff2b528 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java @@ -110,10 +110,10 @@ public class RegisterPermissionTemplates implements Startable { private void insertPermissionsForDefaultGroup(DbSession dbSession, PermissionTemplateDto template) { String organizationUuid = template.getOrganizationUuid(); - Integer defaultGroupId = dbClient.organizationDao().getDefaultGroupId(dbSession, organizationUuid) + String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organizationUuid) .orElseThrow(() -> new IllegalStateException(format("Default group for organization %s is not defined", organizationUuid))); - GroupDto defaultGroup = Optional.ofNullable(dbClient.groupDao().selectById(dbSession, defaultGroupId)) - .orElseThrow(() -> new IllegalStateException(format("Default group with id %s for organization %s doesn't exist", defaultGroupId, organizationUuid))); + GroupDto defaultGroup = Optional.ofNullable(dbClient.groupDao().selectByUuid(dbSession, defaultGroupUuid)) + .orElseThrow(() -> new IllegalStateException(format("Default group with id %s for organization %s doesn't exist", defaultGroupUuid, organizationUuid))); insertGroupPermission(dbSession, template, UserRole.USER, defaultGroup); insertGroupPermission(dbSession, template, UserRole.CODEVIEWER, defaultGroup); insertGroupPermission(dbSession, template, UserRole.ISSUE_ADMIN, defaultGroup); @@ -121,7 +121,7 @@ public class RegisterPermissionTemplates implements Startable { } private void insertGroupPermission(DbSession dbSession, PermissionTemplateDto template, String permission, GroupDto group) { - dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getId(), permission); + dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java index 8102ecbd99c..4c52c91961f 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java @@ -71,7 +71,7 @@ public class RegisterPermissionTemplatesTest { @Test public void fail_with_ISE_if_default_template_must_be_created_and_default_group_does_not_exist() { - setDefaultGroupId(new GroupDto().setId(22)); + setDefaultGroupId(new GroupDto().setUuid("22")); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Default group with id 22 for organization " + db.getDefaultOrganization().getUuid() + " doesn't exist"); @@ -200,7 +200,7 @@ public class RegisterPermissionTemplatesTest { } private void setDefaultGroupId(GroupDto defaultGroup) { - db.getDbClient().organizationDao().setDefaultGroupId(db.getSession(), db.getDefaultOrganization().getUuid(), defaultGroup); + db.getDbClient().organizationDao().setDefaultGroupUuid(db.getSession(), db.getDefaultOrganization().getUuid(), defaultGroup); db.commit(); } diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java index c695f67ddbe..2ca7818d3ff 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java @@ -48,7 +48,7 @@ public class PermissionIndexerDao { " project_authorization.kind as kind, " + " project_authorization.project as project, " + " project_authorization.user_id as user_id, " + - " project_authorization.group_id as group_id, " + + " project_authorization.group_uuid as group_uuid, " + " project_authorization.qualifier as qualifier " + "FROM ( " + @@ -58,7 +58,7 @@ public class PermissionIndexerDao { " c.uuid AS project, " + " c.qualifier AS qualifier, " + " user_roles.user_id AS user_id, " + - " NULL AS group_id " + + " NULL AS group_uuid " + " FROM components c " + " INNER JOIN user_roles ON user_roles.component_uuid = c.uuid AND user_roles.role = 'user' " + " WHERE " + @@ -75,17 +75,17 @@ public class PermissionIndexerDao { " c.uuid AS project, " + " c.qualifier AS qualifier, " + " NULL AS user_id, " + - " groups.id AS group_id " + + " groups.uuid AS group_uuid " + " FROM components c " + " INNER JOIN group_roles ON group_roles.component_uuid = c.uuid AND group_roles.role = 'user' " + - " INNER JOIN groups ON groups.id = group_roles.group_id " + + " INNER JOIN groups ON groups.uuid = group_roles.group_uuid " + " WHERE " + " (c.qualifier = 'TRK' " + " or c.qualifier = 'VW' " + " or c.qualifier = 'APP') " + " AND c.copy_component_uuid is NULL " + " {projectsCondition} " + - " AND group_id IS NOT NULL " + + " AND group_uuid IS NOT NULL " + " UNION " + // public projects are accessible to any one @@ -94,7 +94,7 @@ public class PermissionIndexerDao { " c.uuid AS project, " + " c.qualifier AS qualifier, " + " NULL AS user_id, " + - " NULL AS group_id " + + " NULL AS group_uuid " + " FROM components c " + " WHERE " + " (c.qualifier = 'TRK' " + @@ -110,7 +110,7 @@ public class PermissionIndexerDao { " c.uuid AS project, " + " c.qualifier AS qualifier, " + " NULL AS user_id, " + - " NULL AS group_id " + + " NULL AS group_uuid " + " FROM components c " + " WHERE " + " (c.qualifier = 'TRK' " + @@ -200,7 +200,7 @@ public class PermissionIndexerDao { dto.addUserId(rs.getInt(3)); break; case GROUP: - dto.addGroupId(rs.getInt(4)); + dto.addGroupUuid(rs.getString(4)); break; case ANYONE: dto.allowAnyone(); diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/WebAuthorizationTypeSupport.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/WebAuthorizationTypeSupport.java index 102c5f10c0e..c7c9adc43a9 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/WebAuthorizationTypeSupport.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/WebAuthorizationTypeSupport.java @@ -67,8 +67,8 @@ public class WebAuthorizationTypeSupport { // groups userSession.getGroups() .stream() - .map(GroupDto::getId) - .forEach(groupId -> filter.should(termQuery(FIELD_GROUP_IDS, groupId))); + .map(GroupDto::getUuid) + .forEach(groupUuid -> filter.should(termQuery(FIELD_GROUP_IDS, groupUuid))); return JoinQueryBuilders.hasParentQuery( TYPE_AUTHORIZATION, diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java index 90887064a9d..e14865bfd14 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java @@ -1677,7 +1677,7 @@ public class ProjectMeasuresIndexTest { private void indexForGroup(GroupDto group, ProjectMeasuresDoc... docs) { es.putDocuments(TYPE_PROJECT_MEASURES, docs); - authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addGroupId(group.getId())).collect(toList())); + authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addGroupUuid(group.getUuid())).collect(toList())); } private static ProjectMeasuresDoc newDoc(ComponentDto project) { diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java index a49e768da49..fb9eb32b389 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java @@ -107,13 +107,13 @@ public class PermissionIndexerDaoTest { isPublic(applicationAuthorization, APP); IndexPermissions privateProject1Authorization = getByProjectUuid(privateProject1.uuid(), dtos); - assertThat(privateProject1Authorization.getGroupIds()).containsOnly(group.getId()); + assertThat(privateProject1Authorization.getGroupUuids()).containsOnly(group.getUuid()); assertThat(privateProject1Authorization.isAllowAnyone()).isFalse(); assertThat(privateProject1Authorization.getUserIds()).containsOnly(user1.getId(), user2.getId()); assertThat(privateProject1Authorization.getQualifier()).isEqualTo(PROJECT); IndexPermissions privateProject2Authorization = getByProjectUuid(privateProject2.uuid(), dtos); - assertThat(privateProject2Authorization.getGroupIds()).isEmpty(); + assertThat(privateProject2Authorization.getGroupUuids()).isEmpty(); assertThat(privateProject2Authorization.isAllowAnyone()).isFalse(); assertThat(privateProject2Authorization.getUserIds()).containsOnly(user1.getId()); assertThat(privateProject2Authorization.getQualifier()).isEqualTo(PROJECT); @@ -142,13 +142,13 @@ public class PermissionIndexerDaoTest { isPublic(applicationAuthorization, APP); IndexPermissions privateProject1Authorization = dtos.get(privateProject1.uuid()); - assertThat(privateProject1Authorization.getGroupIds()).containsOnly(group.getId()); + assertThat(privateProject1Authorization.getGroupUuids()).containsOnly(group.getUuid()); assertThat(privateProject1Authorization.isAllowAnyone()).isFalse(); assertThat(privateProject1Authorization.getUserIds()).containsOnly(user1.getId(), user2.getId()); assertThat(privateProject1Authorization.getQualifier()).isEqualTo(PROJECT); IndexPermissions privateProject2Authorization = dtos.get(privateProject2.uuid()); - assertThat(privateProject2Authorization.getGroupIds()).isEmpty(); + assertThat(privateProject2Authorization.getGroupUuids()).isEmpty(); assertThat(privateProject2Authorization.isAllowAnyone()).isFalse(); assertThat(privateProject2Authorization.getUserIds()).containsOnly(user1.getId()); assertThat(privateProject2Authorization.getQualifier()).isEqualTo(PROJECT); @@ -175,7 +175,7 @@ public class PermissionIndexerDaoTest { GroupPermissionDto dto = new GroupPermissionDto() .setUuid(Uuids.createFast()) .setOrganizationUuid(group.getOrganizationUuid()) - .setGroupId(group.getId()) + .setGroupUuid(group.getUuid()) .setRole(USER) .setComponentUuid(project.uuid()); dbClient.groupPermissionDao().insert(dbSession, dto); @@ -195,7 +195,7 @@ public class PermissionIndexerDaoTest { // no permissions Assertions.assertThat(dtos).hasSize(1); IndexPermissions dto = dtos.get(0); - assertThat(dto.getGroupIds()).isEmpty(); + assertThat(dto.getGroupUuids()).isEmpty(); assertThat(dto.getUserIds()).isEmpty(); assertThat(dto.isAllowAnyone()).isFalse(); assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); @@ -208,7 +208,7 @@ public class PermissionIndexerDaoTest { Assertions.assertThat(dtos).hasSize(1); IndexPermissions dto = dtos.get(0); - assertThat(dto.getGroupIds()).isEmpty(); + assertThat(dto.getGroupUuids()).isEmpty(); assertThat(dto.getUserIds()).isEmpty(); assertThat(dto.isAllowAnyone()).isTrue(); assertThat(dto.getProjectUuid()).isEqualTo(publicProject.uuid()); @@ -222,7 +222,7 @@ public class PermissionIndexerDaoTest { Assertions.assertThat(dtos).hasSize(1); IndexPermissions dto = dtos.get(0); - assertThat(dto.getGroupIds()).isEmpty(); + assertThat(dto.getGroupUuids()).isEmpty(); assertThat(dto.getUserIds()).containsOnly(user1.getId()); assertThat(dto.isAllowAnyone()).isFalse(); assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); @@ -237,7 +237,7 @@ public class PermissionIndexerDaoTest { Assertions.assertThat(dtos).hasSize(1); IndexPermissions dto = dtos.get(0); - assertThat(dto.getGroupIds()).containsOnly(group.getId()); + assertThat(dto.getGroupUuids()).containsOnly(group.getUuid()); assertThat(dto.getUserIds()).isEmpty(); assertThat(dto.isAllowAnyone()).isFalse(); assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); @@ -245,7 +245,7 @@ public class PermissionIndexerDaoTest { } private void isPublic(IndexPermissions view1Authorization, String qualifier) { - assertThat(view1Authorization.getGroupIds()).isEmpty(); + assertThat(view1Authorization.getGroupUuids()).isEmpty(); assertThat(view1Authorization.isAllowAnyone()).isTrue(); assertThat(view1Authorization.getUserIds()).isEmpty(); assertThat(view1Authorization.getQualifier()).isEqualTo(qualifier); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/WebAuthorizationTypeSupportTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/WebAuthorizationTypeSupportTest.java index 11c4a2507a8..6814a3e0e79 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/WebAuthorizationTypeSupportTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/WebAuthorizationTypeSupportTest.java @@ -108,8 +108,8 @@ public class WebAuthorizationTypeSupportTest { @Test public void createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups() { - GroupDto group1 = GroupTesting.newGroupDto().setId(10); - GroupDto group2 = GroupTesting.newGroupDto().setId(11); + GroupDto group1 = GroupTesting.newGroupDto().setUuid("10"); + GroupDto group2 = GroupTesting.newGroupDto().setUuid("11"); userSession.logIn().setUserId(1234).setGroups(group1, group2); HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter(); @@ -133,12 +133,12 @@ public class WebAuthorizationTypeSupportTest { " }," + " {" + " \"term\": {" + - " \"auth_groupIds\": {\"value\": 10}" + + " \"auth_groupIds\": {\"value\": \"10\"}" + " }" + " }," + " {" + " \"term\": {" + - " \"auth_groupIds\": {\"value\": 11}" + + " \"auth_groupIds\": {\"value\": \"11\"}" + " }" + " }" + " ]" + diff --git a/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java b/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java index 6043b24d3d6..e6d14ec137a 100644 --- a/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java +++ b/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java @@ -50,7 +50,7 @@ public class PermissionIndexerTester { public PermissionIndexerTester allowOnlyGroup(ComponentDto project, GroupDto group) { IndexPermissions dto = new IndexPermissions(project.uuid(), project.qualifier()) - .addGroupId(group.getId()); + .addGroupUuid(group.getUuid()); return allow(dto); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java index 59baccc69ae..ef1e94e77e9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java @@ -23,15 +23,15 @@ import javax.annotation.Nullable; public class GroupPermissionChange extends PermissionChange { - private final GroupIdOrAnyone groupId; + private final GroupUuidOrAnyone groupId; public GroupPermissionChange(Operation operation, String permission, @Nullable ProjectUuid projectUuid, - GroupIdOrAnyone groupId, PermissionService permissionService) { + GroupUuidOrAnyone groupId, PermissionService permissionService) { super(operation, groupId.getOrganizationUuid(), permission, projectUuid, permissionService); this.groupId = groupId; } - public GroupIdOrAnyone getGroupIdOrAnyone() { + public GroupUuidOrAnyone getGroupIdOrAnyone() { return groupId; } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java index 65f0d401556..90049daf441 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java @@ -115,13 +115,13 @@ public class GroupPermissionChanger { .setUuid(uuidFactory.create()) .setRole(change.getPermission()) .setOrganizationUuid(change.getOrganizationUuid()) - .setGroupId(change.getGroupIdOrAnyone().getId()) + .setGroupUuid(change.getGroupIdOrAnyone().getUuid()) .setComponentUuid(change.getProjectUuid()); dbClient.groupPermissionDao().insert(dbSession, addedDto); return true; } - private static void validateNotAnyoneAndAdminPermission(String permission, GroupIdOrAnyone group) { + private static void validateNotAnyoneAndAdminPermission(String permission, GroupUuidOrAnyone group) { checkRequest(!GlobalPermissions.SYSTEM_ADMIN.equals(permission) || !group.isAnyone(), format("It is not possible to add the '%s' permission to group 'Anyone'.", permission)); } @@ -134,7 +134,7 @@ public class GroupPermissionChanger { dbClient.groupPermissionDao().delete(dbSession, change.getPermission(), change.getOrganizationUuid(), - change.getGroupIdOrAnyone().getId(), + change.getGroupIdOrAnyone().getUuid(), change.getProjectUuid()); return true; } @@ -144,12 +144,12 @@ public class GroupPermissionChanger { if (projectUuid != null) { return dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, change.getOrganizationUuid(), - change.getGroupIdOrAnyone().getId(), + change.getGroupIdOrAnyone().getUuid(), projectUuid); } return dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, change.getOrganizationUuid(), - change.getGroupIdOrAnyone().getId()); + change.getGroupIdOrAnyone().getUuid()); } private void checkIfRemainingGlobalAdministrators(DbSession dbSession, GroupPermissionChange change) { @@ -158,7 +158,7 @@ public class GroupPermissionChanger { change.getProjectUuid() == null) { // removing global admin permission from group int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingGroup(dbSession, - change.getOrganizationUuid(), SYSTEM_ADMIN, change.getGroupIdOrAnyone().getId()); + change.getOrganizationUuid(), SYSTEM_ADMIN, change.getGroupIdOrAnyone().getUuid()); checkRequest(remaining > 0, "Last group with permission '%s'. Permission cannot be removed.", SYSTEM_ADMIN); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index 577173115e7..e34c5a3343b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -146,7 +146,7 @@ public class PermissionTemplateService { GroupPermissionDto dto = new GroupPermissionDto() .setUuid(uuidFactory.create()) .setOrganizationUuid(organizationUuid) - .setGroupId(isAnyone(gp.getGroupName()) ? null : gp.getGroupId()) + .setGroupUuid(isAnyone(gp.getGroupName()) ? null : gp.getGroupUuid()) .setRole(gp.getPermission()) .setComponentUuid(project.uuid()); dbClient.groupPermissionDao().insert(dbSession, dto); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java index f2213faaa7a..a34f2cb3647 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java @@ -26,7 +26,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuidOrAnyone; import org.sonar.server.permission.GroupPermissionChange; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionService; @@ -87,7 +87,7 @@ public class AddGroupAction implements PermissionsWsAction { @Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { - GroupIdOrAnyone group = wsSupport.findGroup(dbSession, request); + GroupUuidOrAnyone group = wsSupport.findGroup(dbSession, request); Optional<ProjectUuid> projectUuid = wsSupport.findProjectUuid(dbSession, request); checkProjectAdmin(userSession, group.getOrganizationUuid(), projectUuid); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java index b6b8eeff9dd..94f5abb1150 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java @@ -128,18 +128,18 @@ public class GroupsAction implements PermissionsWsAction { } private static WsGroupsResponse buildResponse(List<GroupDto> groups, List<GroupPermissionDto> groupPermissions, Paging paging) { - Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); - groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getRole())); + Multimap<String, String> permissionsByGroupUuid = TreeMultimap.create(); + groupPermissions.forEach(groupPermission -> permissionsByGroupUuid.put(groupPermission.getGroupUuid(), groupPermission.getRole())); WsGroupsResponse.Builder response = WsGroupsResponse.newBuilder(); groups.forEach(group -> { Group.Builder wsGroup = response.addGroupsBuilder() .setName(group.getName()); - if (group.getId() != 0) { - wsGroup.setId(String.valueOf(group.getId())); + if (group.getUuid() != null) { + wsGroup.setId(String.valueOf(group.getUuid())); } ofNullable(group.getDescription()).ifPresent(wsGroup::setDescription); - wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); + wsGroup.addAllPermissions(permissionsByGroupUuid.get(group.getUuid())); }); response.getPagingBuilder() @@ -154,7 +154,7 @@ public class GroupsAction implements PermissionsWsAction { List<String> orderedNames = dbClient.groupPermissionDao().selectGroupNamesByQuery(dbSession, dbQuery); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, org.getUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { - groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); + groups.add(0, new GroupDto().setUuid(DefaultGroups.ANYONE).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); } @@ -163,7 +163,7 @@ public class GroupsAction implements PermissionsWsAction { if (groups.isEmpty()) { return emptyList(); } - List<Integer> ids = groups.stream().map(GroupDto::getId).collect(MoreCollectors.toList(groups.size())); - return dbClient.groupPermissionDao().selectByGroupIds(dbSession, org.getUuid(), ids, project.map(ProjectUuid::getUuid).orElse(null)); + List<String> uuids = groups.stream().map(GroupDto::getUuid).collect(MoreCollectors.toList(groups.size())); + return dbClient.groupPermissionDao().selectByGroupUuids(dbSession, org.getUuid(), uuids, project.map(ProjectUuid::getUuid).orElse(null)); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index 721e4f9dc45..b4c1130de8d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -29,7 +29,7 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuidOrAnyone; import org.sonar.server.permission.ProjectUuid; import org.sonar.server.permission.UserId; import org.sonar.server.permission.ws.template.WsTemplateRef; @@ -78,11 +78,11 @@ public class PermissionWsSupport { return componentFinder.getRootComponentByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key()); } - public GroupIdOrAnyone findGroup(DbSession dbSession, Request request) { - Integer groupId = request.paramAsInt(PARAM_GROUP_ID); + public GroupUuidOrAnyone findGroup(DbSession dbSession, Request request) { + String groupUuid = request.param(PARAM_GROUP_ID); String orgKey = request.param(PARAM_ORGANIZATION); String groupName = request.param(PARAM_GROUP_NAME); - GroupWsRef groupRef = GroupWsRef.create(groupId, orgKey, groupName); + GroupWsRef groupRef = GroupWsRef.create(groupUuid, orgKey, groupName); return groupWsSupport.findGroupOrAnyone(dbSession, groupRef); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java index abc7a494723..94518082ae9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuidOrAnyone; import org.sonar.server.permission.GroupPermissionChange; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionService; @@ -87,7 +87,7 @@ public class RemoveGroupAction implements PermissionsWsAction { @Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { - GroupIdOrAnyone group = wsSupport.findGroup(dbSession, request); + GroupUuidOrAnyone group = wsSupport.findGroup(dbSession, request); Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request); checkProjectAdmin(userSession, group.getOrganizationUuid(), project); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java index 6680a866d02..e26bd27d765 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.template.PermissionTemplateDto; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuidOrAnyone; import org.sonar.server.permission.ws.PermissionWsSupport; import org.sonar.server.permission.ws.PermissionsWsAction; import org.sonar.server.permission.ws.WsParameters; @@ -75,7 +75,7 @@ public class AddGroupToTemplateAction implements PermissionsWsAction { public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { String permission = request.mandatoryParam(PARAM_PERMISSION); - GroupIdOrAnyone groupId = support.findGroup(dbSession, request); + GroupUuidOrAnyone groupId = support.findGroup(dbSession, request); checkRequest(!SYSTEM_ADMIN.equals(permission) || !groupId.isAnyone(), format("It is not possible to add the '%s' permission to the group 'Anyone'.", permission)); @@ -83,14 +83,14 @@ public class AddGroupToTemplateAction implements PermissionsWsAction { checkGlobalAdmin(userSession, template.getOrganizationUuid()); if (!groupAlreadyAdded(dbSession, template.getUuid(), permission, groupId)) { - dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), groupId.getId(), permission); + dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), groupId.getUuid(), permission); dbSession.commit(); } } response.noContent(); } - private boolean groupAlreadyAdded(DbSession dbSession, String templateUuid, String permission, GroupIdOrAnyone group) { - return dbClient.permissionTemplateDao().hasGroupsWithPermission(dbSession, templateUuid, permission, group.getId()); + private boolean groupAlreadyAdded(DbSession dbSession, String templateUuid, String permission, GroupUuidOrAnyone group) { + return dbClient.permissionTemplateDao().hasGroupsWithPermission(dbSession, templateUuid, permission, group.getUuid()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java index af80d88a403..3c2de719d2d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.template.PermissionTemplateDto; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuidOrAnyone; import org.sonar.server.permission.ws.PermissionWsSupport; import org.sonar.server.permission.ws.PermissionsWsAction; import org.sonar.server.permission.ws.WsParameters; @@ -74,10 +74,10 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction { String permission = request.mandatoryParam(PARAM_PERMISSION); PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.fromRequest(request)); checkGlobalAdmin(userSession, template.getOrganizationUuid()); - GroupIdOrAnyone groupId = wsSupport.findGroup(dbSession, request); + GroupUuidOrAnyone groupId = wsSupport.findGroup(dbSession, request); checkArgument(groupId.getOrganizationUuid().equals(template.getOrganizationUuid()), "Group and template are on different organizations"); - dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), groupId.getId(), permission); + dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), groupId.getUuid(), permission); dbSession.commit(); } response.noContent(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java index eb6bc4db4c0..fe26fda9152 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java @@ -121,18 +121,18 @@ public class TemplateGroupsAction implements PermissionsWsAction { } private static Permissions.WsGroupsResponse buildResponse(List<GroupDto> groups, List<PermissionTemplateGroupDto> groupPermissions, Paging paging) { - Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); - groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getPermission())); + Multimap<String, String> permissionsByGroupUuid = TreeMultimap.create(); + groupPermissions.forEach(groupPermission -> permissionsByGroupUuid.put(groupPermission.getGroupUuid(), groupPermission.getPermission())); Permissions.WsGroupsResponse.Builder response = Permissions.WsGroupsResponse.newBuilder(); groups.forEach(group -> { Permissions.Group.Builder wsGroup = response.addGroupsBuilder() .setName(group.getName()); - if (group.getId() != 0) { - wsGroup.setId(String.valueOf(group.getId())); + if (group.getUuid() != null) { + wsGroup.setId(String.valueOf(group.getUuid())); } ofNullable(group.getDescription()).ifPresent(wsGroup::setDescription); - wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); + wsGroup.addAllPermissions(permissionsByGroupUuid.get(group.getUuid())); }); response.getPagingBuilder() @@ -146,7 +146,7 @@ public class TemplateGroupsAction implements PermissionsWsAction { List<String> orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getUuid()); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { - groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE)); + groups.add(0, new GroupDto().setUuid(DefaultGroups.ANYONE).setName(DefaultGroups.ANYONE)); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java index ef16e285491..77afd13dcc3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java @@ -141,10 +141,10 @@ public class UpdateVisibilityAction implements ProjectsWsAction { private void updatePermissionsToPrivate(DbSession dbSession, ComponentDto component) { // delete project permissions for group AnyOne - dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupId(dbSession, component.uuid(), null); + dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupUuid(dbSession, component.uuid(), null); // grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project PUBLIC_PERMISSIONS.forEach(permission -> { - dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) + dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) .forEach(groupId -> insertProjectPermissionOnGroup(dbSession, component, permission, groupId)); dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) .forEach(userId -> insertProjectPermissionOnUser(dbSession, component, permission, userId)); @@ -155,12 +155,12 @@ public class UpdateVisibilityAction implements ProjectsWsAction { dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), component.getOrganizationUuid(), permission, userId, component.uuid())); } - private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, Integer groupId) { + private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, String groupUuid) { dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto() .setUuid(uuidFactory.create()) .setOrganizationUuid(component.getOrganizationUuid()) .setComponentUuid(component.uuid()) - .setGroupId(groupId) + .setGroupUuid(groupUuid) .setRole(permission)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java index 0f20c7d5da4..07c4f3a469f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java @@ -108,7 +108,7 @@ public class AddGroupAction implements QProfileWsAction { dbClient.qProfileEditGroupsDao().insert(dbSession, new QProfileEditGroupsDto() .setUuid(uuidFactory.create()) - .setGroupId(group.getId()) + .setGroupUuid(group.getUuid()) .setQProfileUuid(profile.getKee())); dbSession.commit(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java index 2a44663ce35..8b5c3f1164b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java @@ -124,14 +124,14 @@ public class SearchGroupsAction implements QProfileWsAction { int total = dbClient.qProfileEditGroupsDao().countByQuery(dbSession, query); List<GroupMembershipDto> groupMemberships = dbClient.qProfileEditGroupsDao().selectByQuery(dbSession, query, forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize())); - Map<Integer, GroupDto> groupsById = dbClient.groupDao().selectByIds(dbSession, - groupMemberships.stream().map(GroupMembershipDto::getGroupId).collect(MoreCollectors.toList())) + Map<String, GroupDto> groupsByUuid = dbClient.groupDao().selectByUuids(dbSession, + groupMemberships.stream().map(GroupMembershipDto::getGroupUuid).collect(MoreCollectors.toList())) .stream() - .collect(MoreCollectors.uniqueIndex(GroupDto::getId)); + .collect(MoreCollectors.uniqueIndex(GroupDto::getUuid)); writeProtobuf( Qualityprofiles.SearchGroupsResponse.newBuilder() .addAllGroups(groupMemberships.stream() - .map(groupsMembership -> toGroup(groupsById.get(groupsMembership.getGroupId()), groupsMembership.isSelected())) + .map(groupsMembership -> toGroup(groupsByUuid.get(groupsMembership.getGroupUuid()), groupsMembership.isSelected())) .collect(toList())) .setPaging(buildPaging(wsRequest, total)).build(), request, response); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java index 6c31367514c..32eefecb39a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java @@ -172,10 +172,10 @@ public class GroupsAction implements UsersWsAction { private static Group toWsGroup(GroupMembershipDto group, GroupDto defaultGroup) { Group.Builder groupBuilder = Group.newBuilder() - .setId(group.getId()) + .setId(group.getUuid()) .setName(group.getName()) .setSelected(group.getUserId() != null) - .setDefault(defaultGroup.getId().longValue() == group.getId()); + .setDefault(defaultGroup.getUuid().equals(group.getUuid())); ofNullable(group.getDescription()).ifPresent(groupBuilder::setDescription); return groupBuilder.build(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java index b5028c67b46..3335565ebb1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java @@ -85,7 +85,7 @@ public class AddUserAction implements UserGroupsWsAction { support.checkGroupIsNotDefault(dbSession, group); if (!isMemberOf(dbSession, user, group)) { - UserGroupDto membershipDto = new UserGroupDto().setGroupId(group.getId()).setUserId(user.getId()); + UserGroupDto membershipDto = new UserGroupDto().setGroupUuid(group.getUuid()).setUserId(user.getId()); dbClient.userGroupDao().insert(dbSession, membershipDto); dbSession.commit(); } @@ -95,7 +95,7 @@ public class AddUserAction implements UserGroupsWsAction { } private boolean isMemberOf(DbSession dbSession, UserDto user, GroupDto groupId) { - return dbClient.groupMembershipDao().selectGroupIdsByUserId(dbSession, user.getId()).contains(groupId.getId()); + return dbClient.groupMembershipDao().selectGroupUuidsByUserId(dbSession, user.getId()).contains(groupId.getUuid()); } private void checkMembership(DbSession dbSession, OrganizationDto organization, UserDto user) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java index 9a900257b5f..29ffb885c39 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java @@ -24,6 +24,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService.NewAction; import org.sonar.api.server.ws.WebService.NewController; import org.sonar.api.user.UserGroupValidation; +import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.organization.OrganizationDto; @@ -46,11 +47,13 @@ public class CreateAction implements UserGroupsWsAction { private final DbClient dbClient; private final UserSession userSession; private final GroupWsSupport support; + private final UuidFactory uuidFactory; - public CreateAction(DbClient dbClient, UserSession userSession, GroupWsSupport support) { + public CreateAction(DbClient dbClient, UserSession userSession, GroupWsSupport support, UuidFactory uuidFactory) { this.dbClient = dbClient; this.userSession = userSession; this.support = support; + this.uuidFactory = uuidFactory; } @Override @@ -89,6 +92,7 @@ public class CreateAction implements UserGroupsWsAction { OrganizationDto organization = support.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY)); userSession.checkPermission(ADMINISTER, organization); GroupDto group = new GroupDto() + .setUuid(uuidFactory.create()) .setOrganizationUuid(organization.getUuid()) .setName(request.mandatoryParam(PARAM_GROUP_NAME)) .setDescription(request.param(PARAM_GROUP_DESCRIPTION)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java index 8e71735ee30..976a43162a4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java @@ -73,7 +73,7 @@ public class DeleteAction implements UserGroupsWsAction { removeFromPermissionTemplates(dbSession, group); removeGroupMembers(dbSession, group); dbClient.qProfileEditGroupsDao().deleteByGroup(dbSession, group); - dbClient.groupDao().deleteById(dbSession, group.getId()); + dbClient.groupDao().deleteByUuid(dbSession, group.getUuid()); dbSession.commit(); response.noContent(); @@ -82,20 +82,20 @@ public class DeleteAction implements UserGroupsWsAction { private void checkNotTryingToDeleteLastAdminGroup(DbSession dbSession, GroupDto group) { int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingGroup(dbSession, - group.getOrganizationUuid(), OrganizationPermission.ADMINISTER.getKey(), group.getId()); + group.getOrganizationUuid(), OrganizationPermission.ADMINISTER.getKey(), group.getUuid()); checkArgument(remaining > 0, "The last system admin group cannot be deleted"); } private void removeGroupPermissions(DbSession dbSession, GroupDto groupId) { - dbClient.roleDao().deleteGroupRolesByGroupId(dbSession, groupId.getId()); + dbClient.roleDao().deleteGroupRolesByGroupUuid(dbSession, groupId.getUuid()); } private void removeFromPermissionTemplates(DbSession dbSession, GroupDto groupId) { - dbClient.permissionTemplateDao().deleteByGroup(dbSession, groupId.getId()); + dbClient.permissionTemplateDao().deleteByGroup(dbSession, groupId.getUuid()); } private void removeGroupMembers(DbSession dbSession, GroupDto groupId) { - dbClient.userGroupDao().deleteByGroupId(dbSession, groupId.getId()); + dbClient.userGroupDao().deleteByGroupUuid(dbSession, groupId.getUuid()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java index b4cab056a4a..a2f38972852 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java @@ -19,14 +19,14 @@ */ package org.sonar.server.usergroups.ws; +import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import org.sonar.api.security.DefaultGroups; -import org.sonar.server.permission.GroupId; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuid; +import org.sonar.server.permission.GroupUuidOrAnyone; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import static org.sonar.server.exceptions.BadRequestException.checkRequest; @@ -35,71 +35,68 @@ import static org.sonar.server.exceptions.BadRequestException.checkRequest; * Reference to a user group <b>as declared by web service requests</b>. It is one, and only one, * of these two options: * <ul> - * <li>group id, for instance 1234</li> + * <li>group uuid, for instance 1234</li> * <li>group name and optional organization key</li> * </ul> * - * The reference is then converted to a {@link GroupId} or {@link GroupIdOrAnyone}. + * The reference is then converted to a {@link GroupUuid} or {@link GroupUuidOrAnyone}. */ @Immutable public class GroupWsRef { - private static final int NULL_ID = -1; - - private final int id; + private final String uuid; private final String organizationKey; private final String name; - private GroupWsRef(int id, @Nullable String organizationKey, @Nullable String name) { - this.id = id; + private GroupWsRef(String uuid, @Nullable String organizationKey, @Nullable String name) { + this.uuid = uuid; this.organizationKey = organizationKey; this.name = name; } /** - * @return {@code true} if id is defined and {@link #getId()} can be called. If {@code false}, then + * @return {@code true} if uuid is defined and {@link #getUuid()} can be called. If {@code false}, then * the couple {organizationKey, name} is defined and the methods {@link #getOrganizationKey()}/{@link #getName()} * can be called. */ - public boolean hasId() { - return id != NULL_ID; + public boolean hasUuid() { + return uuid != null; } /** - * @return the group id - * @throws IllegalStateException if {@link #getId()} is {@code false} + * @return the group uuid + * @throws IllegalStateException if {@link #getUuid()} is {@code false} */ - public int getId() { - checkState(hasId(), "Id is not present. Please see hasId()."); - return id; + public String getUuid() { + checkState(hasUuid(), "Id is not present. Please see hasUuid()."); + return uuid; } /** * @return the organization key - * @throws IllegalStateException if {@link #getId()} is {@code true} + * @throws IllegalStateException if {@link #getUuid()} is {@code true} */ @CheckForNull public String getOrganizationKey() { - checkState(!hasId(), "Organization is not present. Please see hasId()."); + checkState(!hasUuid(), "Organization is not present. Please see hasId()."); return organizationKey; } /** * @return the non-null group name. Can be anyone. - * @throws IllegalStateException if {@link #getId()} is {@code true} + * @throws IllegalStateException if {@link #getUuid()} is {@code true} */ public String getName() { - checkState(!hasId(), "Name is not present. Please see hasId()."); + checkState(!hasUuid(), "Name is not present. Please see hasId()."); return name; } /** - * Creates a reference to a group by its id. Virtual groups "Anyone" can't be returned - * as they can't be referenced by an id. + * Creates a reference to a group by its uuid. Virtual groups "Anyone" can't be returned + * as they can't be referenced by an uuid. */ - static GroupWsRef fromId(int id) { - checkArgument(id > -1, "Group id must be positive: %s", id); - return new GroupWsRef(id, null, null); + static GroupWsRef fromUuid(String uuid) { + return new GroupWsRef(uuid, null, null); } /** @@ -110,13 +107,13 @@ public class GroupWsRef { * @param name non-null name. Can refer to anyone group (case-insensitive {@code "anyone"}). */ static GroupWsRef fromName(@Nullable String organizationKey, String name) { - return new GroupWsRef(NULL_ID, organizationKey, requireNonNull(name)); + return new GroupWsRef(null, organizationKey, requireNonNull(name)); } - public static GroupWsRef create(@Nullable Integer id, @Nullable String organizationKey, @Nullable String name) { - if (id != null) { + public static GroupWsRef create(@Nullable String uuid, @Nullable String organizationKey, @Nullable String name) { + if (uuid != null) { checkRequest(organizationKey == null && name == null, "Either group id or couple organization/group name must be set"); - return fromId(id); + return fromUuid(uuid); } checkRequest(name != null, "Group name or group id must be provided"); @@ -124,7 +121,7 @@ public class GroupWsRef { } public boolean isAnyone() { - return !hasId() && DefaultGroups.isAnyone(name); + return !hasUuid() && DefaultGroups.isAnyone(name); } @Override @@ -136,27 +133,18 @@ public class GroupWsRef { return false; } GroupWsRef that = (GroupWsRef) o; - if (id != that.id) { - return false; - } - if (organizationKey != null ? !organizationKey.equals(that.organizationKey) : (that.organizationKey != null)) { - return false; - } - return name != null ? name.equals(that.name) : (that.name == null); + return Objects.equals(uuid, that.uuid) && Objects.equals(organizationKey, that.organizationKey) && Objects.equals(name, that.name); } @Override public int hashCode() { - int result = id; - result = 31 * result + (organizationKey != null ? organizationKey.hashCode() : 0); - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; + return Objects.hash(uuid, organizationKey, name); } @Override public String toString() { StringBuilder sb = new StringBuilder("GroupWsRef{"); - sb.append("id=").append(id); + sb.append("uuid=").append(uuid); sb.append(", organizationKey='").append(organizationKey).append('\''); sb.append(", name='").append(name).append('\''); sb.append('}'); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java index c60a1262c23..b25a09ac055 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java @@ -29,8 +29,8 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.GroupDto; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.organization.DefaultOrganizationProvider; -import org.sonar.server.permission.GroupId; -import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.GroupUuid; +import org.sonar.server.permission.GroupUuidOrAnyone; import org.sonar.server.usergroups.DefaultGroupFinder; import org.sonarqube.ws.UserGroups; @@ -74,21 +74,21 @@ public class GroupWsSupport { * @throws NotFoundException if parameters are missing/incorrect, if the requested group does not exist * or if the virtual group "Anyone" is requested. */ - public GroupId findGroup(DbSession dbSession, Request request) { - return GroupId.from(findGroupDto(dbSession, request)); + public GroupUuid findGroup(DbSession dbSession, Request request) { + return GroupUuid.from(findGroupDto(dbSession, request)); } public GroupDto findGroupDto(DbSession dbSession, Request request) { - Integer id = request.paramAsInt(PARAM_GROUP_ID); + String uuid = request.param(PARAM_GROUP_ID); String organizationKey = request.param(PARAM_ORGANIZATION_KEY); String name = request.param(PARAM_GROUP_NAME); - return findGroupDto(dbSession, GroupWsRef.create(id, organizationKey, name)); + return findGroupDto(dbSession, GroupWsRef.create(uuid, organizationKey, name)); } public GroupDto findGroupDto(DbSession dbSession, GroupWsRef ref) { - if (ref.hasId()) { - GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId()); - checkFound(group, "No group with id '%s'", ref.getId()); + if (ref.hasUuid()) { + GroupDto group = dbClient.groupDao().selectByUuid(dbSession, ref.getUuid()); + checkFound(group, "No group with id '%s'", ref.getUuid()); return group; } @@ -98,21 +98,21 @@ public class GroupWsSupport { return group.get(); } - public GroupIdOrAnyone findGroupOrAnyone(DbSession dbSession, GroupWsRef ref) { - if (ref.hasId()) { - GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId()); - checkFound(group, "No group with id '%s'", ref.getId()); - return GroupIdOrAnyone.from(group); + public GroupUuidOrAnyone findGroupOrAnyone(DbSession dbSession, GroupWsRef ref) { + if (ref.hasUuid()) { + GroupDto group = dbClient.groupDao().selectByUuid(dbSession, ref.getUuid()); + checkFound(group, "No group with id '%s'", ref.getUuid()); + return GroupUuidOrAnyone.from(group); } OrganizationDto org = findOrganizationByKey(dbSession, ref.getOrganizationKey()); if (ref.isAnyone()) { - return GroupIdOrAnyone.forAnyone(org.getUuid()); + return GroupUuidOrAnyone.forAnyone(org.getUuid()); } Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, org.getUuid(), ref.getName()); checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", ref.getName(), org.getKey()); - return GroupIdOrAnyone.from(group.get()); + return GroupUuidOrAnyone.from(group.get()); } /** @@ -141,12 +141,12 @@ public class GroupWsSupport { void checkGroupIsNotDefault(DbSession dbSession, GroupDto groupDto) { GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession, groupDto.getOrganizationUuid()); - checkArgument(!defaultGroup.getId().equals(groupDto.getId()), "Default group '%s' cannot be used to perform this action", groupDto.getName()); + checkArgument(!defaultGroup.getUuid().equals(groupDto.getUuid()), "Default group '%s' cannot be used to perform this action", groupDto.getName()); } static UserGroups.Group.Builder toProtobuf(OrganizationDto organization, GroupDto group, int membersCount, boolean isDefault) { UserGroups.Group.Builder wsGroup = UserGroups.Group.newBuilder() - .setId(group.getId()) + .setUuid(group.getUuid()) .setOrganization(organization.getKey()) .setName(group.getName()) .setMembersCount(membersCount) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java index e201e718161..9ae83d7d720 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java @@ -80,7 +80,7 @@ public class RemoveUserAction implements UserGroupsWsAction { ensureLastAdminIsNotRemoved(dbSession, group, user); - dbClient.userGroupDao().delete(dbSession, group.getId(), user.getId()); + dbClient.userGroupDao().delete(dbSession, group.getUuid(), user.getId()); dbSession.commit(); response.noContent(); @@ -92,7 +92,7 @@ public class RemoveUserAction implements UserGroupsWsAction { */ private void ensureLastAdminIsNotRemoved(DbSession dbSession, GroupDto group, UserDto user) { int remainingAdmins = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingGroupMember(dbSession, - group.getOrganizationUuid(), OrganizationPermission.ADMINISTER.getKey(), group.getId(), user.getId()); + group.getOrganizationUuid(), OrganizationPermission.ADMINISTER.getKey(), group.getUuid(), user.getId()); checkRequest(remainingAdmins > 0, "The last administrator user cannot be removed"); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java index b3828aea235..dc456bfff52 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java @@ -111,8 +111,8 @@ public class SearchAction implements UserGroupsWsAction { int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query); Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(limit); List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize); - List<Integer> groupIds = groups.stream().map(GroupDto::getId).collect(MoreCollectors.toList(groups.size())); - Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds); + List<String> groupUuids = groups.stream().map(GroupDto::getUuid).collect(MoreCollectors.toList(groups.size())); + Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupUuids); writeProtobuf(buildResponse(groups, userCountByGroup, fields, paging, defaultGroup), request, response); } } @@ -131,7 +131,7 @@ public class SearchAction implements UserGroupsWsAction { private static SearchWsResponse buildResponse(List<GroupDto> groups, Map<String, Integer> userCountByGroup, Set<String> fields, Paging paging, GroupDto defaultGroup) { SearchWsResponse.Builder responseBuilder = SearchWsResponse.newBuilder(); groups.forEach(group -> responseBuilder - .addGroups(toWsGroup(group, userCountByGroup.get(group.getName()), fields, defaultGroup.getId().equals(group.getId())))); + .addGroups(toWsGroup(group, userCountByGroup.get(group.getName()), fields, defaultGroup.getUuid().equals(group.getUuid())))); responseBuilder.getPagingBuilder() .setPageIndex(paging.pageIndex()) .setPageSize(paging.pageSize()) @@ -142,7 +142,7 @@ public class SearchAction implements UserGroupsWsAction { private static Group toWsGroup(GroupDto group, Integer memberCount, Set<String> fields, boolean isDefault) { Group.Builder groupBuilder = Group.newBuilder() - .setId(group.getId()) + .setUuid(group.getUuid()) .setDefault(isDefault); if (fields.contains(FIELD_NAME)) { groupBuilder.setName(group.getName()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java index 7303552ab38..29902c15cd6 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java @@ -90,9 +90,9 @@ public class UpdateAction implements UserGroupsWsAction { @Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { - int groupId = request.mandatoryParamAsInt(PARAM_GROUP_ID); - GroupDto group = dbClient.groupDao().selectById(dbSession, groupId); - checkFound(group, "Could not find a user group with id '%s'.", groupId); + String groupUuid = request.mandatoryParam(PARAM_GROUP_ID); + GroupDto group = dbClient.groupDao().selectByUuid(dbSession, groupUuid); + checkFound(group, "Could not find a user group with id '%s'.", groupUuid); Optional<OrganizationDto> org = dbClient.organizationDao().selectByUuid(dbSession, group.getOrganizationUuid()); checkFoundWithOptional(org, "Could not find organization with id '%s'.", group.getOrganizationUuid()); userSession.checkPermission(ADMINISTER, org.get()); @@ -124,7 +124,7 @@ public class UpdateAction implements UserGroupsWsAction { private void writeResponse(DbSession dbSession, Request request, Response response, OrganizationDto organization, GroupDto group) { UserMembershipQuery query = UserMembershipQuery.builder() - .groupId(group.getId()) + .groupUuid(group.getUuid()) .organizationUuid(organization.getUuid()) .membership(UserMembershipQuery.IN) .build(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java index 3c6d88e8ea2..51d59895eca 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java @@ -33,7 +33,7 @@ import org.sonar.db.DbSession; import org.sonar.db.permission.OrganizationPermission; import org.sonar.db.user.UserMembershipDto; import org.sonar.db.user.UserMembershipQuery; -import org.sonar.server.permission.GroupId; +import org.sonar.server.permission.GroupUuid; import org.sonar.server.user.UserSession; import static org.sonar.api.utils.Paging.forPageIndex; @@ -78,11 +78,11 @@ public class UsersAction implements UserGroupsWsAction { String selected = request.mandatoryParam(Param.SELECTED); try (DbSession dbSession = dbClient.openSession(false)) { - GroupId group = support.findGroup(dbSession, request); + GroupUuid group = support.findGroup(dbSession, request); userSession.checkPermission(OrganizationPermission.ADMINISTER, group.getOrganizationUuid()); UserMembershipQuery query = UserMembershipQuery.builder() - .groupId(group.getId()) + .groupUuid(group.getUuid()) .organizationUuid(group.getOrganizationUuid()) .memberSearch(queryString) .membership(getMembership(selected)) @@ -108,7 +108,7 @@ public class UsersAction implements UserGroupsWsAction { json.beginObject() .prop(FIELD_LOGIN, user.getLogin()) .prop(FIELD_NAME, user.getName()) - .prop(FIELD_SELECTED, user.getGroupId() != null) + .prop(FIELD_SELECTED, user.getGroupUuid() != null) .endObject(); } json.endArray(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index bfcf9261561..8a2242c98e2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -1157,7 +1157,7 @@ public class SearchActionTest { new GroupPermissionDto() .setUuid(Uuids.createFast()) .setOrganizationUuid(project.getOrganizationUuid()) - .setGroupId(null) + .setGroupUuid(null) .setComponentUuid(project.uuid()) .setRole(permission)); session.commit(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java index ba7e5355b8b..0df8147b1e9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/AddMemberActionTest.java @@ -268,12 +268,12 @@ public class AddMemberActionTest { private void assertMember(String organizationUuid, int userId) { assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, userId)).isPresent(); - Integer defaultGroupId = dbClient.organizationDao().getDefaultGroupId(dbSession, organizationUuid).get(); + String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organizationUuid).get(); assertThat(db.getDbClient().groupMembershipDao().selectGroups(db.getSession(), GroupMembershipQuery.builder() .membership(IN) .organizationUuid(organizationUuid).build(), userId, 0, 10)) - .extracting(GroupMembershipDto::getId) - .containsOnly(defaultGroupId.longValue()); + .extracting(GroupMembershipDto::getUuid) + .containsOnly(defaultGroupUuid); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java index d5a7d4c31ca..b98c8208bc8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java @@ -34,6 +34,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.core.util.SequenceUuidFactory; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -109,7 +110,7 @@ public class CreateActionTest { private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT); private PermissionService permissionService = new PermissionServiceImpl(resourceTypes); private OrganizationUpdater organizationUpdater = new OrganizationUpdaterImpl(dbClient, system2, UuidFactoryFast.getInstance(), organizationValidation, - userIndexer, mock(BuiltInQProfileRepository.class), new DefaultGroupCreatorImpl(dbClient), permissionService); + userIndexer, mock(BuiltInQProfileRepository.class), new DefaultGroupCreatorImpl(dbClient, new SequenceUuidFactory()), permissionService); private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone().setEnabled(true); private OrganizationAlmBinding organizationAlmBinding = mock(OrganizationAlmBinding.class); @@ -159,13 +160,13 @@ public class CreateActionTest { assertThat(groupDtoOptional).isNotEmpty(); GroupDto groupDto = groupDtoOptional.get(); assertThat(groupDto.getDescription()).isEqualTo("Owners of organization"); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())) + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getUuid())) .containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()])); List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers( dbSession, UserMembershipQuery.builder() .organizationUuid(organization.getUuid()) - .groupId(groupDto.getId()) + .groupUuid(groupDto.getUuid()) .membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE); assertThat(members) @@ -187,12 +188,12 @@ public class CreateActionTest { assertThat(groupDtoOptional).isNotEmpty(); GroupDto groupDto = groupDtoOptional.get(); assertThat(groupDto.getDescription()).isEqualTo("All members of the organization"); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).isEmpty(); + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getUuid())).isEmpty(); List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers( dbSession, UserMembershipQuery.builder() .organizationUuid(organization.getUuid()) - .groupId(groupDto.getId()) + .groupUuid(groupDto.getUuid()) .membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE); assertThat(members) @@ -218,14 +219,14 @@ public class CreateActionTest { assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid()); assertThat(defaultTemplates.getApplicationsUuid()).isNull(); assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateUuid(dbSession, defaultTemplate.getUuid())) - .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission) + .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission) .containsOnly( - tuple(ownersGroup.getId(), UserRole.ADMIN), - tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), - tuple(defaultGroup.getId(), UserRole.USER), - tuple(defaultGroup.getId(), UserRole.CODEVIEWER), - tuple(defaultGroup.getId(), UserRole.ISSUE_ADMIN), - tuple(defaultGroup.getId(), UserRole.SECURITYHOTSPOT_ADMIN)); + tuple(ownersGroup.getUuid(), UserRole.ADMIN), + tuple(ownersGroup.getUuid(), GlobalPermissions.SCAN_EXECUTION), + tuple(defaultGroup.getUuid(), UserRole.USER), + tuple(defaultGroup.getUuid(), UserRole.CODEVIEWER), + tuple(defaultGroup.getUuid(), UserRole.ISSUE_ADMIN), + tuple(defaultGroup.getUuid(), UserRole.SECURITYHOTSPOT_ADMIN)); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java index 41dd5dc165b..a5a80e6f2c4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java @@ -405,9 +405,9 @@ public class DeleteActionTest { sendRequest(org); verifyOrganizationDoesNotExist(org); - assertThat(dbClient.groupDao().selectByIds(dbSession, of(group1.getId(), otherGroup1.getId(), group2.getId(), otherGroup2.getId()))) - .extracting(GroupDto::getId) - .containsOnly(otherGroup1.getId(), otherGroup2.getId()); + assertThat(dbClient.groupDao().selectByUuids(dbSession, of(group1.getUuid(), otherGroup1.getUuid(), group2.getUuid(), otherGroup2.getUuid()))) + .extracting(GroupDto::getUuid) + .containsOnly(otherGroup1.getUuid(), otherGroup2.getUuid()); assertThat(dbClient.permissionTemplateDao().selectByUuid(dbSession, templateDto.getUuid())) .isNull(); assertThat(dbClient.permissionTemplateDao().selectByUuid(dbSession, otherTemplateDto.getUuid())) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/OrganizationDeleterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/OrganizationDeleterTest.java index 8d096e63b94..90d5e1d9176 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/OrganizationDeleterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/organization/ws/OrganizationDeleterTest.java @@ -237,9 +237,9 @@ public class OrganizationDeleterTest { underTest.delete(dbSession, org); verifyOrganizationDoesNotExist(org); - assertThat(dbClient.groupDao().selectByIds(dbSession, of(group1.getId(), otherGroup1.getId(), group2.getId(), otherGroup2.getId()))) - .extracting(GroupDto::getId) - .containsOnly(otherGroup1.getId(), otherGroup2.getId()); + assertThat(dbClient.groupDao().selectByUuids(dbSession, of(group1.getUuid(), otherGroup1.getUuid(), group2.getUuid(), otherGroup2.getUuid()))) + .extracting(GroupDto::getUuid) + .containsOnly(otherGroup1.getUuid(), otherGroup2.getUuid()); assertThat(dbClient.permissionTemplateDao().selectByUuid(dbSession, templateDto.getUuid())) .isNull(); assertThat(dbClient.permissionTemplateDao().selectByUuid(dbSession, otherTemplateDto.getUuid())) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java index e2e8a9558ac..d9f392873ad 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java @@ -72,7 +72,7 @@ public class GroupPermissionChangerTest { @Test public void apply_adds_organization_permission_to_group() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId, permissionService)); @@ -81,7 +81,7 @@ public class GroupPermissionChangerTest { @Test public void apply_adds_organization_permission_to_group_AnyOne() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId, permissionService)); @@ -90,7 +90,7 @@ public class GroupPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_adding_any_permission_to_group_AnyOne_on_private_project() { - GroupIdOrAnyone anyOneGroupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone anyOneGroupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); permissionService.getAllProjectPermissions() .forEach(perm -> { try { @@ -107,7 +107,7 @@ public class GroupPermissionChangerTest { permissionService.getAllProjectPermissions() .forEach(this::unsafeInsertProjectPermissionOnAnyone); - GroupIdOrAnyone anyOneGroupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone anyOneGroupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); permissionService.getAllProjectPermissions() .forEach(perm -> { apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService)); @@ -142,7 +142,7 @@ public class GroupPermissionChangerTest { } private void applyAddsPermissionToGroupOnPrivateProject(String permission) { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService)); @@ -176,7 +176,7 @@ public class GroupPermissionChangerTest { } private void applyRemovesPermissionFromGroupOnPrivateProject(String permission) { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); db.users().insertProjectPermissionOnGroup(group, permission, privateProject); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService)); @@ -186,7 +186,7 @@ public class GroupPermissionChangerTest { @Test public void apply_has_no_effect_when_adding_USER_permission_to_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); @@ -195,7 +195,7 @@ public class GroupPermissionChangerTest { @Test public void apply_has_no_effect_when_adding_CODEVIEWER_permission_to_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); @@ -204,7 +204,7 @@ public class GroupPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_adding_permission_ADMIN_to_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("It is not possible to add the 'admin' permission to group 'Anyone'"); @@ -214,7 +214,7 @@ public class GroupPermissionChangerTest { @Test public void apply_adds_permission_ISSUE_ADMIN_to_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectUuid(publicProject), groupId, permissionService)); @@ -223,7 +223,7 @@ public class GroupPermissionChangerTest { @Test public void apply_adds_permission_SCAN_EXECUTION_to_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectUuid(publicProject), groupId, permissionService)); @@ -232,7 +232,7 @@ public class GroupPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_removing_USER_permission_from_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission user can't be removed from a public component"); @@ -242,7 +242,7 @@ public class GroupPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_removing_CODEVIEWER_permission_from_group_AnyOne_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); @@ -266,7 +266,7 @@ public class GroupPermissionChangerTest { } private void applyRemovesPermissionFromGroupAnyOneOnAPublicProject(String permission) { - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(org.getUuid()); db.users().insertProjectPermissionOnAnyone(permission, publicProject); apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectUuid(publicProject), groupId, permissionService)); @@ -276,7 +276,7 @@ public class GroupPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_removing_USER_permission_from_a_group_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission user can't be removed from a public component"); @@ -286,7 +286,7 @@ public class GroupPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_removing_CODEVIEWER_permission_from_a_group_on_a_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); @@ -297,7 +297,7 @@ public class GroupPermissionChangerTest { @Test public void add_permission_to_anyone() { OrganizationDto defaultOrganization = db.getDefaultOrganization(); - GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(defaultOrganization.getUuid()); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.forAnyone(defaultOrganization.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId, permissionService)); @@ -307,7 +307,7 @@ public class GroupPermissionChangerTest { @Test public void do_nothing_when_adding_permission_that_already_exists() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, ADMINISTER_QUALITY_GATES.getKey(), null, groupId, permissionService)); @@ -317,7 +317,7 @@ public class GroupPermissionChangerTest { @Test public void fail_to_add_global_permission_but_SCAN_and_ADMIN_on_private_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); permissionService.getAllOrganizationPermissions().stream() .map(OrganizationPermission::getKey) @@ -335,7 +335,7 @@ public class GroupPermissionChangerTest { @Test public void fail_to_add_global_permission_but_SCAN_and_ADMIN_on_public_project() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); permissionService.getAllOrganizationPermissions().stream() .map(OrganizationPermission::getKey) @@ -353,7 +353,7 @@ public class GroupPermissionChangerTest { @Test public void fail_to_add_project_permission_but_SCAN_and_ADMIN_on_global_group() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); permissionService.getAllProjectPermissions() .stream() @@ -370,7 +370,7 @@ public class GroupPermissionChangerTest { @Test public void remove_permission_from_group() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES); db.users().insertPermissionOnGroup(group, PROVISION_PROJECTS); @@ -381,7 +381,7 @@ public class GroupPermissionChangerTest { @Test public void remove_project_permission_from_group() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES); db.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, privateProject); db.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, privateProject); @@ -394,7 +394,7 @@ public class GroupPermissionChangerTest { @Test public void do_not_fail_if_removing_a_permission_that_does_not_exist() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService)); @@ -404,7 +404,7 @@ public class GroupPermissionChangerTest { @Test public void fail_to_remove_admin_permission_if_no_more_admins() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); db.users().insertPermissionOnGroup(group, ADMINISTER); expectedException.expect(BadRequestException.class); @@ -415,7 +415,7 @@ public class GroupPermissionChangerTest { @Test public void remove_admin_group_if_still_other_admins() { - GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); + GroupUuidOrAnyone groupId = GroupUuidOrAnyone.from(group); db.users().insertPermissionOnGroup(group, ADMINISTER); UserDto admin = db.users().insertUser(); db.users().insertPermissionOnUser(org, admin, ADMINISTER); @@ -434,7 +434,7 @@ public class GroupPermissionChangerTest { GroupPermissionDto dto = new GroupPermissionDto() .setUuid(Uuids.createFast()) .setOrganizationUuid(privateProject.getOrganizationUuid()) - .setGroupId(null) + .setGroupUuid(null) .setRole(perm) .setComponentUuid(privateProject.uuid()); db.getDbClient().groupPermissionDao().insert(db.getSession(), dto); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index 7265a3fa09f..59069ecd31e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -437,7 +437,7 @@ public class PermissionTemplateServiceTest { private List<String> selectProjectPermissionsOfGroup(OrganizationDto organizationDto, @Nullable GroupDto groupDto, ComponentDto project) { return dbTester.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(session, - organizationDto.getUuid(), groupDto != null ? groupDto.getId() : null, project.uuid()); + organizationDto.getUuid(), groupDto != null ? groupDto.getUuid() : null, project.uuid()); } private List<String> selectProjectPermissionsOfUser(UserDto userDto, ComponentDto project) { @@ -455,7 +455,7 @@ public class PermissionTemplateServiceTest { dbTester.organizations().setDefaultTemplates(template, null, null); templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN.getKey()); templateDb.addUserToTemplate(template.getUuid(), user.getId(), UserRole.USER); - templateDb.addGroupToTemplate(template.getUuid(), group.getId(), UserRole.CODEVIEWER); + templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER); templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN); // authenticated user diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java index 24cd33f2e1d..143e4977e86 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java @@ -105,7 +105,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { loginAsAdmin(db.getDefaultOrganization()); newRequest() - .setParam(PARAM_GROUP_ID, group.getId().toString()) + .setParam(PARAM_GROUP_ID, group.getUuid().toString()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -302,7 +302,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { expectedException.expect(ForbiddenException.class); newRequest() - .setParam(PARAM_GROUP_ID, group.getId().toString()) + .setParam(PARAM_GROUP_ID, group.getUuid().toString()) .setParam(PARAM_PERMISSION, PROVISIONING) .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index 5e8bae5031c..4f33c807f3d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -96,7 +96,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio loginAsAdmin(db.getDefaultOrganization()); newRequest() - .setParam(PARAM_GROUP_ID, aGroup.getId().toString()) + .setParam(PARAM_GROUP_ID, aGroup.getUuid().toString()) .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey()) .execute(); @@ -476,7 +476,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio GroupPermissionDto dto = new GroupPermissionDto() .setUuid(Uuids.createFast()) .setOrganizationUuid(project.getOrganizationUuid()) - .setGroupId(null) + .setGroupUuid(null) .setRole(perm) .setComponentUuid(project.uuid()); db.getDbClient().groupPermissionDao().insert(db.getSession(), dto); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java index 40f50015054..3af76e20ec7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java @@ -99,7 +99,7 @@ public class AddGroupToTemplateActionTest extends BasePermissionWsTest<AddGroupT newRequest() .setParam(PARAM_TEMPLATE_ID, template.getUuid()) .setParam(PARAM_PERMISSION, CODEVIEWER) - .setParam(PARAM_GROUP_ID, String.valueOf(group.getId())) + .setParam(PARAM_GROUP_ID, String.valueOf(group.getUuid())) .execute(); assertThat(getGroupNamesInTemplateAndPermission(template, CODEVIEWER)).containsExactly(group.getName()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java index b5a79611dc2..dfe00d8a2a5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java @@ -212,7 +212,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA } private void addGroupToTemplate(GroupDto group, PermissionTemplateDto permissionTemplate, String permission) { - db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getId(), permission); + db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(), permission); db.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java index 2aa2bc0c7b2..16e26ca06f0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java @@ -350,7 +350,7 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT } private void addGroupToTemplate(GroupDto group, PermissionTemplateDto permissionTemplate, String permission) { - db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getId(), permission); + db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(), permission); db.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java index ea198a96306..ee951cc4552 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java @@ -422,7 +422,7 @@ public class DeleteTemplateActionTest { UserDto user = db.getDbClient().userDao().insert(db.getSession(), UserTesting.newUserDto().setActive(true)); GroupDto group = db.getDbClient().groupDao().insert(db.getSession(), GroupTesting.newGroupDto()); db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getUuid(), user.getId(), UserRole.ADMIN); - db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getUuid(), group.getId(), UserRole.CODEVIEWER); + db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getUuid(), group.getUuid(), UserRole.CODEVIEWER); db.commit(); return dto; } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java index ebf04fa91aa..a58014937a1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java @@ -71,7 +71,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo group = db.users().insertGroup(db.getDefaultOrganization(), "group-name"); template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization()); - addGroupToTemplate(template, group.getId(), PERMISSION); + addGroupToTemplate(template, group.getUuid(), PERMISSION); } @Test @@ -97,7 +97,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo newRequest() .setParam(PARAM_TEMPLATE_ID, template.getUuid()) .setParam(PARAM_PERMISSION, PERMISSION) - .setParam(PARAM_GROUP_ID, String.valueOf(group.getId())) + .setParam(PARAM_GROUP_ID, String.valueOf(group.getUuid())) .execute(); assertThat(getGroupNamesInTemplateAndPermission(template, PERMISSION)).isEmpty(); @@ -196,8 +196,8 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo request.execute(); } - private void addGroupToTemplate(PermissionTemplateDto template, @Nullable Integer groupId, String permission) { - db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), groupId, permission); + private void addGroupToTemplate(PermissionTemplateDto template, @Nullable String groupUuid, String permission) { + db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), groupUuid, permission); db.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java index c6d5598b089..c5482f55dae 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java @@ -97,7 +97,7 @@ public class SearchTemplatesActionTest extends BasePermissionWsTest<SearchTempla addUserToTemplate(projectTemplate.getUuid(), user2.getId(), UserRole.ISSUE_ADMIN); addUserToTemplate(projectTemplate.getUuid(), user3.getId(), UserRole.ISSUE_ADMIN); addUserToTemplate(projectTemplate.getUuid(), user1.getId(), UserRole.CODEVIEWER); - addGroupToTemplate(projectTemplate.getUuid(), group1.getId(), UserRole.ADMIN); + addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN); addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN); db.organizations().setDefaultTemplates(projectTemplate, null, null); @@ -128,14 +128,14 @@ public class SearchTemplatesActionTest extends BasePermissionWsTest<SearchTempla addUserToTemplate(projectTemplate.getUuid(), user2.getId(), UserRole.ISSUE_ADMIN); addUserToTemplate(projectTemplate.getUuid(), user3.getId(), UserRole.ISSUE_ADMIN); addUserToTemplate(projectTemplate.getUuid(), user1.getId(), UserRole.CODEVIEWER); - addGroupToTemplate(projectTemplate.getUuid(), group1.getId(), UserRole.ADMIN); + addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN); addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN); addUserToTemplate(portfoliosTemplate.getUuid(), user1.getId(), UserRole.USER); addUserToTemplate(portfoliosTemplate.getUuid(), user2.getId(), UserRole.USER); - addGroupToTemplate(portfoliosTemplate.getUuid(), group1.getId(), UserRole.ISSUE_ADMIN); - addGroupToTemplate(portfoliosTemplate.getUuid(), group2.getId(), UserRole.ISSUE_ADMIN); - addGroupToTemplate(portfoliosTemplate.getUuid(), group3.getId(), UserRole.ISSUE_ADMIN); + addGroupToTemplate(portfoliosTemplate.getUuid(), group1.getUuid(), UserRole.ISSUE_ADMIN); + addGroupToTemplate(portfoliosTemplate.getUuid(), group2.getUuid(), UserRole.ISSUE_ADMIN); + addGroupToTemplate(portfoliosTemplate.getUuid(), group3.getUuid(), UserRole.ISSUE_ADMIN); db.organizations().setDefaultTemplates(projectTemplate, applicationsTemplate, portfoliosTemplate); @@ -377,8 +377,8 @@ public class SearchTemplatesActionTest extends BasePermissionWsTest<SearchTempla return insert; } - private void addGroupToTemplate(String templateUuid, @Nullable Integer groupId, String permission) { - dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupId, permission); + private void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission) { + dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupUuid, permission); db.getSession().commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java index 9f1265c5a40..1c3951eba67 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java @@ -89,8 +89,8 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup GroupDto userGroup = insertGroupOnDefaultOrganization("sonar-users", "Any new users created will automatically join this group"); PermissionTemplateDto template = addTemplateToDefaultOrganization(); - addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getId())); - addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getId())); + addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid())); // Anyone group addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null)); addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null)); @@ -114,8 +114,8 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup String groupName = "group-name"; GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), groupName); - addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getId())); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getId())); + addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getUuid())); OrganizationDto otherOrganization = db.organizations().insert(); db.users().insertGroup(otherOrganization, groupName); @@ -123,10 +123,10 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup loginAsAdmin(db.getDefaultOrganization()); newRequest() - .setMediaType(PROTOBUF) - .setParam(PARAM_TEMPLATE_ID, template.getUuid()) - .setParam(TEXT_QUERY, "-nam") - .execute(); + .setMediaType(PROTOBUF) + .setParam(PARAM_TEMPLATE_ID, template.getUuid()) + .setParam(TEXT_QUERY, "-nam") + .execute(); } @Test @@ -134,12 +134,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup PermissionTemplateDto template = addTemplateToDefaultOrganization(); GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name"); - addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getId())); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getId())); + addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getUuid())); GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name"); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getId())); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid())); GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name"); @@ -149,8 +149,8 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization(); GroupDto group4 = db.users().insertGroup(db.getDefaultOrganization(), "group-4-name"); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getId())); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getId())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid())); loginAsAdmin(db.getDefaultOrganization()); WsGroupsResponse response = newRequest() @@ -169,11 +169,11 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup PermissionTemplateDto template = addTemplateToDefaultOrganization(); GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name"); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getId())); - addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid())); GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name"); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getId())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid())); GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name"); @@ -181,7 +181,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null)); PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization(); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getId())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid())); loginAsAdmin(db.getDefaultOrganization()); WsGroupsResponse response = newRequest() @@ -202,12 +202,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3-name"); PermissionTemplateDto template = addTemplateToDefaultOrganization(); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getId())); - addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid())); + addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid())); addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null)); PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization(); - addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid())); loginAsAdmin(db.getDefaultOrganization()); WsGroupsResponse response = newRequest() @@ -222,9 +222,9 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup OrganizationDto defaultOrg = db.getDefaultOrganization(); PermissionTemplateDto template = addTemplateToDefaultOrganization(); GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name"); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid())); GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name"); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid())); loginAsAdmin(db.getDefaultOrganization()); WsGroupsResponse response = newRequest() @@ -242,7 +242,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup OrganizationDto defaultOrg = db.getDefaultOrganization(); PermissionTemplateDto template = addTemplateToDefaultOrganization(); GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name"); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid())); GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name"); GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3"); loginAsAdmin(db.getDefaultOrganization()); @@ -279,7 +279,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup public void search_with_text_query_return_anyone_group_even_when_no_permission_set() { PermissionTemplateDto template = addTemplateToDefaultOrganization(); GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group"); - addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getId())); + addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid())); loginAsAdmin(db.getDefaultOrganization()); WsGroupsResponse response = newRequest() @@ -399,11 +399,11 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup db.commit(); } - private static PermissionTemplateGroupDto newPermissionTemplateGroup(String permission, String templateUuid, @Nullable Integer groupId) { + private static PermissionTemplateGroupDto newPermissionTemplateGroup(String permission, String templateUuid, @Nullable String groupUuid) { return newPermissionTemplateGroupDto() .setPermission(permission) .setTemplateUuid(templateUuid) - .setGroupId(groupId); + .setGroupUuid(groupUuid); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index 44654eb54e4..bbbe522c1c5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -495,11 +495,11 @@ public class UpdateVisibilityActionTest { .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getUuid(), project.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p1", "p2"); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getUuid(), project.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p2"); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group3.getId(), project.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group3.getUuid(), project.uuid())) .isEmpty(); } @@ -518,7 +518,7 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isTrue(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), portfolio.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN); assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN); @@ -543,7 +543,7 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), portfolio.uuid())) .containsOnly(UserRole.ISSUE_ADMIN); assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) .containsOnly(UserRole.ADMIN); @@ -564,7 +564,7 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, application.uuid()).get().isPrivate()).isTrue(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), application.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), application.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN); assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), application.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN); @@ -589,7 +589,7 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getUuid(), portfolio.uuid())) .containsOnly(UserRole.ISSUE_ADMIN); assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) .containsOnly(UserRole.ADMIN); @@ -659,7 +659,7 @@ public class UpdateVisibilityActionTest { GroupPermissionDto dto = new GroupPermissionDto() .setUuid(Uuids.createFast()) .setOrganizationUuid(component.getOrganizationUuid()) - .setGroupId(null) + .setGroupUuid(null) .setRole(permission) .setComponentUuid(component.uuid()); dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto); @@ -670,7 +670,7 @@ public class UpdateVisibilityActionTest { GroupPermissionDto dto = new GroupPermissionDto() .setUuid(Uuids.createFast()) .setOrganizationUuid(group.getOrganizationUuid()) - .setGroupId(group.getId()) + .setGroupUuid(group.getUuid()) .setRole(permission) .setComponentUuid(component.uuid()); dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto); @@ -686,13 +686,13 @@ public class UpdateVisibilityActionTest { private void verifyHasAllPermissionsButProjectPermissionsToGroupAnyOne(ComponentDto component, UserDto user, GroupDto group) { assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null)) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId())) + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) .isEmpty(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); @@ -701,7 +701,7 @@ public class UpdateVisibilityActionTest { private void verifyHasAllPermissionsButProjectPermissionsUserAndBrowse(ComponentDto component, UserDto user, GroupDto group) { assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null)) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId())) + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); @@ -709,7 +709,7 @@ public class UpdateVisibilityActionTest { .doesNotContain(UserRole.USER) .doesNotContain(UserRole.CODEVIEWER) .containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid(), component.uuid())) .doesNotContain(UserRole.USER) .doesNotContain(UserRole.CODEVIEWER) .containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); @@ -722,13 +722,13 @@ public class UpdateVisibilityActionTest { private void verifyStillHasAllPermissions(ComponentDto component, UserDto user, GroupDto group) { assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null)) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); - assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId())) + assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getUuid(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index 94b2fb5d5a2..c0e91ea4469 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -126,7 +126,7 @@ public class CreateActionTest { assertThat(dbUser.get().isRoot()).isFalse(); // member of default group in default organization - assertThat(db.users().selectGroupIdsOfUser(dbUser.get())).containsOnly(defaultGroupInDefaultOrg.getId()); + assertThat(db.users().selectGroupUuidsOfUser(dbUser.get())).containsOnly(defaultGroupInDefaultOrg.getUuid()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index da7042356d4..1e1258bdf60 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -120,7 +120,7 @@ public class DeactivateActionTest { deactivate(user.getLogin()); - assertThat(db.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbSession, user.getId())).isEmpty(); + assertThat(db.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbSession, user.getId())).isEmpty(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java index 6339d0786d4..807d9be192b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java @@ -89,8 +89,8 @@ public class GroupsActionTest { assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDescription, GroupsWsResponse.Group::getSelected) .containsOnly( - tuple(usersGroup.getId().longValue(), usersGroup.getName(), usersGroup.getDescription(), true), - tuple(adminGroup.getId().longValue(), adminGroup.getName(), adminGroup.getDescription(), false)); + tuple(usersGroup.getUuid(), usersGroup.getName(), usersGroup.getDescription(), true), + tuple(adminGroup.getUuid(), adminGroup.getName(), adminGroup.getDescription(), false)); } @Test @@ -104,7 +104,7 @@ public class GroupsActionTest { assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDescription, GroupsWsResponse.Group::getSelected) - .containsOnly(tuple(usersGroup.getId().longValue(), usersGroup.getName(), usersGroup.getDescription(), true)); + .containsOnly(tuple(usersGroup.getUuid(), usersGroup.getName(), usersGroup.getDescription(), true)); } @Test @@ -118,7 +118,7 @@ public class GroupsActionTest { assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDescription, GroupsWsResponse.Group::getSelected) - .containsOnly(tuple(usersGroup.getId().longValue(), usersGroup.getName(), usersGroup.getDescription(), true)); + .containsOnly(tuple(usersGroup.getUuid(), usersGroup.getName(), usersGroup.getDescription(), true)); } @Test @@ -132,7 +132,7 @@ public class GroupsActionTest { assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDescription, GroupsWsResponse.Group::getSelected) - .containsOnly(tuple(adminGroup.getId().longValue(), adminGroup.getName(), adminGroup.getDescription(), false)); + .containsOnly(tuple(adminGroup.getUuid(), adminGroup.getName(), adminGroup.getDescription(), false)); } @Test @@ -191,8 +191,8 @@ public class GroupsActionTest { assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDefault) .containsOnly( - tuple(usersGroup.getId().longValue(), usersGroup.getName(), true), - tuple(adminGroup.getId().longValue(), adminGroup.getName(), false)); + tuple(usersGroup.getUuid(), usersGroup.getName(), true), + tuple(adminGroup.getUuid(), adminGroup.getName(), false)); } @Test @@ -213,7 +213,7 @@ public class GroupsActionTest { assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDescription, GroupsWsResponse.Group::getSelected, GroupsWsResponse.Group::getDefault) - .containsOnly(tuple(group.getId().longValue(), group.getName(), group.getDescription(), true, true)); + .containsOnly(tuple(group.getUuid(), group.getName(), group.getDescription(), true, true)); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java index 2efb791a3a9..bfba587dd9b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java @@ -66,11 +66,11 @@ public class AddUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(group.getUuid()); } @Test @@ -86,7 +86,7 @@ public class AddUserActionTest { .setParam(PARAM_LOGIN, user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(group.getUuid()); } @Test @@ -104,7 +104,7 @@ public class AddUserActionTest { .setParam(PARAM_LOGIN, user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(group.getUuid()); } @Test @@ -119,11 +119,11 @@ public class AddUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", admins.getId().toString()) + .setParam("id", admins.getUuid().toString()) .setParam("login", user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(admins.getId(), users.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(admins.getUuid(), users.getUuid()); } @Test @@ -136,12 +136,12 @@ public class AddUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", users.getId().toString()) + .setParam("id", users.getUuid().toString()) .setParam("login", user.getLogin()) .execute(); // do not insert duplicated row - assertThat(db.users().selectGroupIdsOfUser(user)).hasSize(1).containsOnly(users.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user)).hasSize(1).containsOnly(users.getUuid()); } @Test @@ -156,12 +156,12 @@ public class AddUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", users.getId().toString()) + .setParam("id", users.getUuid().toString()) .setParam("login", user2.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user1)).containsOnly(users.getId()); - assertThat(db.users().selectGroupIdsOfUser(user2)).containsOnly(users.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user1)).containsOnly(users.getUuid()); + assertThat(db.users().selectGroupUuidsOfUser(user2)).containsOnly(users.getUuid()); } @Test @@ -173,7 +173,7 @@ public class AddUserActionTest { loginAsAdminOnDefaultOrganization(); TestResponse response = newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", user.getLogin()) .execute(); @@ -204,7 +204,7 @@ public class AddUserActionTest { expectedException.expectMessage("Could not find a user with login 'my-admin'"); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", "my-admin") .execute(); } @@ -285,7 +285,7 @@ public class AddUserActionTest { expectedException.expectMessage("Default group 'default' cannot be used to perform this action"); newRequest() - .setParam("id", Integer.toString(defaultGroup.getId())) + .setParam("id", defaultGroup.getUuid()) .setParam(PARAM_LOGIN, user.getLogin()) .execute(); } @@ -310,7 +310,7 @@ public class AddUserActionTest { private void executeRequest(GroupDto groupDto, UserDto userDto) { newRequest() - .setParam("id", groupDto.getId().toString()) + .setParam("id", groupDto.getUuid()) .setParam("login", userDto.getLogin()) .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java index 0efe3a72de7..43e58a54fb6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; +import org.sonar.core.util.SequenceUuidFactory; import org.sonar.db.DbTester; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.GroupDto; @@ -49,7 +50,7 @@ public class CreateActionTest { public ExpectedException expectedException = ExpectedException.none(); private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); - private CreateAction underTest = new CreateAction(db.getDbClient(), userSession, newGroupWsSupport()); + private CreateAction underTest = new CreateAction(db.getDbClient(), userSession, newGroupWsSupport(), new SequenceUuidFactory()); private WsActionTester tester = new WsActionTester(underTest); @Test @@ -102,7 +103,7 @@ public class CreateActionTest { "}"); GroupDto createdGroup = db.users().selectGroup(org, "some-product-bu").get(); - assertThat(createdGroup.getId()).isNotNull(); + assertThat(createdGroup.getUuid()).isNotNull(); assertThat(createdGroup.getOrganizationUuid()).isEqualTo(org.getUuid()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java index 22f33ff4ade..90cec02053a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java @@ -70,7 +70,7 @@ public class DeleteActionTest { loginAsAdminOnDefaultOrganization(); TestResponse response = newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute(); assertThat(response.getStatus()).isEqualTo(204); @@ -84,10 +84,10 @@ public class DeleteActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute(); - assertThat(db.users().selectGroupById(group.getId())).isNull(); + assertThat(db.users().selectGroupByUuid(group.getUuid())).isNull(); } @Test @@ -101,7 +101,7 @@ public class DeleteActionTest { .setParam(PARAM_GROUP_NAME, group.getName()) .execute(); - assertThat(db.users().selectGroupById(group.getId())).isNull(); + assertThat(db.users().selectGroupByUuid(group.getUuid())).isNull(); } @Test @@ -117,7 +117,7 @@ public class DeleteActionTest { .setParam(PARAM_GROUP_NAME, group.getName()) .execute(); - assertThat(db.users().selectGroupById(group.getId())).isNull(); + assertThat(db.users().selectGroupByUuid(group.getUuid())).isNull(); } @Test @@ -145,7 +145,7 @@ public class DeleteActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute(); assertThat(db.countRowsOfTable("groups_users")).isEqualTo(0); @@ -161,7 +161,7 @@ public class DeleteActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute(); assertThat(db.countRowsOfTable("group_roles")).isEqualTo(0); @@ -173,13 +173,13 @@ public class DeleteActionTest { insertDefaultGroupOnDefaultOrganization(); GroupDto group = db.users().insertGroup(); PermissionTemplateDto template = db.getDbClient().permissionTemplateDao().insert(db.getSession(), PermissionTemplateTesting.newPermissionTemplateDto()); - db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), group.getId(), "perm"); + db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), group.getUuid(), "perm"); db.commit(); loginAsAdminOnDefaultOrganization(); assertThat(db.countRowsOfTable("perm_templates_groups")).isEqualTo(1); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute(); assertThat(db.countRowsOfTable("perm_templates_groups")).isEqualTo(0); @@ -195,7 +195,7 @@ public class DeleteActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute(); assertThat(db.countRowsOfTable("qprofile_edit_groups")).isZero(); @@ -224,7 +224,7 @@ public class DeleteActionTest { expectedException.expectMessage("Default group 'default' cannot be used to perform this action"); newRequest() - .setParam("id", defaultGroup.getId().toString()) + .setParam("id", defaultGroup.getUuid()) .execute(); } @@ -239,7 +239,7 @@ public class DeleteActionTest { expectedException.expectMessage("Default group 'default' cannot be used to perform this action"); newRequest() - .setParam("id", defaultGroup.getId().toString()) + .setParam("id", defaultGroup.getUuid()) .execute(); } @@ -294,7 +294,7 @@ public class DeleteActionTest { private void executeDeleteGroupRequest(GroupDto adminGroup1) { newRequest() - .setParam(PARAM_GROUP_ID, adminGroup1.getId().toString()) + .setParam(PARAM_GROUP_ID, adminGroup1.getUuid()) .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java index 95437bca7f1..86c9d2ad904 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java @@ -33,16 +33,16 @@ public class GroupWsRefTest { @Test public void test_ref_by_id() { - GroupWsRef ref = GroupWsRef.fromId(10); - assertThat(ref.hasId()).isTrue(); - assertThat(ref.getId()).isEqualTo(10); + GroupWsRef ref = GroupWsRef.fromUuid("10"); + assertThat(ref.hasUuid()).isTrue(); + assertThat(ref.getUuid()).isEqualTo("10"); assertThat(ref.isAnyone()).isFalse(); } @Test public void test_ref_by_name() { GroupWsRef ref = fromName("ORG1", "the-group"); - assertThat(ref.hasId()).isFalse(); + assertThat(ref.hasUuid()).isFalse(); assertThat(ref.getOrganizationKey()).isEqualTo("ORG1"); assertThat(ref.getName()).isEqualTo("the-group"); assertThat(ref.isAnyone()).isFalse(); @@ -50,11 +50,11 @@ public class GroupWsRefTest { @Test public void test_equals_and_hashCode() { - GroupWsRef refId1 = GroupWsRef.fromId(10); - GroupWsRef refId2 = GroupWsRef.fromId(11); + GroupWsRef refId1 = GroupWsRef.fromUuid("10"); + GroupWsRef refId2 = GroupWsRef.fromUuid("11"); assertThat(refId1.equals(refId1)).isTrue(); - assertThat(refId1.equals(GroupWsRef.fromId(10))).isTrue(); - assertThat(refId1.hashCode()).isEqualTo(GroupWsRef.fromId(10).hashCode()); + assertThat(refId1.equals(GroupWsRef.fromUuid("10"))).isTrue(); + assertThat(refId1.hashCode()).isEqualTo(GroupWsRef.fromUuid("10").hashCode()); assertThat(refId1.equals(refId2)).isFalse(); GroupWsRef refName1 = fromName("ORG1", "the-group"); @@ -69,8 +69,8 @@ public class GroupWsRefTest { @Test public void test_toString() { - GroupWsRef refId = GroupWsRef.fromId(10); - assertThat(refId.toString()).isEqualTo("GroupWsRef{id=10, organizationKey='null', name='null'}"); + GroupWsRef refId = GroupWsRef.fromUuid("10"); + assertThat(refId.toString()).isEqualTo("GroupWsRef{uuid=10, organizationKey='null', name='null'}"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java index 6bd357cf708..fc9a952fe4b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java @@ -69,11 +69,11 @@ public class RemoveUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty(); + assertThat(db.users().selectGroupUuidsOfUser(user)).isEmpty(); } @Test @@ -87,11 +87,11 @@ public class RemoveUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", users.getId().toString()) + .setParam("id", users.getUuid()) .setParam("login", user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty(); + assertThat(db.users().selectGroupUuidsOfUser(user)).isEmpty(); } @Test @@ -108,7 +108,7 @@ public class RemoveUserActionTest { .setParam(PARAM_LOGIN, user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty(); + assertThat(db.users().selectGroupUuidsOfUser(user)).isEmpty(); } @Test @@ -129,7 +129,7 @@ public class RemoveUserActionTest { .setParam(PARAM_LOGIN, user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty(); + assertThat(db.users().selectGroupUuidsOfUser(user)).isEmpty(); } @Test @@ -147,11 +147,11 @@ public class RemoveUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", admins.getId().toString()) + .setParam("id", admins.getUuid()) .setParam("login", user.getLogin()) .execute(); - assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(users.getId()); + assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(users.getUuid()); } @Test @@ -165,7 +165,7 @@ public class RemoveUserActionTest { loginAsAdminOnDefaultOrganization(); TestResponse response = newRequest() - .setParam("id", users.getId().toString()) + .setParam("id", users.getUuid()) .setParam("login", user.getLogin()) .execute(); @@ -194,7 +194,7 @@ public class RemoveUserActionTest { loginAsAdminOnDefaultOrganization(); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", "my-admin") .execute(); } @@ -211,7 +211,7 @@ public class RemoveUserActionTest { expectedException.expectMessage("Insufficient privileges"); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", user.getLogin()) .execute(); } @@ -230,7 +230,7 @@ public class RemoveUserActionTest { expectedException.expectMessage("The last administrator user cannot be removed"); newRequest() - .setParam("id", adminGroup.getId().toString()) + .setParam("id", adminGroup.getUuid()) .setParam("login", adminUser.getLogin()) .execute(); } @@ -247,7 +247,7 @@ public class RemoveUserActionTest { expectedException.expectMessage("Default group 'default' cannot be used to perform this action"); newRequest() - .setParam("id", Integer.toString(defaultGroup.getId())) + .setParam("id", defaultGroup.getUuid()) .setParam(PARAM_LOGIN, user.getLogin()) .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java index 28882b03a96..6c280aebeef 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java @@ -161,15 +161,15 @@ public class SearchActionTest { insertDefaultGroup(db.getDefaultOrganization(), "sonar-users", 0); loginAsDefaultOrgAdmin(); - assertThat(call(ws.newRequest()).getGroupsList()).extracting(Group::hasId, Group::hasName, Group::hasDescription, Group::hasMembersCount) + assertThat(call(ws.newRequest()).getGroupsList()).extracting(Group::hasUuid, Group::hasName, Group::hasDescription, Group::hasMembersCount) .containsOnly(tuple(true, true, true, true)); - assertThat(call(ws.newRequest().setParam(FIELDS, "")).getGroupsList()).extracting(Group::hasId, Group::hasName, Group::hasDescription, Group::hasMembersCount) + assertThat(call(ws.newRequest().setParam(FIELDS, "")).getGroupsList()).extracting(Group::hasUuid, Group::hasName, Group::hasDescription, Group::hasMembersCount) .containsOnly(tuple(true, true, true, true)); - assertThat(call(ws.newRequest().setParam(FIELDS, "name")).getGroupsList()).extracting(Group::hasId, Group::hasName, Group::hasDescription, Group::hasMembersCount) + assertThat(call(ws.newRequest().setParam(FIELDS, "name")).getGroupsList()).extracting(Group::hasUuid, Group::hasName, Group::hasDescription, Group::hasMembersCount) .containsOnly(tuple(true, true, false, false)); - assertThat(call(ws.newRequest().setParam(FIELDS, "description")).getGroupsList()).extracting(Group::hasId, Group::hasName, Group::hasDescription, Group::hasMembersCount) + assertThat(call(ws.newRequest().setParam(FIELDS, "description")).getGroupsList()).extracting(Group::hasUuid, Group::hasName, Group::hasDescription, Group::hasMembersCount) .containsOnly(tuple(true, false, true, false)); - assertThat(call(ws.newRequest().setParam(FIELDS, "membersCount")).getGroupsList()).extracting(Group::hasId, Group::hasName, Group::hasDescription, Group::hasMembersCount) + assertThat(call(ws.newRequest().setParam(FIELDS, "membersCount")).getGroupsList()).extracting(Group::hasUuid, Group::hasName, Group::hasDescription, Group::hasMembersCount) .containsOnly(tuple(true, false, false, true)); } @@ -184,7 +184,7 @@ public class SearchActionTest { SearchWsResponse response = call(ws.newRequest().setParam("organization", org.getKey())); - assertThat(response.getGroupsList()).extracting(Group::getId, Group::getName).containsOnly(tuple(group.getId().longValue(), "users")); + assertThat(response.getGroupsList()).extracting(Group::getUuid, Group::getName).containsOnly(tuple(group.getUuid(), "users")); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java index 334158310d8..d13692ce1ff 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java @@ -62,7 +62,7 @@ public class UpdateActionTest { loginAsAdminOnDefaultOrganization(); String result = newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "new-name") .setParam("description", "New Description") .execute().getInput(); @@ -83,7 +83,7 @@ public class UpdateActionTest { loginAsAdminOnDefaultOrganization(); String result = newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "new-name") .execute().getInput(); @@ -103,7 +103,7 @@ public class UpdateActionTest { loginAsAdminOnDefaultOrganization(); String result = newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("description", "New Description") .execute().getInput(); @@ -123,7 +123,7 @@ public class UpdateActionTest { loginAsAdminOnDefaultOrganization(); String result = newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "new-name") .execute().getInput(); @@ -146,7 +146,7 @@ public class UpdateActionTest { expectedException.expect(ForbiddenException.class); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "some-product-bu") .setParam("description", "Business Unit for Some Awesome Product") .execute(); @@ -164,7 +164,7 @@ public class UpdateActionTest { expectedException.expect(ForbiddenException.class); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "some-product-bu") .setParam("description", "Business Unit for Some Awesome Product") .execute(); @@ -180,7 +180,7 @@ public class UpdateActionTest { expectedException.expectMessage("Group name cannot be empty"); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "") .execute(); } @@ -195,7 +195,7 @@ public class UpdateActionTest { expectedException.expectMessage("Anyone group cannot be used"); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "AnYoNe") .execute(); } @@ -213,7 +213,7 @@ public class UpdateActionTest { expectedException.expectMessage("Group 'new-name' already exists"); newRequest() - .setParam("id", groupToBeRenamed.getId().toString()) + .setParam("id", groupToBeRenamed.getUuid().toString()) .setParam("name", newName) .execute(); } @@ -239,7 +239,7 @@ public class UpdateActionTest { expectedException.expectMessage("Default group 'default' cannot be used to perform this action"); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("name", "new name") .execute(); } @@ -253,7 +253,7 @@ public class UpdateActionTest { expectedException.expectMessage("Default group 'default' cannot be used to perform this action"); newRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid().toString()) .setParam("description", "new description") .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java index 3b75f4245ef..cfce3877ed3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java @@ -56,7 +56,7 @@ public class UsersActionTest { new UsersAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider, new DefaultGroupFinder(db.getDbClient())))); @Test - public void fail_if_unknown_group_id() { + public void fail_if_unknown_group_uuid() { loginAsAdminOnDefaultOrganization(); expectedException.expect(NotFoundException.class); @@ -75,7 +75,7 @@ public class UsersActionTest { expectedException.expect(ForbiddenException.class); newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", "john").execute(); } @@ -89,7 +89,7 @@ public class UsersActionTest { expectedException.expect(ForbiddenException.class); newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("login", "john").execute(); } @@ -100,7 +100,7 @@ public class UsersActionTest { String result = newUsersRequest() .setParam("login", "john") - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute() .getInput(); @@ -112,7 +112,7 @@ public class UsersActionTest { } @Test - public void return_members_by_group_id() { + public void return_members_by_group_uuid() { GroupDto group = db.users().insertGroup(); UserDto lovelace = db.users().insertUser(newUserDto().setLogin("ada.login").setName("Ada Lovelace")); db.organizations().addMember(db.getDefaultOrganization(), lovelace); @@ -122,7 +122,7 @@ public class UsersActionTest { loginAsAdminOnDefaultOrganization(); String result = newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() .getInput(); @@ -196,7 +196,7 @@ public class UsersActionTest { db.users().insertMember(group, graceHopper); loginAsAdminOnDefaultOrganization(); - String response = newUsersRequest().setParam(PARAM_GROUP_ID, group.getId().toString()).execute().getInput(); + String response = newUsersRequest().setParam(PARAM_GROUP_ID, group.getUuid()).execute().getInput(); assertThat(response).contains("Ada Lovelace", "Grace Hopper"); } @@ -212,7 +212,7 @@ public class UsersActionTest { loginAsAdminOnDefaultOrganization(); assertJson(newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .execute() .getInput()).isSimilarTo("{\n" + " \"users\": [\n" + @@ -221,7 +221,7 @@ public class UsersActionTest { "}"); assertJson(newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam(Param.SELECTED, SelectionMode.SELECTED.value()) .execute() .getInput()).isSimilarTo("{\n" + @@ -242,7 +242,7 @@ public class UsersActionTest { loginAsAdminOnDefaultOrganization(); String result = newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam(Param.SELECTED, SelectionMode.DESELECTED.value()) .execute() .getInput(); @@ -265,7 +265,7 @@ public class UsersActionTest { loginAsAdminOnDefaultOrganization(); assertJson(newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("ps", "1") .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() @@ -279,7 +279,7 @@ public class UsersActionTest { "}"); assertJson(newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("ps", "1") .setParam("p", "2") .setParam(Param.SELECTED, SelectionMode.ALL.value()) @@ -305,7 +305,7 @@ public class UsersActionTest { loginAsAdminOnDefaultOrganization(); assertJson(newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam("q", "ace") .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() @@ -316,7 +316,7 @@ public class UsersActionTest { " ]\n" + "}\n"); - assertJson(newUsersRequest().setParam("id", group.getId().toString()) + assertJson(newUsersRequest().setParam("id", group.getUuid()) .setParam("q", ".logi") .execute() .getInput()).isSimilarTo("{\n" + @@ -329,7 +329,7 @@ public class UsersActionTest { " ]\n" + "}\n"); - assertJson(newUsersRequest().setParam("id", group.getId().toString()) + assertJson(newUsersRequest().setParam("id", group.getUuid()) .setParam("q", "OvE") .execute() .getInput()).isSimilarTo("{\n" + @@ -342,7 +342,7 @@ public class UsersActionTest { " ]\n" + "}\n"); - assertJson(newUsersRequest().setParam("id", group.getId().toString()) + assertJson(newUsersRequest().setParam("id", group.getUuid()) .setParam("q", "mail") .execute() .getInput()).isSimilarTo("{\n" + @@ -368,7 +368,7 @@ public class UsersActionTest { loginAsAdminOnDefaultOrganization(); String result = newUsersRequest() - .setParam("id", group.getId().toString()) + .setParam("id", group.getUuid()) .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() .getInput(); |