Skip to content

Commit

Permalink
more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Apr 3, 2024
1 parent 79da7be commit 979c37a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import java.sql.Timestamp;

import static gov.cms.ab2d.optout.OptOutConstants.ENDPOINT;

public class OptOutHandler implements RequestHandler<SQSEvent, Void> {
Expand All @@ -25,6 +27,7 @@ public void processSQSMessage(SQSEvent.SQSMessage msg, Context context) {
var logger = context.getLogger();
try {
logger.log("OptOut Lambda started. Processing message from SQS " + msg.getBody());
var start = System.nanoTime();

JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(msg.getBody());
Expand All @@ -33,6 +36,8 @@ public void processSQSMessage(SQSEvent.SQSMessage msg, Context context) {

var optOutProcessing = processorInit(logger);
optOutProcessing.process(getFileName(notification), getBucketName(notification), ENDPOINT);
var stop = System.nanoTime();
logger.log("TIME " + (stop - start));
} catch (Exception ex) {
logger.log("An error occurred");
throw new OptOutException("An error occurred", ex);
Expand Down
4 changes: 4 additions & 0 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public void processFileFromS3(BufferedReader reader) {
String line;
var lineNumber = 0L;
try (var dbConnection = DriverManager.getConnection(parameterStore.getDbHost(), parameterStore.getDbUser(), parameterStore.getDbPassword())){
logger.log("Connection: " + dbConnection);
while ((line = reader.readLine()) != null) {
logger.log("lineNumber " + lineNumber);
if (!line.startsWith(HEADER_RESP) && !line.startsWith(TRAILER_RESP)) {
var optOutInformation = createOptOutInformation(line);
optOutInformationMap.put(lineNumber, optOutInformation);
Expand All @@ -94,6 +96,7 @@ public void processFileFromS3(BufferedReader reader) {
public OptOutInformation createOptOutInformation(String information) {
var mbi = information.substring(MBI_INDEX_START, MBI_INDEX_END).trim();
var optOutFlag = (information.charAt(OPTOUT_FLAG_INDEX) == 'Y');
logger.log("OptOutInformation " + optOutFlag);
return new OptOutInformation(mbi, optOutFlag);
}

Expand All @@ -103,6 +106,7 @@ public void updateOptOut(long lineNumber, OptOutInformation optOutInformation, C
statement.execute();
} catch (SQLException ex) {
logger.log("There is an insertion error on the line " + lineNumber);
logger.log(ex.getMessage());
isRejected = true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public String createResponseOptOutFile(String responseContent) {
.build();

s3Client.putObject(objectRequest, RequestBody.fromString(responseContent));
logger.log("Response file done");
return key;
} catch (AmazonS3Exception ex) {
var errorMessage = "Response OptOut file cannot be created. ";
Expand All @@ -85,6 +86,7 @@ public void deleteFileFromS3() {
.build();

s3Client.deleteObject(request);
logger.log("delete file done");
} catch (SdkClientException ex) {
logger.log(ex.getMessage());
}
Expand Down

0 comments on commit 979c37a

Please sign in to comment.