From f24b8904511023c9021541d6cfc318cf27c6f200 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 28 Feb 2024 10:17:53 +0530 Subject: [PATCH 1/4] fix: PR changes --- .../bulkimport/BulkImportStorage.java | 2 +- .../bulkimport/BulkImportUser.java | 101 +++++++++--------- .../bulkimport/BulkImportUserInfo.java | 47 -------- 3 files changed, 49 insertions(+), 101 deletions(-) delete mode 100644 src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUserInfo.java diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java index 9874712d..27d75d04 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -39,7 +39,7 @@ void addBulkImportUsers(AppIdentifier appIdentifier, List users) /** * Get users from the bulk_import_users table */ - List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status, + List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status, @Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException; /** diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index f3bb6d8d..0f097384 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -21,6 +21,8 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; +import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BulkImportUserStatus; + public class BulkImportUser { public String id; public String externalUserId; @@ -29,7 +31,13 @@ public class BulkImportUser { public List totpDevices; public List loginMethods; - public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List userRoles, List totpDevices, List loginMethods) { + // Following fields come from the DB Record. + public BulkImportUserStatus status; + public Long createdAt; + public Long updatedAt; + + public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List userRoles, + List totpDevices, List loginMethods) { this.id = id; this.externalUserId = externalUserId; this.userMetadata = userMetadata; @@ -38,17 +46,31 @@ public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, this.loginMethods = loginMethods; } - public String toString() { - Gson gson = new Gson(); - JsonObject json = new JsonObject(); + public static BulkImportUser fromDBJson(String id, String rawData, BulkImportUserStatus status, long createdAt, + long updatedAt) { + BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class); + user.id = id; + user.status = status; + user.createdAt = createdAt; + user.updatedAt = updatedAt; + return user; + } - json.addProperty("externalUserId", externalUserId); - json.add("userMetadata", userMetadata); - json.add("roles", gson.toJsonTree(userRoles)); - json.add("totp", gson.toJsonTree(totpDevices)); - json.add("loginMethods", gson.toJsonTree(loginMethods)); + public String toString() { + return new Gson().toJson(this); + } - return json.toString(); + // This method returns a JSON object string representation, excluding 'status', 'createdAt', and 'updatedAt'. Useful for test comparisons. + public String toRawData() { + JsonObject jsonObject = new Gson().fromJson(this.toString(), JsonObject.class); + jsonObject.remove("status"); + jsonObject.remove("createdAt"); + jsonObject.remove("updatedAt"); + return jsonObject.toString(); + } + + public JsonObject toJsonObject() { + return new Gson().fromJson(this.toString(), JsonObject.class); } public static class TotpDevice { @@ -71,54 +93,27 @@ public static class LoginMethod { public boolean isPrimary; public long timeJoinedInMSSinceEpoch; public String recipeId; - - public EmailPasswordLoginMethod emailPasswordLoginMethod; - public ThirdPartyLoginMethod thirdPartyLoginMethod; - public PasswordlessLoginMethod passwordlessLoginMethod; - - public LoginMethod(String tenantId, String recipeId, boolean isVerified, boolean isPrimary, long timeJoinedInMSSinceEpoch, EmailPasswordLoginMethod emailPasswordLoginMethod, ThirdPartyLoginMethod thirdPartyLoginMethod, PasswordlessLoginMethod passwordlessLoginMethod) { + public String email; + public String passwordHash; + public String hashingAlgorithm; + public String thirdPartyId; + public String thirdPartyUserId; + public String phoneNumber; + + public LoginMethod(String tenantId, String recipeId, boolean isVerified, boolean isPrimary, + long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm, + String thirdPartyId, String thirdPartyUserId, String phoneNumber) { this.tenantId = tenantId; this.recipeId = recipeId; this.isVerified = isVerified; this.isPrimary = isPrimary; this.timeJoinedInMSSinceEpoch = timeJoinedInMSSinceEpoch; - this.emailPasswordLoginMethod = emailPasswordLoginMethod; - this.thirdPartyLoginMethod = thirdPartyLoginMethod; - this.passwordlessLoginMethod = passwordlessLoginMethod; - } - - public static class EmailPasswordLoginMethod { - public String email; - public String passwordHash; - public String hashingAlgorithm; - - public EmailPasswordLoginMethod(String email, String passwordHash, String hashingAlgorithm) { - this.email = email; - this.passwordHash = passwordHash; - this.hashingAlgorithm = hashingAlgorithm; - } - } - - public static class ThirdPartyLoginMethod { - public String email; - public String thirdPartyId; - public String thirdPartyUserId; - - public ThirdPartyLoginMethod(String email, String thirdPartyId, String thirdPartyUserId) { - this.email = email; - this.thirdPartyId = thirdPartyId; - this.thirdPartyUserId = thirdPartyUserId; - } - } - - public static class PasswordlessLoginMethod { - public String email; - public String phoneNumber; - - public PasswordlessLoginMethod(String email, String phoneNumber) { - this.email = email; - this.phoneNumber = phoneNumber; - } + this.email = email; + this.passwordHash = passwordHash; + this.hashingAlgorithm = hashingAlgorithm; + this.thirdPartyId = thirdPartyId; + this.thirdPartyUserId = thirdPartyUserId; + this.phoneNumber = phoneNumber; } } } diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUserInfo.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUserInfo.java deleted file mode 100644 index 5d91d0f8..00000000 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUserInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.supertokens.pluginInterface.bulkimport; - -import com.google.gson.JsonObject; - -import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BulkImportUserStatus; - -public class BulkImportUserInfo { - public String id; - public String rawData; - public BulkImportUserStatus status; - public Long createdAt; - public Long updatedAt; - - public BulkImportUserInfo(String id, String rawData, BulkImportUserStatus status, Long createdAt, Long updatedAt) { - this.id = id; - this.rawData = rawData; - this.status = status; - this.createdAt = createdAt; - this.updatedAt = updatedAt; - } - - public JsonObject toJsonObject() { - JsonObject result = new JsonObject(); - result.addProperty("id", id); - result.addProperty("rawData", rawData); - result.addProperty("status", status.toString()); - result.addProperty("createdAt", createdAt); - result.addProperty("updatedAt", updatedAt); - return result; - } -} From d81681b59ea145908d86e68355cf6219f411ba88 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 28 Feb 2024 10:53:27 +0530 Subject: [PATCH 2/4] fix: PR changes --- .../pluginInterface/bulkimport/BulkImportUser.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index 0f097384..35ce5a05 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -46,14 +46,8 @@ public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, this.loginMethods = loginMethods; } - public static BulkImportUser fromDBJson(String id, String rawData, BulkImportUserStatus status, long createdAt, - long updatedAt) { - BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class); - user.id = id; - user.status = status; - user.createdAt = createdAt; - user.updatedAt = updatedAt; - return user; + public static BulkImportUser fromJson(JsonObject jsonObject) { + return new Gson().fromJson(jsonObject, BulkImportUser.class); } public String toString() { From 29345b199da99ffe0a5cb0cb77a9ffd0ff8b461a Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 28 Feb 2024 12:34:31 +0530 Subject: [PATCH 3/4] fix: PR changes --- .../bulkimport/BulkImportStorage.java | 4 +-- .../bulkimport/BulkImportUser.java | 26 ++++++++++++------- .../sqlStorage/BulkImportSQLStorage.java | 2 +- .../AppIdentifierWithStorage.java | 6 ++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java index 27d75d04..9c9efd34 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -39,7 +39,7 @@ void addBulkImportUsers(AppIdentifier appIdentifier, List users) /** * Get users from the bulk_import_users table */ - List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status, + List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BULK_IMPORT_USER_STATUS status, @Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException; /** @@ -49,7 +49,7 @@ List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull In // ArrayList bulkImportUserIds) // throws StorageQueryException; - public enum BulkImportUserStatus { + public enum BULK_IMPORT_USER_STATUS { NEW, PROCESSING, FAILED } } diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index 35ce5a05..ce98f24d 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -21,7 +21,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; -import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BulkImportUserStatus; +import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BULK_IMPORT_USER_STATUS; public class BulkImportUser { public String id; @@ -32,7 +32,7 @@ public class BulkImportUser { public List loginMethods; // Following fields come from the DB Record. - public BulkImportUserStatus status; + public BULK_IMPORT_USER_STATUS status; public Long createdAt; public Long updatedAt; @@ -50,21 +50,27 @@ public static BulkImportUser fromJson(JsonObject jsonObject) { return new Gson().fromJson(jsonObject, BulkImportUser.class); } - public String toString() { - return new Gson().toJson(this); - } - - // This method returns a JSON object string representation, excluding 'status', 'createdAt', and 'updatedAt'. Useful for test comparisons. - public String toRawData() { - JsonObject jsonObject = new Gson().fromJson(this.toString(), JsonObject.class); + // This method returns a JSON object string representation, excluding 'status', 'createdAt', and 'updatedAt'. + // It is used for inserting the user into the database or during testing. + public String toRawDataForDbStorage() { + JsonObject jsonObject = new Gson().fromJson(new Gson().toJson(this), JsonObject.class); jsonObject.remove("status"); jsonObject.remove("createdAt"); jsonObject.remove("updatedAt"); return jsonObject.toString(); } + + public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, long createdAt, long updatedAt) { + BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class); + user.id = id; + user.status = status; + user.createdAt = createdAt; + user.updatedAt = updatedAt; + return user; + } public JsonObject toJsonObject() { - return new Gson().fromJson(this.toString(), JsonObject.class); + return new Gson().fromJson(new Gson().toJson(this), JsonObject.class); } public static class TotpDevice { diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java index eb297619..be446472 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java @@ -30,5 +30,5 @@ public interface BulkImportSQLStorage extends BulkImportStorage, SQLStorage { * Update the status of the users in the bulk_import_users table */ void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier, - TransactionConnection con, @Nonnull String[] bulkImportUserIds, @Nonnull BulkImportUserStatus status) throws StorageQueryException; + TransactionConnection con, @Nonnull String[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status) throws StorageQueryException; } diff --git a/src/main/java/io/supertokens/pluginInterface/multitenancy/AppIdentifierWithStorage.java b/src/main/java/io/supertokens/pluginInterface/multitenancy/AppIdentifierWithStorage.java index 81f61394..ed5db6e3 100644 --- a/src/main/java/io/supertokens/pluginInterface/multitenancy/AppIdentifierWithStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/multitenancy/AppIdentifierWithStorage.java @@ -20,7 +20,7 @@ import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.authRecipe.AuthRecipeStorage; -import io.supertokens.pluginInterface.bulkimport.BulkImportStorage; +import io.supertokens.pluginInterface.bulkimport.sqlStorage.BulkImportSQLStorage; import io.supertokens.pluginInterface.dashboard.sqlStorage.DashboardSQLStorage; import io.supertokens.pluginInterface.emailpassword.sqlStorage.EmailPasswordSQLStorage; import io.supertokens.pluginInterface.emailverification.sqlStorage.EmailVerificationSQLStorage; @@ -161,11 +161,11 @@ public ActiveUsersSQLStorage getActiveUsersStorage() { return (ActiveUsersSQLStorage) this.storage; } - public BulkImportStorage getBulkImportStorage() { + public BulkImportSQLStorage getBulkImportStorage() { if (this.storage.getType() != STORAGE_TYPE.SQL) { // we only support SQL for now throw new UnsupportedOperationException(""); } - return (BulkImportStorage) this.storage; + return (BulkImportSQLStorage) this.storage; } } From 0e862f7a13efbdc6d0e5f3e31563d63406c483b2 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 28 Feb 2024 13:06:50 +0530 Subject: [PATCH 4/4] fix: PR changes --- .../supertokens/pluginInterface/bulkimport/BulkImportUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index ce98f24d..d0d99a1b 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -46,7 +46,7 @@ public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, this.loginMethods = loginMethods; } - public static BulkImportUser fromJson(JsonObject jsonObject) { + public static BulkImportUser fromTesting_fromJson(JsonObject jsonObject) { return new Gson().fromJson(jsonObject, BulkImportUser.class); }