Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/bulk-import-api-1' into fea…
Browse files Browse the repository at this point in the history
…t/bulk-import-api-2
  • Loading branch information
anku255 committed Feb 28, 2024
2 parents 0c2f411 + 0e862f7 commit 5def46a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ void addBulkImportUsers(AppIdentifier appIdentifier, List<BulkImportUser> users)
/**
* Get users from the bulk_import_users table
*/
List<BulkImportUserInfo> getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status,
List<BulkImportUser> getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BULK_IMPORT_USER_STATUS status,
@Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException;

/**
* Delete users by id from the bulk_import_users table
*/
List<String> deleteBulkImportUsers(AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws StorageQueryException;

public enum BulkImportUserStatus {
public enum BULK_IMPORT_USER_STATUS {
NEW, PROCESSING, FAILED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BULK_IMPORT_USER_STATUS;

public class BulkImportUser {
public String id;
public String externalUserId;
Expand All @@ -29,7 +31,13 @@ public class BulkImportUser {
public List<TotpDevice> totpDevices;
public List<LoginMethod> loginMethods;

public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List<String> userRoles, List<TotpDevice> totpDevices, List<LoginMethod> loginMethods) {
// Following fields come from the DB Record.
public BULK_IMPORT_USER_STATUS status;
public Long createdAt;
public Long updatedAt;

public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List<String> userRoles,
List<TotpDevice> totpDevices, List<LoginMethod> loginMethods) {
this.id = id;
this.externalUserId = externalUserId;
this.userMetadata = userMetadata;
Expand All @@ -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 fromTesting_fromJson(JsonObject jsonObject) {
return new Gson().fromJson(jsonObject, BulkImportUser.class);
}

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));
// 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();
}

return json.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(new Gson().toJson(this), JsonObject.class);
}

public static class TotpDevice {
Expand All @@ -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;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 5def46a

Please sign in to comment.