From ae75c8d37894beffd6d5dcc742b41217291b6f03 Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Fri, 19 Sep 2025 16:33:23 +0530 Subject: [PATCH 1/4] SK-2302 add changes for bulk async changes --- .../java/com/skyflow/errors/ErrorMessage.java | 7 +- .../main/java/com/skyflow/logs/ErrorLogs.java | 2 + v3/src/main/java/com/skyflow/VaultClient.java | 10 +- .../java/com/skyflow/enums/UpdateType.java | 2 - .../java/com/skyflow/utils/Constants.java | 1 - .../utils/validations/Validations.java | 39 ++--- .../vault/data/DetokenizeResponse.java | 5 +- .../com/skyflow/vault/data/InsertRecord.java | 8 +- .../java/com/skyflow/vault/data/Success.java | 1 + .../java/com/skyflow/VaultClientTests.java | 123 +++++++++++++ .../java/com/skyflow/utils/UtilsTests.java | 165 +++++++++++++++++- .../com/skyflow/vault/data/InsertTests.java | 108 +++++++++++- 12 files changed, 425 insertions(+), 46 deletions(-) diff --git a/common/src/main/java/com/skyflow/errors/ErrorMessage.java b/common/src/main/java/com/skyflow/errors/ErrorMessage.java index 52d38bfe..68021dd2 100644 --- a/common/src/main/java/com/skyflow/errors/ErrorMessage.java +++ b/common/src/main/java/com/skyflow/errors/ErrorMessage.java @@ -11,9 +11,8 @@ public enum ErrorMessage { ConnectionIdNotInConfigList("%s0 Validation error. ConnectionId is missing from the config. Specify the connectionIds from configs."), EmptyCredentials("%s0 Validation error. Invalid credentials. Credentials must not be empty."), TableSpecifiedInRequestAndRecordObject("%s0 Validation error. Table name cannot be specified at both the request and record levels. Please specify the table name in only one place."), - UpsertAtRecordLevel("%s0 Validation error. Upsert specify "), UpsertTableRequestAtRecordLevel("%s0 Validation error. Table name should be present at each record level when upsert is present at record level."), - UpsertTableRequestAtRequestLevel("%S0 Validation error. Upsert should be present at each record level when table name is present at record level."), + UpsertTableRequestAtRequestLevel("%s0 Validation error. Upsert should be present at each record level when table name is present at record level."), TableNotSpecifiedInRequestAndRecordObject("%s0 Validation error. Table name is missing. Table name should be specified at one place either at the request level or record level. Please specify the table name at one place."), // Vault config InvalidVaultId("%s0 Initialization failed. Invalid vault ID. Specify a valid vault ID."), @@ -64,6 +63,10 @@ public enum ErrorMessage { TableKeyError("%s0 Validation error. 'table' key is missing from the payload. Specify a 'table' key."), EmptyTable("%s0 Validation error. 'table' can't be empty. Specify a table."), ValuesKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."), + EmptyRecords("%s0 Validation error. 'values' can't be empty. Specify values."), + EmptyKeyInRecords("%s0 Validation error. Invalid key in values. Specify a valid key."), + EmptyValueInRecords("%s0 Validation error. Invalid value in values. Specify a valid value."), + RecordsKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."), EmptyValues("%s0 Validation error. 'values' can't be empty. Specify values."), EmptyKeyInValues("%s0 Validation error. Invalid key in values. Specify a valid key."), EmptyValueInValues("%s0 Validation error. Invalid value in values. Specify a valid value."), diff --git a/common/src/main/java/com/skyflow/logs/ErrorLogs.java b/common/src/main/java/com/skyflow/logs/ErrorLogs.java index dc242850..a481f9f6 100644 --- a/common/src/main/java/com/skyflow/logs/ErrorLogs.java +++ b/common/src/main/java/com/skyflow/logs/ErrorLogs.java @@ -51,6 +51,8 @@ public enum ErrorLogs { EMPTY_TABLE_NAME("Invalid %s1 request. Table name can not be empty."), VALUES_IS_REQUIRED("Invalid %s1 request. Values are required."), EMPTY_VALUES("Invalid %s1 request. Values can not be empty."), + RECORDS_IS_REQUIRED("Invalid %s1 request. Records are required."), + EMPTY_RECORDS("Invalid %s1 request. Records can not be empty."), RECORD_SIZE_EXCEED("Maximum number of records exceeded. The limit is 10000."), TOKENS_SIZE_EXCEED("Maximum number of tokens exceeded. The limit is 10000."), EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."), diff --git a/v3/src/main/java/com/skyflow/VaultClient.java b/v3/src/main/java/com/skyflow/VaultClient.java index 54730b02..6bbb9c4d 100644 --- a/v3/src/main/java/com/skyflow/VaultClient.java +++ b/v3/src/main/java/com/skyflow/VaultClient.java @@ -1,5 +1,8 @@ package com.skyflow; +import java.util.ArrayList; +import java.util.List; + import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; import com.skyflow.enums.UpdateType; @@ -27,9 +30,6 @@ import okhttp3.OkHttpClient; import okhttp3.Request; -import java.util.ArrayList; -import java.util.List; - public class VaultClient { private final VaultConfig vaultConfig; @@ -145,9 +145,9 @@ protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRe if (value.getUpsert() != null && !value.getUpsert().isEmpty()){ if (value.getUpsertType() != null) { EnumUpdateType updateType = null; - if (request.getUpsertType() == UpdateType.REPLACE) { + if (value.getUpsertType() == UpdateType.REPLACE) { updateType = EnumUpdateType.REPLACE; - } else if (request.getUpsertType() == UpdateType.UPDATE) { + } else if (value.getUpsertType() == UpdateType.UPDATE) { updateType = EnumUpdateType.UPDATE; } Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).updateType(updateType).build(); diff --git a/v3/src/main/java/com/skyflow/enums/UpdateType.java b/v3/src/main/java/com/skyflow/enums/UpdateType.java index 7fcb6f65..45641c13 100644 --- a/v3/src/main/java/com/skyflow/enums/UpdateType.java +++ b/v3/src/main/java/com/skyflow/enums/UpdateType.java @@ -1,7 +1,5 @@ package com.skyflow.enums; -import com.fasterxml.jackson.annotation.JsonValue; - public enum UpdateType { UPDATE("UPDATE"), diff --git a/v3/src/main/java/com/skyflow/utils/Constants.java b/v3/src/main/java/com/skyflow/utils/Constants.java index cfc29792..a21662c8 100644 --- a/v3/src/main/java/com/skyflow/utils/Constants.java +++ b/v3/src/main/java/com/skyflow/utils/Constants.java @@ -9,7 +9,6 @@ public final class Constants extends BaseConstants { public static final Integer MAX_INSERT_BATCH_SIZE = 1000; public static final Integer INSERT_CONCURRENCY_LIMIT = 10; public static final Integer MAX_INSERT_CONCURRENCY_LIMIT = 10; - public static final Integer DETOKENIZE_BATCH_SIZE = 50; public static final Integer DETOKENIZE_CONCURRENCY_LIMIT = 10; public static final Integer MAX_DETOKENIZE_BATCH_SIZE = 1000; diff --git a/v3/src/main/java/com/skyflow/utils/validations/Validations.java b/v3/src/main/java/com/skyflow/utils/validations/Validations.java index 00c2d4ff..f0a07fdc 100644 --- a/v3/src/main/java/com/skyflow/utils/validations/Validations.java +++ b/v3/src/main/java/com/skyflow/utils/validations/Validations.java @@ -28,33 +28,22 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky ArrayList values = insertRequest.getRecords(); if (values == null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.VALUES_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName() + ErrorLogs.RECORDS_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName() )); - throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.ValuesKeyError.getMessage()); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordsKeyError.getMessage()); } else if (values.isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.EMPTY_VALUES.getLog(), InterfaceName.INSERT.getName() + ErrorLogs.EMPTY_RECORDS.getLog(), InterfaceName.INSERT.getName() )); - throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValues.getMessage()); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRecords.getMessage()); } else if (values.size() > 10000) { LogUtil.printErrorLog(ErrorLogs.RECORD_SIZE_EXCEED.getLog()); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordSizeExceedError.getMessage()); } -// if (table == null) { -// LogUtil.printErrorLog(Utils.parameterizedString( -// ErrorLogs.TABLE_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName() -// )); -// throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TableKeyError.getMessage()); -// } else if (table.trim().isEmpty()) { -// LogUtil.printErrorLog(Utils.parameterizedString( -// ErrorLogs.EMPTY_TABLE_NAME.getLog(), InterfaceName.INSERT.getName() -// )); -// throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyTable.getMessage()); -// } // table check if specified for both if (insertRequest.getTable() != null && !table.trim().isEmpty()){ // if table name specified at both place for (InsertRecord valuesMap : values) { - if (valuesMap.getTable() != null || !valuesMap.getTable().trim().isEmpty()){ + if (valuesMap.getTable() != null && !valuesMap.getTable().trim().isEmpty()){ LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.TABLE_SPECIFIED_AT_BOTH_PLACE.getLog(), InterfaceName.INSERT.getName() )); @@ -76,6 +65,12 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky // upsert check 1 if (insertRequest.getTable() != null && !table.trim().isEmpty()){ // if table name specified at both place for (InsertRecord valuesMap : values) { + if (valuesMap.getUpsert() != null && valuesMap.getUpsert().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_UPSERT_VALUES.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage()); + } if (valuesMap.getUpsert() != null && !valuesMap.getUpsert().isEmpty()){ LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.UPSERT_TABLE_REQUEST_AT_RECORD_LEVEL.getLog(), InterfaceName.INSERT.getName() @@ -94,12 +89,12 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky } } -// else if (upsert != null && upsert.isEmpty()) { -// LogUtil.printErrorLog(Utils.parameterizedString( -// ErrorLogs.EMPTY_UPSERT_VALUES.getLog(), InterfaceName.INSERT.getName() -// )); -// throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage()); -// } + if (insertRequest.getUpsert() != null && insertRequest.getUpsert().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_UPSERT_VALUES.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage()); + } for (InsertRecord valuesMap : values) { if (valuesMap != null ) { diff --git a/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java b/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java index b00817db..7a356245 100644 --- a/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java +++ b/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java @@ -9,11 +9,12 @@ import java.util.stream.Collectors; public class DetokenizeResponse { - @Expose(serialize = true) - private List success; @Expose(serialize = true) private DetokenizeSummary summary; + @Expose(serialize = true) + private List success; + @Expose(serialize = true) private List errors; diff --git a/v3/src/main/java/com/skyflow/vault/data/InsertRecord.java b/v3/src/main/java/com/skyflow/vault/data/InsertRecord.java index c6da54d2..4373d920 100644 --- a/v3/src/main/java/com/skyflow/vault/data/InsertRecord.java +++ b/v3/src/main/java/com/skyflow/vault/data/InsertRecord.java @@ -1,5 +1,7 @@ package com.skyflow.vault.data; +import com.skyflow.enums.UpdateType; + import java.util.List; import java.util.Map; @@ -23,7 +25,7 @@ public List getUpsert() { return this.builder.upsert; } - public String getUpsertType() { + public UpdateType getUpsertType() { return this.builder.upsertType; } @@ -32,7 +34,7 @@ public static final class InsertRecordBuilder { private String table; private Map data; private List upsert; - private String upsertType; + private UpdateType upsertType; public InsertRecordBuilder table(String table) { this.table = table; @@ -49,7 +51,7 @@ public InsertRecordBuilder upsert(List upsert) { return this; } - public InsertRecordBuilder upsertType(String upsertType) { + public InsertRecordBuilder upsertType(UpdateType upsertType) { this.upsertType = upsertType; return this; } diff --git a/v3/src/main/java/com/skyflow/vault/data/Success.java b/v3/src/main/java/com/skyflow/vault/data/Success.java index 94a3d62d..ac8d5f08 100644 --- a/v3/src/main/java/com/skyflow/vault/data/Success.java +++ b/v3/src/main/java/com/skyflow/vault/data/Success.java @@ -26,6 +26,7 @@ public Success(int index, String skyflow_id, Map> tokens, Ma this.skyflow_id = skyflow_id; this.tokens = tokens; this.data = data; + this.table = table; } public String getSkyflowId() { diff --git a/v3/test/java/com/skyflow/VaultClientTests.java b/v3/test/java/com/skyflow/VaultClientTests.java index c99d8a08..a6686fdc 100644 --- a/v3/test/java/com/skyflow/VaultClientTests.java +++ b/v3/test/java/com/skyflow/VaultClientTests.java @@ -3,16 +3,22 @@ import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; import com.skyflow.enums.Env; +import com.skyflow.enums.UpdateType; import com.skyflow.errors.ErrorCode; import com.skyflow.errors.SkyflowException; import com.skyflow.generated.rest.resources.recordservice.RecordserviceClient; +import com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest; +import com.skyflow.generated.rest.types.InsertRecordData; import com.skyflow.utils.Constants; import com.skyflow.utils.SdkVersion; +import com.skyflow.vault.data.InsertRecord; import io.github.cdimascio.dotenv.Dotenv; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.util.*; + public class VaultClientTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static VaultClient vaultClient; @@ -151,6 +157,123 @@ public void testPrioritiseCredentialsWithCommonCredentials() throws Exception { Assert.assertEquals(credentials, getPrivateField(vaultClient, "finalCredentials")); } + @Test + public void testEmptyRecords() { + com.skyflow.vault.data.InsertRequest request = + com.skyflow.vault.data.InsertRequest.builder().records(new ArrayList<>()).build(); + InsertRequest result = vaultClient.getBulkInsertRequestBody(request, vaultConfig); + Assert.assertTrue(result.getRecords().get().isEmpty()); + } + + @Test + public void testTableAtRequestLevel() { + Map data = new HashMap<>(); + data.put("key", "value"); + InsertRecord record = InsertRecord.builder().data(data).build(); + ArrayList records = new ArrayList<>(); + records.add(record); + + com.skyflow.vault.data.InsertRequest request = + com.skyflow.vault.data.InsertRequest.builder() + .table("table1") + .records(records) + .build(); + + InsertRequest result = vaultClient.getBulkInsertRequestBody(request, vaultConfig); + Assert.assertEquals("table1", result.getTableName().get()); + List recordData = result.getRecords().get(); + Assert.assertEquals("value", recordData.get(0).getData().get().get("key")); + } + + @Test + public void testTableAtRecordLevel() { + Map data = new HashMap<>(); + data.put("key", "value"); + InsertRecord record = InsertRecord.builder().data(data).table("table2").build(); + + ArrayList records = new ArrayList<>(); + records.add(record); + + com.skyflow.vault.data.InsertRequest request = + com.skyflow.vault.data.InsertRequest.builder() + .records(records) + .build(); + + InsertRequest result = vaultClient.getBulkInsertRequestBody(request, vaultConfig); + Assert.assertEquals("table2", result.getRecords().get().get(0).getTableName().get()); + } + + @Test + public void testUpsertAtRequestLevel() { + Map data = new HashMap<>(); + data.put("key", "value"); + InsertRecord record = InsertRecord.builder().data(data).build(); + ArrayList records = new ArrayList<>(); + records.add(record); + + + List upsertColumns = Arrays.asList("col1"); + com.skyflow.vault.data.InsertRequest request = + com.skyflow.vault.data.InsertRequest.builder() + .records(records) + .upsert(upsertColumns) + .upsertType(UpdateType.REPLACE) + .build(); + + InsertRequest result = vaultClient.getBulkInsertRequestBody(request, vaultConfig); + Assert.assertNotNull(result.getUpsert()); + Assert.assertEquals("col1", result.getUpsert().get().getUniqueColumns().get().get(0)); + Assert.assertEquals("REPLACE", result.getUpsert().get().getUpdateType().get().name()); + } + + @Test + public void testUpsertAtRecordLevel() { + Map data = new HashMap<>(); + data.put("key", "value"); + List upsertColumns = Arrays.asList("col2"); + InsertRecord record = InsertRecord.builder().data(data).upsert(upsertColumns).upsertType(UpdateType.UPDATE).build(); + System.out.println("record upsert: " + record.getUpsertType()); + ArrayList records = new ArrayList<>(); + records.add(record); + + + com.skyflow.vault.data.InsertRequest request = + com.skyflow.vault.data.InsertRequest.builder() + .records(records) + .build(); + + InsertRequest result = vaultClient.getBulkInsertRequestBody(request, vaultConfig); + Assert.assertNotNull(result.getRecords().get().get(0).getUpsert()); + System.out.println("result upsert: " + result.getRecords().get().get(0).getUpsert()); + Assert.assertEquals("col2", result.getRecords().get().get(0).getUpsert().get().getUniqueColumns().get().get(0)); + Assert.assertEquals("UPDATE", result.getRecords().get().get(0).getUpsert().get().getUpdateType().get().name()); + } + + @Test + public void testMixedTableAndUpsertLevels() { + Map data = new HashMap<>(); + data.put("key", "value"); + List upsertColumns = Arrays.asList("col3"); + InsertRecord record = InsertRecord.builder().data(data).table("table3").upsert(upsertColumns).build(); + ArrayList records = new ArrayList<>(); + records.add(record); + + + com.skyflow.vault.data.InsertRequest request = + com.skyflow.vault.data.InsertRequest.builder() + .table("table4") + .upsert(Arrays.asList("col4")) + .records(records) + .build(); + + InsertRequest result = vaultClient.getBulkInsertRequestBody(request, vaultConfig); + Assert.assertEquals("table4", result.getTableName().get()); + Assert.assertEquals("table3", result.getRecords().get().get(0).getTableName().get()); + Assert.assertEquals("col3", result.getRecords().get().get(0).getUpsert().get().getUniqueColumns().get().get(0)); + Assert.assertEquals("col4", result.getUpsert().get().getUniqueColumns().get().get(0)); + } + + // Helper methods for reflection field access private Object getPrivateField(Object obj, String fieldName) throws Exception { java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName); diff --git a/v3/test/java/com/skyflow/utils/UtilsTests.java b/v3/test/java/com/skyflow/utils/UtilsTests.java index e7373115..c2b05451 100644 --- a/v3/test/java/com/skyflow/utils/UtilsTests.java +++ b/v3/test/java/com/skyflow/utils/UtilsTests.java @@ -288,7 +288,7 @@ public void testHandleBatchExceptionWithNonZeroBatchNumber() { } @Test - public void testHandleBatchExceptionWithNullResponseBody() { + public void testHandleBatchExceptionWithNullResponseBody1() { List batch = Arrays.asList(InsertRecordData.builder().build(), InsertRecordData.builder().build()); List> batches = Collections.singletonList(batch); @@ -680,7 +680,7 @@ public void testValidateInsertRequestNullTable() { try { Validations.validateInsertRequest(request); } catch (SkyflowException e) { - assertEquals(ErrorMessage.TableKeyError.getMessage(), e.getMessage()); // Replace with the actual error message + assertEquals(ErrorMessage.TableNotSpecifiedInRequestAndRecordObject.getMessage(), e.getMessage()); // Replace with the actual error message } } @@ -701,7 +701,7 @@ public void testValidateInsertRequestEmptyTable() { try { Validations.validateInsertRequest(request); } catch (SkyflowException e) { - assertEquals(ErrorMessage.EmptyTable.getMessage(), e.getMessage()); // Replace with the actual error message + assertEquals(ErrorMessage.TableNotSpecifiedInRequestAndRecordObject.getMessage(), e.getMessage()); // Replace with the actual error message } } @@ -793,6 +793,74 @@ public void testFormatDetokenizeResponse_NullResponse() { Assert.assertNull(result); } + @Test + public void testCreateDetokenizeBatchesWithTokenGroupRedactions() { + List tokens = Arrays.asList("token1", "token2", "token3"); + List groupRedactions = Arrays.asList( + com.skyflow.generated.rest.types.TokenGroupRedactions.builder().tokenGroupName("group1").redaction("MASK").build(), + com.skyflow.generated.rest.types.TokenGroupRedactions.builder().tokenGroupName("group2").redaction("PLAIN_TEXT").build(), + com.skyflow.generated.rest.types.TokenGroupRedactions.builder().tokenGroupName("group3").redaction("REDACTED").build() + ); + + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request = com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.builder() + .vaultId("vaultId") + .tokens(tokens) + .tokenGroupRedactions(groupRedactions) + .build(); + + List batches = Utils.createDetokenizeBatches(request, 2); + + Assert.assertEquals(2, batches.size()); + Assert.assertEquals(Arrays.asList("token1", "token2"), batches.get(0).getTokens().get()); + Assert.assertEquals(Arrays.asList("token3"), batches.get(1).getTokens().get()); + Assert.assertTrue(batches.get(0).getTokenGroupRedactions().isPresent()); + } + + @Test + public void testCreateDetokenizeBatchesWithEmptyTokenGroupRedactions() { + List tokens = Arrays.asList("token1", "token2"); + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request = com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.builder() + .vaultId("vaultId") + .tokens(tokens) + .tokenGroupRedactions(new ArrayList<>()) + .build(); + + List batches = Utils.createDetokenizeBatches(request, 1); + + Assert.assertEquals(2, batches.size()); + Assert.assertTrue(batches.get(0).getTokenGroupRedactions().isEmpty()); + } + + @Test + public void testCreateDetokenizeBatchesWithNullTokenGroupRedactions() { + List tokens = Arrays.asList("token1", "token2"); + List groupRedactions = new ArrayList<>(); + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request = com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.builder() + .vaultId("vaultId") + .tokens(tokens) + .tokenGroupRedactions(groupRedactions) + .build(); + + List batches = Utils.createDetokenizeBatches(request, 1); + + Assert.assertEquals(2, batches.size()); + Assert.assertFalse(batches.get(0).getTokenGroupRedactions().isPresent()); + } + + @Test + public void testCreateDetokenizeBatchesWithBatchSizeGreaterThanTokens() { + List tokens = Arrays.asList("token1"); + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request = com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.builder() + .vaultId("vaultId") + .tokens(tokens) + .build(); + + List batches = Utils.createDetokenizeBatches(request, 5); + + Assert.assertEquals(1, batches.size()); + Assert.assertEquals(Arrays.asList("token1"), batches.get(0).getTokens().get()); + } + public static List createDetokenizeBatches(com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request, int batchSize) { List detokenizeRequests = new ArrayList<>(); List tokens = request.getTokens().get(); @@ -828,4 +896,95 @@ private DetokenizeResponseObject createResponseObject(String token, String value );return responseObject; } + @Test + public void testCreateErrorRecordWithHttpCodeKey() { + Map recordMap = new HashMap<>(); + recordMap.put("message", "Test message"); + recordMap.put("httpCode", 401); + + ErrorRecord error = Utils.createErrorRecord(recordMap, 2); + + Assert.assertEquals(2, error.getIndex()); + Assert.assertEquals("Test message", error.getError()); + Assert.assertEquals(401, error.getCode()); + } + + @Test + public void testCreateErrorRecordWithStatusCodeKey() { + Map recordMap = new HashMap<>(); + recordMap.put("statusCode", 402); + + ErrorRecord error = Utils.createErrorRecord(recordMap, 3); + + Assert.assertEquals(3, error.getIndex()); + Assert.assertEquals("Unknown error", error.getError()); + Assert.assertEquals(402, error.getCode()); + } + + @Test + public void testCreateErrorRecordWithUnknownErrorMessage() { + Map recordMap = new HashMap<>(); + recordMap.put("http_code", 403); + + ErrorRecord error = Utils.createErrorRecord(recordMap, 4); + + Assert.assertEquals(4, error.getIndex()); + Assert.assertEquals("Unknown error", error.getError()); + Assert.assertEquals(403, error.getCode()); + } + @Test + public void testHandleBatchExceptionWithNullResponseBody() { + List batch = Arrays.asList(InsertRecordData.builder().build()); + ApiClientApiException apiException = new ApiClientApiException("Error", 500, null); + Exception exception = new Exception("Test", apiException); + + List errors = Utils.handleBatchException(exception, batch, 0); + Assert.assertEquals(1, errors.size()); + Assert.assertEquals("Test", errors.get(0).getError()); + Assert.assertEquals(500, errors.get(0).getCode()); + } + + @Test + public void testHandleBatchExceptionWithNonListRecords() { + List batch = Arrays.asList(InsertRecordData.builder().build()); + Map responseBody = new HashMap<>(); + responseBody.put("records", "not_a_list"); + ApiClientApiException apiException = new ApiClientApiException("Error", 500, responseBody); + Exception exception = new Exception("Test", apiException); + + List errors = Utils.handleBatchException(exception, batch, 0); + Assert.assertEquals(1, errors.size()); + } + + @Test + public void testHandleBatchExceptionWithErrorNotMap() { + List batch = Arrays.asList(InsertRecordData.builder().build()); + Map responseBody = new HashMap<>(); + responseBody.put("error", "not_a_map"); + ApiClientApiException apiException = new ApiClientApiException("Error", 500, responseBody); + Exception exception = new Exception("Test", apiException); + + List errors = Utils.handleBatchException(exception, batch, 0); + Assert.assertEquals(1, errors.size()); + } + + @Test + public void testHandleBatchExceptionWithApiClientApiExceptionCause() { + List batch = Arrays.asList(InsertRecordData.builder().build()); + Map responseBody = new HashMap<>(); + Map error = new HashMap<>(); + error.put("message", "Test error"); + error.put("http_code", 400); + responseBody.put("error", error); + responseBody.put("http_code", 400); + + com.skyflow.generated.rest.core.ApiClientApiException apiException = new com.skyflow.generated.rest.core.ApiClientApiException("Error", 400, responseBody); + Exception exception = new Exception("Outer exception", apiException); + + List errors = Utils.handleBatchException(exception, batch, 0); + Assert.assertEquals(1, errors.size()); + Assert.assertEquals("Test error", errors.get(0).getError()); + Assert.assertEquals(400, errors.get(0).getCode()); + } + } \ No newline at end of file diff --git a/v3/test/java/com/skyflow/vault/data/InsertTests.java b/v3/test/java/com/skyflow/vault/data/InsertTests.java index be59a4cd..262119d5 100644 --- a/v3/test/java/com/skyflow/vault/data/InsertTests.java +++ b/v3/test/java/com/skyflow/vault/data/InsertTests.java @@ -115,14 +115,17 @@ public void testValidInputInInsertRequestValidationsWithTokenModeDisable() { @Test public void testNoTableInInsertRequestValidations() { - InsertRequest request = InsertRequest.builder().build(); + ArrayList records = new ArrayList<>(); + InsertRecord record = InsertRecord.builder().data(valueMap).build(); + records.add(record); + InsertRequest request = InsertRequest.builder().records(records).table("").build(); try { Validations.validateInsertRequest(request); Assert.fail(EXCEPTION_NOT_THROWN); } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.TableKeyError.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.TableNotSpecifiedInRequestAndRecordObject.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); } @@ -130,14 +133,17 @@ public void testNoTableInInsertRequestValidations() { @Test public void testEmptyTableInInsertRequestValidations() { - InsertRequest request = InsertRequest.builder().table("").build(); + ArrayList records = new ArrayList<>(); + InsertRecord record = InsertRecord.builder().data(valueMap).build(); + records.add(record); + InsertRequest request = InsertRequest.builder().records(records).table("").build(); try { Validations.validateInsertRequest(request); Assert.fail(EXCEPTION_NOT_THROWN); } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.EmptyTable.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.TableNotSpecifiedInRequestAndRecordObject.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); } @@ -236,7 +242,7 @@ public void testInsertResponse() { List successList = new ArrayList<>(); successList.add(success); InsertResponse response = new InsertResponse(successList, null); - String responseString = "{\"success\":[{\"index\":0,\"skyflow_id\":\"id\"}]}"; + String responseString = "{\"success\":[{\"index\":0,\"skyflow_id\":\"id\",\"table\":\"table\"}]}"; Assert.assertEquals(1, response.getSuccess().size()); Assert.assertNull(response.getErrors()); Assert.assertEquals(responseString, response.toString()); @@ -260,7 +266,7 @@ public void testInsertErrorResponse() { errorList.add(error); InsertResponse response1 = new InsertResponse(successList, errorList); - String responseString = "{\"success\":[{\"index\":0,\"skyflow_id\":\"id\",\"data\":{\"test_column_1\":\"test_value_1\"}}],\"errors\":[{\"index\":1,\"error\":\"Bad Request\",\"code\":400}]}"; + String responseString = "{\"success\":[{\"index\":0,\"skyflow_id\":\"id\",\"data\":{\"test_column_1\":\"test_value_1\"},\"table\":\"table\"}],\"errors\":[{\"index\":1,\"error\":\"Bad Request\",\"code\":400}]}"; Assert.assertEquals(1, response1.getSuccess().size()); Assert.assertEquals(1, response1.getErrors().size()); Assert.assertEquals(responseString, response1.toString()); @@ -268,5 +274,95 @@ public void testInsertErrorResponse() { Assert.fail(INVALID_EXCEPTION_THROWN); } } +// Java + + @Test + public void testTableSpecifiedAtBothRequestAndRecordLevel() { + InsertRecord record = InsertRecord.builder().data(valueMap).table("record_table").build(); + values.add(record); + InsertRequest request = InsertRequest.builder().table(table).records(values).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.TableSpecifiedInRequestAndRecordObject.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } +} + + @Test + public void testUpsertSpecifiedAtBothRequestAndRecordLevel() { + InsertRecord record = InsertRecord.builder().data(valueMap).upsert(upsert).build(); + values.add(record); + InsertRequest request = InsertRequest.builder().table(table).records(values).upsert(upsert).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.UpsertTableRequestAtRecordLevel.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } +} + + @Test + public void testUpsertAtRecordLevelWithTableAtRequestLevel() { + InsertRecord record = InsertRecord.builder().data(valueMap).upsert(upsert).build(); + values.add(record); + InsertRequest request = InsertRequest.builder().table(table).records(values).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.UpsertTableRequestAtRecordLevel.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } +} + + @Test + public void testUpsertAtRequestLevelWithNoTable() { + InsertRecord record = InsertRecord.builder().table("table").data(valueMap).build(); + values.add(record); + InsertRequest request = InsertRequest.builder().records(values).upsert(upsert).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.UpsertTableRequestAtRequestLevel.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } +} + + @Test + public void testUpsertAtRequestLevelWithEmptyTable() { + InsertRecord record = InsertRecord.builder().table("table").data(valueMap).build(); + values.add(record); + List upsert = new ArrayList<>(); + upsert.add("upsert_column"); + + InsertRequest request = InsertRequest.builder().table("").records(values).upsert(upsert).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.UpsertTableRequestAtRequestLevel.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + } From e5616228c3d050b6243fcc32f121131461d9b0c4 Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Fri, 19 Sep 2025 16:39:53 +0530 Subject: [PATCH 2/4] SK-2302 updated the messages --- v3/test/java/com/skyflow/utils/UtilsTests.java | 2 +- v3/test/java/com/skyflow/vault/data/InsertTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/v3/test/java/com/skyflow/utils/UtilsTests.java b/v3/test/java/com/skyflow/utils/UtilsTests.java index c2b05451..a8f94f6f 100644 --- a/v3/test/java/com/skyflow/utils/UtilsTests.java +++ b/v3/test/java/com/skyflow/utils/UtilsTests.java @@ -729,7 +729,7 @@ public void testValidateInsertRequestEmptyValues() { try { Validations.validateInsertRequest(request); } catch (SkyflowException e) { - assertEquals(ErrorMessage.EmptyValues.getMessage(), e.getMessage()); // Replace with the actual error message + assertEquals(ErrorMessage.EmptyRecords.getMessage(), e.getMessage()); // Replace with the actual error message } } diff --git a/v3/test/java/com/skyflow/vault/data/InsertTests.java b/v3/test/java/com/skyflow/vault/data/InsertTests.java index 262119d5..e8d1ddf4 100644 --- a/v3/test/java/com/skyflow/vault/data/InsertTests.java +++ b/v3/test/java/com/skyflow/vault/data/InsertTests.java @@ -173,7 +173,7 @@ public void testEmptyValuesInInsertRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.EmptyValues.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.EmptyRecords.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); } From a5514d3277c1a66fb9b068400309bb510c28b481 Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Fri, 19 Sep 2025 16:44:17 +0530 Subject: [PATCH 3/4] SK-2302 updated the messages --- common/src/main/java/com/skyflow/errors/ErrorMessage.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/skyflow/errors/ErrorMessage.java b/common/src/main/java/com/skyflow/errors/ErrorMessage.java index 68021dd2..60a72489 100644 --- a/common/src/main/java/com/skyflow/errors/ErrorMessage.java +++ b/common/src/main/java/com/skyflow/errors/ErrorMessage.java @@ -63,9 +63,9 @@ public enum ErrorMessage { TableKeyError("%s0 Validation error. 'table' key is missing from the payload. Specify a 'table' key."), EmptyTable("%s0 Validation error. 'table' can't be empty. Specify a table."), ValuesKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."), - EmptyRecords("%s0 Validation error. 'values' can't be empty. Specify values."), - EmptyKeyInRecords("%s0 Validation error. Invalid key in values. Specify a valid key."), - EmptyValueInRecords("%s0 Validation error. Invalid value in values. Specify a valid value."), + EmptyRecords("%s0 Validation error. 'records' can't be empty. Specify records."), + EmptyKeyInRecords("%s0 Validation error. Invalid key in records. Specify a valid key."), + EmptyValueInRecords("%s0 Validation error. Invalid value in records. Specify a valid value."), RecordsKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."), EmptyValues("%s0 Validation error. 'values' can't be empty. Specify values."), EmptyKeyInValues("%s0 Validation error. Invalid key in values. Specify a valid key."), From c5595d0dfdb0d4d091bd8741e75b20d1372f42e6 Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Fri, 19 Sep 2025 18:03:53 +0530 Subject: [PATCH 4/4] SK-2302 updated variable names --- .../java/com/skyflow/errors/ErrorMessage.java | 5 +- .../main/java/com/skyflow/logs/ErrorLogs.java | 1 + v3/src/main/java/com/skyflow/VaultClient.java | 22 ++++---- .../utils/validations/Validations.java | 50 +++++++++++-------- .../java/com/skyflow/utils/UtilsTests.java | 2 +- .../com/skyflow/vault/data/InsertTests.java | 4 +- 6 files changed, 47 insertions(+), 37 deletions(-) diff --git a/common/src/main/java/com/skyflow/errors/ErrorMessage.java b/common/src/main/java/com/skyflow/errors/ErrorMessage.java index 60a72489..e1c0eeba 100644 --- a/common/src/main/java/com/skyflow/errors/ErrorMessage.java +++ b/common/src/main/java/com/skyflow/errors/ErrorMessage.java @@ -64,9 +64,9 @@ public enum ErrorMessage { EmptyTable("%s0 Validation error. 'table' can't be empty. Specify a table."), ValuesKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."), EmptyRecords("%s0 Validation error. 'records' can't be empty. Specify records."), - EmptyKeyInRecords("%s0 Validation error. Invalid key in records. Specify a valid key."), + EmptyKeyInRecords("%s0 Validation error. Invalid key in data in records. Specify a valid key."), EmptyValueInRecords("%s0 Validation error. Invalid value in records. Specify a valid value."), - RecordsKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."), + RecordsKeyError("%s0 Validation error. 'records' key is missing from the payload. Specify a 'records' key."), EmptyValues("%s0 Validation error. 'values' can't be empty. Specify values."), EmptyKeyInValues("%s0 Validation error. Invalid key in values. Specify a valid key."), EmptyValueInValues("%s0 Validation error. Invalid value in values. Specify a valid value."), @@ -171,6 +171,7 @@ public enum ErrorMessage { NullRedactionInTokenGroup("%s0 Validation error. Redaction in TokenGroupRedactions is null or empty. Specify a valid redaction."), NullTokenGroupNameInTokenGroup("%s0 Validation error. TokenGroupName in TokenGroupRedactions is null or empty. Specify a valid tokenGroupName."), + InvalidRecord("%s0 Validation error. InsertRecord object in the list is invalid. Specify a valid InsertRecord object."), ; ; private final String message; diff --git a/common/src/main/java/com/skyflow/logs/ErrorLogs.java b/common/src/main/java/com/skyflow/logs/ErrorLogs.java index a481f9f6..64d1c5e6 100644 --- a/common/src/main/java/com/skyflow/logs/ErrorLogs.java +++ b/common/src/main/java/com/skyflow/logs/ErrorLogs.java @@ -53,6 +53,7 @@ public enum ErrorLogs { EMPTY_VALUES("Invalid %s1 request. Values can not be empty."), RECORDS_IS_REQUIRED("Invalid %s1 request. Records are required."), EMPTY_RECORDS("Invalid %s1 request. Records can not be empty."), + INVALID_RECORD("Invalid %s1 request. Invalid record. Specify a valid record."), RECORD_SIZE_EXCEED("Maximum number of records exceeded. The limit is 10000."), TOKENS_SIZE_EXCEED("Maximum number of tokens exceeded. The limit is 10000."), EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."), diff --git a/v3/src/main/java/com/skyflow/VaultClient.java b/v3/src/main/java/com/skyflow/VaultClient.java index 6bbb9c4d..559a7d3a 100644 --- a/v3/src/main/java/com/skyflow/VaultClient.java +++ b/v3/src/main/java/com/skyflow/VaultClient.java @@ -134,26 +134,26 @@ protected void updateExecutorInHTTP() { } protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) { - ArrayList values = request.getRecords(); + ArrayList records = request.getRecords(); List insertRecordDataList = new ArrayList<>(); - for (InsertRecord value : values) { + for (InsertRecord record : records) { InsertRecordData.Builder data = InsertRecordData.builder(); - data.data(value.getData()); - if (value.getTable() != null && !value.getTable().isEmpty()){ - data.tableName(value.getTable()); + data.data(record.getData()); + if (record.getTable() != null && !record.getTable().isEmpty()){ + data.tableName(record.getTable()); } - if (value.getUpsert() != null && !value.getUpsert().isEmpty()){ - if (value.getUpsertType() != null) { + if (record.getUpsert() != null && !record.getUpsert().isEmpty()){ + if (record.getUpsertType() != null) { EnumUpdateType updateType = null; - if (value.getUpsertType() == UpdateType.REPLACE) { + if (record.getUpsertType() == UpdateType.REPLACE) { updateType = EnumUpdateType.REPLACE; - } else if (value.getUpsertType() == UpdateType.UPDATE) { + } else if (record.getUpsertType() == UpdateType.UPDATE) { updateType = EnumUpdateType.UPDATE; } - Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).updateType(updateType).build(); + Upsert upsert = Upsert.builder().uniqueColumns(record.getUpsert()).updateType(updateType).build(); data.upsert(upsert); } else { - Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).build(); + Upsert upsert = Upsert.builder().uniqueColumns(record.getUpsert()).build(); data.upsert(upsert); } } diff --git a/v3/src/main/java/com/skyflow/utils/validations/Validations.java b/v3/src/main/java/com/skyflow/utils/validations/Validations.java index f0a07fdc..deb612f0 100644 --- a/v3/src/main/java/com/skyflow/utils/validations/Validations.java +++ b/v3/src/main/java/com/skyflow/utils/validations/Validations.java @@ -1,5 +1,8 @@ package com.skyflow.utils.validations; +import java.util.ArrayList; +import java.util.List; + import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; import com.skyflow.enums.InterfaceName; @@ -14,10 +17,6 @@ import com.skyflow.vault.data.InsertRequest; import com.skyflow.vault.data.TokenGroupRedactions; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - public class Validations extends BaseValidations { private Validations() { super(); @@ -25,25 +24,34 @@ private Validations() { public static void validateInsertRequest(InsertRequest insertRequest) throws SkyflowException { String table = insertRequest.getTable(); - ArrayList values = insertRequest.getRecords(); - if (values == null) { + ArrayList records = insertRequest.getRecords(); + if (records == null) { LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.RECORDS_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordsKeyError.getMessage()); - } else if (values.isEmpty()) { + } else if (records.isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.EMPTY_RECORDS.getLog(), InterfaceName.INSERT.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRecords.getMessage()); - } else if (values.size() > 10000) { + } else if (records.size() > 10000) { LogUtil.printErrorLog(ErrorLogs.RECORD_SIZE_EXCEED.getLog()); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordSizeExceedError.getMessage()); } + for (InsertRecord record : records) { + if(record == null){ + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.INVALID_RECORD.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRecord.getMessage()); + } + } + // table check if specified for both if (insertRequest.getTable() != null && !table.trim().isEmpty()){ // if table name specified at both place - for (InsertRecord valuesMap : values) { - if (valuesMap.getTable() != null && !valuesMap.getTable().trim().isEmpty()){ + for (InsertRecord record : records) { + if (record.getTable() != null && !record.getTable().trim().isEmpty()){ LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.TABLE_SPECIFIED_AT_BOTH_PLACE.getLog(), InterfaceName.INSERT.getName() )); @@ -53,8 +61,8 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky } // table check if not specified for both or if missing in any object if (insertRequest.getTable() == null || table.trim().isEmpty()){ // if table name specified at both place - for (InsertRecord valuesMap : values) { - if (valuesMap.getTable() == null || valuesMap.getTable().trim().isEmpty()){ + for (InsertRecord record : records) { + if (record.getTable() == null || record.getTable().trim().isEmpty()){ LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.TABLE_NOT_SPECIFIED_AT_BOTH_PLACE.getLog(), InterfaceName.INSERT.getName() )); @@ -64,14 +72,14 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky } // upsert check 1 if (insertRequest.getTable() != null && !table.trim().isEmpty()){ // if table name specified at both place - for (InsertRecord valuesMap : values) { - if (valuesMap.getUpsert() != null && valuesMap.getUpsert().isEmpty()) { + for (InsertRecord record : records) { + if (record.getUpsert() != null && record.getUpsert().isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.EMPTY_UPSERT_VALUES.getLog(), InterfaceName.INSERT.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage()); } - if (valuesMap.getUpsert() != null && !valuesMap.getUpsert().isEmpty()){ + if (record.getUpsert() != null && !record.getUpsert().isEmpty()){ LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.UPSERT_TABLE_REQUEST_AT_RECORD_LEVEL.getLog(), InterfaceName.INSERT.getName() )); @@ -96,17 +104,17 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage()); } - for (InsertRecord valuesMap : values) { - if (valuesMap != null ) { - if (valuesMap.getData() != null){ - for (String key : valuesMap.getData().keySet()) { + for (InsertRecord record : records) { + if (record != null ) { + if (record.getData() != null){ + for (String key : record.getData().keySet()) { if (key == null || key.trim().isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.EMPTY_OR_NULL_KEY_IN_VALUES.getLog(), InterfaceName.INSERT.getName() )); - throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInValues.getMessage()); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInRecords.getMessage()); } else { - Object value = valuesMap.getData().get(key); + Object value = record.getData().get(key); if (value == null || value.toString().trim().isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.EMPTY_OR_NULL_VALUE_IN_VALUES.getLog(), diff --git a/v3/test/java/com/skyflow/utils/UtilsTests.java b/v3/test/java/com/skyflow/utils/UtilsTests.java index a8f94f6f..1d32318e 100644 --- a/v3/test/java/com/skyflow/utils/UtilsTests.java +++ b/v3/test/java/com/skyflow/utils/UtilsTests.java @@ -715,7 +715,7 @@ public void testValidateInsertRequestNullValues() { try { Validations.validateInsertRequest(request); } catch (SkyflowException e) { - assertEquals(ErrorMessage.ValuesKeyError.getMessage(), e.getMessage()); // Replace with the actual error message + assertEquals(ErrorMessage.RecordsKeyError.getMessage(), e.getMessage()); // Replace with the actual error message } } diff --git a/v3/test/java/com/skyflow/vault/data/InsertTests.java b/v3/test/java/com/skyflow/vault/data/InsertTests.java index e8d1ddf4..5894d899 100644 --- a/v3/test/java/com/skyflow/vault/data/InsertTests.java +++ b/v3/test/java/com/skyflow/vault/data/InsertTests.java @@ -158,7 +158,7 @@ public void testNoValuesInInsertRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.ValuesKeyError.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.RecordsKeyError.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); } @@ -191,7 +191,7 @@ public void testEmptyKeyInValuesInInsertRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.EmptyKeyInValues.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.EmptyKeyInRecords.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); }