From 7925b2f67b87f0d3d6086a3b006e276341f70566 Mon Sep 17 00:00:00 2001 From: Jacek Date: Thu, 30 Apr 2020 13:05:38 +0200 Subject: [PATCH] SONAR-13221 change PROPERTIES user_id FK to user_uuid --- .../org/sonar/db/property/PropertiesDao.java | 25 +- .../sonar/db/property/PropertiesMapper.java | 12 +- .../org/sonar/db/property/PropertyDto.java | 16 +- .../org/sonar/db/property/PropertyQuery.java | 14 +- .../sonar/db/property/PropertiesMapper.xml | 74 ++-- server/sonar-db-dao/src/schema/schema-sq.ddl | 4 +- .../sonar/db/property/PropertiesDaoTest.java | 324 +++++++++--------- .../org/sonar/db/property/PropertiesRow.java | 10 +- .../db/property/PropertiesRowAssert.java | 21 +- .../sonar/db/property/PropertyDtoTest.java | 3 +- .../sonar/db/favorite/FavoriteDbTester.java | 8 +- .../db/notification/NotificationDbTester.java | 8 +- .../sonar/db/property/PropertyTesting.java | 18 +- .../db/migration/version/v83/DbVersion83.java | 8 + .../AddUserUuidColumnToPropertiesUsers.java | 30 ++ .../DropUserIdColumnOfPropertiesTable.java | 36 ++ .../PopulatePropertiesUserUuid.java | 52 +++ ...ddUserUuidColumnToPropertiesUsersTest.java | 65 ++++ ...DropUserIdColumnOfPropertiesTableTest.java | 51 +++ .../PopulatePropertiesUserUuidTest.java | 154 +++++++++ .../schema.sql | 11 + .../schema.sql | 15 + .../PopulatePropertiesUserUuidTest/schema.sql | 44 +++ .../server/favorite/FavoriteUpdater.java | 16 +- .../server/favorite/FavoriteUpdaterTest.java | 30 +- .../server/organization/MemberUpdater.java | 4 +- .../organization/MemberUpdaterTest.java | 19 +- .../server/ce/queue/ReportSubmitter.java | 3 +- .../server/component/ComponentUpdater.java | 14 +- .../ws/ComponentViewerJsonWriter.java | 2 +- .../component/ws/SearchProjectsAction.java | 2 +- .../sonar/server/favorite/FavoriteFinder.java | 2 +- .../sonar/server/favorite/ws/AddAction.java | 2 +- .../server/favorite/ws/RemoveAction.java | 2 +- .../server/notification/ws/ListAction.java | 2 +- .../notification/ws/NotificationUpdater.java | 8 +- .../permission/PermissionTemplateService.java | 12 +- .../sonar/server/project/ws/CreateAction.java | 2 +- .../sonar/server/ui/ws/ComponentAction.java | 2 +- .../server/user/ws/DeactivateAction.java | 2 +- .../ce/queue/BranchReportSubmitterTest.java | 2 +- .../server/ce/queue/ReportSubmitterTest.java | 4 +- .../component/ComponentUpdaterTest.java | 16 +- .../server/component/ws/AppActionTest.java | 2 +- .../ws/SearchProjectsActionTest.java | 2 +- .../server/favorite/ws/AddActionTest.java | 12 +- .../server/favorite/ws/RemoveActionTest.java | 19 +- .../server/favorite/ws/SearchActionTest.java | 21 +- .../server/notification/ws/AddActionTest.java | 22 +- .../notification/ws/RemoveActionTest.java | 10 +- .../PermissionTemplateServiceTest.java | 6 +- .../server/project/ws/CreateActionTest.java | 4 +- .../server/setting/ws/ResetActionTest.java | 2 +- .../server/setting/ws/SetActionTest.java | 12 +- .../setting/ws/SettingsUpdaterTest.java | 2 +- .../server/ui/ws/ComponentActionTest.java | 6 +- .../server/user/ws/DeactivateActionTest.java | 4 +- 57 files changed, 878 insertions(+), 395 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsers.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuid.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest/schema.sql diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java index 1d304cf3ff7..18a7915dbb7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.apache.ibatis.annotations.Param; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.core.util.UuidFactory; @@ -114,7 +113,7 @@ public class PropertiesDao implements Dao { private static PreparedStatement createStatement(String projectUuid, Collection dispatcherKeys, Connection connection) throws SQLException { String sql = "SELECT count(1) FROM properties pp " + "left outer join components pj on pp.component_uuid = pj.uuid " + - "where pp.user_id is not null and (pp.component_uuid is null or pj.uuid=?) " + + "where pp.user_uuid is not null and (pp.component_uuid is null or pj.uuid=?) " + "and (" + repeat("pp.prop_key like ?", " or ", dispatcherKeys.size()) + ")"; PreparedStatement res = connection.prepareStatement(sql); res.setString(1, projectUuid); @@ -191,8 +190,8 @@ public class PropertiesDao implements Dao { return getMapper(session).selectByKeyAndMatchingValue(key, value); } - public List selectByKeyAndUserIdAndComponentQualifier(DbSession session, String key, int userId, String qualifier) { - return getMapper(session).selectByKeyAndUserIdAndComponentQualifier(key, userId, qualifier); + public List selectByKeyAndUserUuidAndComponentQualifier(DbSession session, String key, String userUuid, String qualifier) { + return getMapper(session).selectByKeyAndUserUuidAndComponentQualifier(key, userUuid, qualifier); } /** @@ -204,22 +203,22 @@ public class PropertiesDao implements Dao { * @throws IllegalArgumentException if {@link PropertyDto#getKey()} is {@code null} or empty */ public void saveProperty(DbSession session, PropertyDto property) { - save(getMapper(session), property.getKey(), property.getUserId(), property.getComponentUuid(), property.getValue()); + save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue()); } private void save(PropertiesMapper mapper, String key, - @Nullable Integer userId, @Nullable String componentUuid, @Nullable String value) { + @Nullable String userUuid, @Nullable String componentUuid, @Nullable String value) { checkKey(key); long now = system2.now(); - mapper.delete(key, userId, componentUuid); + mapper.delete(key, userUuid, componentUuid); String uuid = uuidFactory.create(); if (isEmpty(value)) { - mapper.insertAsEmpty(uuid, key, userId, componentUuid, now); + mapper.insertAsEmpty(uuid, key, userUuid, componentUuid, now); } else if (mustBeStoredInClob(value)) { - mapper.insertAsClob(uuid, key, userId, componentUuid, value, now); + mapper.insertAsClob(uuid, key, userUuid, componentUuid, value, now); } else { - mapper.insertAsText(uuid, key, userId, componentUuid, value, now); + mapper.insertAsText(uuid, key, userUuid, componentUuid, value, now); } } @@ -254,7 +253,7 @@ public class PropertiesDao implements Dao { } public int delete(DbSession dbSession, PropertyDto dto) { - return getMapper(dbSession).delete(dto.getKey(), dto.getUserId(), dto.getComponentUuid()); + return getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid()); } public void deleteProjectProperty(String key, String projectUuid) { @@ -290,8 +289,8 @@ public class PropertiesDao implements Dao { } } - public void deleteByOrganizationAndUser(DbSession dbSession, String organizationUuid, int userId) { - List uuids = getMapper(dbSession).selectUuidsByOrganizationAndUser(organizationUuid, userId); + public void deleteByOrganizationAndUser(DbSession dbSession, String organizationUuid, String userUuid) { + List uuids = getMapper(dbSession).selectUuidsByOrganizationAndUser(organizationUuid, userUuid); executeLargeInputsWithoutOutput(uuids, subList -> getMapper(dbSession).deleteByUuids(subList)); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java index f7c3c4b029a..8466e95665a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java @@ -42,7 +42,7 @@ public interface PropertiesMapper { List selectByKeysAndComponentUuids(@Param("keys") List keys, @Param("componentUuids") List componentUuids); - List selectByKeyAndUserIdAndComponentQualifier(@Param("key") String key, @Param("userId") int userId, @Param("qualifier") String qualifier); + List selectByKeyAndUserUuidAndComponentQualifier(@Param("key") String key, @Param("userUuid") String userUuid, @Param("qualifier") String qualifier); List selectByComponentUuids(@Param("componentUuids") List componentUuids); @@ -50,21 +50,21 @@ public interface PropertiesMapper { List selectByKeyAndMatchingValue(@Param("key") String key, @Param("value") String value); - List selectUuidsByOrganizationAndUser(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId); + List selectUuidsByOrganizationAndUser(@Param("organizationUuid") String organizationUuid, @Param("userUuid") String userUuid); List selectIdsByOrganizationAndMatchingLogin(@Param("organizationUuid") String organizationUuid, @Param("login") String login, @Param("propertyKeys") List propertyKeys); - void insertAsEmpty(@Param("uuid") String uuid, @Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid, + void insertAsEmpty(@Param("uuid") String uuid, @Param("key") String key, @Nullable @Param("userUuid") String userUuid, @Nullable @Param("componentUuid") String componentUuid, @Param("now") long now); - void insertAsText(@Param("uuid") String uuid, @Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid, + void insertAsText(@Param("uuid") String uuid, @Param("key") String key, @Nullable @Param("userUuid") String userUuid, @Nullable @Param("componentUuid") String componentUuid, @Param("value") String value, @Param("now") long now); - void insertAsClob(@Param("uuid") String uuid, @Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid, + void insertAsClob(@Param("uuid") String uuid, @Param("key") String key, @Nullable @Param("userUuid") String userUuid, @Nullable @Param("componentUuid") String componentUuid, @Param("value") String value, @Param("now") long now); - int delete(@Param("key") String key, @Nullable @Param("userId") Integer userId, @Nullable @Param("componentUuid") String componentUuid); + int delete(@Param("key") String key, @Nullable @Param("userUuid") String userUuid, @Nullable @Param("componentUuid") String componentUuid); int deleteById(long id); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java index 2b75f616ae1..db0c1d9ef36 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyDto.java @@ -33,7 +33,7 @@ public class PropertyDto { private String key; private String value; private String componentUuid; - private Integer userId; + private String userUuid; String getUuid() { return uuid; @@ -74,12 +74,12 @@ public class PropertyDto { } @CheckForNull - public Integer getUserId() { - return userId; + public String getUserUuid() { + return userUuid; } - public PropertyDto setUserId(@Nullable Integer userId) { - this.userId = userId; + public PropertyDto setUserUuid(@Nullable String userUuid) { + this.userUuid = userUuid; return this; } @@ -93,14 +93,14 @@ public class PropertyDto { } PropertyDto other = (PropertyDto) obj; return Objects.equals(this.key, other.key) - && Objects.equals(this.userId, other.userId) + && Objects.equals(this.userUuid, other.userUuid) && Objects.equals(this.componentUuid, other.componentUuid) && Objects.equals(this.value, other.value); } @Override public int hashCode() { - return Objects.hash(this.key, this.value, this.componentUuid, this.userId); + return Objects.hash(this.key, this.value, this.componentUuid, this.userUuid); } @Override @@ -109,7 +109,7 @@ public class PropertyDto { .addValue(this.key) .addValue(this.value) .addValue(this.componentUuid) - .addValue(this.userId) + .addValue(this.userUuid) .toString(); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java index 04f5eafa324..d1d2743fe1d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertyQuery.java @@ -25,12 +25,12 @@ public class PropertyQuery { private final String key; private final String componentUuid; - private final Integer userId; + private final String userUuid; private PropertyQuery(Builder builder) { this.key = builder.key; this.componentUuid = builder.componentUuid; - this.userId = builder.userId; + this.userUuid = builder.userUuid; } public String key() { @@ -41,8 +41,8 @@ public class PropertyQuery { return componentUuid; } - public Integer userId() { - return userId; + public String userUuid() { + return userUuid; } public static Builder builder() { @@ -52,7 +52,7 @@ public class PropertyQuery { public static class Builder { private String key; private String componentUuid; - private Integer userId; + private String userUuid; public Builder setKey(String key) { this.key = key; @@ -64,8 +64,8 @@ public class PropertyQuery { return this; } - public Builder setUserId(Integer userId) { - this.userId = userId; + public Builder setUserUuid(String userUuid) { + this.userUuid = userUuid; return this; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml index 828c63cb10a..1b35a43ec3c 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml @@ -9,7 +9,7 @@ ${_true} as "global" FROM users u - INNER JOIN properties p ON p.user_id = u.id + INNER JOIN properties p ON p.user_uuid = u.uuid WHERE p.prop_key = #{notifKey,jdbcType=VARCHAR} AND p.text_value = 'true' @@ -24,7 +24,7 @@ FROM users u INNER JOIN components c on c.kee = #{projectKey,jdbcType=VARCHAR} - INNER JOIN properties p ON p.user_id = u.id + INNER JOIN properties p ON p.user_uuid = u.uuid WHERE p.prop_key = #{notifKey,jdbcType=VARCHAR} AND p.text_value = 'true' @@ -40,7 +40,7 @@ FROM users u INNER JOIN properties p ON - p.user_id = u.id + p.user_uuid = u.uuid and p.prop_key = #{notifKey,jdbcType=VARCHAR} and p.text_value = 'true' and p.component_uuid IS NULL @@ -62,7 +62,7 @@ INNER JOIN components c on c.kee = #{projectKey,jdbcType=VARCHAR} INNER JOIN properties p ON - p.user_id = u.id + p.user_uuid = u.uuid and p.prop_key = #{notifKey,jdbcType=VARCHAR} and p.text_value = 'true' and p.component_uuid = c.uuid @@ -81,7 +81,7 @@ p.text_value as textValue, p.clob_value as clobValue, p.component_uuid as componentUuid, - p.user_id as userId + p.user_uuid as userUuid @@ -119,11 +119,11 @@ and p.component_uuid=#{componentUuid} - - and p.user_id is null + + and p.user_uuid is null - - and p.user_id=#{userId,jdbcType=INTEGER} + + and p.user_uuid=#{userUuid,jdbcType=VARCHAR} @@ -138,7 +138,7 @@ #{key} and p.component_uuid is null - and p.user_id is null + and p.user_uuid is null order by p.created_at @@ -156,7 +156,7 @@ #{componentUuid} - and p.user_id is null + and p.user_uuid is null - select from @@ -180,7 +180,7 @@ inner join components prj on prj.uuid=p.component_uuid and prj.qualifier = #{qualifier, jdbcType=VARCHAR} where p.prop_key = #{key, jdbcType=VARCHAR} - and p.user_id = #{userId, jdbcType=INTEGER} + and p.user_uuid = #{userUuid, jdbcType=VARCHAR} @@ -206,7 +206,7 @@ from properties py inner join components ps on py.component_uuid = ps.uuid where - py.user_id=#{userId,jdbcType=INTEGER} + py.user_uuid=#{userUuid,jdbcType=VARCHAR} and ps.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} @@ -239,7 +239,7 @@ uuid, prop_key, component_uuid, - user_id, + user_uuid, is_empty, created_at ) @@ -247,7 +247,7 @@ #{uuid}, #{key}, #{componentUuid}, - #{userId,jdbcType=INTEGER}, + #{userUuid,jdbcType=VARCHAR}, ${_true}, #{now} ) @@ -259,7 +259,7 @@ uuid, prop_key, component_uuid, - user_id, + user_uuid, is_empty, text_value, created_at @@ -268,7 +268,7 @@ #{uuid}, #{key}, #{componentUuid}, - #{userId,jdbcType=INTEGER}, + #{userUuid,jdbcType=VARCHAR}, ${_false}, #{value}, #{now} @@ -281,7 +281,7 @@ uuid, prop_key, component_uuid, - user_id, + user_uuid, is_empty, clob_value, created_at @@ -290,7 +290,7 @@ #{uuid}, #{key}, #{componentUuid}, - #{userId,jdbcType=INTEGER}, + #{userUuid,jdbcType=VARCHAR}, ${_false}, #{value}, #{now} @@ -302,21 +302,21 @@ where prop_key=#{key} - + and component_uuid=#{componentUuid} - and user_id=#{userId,jdbcType=INTEGER} + and user_uuid=#{userUuid,jdbcType=VARCHAR} and component_uuid=#{componentUuid} - and user_id is null + and user_uuid is null - + and component_uuid is null - and user_id=#{userId,jdbcType=INTEGER} + and user_uuid=#{userUuid,jdbcType=VARCHAR} and component_uuid is null - and user_id is null + and user_uuid is null @@ -326,7 +326,7 @@ where prop_key=#{key} and component_uuid=#{componentUuid} - and user_id is null + and user_uuid is null @@ -335,7 +335,7 @@ prop_key=#{key} and text_value = #{value} and component_uuid is not null - and user_id is null + and user_uuid is null @@ -343,14 +343,14 @@ where prop_key=#{key} and component_uuid is null - and user_id is null + and user_uuid is null delete from properties where component_uuid is null - and user_id is null + and user_uuid is null @@ -362,8 +362,8 @@ and component_uuid=#{query.componentUuid,jdbcType=BIGINT} - - and user_id=#{query.userId,jdbcType=INTEGER} + + and user_uuid=#{query.userUuid,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index ffa3ad66265..9a09829ee26 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -726,13 +726,13 @@ CREATE INDEX "IDX_QUALIFIER" ON "PROJECTS"("QUALIFIER"); CREATE TABLE "PROPERTIES"( "PROP_KEY" VARCHAR(512) NOT NULL, - "USER_ID" BIGINT, "IS_EMPTY" BOOLEAN NOT NULL, "TEXT_VALUE" VARCHAR(4000), "CLOB_VALUE" CLOB(2147483647), "CREATED_AT" BIGINT NOT NULL, "COMPONENT_UUID" VARCHAR(40), - "UUID" VARCHAR(40) NOT NULL + "UUID" VARCHAR(40) NOT NULL, + "USER_UUID" VARCHAR(40) ); ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID"); CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index 12b4553e728..42c85973c39 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -83,11 +83,11 @@ public class PropertiesDaoTest { UserDto user1 = db.users().insertUser(u -> u.setLogin("user1")); UserDto user2 = db.users().insertUser(u -> u.setLogin("user2")); UserDto user3 = db.users().insertUser(u -> u.setLogin("user3")); - insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getId()); - insertProperty("notification.NewViolations.Twitter", "true", null, user3.getId()); - insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getId()); - insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getId()); - insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getId()); + insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid()); + insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid()); + insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid()); + insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid()); + insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid()); db.users().insertProjectPermissionOnUser(user2, UserRole.USER, project1); db.users().insertProjectPermissionOnUser(user3, UserRole.USER, project2); db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project2); @@ -119,19 +119,19 @@ public class PropertiesDaoTest { @Test public void hasNotificationSubscribers() { - int userId1 = db.users().insertUser(u -> u.setLogin("user1")).getId(); - int userId2 = db.users().insertUser(u -> u.setLogin("user2")).getId(); + String userUuid1 = db.users().insertUser(u -> u.setLogin("user1")).getUuid(); + String userUuid2 = db.users().insertUser(u -> u.setLogin("user2")).getUuid(); String projectUuid = randomAlphabetic(8); db.components().insertPrivateProject(db.getDefaultOrganization(), projectUuid); // global subscription - insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userId2); + insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userUuid2); // project subscription - insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, userId1); - insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", userId1); - insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, userId1); + insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, userUuid1); + insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", userUuid1); + insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, userUuid1); // global subscription - insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userId2); + insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userUuid2); // Nobody is subscribed assertThat(underTest.hasProjectNotificationSubscribersForDispatchers(projectUuid, singletonList("NotSexyDispatcher"))) @@ -181,24 +181,24 @@ public class PropertiesDaoTest { @Test public void findEmailRecipientsForNotification_finds_only_globally_subscribed_users_if_projectKey_is_null() { - int userId1 = db.users().insertUser(withEmail("user1")).getId(); - int userId2 = db.users().insertUser(withEmail("user2")).getId(); - int userId3 = db.users().insertUser(withEmail("user3")).getId(); - int userId4 = db.users().insertUser(withEmail("user4")).getId(); + String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid(); + String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid(); + String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid(); + String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid(); String projectUuid = insertPrivateProject("PROJECT_A").uuid(); String dispatcherKey = randomAlphabetic(5); String otherDispatcherKey = randomAlphabetic(6); String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null)) .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2"))); @@ -213,24 +213,24 @@ public class PropertiesDaoTest { @Test public void findEmailRecipientsForNotification_with_logins_finds_only_globally_subscribed_specified_users_if_projectKey_is_null() { - int userId1 = db.users().insertUser(withEmail("user1")).getId(); - int userId2 = db.users().insertUser(withEmail("user2")).getId(); - int userId3 = db.users().insertUser(withEmail("user3")).getId(); - int userId4 = db.users().insertUser(withEmail("user4")).getId(); + String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid(); + String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid(); + String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid(); + String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid(); String projectUuid = insertPrivateProject("PROJECT_A").uuid(); String dispatcherKey = randomAlphabetic(5); String otherDispatcherKey = randomAlphabetic(6); String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4); Set allLogins = of("user1", "user2", "user3", "user4"); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins)) @@ -254,10 +254,10 @@ public class PropertiesDaoTest { @Test public void findEmailRecipientsForNotification_finds_global_and_project_subscribed_users_when_projectKey_is_non_null() { - int userId1 = db.users().insertUser(withEmail("user1")).getId(); - int userId2 = db.users().insertUser(withEmail("user2")).getId(); - int userId3 = db.users().insertUser(withEmail("user3")).getId(); - int userId4 = db.users().insertUser(withEmail("user4")).getId(); + String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid(); + String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid(); + String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid(); + String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid(); String projectKey = randomAlphabetic(3); String otherProjectKey = randomAlphabetic(4); String projectUuid = insertPrivateProject(projectKey).uuid(); @@ -266,14 +266,14 @@ public class PropertiesDaoTest { String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey)) .containsOnly( @@ -293,10 +293,10 @@ public class PropertiesDaoTest { @Test public void findEmailRecipientsForNotification_with_logins_finds_global_and_project_subscribed_specified_users_when_projectKey_is_non_null() { - int userId1 = db.users().insertUser(withEmail("user1")).getId(); - int userId2 = db.users().insertUser(withEmail("user2")).getId(); - int userId3 = db.users().insertUser(withEmail("user3")).getId(); - int userId4 = db.users().insertUser(withEmail("user4")).getId(); + String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid(); + String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid(); + String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid(); + String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid(); String projectKey = randomAlphabetic(3); String otherProjectKey = randomAlphabetic(4); String projectUuid = insertPrivateProject(projectKey).uuid(); @@ -305,14 +305,14 @@ public class PropertiesDaoTest { String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId3); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userId4); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4); Set allLogins = of("user1", "user2", "user3", "user4"); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins)) @@ -343,22 +343,22 @@ public class PropertiesDaoTest { @Test public void findEmailRecipientsForNotification_ignores_subscribed_users_without_email() { - int userId1 = db.users().insertUser(withEmail("user1")).getId(); - int userId2 = db.users().insertUser(noEmail("user2")).getId(); - int userId3 = db.users().insertUser(withEmail("user3")).getId(); - int userId4 = db.users().insertUser(noEmail("user4")).getId(); + String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid(); + String userUuid2 = db.users().insertUser(noEmail("user2")).getUuid(); + String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid(); + String userUuid4 = db.users().insertUser(noEmail("user4")).getUuid(); String projectKey = randomAlphabetic(3); String projectUuid = insertPrivateProject(projectKey).uuid(); String dispatcherKey = randomAlphabetic(4); String channelKey = randomAlphabetic(5); // user1 and user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId1); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2); // user3 and user4 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId3); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId4); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid3); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid4); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey)) .containsOnly( @@ -372,23 +372,23 @@ public class PropertiesDaoTest { @Test public void findEmailRecipientsForNotification_with_logins_ignores_subscribed_users_without_email() { - int userId1 = db.users().insertUser(withEmail("user1")).getId(); - int userId2 = db.users().insertUser(noEmail("user2")).getId(); - int userId3 = db.users().insertUser(withEmail("user3")).getId(); - int userId4 = db.users().insertUser(noEmail("user4")).getId(); + String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid(); + String userUuid2 = db.users().insertUser(noEmail("user2")).getUuid(); + String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid(); + String userUuid4 = db.users().insertUser(noEmail("user4")).getUuid(); Set allLogins = of("user1", "user2", "user3"); String projectKey = randomAlphabetic(3); String projectUuid = insertPrivateProject(projectKey).uuid(); String dispatcherKey = randomAlphabetic(4); String channelKey = randomAlphabetic(5); // user1 and user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId1); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId1); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId2); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userId2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid1); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2); // user3 and user4 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId3); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userId4); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid3); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid4); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins)) .containsOnly( @@ -411,11 +411,11 @@ public class PropertiesDaoTest { .isEqualTo(2); assertThat(findByKey(properties, "global.one")) - .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue) + .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) .containsExactly("global.one", null, null, "one"); assertThat(findByKey(properties, "global.two")) - .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue) + .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) .containsExactly("global.two", null, null, "two"); } @@ -429,7 +429,7 @@ public class PropertiesDaoTest { .hasSize(1); assertThat(dtos.iterator().next()) - .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue) + .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) .containsExactly("global.one", null, null, expected); } @@ -441,10 +441,10 @@ public class PropertiesDaoTest { // project insertProperty("project.one", "one", "uuid10", null); // user - insertProperty("user.one", "one", null, 100); + insertProperty("user.one", "one", null, "100"); assertThat(underTest.selectGlobalProperty("global.one")) - .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue) + .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) .containsExactly(null, null, "one"); assertThat(underTest.selectGlobalProperty("project.one")).isNull(); @@ -458,7 +458,7 @@ public class PropertiesDaoTest { insertProperty("global.one", dbValue, null, null); assertThat(underTest.selectGlobalProperty("global.one")) - .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue) + .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) .containsExactly(null, null, expected); } @@ -517,7 +517,7 @@ public class PropertiesDaoTest { PropertyDto property = underTest.selectProjectProperty("uuid10", "project.one"); assertThat(property) - .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getValue) + .extracting(PropertyDto::getKey, PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) .containsExactly("project.one", "uuid10", null, "one"); } @@ -531,17 +531,17 @@ public class PropertiesDaoTest { // commons insertProperty("commonslang.one", "one", "uuid11", null); // user - insertProperty("user.one", "one", null, 100); - insertProperty("user.two", "two", "uuid10", 100); + insertProperty("user.one", "one", null, "100"); + insertProperty("user.two", "two", "uuid10", "100"); // other insertProperty("other.one", "one", "uuid12", null); List results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.two").setComponentUuid("uuid10") - .setUserId(100).build(), db.getSession()); + .setUserUuid("100").build(), db.getSession()); assertThat(results).hasSize(1); assertThat(results.get(0).getValue()).isEqualTo("two"); - results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.one").setUserId(100).build(), db.getSession()); + results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.one").setUserUuid("100").build(), db.getSession()); assertThat(results).hasSize(1); assertThat(results.get(0).getValue()).isEqualTo("one"); } @@ -549,13 +549,13 @@ public class PropertiesDaoTest { @Test public void select_global_properties_by_keys() { insertPrivateProject("A"); - int userId = db.users().insertUser(u -> u.setLogin("B")).getId(); + String userUuid = db.users().insertUser(u -> u.setLogin("B")).getUuid(); String key = "key"; String anotherKey = "anotherKey"; insertProperty(key, "value", null, null); insertProperty(key, "value", "uuid10", null); - insertProperty(key, "value", null, userId); + insertProperty(key, "value", null, userUuid); insertProperty(anotherKey, "value", null, null); insertProperty("key1", "value", null, null); @@ -657,7 +657,7 @@ public class PropertiesDaoTest { } @Test - public void selectByKeyAndUserIdAndComponentQualifier() { + public void selectByKeyAndUserUuidAndComponentQualifier() { UserDto user1 = db.users().insertUser(); UserDto user2 = db.users().insertUser(); ComponentDto project1 = db.components().insertPrivateProject(); @@ -671,11 +671,11 @@ public class PropertiesDaoTest { newPropertyDto("key", "5", project1, user2), newGlobalPropertyDto("key", "global")); - assertThat(underTest.selectByKeyAndUserIdAndComponentQualifier(db.getSession(), "key", user1.getId(), "TRK")) + assertThat(underTest.selectByKeyAndUserUuidAndComponentQualifier(db.getSession(), "key", user1.getUuid(), "TRK")) .extracting(PropertyDto::getValue).containsExactlyInAnyOrder("1", "2"); - assertThat(underTest.selectByKeyAndUserIdAndComponentQualifier(db.getSession(), "key", user1.getId(), "FIL")) + assertThat(underTest.selectByKeyAndUserUuidAndComponentQualifier(db.getSession(), "key", user1.getUuid(), "FIL")) .extracting(PropertyDto::getValue).containsExactlyInAnyOrder("3"); - assertThat(underTest.selectByKeyAndUserIdAndComponentQualifier(db.getSession(), "key", user2.getId(), "FIL")).isEmpty(); + assertThat(underTest.selectByKeyAndUserUuidAndComponentQualifier(db.getSession(), "key", user2.getUuid(), "FIL")).isEmpty(); } @Test @@ -688,27 +688,27 @@ public class PropertiesDaoTest { assertThatPropertiesRow("global.null") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .isEmpty() .hasCreatedAt(INITIAL_DATE + 2); assertThatPropertiesRow("global.empty") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .isEmpty() .hasCreatedAt(INITIAL_DATE + 3); assertThatPropertiesRow("global.text") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("some text") .hasCreatedAt(INITIAL_DATE + 4); assertThatPropertiesRow("global.4000") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(INITIAL_DATE + 5); assertThatPropertiesRow("global.clob") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(INITIAL_DATE + 6); } @@ -724,63 +724,63 @@ public class PropertiesDaoTest { assertThatPropertiesRow("component.null") .hasComponentUuid(componentUuid) - .hasNoUserId() + .hasNoUserUuid() .isEmpty() .hasCreatedAt(INITIAL_DATE + 2); assertThatPropertiesRow("component.empty") .hasComponentUuid(componentUuid) - .hasNoUserId() + .hasNoUserUuid() .isEmpty() .hasCreatedAt(INITIAL_DATE + 3); assertThatPropertiesRow("component.text") .hasComponentUuid(componentUuid) - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("some text") .hasCreatedAt(INITIAL_DATE + 4); assertThatPropertiesRow("component.4000") .hasComponentUuid(componentUuid) - .hasNoUserId() + .hasNoUserUuid() .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(INITIAL_DATE + 5); assertThatPropertiesRow("component.clob") .hasComponentUuid(componentUuid) - .hasNoUserId() + .hasNoUserUuid() .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(INITIAL_DATE + 6); } @Test public void saveProperty_inserts_user_properties_when_they_do_not_exist_in_db() { - 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")); - underTest.saveProperty(new PropertyDto().setKey("user.4000").setUserId(userId).setValue(VALUE_SIZE_4000)); - underTest.saveProperty(new PropertyDto().setKey("user.clob").setUserId(userId).setValue(VALUE_SIZE_4001)); + String userUuid = "uuid-100"; + underTest.saveProperty(new PropertyDto().setKey("user.null").setUserUuid(userUuid).setValue(null)); + underTest.saveProperty(new PropertyDto().setKey("user.empty").setUserUuid(userUuid).setValue("")); + underTest.saveProperty(new PropertyDto().setKey("user.text").setUserUuid(userUuid).setValue("some text")); + underTest.saveProperty(new PropertyDto().setKey("user.4000").setUserUuid(userUuid).setValue(VALUE_SIZE_4000)); + underTest.saveProperty(new PropertyDto().setKey("user.clob").setUserUuid(userUuid).setValue(VALUE_SIZE_4001)); assertThatPropertiesRow("user.null") .hasNoComponentUuid() - .hasUserId(userId) + .hasUserUuid(userUuid) .isEmpty() .hasCreatedAt(INITIAL_DATE + 2); assertThatPropertiesRow("user.empty") .hasNoComponentUuid() - .hasUserId(userId) + .hasUserUuid(userUuid) .isEmpty() .hasCreatedAt(INITIAL_DATE + 3); assertThatPropertiesRow("user.text") .hasNoComponentUuid() - .hasUserId(userId) + .hasUserUuid(userUuid) .hasTextValue("some text") .hasCreatedAt(INITIAL_DATE + 4); assertThatPropertiesRow("user.4000") .hasNoComponentUuid() - .hasUserId(userId) + .hasUserUuid(userUuid) .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(INITIAL_DATE + 5); assertThatPropertiesRow("user.clob") .hasNoComponentUuid() - .hasUserId(userId) + .hasUserUuid(userUuid) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(INITIAL_DATE + 6); } @@ -797,7 +797,7 @@ public class PropertiesDaoTest { PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasCreatedAt(INITIAL_DATE + 3); if (newValue == null || newValue.isEmpty()) { propertiesRowAssert.isEmpty(); @@ -820,7 +820,7 @@ public class PropertiesDaoTest { .doesNotExist(); PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") .hasComponentUuid(componentUuid) - .hasNoUserId() + .hasNoUserUuid() .hasCreatedAt(INITIAL_DATE + 3); if (newValue == null || newValue.isEmpty()) { propertiesRowAssert.isEmpty(); @@ -834,17 +834,17 @@ 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) { - int userId = 90; - String uuid = insertProperty("global", oldValue, null, userId); + String userUuid = "uuid-90"; + String uuid = insertProperty("global", oldValue, null, userUuid); - underTest.saveProperty(new PropertyDto().setKey("global").setUserId(userId).setValue(newValue)); + underTest.saveProperty(new PropertyDto().setKey("global").setUserUuid(userUuid).setValue(newValue)); assertThatPropertiesRowByUuid(uuid) .doesNotExist(); PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") .hasNoComponentUuid() - .hasUserId(userId) + .hasUserUuid(userUuid) .hasCreatedAt(INITIAL_DATE + 3); if (newValue == null || newValue.isEmpty()) { propertiesRowAssert.isEmpty(); @@ -898,8 +898,8 @@ public class PropertiesDaoTest { String uuid2 = insertProperty("global.two", "two", null, null); String uuid3 = insertProperty("struts.one", "one", "project1", null); String uuid4 = insertProperty("commonslang.one", "one", "project2", null); - String uuid5 = insertProperty("user.one", "one", null, 100); - String uuid6 = insertProperty("user.two", "two", null, 100); + String uuid5 = insertProperty("user.one", "one", null, "100"); + String uuid6 = insertProperty("user.two", "two", null, "100"); String uuid7 = insertProperty("other.one", "one", "project3", null); underTest.deleteProjectProperty("struts.one", "project1"); @@ -907,34 +907,34 @@ public class PropertiesDaoTest { assertThatPropertiesRowByUuid(uuid1) .hasKey("global.one") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("one"); assertThatPropertiesRowByUuid(uuid2) .hasKey("global.two") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("two"); assertThatPropertiesRowByUuid(uuid3) .doesNotExist(); assertThatPropertiesRowByUuid(uuid4) .hasKey("commonslang.one") .hasComponentUuid("project2") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("one"); assertThatPropertiesRowByUuid(uuid5) .hasKey("user.one") .hasNoComponentUuid() - .hasUserId(100) + .hasUserUuid("100") .hasTextValue("one"); assertThatPropertiesRowByUuid(uuid6) .hasKey("user.two") .hasNoComponentUuid() - .hasUserId(100) + .hasUserUuid("100") .hasTextValue("two"); assertThatPropertiesRowByUuid(uuid7) .hasKey("other.one") .hasComponentUuid("project3") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("one"); } @@ -958,22 +958,22 @@ public class PropertiesDaoTest { assertThatPropertiesRowByUuid(uuid3) .hasKey("sonar.profile.java") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("Sonar Way"); assertThatPropertiesRowByUuid(uuid4) .hasKey("sonar.profile.js") .hasComponentUuid("uuid1") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("Sonar Way"); assertThatPropertiesRowByUuid(uuid5) .hasKey("sonar.profile.js") .hasComponentUuid("uuid2") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("Sonar Way"); assertThatPropertiesRowByUuid(uuid6) .hasKey("sonar.profile.js") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("Sonar Way"); } @@ -985,13 +985,13 @@ public class PropertiesDaoTest { // project - do not delete this project property that has the same key String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null); // user - String uuid4 = insertProperty("user.key", "new_user", null, 100); + String uuid4 = insertProperty("user.key", "new_user", null, "100"); underTest.deleteGlobalProperty("to_be_deleted"); assertThatPropertiesRowByUuid(uuid1) .hasKey("global.key") - .hasNoUserId() + .hasNoUserUuid() .hasNoComponentUuid() .hasTextValue("new_global"); assertThatPropertiesRowByUuid(uuid2) @@ -1001,12 +1001,12 @@ public class PropertiesDaoTest { assertThatPropertiesRowByUuid(uuid3) .hasKey("to_be_deleted") .hasComponentUuid("to_be_deleted") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("new_project"); assertThatPropertiesRowByUuid(uuid4) .hasKey("user.key") .hasNoComponentUuid() - .hasUserId(100) + .hasUserUuid("100") .hasTextValue("new_user"); } @@ -1018,19 +1018,19 @@ public class PropertiesDaoTest { ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization); UserDto user = db.users().insertUser(); UserDto anotherUser = db.users().insertUser(); - insertProperty("KEY_11", "VALUE", project.uuid(), user.getId()); - insertProperty("KEY_12", "VALUE", project.uuid(), user.getId()); - insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getId()); - insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getId()); + insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid()); + insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid()); + insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid()); + insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid()); - underTest.deleteByOrganizationAndUser(session, organization.getUuid(), user.getId()); + underTest.deleteByOrganizationAndUser(session, organization.getUuid(), user.getUuid()); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), session)) .hasSize(1) - .extracting(PropertyDto::getUserId).containsOnly(anotherUser.getId()); + .extracting(PropertyDto::getUserUuid).containsOnly(anotherUser.getUuid()); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), session)) - .extracting(PropertyDto::getUserId) - .hasSize(1).containsOnly(user.getId()); + .extracting(PropertyDto::getUserUuid) + .hasSize(1).containsOnly(user.getUuid()); } @Test @@ -1062,19 +1062,19 @@ public class PropertiesDaoTest { ComponentDto anotherProject = db.components().insertPrivateProject(); insertProperty("KEY", "VALUE", null, null); insertProperty("KEY", "VALUE", project.uuid(), null); - insertProperty("KEY", "VALUE", null, 100); - insertProperty("KEY", "VALUE", project.uuid(), 100); + insertProperty("KEY", "VALUE", null, "100"); + insertProperty("KEY", "VALUE", project.uuid(), "100"); insertProperty("KEY", "VALUE", anotherProject.uuid(), null); // Should not be removed insertProperty("KEY", "ANOTHER_VALUE", null, null); - insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), 100); + insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100"); underTest.deleteByKeyAndValue(session, "KEY", "VALUE"); db.commit(); - assertThat(db.select("select prop_key as \"key\", text_value as \"value\", component_uuid as \"projectUuid\", user_id as \"userId\" from properties")) - .extracting((row) -> row.get("key"), (row) -> row.get("value"), (row) -> row.get("projectUuid"), (row) -> row.get("userId")) - .containsOnly(tuple("KEY", "ANOTHER_VALUE", null, null), tuple("ANOTHER_KEY", "VALUE", project.uuid(), 100L)); + assertThat(db.select("select prop_key as \"key\", text_value as \"value\", component_uuid as \"projectUuid\", user_uuid as \"userUuid\" from properties")) + .extracting((row) -> row.get("key"), (row) -> row.get("value"), (row) -> row.get("projectUuid"), (row) -> row.get("userUuid")) + .containsOnly(tuple("KEY", "ANOTHER_VALUE", null, null), tuple("ANOTHER_KEY", "VALUE", project.uuid(), "100")); } @Test @@ -1088,27 +1088,27 @@ public class PropertiesDaoTest { assertThatPropertiesRow("null_value_property") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .isEmpty() .hasCreatedAt(INITIAL_DATE + 2); assertThatPropertiesRow("empty_value_property") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .isEmpty() .hasCreatedAt(INITIAL_DATE + 3); assertThatPropertiesRow("text_value_property") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("dfdsfsd") .hasCreatedAt(INITIAL_DATE + 4); assertThatPropertiesRow("4000_char_value_property") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(INITIAL_DATE + 5); assertThatPropertiesRow("clob_value_property") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(INITIAL_DATE + 6); } @@ -1124,7 +1124,7 @@ public class PropertiesDaoTest { assertThatPropertiesRow("to_be_updated") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("new value") .hasCreatedAt(INITIAL_DATE + 3); } @@ -1145,45 +1145,45 @@ public class PropertiesDaoTest { String uuid2 = insertProperty("old_name", "doc1", null, null); String uuid3 = insertProperty("old_name", "doc2", "15", null); String uuid4 = insertProperty("old_name", "doc3", "16", null); - String uuid5 = insertProperty("old_name", "doc4", null, 100); - String uuid6 = insertProperty("old_name", "doc5", null, 101); + String uuid5 = insertProperty("old_name", "doc4", null, "100"); + String uuid6 = insertProperty("old_name", "doc5", null, "101"); underTest.renamePropertyKey("old_name", "new_name"); assertThatPropertiesRowByUuid(uuid1) .hasKey("foo") - .hasNoUserId() + .hasNoUserUuid() .hasNoComponentUuid() .hasTextValue("bar") .hasCreatedAt(INITIAL_DATE + 2); assertThatPropertiesRowByUuid(uuid2) .hasKey("new_name") .hasNoComponentUuid() - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("doc1") .hasCreatedAt(INITIAL_DATE + 3); assertThatPropertiesRowByUuid(uuid3) .hasKey("new_name") .hasComponentUuid("15") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("doc2") .hasCreatedAt(INITIAL_DATE + 4); assertThatPropertiesRowByUuid(uuid4) .hasKey("new_name") .hasComponentUuid("16") - .hasNoUserId() + .hasNoUserUuid() .hasTextValue("doc3") .hasCreatedAt(INITIAL_DATE + 5); assertThatPropertiesRowByUuid(uuid5) .hasKey("new_name") .hasNoComponentUuid() - .hasUserId(100) + .hasUserUuid("100") .hasTextValue("doc4") .hasCreatedAt(INITIAL_DATE + 6); assertThatPropertiesRowByUuid(uuid6) .hasKey("new_name") .hasNoComponentUuid() - .hasUserId(101) + .hasUserUuid("101") .hasTextValue("doc5") .hasCreatedAt(INITIAL_DATE + 7); } @@ -1199,7 +1199,7 @@ public class PropertiesDaoTest { assertThatPropertiesRowByUuid(uuid) .hasKey("foo") - .hasNoUserId() + .hasNoUserUuid() .hasNoComponentUuid() .hasTextValue("bar") .hasCreatedAt(INITIAL_DATE + 2); @@ -1233,16 +1233,16 @@ public class PropertiesDaoTest { session.commit(); } - private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable Integer userId) { + private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid) { PropertyDto dto = new PropertyDto().setKey(key) .setComponentUuid(componentUuid) - .setUserId(userId) + .setUserUuid(userUuid) .setValue(value); db.properties().insertProperty(dto); return (String) db.selectFirst(session, "select uuid as \"uuid\" from properties" + " where prop_key='" + key + "'" + - " and user_id" + (userId == null ? " is null" : "='" + userId + "'") + + " and user_uuid" + (userUuid == null ? " is null" : "='" + userUuid + "'") + " and component_uuid" + (componentUuid == null ? " is null" : "='" + componentUuid + "'")).get("uuid"); } @@ -1266,8 +1266,8 @@ public class PropertiesDaoTest { return String.format("notification.%s.%s", dispatcherKey, channelKey); } - private PropertiesRowAssert assertThatPropertiesRow(String key, @Nullable Integer userId, @Nullable String componentUuid) { - return new PropertiesRowAssert(db, key, userId, componentUuid); + private PropertiesRowAssert assertThatPropertiesRow(String key, @Nullable String userUuid, @Nullable String componentUuid) { + return new PropertiesRowAssert(db, key, userUuid, componentUuid); } private PropertiesRowAssert assertThatPropertiesRow(String key) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java index f1f608b4310..3168659061d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRow.java @@ -24,18 +24,18 @@ import javax.annotation.Nullable; final class PropertiesRow { private final String key; - private final Integer userId; + private final String userUuid; private final String componentUuid; private final Boolean empty; private final String textValue; private final String clobValue; private final Long createdAt; - public PropertiesRow(String key, @Nullable Integer userId, @Nullable String componentUuid, + public PropertiesRow(String key, @Nullable String userUuid, @Nullable String componentUuid, @Nullable Boolean empty, @Nullable String textValue, @Nullable String clobValue, @Nullable Long createdAt) { this.key = key; - this.userId = userId; + this.userUuid = userUuid; this.componentUuid = componentUuid; this.empty = empty; this.textValue = textValue; @@ -47,8 +47,8 @@ final class PropertiesRow { return key; } - public Integer getUserId() { - return userId; + public String getUserUuid() { + return userUuid; } public String getComponentUuid() { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java index 2bdd491c2f8..bc01713fc6e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesRowAssert.java @@ -35,12 +35,12 @@ import static java.util.Objects.requireNonNull; final class PropertiesRowAssert extends AbstractAssert { - PropertiesRowAssert(DbTester dbTester, String propertyKey, @Nullable Integer userId, @Nullable String componentUuid) { + PropertiesRowAssert(DbTester dbTester, String propertyKey, @Nullable String userUuid, @Nullable String componentUuid) { super( asInternalProperty( dbTester, () -> " where prop_key='" + propertyKey + "'" + - " and user_id" + (userId == null ? " is null" : "='" + userId + "'") + + " and user_uuid" + (userUuid == null ? " is null" : "='" + userUuid + "'") + " and component_uuid" + (componentUuid == null ? " is null" : "='" + componentUuid + "'")), PropertiesRowAssert.class); } @@ -62,7 +62,7 @@ final class PropertiesRowAssert extends AbstractAssert> rows = dbTester.select( "select" + - " prop_key as \"key\", user_id as \"userId\", component_uuid as \"componentUuid\", is_empty as \"isEmpty\", " + " prop_key as \"key\", user_uuid as \"userUuid\", component_uuid as \"componentUuid\", is_empty as \"isEmpty\", " + "text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\"" + " from properties" + @@ -72,10 +72,9 @@ final class PropertiesRowAssert extends AbstractAssert row = rows.iterator().next(); - Long userId = (Long) row.get("userId"); return new PropertiesRow( (String) row.get("key"), - userId == null ? null : userId.intValue(), + (String) row.get("userUuid"), (String) row.get("componentUuid"), toBoolean(row.get("isEmpty")), (String) row.get("textValue"), @@ -109,21 +108,21 @@ final class PropertiesRowAssert extends AbstractAssert", actual.getUserId()); + if (actual.getUserUuid() != null) { + failWithMessage("Expected PropertiesRow to have column USER_ID to be null but was <%s>", actual.getUserUuid()); } return this; } - public PropertiesRowAssert hasUserId(int expected) { + public PropertiesRowAssert hasUserUuid(String expected) { isNotNull(); - if (!Objects.equals(actual.getUserId(), expected)) { - failWithMessage("Expected PropertiesRow to have column USER_ID to be <%s> but was <%s>", true, actual.getUserId()); + if (!Objects.equals(actual.getUserUuid(), expected)) { + failWithMessage("Expected PropertiesRow to have column USER_ID to be <%s> but was <%s>", true, actual.getUserUuid()); } return this; diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java index 4fd787acb4c..5252ab28cfe 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java @@ -49,7 +49,8 @@ public class PropertyDtoTest { @Test public void testToString() { - assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setComponentUuid("uuid123").setUserId(456).toString()).isEqualTo("PropertyDto{foo:bar, value, uuid123, 456}"); + assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setComponentUuid("uuid123").setUserUuid("456").toString()) + .isEqualTo("PropertyDto{foo:bar, value, uuid123, 456}"); } @Test diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java index 9b4427dd171..cb0167d15ba 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java @@ -38,19 +38,19 @@ public class FavoriteDbTester { this.dbSession = db.getSession(); } - public void add(ComponentDto componentDto, int userId) { + public void add(ComponentDto componentDto, String userUuid) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) - .setUserId(userId) + .setUserUuid(userUuid) .setComponentUuid(componentDto.uuid())); dbSession.commit(); } - public boolean hasFavorite(ComponentDto componentDto, int userId) { + public boolean hasFavorite(ComponentDto componentDto, String userUuid) { List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentUuid(componentDto.uuid()) - .setUserId(userId) + .setUserUuid(userUuid) .build(), dbSession); return !result.isEmpty(); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java index ecbefb5588b..fdca6d3a340 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java @@ -42,11 +42,11 @@ public class NotificationDbTester { this.dbSession = db.getSession(); } - public void assertExists(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { + public void assertExists(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) { List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentUuid(component == null ? null : component.uuid()) - .setUserId(userId) + .setUserUuid(userUuid) .build(), dbSession).stream() .filter(prop -> component == null ? prop.getComponentUuid() == null : prop.getComponentUuid() != null) .collect(MoreCollectors.toList()); @@ -54,11 +54,11 @@ public class NotificationDbTester { assertThat(result.get(0).getValue()).isEqualTo("true"); } - public void assertDoesNotExist(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { + public void assertDoesNotExist(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) { List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentUuid(component == null ? null : component.uuid()) - .setUserId(userId) + .setUserUuid(userUuid) .build(), dbSession); assertThat(result).isEmpty(); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java index 47a7488bcdf..12af97d04d1 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyTesting.java @@ -54,43 +54,43 @@ public class PropertyTesting { public static PropertyDto newUserPropertyDto(String key, String value, UserDto user) { checkNotNull(user.getId()); - return newPropertyDto(key, value, null, user.getId()); + return newPropertyDto(key, value, null, user.getUuid()); } public static PropertyDto newUserPropertyDto(UserDto user) { checkNotNull(user.getId()); - return newPropertyDto(null, user.getId()); + return newPropertyDto(null, user.getUuid()); } public static PropertyDto newPropertyDto(String key, String value, ComponentDto component, UserDto user) { checkNotNull(component.uuid()); checkNotNull(user.getId()); - return newPropertyDto(key, value, component.uuid(), user.getId()); + return newPropertyDto(key, value, component.uuid(), user.getUuid()); } public static PropertyDto newPropertyDto(ComponentDto component, UserDto user) { checkNotNull(component.uuid()); checkNotNull(user.getId()); - return newPropertyDto(component.uuid(), user.getId()); + return newPropertyDto(component.uuid(), user.getUuid()); } - private static PropertyDto newPropertyDto(@Nullable String componentUuid, @Nullable Integer userId) { + private static PropertyDto newPropertyDto(@Nullable String componentUuid, @Nullable String userUuid) { String key = String.valueOf(cursor); cursor++; String value = String.valueOf(cursor); cursor++; - return newPropertyDto(key, value, componentUuid, userId); + return newPropertyDto(key, value, componentUuid, userUuid); } - private static PropertyDto newPropertyDto(String key, String value, @Nullable String componentUuid, @Nullable Integer userId) { + private static PropertyDto newPropertyDto(String key, String value, @Nullable String componentUuid, @Nullable String userUuid) { PropertyDto propertyDto = new PropertyDto() .setKey(key) .setValue(value); if (componentUuid != null) { propertyDto.setComponentUuid(componentUuid); } - if (userId != null) { - propertyDto.setUserId(userId); + if (userUuid != null) { + propertyDto.setUserUuid(userUuid); } return propertyDto; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index 259a43befbd..f567447bfba 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -279,6 +279,9 @@ import org.sonar.server.platform.db.migration.version.v83.users.fk.permtemplates import org.sonar.server.platform.db.migration.version.v83.users.fk.permtemplatesusers.DropUserIdColumnOfPermTemplatesUsersTable; import org.sonar.server.platform.db.migration.version.v83.users.fk.permtemplatesusers.MakePermTemplatesUsersUserUuidColumnNotNullable; import org.sonar.server.platform.db.migration.version.v83.users.fk.permtemplatesusers.PopulatePermTemplatesUsersUserUuid; +import org.sonar.server.platform.db.migration.version.v83.users.fk.properties.AddUserUuidColumnToPropertiesUsers; +import org.sonar.server.platform.db.migration.version.v83.users.fk.properties.DropUserIdColumnOfPropertiesTable; +import org.sonar.server.platform.db.migration.version.v83.users.fk.properties.PopulatePropertiesUserUuid; import org.sonar.server.platform.db.migration.version.v83.usertokens.AddPrimaryKeyOnUuidColumnOfUserTokensTable; import org.sonar.server.platform.db.migration.version.v83.usertokens.AddUuidColumnToUserTokens; import org.sonar.server.platform.db.migration.version.v83.usertokens.DropIdColumnOfUserTokensTable; @@ -674,6 +677,11 @@ public class DbVersion83 implements DbVersion { .add(3653, "Make 'user_uuid' not-null for 'PERM_TEMPLATES_USERS'", MakePermTemplatesUsersUserUuidColumnNotNullable.class) .add(3654, "Drop column on 'user_id' column of 'PERM_TEMPLATES_USERS' table", DropUserIdColumnOfPermTemplatesUsersTable.class) + // Migration of FK in PROPERTIES to USERS + .add(3616, "Add 'user_uuid' column on 'PROPERTIES' table", AddUserUuidColumnToPropertiesUsers.class) + .add(3617, "Populate 'user_uuid' for 'PROPERTIES'", PopulatePropertiesUserUuid.class) + .add(3618, "Drop column on 'user_id' column of 'PROPERTIES' table", DropUserIdColumnOfPropertiesTable.class) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsers.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsers.java new file mode 100644 index 00000000000..7aaf723df88 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsers.java @@ -0,0 +1,30 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.users.fk.properties; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.users.fk.util.AddUserUuidColumnToTable; + +public class AddUserUuidColumnToPropertiesUsers extends AddUserUuidColumnToTable { + + public AddUserUuidColumnToPropertiesUsers(Database db) { + super(db, "properties"); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTable.java new file mode 100644 index 00000000000..89453c14d17 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTable.java @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.users.fk.properties; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropUserIdColumnOfPropertiesTable extends DdlChange { + public DropUserIdColumnOfPropertiesTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropColumnsBuilder(getDialect(), "properties", "user_id").build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuid.java new file mode 100644 index 00000000000..fb709768fec --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuid.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.users.fk.properties; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +public class PopulatePropertiesUserUuid extends DataChange { + + public PopulatePropertiesUserUuid(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + + massUpdate.select("select p.uuid, u.uuid " + + "from properties p " + + "join users u on p.user_id = u.id where p.user_uuid is null"); + + massUpdate.update("update properties set user_uuid = ? where uuid = ?"); + + massUpdate.execute((row, update, index) -> { + String propertiesUuid = row.getString(1); + String userUuid = row.getString(2); + + update.setString(1, userUuid); + update.setString(2, propertiesUuid); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest.java new file mode 100644 index 00000000000..49370b15b1e --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.users.fk.properties; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.Uuids; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AddUserUuidColumnToPropertiesUsersTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddUserUuidColumnToPropertiesUsersTest.class, "schema.sql"); + + private DdlChange underTest = new AddUserUuidColumnToPropertiesUsers(db.database()); + + @Before + public void setup() { + insertProperty(Uuids.createFast()); + insertProperty(Uuids.createFast()); + insertProperty(Uuids.createFast()); + } + + @Test + public void add_uuid_column() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("properties", "user_uuid", Types.VARCHAR, 40, true); + + assertThat(db.countSql("select count(*) from properties")) + .isEqualTo(3); + } + + private void insertProperty(String uuid) { + db.executeInsert("properties", + "uuid", uuid, + "prop_key", "kee-" + uuid, + "is_empty", false, + "created_at", System.currentTimeMillis()); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest.java new file mode 100644 index 00000000000..ca84f8399cf --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.users.fk.properties; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropUserIdColumnOfPropertiesTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropUserIdColumnOfPropertiesTableTest.class, "schema.sql"); + + private DdlChange underTest = new DropUserIdColumnOfPropertiesTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("properties", "user_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest.java new file mode 100644 index 00000000000..63943ddc6ad --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest.java @@ -0,0 +1,154 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.users.fk.properties; + +import java.sql.SQLException; +import java.util.Objects; +import java.util.Optional; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.Uuids; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulatePropertiesUserUuidTest { + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulatePropertiesUserUuidTest.class, "schema.sql"); + + private DataChange underTest = new PopulatePropertiesUserUuid(db.database()); + + @Test + public void populate_uuids() throws SQLException { + long userId_1 = 1L; + String userUuid_1 = "uuid-1"; + insertUser(userId_1, userUuid_1); + + long userId_2 = 2L; + String userUuid_2 = "uuid-2"; + insertUser(userId_2, userUuid_2); + + long userId_3 = 3L; + String userUuid_3 = "uuid-3"; + insertUser(userId_3, userUuid_3); + + long userId_4 = 4L; + String userUuid_4 = "uuid-4"; + insertUser(userId_4, userUuid_4); + + String propertyUuid_1 = Uuids.createFast(); + insertProperty(propertyUuid_1, userId_1); + String propertyUuid_2 = Uuids.createFast(); + insertProperty(propertyUuid_2, userId_2); + String propertyUuid_3 = Uuids.createFast(); + insertProperty(propertyUuid_3, userId_3); + String propertyUuid_4 = Uuids.createFast(); + insertProperty(propertyUuid_4, userId_4); + String propertyUuid_5 = Uuids.createFast(); + insertProperty(propertyUuid_5, null); + + underTest.execute(); + + assertThatPropertyUserUuidIsEqualTo(propertyUuid_1, userUuid_1); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_2, userUuid_2); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_3, userUuid_3); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_4, userUuid_4); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_5, null); + } + + @Test + public void migration_is_reentrant() throws SQLException { + long userId_1 = 1L; + String userUuid_1 = "uuid-1"; + insertUser(userId_1, userUuid_1); + + long userId_2 = 2L; + String userUuid_2 = "uuid-2"; + insertUser(userId_2, userUuid_2); + + long userId_3 = 3L; + String userUuid_3 = "uuid-3"; + insertUser(userId_3, userUuid_3); + + long userId_4 = 4L; + String userUuid_4 = "uuid-4"; + insertUser(userId_4, userUuid_4); + + String propertyUuid_1 = Uuids.createFast(); + insertProperty(propertyUuid_1, userId_1); + String propertyUuid_2 = Uuids.createFast(); + insertProperty(propertyUuid_2, userId_2); + String propertyUuid_3 = Uuids.createFast(); + insertProperty(propertyUuid_3, userId_3); + + underTest.execute(); + + String propertyUuid_4 = Uuids.createFast(); + insertProperty(propertyUuid_4, userId_4); + String propertyUuid_5 = Uuids.createFast(); + insertProperty(propertyUuid_5, null); + + // re-entrant + underTest.execute(); + + assertThatPropertyUserUuidIsEqualTo(propertyUuid_1, userUuid_1); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_2, userUuid_2); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_3, userUuid_3); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_4, userUuid_4); + assertThatPropertyUserUuidIsEqualTo(propertyUuid_5, null); + } + + private void assertThatPropertyUserUuidIsEqualTo(String propertyUuid, String expectedUuid) { + Optional optional = db.select(String.format("select user_uuid from properties where uuid = '%s'", propertyUuid)) + .stream() + .map(row -> row.get("USER_UUID")) + .filter(Objects::nonNull) + .findFirst(); + + if (expectedUuid != null) { + assertThat(optional).hasValue(expectedUuid); + } else { + assertThat(optional).isEmpty(); + } + + } + + private void insertProperty(String uuid, Long userId) { + db.executeInsert("properties", + "uuid", uuid, + "user_id", userId, + "prop_key", "kee-" + uuid, + "is_empty", false, + "created_at", System.currentTimeMillis()); + } + + private void insertUser(Long id, String uuid) { + db.executeInsert("users", + "id", id, + "uuid", uuid, + "login", "login" + id, + "external_login", "ex-login" + id, + "external_identity_provider", "ex-provider" + id, + "external_id", id + 1, + "is_root", false, + "onboarded", false); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest/schema.sql new file mode 100644 index 00000000000..e63f2fb66c8 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/AddUserUuidColumnToPropertiesUsersTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "PROPERTIES"( + "UUID" VARCHAR(40) NOT NULL, + "PROP_KEY" VARCHAR(512) NOT NULL, + "IS_EMPTY" BOOLEAN NOT NULL, + "TEXT_VALUE" VARCHAR(4000), + "CLOB_VALUE" CLOB(2147483647), + "CREATED_AT" BIGINT NOT NULL, + "COMPONENT_UUID" VARCHAR(40) +); +ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID"); +CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest/schema.sql new file mode 100644 index 00000000000..a3d1fbfeeea --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/DropUserIdColumnOfPropertiesTableTest/schema.sql @@ -0,0 +1,15 @@ +CREATE TABLE "PROPERTIES"( + "UUID" VARCHAR(40) NOT NULL, + "PROP_KEY" VARCHAR(512) NOT NULL, + "USER_ID" INTEGER, + "IS_EMPTY" BOOLEAN NOT NULL, + "TEXT_VALUE" VARCHAR(4000), + "CLOB_VALUE" CLOB(2147483647), + "CREATED_AT" BIGINT NOT NULL, + "COMPONENT_UUID" VARCHAR(40), + "USER_UUID" VARCHAR(40) +); +ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID"); +CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY"); + + diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest/schema.sql new file mode 100644 index 00000000000..7b392af768c --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/users/fk/properties/PopulatePropertiesUserUuidTest/schema.sql @@ -0,0 +1,44 @@ +CREATE TABLE "USERS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(255) NOT NULL, + "LOGIN" VARCHAR(255) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40), + "NAME" VARCHAR(200), + "EMAIL" VARCHAR(100), + "CRYPTED_PASSWORD" VARCHAR(100), + "SALT" VARCHAR(40), + "HASH_METHOD" VARCHAR(10), + "ACTIVE" BOOLEAN DEFAULT TRUE, + "SCM_ACCOUNTS" VARCHAR(4000), + "EXTERNAL_LOGIN" VARCHAR(255) NOT NULL, + "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100) NOT NULL, + "EXTERNAL_ID" VARCHAR(255) NOT NULL, + "IS_ROOT" BOOLEAN NOT NULL, + "USER_LOCAL" BOOLEAN, + "ONBOARDED" BOOLEAN NOT NULL, + "HOMEPAGE_TYPE" VARCHAR(40), + "HOMEPAGE_PARAMETER" VARCHAR(40), + "LAST_CONNECTION_DATE" BIGINT, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT +); +ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("ID"); +CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN"); +CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT"); +CREATE UNIQUE INDEX "USERS_UUID" ON "USERS"("UUID"); +CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER", "EXTERNAL_ID"); +CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER", "EXTERNAL_LOGIN"); + +CREATE TABLE "PROPERTIES"( + "UUID" VARCHAR(40) NOT NULL, + "PROP_KEY" VARCHAR(512) NOT NULL, + "USER_ID" INTEGER, + "IS_EMPTY" BOOLEAN NOT NULL, + "TEXT_VALUE" VARCHAR(4000), + "CLOB_VALUE" CLOB(2147483647), + "CREATED_AT" BIGINT NOT NULL, + "COMPONENT_UUID" VARCHAR(40), + "USER_UUID" VARCHAR(40) +); +ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID"); +CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY"); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java index 4e115b3ae70..c7af1c696c3 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java @@ -41,19 +41,19 @@ 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 Integer userId, boolean failIfTooManyFavorites) { - if (userId == null) { + public void add(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, boolean failIfTooManyFavorites) { + if (userUuid == null) { return; } List existingFavoriteOnComponent = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) - .setUserId(userId) + .setUserUuid(userUuid) .setComponentUuid(componentDto.uuid()) .build(), dbSession); checkArgument(existingFavoriteOnComponent.isEmpty(), "Component '%s' is already a favorite", componentDto.getDbKey()); - List existingFavorites = dbClient.propertiesDao().selectByKeyAndUserIdAndComponentQualifier(dbSession, PROP_FAVORITE_KEY, userId, componentDto.qualifier()); + List existingFavorites = dbClient.propertiesDao().selectByKeyAndUserUuidAndComponentQualifier(dbSession, PROP_FAVORITE_KEY, userUuid, componentDto.qualifier()); if (existingFavorites.size() >= 100) { checkArgument(!failIfTooManyFavorites, "You cannot have more than 100 favorites on components with qualifier '%s'", componentDto.qualifier()); return; @@ -61,22 +61,22 @@ public class FavoriteUpdater { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setComponentUuid(componentDto.uuid()) - .setUserId(userId)); + .setUserUuid(userUuid)); } /** * Remove a favorite to the user. * @throws IllegalArgumentException if the component is not a favorite */ - public void remove(DbSession dbSession, ComponentDto component, @Nullable Integer userId) { - if (userId == null) { + public void remove(DbSession dbSession, ComponentDto component, @Nullable String userUuid) { + if (userUuid == null) { return; } int result = dbClient.propertiesDao().delete(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setComponentUuid(component.uuid()) - .setUserId(userId)); + .setUserUuid(userUuid)); checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey()); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java index e5a3ac80176..4daeff65961 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java @@ -50,7 +50,7 @@ public class FavoriteUpdaterTest { UserDto user = db.users().insertUser(); assertNoFavorite(project, user); - underTest.add(dbSession, project, user.getId(), true); + underTest.add(dbSession, project, user.getUuid(), true); assertFavorite(project, user); } @@ -69,70 +69,70 @@ public class FavoriteUpdaterTest { @Test public void do_not_add_favorite_when_already_100_favorite_projects() { UserDto user = db.users().insertUser(); - IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getId())); + IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid())); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession)).hasSize(100); ComponentDto project = db.components().insertPrivateProject(); - underTest.add(dbSession, project, user.getId(), false); + underTest.add(dbSession, project, user.getUuid(), false); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession)).hasSize(100); } @Test public void do_not_add_favorite_when_already_100_favorite_portfolios() { UserDto user = db.users().insertUser(); - IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getId())); + IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid())); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession)).hasSize(100); ComponentDto project = db.components().insertPrivateProject(); - underTest.add(dbSession, project, user.getId(), false); + underTest.add(dbSession, project, user.getUuid(), false); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession)).hasSize(100); } @Test public void fail_when_more_than_100_projects_favorites() { UserDto user = db.users().insertUser(); - IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getId())); + IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid())); ComponentDto project = db.components().insertPrivateProject(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("You cannot have more than 100 favorites on components with qualifier 'TRK'"); - underTest.add(dbSession, project, user.getId(), true); + underTest.add(dbSession, project, user.getUuid(), true); } @Test public void fail_when_adding_existing_favorite() { ComponentDto project = db.components().insertPrivateProject(); UserDto user = db.users().insertUser(); - underTest.add(dbSession, project, user.getId(), true); + underTest.add(dbSession, project, user.getUuid(), true); assertFavorite(project, user); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(String.format("Component '%s' is already a favorite", project.getKey())); - underTest.add(dbSession, project, user.getId(), true); + underTest.add(dbSession, project, user.getUuid(), true); } private void assertFavorite(ComponentDto project, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .setComponentUuid(project.uuid()) .build(), dbSession)).hasSize(1); } private void assertNoFavorite(ComponentDto project, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .setComponentUuid(project.uuid()) .build(), dbSession)).isEmpty(); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java index 39604174886..58da4ebdee1 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java @@ -139,8 +139,8 @@ public class MemberUpdater { dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userId); dbClient.permissionTemplateDao().deleteUserPermissionsByOrganization(dbSession, organizationUuid, userUuid); dbClient.qProfileEditUsersDao().deleteByOrganizationAndUser(dbSession, organization, user); - dbClient.userGroupDao().deleteByOrganizationAndUser(dbSession, organizationUuid, user.getUuid()); - dbClient.propertiesDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); + dbClient.userGroupDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userUuid); + dbClient.propertiesDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userUuid); dbClient.propertiesDao().deleteByOrganizationAndMatchingLogin(dbSession, organizationUuid, user.getLogin(), singletonList(DEFAULT_ISSUE_ASSIGNEE)); dbClient.organizationMemberDao().delete(dbSession, organizationUuid, userUuid); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java index e1a99f1022b..f8d11d8bd49 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java @@ -337,17 +337,18 @@ public class MemberUpdaterTest { OrganizationDto anotherOrganization = db.organizations().insert(); ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization); UserDto anotherUser = db.users().insertUser(); - insertProperty("KEY_11", "VALUE", project.uuid(), user.getId()); - insertProperty("KEY_12", "VALUE", project.uuid(), user.getId()); - insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getId()); - insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getId()); + insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid()); + insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid()); + insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid()); + insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid()); underTest.removeMember(db.getSession(), organization, user); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), db.getSession())) - .hasSize(1).extracting(PropertyDto::getUserId).containsOnly(anotherUser.getId()); - assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), db.getSession())).extracting(PropertyDto::getUserId) - .hasSize(1).containsOnly(user.getId()); + .hasSize(1).extracting(PropertyDto::getUserUuid).containsOnly(anotherUser.getUuid()); + assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(anotherProject.uuid()).build(), db.getSession())) + .extracting(PropertyDto::getUserUuid) + .hasSize(1).containsOnly(user.getUuid()); } @Test @@ -506,10 +507,10 @@ public class MemberUpdaterTest { assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(db.getSession(), user.getId(), project.uuid())).containsOnly(permissions); } - private void insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable Integer userId) { + private void insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid) { PropertyDto dto = new PropertyDto().setKey(key) .setComponentUuid(componentUuid) - .setUserId(userId) + .setUserUuid(userUuid) .setValue(value); db.properties().insertProperty(dto); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java index 74f42df895f..b853c99d508 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java @@ -161,7 +161,6 @@ public class ReportSubmitter { private ComponentDto createProject(DbSession dbSession, OrganizationDto organization, BranchSupport.ComponentKey componentKey, @Nullable String projectName) { userSession.checkPermission(OrganizationPermission.PROVISION_PROJECTS, organization); - Integer userId = userSession.getUserId(); String userUuid = userSession.getUuid(); boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate( @@ -179,7 +178,7 @@ public class ReportSubmitter { .setQualifier(Qualifiers.PROJECT) .setPrivate(newProjectPrivate) .build(); - return componentUpdater.createWithoutCommit(dbSession, newProject, userId, c -> { + return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, c -> { }); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java index 0ae333ec5ee..3043090204d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -75,8 +75,8 @@ public class ComponentUpdater { * - Add component to favorite if the component has the 'Project Creators' permission * - Index component in es indexes */ - public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable Integer userId) { - ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userId, c -> { + public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid) { + ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, c -> { }); commitAndIndex(dbSession, componentDto); return componentDto; @@ -86,13 +86,13 @@ public class ComponentUpdater { * Create component without committing. * Don't forget to call commitAndIndex(...) when ready to commit. */ - public ComponentDto createWithoutCommit(DbSession dbSession, NewComponent newComponent, @Nullable Integer userId, Consumer componentModifier) { + public ComponentDto createWithoutCommit(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid, Consumer componentModifier) { checkKeyFormat(newComponent.qualifier(), newComponent.key()); ComponentDto componentDto = createRootComponent(dbSession, newComponent, componentModifier); if (isRootProject(componentDto)) { createMainBranch(dbSession, componentDto.uuid()); } - handlePermissionTemplate(dbSession, componentDto, userId); + handlePermissionTemplate(dbSession, componentDto, userUuid); return componentDto; } @@ -161,11 +161,11 @@ public class ComponentUpdater { dbClient.branchDao().upsert(session, branch); } - private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable Integer userId) { - permissionTemplateService.applyDefault(dbSession, componentDto, userId); + private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid) { + permissionTemplateService.applyDefault(dbSession, componentDto, userUuid); if (componentDto.qualifier().equals(PROJECT) && permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(dbSession, componentDto)) { - favoriteUpdater.add(dbSession, componentDto, userId, false); + favoriteUpdater.add(dbSession, componentDto, userUuid, false); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java index 853cbb090ff..7134dfc1bb1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java @@ -100,7 +100,7 @@ public class ComponentViewerJsonWriter { List propertyDtos = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey("favourite") .setComponentUuid(component.uuid()) - .setUserId(userSession.getUserId()) + .setUserUuid(userSession.getUuid()) .build(), session); boolean isFavourite = propertyDtos.size() == 1; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index dc1ec5f7179..16d4170e02a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -331,7 +331,7 @@ public class SearchProjectsAction implements ComponentsWsAction { List props = dbClient.propertiesDao().selectByQuery( PropertyQuery.builder() - .setUserId(userSession.getUserId()) + .setUserUuid(userSession.getUuid()) .setKey("favourite") .build(), dbSession); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java index 3f1b145fff5..74985399456 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java @@ -54,7 +54,7 @@ public class FavoriteFinder { try (DbSession dbSession = dbClient.openSession(false)) { PropertyQuery dbQuery = PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) - .setUserId(userSession.getUserId()) + .setUserUuid(userSession.getUuid()) .build(); Set componentUuids = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getComponentUuid).collect(Collectors.toSet()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java index 26a9394dd48..eb2d3f5da13 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java @@ -97,7 +97,7 @@ public class AddAction implements FavoritesWsAction { userSession .checkLoggedIn() .checkComponentPermission(USER, componentDto); - favoriteUpdater.add(dbSession, componentDto, userSession.isLoggedIn() ? userSession.getUserId() : null, true); + favoriteUpdater.add(dbSession, componentDto, userSession.isLoggedIn() ? userSession.getUuid() : null, true); dbSession.commit(); } }; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java index a3d8597e476..84119ae281e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java @@ -75,7 +75,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() : null); + favoriteUpdater.remove(dbSession, component, userSession.isLoggedIn() ? userSession.getUuid() : null); dbSession.commit(); } }; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java index 190bc862f8c..82b55e1e822 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java @@ -121,7 +121,7 @@ public class ListAction implements NotificationsWsAction { private UnaryOperator addNotifications(DbSession dbSession, UserDto user) { return response -> { - List properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession); + List properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserUuid(user.getUuid()).build(), dbSession); Map componentsByUuid = searchProjects(dbSession, properties); Map organizationsByUuid = getOrganizations(dbSession, componentsByUuid.values()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java index ce79c49be02..de444fbe2cc 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java @@ -53,7 +53,7 @@ public class NotificationUpdater { PropertyQuery.builder() .setKey(key) .setComponentUuid(projectUuid) - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession).stream() .filter(notificationScope(project)) @@ -63,7 +63,7 @@ public class NotificationUpdater { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(key) - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .setValue(PROP_NOTIFICATION_VALUE) .setComponentUuid(projectUuid)); } @@ -79,7 +79,7 @@ public class NotificationUpdater { PropertyQuery.builder() .setKey(key) .setComponentUuid(projectUuid) - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession).stream() .filter(notificationScope(project)) @@ -88,7 +88,7 @@ public class NotificationUpdater { dbClient.propertiesDao().delete(dbSession, new PropertyDto() .setKey(key) - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .setValue(PROP_NOTIFICATION_VALUE) .setComponentUuid(projectUuid)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index 3ed572b6aae..f0f965d49ca 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -110,7 +110,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, ComponentDto component, @Nullable Integer projectCreatorUserId) { + public void applyDefault(DbSession dbSession, ComponentDto component, @Nullable String projectCreatorUserId) { PermissionTemplateDto template = findTemplate(dbSession, component); checkArgument(template != null, "Cannot retrieve default permission template"); copyPermissions(dbSession, template, component, projectCreatorUserId); @@ -126,7 +126,7 @@ public class PermissionTemplateService { .anyMatch(PermissionTemplateCharacteristicDto::getWithProjectCreator); } - private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Integer projectCreatorUserId) { + private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable String projectCreatorUserUuid) { dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid()); dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid()); @@ -158,17 +158,19 @@ public class PermissionTemplateService { }); List characteristics = dbClient.permissionTemplateCharacteristicDao().selectByTemplateUuids(dbSession, singletonList(template.getUuid())); - if (projectCreatorUserId != null) { + if (projectCreatorUserUuid != null) { Set permissionsForCurrentUserAlreadyInDb = usersPermissions.stream() - .filter(userPermission -> projectCreatorUserId.equals(userPermission.getUserUuid())) + .filter(userPermission -> projectCreatorUserUuid.equals(userPermission.getUserUuid())) .map(PermissionTemplateUserDto::getPermission) .collect(java.util.stream.Collectors.toSet()); + + UserDto userDto = dbClient.userDao().selectByUuid(dbSession, projectCreatorUserUuid); characteristics.stream() .filter(PermissionTemplateCharacteristicDto::getWithProjectCreator) .filter(up -> permissionValidForProject(project, up.getPermission())) .filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission())) .forEach(c -> { - UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), organizationUuid, c.getPermission(), projectCreatorUserId, project.uuid()); + UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), organizationUuid, c.getPermission(), userDto.getId(), project.uuid()); dbClient.userPermissionDao().insert(dbSession, dto); }); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java index f023058ab29..6b3c7f097af 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java @@ -118,7 +118,7 @@ public class CreateAction implements ProjectsWsAction { .setPrivate(changeToPrivate) .setQualifier(PROJECT) .build(), - userSession.isLoggedIn() ? userSession.getUserId() : null); + userSession.isLoggedIn() ? userSession.getUuid() : null); return toCreateResponse(componentDto); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index fb5da6beebf..c48578ffd39 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -243,7 +243,7 @@ public class ComponentAction implements NavigationWsAction { private boolean isFavourite(DbSession session, ComponentDto component) { PropertyQuery propertyQuery = PropertyQuery.builder() - .setUserId(userSession.getUserId()) + .setUserUuid(userSession.getUuid()) .setKey("favourite") .setComponentUuid(component.uuid()) .build(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java index c5bbd0e145b..eb4a2ce0566 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java @@ -101,7 +101,7 @@ public class DeactivateAction implements UsersWsAction { String userUuid = user.getUuid(); dbClient.userTokenDao().deleteByUser(dbSession, user); dbClient.propertiesDao().deleteByKeyAndValue(dbSession, DEFAULT_ISSUE_ASSIGNEE, user.getLogin()); - dbClient.propertiesDao().deleteByQuery(dbSession, PropertyQuery.builder().setUserId(userId).build()); + dbClient.propertiesDao().deleteByQuery(dbSession, PropertyQuery.builder().setUserUuid(userUuid).build()); dbClient.userGroupDao().deleteByUserUuid(dbSession, userUuid); dbClient.userPermissionDao().deleteByUserId(dbSession, userId); dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java index cc06ba33093..293b2b6d7b3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java @@ -181,7 +181,7 @@ public class BranchReportSubmitterTest { BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); when(branchSupportDelegate.createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics)) .thenReturn(componentKey); - when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getId()), any())) + when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), any())) .thenAnswer((Answer) invocation -> db.components().insertPrivateProject(nonExistingProject)); when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(organization), eq(nonExistingProject), any())) .thenReturn(createdBranch); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java index 130cbf2e384..53a5cf331c7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java @@ -187,7 +187,7 @@ public class ReportSubmitterTest { underTest.submit(organization.getKey(), PROJECT_KEY, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}")); ComponentDto createdProject = db.getDbClient().componentDao().selectByKey(db.getSession(), PROJECT_KEY).get(); - assertThat(db.favorites().hasFavorite(createdProject, user.getId())).isTrue(); + assertThat(db.favorites().hasFavorite(createdProject, user.getUuid())).isTrue(); } @Test @@ -209,7 +209,7 @@ public class ReportSubmitterTest { @Test public void do_no_add_favorite_when_already_100_favorite_projects_and_no_project_creator_permission_on_permission_template() { UserDto user = db.users().insertUser(); - rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getId())); + rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid())); OrganizationDto organization = db.organizations().insert(); userSession .logIn(user) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java index bb2ea365fff..915b6adea8c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java @@ -183,15 +183,15 @@ public class ComponentUpdaterTest { @Test public void apply_default_permission_template() { - int userId = 42; + String userUuid = "42"; NewComponent project = NewComponent.newComponentBuilder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) .setOrganizationUuid(db.getDefaultOrganization().getUuid()) .build(); - ComponentDto dto = underTest.create(db.getSession(), project, userId); + ComponentDto dto = underTest.create(db.getSession(), project, userUuid); - verify(permissionTemplateService).applyDefault(db.getSession(), dto, userId); + verify(permissionTemplateService).applyDefault(db.getSession(), dto, userUuid); } @Test @@ -205,15 +205,15 @@ public class ComponentUpdaterTest { when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class))) .thenReturn(true); - ComponentDto dto = underTest.create(db.getSession(), project, userDto.getId()); + ComponentDto dto = underTest.create(db.getSession(), project, userDto.getUuid()); - assertThat(db.favorites().hasFavorite(dto, userDto.getId())).isTrue(); + assertThat(db.favorites().hasFavorite(dto, userDto.getUuid())).isTrue(); } @Test public void do_not_add_project_to_user_favorites_if_project_creator_is_defined_in_permission_template_and_already_100_favorites() { UserDto user = db.users().insertUser(); - rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getId())); + rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid())); NewComponent project = NewComponent.newComponentBuilder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) @@ -224,9 +224,9 @@ public class ComponentUpdaterTest { ComponentDto dto = underTest.create(db.getSession(), project, - user.getId()); + user.getUuid()); - assertThat(db.favorites().hasFavorite(dto, user.getId())).isFalse(); + assertThat(db.favorites().hasFavorite(dto, user.getUuid())).isFalse(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java index 5675a87bace..de48f24eead 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java @@ -224,7 +224,7 @@ public class AppActionTest { public void component_is_favorite() { ComponentDto project = db.components().insertPrivateProject(); userSession.logIn("john").addProjectPermission(USER, project); - db.favorites().add(project, userSession.getUserId()); + db.favorites().add(project, userSession.getUuid()); String result = ws.newRequest() .setParam("component", project.getKey()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index a8b00a512b8..2bb15d7a4e7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -1406,7 +1406,7 @@ public class SearchProjectsActionTest { } private void addFavourite(ComponentDto project) { - dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(userSession.getUserId())); + dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(userSession.getUuid())); dbSession.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java index 57c97bb768a..4f94200f62b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java @@ -78,14 +78,14 @@ public class AddActionTest { assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT); List favorites = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .setKey("favourite") .build(), dbSession); assertThat(favorites).hasSize(1); PropertyDto favorite = favorites.get(0); assertThat(favorite) - .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getKey) - .containsOnly(project.uuid(), user.getId(), "favourite"); + .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getKey) + .containsOnly(project.uuid(), user.getUuid(), "favourite"); } @Test @@ -98,14 +98,14 @@ public class AddActionTest { call(file.getKey()); List favorites = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .setKey("favourite") .build(), dbSession); assertThat(favorites).hasSize(1); PropertyDto favorite = favorites.get(0); assertThat(favorite) - .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getKey) - .containsOnly(file.uuid(), user.getId(), "favourite"); + .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getKey) + .containsOnly(file.uuid(), user.getUuid(), "favourite"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java index 8983cb11860..f6228f5e463 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java @@ -20,6 +20,7 @@ package org.sonar.server.favorite.ws; import javax.annotation.Nullable; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -29,6 +30,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; +import org.sonar.db.user.UserDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -49,7 +51,7 @@ import static org.sonar.server.favorite.ws.FavoritesWsParameters.PARAM_COMPONENT public class RemoveActionTest { private static final String PROJECT_KEY = "project-key"; private static final String PROJECT_UUID = "project-uuid"; - private static final int USER_ID = 123; + private UserDto user; @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -63,18 +65,23 @@ public class RemoveActionTest { private FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient); private WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db))); + @Before + public void before() { + user = db.users().insertUser(); + } + @Test public void remove_a_favorite_project() { ComponentDto project = insertProjectAndPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - db.favorites().add(project, USER_ID); - db.favorites().add(file, USER_ID); + db.favorites().add(project, user.getUuid()); + db.favorites().add(file, user.getUuid()); TestResponse result = call(PROJECT_KEY); assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT); - assertThat(db.favorites().hasFavorite(project, USER_ID)).isFalse(); - assertThat(db.favorites().hasFavorite(file, USER_ID)).isTrue(); + assertThat(db.favorites().hasFavorite(project, user.getUuid())).isFalse(); + assertThat(db.favorites().hasFavorite(file, user.getUuid())).isTrue(); } @Test @@ -132,7 +139,7 @@ public class RemoveActionTest { } private ComponentDto insertProjectAndPermissions() { - userSession.logIn().setUserId(USER_ID); + userSession.logIn(user); return insertProject(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java index eb50c09c802..a4a70e1cc40 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java @@ -21,6 +21,7 @@ package org.sonar.server.favorite.ws; import java.util.stream.IntStream; import javax.annotation.Nullable; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -32,6 +33,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; +import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.favorite.FavoriteFinder; import org.sonar.server.tester.UserSessionRule; @@ -52,11 +54,11 @@ import static org.sonar.test.JsonAssert.assertJson; import static org.sonarqube.ws.client.WsRequest.Method.POST; public class SearchActionTest { - private static final int USER_ID = 123; + private String userUuid; @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule - public UserSessionRule userSession = UserSessionRule.standalone().logIn().setUserId(USER_ID); + public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(); private DbClient dbClient = db.getDbClient(); @@ -65,6 +67,13 @@ public class SearchActionTest { private WsActionTester ws = new WsActionTester(new SearchAction(favoriteFinder, dbClient, userSession)); + @Before + public void before() { + UserDto userDto = db.users().insertUser(); + userSession.logIn(userDto); + userUuid = userDto.getUuid(); + } + @Test public void return_favorites() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "P1").setDbKey("K1").setName("N1"); @@ -98,7 +107,7 @@ public class SearchActionTest { OrganizationDto organizationDto = db.organizations().insert(); addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("K1")); ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto)); - db.favorites().add(unauthorizedProject, USER_ID); + db.favorites().add(unauthorizedProject, userUuid); SearchResponse result = call(); @@ -111,7 +120,7 @@ public class SearchActionTest { IntStream.rangeClosed(1, 9) .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("K" + i).setName("N" + i))); ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization())); - db.favorites().add(unauthorizedProject, USER_ID); + db.favorites().add(unauthorizedProject, userUuid); SearchResponse result = call(2, 3); @@ -128,7 +137,7 @@ public class SearchActionTest { addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("K1")); ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("K42"); db.components().insertComponent(otherUserFavorite); - db.favorites().add(otherUserFavorite, 42); + db.favorites().add(otherUserFavorite, "42"); db.commit(); SearchResponse result = call(); @@ -181,7 +190,7 @@ public class SearchActionTest { private void addComponent(ComponentDto component) { db.components().insertComponent(component); - db.favorites().add(component, USER_ID); + db.favorites().add(component, userUuid); db.commit(); userSession.addProjectPermission(UserRole.USER, component); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java index fb5f26017c0..927ce60002d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java @@ -89,7 +89,7 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, null, null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), null); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), null); } @Test @@ -100,7 +100,7 @@ public class AddActionTest { call(NOTIF_NEW_QUALITY_GATE_STATUS, twitterChannel.getKey(), null, null); - db.notifications().assertExists(twitterChannel.getKey(), NOTIF_NEW_QUALITY_GATE_STATUS, userSession.getUserId(), null); + db.notifications().assertExists(twitterChannel.getKey(), NOTIF_NEW_QUALITY_GATE_STATUS, userSession.getUuid(), null); } @Test @@ -114,7 +114,7 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), project); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); } @Test @@ -128,7 +128,7 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), project); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); } @Test @@ -143,8 +143,8 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, null, null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), project); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), null); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), null); } @Test @@ -159,8 +159,8 @@ public class AddActionTest { userSession.addProjectPermission(USER, project); call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), project); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), null); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), null); } @Test @@ -175,8 +175,8 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), project); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), null); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), project); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUuid(), null); } @Test @@ -198,7 +198,7 @@ public class AddActionTest { call(NOTIF_MY_NEW_ISSUES, null, null, user.getLogin()); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getId(), null); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getUuid(), null); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java index 54e3c737d62..f47fcd48063 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java @@ -92,7 +92,7 @@ public class RemoveActionTest { call(request); - db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getId(), null); + db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getUuid(), null); } @Test @@ -105,7 +105,7 @@ public class RemoveActionTest { call(request.setType(NOTIF_NEW_QUALITY_GATE_STATUS).setChannel(twitterChannel.getKey())); - db.notifications().assertDoesNotExist(twitterChannel.getKey(), NOTIF_NEW_QUALITY_GATE_STATUS, user.getId(), null); + db.notifications().assertDoesNotExist(twitterChannel.getKey(), NOTIF_NEW_QUALITY_GATE_STATUS, user.getUuid(), null); } @Test @@ -120,7 +120,7 @@ public class RemoveActionTest { call(request.setProject(project.getDbKey())); - db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getId(), project); + db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getUuid(), project); } @Test @@ -175,13 +175,13 @@ public class RemoveActionTest { userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null); - db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getId(), null); + db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getUuid(), null); userSession.logIn().setSystemAdministrator(); dbSession.commit(); call(request.setLogin(user.getLogin())); - db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getId(), null); + db.notifications().assertDoesNotExist(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user.getUuid(), null); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index c8236a92a8e..f1ecbd8cd0c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -89,7 +89,7 @@ public class PermissionTemplateServiceTest { dbTester.permissionTemplates().addAnyoneToTemplate(permissionTemplate, "p1"); dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null); - underTest.applyDefault(session, privateProject, creator.getId()); + underTest.applyDefault(session, privateProject, creator.getUuid()); assertThat(selectProjectPermissionsOfGroup(organization, null, privateProject)).isEmpty(); } @@ -268,7 +268,7 @@ public class PermissionTemplateServiceTest { dbTester.permissionTemplates().addProjectCreatorToTemplate(permissionTemplate, "p1"); dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null); - underTest.applyDefault(session, publicProject, user.getId()); + underTest.applyDefault(session, publicProject, user.getUuid()); assertThat(selectProjectPermissionsOfUser(user, publicProject)) .containsOnly("p1", UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey()); @@ -285,7 +285,7 @@ public class PermissionTemplateServiceTest { dbTester.permissionTemplates().addProjectCreatorToTemplate(permissionTemplate, "p1"); dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null); - underTest.applyDefault(session, privateProject, user.getId()); + underTest.applyDefault(session, privateProject, user.getUuid()); assertThat(selectProjectPermissionsOfUser(user, privateProject)) .containsOnly("p1", UserRole.CODEVIEWER, UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, SCAN.getKey()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java index 4b23370bc14..9b44d302a13 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java @@ -218,7 +218,7 @@ public class CreateActionTest { .executeProtobuf(CreateWsResponse.class); ComponentDto project = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get(); - assertThat(db.favorites().hasFavorite(project, user.getId())).isTrue(); + assertThat(db.favorites().hasFavorite(project, user.getUuid())).isTrue(); } @Test @@ -226,7 +226,7 @@ public class CreateActionTest { OrganizationDto organization = db.organizations().insert(); UserDto user = db.users().insertUser(); when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class))).thenReturn(true); - rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getId())); + rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid())); userSession.logIn(user).addPermission(PROVISION_PROJECTS, organization); ws.newRequest() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index 30a51c956e5..6609556ffe7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -495,7 +495,7 @@ public class ResetActionTest { private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(key) - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession)).isNotEmpty(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index ac26830ad8c..41000bffc1a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -365,13 +365,13 @@ public class SetActionTest { @Test public void user_setting_is_not_updated() { - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserId(42)); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("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", 42); + assertUserSetting("my.key", "my user value", "42"); } @Test @@ -966,12 +966,12 @@ public class SetActionTest { .containsExactly(key, value, null); } - private void assertUserSetting(String key, String value, int userId) { - List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(key).setUserId(userId).build(), dbSession); + private void assertUserSetting(String key, String value, String userUuid) { + List result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(key).setUserUuid(userUuid).build(), dbSession); assertThat(result).hasSize(1) - .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getUserId) - .containsExactly(tuple(key, value, userId)); + .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getUserUuid) + .containsExactly(tuple(key, value, userUuid)); } private void assertComponentSetting(String key, String value, String componentUuid) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java index 6c04d4f67f0..f57833e9e07 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java @@ -216,7 +216,7 @@ public class SettingsUpdaterTest { private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(key) - .setUserId(user.getId()) + .setUserUuid(user.getUuid()) .build(), dbSession)).isNotEmpty(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index 984282b4370..32f037f8034 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -148,7 +148,7 @@ public class ComponentActionTest { public void return_component_info_with_favourite() { ComponentDto project = insertOrganizationAndProject(); UserDto user = db.users().insertUser("obiwan"); - propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId())); + propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid())); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); @@ -160,7 +160,7 @@ public class ComponentActionTest { ComponentDto project = insertOrganizationAndProject(); ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz")); UserDto user = db.users().insertUser("obiwan"); - propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId())); + propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid())); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); @@ -607,7 +607,7 @@ public class ComponentActionTest { componentDbTester.insertSnapshot(analysis); when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType()); UserDto user = db.users().insertUser("obiwan"); - propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId())); + propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid())); addQualityProfiles(project, createQProfile("qp1", "Sonar Way Java", "java"), createQProfile("qp2", "Sonar Way Xoo", "xoo")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 7dc5a9130d0..732cea32753 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -147,8 +147,8 @@ public class DeactivateActionTest { deactivate(user.getLogin()); - assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty(); - assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentUuid(project.uuid()).build(), dbSession)).isEmpty(); + assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserUuid(user.getUuid()).build(), dbSession)).isEmpty(); + assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserUuid(user.getUuid()).setComponentUuid(project.uuid()).build(), dbSession)).isEmpty(); } @Test -- 2.39.5