Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed file name prefix #96

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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));
}
}
Loading