Resolved Conflicts

This commit is contained in:
harish
2024-11-04 17:06:33 +05:30
14 changed files with 216 additions and 47 deletions

View File

@@ -18,10 +18,13 @@ 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.util.Validator;
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
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;
@@ -84,6 +87,13 @@ public class ApplicationAmendmentRequestDao {
@Autowired
private AssignedApplicationsRepository assignedApplicationsRepository;
@Autowired
private SystemEmailTemplatesService systemEmailTemplatesService;
@Autowired
private HubService hubService;
// @Autowired
// private MailUtil mailUtil;
@Autowired
private Validator validator;
@@ -517,4 +527,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(email),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);
}
}