-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from transcom/B-20564-MalformedData-Notification
B-20564: Malformed Data Notification
- Loading branch information
Showing
13 changed files
with
279 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 0 additions & 136 deletions
136
src/main/java/com/milmove/trdmlambda/milmove/service/EmailService.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/main/java/com/milmove/trdmlambda/milmove/service/S3Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.milmove.trdmlambda.milmove.service; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
|
||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.core.ResponseInputStream; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.GetObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.GetObjectResponse; | ||
import software.amazon.awssdk.services.s3.model.S3Exception; | ||
|
||
@Component | ||
public class S3Service { | ||
|
||
private Logger logger = (Logger) LoggerFactory.getLogger(S3Service.class); | ||
|
||
private S3Client s3Client; | ||
private final String trdmBucketName = "transcom-gov-milmove-stg-lambda-trdm-soap-us-gov-west-1"; | ||
private final String trdmTruststoreKeyName = "trdm_lambda_milmove_truststore_base64.txt"; | ||
|
||
public S3Service() throws URISyntaxException { | ||
logger.info("S3Service::S3Service - starting initialization of S3 Service"); | ||
|
||
this.s3Client = S3Client.builder() | ||
.region(Region.US_GOV_WEST_1) | ||
.credentialsProvider(DefaultCredentialsProvider.create()) | ||
.build(); | ||
|
||
logger.info("S3Service::S3Service - finished initialization of S3 Service"); | ||
} | ||
|
||
public String getTRDMTruststore() { | ||
logger.info("S3Service::getTRDMTruststore - getting TRDM Truststore base64 string from S3"); | ||
String trdmTruststoreBase64String = getS3Object(trdmBucketName, trdmTruststoreKeyName); | ||
logger.info("S3Service::getTRDMTruststore - returning TRDM Truststore string"); | ||
return trdmTruststoreBase64String; | ||
} | ||
|
||
private String getS3Object(String bucketName, String keyName) { | ||
try { | ||
GetObjectRequest objectRequest = GetObjectRequest.builder() | ||
.key(keyName) | ||
.bucket(bucketName) | ||
.build(); | ||
|
||
ResponseInputStream<GetObjectResponse> object = this.s3Client.getObject(objectRequest); | ||
String trdmTruststoreBase64 = new String(object.readAllBytes()).trim(); | ||
|
||
logger.info("successfully obtained object from bucket " + bucketName | ||
+ " S3 object " + keyName); | ||
|
||
object.close(); | ||
return trdmTruststoreBase64; | ||
} catch (S3Exception ex) { | ||
logger.error("S3Service::getS3ObjectBytes - error with S3 client" + ex); | ||
} catch (IOException ex) { | ||
logger.error("S3Service::getS3ObjectBytes - IO error with S3 client" + ex); | ||
} | ||
return null; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/milmove/trdmlambda/milmove/service/SNSService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.milmove.trdmlambda.milmove.service; | ||
|
||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import jakarta.mail.MessagingException; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.core.exception.SdkClientException; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.sns.SnsClient; | ||
import software.amazon.awssdk.services.sns.model.PublishRequest; | ||
import software.amazon.awssdk.services.sns.model.PublishResponse; | ||
import software.amazon.awssdk.services.sns.model.SnsException; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
|
||
@Service | ||
public class SNSService { | ||
|
||
private Logger logger = (Logger) LoggerFactory.getLogger(SNSService.class); | ||
private final String engGovTopicARN = "arn:aws-us-gov:sns:us-gov-west-1:015932076428:eng-gov-notification"; | ||
|
||
public SNSService() throws URISyntaxException { | ||
logger.info("starting initialization of SNS Service"); | ||
logger.info("finished initializing SNS Service"); | ||
} | ||
|
||
public void sendMalformedData(ArrayList<String> sysIds, String msgType) | ||
throws MessagingException, URISyntaxException { | ||
|
||
String msg = ""; | ||
String sysIdsListed = ""; | ||
String tacMsg = "Malformed TAC data has been detected when ingesting TGET Data. \n"; | ||
String tacSysIdsListHeader = "The following tacSysIds had malformed rows: \n"; | ||
String loaMsg = "Malformed LOA data has been detected when ingesting TGET Data. \n"; | ||
String loaSysIdsListHeader = "The following loaSysIds had malformed rows: \n"; | ||
|
||
if (msgType == "TAC") { | ||
msg += tacMsg + tacSysIdsListHeader; | ||
} else if (msgType == "LOA") { | ||
msg += loaMsg + loaSysIdsListHeader; | ||
} | ||
|
||
for (String sysId : sysIds) { | ||
sysIdsListed += sysId + "\n"; | ||
} | ||
|
||
msg += sysIdsListed; | ||
|
||
logger.info("sending malformed " + msgType + " SNS"); | ||
send(engGovTopicARN, msg); | ||
logger.info("finished sending malformed " + msgType + " SNS"); | ||
|
||
} | ||
|
||
private void send(String topicArn, String msg) throws MessagingException, URISyntaxException { | ||
logger.info("sending SNS message"); | ||
try { | ||
PublishRequest request = PublishRequest.builder() | ||
.message(msg) | ||
.topicArn(topicArn) | ||
.build(); | ||
|
||
SnsClient snsClient = SnsClient.builder() | ||
.region(Region.US_GOV_WEST_1) | ||
.credentialsProvider(DefaultCredentialsProvider.create()) | ||
.build(); | ||
|
||
PublishResponse result = snsClient.publish(request); | ||
logger.info("message successfully sent. With status code: " | ||
+ result.sdkHttpResponse().statusCode() + " and Message Id: " | ||
+ result.messageId()); | ||
|
||
snsClient.close(); | ||
logger.info("finished sending SNS message"); | ||
} catch (SnsException e) { | ||
logger.error("SnsException executing sns notification cron job", e); | ||
} catch (SdkClientException sdke) { | ||
logger.error("SdkClientException: " + sdke.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.