165 lines
9.8 KiB
Java
165 lines
9.8 KiB
Java
package net.gepafin.tendermanagement.dao;
|
|
|
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
|
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
|
import net.gepafin.tendermanagement.entities.HubEntity;
|
|
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity;
|
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
|
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
|
import net.gepafin.tendermanagement.service.HubService;
|
|
import net.gepafin.tendermanagement.service.SystemEmailTemplatesService;
|
|
import net.gepafin.tendermanagement.service.UserService;
|
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
|
import net.gepafin.tendermanagement.util.MailUtil;
|
|
import net.gepafin.tendermanagement.util.Utils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@Component
|
|
public class EmailNotificationDao {
|
|
|
|
@Autowired
|
|
private MailUtil mailUtil;
|
|
|
|
@Autowired
|
|
private SystemEmailTemplatesService systemEmailTemplatesService;
|
|
|
|
@Autowired
|
|
private ApplicationService applicationService;
|
|
|
|
@Autowired
|
|
private UserService userService;
|
|
|
|
@Autowired
|
|
private HubService hubService;
|
|
|
|
public void sendMailToNotifyBeneficiaryRegardingNewAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequest) {
|
|
|
|
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequest.getApplicationId());
|
|
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
|
|
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, hub, null);
|
|
|
|
// Create the map for subject placeholders
|
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
|
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
subjectPlaceholders.put("{{company_name}}", applicationEntity.getCompany().getCompanyName());
|
|
|
|
// Create the map for body placeholders
|
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
|
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
|
|
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatLocalDateTime(applicationAmendmentRequest.getProtocol().getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
|
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationAmendmentRequest.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
|
bodyPlaceholders.put("{{form_dataInput}}", "");
|
|
|
|
// Replace placeholders in the subject and body
|
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
|
mailUtil.sendByMailGun(subject, body, List.of(userEntity.getBeneficiary().getEmail()), null);
|
|
}
|
|
|
|
public void sendApplicationFailureNotificationEmail(ApplicationAmendmentRequestEntity amendmentRequest) {
|
|
|
|
ApplicationEntity applicationEntity = applicationService.validateApplication(amendmentRequest.getApplicationId());
|
|
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
|
|
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE, hub, null);
|
|
|
|
// Create the map for subject placeholders
|
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
|
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
subjectPlaceholders.put("{{company_name}}", applicationEntity.getCompany().getCompanyName());
|
|
|
|
// Create the map for body placeholders
|
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
|
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
bodyPlaceholders.put("{{date_time_emailSend}}", DateTimeUtil.formatLocalDateTime(amendmentRequest.getCreatedDate(), GepafinConstant.DD_MM_YYYY_HH_MM));
|
|
|
|
// Replace placeholders in the subject and body
|
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
|
if (userEntity.getBeneficiary().getEmail() != null) {
|
|
mailUtil.sendByMailGun(subject, body, List.of(userEntity.getBeneficiary().getEmail()), null);
|
|
}
|
|
}
|
|
|
|
public void sendAdmissibilityNotificationEmailForApprovedApplication(ApplicationAmendmentRequestEntity amendmentRequest) {
|
|
|
|
ApplicationEntity applicationEntity = applicationService.validateApplication(amendmentRequest.getApplicationId());
|
|
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
|
|
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.ADMISSIBILITY_NOTIFICATION, hub, null);
|
|
|
|
// Create the map for subject placeholders
|
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
|
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
subjectPlaceholders.put("{{company_name}}", applicationEntity.getCompany().getCompanyName());
|
|
|
|
// Create the map for body placeholders
|
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
|
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
|
|
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatCreatedDate(applicationEntity.getProtocol().getCreatedDate()));
|
|
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
|
|
|
// Replace placeholders in the subject and body
|
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
|
|
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
|
String userEmail;
|
|
String companyEmail;
|
|
if (userEntity.getBeneficiary().getEmail() != null && applicationEntity.getCompany().getEmail() != null) {
|
|
userEmail = userEntity.getBeneficiary().getEmail();
|
|
companyEmail = applicationEntity.getCompany().getEmail();
|
|
mailUtil.sendByMailGun(subject, body, List.of(userEmail), null);
|
|
mailUtil.sendByMailGun(subject, body, List.of(companyEmail), null);
|
|
}
|
|
}
|
|
|
|
public void sendInadmissibilityEmailForRejectedApplication(ApplicationAmendmentRequestEntity amendmentRequest) {
|
|
|
|
ApplicationEntity applicationEntity = applicationService.validateApplication(amendmentRequest.getApplicationId());
|
|
HubEntity hub = hubService.valdateHub(applicationEntity.getHubId());
|
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(
|
|
SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, hub, null);
|
|
|
|
// Create the map for subject placeholders
|
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
|
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
subjectPlaceholders.put("{{company_name}}", applicationEntity.getCompany().getCompanyName());
|
|
|
|
// Create the map for body placeholders
|
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
|
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
|
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
|
|
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatCreatedDate(applicationEntity.getProtocol().getCreatedDate()));
|
|
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
|
bodyPlaceholders.put("{{form_text}}", "");
|
|
|
|
// Replace placeholders in the subject and body
|
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
|
|
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
|
String userEmail;
|
|
String companyEmail;
|
|
if (userEntity.getBeneficiary().getEmail() != null && applicationEntity.getCompany().getEmail() != null) {
|
|
userEmail = userEntity.getBeneficiary().getEmail();
|
|
companyEmail = applicationEntity.getCompany().getEmail();
|
|
mailUtil.sendByMailGun(subject, body, List.of(userEmail), null);
|
|
mailUtil.sendByMailGun(subject, body, List.of(companyEmail), null);
|
|
}
|
|
}
|
|
|
|
}
|