diff --git a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareConstants.java b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareConstants.java index 6202943..e3eaf0d 100644 --- a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareConstants.java +++ b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareConstants.java @@ -12,7 +12,7 @@ public class AttributionDataShareConstants { public static final String TEST_ENDPOINT = "http://127.0.0.1:8001"; public static final Region S3_REGION = Region.US_EAST_1; public static final String FILE_PATH = "/tmp/"; - public static final String REQ_FILE_NAME = "P#EFT.ON.AB2D.NGD.REQ."; + public static final String REQ_FILE_NAME = "#EFT.ON.AB2D.NGD.REQ."; public static final String REQ_FILE_NAME_PATTERN = "'D'yyMMdd.'T'HHmmsss"; public static final String FIRST_LINE = "HDR_BENEDATAREQ"; public static final String LAST_LINE = "TLR_BENEDATAREQ"; diff --git a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHandler.java b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHandler.java index 311169e..634f907 100644 --- a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHandler.java +++ b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHandler.java @@ -31,7 +31,8 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co logger.log("AttributionDataShare Lambda is started"); String currentDate = new SimpleDateFormat(REQ_FILE_NAME_PATTERN).format(new Date()); - String fileName = REQ_FILE_NAME + currentDate; + var prefix = (System.getenv(BUCKET_NAME_PROP).contains("prod")) ? "P" : "T"; + String fileName = prefix + REQ_FILE_NAME + currentDate; String fileFullPath = FILE_PATH + fileName; var parameterStore = AttributionParameterStore.getParameterStore(); AttributionDataShareHelper helper = helperInit(fileName, fileFullPath, logger); diff --git a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelper.java b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelper.java index bb95130..64dc991 100644 --- a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelper.java +++ b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelper.java @@ -69,14 +69,15 @@ String getResponseLine(String currentMbi, Timestamp effectiveDate, Boolean optOu } public String uploadToS3(S3AsyncClient s3AsyncClient) { - String currentDate = new SimpleDateFormat(REQ_FILE_NAME_PATTERN).format(new Date()); - var key = REQ_FILE_NAME + currentDate; S3TransferManager transferManager = S3TransferManager.builder() .s3Client(s3AsyncClient) .build(); + var name = getUploadPath() + fileName; + var bucketName = getBucketName(); + UploadFileRequest uploadFileRequest = UploadFileRequest.builder() - .putObjectRequest(b -> b.bucket(getBucketName()).key(getUploadPath() + key)) + .putObjectRequest(b -> b.bucket(bucketName).key(name)) .addTransferListener(LoggingTransferListener.create()) .source(Paths.get(fileFullPath)) .build(); @@ -84,6 +85,7 @@ public String uploadToS3(S3AsyncClient s3AsyncClient) { FileUpload fileUpload = transferManager.uploadFile(uploadFileRequest); CompletedFileUpload uploadResult = fileUpload.completionFuture().join(); + logger.log("File with name: " + name + " was uploaded to bucket: " + bucketName); return uploadResult.response().eTag(); } diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutConstants.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutConstants.java index d92dd27..71293de 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutConstants.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutConstants.java @@ -19,7 +19,7 @@ public class OptOutConstants { public static final String EFFECTIVE_DATE_PATTERN = "yyyyMMdd"; public static final int EFFECTIVE_DATE_LENGTH = 8; public static final String LINE_SEPARATOR = System.getProperty("line.separator"); - public static final String CONF_FILE_NAME = "P#EFT.ON.AB2D.NGD.CONF."; + public static final String CONF_FILE_NAME = "#EFT.ON.AB2D.NGD.CONF."; public static final String CONF_FILE_NAME_PATTERN = "'D'yyMMdd.'T'HHmmsss"; public static final String UPDATE_STATEMENT = "UPDATE public.coverage\n" + "SET opt_out_flag = ?, effective_date = current_timestamp\n" + diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java index 70bcb5d..f5d4296 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java @@ -8,8 +8,6 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import java.net.URISyntaxException; - import static gov.cms.ab2d.optout.OptOutConstants.ENDPOINT; public class OptOutHandler implements RequestHandler { @@ -41,7 +39,7 @@ public void processSQSMessage(SQSEvent.SQSMessage msg, Context context) { } } - public OptOutProcessor processorInit(LambdaLogger logger) throws URISyntaxException { + public OptOutProcessor processorInit(LambdaLogger logger) { return new OptOutProcessor(logger); } diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java index f758365..cb1389c 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java @@ -40,7 +40,8 @@ public void process(String fileName, String bfdBucket, String endpoint) throws U var optOutS3 = new OptOutS3(getS3Client(endpoint), fileName, bfdBucket, logger); processFileFromS3(optOutS3.openFileS3()); - optOutS3.createResponseOptOutFile(createResponseContent()); + var name = optOutS3.createResponseOptOutFile(createResponseContent()); + logger.log("File with name " + name + " was uploaded to bucket: " + bfdBucket); if (!isRejected) optOutS3.deleteFileFromS3(); } diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java index c55013c..fe6721a 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java @@ -92,7 +92,8 @@ public void deleteFileFromS3() { public String getOutFileName() { //bfdeft01/ab2d/in/testing.txt - var name = CONF_FILE_NAME + var prefix = (bfdBucket.contains("prod")) ? "P" : "T"; + var name = prefix + CONF_FILE_NAME + new SimpleDateFormat(CONF_FILE_NAME_PATTERN).format(new Date()); String[] path = fileName.split("in"); diff --git a/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java b/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java index 4c259d7..286551e 100644 --- a/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java +++ b/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java @@ -1,6 +1,5 @@ package gov.cms.ab2d.optout; -import com.amazonaws.services.lambda.runtime.LambdaLogger; import com.amazonaws.services.lambda.runtime.events.SQSEvent; import com.amazonaws.services.s3.event.S3EventNotification; import gov.cms.ab2d.testutils.AB2DPostgresqlContainer; @@ -14,14 +13,12 @@ import org.testcontainers.junit.jupiter.Testcontainers; import java.io.IOException; -import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collections; import static gov.cms.ab2d.optout.OptOutConstantsTest.*; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @Testcontainers @@ -31,15 +28,15 @@ public class OptOutHandlerTest { @Container private static final PostgreSQLContainer POSTGRE_SQL_CONTAINER = new AB2DPostgresqlContainer(); private final static OptOutHandler handler = spy(new OptOutHandler()); - private final static OptOutProcessor OPT_OUT_PROCESSOR = mock(OptOutProcessor.class); + // private final static OptOutProcessor OPT_OUT_PROCESSOR = mock(OptOutProcessor.class); private final static SQSEvent sqsEvent = mock(SQSEvent.class); private final static SQSEvent.SQSMessage sqsMessage = mock(SQSEvent.SQSMessage.class); @BeforeAll - static void beforeAll() throws URISyntaxException, IOException { + static void beforeAll() throws IOException { when(sqsEvent.getRecords()).thenReturn(Collections.singletonList(sqsMessage)); when(sqsMessage.getBody()).thenReturn(getPayload()); - when(handler.processorInit(any(LambdaLogger.class))).thenReturn(OPT_OUT_PROCESSOR); + // when(handler.processorInit(any(LambdaLogger.class))).thenReturn(OPT_OUT_PROCESSOR); } @Test diff --git a/optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java b/optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java index e60cd62..99994c0 100644 --- a/optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java +++ b/optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java @@ -63,6 +63,6 @@ void deleteFileFromS3Test() { void getOutFileName() { OPT_OUT_S3 = new OptOutS3(S3_CLIENT, TEST_BUCKET_PATH + "/in/" + TEST_FILE_NAME, TEST_BFD_BUCKET_NAME, mock(LambdaLogger.class)); var outFileName = OPT_OUT_S3.getOutFileName(); - Assertions.assertTrue(outFileName.startsWith(TEST_BUCKET_PATH + "/out/" + CONF_FILE_NAME)); + Assertions.assertTrue(outFileName.startsWith(TEST_BUCKET_PATH + "/out/T" + CONF_FILE_NAME)); } }