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; } }