Skip to content

Commit c5595d0

Browse files
SK-2302 updated variable names
1 parent a5514d3 commit c5595d0

File tree

6 files changed

+47
-37
lines changed

6 files changed

+47
-37
lines changed

common/src/main/java/com/skyflow/errors/ErrorMessage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public enum ErrorMessage {
6464
EmptyTable("%s0 Validation error. 'table' can't be empty. Specify a table."),
6565
ValuesKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."),
6666
EmptyRecords("%s0 Validation error. 'records' can't be empty. Specify records."),
67-
EmptyKeyInRecords("%s0 Validation error. Invalid key in records. Specify a valid key."),
67+
EmptyKeyInRecords("%s0 Validation error. Invalid key in data in records. Specify a valid key."),
6868
EmptyValueInRecords("%s0 Validation error. Invalid value in records. Specify a valid value."),
69-
RecordsKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."),
69+
RecordsKeyError("%s0 Validation error. 'records' key is missing from the payload. Specify a 'records' key."),
7070
EmptyValues("%s0 Validation error. 'values' can't be empty. Specify values."),
7171
EmptyKeyInValues("%s0 Validation error. Invalid key in values. Specify a valid key."),
7272
EmptyValueInValues("%s0 Validation error. Invalid value in values. Specify a valid value."),
@@ -171,6 +171,7 @@ public enum ErrorMessage {
171171
NullRedactionInTokenGroup("%s0 Validation error. Redaction in TokenGroupRedactions is null or empty. Specify a valid redaction."),
172172

173173
NullTokenGroupNameInTokenGroup("%s0 Validation error. TokenGroupName in TokenGroupRedactions is null or empty. Specify a valid tokenGroupName."),
174+
InvalidRecord("%s0 Validation error. InsertRecord object in the list is invalid. Specify a valid InsertRecord object."),
174175
;
175176
;
176177
private final String message;

common/src/main/java/com/skyflow/logs/ErrorLogs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum ErrorLogs {
5353
EMPTY_VALUES("Invalid %s1 request. Values can not be empty."),
5454
RECORDS_IS_REQUIRED("Invalid %s1 request. Records are required."),
5555
EMPTY_RECORDS("Invalid %s1 request. Records can not be empty."),
56+
INVALID_RECORD("Invalid %s1 request. Invalid record. Specify a valid record."),
5657
RECORD_SIZE_EXCEED("Maximum number of records exceeded. The limit is 10000."),
5758
TOKENS_SIZE_EXCEED("Maximum number of tokens exceeded. The limit is 10000."),
5859
EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."),

v3/src/main/java/com/skyflow/VaultClient.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,26 @@ protected void updateExecutorInHTTP() {
134134
}
135135

136136
protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) {
137-
ArrayList<InsertRecord> values = request.getRecords();
137+
ArrayList<InsertRecord> records = request.getRecords();
138138
List<InsertRecordData> insertRecordDataList = new ArrayList<>();
139-
for (InsertRecord value : values) {
139+
for (InsertRecord record : records) {
140140
InsertRecordData.Builder data = InsertRecordData.builder();
141-
data.data(value.getData());
142-
if (value.getTable() != null && !value.getTable().isEmpty()){
143-
data.tableName(value.getTable());
141+
data.data(record.getData());
142+
if (record.getTable() != null && !record.getTable().isEmpty()){
143+
data.tableName(record.getTable());
144144
}
145-
if (value.getUpsert() != null && !value.getUpsert().isEmpty()){
146-
if (value.getUpsertType() != null) {
145+
if (record.getUpsert() != null && !record.getUpsert().isEmpty()){
146+
if (record.getUpsertType() != null) {
147147
EnumUpdateType updateType = null;
148-
if (value.getUpsertType() == UpdateType.REPLACE) {
148+
if (record.getUpsertType() == UpdateType.REPLACE) {
149149
updateType = EnumUpdateType.REPLACE;
150-
} else if (value.getUpsertType() == UpdateType.UPDATE) {
150+
} else if (record.getUpsertType() == UpdateType.UPDATE) {
151151
updateType = EnumUpdateType.UPDATE;
152152
}
153-
Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).updateType(updateType).build();
153+
Upsert upsert = Upsert.builder().uniqueColumns(record.getUpsert()).updateType(updateType).build();
154154
data.upsert(upsert);
155155
} else {
156-
Upsert upsert = Upsert.builder().uniqueColumns(value.getUpsert()).build();
156+
Upsert upsert = Upsert.builder().uniqueColumns(record.getUpsert()).build();
157157
data.upsert(upsert);
158158
}
159159
}

v3/src/main/java/com/skyflow/utils/validations/Validations.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.skyflow.utils.validations;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import com.skyflow.config.Credentials;
47
import com.skyflow.config.VaultConfig;
58
import com.skyflow.enums.InterfaceName;
@@ -14,36 +17,41 @@
1417
import com.skyflow.vault.data.InsertRequest;
1518
import com.skyflow.vault.data.TokenGroupRedactions;
1619

17-
import java.util.ArrayList;
18-
import java.util.HashMap;
19-
import java.util.List;
20-
2120
public class Validations extends BaseValidations {
2221
private Validations() {
2322
super();
2423
}
2524

2625
public static void validateInsertRequest(InsertRequest insertRequest) throws SkyflowException {
2726
String table = insertRequest.getTable();
28-
ArrayList<InsertRecord> values = insertRequest.getRecords();
29-
if (values == null) {
27+
ArrayList<InsertRecord> records = insertRequest.getRecords();
28+
if (records == null) {
3029
LogUtil.printErrorLog(Utils.parameterizedString(
3130
ErrorLogs.RECORDS_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName()
3231
));
3332
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordsKeyError.getMessage());
34-
} else if (values.isEmpty()) {
33+
} else if (records.isEmpty()) {
3534
LogUtil.printErrorLog(Utils.parameterizedString(
3635
ErrorLogs.EMPTY_RECORDS.getLog(), InterfaceName.INSERT.getName()
3736
));
3837
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRecords.getMessage());
39-
} else if (values.size() > 10000) {
38+
} else if (records.size() > 10000) {
4039
LogUtil.printErrorLog(ErrorLogs.RECORD_SIZE_EXCEED.getLog());
4140
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordSizeExceedError.getMessage());
4241
}
42+
for (InsertRecord record : records) {
43+
if(record == null){
44+
LogUtil.printErrorLog(Utils.parameterizedString(
45+
ErrorLogs.INVALID_RECORD.getLog(), InterfaceName.INSERT.getName()
46+
));
47+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRecord.getMessage());
48+
}
49+
}
50+
4351
// table check if specified for both
4452
if (insertRequest.getTable() != null && !table.trim().isEmpty()){ // if table name specified at both place
45-
for (InsertRecord valuesMap : values) {
46-
if (valuesMap.getTable() != null && !valuesMap.getTable().trim().isEmpty()){
53+
for (InsertRecord record : records) {
54+
if (record.getTable() != null && !record.getTable().trim().isEmpty()){
4755
LogUtil.printErrorLog(Utils.parameterizedString(
4856
ErrorLogs.TABLE_SPECIFIED_AT_BOTH_PLACE.getLog(), InterfaceName.INSERT.getName()
4957
));
@@ -53,8 +61,8 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
5361
}
5462
// table check if not specified for both or if missing in any object
5563
if (insertRequest.getTable() == null || table.trim().isEmpty()){ // if table name specified at both place
56-
for (InsertRecord valuesMap : values) {
57-
if (valuesMap.getTable() == null || valuesMap.getTable().trim().isEmpty()){
64+
for (InsertRecord record : records) {
65+
if (record.getTable() == null || record.getTable().trim().isEmpty()){
5866
LogUtil.printErrorLog(Utils.parameterizedString(
5967
ErrorLogs.TABLE_NOT_SPECIFIED_AT_BOTH_PLACE.getLog(), InterfaceName.INSERT.getName()
6068
));
@@ -64,14 +72,14 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
6472
}
6573
// upsert check 1
6674
if (insertRequest.getTable() != null && !table.trim().isEmpty()){ // if table name specified at both place
67-
for (InsertRecord valuesMap : values) {
68-
if (valuesMap.getUpsert() != null && valuesMap.getUpsert().isEmpty()) {
75+
for (InsertRecord record : records) {
76+
if (record.getUpsert() != null && record.getUpsert().isEmpty()) {
6977
LogUtil.printErrorLog(Utils.parameterizedString(
7078
ErrorLogs.EMPTY_UPSERT_VALUES.getLog(), InterfaceName.INSERT.getName()
7179
));
7280
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage());
7381
}
74-
if (valuesMap.getUpsert() != null && !valuesMap.getUpsert().isEmpty()){
82+
if (record.getUpsert() != null && !record.getUpsert().isEmpty()){
7583
LogUtil.printErrorLog(Utils.parameterizedString(
7684
ErrorLogs.UPSERT_TABLE_REQUEST_AT_RECORD_LEVEL.getLog(), InterfaceName.INSERT.getName()
7785
));
@@ -96,17 +104,17 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
96104
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyUpsertValues.getMessage());
97105
}
98106

99-
for (InsertRecord valuesMap : values) {
100-
if (valuesMap != null ) {
101-
if (valuesMap.getData() != null){
102-
for (String key : valuesMap.getData().keySet()) {
107+
for (InsertRecord record : records) {
108+
if (record != null ) {
109+
if (record.getData() != null){
110+
for (String key : record.getData().keySet()) {
103111
if (key == null || key.trim().isEmpty()) {
104112
LogUtil.printErrorLog(Utils.parameterizedString(
105113
ErrorLogs.EMPTY_OR_NULL_KEY_IN_VALUES.getLog(), InterfaceName.INSERT.getName()
106114
));
107-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInValues.getMessage());
115+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInRecords.getMessage());
108116
} else {
109-
Object value = valuesMap.getData().get(key);
117+
Object value = record.getData().get(key);
110118
if (value == null || value.toString().trim().isEmpty()) {
111119
LogUtil.printErrorLog(Utils.parameterizedString(
112120
ErrorLogs.EMPTY_OR_NULL_VALUE_IN_VALUES.getLog(),

v3/test/java/com/skyflow/utils/UtilsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public void testValidateInsertRequestNullValues() {
715715
try {
716716
Validations.validateInsertRequest(request);
717717
} catch (SkyflowException e) {
718-
assertEquals(ErrorMessage.ValuesKeyError.getMessage(), e.getMessage()); // Replace with the actual error message
718+
assertEquals(ErrorMessage.RecordsKeyError.getMessage(), e.getMessage()); // Replace with the actual error message
719719
}
720720
}
721721

v3/test/java/com/skyflow/vault/data/InsertTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void testNoValuesInInsertRequestValidations() {
158158
} catch (SkyflowException e) {
159159
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
160160
Assert.assertEquals(
161-
Utils.parameterizedString(ErrorMessage.ValuesKeyError.getMessage(), Constants.SDK_PREFIX),
161+
Utils.parameterizedString(ErrorMessage.RecordsKeyError.getMessage(), Constants.SDK_PREFIX),
162162
e.getMessage()
163163
);
164164
}
@@ -191,7 +191,7 @@ public void testEmptyKeyInValuesInInsertRequestValidations() {
191191
} catch (SkyflowException e) {
192192
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
193193
Assert.assertEquals(
194-
Utils.parameterizedString(ErrorMessage.EmptyKeyInValues.getMessage(), Constants.SDK_PREFIX),
194+
Utils.parameterizedString(ErrorMessage.EmptyKeyInRecords.getMessage(), Constants.SDK_PREFIX),
195195
e.getMessage()
196196
);
197197
}

0 commit comments

Comments
 (0)