updated code
This commit is contained in:
@@ -1,23 +1,15 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse;
|
||||
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
||||
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||
import net.gepafin.tendermanagement.repositories.HubRepository;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
import net.gepafin.tendermanagement.service.impl.EmailService;
|
||||
import net.gepafin.tendermanagement.service.impl.EmailServiceFactory;
|
||||
@@ -26,6 +18,7 @@ import net.gepafin.tendermanagement.util.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -71,6 +64,12 @@ public class EmailNotificationDao {
|
||||
@Autowired
|
||||
private ApplicationFormFieldRepository applicationFormFieldRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@Value("${rinaldo_email}")
|
||||
private String rinaldoEmail;
|
||||
|
||||
private void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType, Map<String, String> bodyPlaceholders,
|
||||
List<String> additionalRecipients, Long amendmentId) {
|
||||
|
||||
@@ -86,36 +85,60 @@ public class EmailNotificationDao {
|
||||
// bodyPlaceholders.put("{{legal_mail}}", legalMail);
|
||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||
|
||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||
List<String> recipientEmails = getRecipientEmails(applicationEntity, userEntity, additionalRecipients);
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY, 1L,
|
||||
Utils.listToCommaSeparatedString(recipientEmails), userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails, emailLogRequest);
|
||||
sendEmails(applicationEntity, userEntity, additionalRecipients,amendmentId,systemEmailTemplateResponse,subject,body);
|
||||
}
|
||||
private List<String> getRecipientEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients) {
|
||||
private void sendEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients,Long amendmentId,SystemEmailTemplateResponse systemEmailTemplateResponse,String subject,String body) {
|
||||
|
||||
List<String> recipientEmails = new ArrayList<>();
|
||||
Optional<ApplicationEvaluationEntity> applicationEvaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId());
|
||||
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||
// String companyEmail = company.getEmail();
|
||||
// String contactEmail = company.getContactEmail();
|
||||
//
|
||||
// if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||
// recipientEmails.add(companyEmail);
|
||||
// }
|
||||
// if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
||||
// recipientEmails.add(contactEmail);
|
||||
// }
|
||||
//
|
||||
// if (userEntity.getBeneficiary().getEmail() != null) {
|
||||
// recipientEmails.add(userEntity.getBeneficiary().getEmail());
|
||||
// }
|
||||
// if (additionalRecipients != null) {
|
||||
// recipientEmails.addAll(additionalRecipients);
|
||||
// }
|
||||
String companyEmail = company.getEmail();
|
||||
String contactEmail = company.getContactEmail();
|
||||
|
||||
recipientEmails.add("piyush1.kag1@gmail.com");
|
||||
return recipientEmails;
|
||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() ,
|
||||
companyEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(companyEmail), emailLogRequest);
|
||||
}
|
||||
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId(),
|
||||
contactEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(contactEmail), emailLogRequest);
|
||||
}
|
||||
|
||||
if (userEntity.getBeneficiary().getEmail() != null) {
|
||||
String beneficiaryEmail = userEntity.getBeneficiary().getEmail();
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY,userEntity.getBeneficiary().getId() ,
|
||||
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(beneficiaryEmail), emailLogRequest);
|
||||
}
|
||||
if(userEntity.getHub().getEmail() != null){
|
||||
String hubEmails = userEntity.getHub().getEmail();
|
||||
String[] hubEmailArray = hubEmails.split(",");
|
||||
for (String hubEmail : hubEmailArray) {
|
||||
hubEmail = hubEmail.trim();
|
||||
if (!hubEmail.isEmpty()) {
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null,
|
||||
hubEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(hubEmail), emailLogRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rinaldoEmail != null) {
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null ,
|
||||
rinaldoEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(rinaldoEmail), emailLogRequest);
|
||||
}
|
||||
if (applicationEvaluationEntity.isPresent()) {
|
||||
Long preInstructorId = applicationEvaluationEntity.get().getUserId(); // Assuming UserEntity has an email field
|
||||
UserEntity instructorUser = userService.validateUser(preInstructorId);
|
||||
String preInstructorEmail = instructorUser.getEmail();
|
||||
if (preInstructorEmail != null && !preInstructorEmail.isEmpty()) {
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.INSTRUCTOR, instructorUser.getId(),
|
||||
preInstructorEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(preInstructorEmail), emailLogRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// private String determineService(Long hubId) {
|
||||
@@ -132,6 +155,7 @@ public class EmailNotificationDao {
|
||||
bodyPlaceholders.put("{{protocol_number}}", applicationAmendmentRequestEntity.getProtocol().getProtocolNumber().toString());
|
||||
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatLocalDateTime(applicationAmendmentRequestEntity.getProtocol().getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
||||
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationAmendmentRequestEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
||||
bodyPlaceholders.put("{{response_days}}", applicationAmendmentRequestEntity.getResponseDays().toString());
|
||||
|
||||
try {
|
||||
// Retrieve forms and initialize required collections
|
||||
@@ -149,8 +173,9 @@ public class EmailNotificationDao {
|
||||
// Process allFormFields and generate bullet points
|
||||
for (AmendmentFormFieldResponse field : allFormFields) {
|
||||
// Build bullet points
|
||||
bulletPoints.append(field.getLabel());
|
||||
bulletPoints.append("\n");
|
||||
// bulletPoints.append(field.getLabel());
|
||||
bulletPoints.append("<li>").append(field.getLabel()).append("</li>");
|
||||
|
||||
}
|
||||
// Add the generated bullet points to placeholders
|
||||
bodyPlaceholders.put("{{form_dataInput}}", bulletPoints.toString());
|
||||
|
||||
Reference in New Issue
Block a user