-
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.
Update application.properties with database and mail configurations
- Set active Spring profile to local by default - Enable ANSI output for logging - Configure logging level and file - Set server port with default value - Expose all management endpoints and show health details - Configure MariaDB datasource with environment variables - Disable JPA SQL logging and stacktrace inclusion in errors - Add security token and issuer configurations - Disable JPA open-in-view - Enable virtual threads - Add Tomcat datasource validation settings - Configure SMTP settings for Gmail
- Loading branch information
1 parent
7a92f8c
commit 58f5cb6
Showing
15 changed files
with
97 additions
and
35 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
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
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package leonardo.labutilities.qualitylabpro.services.analytics; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import leonardo.labutilities.qualitylabpro.dtos.analytics.*; | ||
import leonardo.labutilities.qualitylabpro.dtos.email.EmailRecord; | ||
import leonardo.labutilities.qualitylabpro.repositories.AnalyticsRepository; | ||
import leonardo.labutilities.qualitylabpro.services.email.EmailService; | ||
import leonardo.labutilities.qualitylabpro.utils.exception.CustomGlobalErrorHandling; | ||
import leonardo.labutilities.qualitylabpro.utils.mappers.AnalyticsMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
@@ -20,10 +23,13 @@ | |
public abstract class AnalyticsHelperService implements IAnalyticsHelperService { | ||
|
||
private final AnalyticsRepository analyticsRepository; | ||
private final EmailService emailService; | ||
|
||
private final Pageable pageable = PageRequest.of(0, 200); | ||
|
||
public AnalyticsHelperService(AnalyticsRepository analyticsRepository) { | ||
public AnalyticsHelperService(AnalyticsRepository analyticsRepository, EmailService emailService) { | ||
this.analyticsRepository = analyticsRepository; | ||
this.emailService = emailService; | ||
} | ||
|
||
@Override | ||
|
@@ -76,7 +82,12 @@ public List<AnalyticsRecord> validateAnalyticsNameExists( | |
@Override | ||
public boolean isRecordValid(AnalyticsRecord record) { | ||
String rules = record.rules(); | ||
return (!Objects.equals(rules, "+3s") && !Objects.equals(rules, "-3s")); | ||
return (!Objects.equals(rules, "+3s") || !Objects.equals(rules, "-3s")); | ||
} | ||
|
||
public boolean isRecordStd3s(AnalyticsRecord record) { | ||
String rules = record.rules(); | ||
return (Objects.equals(rules, "+3s") || Objects.equals(rules, "-3s")); | ||
} | ||
|
||
@Override | ||
|
@@ -209,7 +220,22 @@ public void saveNewAnalyticsRecords(List<AnalyticsRecord> valuesOfLevelsList) { | |
if (newAnalytics.isEmpty()) { | ||
throw new CustomGlobalErrorHandling.DataIntegrityViolationException(); | ||
} | ||
analyticsRepository.saveAll(newAnalytics); | ||
|
||
var analyticsList = analyticsRepository.saveAll(newAnalytics); | ||
log.info("New analytics records saved: {}...", analyticsList.get(0).toString()); | ||
var notPassedList = analyticsList.stream() | ||
.map(AnalyticsMapper::toRecord).filter(this::isRecordStd3s).toList(); | ||
if (!notPassedList.isEmpty()) { | ||
String formattedList = notPassedList.stream() | ||
.map(record -> String.format( | ||
"name: %s:, level: %s, value: %s, expected value: %s, rules: %s, status: %s, at: %s\n Recommendation: Please review the test procedures and ensure all equipment is calibrated.", | ||
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")); | ||
String emailBody = String.format( | ||
"Dear Team,\n\nThe following analytics records did not pass the standard deviation criteria:\n\n%s\n\nPlease take the necessary actions to address these issues.", | ||
formattedList); | ||
emailService.sendEmail(new EmailRecord("[email protected]", "Warning: Analytics Not Passed", emailBody)); | ||
} | ||
} | ||
|
||
@Override | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,28 @@ | |
import lombok.RequiredArgsConstructor; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class EmailService { | ||
private final JavaMailSender javaMailSender; | ||
|
||
@Value("${spring.mail.username}") | ||
private String emailFrom; | ||
@Async | ||
public void sendEmail(EmailRecord email) { | ||
var message = new SimpleMailMessage(); | ||
message.setFrom("[email protected]"); | ||
message.setFrom(emailFrom); | ||
message.setTo(email.to()); | ||
message.setSubject(email.subject()); | ||
message.setText(email.body()); | ||
message.setSubject("LabGraph - " + email.subject()); | ||
message.setText(buildEmailBody(email)); | ||
javaMailSender.send(message); | ||
} | ||
|
||
} | ||
private String buildEmailBody(EmailRecord email) { | ||
return String.format("\n\n%s\n\nBest regards,\nLabGraph Team", | ||
email.body()); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
server.port = 8080 | ||
|
||
logging.level.leonardo=DEBUG | ||
management.endpoint.health.show-details=always | ||
# Database config | ||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver | ||
spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:mariadb://localhost:3306/lab_api_alpha_} | ||
|
@@ -18,7 +19,7 @@ spring.jpa.properties.hibernate.format_sql=true | |
|
||
spring.mail.host=smtp.gmail.com | ||
spring.mail.port=587 | ||
spring.mail.username=[email protected] | ||
spring.mail.password=test_password | ||
spring.mail.username=${SPRING_MAIL_USERNAME} | ||
spring.mail.password=${SPRING_MAIL_PASSWORD} | ||
spring.mail.properties.mail.smtp.auth=true | ||
spring.mail.properties.mail.smtp.starttls.enable=true | ||
spring.mail.properties.mail.smtp.starttls.enable=true |
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
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