From c0bd9bb928ead7e5c644782dbb1727e1d808a2a9 Mon Sep 17 00:00:00 2001 From: harish Date: Thu, 31 Oct 2024 14:16:26 +0530 Subject: [PATCH] Reminder mail to beneficiary --- .../constants/GepafinConstant.java | 4 +- .../dao/ApplicationAmendmentRequestDao.java | 65 +++++++++++++++++++ .../entities/SystemEmailTemplatesEntity.java | 1 + .../ApplicationAmendmentRequestService.java | 2 +- ...pplicationAmendmentRequestServiceImpl.java | 24 +++++++ .../api/ApplicationAmendmentRequestApi.java | 15 +++++ ...ApplicationAmendmentRequestController.java | 12 ++++ .../db/changelog/db.changelog-1.0.0.xml | 9 +++ ...mail_template_for_sollecito_30_10_2024.sql | 29 +++++++++ src/main/resources/message_en.properties | 2 + src/main/resources/message_it.properties | 2 + 11 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/db/dump/insert_system_email_template_for_sollecito_30_10_2024.sql diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 23b14cf0..3a160d09 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -259,7 +259,7 @@ public class GepafinConstant { public static final String EVALUATIONCRITERIA_INVALID = "evaluationCriteria.invalid"; public static final String APPLICATION_NOT_IN_DRAFT_STATUS="application.not.in.draft.status"; public static final String GET_ERROR_S3 = "get.error.s3"; - + public static final String BENEFICIARY_EMAIL_NOT_FOUND_MSG = "beneficiary.email.not.found.msg"; public static final String ADDED_S3_PATH_STRUCTURE ="added.s3.path.structure"; public static final String S3_PATH_STRUCTURE_BY_TYPE ="fetched.s3.path.structure.by.type.successfully"; public static final String S3_PATH_STRUCTURE_NOT_FOUND_BY_TYPE_MSG ="s3.path.not.found.by.type"; @@ -287,7 +287,7 @@ public class GepafinConstant { public static final String AMENDMENT_FOUND_SUCCESS = "amendment.found.success"; public static final String INVALID_AMENDMENT_FOR_COMMENT = "invalid.amendment.for.comment"; public static final String DD_MM_YYYY_HH_MM = "DD_MM_YYYY_HH_MM"; - + public static final String REMINDER_EMAIL_SENT_SUCCESS_MSG = "reminder.email.sent.success.msg"; public static final String ENCRYPT_INIT_VECTOR = "IG8*(*@&)*#biVVD"; public static final String ENCRYPT_KEY = "U2VjdXJlRW5jcnlwdEtleQ=="; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index b5d36dac..1f39459b 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -18,9 +18,14 @@ import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBea import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest; import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse; import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; +import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse; import net.gepafin.tendermanagement.repositories.*; import net.gepafin.tendermanagement.service.*; import net.gepafin.tendermanagement.util.DateTimeUtil; +import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum; +import net.gepafin.tendermanagement.util.MailUtil; +import net.gepafin.tendermanagement.util.Utils; +import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.springframework.beans.factory.annotation.Autowired; @@ -83,6 +88,13 @@ public class ApplicationAmendmentRequestDao { @Autowired private AssignedApplicationsRepository assignedApplicationsRepository; + @Autowired + private SystemEmailTemplatesService systemEmailTemplatesService; + + @Autowired + private HubService hubService; +// @Autowired +// private MailUtil mailUtil; public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) { log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); @@ -481,4 +493,57 @@ public class ApplicationAmendmentRequestDao { log.info("Amendment status updated successfully: {}", response); return response; } + public void sendReminderEmail(Long amendmentId) { + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId) + .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, + Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + ApplicationEntity applicationEntity = applicationService.validateApplication(entityOptional.get().getApplicationId()); + UserEntity beneficiaryUser = userService.validateUser(applicationEntity.getUserId()); + HubEntity hub = hubService.valdateHub(applicationEntity.getHubId()); + SystemEmailTemplateResponse emailTemplate = systemEmailTemplatesService + .retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.AMENDMENT_REMINDER, hub, null); + String subject = prepareSubject(emailTemplate, amendment, beneficiaryUser); + String body = prepareBody(emailTemplate, amendment, beneficiaryUser); + String email = beneficiaryUser.getEmail(); + if (Boolean.TRUE.equals(amendment.getIsEmail())&&email != null && !email.isEmpty()) { + emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email)); +// mailUtil.sendByMailGun(subject,body,List.of("harish.bagora1@gmail.com"),null); + } else { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.BENEFICIARY_EMAIL_NOT_FOUND_MSG)); + } + } + } + + private String prepareSubject(SystemEmailTemplateResponse template, ApplicationAmendmentRequestEntity amendment, UserEntity beneficiary) { + Map subjectPlaceholders = new HashMap<>(); + String firstName = beneficiary.getFirstName() != null ? beneficiary.getFirstName() : ""; + String lastName = beneficiary.getLastName() != null ? beneficiary.getLastName() : ""; + String beneficiaryName = String.join(" ", firstName, lastName).trim(); + + subjectPlaceholders.put("{{amendment_id}}", amendment.getId().toString()); + subjectPlaceholders.put("{{beneficiary_name}}", beneficiaryName); + + return Utils.replacePlaceholders(template.getSubject(), subjectPlaceholders); + } + + private String prepareBody(SystemEmailTemplateResponse template, ApplicationAmendmentRequestEntity amendment, UserEntity beneficiary) { + Map bodyPlaceholders = new HashMap<>(); + bodyPlaceholders.put("{{amendment_id}}", amendment.getId().toString()); + + if (amendment.getStartDate() != null && amendment.getResponseDays() != null) { + + LocalDateTime dueDate = amendment.getStartDate().plusDays(amendment.getResponseDays()); + bodyPlaceholders.put("{{amendment_due_date}}", DateTimeUtil.formatLocalDateTime(dueDate, GepafinConstant.DD_MM_YYYY)); + } else { + + bodyPlaceholders.put("{{amendment_due_date}}", "Not available"); + } + + return Utils.replacePlaceholders(template.getHtmlContent(), bodyPlaceholders); + } + + } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/SystemEmailTemplatesEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/SystemEmailTemplatesEntity.java index 6d8ff6de..1440e00d 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/SystemEmailTemplatesEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/SystemEmailTemplatesEntity.java @@ -43,6 +43,7 @@ public class SystemEmailTemplatesEntity extends BaseEntity { DOCUMENTATION_INTEGRATION_REQUEST("DOCUMENTATION_INTEGRATION_REQUEST"), INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE("INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE"), ADMISSIBILITY_NOTIFICATION("ADMISSIBILITY_NOTIFICATION"), + AMENDMENT_REMINDER("AMENDMENT_REMINDER"), INADMISSIBILITY_TEMPLATE("INADMISSIBILITY_NOTIFICATION"); private String value; diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java index 318e48c1..a6112bf0 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java @@ -25,5 +25,5 @@ public interface ApplicationAmendmentRequestService { public ApplicationAmendmentRequestResponse getAmendmentByApplicationId(HttpServletRequest request,Long applicationId); public ApplicationAmendmentRequestResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationAmendmentRequestEnum status); - + void sendReminderEmail(HttpServletRequest request,Long amendmentId); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java index d8a93d36..2d45bddd 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java @@ -1,8 +1,11 @@ package net.gepafin.tendermanagement.service.impl; import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.config.Translator; +import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao; import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; +import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity; import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum; import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; @@ -10,12 +13,17 @@ import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest; import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; +import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository; +import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository; import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; import net.gepafin.tendermanagement.util.Validator; +import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; +import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendmentRequestService { @@ -25,6 +33,10 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm @Autowired private ApplicationAmendmentRequestDao applicationAmendmentRequestDao; + @Autowired + private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository; + @Autowired + private ApplicationEvaluationRepository applicationEvaluationRepository; @Override public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) { @@ -88,5 +100,17 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm return applicationAmendmentRequestDao.updateApplicationAmendmentStatus(applicationId, status); } + @Override + public void sendReminderEmail(HttpServletRequest request,Long amendmentId) { + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId) + .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, + Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); + + applicationAmendmentRequestDao.sendReminderEmail(amendmentId); + } + } } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java index 2438eae6..42977539 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java @@ -171,4 +171,19 @@ public interface ApplicationAmendmentRequestApi { @Parameter(description = "The application amendment id", required = true) @PathVariable("applicationAmendmentId") Long applicationAmendmentId, @Parameter(description = "status", required = true)@RequestParam(value = "status", required = true) ApplicationAmendmentRequestEnum status); + @Operation(summary = "Send reminder email for the specified amendment", + responses = { + @ApiResponse(responseCode = "200", description = "Email sent successfully"), + @ApiResponse(responseCode = "404", description = "Amendment not found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })) + }) + @PostMapping(value = "sendReminderEmail/{amendmentId}", produces = MediaType.APPLICATION_JSON_VALUE) + ResponseEntity> sendReminderEmail(HttpServletRequest request, + @Parameter( required = true) + @PathVariable(value = "amendmentId") Long amendmentId); + } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java index de74ac06..9a75fe23 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java @@ -117,4 +117,16 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(applicationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_STATUS_UPDATED_SUCCESSFULLY))); } + @Override + public ResponseEntity> sendReminderEmail( + HttpServletRequest request, + Long amendmentId) { + + log.info("Sending reminder email for Amendment ID: {}", amendmentId); + applicationAmendmentRequestService.sendReminderEmail(request,amendmentId); + + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.REMINDER_EMAIL_SENT_SUCCESS_MSG))); + } + } diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index 4156ccf4..5eb2f8b6 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -1695,5 +1695,14 @@ + + select + setval('gepafin_schema.system_email_template_id_seq', (select + max(id)+1 + from gepafin_schema.system_email_template), false) + + + diff --git a/src/main/resources/db/dump/insert_system_email_template_for_sollecito_30_10_2024.sql b/src/main/resources/db/dump/insert_system_email_template_for_sollecito_30_10_2024.sql new file mode 100644 index 00000000..435cf965 --- /dev/null +++ b/src/main/resources/db/dump/insert_system_email_template_for_sollecito_30_10_2024.sql @@ -0,0 +1,29 @@ +-- SQL Dump to insert system email template for amendment reminder email with calculated due date +INSERT INTO gepafin_schema.system_email_template +(template_name, "type", html_content, subject, "json", "system", is_deleted, created_date, updated_date) +VALUES +( + 'Amendment Reminder Email', + 'AMENDMENT_REMINDER', + ' + +
+

PROMEMORIA PER LA PRESENTAZIONE DELL''EMENDAMENTO

+

Buongiorno,

+

Questo รจ un promemoria per completare la presentazione dell''emendamento entro il termine specificato. Di seguito i dettagli:

+
    +
  • Amendment ID: {{amendment_id}}
  • +
  • Data di Scadenza: {{amendment_due_date}}
  • +
+

Si prega di assicurarsi che l''emendamento venga presentato entro la data di scadenza per evitare ritardi. Inviare l''emendamento tramite la piattaforma online {{platform_link}}

+

Distinti saluti,

+

{{email_signature}}

+
+ + ', + 'Reminder: Pending Amendment Submission - ID {{amendment_id}}', + NULL, + true, + false, +CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP); diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 2d547b8c..220d4654 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -101,6 +101,7 @@ success.password.changed=Password changed successfully. logout.successful.msg=Logout successful. You have been logged out successfully. #Update user Active or Deactive status update.user.status.success=User status has been successfully updated. +beneficiary.email.not.found.msg=The email address for the beneficiary could not be found. Please ensure that the beneficiary has a valid email address. #Form-field-related messages @@ -295,6 +296,7 @@ application.amendment.get.success = Application Amendment details fetched succes application.amendment.update.successfully = Application Amendment Updated Successfully. application.amendment.closed.successfully = Application Amendment Closed Successfully. response.days.extended.success=Response days extended successfully. +reminder.email.sent.success.msg=Reminder email sent successfully! added.comment.to.amendment.request.success = Application Amendment Comment Added Successfully. comment.not.found = Comment Not Found. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 544ff70b..ea702497 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -299,3 +299,5 @@ amendment.found.success = Richiesta di emendamento trovata con successo. invalid.amendment.for.comment = Richiesta di emendamento non valida per il commento fornito. DD_MM_YYYY_HH_MM = dd_MM_yyyy HH:mm create.application.data.amendment.msg =Emendamento alla domanda inviato con successo +beneficiary.email.not.found.msg=L'indirizzo email per il beneficiario non ่ stato trovato. Si prega di assicurarsi che il beneficiario abbia un indirizzo email valido. +reminder.email.sent.success.msg=Email di promemoria inviata con successo!