Reminder mail to beneficiary

This commit is contained in:
harish
2024-10-31 14:16:26 +05:30
parent 7f0f447c8c
commit c0bd9bb928
11 changed files with 162 additions and 3 deletions

View File

@@ -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==";
}

View File

@@ -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<ApplicationEvaluationEntity> 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<String, String> 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<String, String> 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);
}
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId());
if (entityOptional.isPresent()) {
UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId());
applicationAmendmentRequestDao.sendReminderEmail(amendmentId);
}
}
}

View File

@@ -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<Response<Void>> sendReminderEmail(HttpServletRequest request,
@Parameter( required = true)
@PathVariable(value = "amendmentId") Long amendmentId);
}

View File

@@ -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<Response<Void>> 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)));
}
}