Skip to content

Commit

Permalink
Refactor to remove repetitive code
Browse files Browse the repository at this point in the history
  • Loading branch information
TevinAdams committed Sep 18, 2024
1 parent a2b2d04 commit 7b0cf6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>1.0.3.15</version>
<version>1.0.3.16</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,32 @@ public SNSService() throws URISyntaxException {
logger.info("finished initializing SNS Service");
}

public void sendMalformedDataSNSLOA(ArrayList<String> loaSysIds) throws MessagingException, URISyntaxException {
if (loaSysIds.size() > 0) {
logger.info("sending malformed LOA SNS");
String loaMsg = "Malformed LOA data has been detected when ingesting TGET Data.";
String loaSysIdsListHeader = "The following loaSysIds had malformed rows: \n";
String loaSysIdsListed = "";

for (String loaSysId : loaSysIds) {
loaSysIdsListed += loaSysId + "\n";
}

loaMsg += "\n" + loaSysIdsListHeader + "\n" + loaSysIdsListed;

send(engGovTopicARN, loaMsg);
} else {
logger.info("not sending malformed LOA SNS. List of malformed loaSysIds is empty");
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;
}
}

public void sendMalformedDataSNSTAC(ArrayList<String> tacSysIds) throws MessagingException, URISyntaxException {
if (tacSysIds.size() > 0) {
logger.info("sending malformed TAC SNS");
String tacMsg = "Malformed TAC data has been detected when ingesting TGET Data.";
String tacSysIdsListHeader = "The following tacSysIds had malformed rows: \n";
String tacSysIdsListed = "";
for (String sysId : sysIds) {
sysIdsListed += sysId + "\n";
}

for (String tacSysId : tacSysIds) {
tacSysIdsListed += tacSysId + "\n";
}
msg += sysIdsListed;

tacMsg += "\n" + tacSysIdsListHeader + "\n" + tacSysIdsListed;
logger.info("sending malformed " + msgType + " SNS");
send(engGovTopicARN, msg);
logger.info("finished sending malformed " + msgType + " SNS");

send(engGovTopicARN, tacMsg);
logger.info("finished sending malformed TAC SNS");
} else {
logger.info("not sending malformed TAC SNS. List of malformed tacSysIds is empty");
}
}

private void send(String topicArn, String msg) throws MessagingException, URISyntaxException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/milmove/trdmlambda/milmove/util/Trdm.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void UpdateTGETData(XMLGregorianCalendar ourLastUpdate, String trdmTable,
try {
logger.info(
"malformed TAC data detected when parsing. Sending malformed TAC data SNS notification");
snsService.sendMalformedDataSNSTAC(tacParser.getMalformedTacList());
snsService.sendMalformedData(tacParser.getMalformedTacList(), "TAC");
;
logger.info("finished sending malformed TAC SNS notification");
} catch (Exception e) {
Expand Down Expand Up @@ -247,7 +247,7 @@ public void UpdateTGETData(XMLGregorianCalendar ourLastUpdate, String trdmTable,
try {
logger.info(
"malformed LOA data detected when parsing. Sending malformed LOA data SNS notification");
snsService.sendMalformedDataSNSLOA(loaParser.getMalformedLoaList());
snsService.sendMalformedData(loaParser.getMalformedLoaList(), "LOA");
;
logger.info("finished sending malformed LOA SNS notification");
} catch (Exception e) {
Expand Down

0 comments on commit 7b0cf6e

Please sign in to comment.