1717import com .skyflow .generated .rest .resources .records .requests .RecordServiceBatchOperationBody ;
1818import com .skyflow .generated .rest .resources .records .requests .RecordServiceInsertRecordBody ;
1919import com .skyflow .generated .rest .resources .records .requests .RecordServiceUpdateRecordBody ;
20+ import com .skyflow .generated .rest .resources .records .requests .UploadFileV2Request ;
2021import com .skyflow .generated .rest .resources .strings .StringsClient ;
2122import com .skyflow .generated .rest .resources .strings .requests .DeidentifyStringRequest ;
2223import com .skyflow .generated .rest .resources .strings .requests .ReidentifyStringRequest ;
3233import com .skyflow .utils .Utils ;
3334import com .skyflow .utils .logger .LogUtil ;
3435import com .skyflow .utils .validations .Validations ;
36+ import com .skyflow .vault .data .FileUploadRequest ;
3537import com .skyflow .vault .data .InsertRequest ;
3638import com .skyflow .vault .data .UpdateRequest ;
3739import com .skyflow .vault .detect .*;
4446import io .github .cdimascio .dotenv .Dotenv ;
4547import io .github .cdimascio .dotenv .DotenvException ;
4648
49+ import java .io .File ;
50+ import java .io .IOException ;
51+ import java .nio .file .Files ;
52+ import java .nio .file .Paths ;
4753import java .util .*;
4854import java .util .stream .Collectors ;
4955
@@ -209,6 +215,22 @@ protected V1TokenizePayload getTokenizePayload(TokenizeRequest request) {
209215 return payloadBuilder .build ();
210216 }
211217
218+ protected File getFileForFileUpload (FileUploadRequest fileUploadRequest ) throws IOException {
219+ if (fileUploadRequest .getFilePath () != null ) {
220+ return new File (fileUploadRequest .getFilePath ());
221+ }
222+ else if (fileUploadRequest .getBase64 () != null ) {
223+ byte [] decodedBytes = Base64 .getDecoder ().decode (fileUploadRequest .getBase64 ());
224+ File file = new File (fileUploadRequest .getFileName ());
225+ Files .write (file .toPath (), decodedBytes );
226+ return file ;
227+ }
228+ else if (fileUploadRequest .getFileObject () != null ) {
229+ return fileUploadRequest .getFileObject ();
230+ }
231+ return null ;
232+ }
233+
212234 protected void setBearerToken () throws SkyflowException {
213235 prioritiseCredentials ();
214236 Validations .validateCredentials (this .finalCredentials );
@@ -512,7 +534,6 @@ protected DeidentifyPdfRequest getDeidentifyPdfRequest(DeidentifyFileRequest req
512534 Optional <List <EntityType >> entityUniqueCounter = Optional .empty ();
513535 Optional <List <String >> allowRegex = Optional .ofNullable (request .getAllowRegexList ());
514536 Optional <List <String >> restrictRegex = Optional .ofNullable (request .getRestrictRegexList ());
515- Optional <Transformations > transformations = Optional .ofNullable (getTransformations (request .getTransformations ()));
516537
517538 if (tokenFormat != null ) {
518539 if (tokenFormat .getEntityOnly () != null && !tokenFormat .getEntityOnly ().isEmpty ()) {
@@ -540,13 +561,12 @@ protected DeidentifyPdfRequest getDeidentifyPdfRequest(DeidentifyFileRequest req
540561 return DeidentifyPdfRequest .builder ()
541562 .vaultId (vaultId )
542563 .file (file )
543- .density (request .getPixelDensity () != null ? request .getPixelDensity ().intValue () : null )
544- .maxResolution (request .getMaxResolution () != null ? request .getMaxResolution ().intValue () : null )
564+ .density (request .getPixelDensity () != null ? request .getPixelDensity ().doubleValue () : null )
565+ .maxResolution (request .getMaxResolution () != null ? request .getMaxResolution ().doubleValue () : null )
545566 .entityTypes (mappedEntityTypes )
546567 .tokenType (tokenType )
547568 .allowRegex (allowRegex )
548569 .restrictRegex (restrictRegex )
549- .transformations (transformations )
550570 .build ();
551571 }
552572
@@ -558,7 +578,6 @@ protected DeidentifyImageRequest getDeidentifyImageRequest(DeidentifyFileRequest
558578 Optional <List <EntityType >> entityUniqueCounter = Optional .empty ();
559579 Optional <List <String >> allowRegex = Optional .ofNullable (request .getAllowRegexList ());
560580 Optional <List <String >> restrictRegex = Optional .ofNullable (request .getRestrictRegexList ());
561- Optional <Transformations > transformations = Optional .ofNullable (getTransformations (request .getTransformations ()));
562581
563582 TokenTypeWithoutVault tokenType = buildTokenType (tokenFormat , entityTypes , entityUniqueCounter );
564583
@@ -580,7 +599,6 @@ protected DeidentifyImageRequest getDeidentifyImageRequest(DeidentifyFileRequest
580599 .tokenType (tokenType )
581600 .allowRegex (allowRegex )
582601 .restrictRegex (restrictRegex )
583- .transformations (transformations )
584602 .outputProcessedImage (request .getOutputProcessedImage ())
585603 .outputOcrText (request .getOutputOcrText ())
586604 .build ();
@@ -594,7 +612,6 @@ protected DeidentifyPresentationRequest getDeidentifyPresentationRequest(Deident
594612 Optional <List <EntityType >> entityUniqueCounter = Optional .empty ();
595613 Optional <List <String >> allowRegex = Optional .ofNullable (request .getAllowRegexList ());
596614 Optional <List <String >> restrictRegex = Optional .ofNullable (request .getRestrictRegexList ());
597- Optional <Transformations > transformations = Optional .ofNullable (getTransformations (request .getTransformations ()));
598615
599616 TokenTypeWithoutVault tokenType = buildTokenType (tokenFormat , entityTypes , entityUniqueCounter );
600617
@@ -610,7 +627,6 @@ protected DeidentifyPresentationRequest getDeidentifyPresentationRequest(Deident
610627 .tokenType (tokenType )
611628 .allowRegex (allowRegex )
612629 .restrictRegex (restrictRegex )
613- .transformations (transformations )
614630 .build ();
615631 }
616632
@@ -622,7 +638,6 @@ protected DeidentifySpreadsheetRequest getDeidentifySpreadsheetRequest(Deidentif
622638 Optional <List <EntityType >> entityUniqueCounter = Optional .empty ();
623639 Optional <List <String >> allowRegex = Optional .ofNullable (request .getAllowRegexList ());
624640 Optional <List <String >> restrictRegex = Optional .ofNullable (request .getRestrictRegexList ());
625- Optional <Transformations > transformations = Optional .ofNullable (getTransformations (request .getTransformations ()));
626641
627642 TokenTypeWithoutVault tokenType = buildTokenType (tokenFormat , entityTypes , entityUniqueCounter );
628643
@@ -638,7 +653,6 @@ protected DeidentifySpreadsheetRequest getDeidentifySpreadsheetRequest(Deidentif
638653 .tokenType (tokenType )
639654 .allowRegex (allowRegex )
640655 .restrictRegex (restrictRegex )
641- .transformations (transformations )
642656 .build ();
643657 }
644658
@@ -678,7 +692,6 @@ protected DeidentifyDocumentRequest getDeidentifyDocumentRequest(DeidentifyFileR
678692 Optional <List <EntityType >> entityUniqueCounter = Optional .empty ();
679693 Optional <List <String >> allowRegex = Optional .ofNullable (request .getAllowRegexList ());
680694 Optional <List <String >> restrictRegex = Optional .ofNullable (request .getRestrictRegexList ());
681- Optional <Transformations > transformations = Optional .ofNullable (getTransformations (request .getTransformations ()));
682695
683696 TokenTypeWithoutVault tokenType = buildTokenType (tokenFormat , entityTypes , entityUniqueCounter );
684697
@@ -694,7 +707,6 @@ protected DeidentifyDocumentRequest getDeidentifyDocumentRequest(DeidentifyFileR
694707 .tokenType (tokenType )
695708 .allowRegex (allowRegex )
696709 .restrictRegex (restrictRegex )
697- .transformations (transformations )
698710 .build ();
699711 }
700712
0 commit comments