From 33acda7596369ed1bffbcd25b8d0d590fa87be49 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 11 Feb 2017 15:29:08 +0100 Subject: [PATCH] Fix integer type of user and group ids User IDs are INTEGER in database. The java classes are fixed to replace long by int. --- .../v62/PopulateOrganizationUuidOfGroups.java | 4 +- ...OrganizationUuidOfPermissionTemplates.java | 4 +- .../v61/PopulateTableProperties2Test.java | 11 ++-- .../PopulateIsRootColumnOnTableUsersTest.java | 34 +++++----- .../server/component/ComponentUpdater.java | 4 +- .../DefaultRubyComponentService.java | 4 +- .../computation/queue/ReportSubmitter.java | 5 +- .../server/favorite/FavoriteUpdater.java | 6 +- .../sonar/server/favorite/ws/AddAction.java | 2 +- .../server/favorite/ws/RemoveAction.java | 2 +- .../notification/NotificationUpdater.java | 4 +- .../organization/OrganizationCreation.java | 2 +- .../OrganizationCreationImpl.java | 4 +- .../server/organization/ws/CreateAction.java | 2 +- .../permission/PermissionTemplateService.java | 6 +- .../org/sonar/server/permission/UserId.java | 6 +- .../index/PermissionIndexerDao.java | 16 ++--- .../server/permission/ws/GroupsAction.java | 8 +-- .../permission/ws/PermissionWsSupport.java | 2 +- .../server/permission/ws/UsersAction.java | 4 +- .../ws/template/TemplateGroupsAction.java | 6 +- .../ws/template/TemplateUsersAction.java | 2 +- .../sonar/server/project/ws/CreateAction.java | 2 +- .../ws/SearchMyProjectsDataLoader.java | 2 +- .../sonar/server/usergroups/ws/GroupId.java | 6 +- .../server/usergroups/ws/GroupIdOrAnyone.java | 6 +- .../server/usergroups/ws/GroupWsRef.java | 20 +++--- .../server/usergroups/ws/GroupWsSupport.java | 2 +- .../server/usergroups/ws/SearchAction.java | 2 +- .../server/usergroups/ws/UpdateAction.java | 2 +- .../authentication/SsoAuthenticatorTest.java | 2 +- .../component/ComponentUpdaterTest.java | 2 +- .../ws/SearchProjectsActionTest.java | 2 +- .../queue/ReportSubmitterTest.java | 8 +-- .../server/favorite/FavoriteUpdaterTest.java | 2 +- .../server/favorite/ws/AddActionTest.java | 4 +- .../server/favorite/ws/SearchActionTest.java | 4 +- .../OrganizationCreationImplTest.java | 4 +- .../organization/ws/CreateActionTest.java | 3 +- .../PermissionTemplateServiceTest.java | 2 +- .../ws/template/ApplyTemplateActionTest.java | 2 +- .../template/BulkApplyTemplateActionTest.java | 2 +- .../RemoveGroupFromTemplateActionTest.java | 2 +- .../template/SearchTemplatesActionTest.java | 4 +- .../ws/template/TemplateGroupsActionTest.java | 2 +- .../server/project/ws/CreateActionTest.java | 8 +-- .../server/setting/ws/SetActionTest.java | 8 +-- .../usergroups/ws/DeleteActionTest.java | 2 +- .../server/usergroups/ws/GroupWsRefTest.java | 14 ++-- .../db/organization/OrganizationDto.java | 6 +- .../sonar/db/permission/AuthorizationDao.java | 20 +++--- .../db/permission/AuthorizationMapper.java | 16 ++--- .../db/permission/GroupPermissionDao.java | 8 +-- .../db/permission/GroupPermissionDto.java | 6 +- .../db/permission/GroupPermissionMapper.java | 8 +-- .../db/permission/UserPermissionDao.java | 10 +-- .../db/permission/UserPermissionDto.java | 6 +- .../db/permission/UserPermissionMapper.java | 8 +-- .../template/PermissionTemplateDao.java | 14 ++-- .../template/PermissionTemplateGroupDto.java | 6 +- .../template/PermissionTemplateMapper.java | 6 +- .../template/PermissionTemplateUserDto.java | 6 +- .../org/sonar/db/property/PropertiesDao.java | 2 +- .../sonar/db/property/PropertiesMapper.java | 8 +-- .../org/sonar/db/property/PropertyDto.java | 6 +- .../sonar/db/property/PropertyTesting.java | 4 +- .../main/java/org/sonar/db/user/GroupDao.java | 6 +- .../main/java/org/sonar/db/user/GroupDto.java | 6 +- .../java/org/sonar/db/user/GroupMapper.java | 8 +-- .../org/sonar/db/user/GroupMembershipDao.java | 8 +-- .../org/sonar/db/user/GroupMembershipDto.java | 6 +- .../sonar/db/user/GroupMembershipMapper.java | 4 +- .../main/java/org/sonar/db/user/RoleDao.java | 4 +- .../java/org/sonar/db/user/RoleMapper.java | 4 +- .../main/java/org/sonar/db/user/UserDao.java | 6 +- .../main/java/org/sonar/db/user/UserDto.java | 6 +- .../java/org/sonar/db/user/UserGroupDao.java | 4 +- .../java/org/sonar/db/user/UserGroupDto.java | 12 ++-- .../org/sonar/db/user/UserGroupMapper.java | 4 +- .../java/org/sonar/db/user/UserMapper.java | 12 ++-- .../org/sonar/db/user/UserMembershipDto.java | 6 +- .../sonar/db/user/UserMembershipQuery.java | 8 +-- .../db/permission/AuthorizationMapper.xml | 30 ++++----- .../db/permission/GroupPermissionMapper.xml | 10 +-- .../db/permission/UserPermissionMapper.xml | 10 +-- .../template/PermissionTemplateMapper.xml | 6 +- .../sonar/db/property/PropertiesMapper.xml | 14 ++-- .../org/sonar/db/user/GroupMapper.xml | 8 +-- .../sonar/db/user/GroupMembershipMapper.xml | 4 +- .../org/sonar/db/user/RoleMapper.xml | 12 ++-- .../org/sonar/db/user/UserGroupMapper.xml | 12 ++-- .../org/sonar/db/user/UserMapper.xml | 22 +++---- .../sonar/db/favorite/FavoriteDbTester.java | 4 +- .../db/notification/NotificationDbTester.java | 4 +- .../db/organization/OrganizationDaoTest.java | 4 +- .../db/permission/AuthorizationDaoTest.java | 16 ++--- .../db/permission/GroupPermissionDaoTest.java | 16 ++--- .../GroupWithPermissionTemplateDaoTest.java | 4 +- .../template/PermissionTemplateDaoTest.java | 8 +-- .../template/PermissionTemplateDbTester.java | 4 +- .../sonar/db/property/PropertiesDaoTest.java | 42 ++++++------ .../org/sonar/db/property/PropertiesRow.java | 6 +- .../db/property/PropertiesRowAssert.java | 5 +- .../sonar/db/property/PropertyDtoTest.java | 2 +- .../java/org/sonar/db/user/GroupDaoTest.java | 2 +- .../sonar/db/user/GroupMembershipDaoTest.java | 66 +++++++++---------- .../java/org/sonar/db/user/GroupTesting.java | 3 +- .../java/org/sonar/db/user/RoleDaoTest.java | 2 +- .../java/org/sonar/db/user/UserDaoTest.java | 8 +-- .../java/org/sonar/db/user/UserDbTester.java | 4 +- .../org/sonar/db/user/UserGroupDaoTest.java | 4 +- .../java/org/sonar/db/user/UserTesting.java | 8 +-- 112 files changed, 422 insertions(+), 419 deletions(-) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfGroups.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfGroups.java index e834084c2ab..3c14db9a7ef 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfGroups.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfGroups.java @@ -49,10 +49,10 @@ public class PopulateOrganizationUuidOfGroups extends DataChange { massUpdate.update("update groups set organization_uuid=?, updated_at=? where id=?"); massUpdate.rowPluralName("groups"); massUpdate.execute((row, update) -> { - long groupId = row.getLong(1); + int groupId = row.getInt(1); update.setString(1, organizationUuid); update.setDate(2, new Date(system2.now())); - update.setLong(3, groupId); + update.setInt(3, groupId); return true; }); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfPermissionTemplates.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfPermissionTemplates.java index a863f0e1e6f..74f2208a91d 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfPermissionTemplates.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v62/PopulateOrganizationUuidOfPermissionTemplates.java @@ -49,10 +49,10 @@ public class PopulateOrganizationUuidOfPermissionTemplates extends DataChange { massUpdate.update("update permission_templates set organization_uuid=?, updated_at=? where id=?"); massUpdate.rowPluralName("permission_templates"); massUpdate.execute((row, update) -> { - long groupId = row.getLong(1); + int groupId = row.getInt(1); update.setString(1, organizationUuid); update.setDate(2, new Date(system2.now())); - update.setLong(3, groupId); + update.setInt(3, groupId); return true; }); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v61/PopulateTableProperties2Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v61/PopulateTableProperties2Test.java index e13fd5f7f33..37b9eb93470 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v61/PopulateTableProperties2Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v61/PopulateTableProperties2Test.java @@ -235,8 +235,9 @@ public class PopulateTableProperties2Test { " user_id as \"userId\", resource_id as \"resourceId\", is_empty as \"isEmpty\", text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\"" + " from properties2" + " where prop_key='" + key + "'"); + Long userId = (Long) row.get("userId"); return new Property2( - (Long) row.get("userId"), + userId == null ? null : userId.intValue(), (Long) row.get("resourceId"), isEmpty(row), (String) row.get("textValue"), @@ -266,7 +267,7 @@ public class PopulateTableProperties2Test { return this; } - public Property2Assert hasUserId(long expected) { + public Property2Assert hasUserId(int expected) { isNotNull(); if (!Objects.equals(actual.getUserId(), expected)) { @@ -357,14 +358,14 @@ public class PopulateTableProperties2Test { } private static final class Property2 { - private final Long userId; + private final Integer userId; private final Long resourceId; private final Boolean empty; private final String textValue; private final String clobValue; private final Long createdAt; - private Property2(@Nullable Long userId, @Nullable Long resourceId, + private Property2(@Nullable Integer userId, @Nullable Long resourceId, @Nullable Boolean empty, @Nullable String textValue, @Nullable String clobValue, @Nullable Long createdAt) { this.userId = userId; @@ -375,7 +376,7 @@ public class PopulateTableProperties2Test { this.createdAt = createdAt; } - public Long getUserId() { + public Integer getUserId() { return userId; } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/PopulateIsRootColumnOnTableUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/PopulateIsRootColumnOnTableUsersTest.java index 6243e4b7c3b..1e86c29ef41 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/PopulateIsRootColumnOnTableUsersTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/PopulateIsRootColumnOnTableUsersTest.java @@ -66,7 +66,7 @@ public class PopulateIsRootColumnOnTableUsersTest { @Test public void execute_sets_active_user_with_admin_role_has_root() throws SQLException { - long userId = insertUser("foo", true); + int userId = insertUser("foo", true); insertRole(userId, ROLE_ADMIN); underTest.execute(); @@ -76,7 +76,7 @@ public class PopulateIsRootColumnOnTableUsersTest { @Test public void execute_sets_inactive_user_with_admin_role_has_not_root() throws SQLException { - long userId = insertUser("bar", false); + int userId = insertUser("bar", false); insertRole(userId, ROLE_ADMIN); underTest.execute(); @@ -86,8 +86,8 @@ public class PopulateIsRootColumnOnTableUsersTest { @Test public void execute_sets_active_user_in_group_with_admin_role_has_root() throws SQLException { - long userId = insertUser("doo", true); - long groupId = insertGroup("admin group"); + int userId = insertUser("doo", true); + int groupId = insertGroup("admin group"); insertGroupRole(groupId, ROLE_ADMIN); addUserToGroup(userId, groupId); @@ -98,8 +98,8 @@ public class PopulateIsRootColumnOnTableUsersTest { @Test public void execute_sets_inactive_user_in_group_with_admin_role_has_not_root() throws SQLException { - long userId = insertUser("bar", false); - long groupId = insertGroup("admin group"); + int userId = insertUser("bar", false); + int groupId = insertGroup("admin group"); insertGroupRole(groupId, ROLE_ADMIN); addUserToGroup(userId, groupId); @@ -110,10 +110,10 @@ public class PopulateIsRootColumnOnTableUsersTest { @Test public void migration_is_reentrant() throws SQLException { - long adminGroupId = insertGroup("admin group"); + int adminGroupId = insertGroup("admin group"); insertGroupRole(adminGroupId, ROLE_ADMIN); - long groupId = insertGroup("other group"); - long[] userIds = { + int groupId = insertGroup("other group"); + int[] userIds = { insertUser("inactive_direct_admin", false), insertUser("active_direct_admin", true), insertUser("inactive_group_admin", false), @@ -158,29 +158,31 @@ public class PopulateIsRootColumnOnTableUsersTest { verifyUser("no_perm_user", false); } - private void insertRole(long userId, String role) { + private void insertRole(int userId, String role) { dbTester.executeInsert("user_roles", "user_id", userId, "role", role); dbTester.commit(); } - private long insertUser(String login, boolean active) { + private int insertUser(String login, boolean active) { dbTester.executeInsert(USERS_TABLE, "login", login, "active", active); dbTester.commit(); - return (Long) dbTester.selectFirst("select id as \"id\" from users where login = '" + login + "'").get("id"); + Long userId = (Long) dbTester.selectFirst("select id as \"id\" from users where login = '" + login + "'").get("id"); + return userId.intValue(); } - private long insertGroup(String groupName) { + private int insertGroup(String groupName) { dbTester.executeInsert("groups", "name", groupName); dbTester.commit(); - return (Long) dbTester.selectFirst("select id as \"id\" from groups where name = '" + groupName + "'").get("id"); + Long groupId = (Long) dbTester.selectFirst("select id as \"id\" from groups where name = '" + groupName + "'").get("id"); + return groupId.intValue(); } - private void insertGroupRole(long groupId, String role) { + private void insertGroupRole(int groupId, String role) { dbTester.executeInsert("group_roles", "group_id", groupId, "role", role); dbTester.commit(); } - private void addUserToGroup(long userId, long groupId) { + private void addUserToGroup(int userId, int groupId) { dbTester.executeInsert("groups_users", "user_id", userId, "group_id", groupId); dbTester.commit(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java index 06a12193f57..ab7644b0a07 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -69,7 +69,7 @@ public class ComponentUpdater { * - Add component to favorite if the component has the 'Project Creators' permission * - Index component if es indexes */ - public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable Long userId) { + public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable Integer userId) { checkKeyFormat(newComponent.qualifier(), newComponent.key()); ComponentDto componentDto = createRootComponent(dbSession, newComponent); removeDuplicatedProjects(dbSession, componentDto.getKey()); @@ -119,7 +119,7 @@ public class ComponentUpdater { } } - private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, String organizationUuid, @Nullable Long userId) { + private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, String organizationUuid, @Nullable Integer userId) { permissionTemplateService.applyDefault(dbSession, organizationUuid, componentDto, userId); if (componentDto.qualifier().equals(PROJECT) && permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(dbSession, organizationUuid, componentDto)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java index d60895caf66..6dd19ba92e4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java @@ -48,7 +48,7 @@ public class DefaultRubyComponentService { // Used in GOV /** - * @deprecated Use {@link ComponentUpdater#create(DbSession, NewComponent, Long)} instead + * @deprecated Use {@link ComponentUpdater#create(DbSession, NewComponent, Integer)} instead */ @Deprecated public Long createComponent(String key, String name, String qualifier) { @@ -62,7 +62,7 @@ public class DefaultRubyComponentService { return componentUpdater.create( dbSession, newComponent, - userSession.isLoggedIn() ? userSession.getUserId().longValue() : null).getId(); + userSession.isLoggedIn() ? userSession.getUserId() : null).getId(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/ReportSubmitter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/ReportSubmitter.java index 9f794643c33..3617da10db1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/queue/ReportSubmitter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/queue/ReportSubmitter.java @@ -109,10 +109,9 @@ public class ReportSubmitter { private ComponentDto createProject(DbSession dbSession, String organizationUuid, String projectKey, @Nullable String projectBranch, @Nullable String projectName) { userSession.checkOrganizationPermission(organizationUuid, PROVISIONING); Integer userId = userSession.getUserId(); - Long projectCreatorUserId = userId == null ? null : userId.longValue(); boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate( - dbSession, organizationUuid, projectCreatorUserId, SCAN_EXECUTION, projectBranch, projectKey, Qualifiers.PROJECT); + dbSession, organizationUuid, userId, SCAN_EXECUTION, projectBranch, projectKey, Qualifiers.PROJECT); if (!wouldCurrentUserHaveScanPermission) { throw insufficientPrivilegesException(); } @@ -124,7 +123,7 @@ public class ReportSubmitter { .setBranch(projectBranch) .setQualifier(Qualifiers.PROJECT) .build(); - return componentUpdater.create(dbSession, newProject, projectCreatorUserId); + return componentUpdater.create(dbSession, newProject, userId); } private CeTask submitReport(DbSession dbSession, InputStream reportInput, ComponentDto project) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java index e7708ff3cd1..a4a0dddd856 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java @@ -42,14 +42,14 @@ public class FavoriteUpdater { /** * Set favorite to the logged in user. If no user, no action is done */ - public void add(DbSession dbSession, ComponentDto componentDto, @Nullable Long userId) { + public void add(DbSession dbSession, ComponentDto componentDto, @Nullable Integer userId) { if (userId == null) { return; } List existingFavoriteOnComponent = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) - .setUserId(userId.intValue()) + .setUserId(userId) .setComponentId(componentDto.getId()) .build(), dbSession); checkRequest(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getKey()); @@ -63,7 +63,7 @@ public class FavoriteUpdater { * Remove a favorite to the user. * @throws BadRequestException if the component is not a favorite */ - public void remove(DbSession dbSession, ComponentDto component, @Nullable Long userId) { + public void remove(DbSession dbSession, ComponentDto component, @Nullable Integer userId) { if (userId == null) { return; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/AddAction.java b/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/AddAction.java index 5c89b44dbaf..8625996ef32 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/AddAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/AddAction.java @@ -75,7 +75,7 @@ public class AddAction implements FavoritesWsAction { userSession .checkLoggedIn() .checkComponentPermission(UserRole.USER, componentDto); - favoriteUpdater.add(dbSession, componentDto, userSession.isLoggedIn() ? userSession.getUserId().longValue() : null); + favoriteUpdater.add(dbSession, componentDto, userSession.isLoggedIn() ? userSession.getUserId() : null); dbSession.commit(); } }; diff --git a/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java b/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java index 38a0865d4c3..a749e33d64f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java @@ -73,7 +73,7 @@ public class RemoveAction implements FavoritesWsAction { ComponentDto component = componentFinder.getByKey(dbSession, request.mandatoryParam(PARAM_COMPONENT)); userSession .checkLoggedIn(); - favoriteUpdater.remove(dbSession, component, userSession.isLoggedIn() ? userSession.getUserId().longValue() : null); + favoriteUpdater.remove(dbSession, component, userSession.isLoggedIn() ? userSession.getUserId() : null); dbSession.commit(); } }; diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationUpdater.java index 4e5bf2f8e1f..377c54a37e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationUpdater.java @@ -70,7 +70,7 @@ public class NotificationUpdater { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(key) - .setUserId(Long.valueOf(userSession.getUserId())) + .setUserId(userSession.getUserId()) .setValue(PROP_NOTIFICATION_VALUE) .setResourceId(projectId)); } @@ -100,7 +100,7 @@ public class NotificationUpdater { dbClient.propertiesDao().delete(dbSession, new PropertyDto() .setKey(key) - .setUserId(Long.valueOf(userSession.getUserId())) + .setUserId(userSession.getUserId()) .setValue(PROP_NOTIFICATION_VALUE) .setResourceId(projectId)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreation.java b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreation.java index 518fc0d3134..4f542a461e3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreation.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreation.java @@ -62,7 +62,7 @@ public interface OrganizationCreation { * @throws KeyConflictException if an organization with the specified key already exists * @throws IllegalArgumentException if any field of {@code newOrganization} is invalid according to {@link OrganizationValidation} */ - OrganizationDto create(DbSession dbSession, long createUserId, NewOrganization newOrganization) throws KeyConflictException; + OrganizationDto create(DbSession dbSession, int createUserId, NewOrganization newOrganization) throws KeyConflictException; /** * Create a new guarded organization which details are based on the login of the specified User. diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java index c5333acf0d0..e342fa7ea65 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java @@ -62,7 +62,7 @@ public class OrganizationCreationImpl implements OrganizationCreation { } @Override - public OrganizationDto create(DbSession dbSession, long creatorUserId, NewOrganization newOrganization) throws KeyConflictException { + public OrganizationDto create(DbSession dbSession, int creatorUserId, NewOrganization newOrganization) throws KeyConflictException { validate(newOrganization); String key = newOrganization.getKey(); if (organizationKeyIsUsed(dbSession, key)) { @@ -201,7 +201,7 @@ public class OrganizationCreationImpl implements OrganizationCreation { .setRole(permission)); } - private void addCurrentUserToGroup(DbSession dbSession, GroupDto group, long createUserId) { + private void addCurrentUserToGroup(DbSession dbSession, GroupDto group, int createUserId) { dbClient.userGroupDao().insert( dbSession, new UserGroupDto().setGroupId(group.getId()).setUserId(createUserId)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java index ae7e2440dff..58fe96f8865 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/CreateAction.java @@ -103,7 +103,7 @@ public class CreateAction implements OrganizationsAction { organizationFlags.checkEnabled(dbSession); OrganizationDto organization = organizationCreation.create( dbSession, - userSession.getUserId().longValue(), + userSession.getUserId(), newOrganizationBuilder() .setName(name) .setKey(key) diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index 19cefb2c7e0..a8c51c35f53 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -70,7 +70,7 @@ public class PermissionTemplateService { } public boolean wouldUserHavePermissionWithDefaultTemplate(DbSession dbSession, - String organizationUuid, @Nullable Long userId, String globalPermission, @Nullable String branch, String projectKey, + String organizationUuid, @Nullable Integer userId, String globalPermission, @Nullable String branch, String projectKey, String qualifier) { if (userSession.hasOrganizationPermission(organizationUuid, globalPermission)) { return true; @@ -109,7 +109,7 @@ public class PermissionTemplateService { * can be provisioned (so has no permissions yet). * @param projectCreatorUserId id of the user who creates the project, only if project is provisioned. He will */ - public void applyDefault(DbSession dbSession, String organizationUuid, ComponentDto component, @Nullable Long projectCreatorUserId) { + public void applyDefault(DbSession dbSession, String organizationUuid, ComponentDto component, @Nullable Integer projectCreatorUserId) { PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, component); checkArgument(template != null, "Cannot retrieve default permission template"); copyPermissions(dbSession, template, component, projectCreatorUserId); @@ -131,7 +131,7 @@ public class PermissionTemplateService { permissionIndexer.indexProjectsByUuids(dbSession, projectOrViewUuids); } - private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Long projectCreatorUserId) { + private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Integer projectCreatorUserId) { dbClient.resourceDao().updateAuthorizationDate(project.getId(), dbSession); dbClient.groupPermissionDao().deleteByRootComponentId(dbSession, project.getId()); dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.getId()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/UserId.java b/server/sonar-server/src/main/java/org/sonar/server/permission/UserId.java index fab7ee941bc..ee7d3085fb2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/UserId.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/UserId.java @@ -32,15 +32,15 @@ import static java.util.Objects.requireNonNull; @Immutable public class UserId { - private final long id; + private final int id; private final String login; - public UserId(long userId, String login) { + public UserId(int userId, String login) { this.id = userId; this.login = requireNonNull(login); } - public long getId() { + public int getId() { return id; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java b/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java index 45898f37d6c..a98674b4fba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java @@ -44,8 +44,8 @@ public class PermissionIndexerDao { private final String projectUuid; private final long updatedAt; private final String qualifier; - private final List userIds = new ArrayList<>(); - private final List groupIds = new ArrayList<>(); + private final List userIds = new ArrayList<>(); + private final List groupIds = new ArrayList<>(); private boolean allowAnyone = false; public Dto(String projectUuid, long updatedAt, String qualifier) { @@ -66,21 +66,21 @@ public class PermissionIndexerDao { return qualifier; } - public List getUserIds() { + public List getUserIds() { return userIds; } - public Dto addUserId(long l) { + public Dto addUserId(int l) { userIds.add(l); return this; } - public Dto addGroupId(long id) { + public Dto addGroupId(int id) { groupIds.add(id); return this; } - public List getGroupIds() { + public List getGroupIds() { return groupIds; } @@ -222,10 +222,10 @@ public class PermissionIndexerDao { } switch (rowKind) { case USER: - dto.addUserId(rs.getLong(3)); + dto.addUserId(rs.getInt(3)); break; case GROUP: - dto.addGroupId(rs.getLong(4)); + dto.addGroupId(rs.getInt(4)); break; case ANYONE: dto.allowAnyone(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java index aa6f72a2ced..77f576ce6d0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java @@ -126,14 +126,14 @@ public class GroupsAction implements PermissionsWsAction { } private static WsGroupsResponse buildResponse(List groups, List groupPermissions, Paging paging) { - Multimap permissionsByGroupId = TreeMultimap.create(); + Multimap permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getRole())); WsGroupsResponse.Builder response = WsGroupsResponse.newBuilder(); groups.forEach(group -> { Group.Builder wsGroup = response.addGroupsBuilder() .setName(group.getName()); - if (group.getId() != 0L) { + if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } setNullable(group.getDescription(), wsGroup::setDescription); @@ -152,7 +152,7 @@ public class GroupsAction implements PermissionsWsAction { List orderedNames = dbClient.groupPermissionDao().selectGroupNamesByQuery(dbSession, org.getUuid(), dbQuery); List groups = dbClient.groupDao().selectByNames(dbSession, org.getUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { - groups.add(0, new GroupDto().setId(0L).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); + groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); } @@ -161,7 +161,7 @@ public class GroupsAction implements PermissionsWsAction { if (groups.isEmpty()) { return emptyList(); } - List ids = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size())); + List ids = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size())); return dbClient.groupPermissionDao().selectByGroupIds(dbSession, org.getUuid(), ids, project.isPresent() ? project.get().getId() : null); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index b2afcfb4794..f5f16d1d08b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -81,7 +81,7 @@ public class PermissionWsSupport { } public GroupIdOrAnyone findGroup(DbSession dbSession, Request request) { - Long groupId = request.paramAsLong(PARAM_GROUP_ID); + Integer groupId = request.paramAsInt(PARAM_GROUP_ID); String orgKey = request.param(PARAM_ORGANIZATION); String groupName = request.param(PARAM_GROUP_NAME); GroupWsRef groupRef = GroupWsRef.create(groupId, orgKey, groupName); diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java index 62aa24d3b7a..57f136db6fa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java @@ -139,7 +139,7 @@ public class UsersAction implements PermissionsWsAction { } private static UsersWsResponse buildResponse(List users, List userPermissions, Paging paging) { - Multimap permissionsByUserId = TreeMultimap.create(); + Multimap permissionsByUserId = TreeMultimap.create(); userPermissions.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(), userPermission.getPermission())); UsersWsResponse.Builder response = UsersWsResponse.newBuilder(); @@ -161,7 +161,7 @@ public class UsersAction implements PermissionsWsAction { } private List findUsers(DbSession dbSession, OrganizationDto org, PermissionQuery query) { - List orderedIds = dbClient.userPermissionDao().selectUserIds(dbSession, org.getUuid(), query); + List orderedIds = dbClient.userPermissionDao().selectUserIds(dbSession, org.getUuid(), query); return Ordering.explicit(orderedIds).onResultOf(UserDto::getId).immutableSortedCopy(dbClient.userDao().selectByIds(dbSession, orderedIds)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java index 99bd59fba19..ca6c180a9f5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateGroupsAction.java @@ -80,14 +80,14 @@ public class TemplateGroupsAction implements PermissionsWsAction { } private static WsPermissions.WsGroupsResponse buildResponse(List groups, List groupPermissions, Paging paging) { - Multimap permissionsByGroupId = TreeMultimap.create(); + Multimap permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getPermission())); WsPermissions.WsGroupsResponse.Builder response = WsPermissions.WsGroupsResponse.newBuilder(); groups.forEach(group -> { WsPermissions.Group.Builder wsGroup = response.addGroupsBuilder() .setName(group.getName()); - if (group.getId() != 0L) { + if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } setNullable(group.getDescription(), wsGroup::setDescription); @@ -143,7 +143,7 @@ public class TemplateGroupsAction implements PermissionsWsAction { List orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getOrganizationUuid(), template.getId()); List groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { - groups.add(0, new GroupDto().setId(0L).setName(DefaultGroups.ANYONE)); + groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE)); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateUsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateUsersAction.java index 1ef850ba541..20afc876451 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateUsersAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/TemplateUsersAction.java @@ -83,7 +83,7 @@ public class TemplateUsersAction implements PermissionsWsAction { } private static WsPermissions.UsersWsResponse buildResponse(List users, List permissionTemplateUsers, Paging paging) { - Multimap permissionsByUserId = TreeMultimap.create(); + Multimap permissionsByUserId = TreeMultimap.create(); permissionTemplateUsers.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(), userPermission.getPermission())); UsersWsResponse.Builder responseBuilder = UsersWsResponse.newBuilder(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java index 07fd764887a..f89f27aa899 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java @@ -112,7 +112,7 @@ public class CreateAction implements ProjectsWsAction { .setBranch(request.getBranch()) .setQualifier(PROJECT) .build(), - userSession.isLoggedIn() ? userSession.getUserId().longValue() : null); + userSession.isLoggedIn() ? userSession.getUserId() : null); return toCreateResponse(componentDto); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java index f360edeaca6..be0e6630dda 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java @@ -76,7 +76,7 @@ public class SearchMyProjectsDataLoader { @VisibleForTesting ProjectsResult searchProjects(DbSession dbSession, SearchMyProjectsRequest request) { - long userId = requireNonNull(userSession.getUserId(), "Current user must be authenticated"); + int userId = requireNonNull(userSession.getUserId(), "Current user must be authenticated"); List componentIds = dbClient.roleDao().selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, userId); ComponentQuery dbQuery = ComponentQuery.builder() diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupId.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupId.java index 714b15b30d6..5421c6e9299 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupId.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupId.java @@ -34,15 +34,15 @@ import static java.util.Objects.requireNonNull; @Immutable public class GroupId { - private final long id; + private final int id; private final String organizationUuid; - public GroupId(String organizationUuid, long id) { + public GroupId(String organizationUuid, int id) { this.id = id; this.organizationUuid = requireNonNull(organizationUuid); } - public long getId() { + public int getId() { return id; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupIdOrAnyone.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupIdOrAnyone.java index 0d2094e582b..cf3a6e4ed80 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupIdOrAnyone.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupIdOrAnyone.java @@ -37,10 +37,10 @@ import static java.util.Objects.requireNonNull; @Immutable public class GroupIdOrAnyone { - private final Long id; + private final Integer id; private final String organizationUuid; - public GroupIdOrAnyone(String organizationUuid, @Nullable Long id) { + public GroupIdOrAnyone(String organizationUuid, @Nullable Integer id) { this.id = id; this.organizationUuid = requireNonNull(organizationUuid); } @@ -55,7 +55,7 @@ public class GroupIdOrAnyone { } @CheckForNull - public Long getId() { + public Integer getId() { return id; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java index b880ff20505..a3d4487ee2d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java @@ -44,11 +44,11 @@ public class GroupWsRef { private static final int NULL_ID = -1; - private final long id; + private final int id; private final String organizationKey; private final String name; - private GroupWsRef(long id, @Nullable String organizationKey, @Nullable String name) { + private GroupWsRef(int id, @Nullable String organizationKey, @Nullable String name) { this.id = id; this.organizationKey = organizationKey; this.name = name; @@ -67,7 +67,7 @@ public class GroupWsRef { * @return the group id * @throws IllegalStateException if {@link #getId()} is {@code false} */ - public long getId() { + public int getId() { checkState(hasId(), "Id is not present. Please see hasId()."); return id; } @@ -95,7 +95,7 @@ public class GroupWsRef { * 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. */ - static GroupWsRef fromId(long id) { + static GroupWsRef fromId(int id) { checkArgument(id > -1, "Group id must be positive: %s", id); return new GroupWsRef(id, null, null); } @@ -111,7 +111,7 @@ public class GroupWsRef { return new GroupWsRef(NULL_ID, organizationKey, requireNonNull(name)); } - public static GroupWsRef create(@Nullable Long id, @Nullable String organizationKey, @Nullable String name) { + public static GroupWsRef create(@Nullable Integer id, @Nullable String organizationKey, @Nullable String name) { if (id != null) { checkRequest(organizationKey == null && name == null, "Either group id or couple organization/group name must be set"); return fromId(id); @@ -133,19 +133,19 @@ public class GroupWsRef { if (o == null || getClass() != o.getClass()) { return false; } - GroupWsRef groupRef = (GroupWsRef) o; - if (id != groupRef.id) { + GroupWsRef that = (GroupWsRef) o; + if (id != that.id) { return false; } - if (organizationKey != null ? !organizationKey.equals(groupRef.organizationKey) : (groupRef.organizationKey != null)) { + if (organizationKey != null ? !organizationKey.equals(that.organizationKey) : (that.organizationKey != null)) { return false; } - return name != null ? name.equals(groupRef.name) : (groupRef.name == null); + return name != null ? name.equals(that.name) : (that.name == null); } @Override public int hashCode() { - int result = (int) (id ^ (id >>> 32)); + int result = id; result = 31 * result + (organizationKey != null ? organizationKey.hashCode() : 0); result = 31 * result + (name != null ? name.hashCode() : 0); return result; diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java index 5bebf0cfc74..d44203d0cbb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java @@ -72,7 +72,7 @@ public class GroupWsSupport { * or if the virtual group "Anyone" is requested. */ public GroupId findGroup(DbSession dbSession, Request request) { - Long id = request.paramAsLong(PARAM_GROUP_ID); + Integer id = request.paramAsInt(PARAM_GROUP_ID); String organizationKey = request.param(PARAM_ORGANIZATION_KEY); String name = request.param(PARAM_GROUP_NAME); return findGroup(dbSession, GroupWsRef.create(id, organizationKey, name)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java index 53a6f704387..061951dff3c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java @@ -96,7 +96,7 @@ public class SearchAction implements UserGroupsWsAction { int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query); List groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize); - List groupIds = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size())); + List groupIds = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size())); Map userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds); JsonWriter json = response.newJsonWriter().beginObject(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java index fce36e871f5..4b0ba22e96c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java @@ -95,7 +95,7 @@ public class UpdateAction implements UserGroupsWsAction { @Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { - long groupId = request.mandatoryParamAsLong(PARAM_GROUP_ID); + 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); Optional org = dbClient.organizationDao().selectByUuid(dbSession, group.getOrganizationUuid()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java index d1a7cc0f962..1aa98293e7a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/SsoAuthenticatorTest.java @@ -424,7 +424,7 @@ public class SsoAuthenticatorTest { if (expectedGroups.length == 0) { assertThat(db.users().selectGroupIdsOfUser(userDto)).isEmpty(); } else { - assertThat(db.users().selectGroupIdsOfUser(userDto)).containsOnly(stream(expectedGroups).map(GroupDto::getId).collect(Collectors.toList()).toArray(new Long[] {})); + assertThat(db.users().selectGroupIdsOfUser(userDto)).containsOnly(stream(expectedGroups).map(GroupDto::getId).collect(Collectors.toList()).toArray(new Integer[] {})); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java index 8ce129bee79..dcb18400303 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java @@ -107,7 +107,7 @@ public class ComponentUpdaterTest { @Test public void should_apply_default_permission_template() throws Exception { - long userId = 42; + int userId = 42; NewComponent project = NewComponent.newComponentBuilder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 8d0d0c852cd..033306fc89c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -440,6 +440,6 @@ public class SearchProjectsActionTest { } private void addFavourite(ComponentDto project) { - dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(Long.valueOf(userSession.getUserId()))); + dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(userSession.getUserId())); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/queue/ReportSubmitterTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/queue/ReportSubmitterTest.java index ce79cd446d2..bc781583e29 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/queue/ReportSubmitterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/queue/ReportSubmitterTest.java @@ -47,7 +47,7 @@ import org.sonar.server.tester.UserSessionRule; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; @@ -142,7 +142,7 @@ public class ReportSubmitterTest { mockSuccessfulPrepareSubmitCall(); ComponentDto createdProject = newProjectDto(organization, PROJECT_UUID).setKey(PROJECT_KEY); when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject); - when(permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), anyLong(), eq(SCAN_EXECUTION), anyString(), + when(permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), anyInt(), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT))) .thenReturn(true); when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), eq(organization.getUuid()), any(ComponentDto.class))).thenReturn(true); @@ -174,7 +174,7 @@ public class ReportSubmitterTest { mockSuccessfulPrepareSubmitCall(); ComponentDto createdProject = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY); when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject); - when(permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), anyLong(), eq(SCAN_EXECUTION), anyString(), + when(permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), anyInt(), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT))) .thenReturn(true); when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), eq(defaultOrganizationUuid), any(ComponentDto.class))).thenReturn(false); @@ -193,7 +193,7 @@ public class ReportSubmitterTest { mockSuccessfulPrepareSubmitCall(); ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY); when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(project); - when(permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), anyLong(), eq(SCAN_EXECUTION), anyString(), + when(permissionTemplateService.wouldUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(defaultOrganizationUuid), anyInt(), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT))) .thenReturn(true); diff --git a/server/sonar-server/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java index 634b1a10d3b..604149dad97 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java @@ -40,7 +40,7 @@ public class FavoriteUpdaterTest { private static final ComponentDto COMPONENT = newProjectDto(OrganizationTesting.newOrganizationDto()) .setId(COMPONENT_ID) .setKey(COMPONENT_KEY); - private static final long USER_ID = 42L; + private static final int USER_ID = 42; @Rule public ExpectedException expectedException = ExpectedException.none(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java index ad7aa92a6b3..4ce86209eef 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java @@ -81,7 +81,7 @@ public class AddActionTest { PropertyDto favorite = favorites.get(0); assertThat(favorite) .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey) - .containsOnly(project.getId(), (long) USER_ID, "favourite"); + .containsOnly(project.getId(), USER_ID, "favourite"); } @Test @@ -100,7 +100,7 @@ public class AddActionTest { PropertyDto favorite = favorites.get(0); assertThat(favorite) .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey) - .containsOnly(file.getId(), (long) USER_ID, "favourite"); + .containsOnly(file.getId(), USER_ID, "favourite"); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java index f74f85be8fb..8d33d924d5a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java @@ -134,8 +134,8 @@ public class SearchActionTest { addComponent(newProjectDto(organizationDto).setKey("K1")); ComponentDto otherUserFavorite = newProjectDto(organizationDto).setKey("K42"); db.components().insertComponent(otherUserFavorite); - db.favorites().add(otherUserFavorite, 42L); - dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(organizationDto.getUuid(), UserRole.USER, 42L, otherUserFavorite.getId())); + db.favorites().add(otherUserFavorite, 42); + dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(organizationDto.getUuid(), UserRole.USER, 42, otherUserFavorite.getId())); db.commit(); SearchResponse result = call(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java index 4ebeec9bb31..3ca80415832 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java @@ -50,7 +50,7 @@ import static org.mockito.Mockito.when; import static org.sonar.server.organization.OrganizationCreation.NewOrganization.newOrganizationBuilder; public class OrganizationCreationImplTest { - private static final long SOME_USER_ID = 1L; + private static final int SOME_USER_ID = 1; private static final String SOME_UUID = "org-uuid"; private static final long SOME_DATE = 12893434L; private static final String A_LOGIN = "a-login"; @@ -316,7 +316,7 @@ public class OrganizationCreationImplTest { .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission) .containsOnly( tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), - tuple(0L, UserRole.USER), tuple(0L, UserRole.CODEVIEWER)); + tuple(0, UserRole.USER), tuple(0, UserRole.CODEVIEWER)); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java index 96f8cb318bd..50ba6976f19 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/CreateActionTest.java @@ -32,7 +32,6 @@ import org.sonar.api.config.MapSettings; import org.sonar.api.config.Settings; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; -import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; import org.sonar.api.web.UserRole; import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.util.UuidFactory; @@ -488,7 +487,7 @@ public class CreateActionTest { .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission) .containsOnly( tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), - tuple(0L, UserRole.USER), tuple(0L, UserRole.CODEVIEWER)); + tuple(0, UserRole.USER), tuple(0, UserRole.CODEVIEWER)); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index 899bfa7ac6e..8878364935d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -149,7 +149,7 @@ public class PermissionTemplateServiceTest { checkWouldUserHavePermission(dbTester.getDefaultOrganization(), null, UserRole.ADMIN, false); } - private void checkWouldUserHavePermission(OrganizationDto organization, @Nullable Long userId, String permission, boolean expectedResult) { + private void checkWouldUserHavePermission(OrganizationDto organization, @Nullable Integer userId, String permission, boolean expectedResult) { assertThat(underTest.wouldUserHavePermissionWithDefaultTemplate(session, organization.getUuid(), userId, permission, null, "PROJECT_KEY", Qualifiers.PROJECT)) .isEqualTo(expectedResult); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java index 8d24772fbff..1c5dd22c758 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java @@ -220,7 +220,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest selectProjectPermissionUsers(ComponentDto project, String permission) { + private List selectProjectPermissionUsers(ComponentDto project, String permission) { PermissionQuery query = PermissionQuery.builder().setPermission(permission).setComponentUuid(project.uuid()).build(); return db.getDbClient().userPermissionDao().selectUserIds(db.getSession(), db.getDefaultOrganization().getUuid(), query); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java index 2089cd81956..4f98e2e7371 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java @@ -223,7 +223,7 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest selectProjectPermissionUsers(ComponentDto project, String permission) { + private List selectProjectPermissionUsers(ComponentDto project, String permission) { PermissionQuery query = PermissionQuery.builder().setPermission(permission).setComponentUuid(project.uuid()).build(); return db.getDbClient().userPermissionDao().selectUserIds(db.getSession(), project.getOrganizationUuid(), query); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java index 9d899f06d04..63ce8f422bf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java @@ -187,7 +187,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest argument = ArgumentCaptor.forClass(NewComponent.class); - verify(componentUpdater).create(any(DbSession.class), argument.capture(), anyLong()); + verify(componentUpdater).create(any(DbSession.class), argument.capture(), anyInt()); return argument.getValue(); } private void expectSuccessfulCallToComponentUpdater() { - when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), anyLong())).thenAnswer(invocation -> { + when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), anyInt())).thenAnswer(invocation -> { NewComponent newC = invocation.getArgumentAt(1, NewComponent.class); return new ComponentDto().setKey(newC.key()).setQualifier(newC.qualifier()).setName(newC.name()); }); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index efb9db0f16a..9c33f556537 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -355,13 +355,13 @@ public class SetActionTest { @Test public void user_setting_is_not_updated() { - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserId(42L)); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserId(42)); propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value")); callForGlobalSetting("my.key", "my new global value"); assertGlobalSetting("my.key", "my new global value"); - assertUserSetting("my.key", "my user value", 42L); + assertUserSetting("my.key", "my user value", 42); } @Test @@ -826,8 +826,8 @@ public class SetActionTest { .containsExactly(key, value, null); } - private void assertUserSetting(String key, String value, long userId) { - List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(key).setUserId((int) userId).build(), dbSession); + private void assertUserSetting(String key, String value, int userId) { + List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(key).setUserId(userId).build(), dbSession); assertThat(result).hasSize(1) .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getUserId) diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java index 6893bd8e510..bdfd129a8eb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java @@ -187,7 +187,7 @@ public class DeleteActionTest { public void fail_if_id_does_not_exist() throws Exception { addAdminToDefaultOrganization(); loginAsAdminOnDefaultOrganization(); - long groupId = defaultGroup.getId() + 123; + int groupId = defaultGroup.getId() + 123; expectedException.expect(NotFoundException.class); expectedException.expectMessage("No group with id '" + groupId + "'"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java index be9137105f3..acb2368c709 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/GroupWsRefTest.java @@ -33,9 +33,9 @@ public class GroupWsRefTest { @Test public void test_ref_by_id() { - GroupWsRef ref = GroupWsRef.fromId(10L); + GroupWsRef ref = GroupWsRef.fromId(10); assertThat(ref.hasId()).isTrue(); - assertThat(ref.getId()).isEqualTo(10L); + assertThat(ref.getId()).isEqualTo(10); assertThat(ref.isAnyone()).isFalse(); } @@ -50,11 +50,11 @@ public class GroupWsRefTest { @Test public void test_equals_and_hashCode() { - GroupWsRef refId1 = GroupWsRef.fromId(10L); - GroupWsRef refId2 = GroupWsRef.fromId(11L); + GroupWsRef refId1 = GroupWsRef.fromId(10); + GroupWsRef refId2 = GroupWsRef.fromId(11); assertThat(refId1.equals(refId1)).isTrue(); - assertThat(refId1.equals(GroupWsRef.fromId(10L))).isTrue(); - assertThat(refId1.hashCode()).isEqualTo(GroupWsRef.fromId(10L).hashCode()); + assertThat(refId1.equals(GroupWsRef.fromId(10))).isTrue(); + assertThat(refId1.hashCode()).isEqualTo(GroupWsRef.fromId(10).hashCode()); assertThat(refId1.equals(refId2)).isFalse(); GroupWsRef refName1 = fromName("ORG1", "the-group"); @@ -69,7 +69,7 @@ public class GroupWsRefTest { @Test public void test_toString() { - GroupWsRef refId = GroupWsRef.fromId(10L); + GroupWsRef refId = GroupWsRef.fromId(10); assertThat(refId.toString()).isEqualTo("GroupWsRef{id=10, organizationKey='null', name='null'}"); } diff --git a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java index 79705021095..7ba488b6c16 100644 --- a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java +++ b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java @@ -40,7 +40,7 @@ public class OrganizationDto { */ private boolean guarded = false; /** If of the user for whom the organization was created, can be null. */ - private Long userId; + private Integer userId; private long createdAt; private long updatedAt; @@ -108,11 +108,11 @@ public class OrganizationDto { } @CheckForNull - public Long getUserId() { + public Integer getUserId() { return userId; } - public OrganizationDto setUserId(@Nullable Long userId) { + public OrganizationDto setUserId(@Nullable Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java index 4a168a5a826..6f843f537ed 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java @@ -44,7 +44,7 @@ public class AuthorizationDao implements Dao { /** * Loads all the permissions granted to logged-in user for the specified organization */ - public Set selectOrganizationPermissions(DbSession dbSession, String organizationUuid, long userId) { + public Set selectOrganizationPermissions(DbSession dbSession, String organizationUuid, int userId) { return mapper(dbSession).selectOrganizationPermissions(organizationUuid, userId); } @@ -60,7 +60,7 @@ public class AuthorizationDao implements Dao { * is deleted. The anyone virtual group is not taken into account. */ public int countUsersWithGlobalPermissionExcludingGroup(DbSession dbSession, String organizationUuid, - String permission, long excludedGroupId) { + String permission, int excludedGroupId) { return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroup(organizationUuid, permission, excludedGroupId); } @@ -69,29 +69,29 @@ public class AuthorizationDao implements Dao { * is deleted. The anyone virtual group is not taken into account. */ public int countUsersWithGlobalPermissionExcludingUser(DbSession dbSession, String organizationUuid, - String permission, long excludedUSerId) { - return mapper(dbSession).countUsersWithGlobalPermissionExcludingUser(organizationUuid, permission, excludedUSerId); + String permission, int excludedUserId) { + return mapper(dbSession).countUsersWithGlobalPermissionExcludingUser(organizationUuid, permission, excludedUserId); } /** * 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. - * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, long)}, user + * 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, long groupId, long userId) { + String permission, int groupId, int userId) { return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroupMember(organizationUuid, permission, groupId, userId); } /** * The number of users who will still have the permission if the permission {@code permission} * is removed from user {@code userId}. The anyone virtual group is not taken into account. - * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, long)}, user + * Contrary to {@link #countUsersWithGlobalPermissionExcludingUser(DbSession, String, String, int)}, user * still exists and may have the permission through groups. */ public int countUsersWithGlobalPermissionExcludingUserPermission(DbSession dbSession, String organizationUuid, - String permission, long userId) { + String permission, int userId) { return mapper(dbSession).countUsersWithGlobalPermissionExcludingUserPermission(organizationUuid, permission, userId); } @@ -102,7 +102,7 @@ public class AuthorizationDao implements Dao { *
* Group membership is taken into account. Anonymous privileges are ignored. */ - public Set selectOrganizationUuidsOfUserWithGlobalPermission(DbSession dbSession, long userId, String permission) { + public Set selectOrganizationUuidsOfUserWithGlobalPermission(DbSession dbSession, int userId, String permission) { return mapper(dbSession).selectOrganizationUuidsOfUserWithGlobalPermission(userId, permission); } @@ -131,7 +131,7 @@ public class AuthorizationDao implements Dao { * Keep only authorized user that have the given permission on a given project. * Please Note that if the permission is 'Anyone' is NOT taking into account by thie method. */ - public Collection keepAuthorizedUsersForRoleAndProject(DbSession dbSession, Collection userIds, String role, long projectId) { + public Collection keepAuthorizedUsersForRoleAndProject(DbSession dbSession, Collection userIds, String role, long projectId) { return executeLargeInputs( userIds, partitionOfIds -> mapper(dbSession).keepAuthorizedUsersForRoleAndProject(role, projectId, partitionOfIds)); diff --git a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java index f13bbd37f85..cc5f1f7f1fc 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java @@ -29,28 +29,28 @@ import org.apache.ibatis.annotations.Param; */ public interface AuthorizationMapper { - Set selectOrganizationPermissions(@Param("organizationUuid") String organizationUuid, @Param("userId") long userId); + Set selectOrganizationPermissions(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId); Set selectOrganizationPermissionsOfAnonymous(@Param("organizationUuid") String organizationUuid); int countUsersWithGlobalPermissionExcludingGroup(@Param("organizationUuid") String organizationUuid, - @Param("permission") String permission, @Param("excludedGroupId") long excludedGroupId); + @Param("permission") String permission, @Param("excludedGroupId") int excludedGroupId); int countUsersWithGlobalPermissionExcludingUser(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission, - @Param("excludedUserId") long excludedUserId); + @Param("excludedUserId") int excludedUserId); int countUsersWithGlobalPermissionExcludingGroupMember(@Param("organizationUuid") String organizationUuid, - @Param("permission") String permission, @Param("groupId") long groupId, @Param("userId") long userId); + @Param("permission") String permission, @Param("groupId") int groupId, @Param("userId") int userId); int countUsersWithGlobalPermissionExcludingUserPermission(@Param("organizationUuid") String organizationUuid, - @Param("permission") String permission, @Param("userId") long userId); + @Param("permission") String permission, @Param("userId") int userId); - Set selectOrganizationUuidsOfUserWithGlobalPermission(@Param("userId") long userId, @Param("permission") String permission); + Set selectOrganizationUuidsOfUserWithGlobalPermission(@Param("userId") int userId, @Param("permission") String permission); Set keepAuthorizedProjectIdsForAnonymous(@Param("role") String role, @Param("componentIds") Collection componentIds); - Set keepAuthorizedProjectIdsForUser(@Param("userId") long userId, @Param("role") String role, @Param("componentIds") Collection componentIds); + Set keepAuthorizedProjectIdsForUser(@Param("userId") int userId, @Param("role") String role, @Param("componentIds") Collection componentIds); - List keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentId") long componentId, @Param("userIds") List userIds); + List keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentId") long componentId, @Param("userIds") List userIds); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 4f1680a444d..c8fe45a4cd3 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -60,7 +60,7 @@ public class GroupPermissionDao implements Dao { * Select global or project permission of given groups and organization. Anyone virtual group is supported * through the value "zero" (0L) in {@code groupIds}. */ - public List selectByGroupIds(DbSession dbSession, String organizationUuid, List groupIds, @Nullable Long projectId) { + public List selectByGroupIds(DbSession dbSession, String organizationUuid, List groupIds, @Nullable Long projectId) { return executeLargeInputs(groupIds, groups -> mapper(dbSession).selectByGroupIds(organizationUuid, groups, projectId)); } @@ -84,7 +84,7 @@ 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 selectGlobalPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Long groupId) { + public List selectGlobalPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId) { return mapper(session).selectGlobalPermissionsOfGroup(organizationUuid, groupId); } @@ -92,7 +92,7 @@ public class GroupPermissionDao implements Dao { * Selects the permissions granted to group and project. An empty list is returned if the * group or project do not exist. */ - public List selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Long groupId, long projectId) { + public List selectProjectPermissionsOfGroup(DbSession session, String organizationUuid, @Nullable Integer groupId, long projectId) { return mapper(session).selectProjectPermissionsOfGroup(organizationUuid, groupId, projectId); } @@ -145,7 +145,7 @@ public class GroupPermissionDao implements Dao { * @param groupId if null, then anyone, else id of group * @param rootComponentId if null, then global permission, else id of root component (project) */ - public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Long groupId, @Nullable Long rootComponentId) { + public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Integer groupId, @Nullable Long rootComponentId) { mapper(dbSession).delete(permission, organizationUuid, groupId, rootComponentId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java index f84d5c76aa1..2a1d166b67f 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDto.java @@ -24,11 +24,11 @@ import javax.annotation.Nullable; public class GroupPermissionDto { private String organizationUuid; - private Long groupId; + private Integer groupId; private Long resourceId; private String role; - public Long getGroupId() { + public Integer getGroupId() { return groupId; } @@ -44,7 +44,7 @@ public class GroupPermissionDto { /** * Null when Anyone */ - public GroupPermissionDto setGroupId(@Nullable Long groupId) { + public GroupPermissionDto setGroupId(@Nullable Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index 9c6ebec558f..10484b173d9 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -34,7 +34,7 @@ public interface GroupPermissionMapper { int countGroupsByQuery(@Param("organizationUuid") String organizationUuid, @Param("query") PermissionQuery query); List selectByGroupIds(@Param("organizationUuid") String organizationUuid, - @Param("groupIds") List groupIds, @Nullable @Param("projectId") Long projectId); + @Param("groupIds") List groupIds, @Nullable @Param("projectId") Long projectId); void groupsCountByProjectIdAndPermission(Map parameters, ResultHandler resultHandler); @@ -43,13 +43,13 @@ public interface GroupPermissionMapper { void deleteByRootComponentId(@Param("rootComponentId") long componentId); void delete(@Param("permission") String permission, @Param("organizationUuid") String organizationUuid, - @Nullable @Param("groupId") Long groupId, @Nullable @Param("rootComponentId") Long rootComponentId); + @Nullable @Param("groupId") Integer groupId, @Nullable @Param("rootComponentId") Long rootComponentId); List selectGlobalPermissionsOfGroup(@Param("organizationUuid") String organizationUuid, - @Nullable @Param("groupId") Long groupId); + @Nullable @Param("groupId") Integer groupId); List selectProjectPermissionsOfGroup(@Param("organizationUuid") String organizationUuid, - @Nullable @Param("groupId") Long groupId, @Param("projectId") long projectId); + @Nullable @Param("groupId") Integer groupId, @Param("projectId") long projectId); void deleteByOrganization(@Param("organizationUuid") String organizationUuid); diff --git a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java index 765a7ee03f2..6ae036500f2 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java @@ -58,7 +58,7 @@ public class UserPermissionDao implements Dao { * Shortcut over {@link #select(DbSession, String, PermissionQuery, Collection)} to return only distinct user * ids, keeping the same order. */ - public List selectUserIds(DbSession dbSession, String organizationUuid, PermissionQuery query) { + public List selectUserIds(DbSession dbSession, String organizationUuid, PermissionQuery query) { List dtos = select(dbSession, organizationUuid, query, null); return dtos.stream() .map(UserPermissionDto::getUserId) @@ -87,7 +87,7 @@ public class UserPermissionDao implements Dao { * * @return the global permissions. An empty list is returned if user or organization do not exist. */ - public List selectGlobalPermissionsOfUser(DbSession dbSession, long userId, String organizationUuid) { + public List selectGlobalPermissionsOfUser(DbSession dbSession, int userId, String organizationUuid) { return mapper(dbSession).selectGlobalPermissionsOfUser(userId, organizationUuid); } @@ -96,7 +96,7 @@ public class UserPermissionDao implements Dao { * * @return the project permissions. An empty list is returned if project or user do not exist. */ - public List selectProjectPermissionsOfUser(DbSession dbSession, long userId, long projectId) { + public List selectProjectPermissionsOfUser(DbSession dbSession, int userId, long projectId) { return mapper(dbSession).selectProjectPermissionsOfUser(userId, projectId); } @@ -119,14 +119,14 @@ public class UserPermissionDao implements Dao { /** * Removes a single global permission from user */ - public void deleteGlobalPermission(DbSession dbSession, long userId, String permission, String organizationUuid) { + public void deleteGlobalPermission(DbSession dbSession, int userId, String permission, String organizationUuid) { mapper(dbSession).deleteGlobalPermission(userId, permission, organizationUuid); } /** * Removes a single project permission from user */ - public void deleteProjectPermission(DbSession dbSession, long userId, String permission, long projectId) { + public void deleteProjectPermission(DbSession dbSession, int userId, String permission, long projectId) { mapper(dbSession).deleteProjectPermission(userId, permission, projectId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java index ae561ffe438..6638cd64d16 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDto.java @@ -26,14 +26,14 @@ public class UserPermissionDto { private String organizationUuid; private String permission; - private long userId; + private int userId; private Long componentId; public UserPermissionDto() { // used by MyBatis } - public UserPermissionDto(String organizationUuid, String permission, long userId, @Nullable Long componentId) { + public UserPermissionDto(String organizationUuid, String permission, int userId, @Nullable Long componentId) { this.organizationUuid = organizationUuid; this.permission = permission; this.userId = userId; @@ -44,7 +44,7 @@ public class UserPermissionDto { return permission; } - public long getUserId() { + public int getUserId() { return userId; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java index 2a6c7b32e07..56209760616 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java @@ -48,17 +48,17 @@ public interface UserPermissionMapper { void insert(UserPermissionDto dto); - void deleteGlobalPermission(@Param("userId") long userId, @Param("permission") String permission, + void deleteGlobalPermission(@Param("userId") int userId, @Param("permission") String permission, @Param("organizationUuid") String organizationUuid); - void deleteProjectPermission(@Param("userId") long userId, @Param("permission") String permission, + void deleteProjectPermission(@Param("userId") int userId, @Param("permission") String permission, @Param("projectId") long projectId); void deleteProjectPermissions(@Param("projectId") long projectId); - List selectGlobalPermissionsOfUser(@Param("userId") long userId, @Param("organizationUuid") String organizationUuid); + List selectGlobalPermissionsOfUser(@Param("userId") int userId, @Param("organizationUuid") String organizationUuid); - List selectProjectPermissionsOfUser(@Param("userId") long userId, @Param("projectId") long projectId); + List selectProjectPermissionsOfUser(@Param("userId") int userId, @Param("projectId") long projectId); void deleteByOrganization(@Param("organizationUuid") String organizationUuid); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java index 061a547d095..a2aed9311f4 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java @@ -88,7 +88,7 @@ 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, long templateId, String permission, @Nullable Long groupId) { + public boolean hasGroupsWithPermission(DbSession dbSession, long templateId, String permission, @Nullable Integer groupId) { return mapper(dbSession).countGroupsWithPermission(templateId, permission, groupId) > 0; } @@ -157,7 +157,7 @@ public class PermissionTemplateDao implements Dao { return permissionTemplate; } - public void insertUserPermission(DbSession session, Long templateId, Long userId, String permission) { + public void insertUserPermission(DbSession session, Long templateId, Integer userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() .setTemplateId(templateId) .setUserId(userId) @@ -169,7 +169,7 @@ public class PermissionTemplateDao implements Dao { session.commit(); } - public void deleteUserPermission(DbSession session, Long templateId, Long userId, String permission) { + public void deleteUserPermission(DbSession session, Long templateId, Integer userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() .setTemplateId(templateId) .setPermission(permission) @@ -178,7 +178,7 @@ public class PermissionTemplateDao implements Dao { session.commit(); } - public void insertGroupPermission(DbSession session, long templateId, @Nullable Long groupId, String permission) { + public void insertGroupPermission(DbSession session, long templateId, @Nullable Integer groupId, String permission) { PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() .setTemplateId(templateId) .setPermission(permission) @@ -192,7 +192,7 @@ public class PermissionTemplateDao implements Dao { mapper(session).insertGroupPermission(permissionTemplateGroup); } - public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Long groupId, String permission) { + public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Integer groupId, String permission) { PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() .setTemplateId(templateId) .setPermission(permission) @@ -205,14 +205,14 @@ public class PermissionTemplateDao implements Dao { return mapper(dbSession).selectByName(organizationUuid, name.toUpperCase(Locale.ENGLISH)); } - public List selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Long currentUserId, long templateId) { + public List selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Integer currentUserId, long templateId) { return mapper(dbSession).selectPotentialPermissionsByUserIdAndTemplateId(currentUserId, templateId); } /** * Remove a group from all templates (used when removing a group) */ - public void deleteByGroup(DbSession session, long groupId) { + public void deleteByGroup(DbSession session, int groupId) { session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java index 06289c90a73..d37b2a4ebf7 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; public class PermissionTemplateGroupDto { private Long id; private Long templateId; - private Long groupId; + private Integer groupId; private String permission; private String groupName; private Date createdAt; @@ -49,11 +49,11 @@ public class PermissionTemplateGroupDto { return this; } - public Long getGroupId() { + public Integer getGroupId() { return groupId; } - public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) { + public PermissionTemplateGroupDto setGroupId(@Nullable Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java index 59de7f79d84..ddf2c0a4c0d 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java @@ -62,7 +62,7 @@ public interface PermissionTemplateMapper { void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); - void deleteByGroupId(long groupId); + void deleteByGroupId(int groupId); PermissionTemplateDto selectByName(@Param("organizationUuid") String organizationUuid, @Param("name") String name); @@ -81,9 +81,9 @@ public interface PermissionTemplateMapper { void groupsCountByTemplateIdAndPermission(Map parameters, ResultHandler resultHandler); - List selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Long currentUserId, @Param("templateId") long templateId); + List selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Integer currentUserId, @Param("templateId") long templateId); - int countGroupsWithPermission(@Param("templateId") long templateId, @Param("permission") String permission, @Nullable @Param("groupId") Long groupId); + int countGroupsWithPermission(@Param("templateId") long templateId, @Param("permission") String permission, @Nullable @Param("groupId") Integer groupId); List selectTemplateIdsByOrganization(@Param("organizationUuid") String organizationUuid); diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java index 89a0526a684..3db22ae1560 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java @@ -24,7 +24,7 @@ import java.util.Date; public class PermissionTemplateUserDto { private Long id; private Long templateId; - private Long userId; + private Integer userId; private String permission; private String userName; private String userLogin; @@ -49,11 +49,11 @@ public class PermissionTemplateUserDto { return this; } - public Long getUserId() { + public Integer getUserId() { return userId; } - public PermissionTemplateUserDto setUserId(Long userId) { + public PermissionTemplateUserDto setUserId(Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java index 0f6bfe392af..df0d6a383be 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -183,7 +183,7 @@ public class PropertiesDao implements Dao { } private void save(PropertiesMapper mapper, - String key, @Nullable Long userId, @Nullable Long componentId, + String key, @Nullable Integer userId, @Nullable Long componentId, @Nullable String value) { checkKey(key); diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java index e7a5b25d5b0..dd8f6c562b8 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java @@ -46,16 +46,16 @@ public interface PropertiesMapper { List selectDescendantModuleProperties(@Param("moduleUuid") String moduleUuid, @Param(value = "scope") String scope, @Param(value = "excludeDisabled") boolean excludeDisabled); - void insertAsEmpty(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId, + void insertAsEmpty(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId, @Param("now") long now); - void insertAsText(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId, + void insertAsText(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId, @Param("value") String value, @Param("now") long now); - void insertAsClob(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId, + void insertAsClob(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId, @Param("value") String value, @Param("now") long now); - int delete(@Param("key") String key, @Nullable @Param("userId") Long userId, @Nullable @Param("componentId") Long componentId); + int delete(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentId") Long componentId); int deleteById(long id); diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java b/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java index 6e0ebc12e8a..f9cabe4c6e7 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertyDto.java @@ -32,7 +32,7 @@ public class PropertyDto { private String key; private String value; private Long resourceId; - private Long userId; + private Integer userId; public String getKey() { return key; @@ -64,11 +64,11 @@ public class PropertyDto { } @CheckForNull - public Long getUserId() { + public Integer getUserId() { return userId; } - public PropertyDto setUserId(@Nullable Long userId) { + public PropertyDto setUserId(@Nullable Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java b/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java index 14593023ae5..79d4d6fd7d1 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertyTesting.java @@ -74,7 +74,7 @@ public class PropertyTesting { return newPropertyDto(component.getId(), user.getId()); } - private static PropertyDto newPropertyDto(@Nullable Long componentId, @Nullable Long userId) { + private static PropertyDto newPropertyDto(@Nullable Long componentId, @Nullable Integer userId) { String key = String.valueOf(cursor); cursor++; String value = String.valueOf(cursor); @@ -82,7 +82,7 @@ public class PropertyTesting { return newPropertyDto(key, value, componentId, userId); } - private static PropertyDto newPropertyDto(String key, String value, @Nullable Long componentId, @Nullable Long userId) { + private static PropertyDto newPropertyDto(String key, String value, @Nullable Long componentId, @Nullable Integer userId) { PropertyDto propertyDto = new PropertyDto() .setKey(key) .setValue(value); diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java index a046383ecb1..22fb347ada5 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java @@ -59,15 +59,15 @@ public class GroupDao implements Dao { } @CheckForNull - public GroupDto selectById(DbSession dbSession, long groupId) { + public GroupDto selectById(DbSession dbSession, int groupId) { return mapper(dbSession).selectById(groupId); } - public List selectByIds(DbSession dbSession, List ids) { + public List selectByIds(DbSession dbSession, List ids) { return executeLargeInputs(ids, mapper(dbSession)::selectByIds); } - public void deleteById(DbSession dbSession, long groupId) { + public void deleteById(DbSession dbSession, int groupId) { mapper(dbSession).deleteById(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java b/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java index 8077cbd5c23..8156414f47a 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupDto.java @@ -25,18 +25,18 @@ import javax.annotation.Nullable; public class GroupDto { - private Long id; + private Integer id; private String name; private String description; private String organizationUuid; private Date createdAt; private Date updatedAt; - public Long getId() { + public Integer getId() { return id; } - public GroupDto setId(Long id) { + public GroupDto setId(Integer id) { this.id = id; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java index f6a7164b5b8..3f70d26a190 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMapper.java +++ b/sonar-db/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(long groupId); + GroupDto selectById(int groupId); List 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") long groupId); + int countGroupByOrganizationAndId(@Param("organizationUuid") String organizationUuid, @Param("groupId") int groupId); - void deleteById(long groupId); + void deleteById(int groupId); void deleteByOrganization(@Param("organizationUuid") String organizationUuid); @@ -58,5 +58,5 @@ public interface GroupMapper { List selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid); - List selectByIds(@Param("ids") List ids); + List selectByIds(@Param("ids") List ids); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java index 82541371094..bde120c6167 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java @@ -34,12 +34,12 @@ import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class GroupMembershipDao implements Dao { - public List selectGroups(DbSession session, GroupMembershipQuery query, Long userId, int offset, int limit) { + public List selectGroups(DbSession session, GroupMembershipQuery query, Integer userId, int offset, int limit) { Map params = ImmutableMap.of("query", query, "userId", userId); return mapper(session).selectGroups(params, new RowBounds(offset, limit)); } - public int countGroups(DbSession session, GroupMembershipQuery query, Long userId) { + public int countGroups(DbSession session, GroupMembershipQuery query, Integer userId) { Map params = ImmutableMap.of("query", query, "userId", userId); return mapper(session).countGroups(params); } @@ -54,7 +54,7 @@ public class GroupMembershipDao implements Dao { return mapper(session).countMembers(params); } - public Map countUsersByGroups(DbSession session, Collection groupIds) { + public Map countUsersByGroups(DbSession session, Collection groupIds) { Map result = Maps.newHashMap(); executeLargeInputs( groupIds, @@ -69,7 +69,7 @@ public class GroupMembershipDao implements Dao { return result; } - public List selectGroupIdsByUserId(DbSession dbSession, long userId) { + public List selectGroupIdsByUserId(DbSession dbSession, int userId) { return mapper(dbSession).selectGroupIdsByUserId(userId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java index 64de46d6621..1307352fd60 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDto.java @@ -30,7 +30,7 @@ public class GroupMembershipDto { private Long id; private String name; private String description; - private Long userId; + private Integer userId; public Long getId() { return id; @@ -61,11 +61,11 @@ public class GroupMembershipDto { } @CheckForNull - public Long getUserId() { + public Integer getUserId() { return userId; } - public GroupMembershipDto setUserId(@Nullable Long userId) { + public GroupMembershipDto setUserId(@Nullable Integer userId) { this.userId = userId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java index 37d7d6cbab8..6bf021b158e 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipMapper.java @@ -34,10 +34,10 @@ public interface GroupMembershipMapper { int countMembers(Map params); - List countUsersByGroup(@Param("groupIds") List groupIds); + List countUsersByGroup(@Param("groupIds") List groupIds); List selectGroupsByLogins(@Param("logins") List logins); - List selectGroupIdsByUserId(@Param("userId") long userId); + List selectGroupIdsByUserId(@Param("userId") int userId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java b/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java index 717ef99e2b6..66e14f432a1 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java @@ -29,11 +29,11 @@ public class RoleDao implements Dao { * All the projects on which the user has {@code permission}, directly or through * groups. */ - public List selectComponentIdsByPermissionAndUserId(DbSession dbSession, String permission, long userId) { + public List selectComponentIdsByPermissionAndUserId(DbSession dbSession, String permission, int userId) { return mapper(dbSession).selectComponentIdsByPermissionAndUserId(permission, userId); } - public void deleteGroupRolesByGroupId(DbSession session, long groupId) { + public void deleteGroupRolesByGroupId(DbSession session, int groupId) { mapper(session).deleteGroupRolesByGroupId(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java b/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java index 7647ce64934..6e9e45a4b03 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java @@ -24,8 +24,8 @@ import org.apache.ibatis.annotations.Param; public interface RoleMapper { - List selectComponentIdsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") long userId); + List selectComponentIdsByPermissionAndUserId(@Param("permission") String permission, @Param("userId") int userId); - void deleteGroupRolesByGroupId(long groupId); + void deleteGroupRolesByGroupId(int groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserDao.java index 0a87ffddae5..754cb376ef5 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserDao.java @@ -50,13 +50,13 @@ public class UserDao implements Dao { this.system2 = system2; } - public UserDto selectUserById(long userId) { + public UserDto selectUserById(int userId) { try (DbSession session = mybatis.openSession(false)) { return selectUserById(session, userId); } } - public UserDto selectUserById(DbSession session, long userId) { + public UserDto selectUserById(DbSession session, int userId) { return mapper(session).selectUser(userId); } @@ -66,7 +66,7 @@ public class UserDao implements Dao { * * Used by the Governance plugin */ - public List selectByIds(DbSession session, Collection ids) { + public List selectByIds(DbSession session, Collection ids) { return executeLargeInputs(ids, mapper(session)::selectByIds); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java index 445990edca7..7f41ce65250 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserDto.java @@ -37,7 +37,7 @@ import static java.util.Objects.requireNonNull; public class UserDto { public static final char SCM_ACCOUNTS_SEPARATOR = '\n'; - private Long id; + private Integer id; private String login; private String name; private String email; @@ -52,11 +52,11 @@ public class UserDto { private boolean local = true; private boolean root = false; - public Long getId() { + public Integer getId() { return id; } - public UserDto setId(Long id) { + public UserDto setId(Integer id) { this.id = id; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java index edea5484b5c..1e53f6a312e 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java @@ -29,11 +29,11 @@ public class UserGroupDao implements Dao { return dto; } - public void delete(DbSession session, long groupId, long userId) { + public void delete(DbSession session, int groupId, int userId) { mapper(session).delete(groupId, userId); } - public void deleteByGroupId(DbSession session, long groupId) { + public void deleteByGroupId(DbSession session, int groupId) { mapper(session).deleteByGroupId(groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java index e60ae970db1..8e8443bf830 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDto.java @@ -21,23 +21,23 @@ package org.sonar.db.user; public class UserGroupDto { - private Long userId; - private Long groupId; + private int userId; + private int groupId; - public Long getUserId() { + public int getUserId() { return userId; } - public UserGroupDto setUserId(Long userId) { + public UserGroupDto setUserId(int userId) { this.userId = userId; return this; } - public Long getGroupId() { + public int getGroupId() { return groupId; } - public UserGroupDto setGroupId(Long groupId) { + public UserGroupDto setGroupId(int groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java index 7de52e9e736..ce0d053d701 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupMapper.java @@ -25,7 +25,7 @@ public interface UserGroupMapper { void insert(UserGroupDto dto); - void delete(@Param("groupId") long groupId, @Param("userId") long userId); + void delete(@Param("groupId") int groupId, @Param("userId") int userId); - void deleteByGroupId(@Param("groupId") long groupId); + void deleteByGroupId(@Param("groupId") int groupId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java b/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java index b7cf25be54e..eac60d442ea 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserMapper.java @@ -37,7 +37,7 @@ public interface UserMapper { List selectNullableByScmAccountOrLoginOrEmail(@Param("scmAccount") String scmAccountOrLoginOrEmail, @Param("likeScmAccount") String likeScmAccount); @CheckForNull - UserDto selectUser(long userId); + UserDto selectUser(int userId); /** * Select user by login. Note that disabled users are ignored. @@ -49,7 +49,7 @@ public interface UserMapper { List selectByLogins(List logins); - List selectByIds(@Param("ids") List ids); + List selectByIds(@Param("ids") List ids); long countByEmail(String email); @@ -64,14 +64,14 @@ public interface UserMapper { void setRoot(@Param("login") String login, @Param("root") boolean root, @Param("now") long now); - void removeUserFromGroups(long userId); + void removeUserFromGroups(int userId); - void deleteUserProperties(long userId); + void deleteUserProperties(int userId); - void deleteUserRoles(long userId); + void deleteUserRoles(int userId); void deletePropertiesMatchingLogin(@Param("propertyKeys") List propertyKeys, @Param("login") String login); - void deactivateUser(@Param("id") long userId, @Param("now") long now); + void deactivateUser(@Param("id") int userId, @Param("now") long now); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java index 750bc2d2d87..a8b5dd6be1d 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipDto.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; public class UserMembershipDto { private Long id; - private Long groupId; + private Integer groupId; private String login; private String name; @@ -58,11 +58,11 @@ public class UserMembershipDto { } @CheckForNull - public Long getGroupId() { + public Integer getGroupId() { return groupId; } - public UserMembershipDto setGroupId(@Nullable Long groupId) { + public UserMembershipDto setGroupId(@Nullable Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java b/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java index 3cc3d669196..e93513c5191 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserMembershipQuery.java +++ b/sonar-db/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 AVAILABLE_MEMBERSHIPS = ImmutableSet.of(ANY, IN, OUT); - private final long groupId; + private final int groupId; private final String membership; private final String memberSearch; @@ -67,7 +67,7 @@ public class UserMembershipQuery { this.pageIndex = builder.pageIndex; } - public long groupId() { + public int groupId() { return groupId; } @@ -97,7 +97,7 @@ public class UserMembershipQuery { } public static class Builder { - private Long groupId; + private Integer groupId; private String membership; private String memberSearch; @@ -107,7 +107,7 @@ public class UserMembershipQuery { private Builder() { } - public Builder groupId(Long groupId) { + public Builder groupId(Integer groupId) { this.groupId = groupId; return this; } diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml index b3f13d570d4..8df1106fb02 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml @@ -10,7 +10,7 @@ where gr.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and gr.resource_id is null and - gu.user_id=#{userId,jdbcType=BIGINT} + gu.user_id=#{userId,jdbcType=INTEGER} union @@ -27,7 +27,7 @@ from user_roles ur where ur.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and - ur.user_id=#{userId,jdbcType=BIGINT} + ur.user_id=#{userId,jdbcType=INTEGER} and ur.resource_id is null @@ -46,7 +46,7 @@ inner join groups_users gu on gr.group_id=gu.group_id where gr.resource_id=#{rootComponentId,jdbcType=BIGINT} and - gu.user_id=#{userId,jdbcType=BIGINT} + gu.user_id=#{userId,jdbcType=INTEGER} union select gr.role @@ -61,7 +61,7 @@ from user_roles ur where ur.resource_id=#{rootComponentId,jdbcType=BIGINT} and - ur.user_id=#{userId,jdbcType=BIGINT} + ur.user_id=#{userId,jdbcType=INTEGER} @@ -132,7 +132,7 @@ gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - (gu.group_id != #{groupId,jdbcType=BIGINT} or gu.user_id != #{userId,jdbcType=BIGINT}) + (gu.group_id != #{groupId,jdbcType=INTEGER} or gu.user_id != #{userId,jdbcType=INTEGER}) union @@ -165,7 +165,7 @@ ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and ur.resource_id is null and ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id != #{userId,jdbcType=BIGINT} + ur.user_id != #{userId,jdbcType=INTEGER} ) remaining @@ -177,7 +177,7 @@ gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gu.user_id = #{userId,jdbcType=BIGINT} + gu.user_id = #{userId,jdbcType=INTEGER} union @@ -186,7 +186,7 @@ where ur.resource_id is null and ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id = #{userId,jdbcType=BIGINT} + ur.user_id = #{userId,jdbcType=INTEGER} - SELECT gu.user_id FROM groups_users gu INNER JOIN group_roles gr ON gr.group_id=gu.group_id diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index 9d011a5d647..9d90ac5213f 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -98,7 +98,7 @@ where sub.groupId in - #{groupId,jdbcType=BIGINT} + #{groupId,jdbcType=INTEGER} and sub.componentId=#{projectId,jdbcType=BIGINT} @@ -116,7 +116,7 @@ gr.resource_id is null and - gr.group_id = #{groupId,jdbcType=BIGINT} + gr.group_id = #{groupId,jdbcType=INTEGER} gr.group_id is null @@ -132,7 +132,7 @@ gr.resource_id = #{projectId,jdbcType=BIGINT} and - gr.group_id = #{groupId,jdbcType=BIGINT} + gr.group_id = #{groupId,jdbcType=INTEGER} gr.group_id is null @@ -148,7 +148,7 @@ role ) values ( #{organizationUuid,jdbcType=VARCHAR}, - #{groupId,jdbcType=BIGINT}, + #{groupId,jdbcType=INTEGER}, #{resourceId,jdbcType=BIGINT}, #{role,jdbcType=VARCHAR} ) @@ -175,7 +175,7 @@ and - group_id=#{groupId,jdbcType=BIGINT} + group_id=#{groupId,jdbcType=INTEGER} group_id is null diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml index 699ed00d86e..18091c27aa0 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml @@ -58,7 +58,7 @@ from user_roles ur where ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and - ur.user_id = #{userId,jdbcType=BIGINT} and + ur.user_id = #{userId,jdbcType=INTEGER} and ur.resource_id is null @@ -66,7 +66,7 @@ select ur.role from user_roles ur where - ur.user_id = #{userId,jdbcType=BIGINT} and + ur.user_id = #{userId,jdbcType=INTEGER} and ur.resource_id = #{projectId,jdbcType=BIGINT} @@ -88,7 +88,7 @@ role ) values ( #{organizationUuid,jdbcType=VARCHAR}, - #{userId,jdbcType=BIGINT}, + #{userId,jdbcType=INTEGER}, #{componentId,jdbcType=BIGINT}, #{permission,jdbcType=VARCHAR} ) @@ -98,7 +98,7 @@ delete from user_roles where role = #{permission,jdbcType=VARCHAR} and - user_id = #{userId,jdbcType=BIGINT} and + user_id = #{userId,jdbcType=INTEGER} and organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and resource_id is null @@ -107,7 +107,7 @@ delete from user_roles where role = #{permission,jdbcType=VARCHAR} and - user_id = #{userId,jdbcType=BIGINT} and + user_id = #{userId,jdbcType=INTEGER} and resource_id = #{projectId,jdbcType=BIGINT} diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml index 769a0f53907..9220cd6befd 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml @@ -98,16 +98,16 @@ INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at) VALUES ( #{templateId,jdbcType=BIGINT}, - #{groupId,jdbcType=BIGINT}, + #{groupId,jdbcType=INTEGER}, #{permission,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP} ) - + delete from perm_templates_groups - where group_id = #{groupId,jdbcType=BIGINT} + where group_id = #{groupId,jdbcType=INTEGER} @@ -193,7 +193,7 @@ values ( #{key}, #{componentId}, - #{userId}, + #{userId,jdbcType=INTEGER}, ${_true}, #{now} ) @@ -212,7 +212,7 @@ values ( #{key}, #{componentId}, - #{userId}, + #{userId,jdbcType=INTEGER}, ${_false}, #{value}, #{now} @@ -232,7 +232,7 @@ values ( #{key}, #{componentId}, - #{userId}, + #{userId,jdbcType=INTEGER}, ${_false}, #{value}, #{now} @@ -246,7 +246,7 @@ and resource_id=#{componentId} - and user_id=#{userId} + and user_id=#{userId,jdbcType=INTEGER} and resource_id=#{componentId} @@ -254,7 +254,7 @@ and resource_id is null - and user_id=#{userId} + and user_id=#{userId,jdbcType=INTEGER} and resource_id is null @@ -305,7 +305,7 @@ and resource_id=#{query.componentId} - and user_id=#{query.userId} + and user_id=#{query.userId,jdbcType=INTEGER} diff --git a/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml index 4f6928e7b28..89fcbc40313 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml @@ -20,7 +20,7 @@ where g.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and g.name = #{name,jdbcType=VARCHAR} - select from groups g @@ -30,7 +30,7 @@ - SELECT FROM groups g @@ -39,7 +39,7 @@ - + DELETE FROM groups id=#{id,jdbcType=BIGINT} @@ -126,7 +126,7 @@ from groups g where g.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} - and g.id = #{groupId,jdbcType=BIGINT} + and g.id = #{groupId,jdbcType=INTEGER} - 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 @@ -92,7 +92,7 @@ - select group_id from groups_users where user_id = #{userId} diff --git a/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml index 98d5c9cc520..545d512be75 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml @@ -7,8 +7,8 @@ select ur.resource_id from user_roles ur - and ur.user_id = #{userId} - and ur.role = #{permission} + and ur.user_id = #{userId,jdbcType=INTEGER} + and ur.role = #{permission,jdbcType=VARCHAR} and ur.resource_id IS NOT NULL UNION @@ -16,14 +16,14 @@ from group_roles gr inner join groups_users gu on gr.group_id=gu.group_id - and gr.role = #{permission} + and gr.role = #{permission,jdbcType=VARCHAR} and gr.resource_id is not null - and gu.user_id=#{userId} + and gu.user_id=#{userId,jdbcType=INTEGER} ORDER by resource_id - - delete from group_roles where group_id=#{id} + + delete from group_roles where group_id=#{id,jdbcType=INTEGER} diff --git a/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml index c7aaa37af75..4ff5a60ffa3 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/UserGroupMapper.xml @@ -8,20 +8,20 @@ user_id, group_id ) values ( - #{userId,jdbcType=BIGINT}, - #{groupId,jdbcType=BIGINT} + #{userId,jdbcType=INTEGER}, + #{groupId,jdbcType=INTEGER} ) delete from groups_users - where user_id = #{userId,jdbcType=BIGINT} and - group_id = #{groupId,jdbcType=BIGINT} + where user_id = #{userId,jdbcType=INTEGER} and + group_id = #{groupId,jdbcType=INTEGER} - + delete from groups_users - where group_id = #{groupId,jdbcType=BIGINT} + where group_id = #{groupId,jdbcType=INTEGER} diff --git a/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml index 17818753a6a..3989967c5fd 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -37,7 +37,7 @@ OR u.scm_accounts like #{likeScmAccount} - SELECT FROM users u @@ -115,30 +115,30 @@ and u.login <> #{login} - + DELETE FROM groups_users WHERE user_id=#{id} - - DELETE FROM user_roles WHERE user_id=#{id} + + DELETE FROM user_roles WHERE user_id=#{id,jdbcType=INTEGER} - - DELETE FROM properties WHERE user_id=#{id} + + DELETE FROM properties WHERE user_id=#{id,jdbcType=BIGINT} DELETE FROM properties - text_value LIKE #{login} + text_value LIKE #{login,jdbcType=VARCHAR} AND prop_key IN - #{property} + #{property,jdbcType=VARCHAR} - + UPDATE users SET active=${_false}, email=null, @@ -149,7 +149,7 @@ crypted_password=null, updated_at=#{now,jdbcType=BIGINT} WHERE - id=#{id} + id=#{id,jdbcType=INTEGER} @@ -207,7 +207,7 @@ crypted_password=#{cryptedPassword,jdbcType=BIGINT}, updated_at=#{updatedAt,jdbcType=BIGINT} WHERE - login = #{login} + login = #{login,jdbcType=VARCHAR} diff --git a/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java b/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java index a02dd3058b9..20c59786b65 100644 --- a/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java @@ -38,7 +38,7 @@ public class FavoriteDbTester { this.dbSession = db.getSession(); } - public void add(ComponentDto componentDto, long userId) { + public void add(ComponentDto componentDto, int userId) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setUserId(userId) @@ -46,7 +46,7 @@ public class FavoriteDbTester { dbSession.commit(); } - public boolean hasFavorite(ComponentDto componentDto, long userId) { + public boolean hasFavorite(ComponentDto componentDto, int userId) { List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentId(componentDto.getId()) diff --git a/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java b/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java index f897d783bf4..2df3453d9b8 100644 --- a/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java @@ -44,7 +44,7 @@ public class NotificationDbTester { this.dbSession = db.getSession(); } - public void assertExists(String channel, String dispatcher, long userId, @Nullable ComponentDto component) { + public void assertExists(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) @@ -56,7 +56,7 @@ public class NotificationDbTester { assertThat(result.get(0).getValue()).isEqualTo("true"); } - public void assertDoesNotExist(String channel, String dispatcher, long userId, @Nullable ComponentDto component) { + public void assertDoesNotExist(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java index 8a03cb98ad5..49195fba4c2 100644 --- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java @@ -66,7 +66,7 @@ public class OrganizationDaoTest { .setUrl("the url 1") .setAvatarUrl("the avatar url 1") .setGuarded(false) - .setUserId(1_000L); + .setUserId(1_000); private static final OrganizationDto ORGANIZATION_DTO_2 = new OrganizationDto() .setUuid("uuid 2") .setKey("the_key 2") @@ -75,7 +75,7 @@ public class OrganizationDaoTest { .setUrl("the url 2") .setAvatarUrl("the avatar url 2") .setGuarded(true) - .setUserId(2_000L); + .setUserId(2_000); private static final String PERMISSION_1 = "foo"; private static final String PERMISSION_2 = "bar"; diff --git a/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java index 3886c179831..07fbd3988dd 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java @@ -45,7 +45,7 @@ public class AuthorizationDaoTest { private static final int USER = 100; private static final Long PROJECT_ID = 300L; private static final Long PROJECT_ID_WITHOUT_SNAPSHOT = 400L; - private static final long MISSING_ID = -1L; + private static final int MISSING_ID = -1; private static final String A_PERMISSION = "a-permission"; private static final String DOES_NOT_EXIST = "does-not-exist"; @@ -330,14 +330,14 @@ public class AuthorizationDaoTest { assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L); + newHashSet(100, 101, 102), "user", PROJECT_ID)).containsOnly(100, 101); assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L), "user", PROJECT_ID)).containsOnly(100L); + newHashSet(100), "user", PROJECT_ID)).containsOnly(100); // user does not have the role "admin" - assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100L), "admin", PROJECT_ID)).isEmpty(); + assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100), "admin", PROJECT_ID)).isEmpty(); // Empty list assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, Collections.emptySet(), "user", PROJECT_ID)).isEmpty(); @@ -349,13 +349,13 @@ public class AuthorizationDaoTest { assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L); + newHashSet(100, 101, 102), "user", PROJECT_ID)).containsOnly(100, 101); assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, - newHashSet(100L), "user", PROJECT_ID)).containsOnly(100L); + newHashSet(100), "user", PROJECT_ID)).containsOnly(100); // user does not have the role "admin" - assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100L), "admin", PROJECT_ID)).isEmpty(); + assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, newHashSet(100), "admin", PROJECT_ID)).isEmpty(); // Empty list assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, Collections.emptySet(), "user", PROJECT_ID)).isEmpty(); @@ -367,7 +367,7 @@ public class AuthorizationDaoTest { assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).isEmpty(); + newHashSet(100, 101, 102), "user", PROJECT_ID)).isEmpty(); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java index d412c1f594d..bb609fa0092 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java @@ -49,8 +49,8 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto; public class GroupPermissionDaoTest { - private static final long ANYONE_ID = 0L; - private static final long MISSING_ID = -1L; + private static final int ANYONE_ID = 0; + private static final int MISSING_ID = -1; @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -202,8 +202,8 @@ public class GroupPermissionDaoTest { assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().build())) - .doesNotContain(ANYONE) - .containsExactly(group.getName()); + .doesNotContain(ANYONE) + .containsExactly(group.getName()); } @Test @@ -237,8 +237,8 @@ public class GroupPermissionDaoTest { assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(ANYONE_ID), null)) .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId) .containsOnly( - tuple(0L, SCAN_EXECUTION, null), - tuple(0L, PROVISIONING, null)); + tuple(0, SCAN_EXECUTION, null), + tuple(0, PROVISIONING, 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(); @@ -274,7 +274,7 @@ public class GroupPermissionDaoTest { assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId())) .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId) - .containsOnly(tuple(0L, PROVISIONING, project.getId())); + .containsOnly(tuple(0, PROVISIONING, project.getId())); assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2); assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty(); @@ -464,7 +464,7 @@ public class GroupPermissionDaoTest { .containsOnly(organizationUuids); } - private Long insertGroupWithPermissions(OrganizationDto organization1) { + private int insertGroupWithPermissions(OrganizationDto organization1) { GroupDto group = db.users().insertGroup(organization1); db.users().insertPermissionOnGroup(group, "foo"); db.users().insertPermissionOnGroup(group, "bar"); diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java index a86bcbffd6b..3c821f3c8d7 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java @@ -191,7 +191,7 @@ public class GroupWithPermissionTemplateDaoTest { assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, anotherTemplate.getId(), asList("Anyone"))) .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission) .containsOnly( - tuple(0L, "Anyone", USER)); + tuple(0, "Anyone", USER)); assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getId(), asList("Group-1", "Group-2", "Anyone"))).hasSize(3); assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getId(), asList("Unknown"))).isEmpty(); @@ -223,7 +223,7 @@ public class GroupWithPermissionTemplateDaoTest { .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission) .containsOnly( tuple(group1.getId(), "Group-1", PROVISIONING), - tuple(0L, "Anyone", USER)); + tuple(0, "Anyone", USER)); assertThat(underTest.selectGroupPermissionsByTemplateId(session, 321L)).isEmpty(); } diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java index e1eafd638f3..b656c8371c2 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java @@ -149,7 +149,7 @@ public class PermissionTemplateDaoTest { public void should_add_user_permission_to_template() { db.prepareDbUnit(getClass(), "addUserPermissionToTemplate.xml"); - underTest.insertUserPermission(dbSession, 1L, 1L, "new_permission"); + underTest.insertUserPermission(dbSession, 1L, 1, "new_permission"); checkTemplateTables("addUserPermissionToTemplate-result.xml"); } @@ -158,7 +158,7 @@ public class PermissionTemplateDaoTest { public void should_remove_user_permission_from_template() { db.prepareDbUnit(getClass(), "removeUserPermissionFromTemplate.xml"); - underTest.deleteUserPermission(dbSession, 1L, 2L, "permission_to_remove"); + underTest.deleteUserPermission(dbSession, 1L, 2, "permission_to_remove"); checkTemplateTables("removeUserPermissionFromTemplate-result.xml"); } @@ -167,7 +167,7 @@ public class PermissionTemplateDaoTest { public void should_add_group_permission_to_template() { db.prepareDbUnit(getClass(), "addGroupPermissionToTemplate.xml"); - underTest.insertGroupPermission(dbSession, 1L, 1L, "new_permission"); + underTest.insertGroupPermission(dbSession, 1L, 1, "new_permission"); dbSession.commit(); checkTemplateTables("addGroupPermissionToTemplate-result.xml"); @@ -177,7 +177,7 @@ public class PermissionTemplateDaoTest { public void remove_by_group() { db.prepareDbUnit(getClass(), "remove_by_group.xml"); - underTest.deleteByGroup(db.getSession(), 2L); + underTest.deleteByGroup(db.getSession(), 2); db.getSession().commit(); db.assertDbUnitTable(getClass(), "remove_by_group-result.xml", "permission_templates", "id", "name", "kee", "description"); diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java index 8ed57a2bfba..aa4f22b07b6 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java @@ -60,7 +60,7 @@ public class PermissionTemplateDbTester { addGroupToTemplate(permissionTemplate.getId(), group.getId(), permission); } - public void addGroupToTemplate(long templateId, @Nullable Long groupId, String permission) { + public void addGroupToTemplate(long templateId, @Nullable Integer groupId, String permission) { dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateId, groupId, permission); db.commit(); } @@ -73,7 +73,7 @@ public class PermissionTemplateDbTester { addUserToTemplate(permissionTemplate.getId(), user.getId(), permission); } - public void addUserToTemplate(long templateId, long userId, String permission) { + public void addUserToTemplate(long templateId, int userId, String permission) { dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateId, userId, permission); db.commit(); } diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index 570c7d96364..00c8552b381 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -80,9 +80,9 @@ public class PropertiesDaoTest { public void shouldFindUsersForNotification() throws SQLException { ComponentDto project1 = insertProject("uuid_45"); ComponentDto project2 = insertProject("uuid_56"); - long userId1 = insertUser("user1"); - long userId2 = insertUser("user2"); - long userId3 = insertUser("user3"); + int userId1 = insertUser("user1"); + int userId2 = insertUser("user2"); + int userId3 = insertUser("user3"); insertProperty("notification.NewViolations.Email", "true", project1.getId(), userId2); insertProperty("notification.NewViolations.Twitter", "true", null, userId3); insertProperty("notification.NewViolations.Twitter", "true", project2.getId(), userId1); @@ -111,8 +111,8 @@ public class PropertiesDaoTest { @Test public void findNotificationSubscribers() throws SQLException { - long userId1 = insertUser("user1"); - long userId2 = insertUser("user2"); + int userId1 = insertUser("user1"); + int userId2 = insertUser("user2"); ComponentDto projectDto = insertProject("PROJECT_A"); long projectId = projectDto.getId(); String projectKey = projectDto.key(); @@ -148,8 +148,8 @@ public class PropertiesDaoTest { @Test public void hasNotificationSubscribers() throws SQLException { - long userId1 = insertUser("user1"); - long userId2 = insertUser("user2"); + int userId1 = insertUser("user1"); + int userId2 = insertUser("user2"); Long projectId = insertProject("PROJECT_A").getId(); // global subscription insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userId2); @@ -227,7 +227,7 @@ public class PropertiesDaoTest { // project insertProperty("project.one", "one", 10L, null); // user - insertProperty("user.one", "one", null, 100L); + insertProperty("user.one", "one", null, 100); assertThatDto(underTest.selectGlobalProperty("global.one")) .hasNoResourceId() @@ -361,8 +361,8 @@ public class PropertiesDaoTest { // commons insertProperty("commonslang.one", "one", 11L, null); // user - insertProperty("user.one", "one", null, 100L); - insertProperty("user.two", "two", 10L, 100L); + insertProperty("user.one", "one", null, 100); + insertProperty("user.two", "two", 10L, 100); // other insertProperty("other.one", "one", 12L, null); @@ -378,7 +378,7 @@ public class PropertiesDaoTest { @Test public void select_global_properties_by_keys() throws Exception { insertProject("A"); - long userId = insertUser("B"); + int userId = insertUser("B"); String key = "key"; String anotherKey = "anotherKey"; @@ -563,7 +563,7 @@ public class PropertiesDaoTest { public void saveProperty_inserts_user_properties_when_they_do_not_exist_in_db() { when(system2.now()).thenReturn(DATE_1, DATE_2, DATE_3, DATE_4, DATE_5); - long userId = 100; + int userId = 100; underTest.saveProperty(new PropertyDto().setKey("user.null").setUserId(userId).setValue(null)); underTest.saveProperty(new PropertyDto().setKey("user.empty").setUserId(userId).setValue("")); underTest.saveProperty(new PropertyDto().setKey("user.text").setUserId(userId).setValue("some text")); @@ -649,7 +649,7 @@ public class PropertiesDaoTest { @Test @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_user_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) throws SQLException { - long userId = 90L; + int userId = 90; long id = insertProperty("global", oldValue, null, userId, DATE_1); when(system2.now()).thenReturn(DATE_4); @@ -714,8 +714,8 @@ public class PropertiesDaoTest { long id2 = insertProperty("global.two", "two", null, null); long id3 = insertProperty("struts.one", "one", projectId1, null); long id4 = insertProperty("commonslang.one", "one", projectId2, null); - long id5 = insertProperty("user.one", "one", null, 100L); - long id6 = insertProperty("user.two", "two", null, 100L); + long id5 = insertProperty("user.one", "one", null, 100); + long id6 = insertProperty("user.two", "two", null, 100); long id7 = insertProperty("other.one", "one", projectId3, null); underTest.deleteProjectProperty("struts.one", projectId1); @@ -801,7 +801,7 @@ public class PropertiesDaoTest { // project - do not delete this project property that has the same key long id3 = insertProperty("to_be_deleted", "new_project", 10L, null); // user - long id4 = insertProperty("user.key", "new_user", null, 100L); + long id4 = insertProperty("user.key", "new_user", null, 100); underTest.deleteGlobalProperty("to_be_deleted"); @@ -898,8 +898,8 @@ public class PropertiesDaoTest { long id2 = insertProperty("old_name", "doc1", null, null, DATE_1); long id3 = insertProperty("old_name", "doc2", 15L, null, DATE_1); long id4 = insertProperty("old_name", "doc3", 16L, null, DATE_1); - long id5 = insertProperty("old_name", "doc4", null, 100L, DATE_1); - long id6 = insertProperty("old_name", "doc5", null, 101L, DATE_1); + long id5 = insertProperty("old_name", "doc4", null, 100, DATE_1); + long id6 = insertProperty("old_name", "doc5", null, 101, DATE_1); underTest.renamePropertyKey("old_name", "new_name"); @@ -987,12 +987,12 @@ public class PropertiesDaoTest { session.commit(); } - private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Long userId, long createdAt) throws SQLException { + private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId, long createdAt) throws SQLException { when(system2.now()).thenReturn(createdAt); return insertProperty(key, value, resourceId, userId); } - private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Long userId) throws SQLException { + private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) throws SQLException { DbSession session = dbTester.getSession(); PropertyDto dto = new PropertyDto().setKey(key) .setResourceId(resourceId == null ? null : resourceId.longValue()) @@ -1015,7 +1015,7 @@ public class PropertiesDaoTest { return project; } - private long insertUser(String login) { + private int insertUser(String login) { UserDto dto = new UserDto().setLogin(login); DbSession session = dbTester.getSession(); dbClient.userDao().insert(session, dto); diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java index a729cf890b6..51ee161eddc 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRow.java @@ -24,14 +24,14 @@ import javax.annotation.Nullable; final class PropertiesRow { private final String key; - private final Long userId; + private final Integer userId; private final Long resourceId; private final Boolean empty; private final String textValue; private final String clobValue; private final Long createdAt; - public PropertiesRow(String key, @Nullable Long userId, @Nullable Long resourceId, + public PropertiesRow(String key, @Nullable Integer userId, @Nullable Long resourceId, @Nullable Boolean empty, @Nullable String textValue, @Nullable String clobValue, @Nullable Long createdAt) { this.key = key; @@ -47,7 +47,7 @@ final class PropertiesRow { return key; } - public Long getUserId() { + public Integer getUserId() { return userId; } diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java index 81febdd8a5c..048d6d52252 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesRowAssert.java @@ -67,9 +67,10 @@ final class PropertiesRowAssert extends AbstractAssert row = rows.iterator().next(); + Long userId = (Long) row.get("userId"); return new PropertiesRow( (String) row.get("key"), - (Long) row.get("userId"), + userId == null ? null : userId.intValue(), (Long) row.get("resourceId"), toBoolean(row.get("isEmpty")), (String) row.get("textValue"), @@ -113,7 +114,7 @@ final class PropertiesRowAssert extends AbstractAssert result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("admin").build(), 0, 10); + List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).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(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("not").build(), 0, 10); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("not").build(), 0, 10); assertThat(result).hasSize(1); } @@ -138,13 +138,13 @@ public class GroupMembershipDaoTest { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); // search is case insensitive only on name - List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("NaMe").build(), 0, 10); + List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("NaMe").build(), 0, 10); assertThat(result).hasSize(1); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("login").build(), 0, 10); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("login").build(), 0, 10); assertThat(result).hasSize(1); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).memberSearch("email").build(), 0, 10); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).memberSearch("email").build(), 0, 10); assertThat(result).hasSize(1); } @@ -152,7 +152,7 @@ public class GroupMembershipDaoTest { public void should_be_sorted_by_user_name() { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); - List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 0, 10); + List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 0, 10); assertThat(result).hasSize(2); assertThat(result.get(0).getName()).isEqualTo("Admin name"); assertThat(result.get(1).getName()).isEqualTo("Not Admin"); @@ -162,16 +162,16 @@ public class GroupMembershipDaoTest { public void members_should_be_paginated() { dbTester.prepareDbUnit(getClass(), "shared_plus_empty_group.xml"); - List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 0, 2); + List result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).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(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 1, 2); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 1, 2); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo("Not Admin"); - result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100L).build(), 2, 1); + result = underTest.selectMembers(dbTester.getSession(), UserMembershipQuery.builder().groupId(100).build(), 2, 1); assertThat(result).isEmpty(); } } diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java b/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java index 87a695712cd..50af08373f3 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java @@ -22,6 +22,7 @@ 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 { @@ -32,7 +33,7 @@ public class GroupTesting { public static GroupDto newGroupDto() { GroupDto group = new GroupDto() - .setId(nextLong()) + .setId(nextInt()) .setOrganizationUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(255)) .setDescription(randomAlphanumeric(200)) diff --git a/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java index 5a9b6ced418..580b26956aa 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java @@ -94,7 +94,7 @@ public class RoleDaoTest { public void delete_all_group_permissions_by_group_id() { db.prepareDbUnit(getClass(), "deleteGroupPermissionsByGroupId.xml"); - underTest.deleteGroupRolesByGroupId(db.getSession(), 100L); + underTest.deleteGroupRolesByGroupId(db.getSession(), 100); db.getSession().commit(); db.assertDbUnit(getClass(), "deleteGroupPermissionsByGroupId-result.xml", "group_roles"); diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java index cbd7af7558b..c1a8623223c 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -70,11 +70,11 @@ public class UserDaoTest { public void selectUsersIds() { db.prepareDbUnit(getClass(), "selectUsersByIds.xml"); - Collection users = underTest.selectByIds(session, asList(100L, 101L, 987L)); + Collection users = underTest.selectByIds(session, asList(100, 101, 987)); assertThat(users).hasSize(2); assertThat(users).extracting("login").containsOnly("marius", "inactive_user"); - assertThat(underTest.selectByIds(session, Collections.emptyList())).isEmpty(); + assertThat(underTest.selectByIds(session, Collections.emptyList())).isEmpty(); } @Test @@ -305,7 +305,7 @@ public class UserDaoTest { Long date = DateUtils.parseDate("2014-06-20").getTime(); UserDto userDto = new UserDto() - .setId(1L) + .setId(1) .setLogin("john") .setName("John") .setEmail("jo@hn.com") @@ -353,7 +353,7 @@ public class UserDaoTest { db.getSession().commit(); UserDto userDto = new UserDto() - .setId(1L) + .setId(1) .setLogin("john") .setName("John Doo") .setEmail("jodoo@hn.com") diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java b/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java index 6257ac9434a..4a2c2c48fa9 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java @@ -177,7 +177,7 @@ public class UserDbTester { } @CheckForNull - public GroupDto selectGroupById(long groupId) { + public GroupDto selectGroupById(int groupId) { return db.getDbClient().groupDao().selectById(db.getSession(), groupId); } @@ -206,7 +206,7 @@ public class UserDbTester { db.commit(); } - public List selectGroupIdsOfUser(UserDto user) { + public List selectGroupIdsOfUser(UserDto user) { return db.getDbClient().groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId()); } diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java index 4e4ee16a5bc..ca36ee4e574 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java @@ -33,7 +33,7 @@ public class UserGroupDaoTest { @Test public void insert() { - UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L); + UserGroupDto userGroupDto = new UserGroupDto().setUserId(1).setGroupId(2); underTest.insert(dbTester.getSession(), userGroupDto); dbTester.getSession().commit(); @@ -43,7 +43,7 @@ public class UserGroupDaoTest { @Test public void delete_members_by_group_id() { dbTester.prepareDbUnit(getClass(), "delete_members_by_group_id.xml"); - underTest.deleteByGroupId(dbTester.getSession(), 1L); + underTest.deleteByGroupId(dbTester.getSession(), 1); dbTester.getSession().commit(); dbTester.assertDbUnit(getClass(), "delete_members_by_group_id-result.xml", "groups_users"); } diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java b/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java index f3a57b63c2d..682699ad4d9 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserTesting.java @@ -34,7 +34,7 @@ public class UserTesting { public static UserDto newUserDto(String login, String name, @Nullable String email) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setActive(true) .setLocal(true) .setName(name) @@ -51,7 +51,7 @@ public class UserTesting { public static UserDto newLocalUser(String login, String name, @Nullable String email) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setActive(true) .setLocal(true) .setName(name) @@ -68,7 +68,7 @@ public class UserTesting { public static UserDto newExternalUser(String login, String name, @Nullable String email) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setActive(true) .setLocal(false) .setName(name) @@ -83,7 +83,7 @@ public class UserTesting { public static UserDto newDisabledUser(String login) { return new UserDto() - .setId((long)nextInt()) + .setId(nextInt()) .setLogin(login) .setActive(false) .setCreatedAt(nextLong()) -- 2.39.5