Skip to content

Commit

Permalink
Merge pull request #33 from LabGraphTeam/fix/refactoring
Browse files Browse the repository at this point in the history
refactor: EmailService to improve email sending logic
  • Loading branch information
LeonardoMeireles55 authored Jan 26, 2025
2 parents e9b7827 + 124339a commit 64dc4b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void sendFailedAnalyticsNotification(List<AnalyticsRecord> failedRecords,
log.warn("No failed analytics records to send notification for");
return;
}
log.info(validationResults.toString());
log.info(validationResults);


String emailBody = generateAnalyticsFailedEmailBody(failedRecords, validationResults);
Expand Down Expand Up @@ -131,17 +131,15 @@ public void sendFailedAnalyticsNotification(List<AnalyticsRecord> failedRecords,
}
}

public String generateAnalyticsFailedEmailBody(List<AnalyticsRecord> notPassedList,
String otherValidations) {
public String generateAnalyticsFailedEmailBody(List<AnalyticsRecord> notPassedList, String otherValidations) {
String formattedList = notPassedList.stream().map(record -> String.format(
"<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
record.name(), record.level(), record.value().toString(), record.mean().toString(),
record.rules(), record.description(),
record.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))))
"<tr><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td><td style=\"padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;\">%s</td></tr>",
record.name(), record.level(), record.value().toString(), record.mean().toString(),
record.rules(), record.description(),
record.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))))
.collect(Collectors.joining("\n"));
return String.format(HTML_TEMPLATE,
TABLE_STYLE + ANALYTICS_WARNING_HEADER + FAILED_ANALYTICS_HEADER + formattedList
+ LAST_ANALYTICS_PARAGRAPH + "\n" + otherValidations);
ANALYTICS_WARNING_HEADER + String.format(TABLE_STYLE, formattedList) + LAST_ANALYTICS_PARAGRAPH + "\n" + otherValidations);
}

public void notifyUserLogin(String username, String email, LocalDateTime date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,33 @@ public class EmailTemplate {
public static final String EMAIL_SUBJECT_PREFIX = "LabGraph - ";
public static final String HTML_TEMPLATE = "<html><head></head><body>%s</body></html>";
public static final String TABLE_STYLE = """
<style>
table {
border-collapse: collapse;
width: 100%%;
margin: 25px 0;
font-family: Arial, sans-serif;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #dddddd;
}
th {
background-color:rgb(0, 89, 149);
color: #ffffff;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f3f3f3;
}
td {
color: #333333;
}
</style>
""";
public static final String ANALYTICS_WARNING_HEADER =
"""
<p style="font-size: 16px; color: #d32f2f; margin-bottom: 20px;">
<strong>⚠️ Quality Control Alert: Westgard violations</strong>
</p>
<p style="color: #424242; margin-bottom: 15px;">
The following laboratory control measurements have triggered quality control violations based on
Westgard multi-rules. These violations may indicate systematic or random errors in the analytical process:
</p>
""";

public static final String FAILED_ANALYTICS_HEADER =
"""
<table><tr><th>Name</th><th>Level</th><th>Value</th><th>Expected Value</th><th>Rules</th><th>Status</th><th>Date</th></tr>
""";
<table style="border-collapse: collapse; width: 100%%; margin: 25px 0; font-family: Arial, sans-serif; box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden;">
<thead>
<tr style="background-color: rgb(0, 89, 149); color: #ffffff; font-weight: bold;">
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Name</th>
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Level</th>
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Value</th>
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Expected Value</th>
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Rules</th>
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Status</th>
<th style="padding: 12px 15px; text-align: left; border-bottom: 1px solid #dddddd;">Date</th>
</tr>
</thead>
<tbody>
%s
</tbody>
</table>
""";
public static final String ANALYTICS_WARNING_HEADER = """
<p style="font-size: 16px; color: #d32f2f; margin-bottom: 20px;">
<strong>⚠️ Quality Control Alert: Westgard violations</strong>
</p>
<p style="color: #424242; margin-bottom: 15px;">
The following laboratory control measurements have triggered quality control violations based on
Westgard multi-rules. These violations may indicate systematic or random errors in the analytical process:
</p>
""";
public static final String LAST_ANALYTICS_PARAGRAPH = """
</table><p>Please take the necessary actions to address these issues.</p>
""";
}
<p>Please take the necessary actions to address these issues.</p>
""";
}

0 comments on commit 64dc4b9

Please sign in to comment.