Skip to content

Commit

Permalink
Changed file name prefix (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae authored Mar 20, 2024
1 parent 716a5d6 commit 90109f3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,23 @@ 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();

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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
4 changes: 1 addition & 3 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<SQSEvent, Void> {
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 90109f3

Please sign in to comment.