11package com .skyflow .utils .validations ;
22
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
36import com .skyflow .config .Credentials ;
47import com .skyflow .config .VaultConfig ;
58import com .skyflow .enums .InterfaceName ;
1417import com .skyflow .vault .data .InsertRequest ;
1518import com .skyflow .vault .data .TokenGroupRedactions ;
1619
17- import java .util .ArrayList ;
18- import java .util .HashMap ;
19- import java .util .List ;
20-
2120public 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 (),
0 commit comments