From 54d9671a777cc55d0c4bea7e2edae9362cea70a9 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Tue, 20 Feb 2024 17:50:17 +0530 Subject: [PATCH] fix: PR changes --- .../bulkimport/BulkImportStorage.java | 2 +- .../bulkimport/BulkImportUser.java | 6 +- .../utils/JsonValidatorUtils.java | 116 ------------------ 3 files changed, 4 insertions(+), 120 deletions(-) delete mode 100644 src/main/java/io/supertokens/pluginInterface/utils/JsonValidatorUtils.java diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java index ee0a7e43..9874712d 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -40,7 +40,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, - @Nullable String bulkImportUserId) throws StorageQueryException; + @Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException; /** * Delete users by id from the bulk_import_users table diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index 7861b0bb..7b65ee54 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -53,11 +53,11 @@ public String toString() { public static class TotpDevice { public String secretKey; - public Number period; - public Number skew; + public Integer period; + public Integer skew; public String deviceName; - public TotpDevice(String secretKey, Number period, Number skew, String deviceName) { + public TotpDevice(String secretKey, Integer period, Integer skew, String deviceName) { this.secretKey = secretKey; this.period = period; this.skew = skew; diff --git a/src/main/java/io/supertokens/pluginInterface/utils/JsonValidatorUtils.java b/src/main/java/io/supertokens/pluginInterface/utils/JsonValidatorUtils.java deleted file mode 100644 index df33d151..00000000 --- a/src/main/java/io/supertokens/pluginInterface/utils/JsonValidatorUtils.java +++ /dev/null @@ -1,116 +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.utils; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -public class JsonValidatorUtils { - @SuppressWarnings("unchecked") - public static T parseAndValidateField(JsonObject jsonObject, String key, ValueType expectedType, - boolean isRequired, Class targetType, List errors, String errorSuffix) { - if (jsonObject.has(key)) { - if (validateJsonFieldType(jsonObject, key, expectedType)) { - T value; - switch (expectedType) { - case STRING: - value = (T) jsonObject.get(key).getAsString(); - break; - case NUMBER: - value = (T) jsonObject.get(key).getAsNumber(); - break; - case BOOLEAN: - Boolean boolValue = jsonObject.get(key).getAsBoolean(); - value = (T) boolValue; - break; - case OBJECT: - value = (T) jsonObject.get(key).getAsJsonObject(); - break; - case ARRAY_OF_OBJECT, ARRAY_OF_STRING: - value = (T) jsonObject.get(key).getAsJsonArray(); - break; - default: - value = null; - break; - } - if (value != null) { - return targetType.cast(value); - } else { - errors.add(key + " should be of type " + getTypeForErrorMessage(expectedType) + errorSuffix); - } - } else { - errors.add(key + " should be of type " + getTypeForErrorMessage(expectedType) + errorSuffix); - } - } else if (isRequired) { - errors.add(key + " is required" + errorSuffix); - } - return null; - } - - public enum ValueType { - STRING, - NUMBER, - BOOLEAN, - OBJECT, - ARRAY_OF_STRING, - ARRAY_OF_OBJECT - } - - private static String getTypeForErrorMessage(ValueType type) { - return switch (type) { - case STRING -> "string"; - case NUMBER -> "number"; - case BOOLEAN -> "boolean"; - case OBJECT -> "object"; - case ARRAY_OF_STRING -> "array of string"; - case ARRAY_OF_OBJECT -> "array of object"; - }; - } - - public static Boolean validateJsonFieldType(JsonObject jsonObject, String key, ValueType expectedType) { - if (jsonObject.has(key)) { - return switch (expectedType) { - case STRING -> jsonObject.get(key).isJsonPrimitive() && jsonObject.getAsJsonPrimitive(key).isString() - && !jsonObject.get(key).getAsString().isEmpty(); - case NUMBER -> jsonObject.get(key).isJsonPrimitive() && jsonObject.getAsJsonPrimitive(key).isNumber(); - case BOOLEAN -> jsonObject.get(key).isJsonPrimitive() && jsonObject.getAsJsonPrimitive(key).isBoolean(); - case OBJECT -> jsonObject.get(key).isJsonObject(); - case ARRAY_OF_OBJECT, ARRAY_OF_STRING -> jsonObject.get(key).isJsonArray() - && validateArrayElements(jsonObject.getAsJsonArray(key), expectedType); - default -> false; - }; - } - return false; - } - - public static Boolean validateArrayElements(JsonArray array, ValueType expectedType) { - List elements = new ArrayList<>(); - array.forEach(elements::add); - - return switch (expectedType) { - case ARRAY_OF_OBJECT -> elements.stream().allMatch(JsonElement::isJsonObject); - case ARRAY_OF_STRING -> - elements.stream().allMatch(el -> el.isJsonPrimitive() && el.getAsJsonPrimitive().isString() - && !el.getAsString().isEmpty()); - default -> false; - }; - } -}