Skip to content

Commit

Permalink
Ab2d-5864/delete file from bfd (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae authored Feb 23, 2024
1 parent 25e29b4 commit 2546fff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
36 changes: 13 additions & 23 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.model.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -78,25 +75,18 @@ public String createResponseOptOutFile(String responseContent) {
}
}

//ToDo: AB2D-5796 Delete Opt-out file from S3 (inbound)
// public static void deleteFileFromS3() {
// // The map always contains 2 lines: the first and last from the optout file.
// if (optOutResultMap.size() == 2) {
// try {
// var request = DeleteObjectRequest.builder()
// .bucket(BFD_S3_BUCKET_NAME)
// .key(fileName)
// .build();
//
// S3_CLIENT.deleteObject(request);
// } catch (SdkClientException ex) {
// logger.log(ex.getMessage());
// }
// }
// else {
// // Slack alert
// }
// }
public void deleteFileFromS3() {
try {
var request = DeleteObjectRequest.builder()
.bucket(BFD_S3_BUCKET_NAME)
.key(fileName)
.build();

s3Client.deleteObject(request);
} catch (SdkClientException ex) {
logger.log(ex.getMessage());
}
}


}
6 changes: 6 additions & 0 deletions optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ void createResponseOptOutFileTest() {
assertTrue(S3MockAPIExtension.isObjectExists(key));
S3MockAPIExtension.deleteFile(key);
}

@Test
void deleteFileFromS3Test() {
OPT_OUT_S3.deleteFileFromS3();
Assertions.assertFalse(S3MockAPIExtension.isObjectExists(TEST_FILE_NAME));
}
}

0 comments on commit 2546fff

Please sign in to comment.