From ad505f507d378bf9ebf2cce3c9dcdf08a61d0c71 Mon Sep 17 00:00:00 2001 From: harish Date: Mon, 24 Feb 2025 16:16:06 +0530 Subject: [PATCH] PEC service is enabled only on the production server --- .../tendermanagement/dao/ApplicationDao.java | 4 +-- .../service/impl/PecEmailService.java | 25 ++++++++++++------- src/main/resources/application-dev.properties | 3 ++- .../resources/application-local.properties | 3 ++- .../application-production.properties | 3 ++- .../resources/application-testing.properties | 3 ++- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index a8e1ca8d..8503b05b 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -117,8 +117,8 @@ public class ApplicationDao { @Autowired private AssignedApplicationsRepository assignedApplicationsRepository; - @Value("${default_System_Receiver_Email}") - private String defaultSystemReceiverEmail; +// @Value("${default_System_Receiver_Email}") +// private String defaultSystemReceiverEmail; @Value("${rinaldo_email}") private String rinaldoEmail; diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/PecEmailService.java b/src/main/java/net/gepafin/tendermanagement/service/impl/PecEmailService.java index 4d076bb4..67e58c2d 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/PecEmailService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/PecEmailService.java @@ -26,6 +26,9 @@ public class PecEmailService implements EmailService { @Value("${isMailSendingEnabled}") private String isEmailSendingEnabled; + @Value("${isPecServiceEnabled}") + private String isPecServiceEnabled; + @Autowired private Validator validator; @@ -55,23 +58,27 @@ public class PecEmailService implements EmailService { emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue()); emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient())); try { - Unirest.setTimeouts(0, 0); - response2 = Unirest.post(url) - .header("Authorization", "Bearer " + authToken) - .header("Content-Type", "application/json") - .body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON - .asString(); + if (Boolean.TRUE.equals(Boolean.parseBoolean(isPecServiceEnabled))) { + Unirest.setTimeouts(0, 0); + response2 = Unirest.post(url) + .header("Authorization", "Bearer " + authToken) + .header("Content-Type", "application/json") + .body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON + .asString(); + } }catch(Exception e) { emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue()); emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE); emailLogRequest.setErrorMessage(e.getMessage()); - EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest); + emailLogDao.createEmailLog(emailLogRequest); throw new RuntimeException("Failed to send email via PEC: " + response2.getStatus()); } - emailLogRequest.setEmailServiceResponse(response2.getBody()); + if(response2 != null) { + emailLogRequest.setEmailServiceResponse(response2.getBody()); + } } emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE); - EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest); + emailLogDao.createEmailLog(emailLogRequest); } } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 87a38095..b865c960 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -10,7 +10,8 @@ spring.h2.console.enabled=true isVatCheckGloballyDisabled = false isMailSendingEnabled = true -default_System_Receiver_Email=antonio.manca@bflows.net +isPecServiceEnabled = false +#default_System_Receiver_Email=antonio.manca@bflows.net gepafin_email=rinaldo.bonazzo@bflows.net rinaldo_email=rinaldo.bonazzo@bflows.net carlo_email=test@test.test diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index e52a9577..1f1f0eb0 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -9,7 +9,8 @@ spring.jpa.show-sql=true base-url=http://localhost:8080 isMailSendingEnabled = false -default_System_Receiver_Email=test@test.test +isPecServiceEnabled = false +#default_System_Receiver_Email=test@test.test gepafin_email=test@test.test rinaldo_email=test@test.test carlo_email=test@test.test diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties index 8c181965..d941e7fc 100644 --- a/src/main/resources/application-production.properties +++ b/src/main/resources/application-production.properties @@ -16,7 +16,8 @@ spid.ipd.base.url=https://login.regione.umbria.it active.profile.folder=production isMailSendingEnabled = true -default_System_Receiver_Email=m.gaudino@gepafin.it,f.marinelli@gepafin.it +isPecServiceEnabled = true +#default_System_Receiver_Email=m.gaudino@gepafin.it,f.marinelli@gepafin.it gepafin_email=bandi@pec.gepafin.it rinaldo_email=rinaldo.bonazzo@bflows.net carlo_email=carlo.mancosu@bflows.net diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties index 8ee53329..7c5751c4 100644 --- a/src/main/resources/application-testing.properties +++ b/src/main/resources/application-testing.properties @@ -7,7 +7,8 @@ spring.datasource.password=sa spring.h2.console.enabled=true base-url=http://localhost:8080 isMailSendingEnabled = false -default_System_Receiver_Email=test@test.test +isPecServiceEnabled = false +#default_System_Receiver_Email=test@test.test gepafin_email=test@test.test rinaldo_email=test@test.test carlo_email=test@test.test