Done ticket GEPAFINBE-6141
This commit is contained in:
@@ -1295,8 +1295,9 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
if (Boolean.TRUE.equals(amendment.getIsEmail()) && email != null && !email.isEmpty()) {
|
if (Boolean.TRUE.equals(amendment.getIsEmail()) && email != null && !email.isEmpty()) {
|
||||||
log.info("Sending reminder email to: {}", email);
|
log.info("Sending reminder email to: {}", email);
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, beneficiaryUser.getId(), email,
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, beneficiaryUser.getId(), email,
|
||||||
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId());
|
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId(),subject,body);
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLogRequest);
|
EmailLogEntity emailLog=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLog);
|
||||||
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
|
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
|
||||||
List<EmailSendResponse> responses = List.of(emailSendResponse);
|
List<EmailSendResponse> responses = List.of(emailSendResponse);
|
||||||
if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())){
|
if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())){
|
||||||
|
|||||||
@@ -1232,7 +1232,7 @@ public class ApplicationDao {
|
|||||||
// Replace placeholders in the subject and body
|
// Replace placeholders in the subject and body
|
||||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.USER,userEntity.getId(),userEntity.getEmail(),userEntity.getId(),applicationEntity.getId(),null,applicationEntity.getCall().getId());
|
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.USER,userEntity.getId(),userEntity.getEmail(),userEntity.getId(),applicationEntity.getId(),null,applicationEntity.getCall().getId(),subject,body);
|
||||||
String email = userEntity.getEmail();
|
String email = userEntity.getEmail();
|
||||||
if (userEntity.getBeneficiary() != null) {
|
if (userEntity.getBeneficiary() != null) {
|
||||||
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
||||||
@@ -1245,12 +1245,14 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
emailLogRequest.setRecipientId(userEntity.getBeneficiary().getId());
|
emailLogRequest.setRecipientId(userEntity.getBeneficiary().getId());
|
||||||
}
|
}
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogEntity);
|
||||||
if (Boolean.TRUE.equals(hub.getUniqueUuid().equals(defaultHubUuid)) && userEntity.getBeneficiary() != null) {
|
if (Boolean.TRUE.equals(hub.getUniqueUuid().equals(defaultHubUuid)) && userEntity.getBeneficiary() != null) {
|
||||||
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
||||||
email = userEntity.getBeneficiary().getEmail();
|
email = userEntity.getBeneficiary().getEmail();
|
||||||
emailLogRequest.setRecipientId(userEntity.getBeneficiary().getId());
|
emailLogRequest.setRecipientId(userEntity.getBeneficiary().getId());
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
EmailLogEntity emailLog=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLog);
|
||||||
}
|
}
|
||||||
List<String> recipientEmails = new ArrayList<>();
|
List<String> recipientEmails = new ArrayList<>();
|
||||||
// recipientEmails.add(email);
|
// recipientEmails.add(email);
|
||||||
@@ -1277,7 +1279,8 @@ public class ApplicationDao {
|
|||||||
emailLogRequest.setRecipientType(RecipientTypeEnum.COMPANY);
|
emailLogRequest.setRecipientType(RecipientTypeEnum.COMPANY);
|
||||||
emailLogRequest.setRecipientEmails(String.valueOf(recipientEmails));
|
emailLogRequest.setRecipientEmails(String.valueOf(recipientEmails));
|
||||||
}
|
}
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, recipientEmails,emailLogRequest);
|
EmailLogEntity emailLog=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body, recipientEmails,emailLog);
|
||||||
}
|
}
|
||||||
private void sendMailTodefaultSystemAndGepafin(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
private void sendMailTodefaultSystemAndGepafin(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||||
CallEntity call = applicationEntity.getCall();
|
CallEntity call = applicationEntity.getCall();
|
||||||
@@ -1319,7 +1322,7 @@ public class ApplicationDao {
|
|||||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||||
|
|
||||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,userEntity.getEmail(),userEntity.getId(),applicationEntity.getId(),null,applicationEntity.getCall().getId());
|
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,userEntity.getEmail(),userEntity.getId(),applicationEntity.getId(),null,applicationEntity.getCall().getId(),subject,body);
|
||||||
|
|
||||||
List<String> hubEmails = Arrays.stream(hub.getEmail().split(","))
|
List<String> hubEmails = Arrays.stream(hub.getEmail().split(","))
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
@@ -1327,9 +1330,11 @@ public class ApplicationDao {
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
emailLogRequest.setRecipientEmails(hub.getEmail());
|
emailLogRequest.setRecipientEmails(hub.getEmail());
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body,hubEmails,emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body,hubEmails,emailLogEntity);
|
||||||
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLogRequest);
|
EmailLogEntity emailLog=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLog);
|
||||||
}
|
}
|
||||||
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId,
|
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId,
|
||||||
MultipartFile file) {
|
MultipartFile file) {
|
||||||
@@ -2447,14 +2452,14 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void sendApplicationSubmissionFailureEmail(EmailLogRequest emailLogRequest){
|
public void sendApplicationSubmissionFailureEmail(EmailLogEntity emailLogEntity){
|
||||||
|
|
||||||
Long callId = emailLogRequest.getCallId();
|
Long callId = emailLogEntity.getCallId();
|
||||||
CallEntity call = callService.validateCall(callId);
|
CallEntity call = callService.validateCall(callId);
|
||||||
HubEntity hub = call.getHub();
|
HubEntity hub = call.getHub();
|
||||||
Long userId = emailLogRequest.getUserId();
|
Long userId = emailLogEntity.getUserId();
|
||||||
UserEntity user = userService.validateUser(userId);
|
UserEntity user = userService.validateUser(userId);
|
||||||
Long applicationId = emailLogRequest.getApplicatioId();
|
Long applicationId = emailLogEntity.getApplicationId();
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
|
|
||||||
@@ -2467,7 +2472,7 @@ public class ApplicationDao {
|
|||||||
subjectPlaceholders.put("{{call_name}}", call.getName());
|
subjectPlaceholders.put("{{call_name}}", call.getName());
|
||||||
|
|
||||||
Map<String, String> bodyPlaceholders = new HashMap<>();
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||||
bodyPlaceholders.put("{{scenario}}",emailLogRequest.getEmailType().getValue());
|
bodyPlaceholders.put("{{scenario}}",emailLogEntity.getEmailType());
|
||||||
bodyPlaceholders.put("{{call_name}}", call.getName());
|
bodyPlaceholders.put("{{call_name}}", call.getName());
|
||||||
bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString());
|
bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString());
|
||||||
bodyPlaceholders.put("{{company_name}}", company.getCompanyName());
|
bodyPlaceholders.put("{{company_name}}", company.getCompanyName());
|
||||||
@@ -2476,15 +2481,16 @@ public class ApplicationDao {
|
|||||||
protocolNumber= String.valueOf(applicationEntity.getProtocol().getProtocolNumber());
|
protocolNumber= String.valueOf(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
}
|
}
|
||||||
bodyPlaceholders.put("{{protocol_number}}", protocolNumber);
|
bodyPlaceholders.put("{{protocol_number}}", protocolNumber);
|
||||||
bodyPlaceholders.put("{{user_action_id}}",emailLogRequest.getUserActionId().toString());
|
bodyPlaceholders.put("{{user_action_id}}",emailLogEntity.getUserAction().getId().toString());
|
||||||
|
|
||||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||||
|
|
||||||
emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,user.getEmail(),user.getId(),applicationEntity.getId(),null,callId);
|
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,user.getEmail(),user.getId(),applicationEntity.getId(),null,callId,subject,body);
|
||||||
|
|
||||||
emailLogRequest.setRecipientEmails(GepafinConstant.RINALDO_EMAIL);
|
emailLogRequest.setRecipientEmails(GepafinConstant.RINALDO_EMAIL);
|
||||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest);
|
EmailLogEntity newEmailLogEntity=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),newEmailLogEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] downloadRankingCsv(Long callId,UserEntity userEntity) {
|
public byte[] downloadRankingCsv(Long callId,UserEntity userEntity) {
|
||||||
|
|||||||
@@ -73,8 +73,9 @@ public class EmailDao {
|
|||||||
log.getUserId(),
|
log.getUserId(),
|
||||||
log.getApplicationId(),
|
log.getApplicationId(),
|
||||||
log.getAmendmentId(),
|
log.getAmendmentId(),
|
||||||
log.getCallId()
|
log.getCallId(),log.getEmailSubject(),log.getEmailBody()
|
||||||
);
|
);
|
||||||
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,Utils.convertJsonStringToList(log.getAttachments(),String.class));
|
||||||
|
|
||||||
List<String> recipients = Utils.commaSeparatedStringToList(log.getRecipientEmails());
|
List<String> recipients = Utils.commaSeparatedStringToList(log.getRecipientEmails());
|
||||||
CallEntity call = callService.validateCall(log.getCallId());
|
CallEntity call = callService.validateCall(log.getCallId());
|
||||||
@@ -83,7 +84,7 @@ public class EmailDao {
|
|||||||
log.getEmailSubject(),
|
log.getEmailSubject(),
|
||||||
log.getEmailBody(),
|
log.getEmailBody(),
|
||||||
recipients,
|
recipients,
|
||||||
emailLogRequest
|
emailLogEntity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
EmailSendResponse emailSendResponse = buildEmailSendResponseFromRequest(request);
|
EmailSendResponse emailSendResponse = buildEmailSendResponseFromRequest(request);
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
|||||||
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
|
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
|
||||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class EmailLogDao {
|
public class EmailLogDao {
|
||||||
@@ -28,7 +30,7 @@ public class EmailLogDao {
|
|||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
|
|
||||||
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest) {
|
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest,List<String> attachments) {
|
||||||
|
|
||||||
EmailLogEntity emailLogEntity = new EmailLogEntity();
|
EmailLogEntity emailLogEntity = new EmailLogEntity();
|
||||||
emailLogEntity.setEmailType(emailLogRequest.getEmailType().getValue());
|
emailLogEntity.setEmailType(emailLogRequest.getEmailType().getValue());
|
||||||
@@ -37,17 +39,17 @@ public class EmailLogDao {
|
|||||||
emailLogEntity.setEmailSubject(emailLogRequest.getEmailSubject());
|
emailLogEntity.setEmailSubject(emailLogRequest.getEmailSubject());
|
||||||
emailLogEntity.setEmailBody(emailLogRequest.getEmailBody());
|
emailLogEntity.setEmailBody(emailLogRequest.getEmailBody());
|
||||||
emailLogEntity.setSendStatus(emailLogRequest.getSendStatus());
|
emailLogEntity.setSendStatus(emailLogRequest.getSendStatus());
|
||||||
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); // Set to now if null
|
|
||||||
emailLogEntity.setErrorMessage(emailLogRequest.getErrorMessage());
|
emailLogEntity.setErrorMessage(emailLogRequest.getErrorMessage());
|
||||||
emailLogEntity.setUserId(emailLogRequest.getUserId());
|
emailLogEntity.setUserId(emailLogRequest.getUserId());
|
||||||
emailLogEntity.setEmailServiceResponse(emailLogRequest.getEmailServiceResponse());
|
emailLogEntity.setEmailServiceResponse(emailLogRequest.getEmailServiceResponse());
|
||||||
emailLogEntity.setRecipientEmails(emailLogRequest.getRecipientEmails());
|
emailLogEntity.setRecipientEmails(emailLogRequest.getRecipientEmails());
|
||||||
emailLogEntity.setEmailServiceType(emailLogRequest.getEmailServiceType().getValue());
|
|
||||||
emailLogEntity.setIsDeleted(false);
|
emailLogEntity.setIsDeleted(false);
|
||||||
emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId());
|
emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId());
|
||||||
emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId());
|
emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId());
|
||||||
emailLogEntity.setCallId(emailLogRequest.getCallId());
|
emailLogEntity.setCallId(emailLogRequest.getCallId());
|
||||||
emailLogEntity.setUserAction(loggingUtil.getUserActionLogById(emailLogRequest.getUserActionId()));
|
emailLogEntity.setUserAction(loggingUtil.getUserActionLogById(emailLogRequest.getUserActionId()));
|
||||||
|
emailLogEntity.setSendStatus(StatusTypeEnum.PENDING.getValue());
|
||||||
|
emailLogEntity.setAttachments(Utils.convertListToJsonString(attachments));
|
||||||
emailLogEntity = saveEmailLogEntity(emailLogEntity);
|
emailLogEntity = saveEmailLogEntity(emailLogEntity);
|
||||||
return emailLogEntity;
|
return emailLogEntity;
|
||||||
}
|
}
|
||||||
@@ -55,7 +57,7 @@ public class EmailLogDao {
|
|||||||
return emailLogRepository.save(emailLogEntity);
|
return emailLogRepository.save(emailLogEntity);
|
||||||
}
|
}
|
||||||
public EmailLogRequest createEmailLogRequest(EmailScenarioTypeEnum emailType, RecipientTypeEnum recipientType, Long recipientId,
|
public EmailLogRequest createEmailLogRequest(EmailScenarioTypeEnum emailType, RecipientTypeEnum recipientType, Long recipientId,
|
||||||
String recipientEmails, Long userId,Long applicationId,Long amendmentId,Long callId) {
|
String recipientEmails, Long userId, Long applicationId, Long amendmentId, Long callId, String subject, String body) {
|
||||||
EmailLogRequest emailLogRequest = new EmailLogRequest();
|
EmailLogRequest emailLogRequest = new EmailLogRequest();
|
||||||
Long userActionId =(Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
|
Long userActionId =(Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
|
||||||
emailLogRequest.setEmailType(emailType);
|
emailLogRequest.setEmailType(emailType);
|
||||||
@@ -67,6 +69,8 @@ public class EmailLogDao {
|
|||||||
emailLogRequest.setAmendmentId(amendmentId);
|
emailLogRequest.setAmendmentId(amendmentId);
|
||||||
emailLogRequest.setCallId(callId);
|
emailLogRequest.setCallId(callId);
|
||||||
emailLogRequest.setUserActionId(userActionId);
|
emailLogRequest.setUserActionId(userActionId);
|
||||||
|
emailLogRequest.setEmailSubject(subject);
|
||||||
|
emailLogRequest.setEmailBody(body);
|
||||||
return emailLogRequest;
|
return emailLogRequest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,23 +143,9 @@ public class EmailNotificationDao {
|
|||||||
applicationAmendmentRequest = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
|
applicationAmendmentRequest = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
|
||||||
}
|
}
|
||||||
List<AttachmentRequest> attachmentRequests =new ArrayList<>();
|
List<AttachmentRequest> attachmentRequests =new ArrayList<>();
|
||||||
S3DocxProcessor processor = new S3DocxProcessor(s3Client);
|
|
||||||
List<String> urls=new ArrayList<>();
|
List<String> urls=new ArrayList<>();
|
||||||
Map<String, String> replacements=new HashMap<>();
|
|
||||||
List<DocumentEntity> documentEntities=new ArrayList<>();
|
List<DocumentEntity> documentEntities=new ArrayList<>();
|
||||||
if(systemEmailTemplateResponse.getEmailScenario().equals(EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED)) {
|
if(systemEmailTemplateResponse.getEmailScenario().equals(EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED)) {
|
||||||
String amount=Utils.convertToItalianFormat(String.valueOf(applicationEntity.getAmountAccepted()));
|
|
||||||
String protocolNumber=applicationEntity.getProtocol().getExternalProtocolNumber();
|
|
||||||
if(protocolNumber==null){
|
|
||||||
protocolNumber= String.valueOf(applicationEntity.getProtocol().getProtocolNumber());
|
|
||||||
}
|
|
||||||
replacements = Map.of(
|
|
||||||
"{call_name}", applicationEntity.getCall().getName(),
|
|
||||||
"{amount_accepted}", amount,
|
|
||||||
"{pec}", "bandi.gepafin@legalmail.it",
|
|
||||||
"{company_name}", company.getCompanyName(),
|
|
||||||
"{protocol_number}", protocolNumber
|
|
||||||
);
|
|
||||||
if(Boolean.TRUE.equals(AmendmentDocumentTypeEnum.ALTRE_GARANZIE.getValue().equals(applicationAmendmentRequest.getAmendmentDocumentType()))){
|
if(Boolean.TRUE.equals(AmendmentDocumentTypeEnum.ALTRE_GARANZIE.getValue().equals(applicationAmendmentRequest.getAmendmentDocumentType()))){
|
||||||
documentEntities=documentRepository.findBySourceInAndIsDeletedFalse(List.of(applicationAmendmentRequest.getAmendmentDocumentType(),"MODELLO_AUTOCERTIFICAZIONE","MODELLO_PRIVACY"));
|
documentEntities=documentRepository.findBySourceInAndIsDeletedFalse(List.of(applicationAmendmentRequest.getAmendmentDocumentType(),"MODELLO_AUTOCERTIFICAZIONE","MODELLO_PRIVACY"));
|
||||||
}else {
|
}else {
|
||||||
@@ -192,20 +178,7 @@ public class EmailNotificationDao {
|
|||||||
urls = documentEntities.stream()
|
urls = documentEntities.stream()
|
||||||
.map(DocumentEntity::getFilePath) // or getUrl()
|
.map(DocumentEntity::getFilePath) // or getUrl()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if(Boolean.FALSE.equals(urls.isEmpty())) {
|
|
||||||
Map<String, AttachmentRequest> processedFiles = null;
|
|
||||||
try {
|
|
||||||
processedFiles = processor.processFiles(urls, replacements);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, AttachmentRequest> entry : processedFiles.entrySet()) {
|
|
||||||
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
|
||||||
attachmentRequest.setName(entry.getKey()); // e.g. "path/file1.docx"
|
|
||||||
attachmentRequest.setFile(entry.getValue().getFile()); // updated file content
|
|
||||||
attachmentRequests.add(attachmentRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
||||||
String companyEmail = userWithCompany.getEmail();
|
String companyEmail = userWithCompany.getEmail();
|
||||||
String contactEmail = userWithCompany.getContactEmail();
|
String contactEmail = userWithCompany.getContactEmail();
|
||||||
@@ -217,22 +190,25 @@ public class EmailNotificationDao {
|
|||||||
recipientEmails.add(userWithCompany.getPec());
|
recipientEmails.add(userWithCompany.getPec());
|
||||||
}
|
}
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() ,
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY,company.getId() ,
|
||||||
String.valueOf(recipientEmails), userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
String.valueOf(recipientEmails), userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails, emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails, emailLogEntity);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY, company.getId(),
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY, company.getId(),
|
||||||
companyEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
companyEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(companyEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(companyEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY, company.getId(),
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.COMPANY, company.getId(),
|
||||||
contactEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
contactEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(contactEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(contactEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,16 +222,18 @@ public class EmailNotificationDao {
|
|||||||
beneficiaryEmail=userEntity.getBeneficiary().getEmail();
|
beneficiaryEmail=userEntity.getBeneficiary().getEmail();
|
||||||
}
|
}
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), recipientTypeEnum,userEntity.getBeneficiary().getId() ,
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), recipientTypeEnum,userEntity.getBeneficiary().getId() ,
|
||||||
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(beneficiaryEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(beneficiaryEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(userEntity.getHub().getUniqueUuid().equals(defaultHubUuid)) && userEntity.getBeneficiary() != null) {
|
if (Boolean.TRUE.equals(userEntity.getHub().getUniqueUuid().equals(defaultHubUuid)) && userEntity.getBeneficiary() != null) {
|
||||||
String beneficiaryEmail = userEntity.getBeneficiary().getEmail();
|
String beneficiaryEmail = userEntity.getBeneficiary().getEmail();
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY, userEntity.getBeneficiary().getId(),
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY, userEntity.getBeneficiary().getId(),
|
||||||
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(beneficiaryEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(beneficiaryEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
if(userEntity.getHub().getEmail() != null){
|
if(userEntity.getHub().getEmail() != null){
|
||||||
String hubEmails = userEntity.getHub().getEmail();
|
String hubEmails = userEntity.getHub().getEmail();
|
||||||
@@ -264,19 +242,21 @@ public class EmailNotificationDao {
|
|||||||
hubEmail = hubEmail.trim();
|
hubEmail = hubEmail.trim();
|
||||||
if (!hubEmail.isEmpty()) {
|
if (!hubEmail.isEmpty()) {
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null,
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null,
|
||||||
hubEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
hubEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(hubEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(hubEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GepafinConstant.RINALDO_EMAIL.equals(rinaldoEmail)) {
|
if (GepafinConstant.RINALDO_EMAIL.equals(rinaldoEmail)) {
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null ,
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null ,
|
||||||
rinaldoEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
rinaldoEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
|
|
||||||
//SMTP
|
//SMTP
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(null, subject, body, List.of(rinaldoEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(null, subject, body, List.of(rinaldoEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
if (applicationEvaluationEntity.isPresent()) {
|
if (applicationEvaluationEntity.isPresent()) {
|
||||||
Long preInstructorId = applicationEvaluationEntity.get().getUserId(); // Assuming UserEntity has an email field
|
Long preInstructorId = applicationEvaluationEntity.get().getUserId(); // Assuming UserEntity has an email field
|
||||||
@@ -284,9 +264,10 @@ public class EmailNotificationDao {
|
|||||||
String preInstructorEmail = instructorUser.getEmail();
|
String preInstructorEmail = instructorUser.getEmail();
|
||||||
if (preInstructorEmail != null && !preInstructorEmail.isEmpty()) {
|
if (preInstructorEmail != null && !preInstructorEmail.isEmpty()) {
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.INSTRUCTOR, instructorUser.getId(),
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.INSTRUCTOR, instructorUser.getId(),
|
||||||
preInstructorEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
preInstructorEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||||
emailLogRequest.setAttachments(attachmentRequests);
|
emailLogRequest.setAttachments(attachmentRequests);
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, List.of(preInstructorEmail), emailLogRequest);
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, List.of(preInstructorEmail), emailLogEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -435,18 +416,31 @@ public class EmailNotificationDao {
|
|||||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null,null,emailType);
|
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null,null,emailType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMail(Long hubId, String subject, String body, List<String> recipientEmails, EmailLogRequest emailLogRequest) {
|
public void sendMail(Long hubId, String subject, String body, List<String> recipientEmails, EmailLogEntity emailLogEntity) {
|
||||||
|
|
||||||
EmailConfig emailConfig = new EmailConfig();
|
EmailConfig emailConfig = new EmailConfig();
|
||||||
|
Boolean isSendEmail=Boolean.TRUE;
|
||||||
|
|
||||||
|
HubEntity hubEntity = hubRepository.findById(hubId).orElseThrow(() -> new IllegalArgumentException("Invalid Hub ID: " + hubId));
|
||||||
|
if(Boolean.TRUE.equals(hubEntity.getUniqueUuid().equals(defaultHubUuid))){
|
||||||
|
if(Boolean.FALSE.equals(emailLogEntity.getEmailType().equals(EmailScenarioTypeEnum.USER_CREATION.getValue()))
|
||||||
|
|| Boolean.FALSE.equals(emailLogEntity.getEmailType().equals(EmailScenarioTypeEnum.APPLICATION_AMENDMENT_REMINDER.getValue()))
|
||||||
|
|| Boolean.FALSE.equals(emailLogEntity.getEmailType().equals(EmailScenarioTypeEnum.APPLICATION_SUBMITTED.getValue()))
|
||||||
|
|| Boolean.FALSE.equals(emailLogEntity.getEmailType().equals(EmailScenarioTypeEnum.PASSWORD_RESET_REQUEST.getValue()))) {
|
||||||
|
isSendEmail = Boolean.FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (recipientEmails.stream().anyMatch(email -> email.equals(GepafinConstant.RINALDO_EMAIL))) {
|
if (recipientEmails.stream().anyMatch(email -> email.equals(GepafinConstant.RINALDO_EMAIL))) {
|
||||||
|
|
||||||
emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||||
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
||||||
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
|
emailService.sendEmail(subject, body, recipientEmails, emailConfig,emailLogEntity,isSendEmail);
|
||||||
} else {
|
} else {
|
||||||
emailConfig = retrieveEmailConfig(hubId);
|
emailConfig = retrieveEmailConfig(hubId);
|
||||||
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
||||||
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
|
emailService.sendEmail(subject, body, recipientEmails, emailConfig,emailLogEntity,isSendEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmailConfig retrieveEmailConfig(Long hubId) {
|
public EmailConfig retrieveEmailConfig(Long hubId) {
|
||||||
@@ -554,4 +548,19 @@ public class EmailNotificationDao {
|
|||||||
EmailContentResponse emailContentResponse= new EmailContentResponse(subject, body, systemEmailTemplateResponse);
|
EmailContentResponse emailContentResponse= new EmailContentResponse(subject, body, systemEmailTemplateResponse);
|
||||||
sendEmails(applicationEntity, user, null,null,emailContentResponse.getSystemEmailTemplateResponse(),emailContentResponse.getSubject(),emailContentResponse.getBody(),applicationContractEntity.getId());
|
sendEmails(applicationEntity, user, null,null,emailContentResponse.getSystemEmailTemplateResponse(),emailContentResponse.getSubject(),emailContentResponse.getBody(),applicationContractEntity.getId());
|
||||||
}
|
}
|
||||||
|
public void sendPendingMail(Long hubId, String subject, String body, List<String> recipientEmails, EmailLogEntity emailLogEntity) {
|
||||||
|
|
||||||
|
EmailConfig emailConfig = new EmailConfig();
|
||||||
|
if (recipientEmails.stream().anyMatch(email -> email.equals(GepafinConstant.RINALDO_EMAIL))) {
|
||||||
|
|
||||||
|
emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||||
|
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
||||||
|
emailService.sendEmail(subject, body, recipientEmails, emailConfig,emailLogEntity,true);
|
||||||
|
} else {
|
||||||
|
emailConfig = retrieveEmailConfig(hubId);
|
||||||
|
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
||||||
|
emailService.sendEmail(subject, body, recipientEmails, emailConfig,emailLogEntity,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -50,24 +50,28 @@ public class PecMailDao {
|
|||||||
private ApplicationService applicationService;
|
private ApplicationService applicationService;
|
||||||
|
|
||||||
|
|
||||||
public PecMailResponse sendPecMail(HttpServletRequest request, List<Long> userActionIds) {
|
public List<PecMailResponse> sendPecMail(HttpServletRequest request, List<Long> userActionIds) {
|
||||||
|
|
||||||
|
List<PecMailResponse> pecMailResponses=new ArrayList<>();
|
||||||
for (Long userActionId: userActionIds) {
|
for (Long userActionId: userActionIds) {
|
||||||
List<EmailLogEntity> emailLogs = getEmailLogEntities(request, userActionId);
|
List<EmailLogEntity> emailLogs = getEmailLogEntities(request, userActionId);
|
||||||
for (EmailLogEntity log : emailLogs) {
|
for (EmailLogEntity log : emailLogs) {
|
||||||
List<String> recipients = Utils.commaSeparatedStringToList(log.getRecipientEmails());
|
List<String> recipients = Utils.commaSeparatedStringToList(log.getRecipientEmails());
|
||||||
CallEntity call = callService.validateCall(log.getCallId());
|
CallEntity call = callService.validateCall(log.getCallId());
|
||||||
emailNotificationDao.sendMail(
|
emailNotificationDao.sendPendingMail(
|
||||||
call.getHub().getId(),
|
call.getHub().getId(),
|
||||||
log.getEmailSubject(),
|
log.getEmailSubject(),
|
||||||
log.getEmailBody(),
|
log.getEmailBody(),
|
||||||
recipients,
|
recipients,
|
||||||
null
|
log
|
||||||
);
|
);
|
||||||
|
ApplicationEntity applicationEntity=applicationService.validateApplication(log.getApplicationId());
|
||||||
|
String callName=applicationEntity.getCall().getName();
|
||||||
|
PecMailResponse pecMailResponse=createPecMailResponse(log.getUserAction().getId(),log,callName);
|
||||||
|
pecMailResponses.add(pecMailResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return pecMailResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<EmailLogEntity> getEmailLogEntities(HttpServletRequest request, Long userActionId) {
|
private List<EmailLogEntity> getEmailLogEntities(HttpServletRequest request, Long userActionId) {
|
||||||
@@ -77,7 +81,7 @@ public class PecMailDao {
|
|||||||
}
|
}
|
||||||
validator.validateHubId(request, userActionEntity.getHubId());
|
validator.validateHubId(request, userActionEntity.getHubId());
|
||||||
|
|
||||||
List<EmailLogEntity> emailLogs = emailLogRepository.findByUserActionIdAndEmailServiceTypeAndSendStatus(userActionId, EmailServiceTypeEnum.PEC_SERVICE.getValue(), StatusTypeEnum.PENDING.getValue());
|
List<EmailLogEntity> emailLogs = emailLogRepository.findByUserActionIdAndSendStatusAndIsDeletedFalse(userActionId,StatusTypeEnum.PENDING.getValue());
|
||||||
|
|
||||||
if (emailLogs.isEmpty()) {
|
if (emailLogs.isEmpty()) {
|
||||||
log.info("No emails found for given userActionId: {}", userActionId);
|
log.info("No emails found for given userActionId: {}", userActionId);
|
||||||
|
|||||||
@@ -192,19 +192,19 @@ public class UserDao {
|
|||||||
: SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING_BANDI;
|
: SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING_BANDI;
|
||||||
|
|
||||||
emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, userEntity.getHub(), null);
|
emailTemplate = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, userEntity.getHub(), null);
|
||||||
|
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, userEntity.getId(), userEntity.getEmail(),
|
|
||||||
userEntity.getId(), null, null, null);
|
|
||||||
|
|
||||||
Map<String, String> placeholders = replacePlaceholders(userEntity, userReq);
|
Map<String, String> placeholders = replacePlaceholders(userEntity, userReq);
|
||||||
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), placeholders);
|
String body = Utils.replacePlaceholders(emailTemplate.getHtmlContent(), placeholders);
|
||||||
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, userEntity.getId(), userEntity.getEmail(),
|
||||||
|
userEntity.getId(), null, null, null,emailTemplate.getSubject(),body);
|
||||||
|
|
||||||
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
|
|
||||||
emailNotificationDao.sendMail(
|
emailNotificationDao.sendMail(
|
||||||
userEntity.getHub().getId(),
|
userEntity.getHub().getId(),
|
||||||
emailTemplate.getSubject(),
|
emailTemplate.getSubject(),
|
||||||
body,
|
body,
|
||||||
List.of(userEntity.getEmail()),
|
List.of(userEntity.getEmail()),
|
||||||
emailLogRequest
|
emailLogEntity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,15 +545,7 @@ public class UserDao {
|
|||||||
redirectUrl = user.getHub().getDomainName();
|
redirectUrl = user.getHub().getDomainName();
|
||||||
}
|
}
|
||||||
|
|
||||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(
|
|
||||||
emailTemplate.getEmailScenario(),
|
|
||||||
RecipientTypeEnum.USER,
|
|
||||||
user.getId(),
|
|
||||||
user.getEmail(),
|
|
||||||
user.getId(),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
redirectUrl = String.format(
|
redirectUrl = String.format(
|
||||||
user.getHub().getDomainName() + GepafinConstant.RESET_PASSWORD_URL_FORMAT,
|
user.getHub().getDomainName() + GepafinConstant.RESET_PASSWORD_URL_FORMAT,
|
||||||
token,
|
token,
|
||||||
@@ -569,12 +561,22 @@ public class UserDao {
|
|||||||
"{{user_name}}", userName,
|
"{{user_name}}", userName,
|
||||||
"{{reset_password_link}}", redirectUrl
|
"{{reset_password_link}}", redirectUrl
|
||||||
));
|
));
|
||||||
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(
|
||||||
|
emailTemplate.getEmailScenario(),
|
||||||
|
RecipientTypeEnum.USER,
|
||||||
|
user.getId(),
|
||||||
|
user.getEmail(),
|
||||||
|
user.getId(),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,subject,body);
|
||||||
|
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||||
emailNotificationDao.sendMail(
|
emailNotificationDao.sendMail(
|
||||||
user.getHub().getId(),
|
user.getHub().getId(),
|
||||||
subject,
|
subject,
|
||||||
body,
|
body,
|
||||||
List.of(user.getEmail()),
|
List.of(user.getEmail()),
|
||||||
emailLogRequest
|
emailLogEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
log.info("Password reset token email sent to: {}", user.getEmail());
|
log.info("Password reset token email sent to: {}", user.getEmail());
|
||||||
|
|||||||
@@ -59,5 +59,8 @@ public class EmailLogEntity extends BaseEntity{
|
|||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "user_action_id")
|
@JoinColumn(name = "user_action_id")
|
||||||
private UserActionEntity userAction;
|
private UserActionEntity userAction;
|
||||||
|
|
||||||
|
@Column(name = "ATTACHMENTS")
|
||||||
|
private String attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,11 @@ public interface EmailLogRepository extends JpaRepository<EmailLogEntity,Long> {
|
|||||||
String sendStatus
|
String sendStatus
|
||||||
);
|
);
|
||||||
|
|
||||||
|
List<EmailLogEntity> findByUserActionIdAndSendStatusAndIsDeletedFalse(Long userActionId,String status);
|
||||||
|
|
||||||
|
|
||||||
@Query(value = """
|
@Query(value = """
|
||||||
SELECT DISTINCT ON (user_action_id) * FROM email_log WHERE send_status = 'PENDING' AND is_deleted = false AND email_service_type = 'PEC_SERVICE' """, nativeQuery = true)
|
SELECT DISTINCT ON (user_action_id) * FROM gepafin_schema.email_log WHERE send_status = 'PENDING' AND is_deleted = false""", nativeQuery = true)
|
||||||
List<EmailLogEntity> findPendingPECEmailLogs();
|
List<EmailLogEntity> findPendingPECEmailLogs();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface PecMailService {
|
public interface PecMailService {
|
||||||
|
|
||||||
public PecMailResponse sendPecMail(HttpServletRequest request, List<Long> userActionIds);
|
public List<PecMailResponse> sendPecMail(HttpServletRequest request, List<Long> userActionIds);
|
||||||
|
|
||||||
public List<PecEmailLogResponse> getEmailLogByUserActionId(HttpServletRequest request, Long userActionId);
|
public List<PecEmailLogResponse> getEmailLogByUserActionId(HttpServletRequest request, Long userActionId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package net.gepafin.tendermanagement.service.impl;
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface EmailService {
|
public interface EmailService {
|
||||||
void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest);
|
void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogEntity emailLogEntity,Boolean isSendEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
|||||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||||
|
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.util.Validator;
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -30,8 +33,11 @@ public class MailgunEmailService implements EmailService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmailLogDao emailLogDao;
|
private EmailLogDao emailLogDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmailLogRepository emailLogRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) {
|
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogEntity emailLogEntity,Boolean isSendEmail) {
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
||||||
return;
|
return;
|
||||||
@@ -45,10 +51,8 @@ public class MailgunEmailService implements EmailService {
|
|||||||
// Send email via Mailgun API
|
// Send email via Mailgun API
|
||||||
HttpResponse<String> response2=null;
|
HttpResponse<String> response2=null;
|
||||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||||
emailLogRequest.setEmailSubject(subject);
|
emailLogEntity.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||||
emailLogRequest.setEmailBody(body);
|
emailLogEntity.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
|
||||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
|
||||||
try {
|
try {
|
||||||
Unirest.setTimeouts(0, 0);
|
Unirest.setTimeouts(0, 0);
|
||||||
response2 = Unirest.post(url)
|
response2 = Unirest.post(url)
|
||||||
@@ -60,16 +64,17 @@ public class MailgunEmailService implements EmailService {
|
|||||||
.field("html", body)
|
.field("html", body)
|
||||||
.asString();
|
.asString();
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE.getValue());
|
||||||
emailLogRequest.setErrorMessage(e.getMessage());
|
emailLogEntity.setErrorMessage(e.getMessage());
|
||||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
emailLogRepository.save(emailLogEntity);
|
||||||
throw new RuntimeException("Failed to send email via Mailgun: " + response2.getStatus());
|
throw new RuntimeException("Failed to send email via Mailgun: " + response2.getStatus());
|
||||||
}
|
}
|
||||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
emailLogEntity.setEmailServiceResponse(response2.getBody());
|
||||||
}
|
}
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE.getValue());
|
||||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
emailLogRepository.save(emailLogEntity);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.gepafin.tendermanagement.service.impl;
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import com.amazonaws.services.s3.AmazonS3Client;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.mashape.unirest.http.HttpResponse;
|
import com.mashape.unirest.http.HttpResponse;
|
||||||
@@ -9,14 +10,18 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
|
|||||||
import net.gepafin.tendermanagement.dao.ApplicationDao;
|
import net.gepafin.tendermanagement.dao.ApplicationDao;
|
||||||
import net.gepafin.tendermanagement.dao.EmailLogDao;
|
import net.gepafin.tendermanagement.dao.EmailLogDao;
|
||||||
import net.gepafin.tendermanagement.dao.NotificationDao;
|
import net.gepafin.tendermanagement.dao.NotificationDao;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||||
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
|
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
import net.gepafin.tendermanagement.model.request.*;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
import net.gepafin.tendermanagement.service.CompanyService;
|
||||||
import net.gepafin.tendermanagement.model.request.PecEmailRequest;
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.S3DocxProcessor;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.util.Validator;
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
|
|
||||||
@@ -25,6 +30,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -51,29 +59,71 @@ public class PecEmailService implements EmailService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationDao applicationDao;
|
private ApplicationDao applicationDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Client s3Client;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmailLogRepository emailLogRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) {
|
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogEntity emailLogEntity, Boolean isSendEmail) {
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(Boolean.TRUE.equals(isSendEmail)) {
|
||||||
|
Map<String, String> replacements=new HashMap<>();
|
||||||
|
List<AttachmentRequest> attachmentRequests =new ArrayList<>();
|
||||||
|
S3DocxProcessor processor = new S3DocxProcessor(s3Client);
|
||||||
|
List<String> urls = Utils.convertJsonStringToList(emailLogEntity.getAttachments(), String.class);
|
||||||
|
|
||||||
|
if(emailLogEntity.getEmailType().equals(EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED.getValue())) {
|
||||||
|
ApplicationEntity applicationEntity = applicationDao.validateApplication(emailLogEntity.getApplicationId());
|
||||||
|
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
|
String amount = Utils.convertToItalianFormat(String.valueOf(applicationEntity.getAmountAccepted()));
|
||||||
|
String protocolNumber = applicationEntity.getProtocol().getExternalProtocolNumber();
|
||||||
|
if (protocolNumber == null) {
|
||||||
|
protocolNumber = String.valueOf(applicationEntity.getProtocol().getProtocolNumber());
|
||||||
|
}
|
||||||
|
replacements = Map.of(
|
||||||
|
"{call_name}", applicationEntity.getCall().getName(),
|
||||||
|
"{amount_accepted}", amount,
|
||||||
|
"{pec}", "bandi.gepafin@legalmail.it",
|
||||||
|
"{company_name}", company.getCompanyName(),
|
||||||
|
"{protocol_number}", protocolNumber
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (urls!=null && Boolean.FALSE.equals(urls.isEmpty())) {
|
||||||
|
Map<String, AttachmentRequest> processedFiles = null;
|
||||||
|
try {
|
||||||
|
processedFiles = processor.processFiles(urls, replacements);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, AttachmentRequest> entry : processedFiles.entrySet()) {
|
||||||
|
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
||||||
|
attachmentRequest.setName(entry.getKey()); // e.g. "path/file1.docx"
|
||||||
|
attachmentRequest.setFile(entry.getValue().getFile()); // updated file content
|
||||||
|
attachmentRequests.add(attachmentRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
PecEmailRequest emailRequest = new PecEmailRequest();
|
PecEmailRequest emailRequest = new PecEmailRequest();
|
||||||
emailRequest.setSender(emailConfig.getSender());
|
emailRequest.setSender(emailConfig.getSender());
|
||||||
emailRequest.setSubject(subject);
|
emailRequest.setSubject(subject);
|
||||||
emailRequest.setBody(body);
|
emailRequest.setBody(body);
|
||||||
emailRequest.setUsername(emailConfig.getUsername());
|
emailRequest.setUsername(emailConfig.getUsername());
|
||||||
emailRequest.setPassword(emailConfig.getPassword());
|
emailRequest.setPassword(emailConfig.getPassword());
|
||||||
emailRequest.setAttachments(emailLogRequest.getAttachments());
|
emailRequest.setAttachments(attachmentRequests);
|
||||||
emailRequest.setRecipient(recipientEmails);
|
emailRequest.setRecipient(recipientEmails);
|
||||||
String url=emailConfig.getUrl()+ GepafinConstant.PEC_SERVICE_SEND_MAIL;
|
String url = emailConfig.getUrl() + GepafinConstant.PEC_SERVICE_SEND_MAIL;
|
||||||
String authToken = emailConfig.getAuthToken();
|
String authToken = emailConfig.getAuthToken();
|
||||||
HttpResponse<String> response2=null;
|
HttpResponse<String> response2 = null;
|
||||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||||
emailLogRequest.setEmailSubject(emailRequest.getSubject());
|
emailLogEntity.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||||
emailLogRequest.setEmailBody(emailRequest.getBody());
|
emailLogEntity.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient()));
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
|
||||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient()));
|
|
||||||
try {
|
try {
|
||||||
if (Boolean.TRUE.equals(Boolean.parseBoolean(isPecServiceEnabled))) {
|
if (Boolean.TRUE.equals(Boolean.parseBoolean(isPecServiceEnabled))) {
|
||||||
Unirest.setTimeouts(0, 0);
|
Unirest.setTimeouts(0, 0);
|
||||||
@@ -85,31 +135,33 @@ public class PecEmailService implements EmailService {
|
|||||||
|
|
||||||
if (!isSuccessfulPecResponse(response2.getBody())) {
|
if (!isSuccessfulPecResponse(response2.getBody())) {
|
||||||
String errorMsg = "PEC sending failed: " + response2.getBody();
|
String errorMsg = "PEC sending failed: " + response2.getBody();
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE.getValue());
|
||||||
emailLogRequest.setErrorMessage(errorMsg);
|
emailLogEntity.setErrorMessage(errorMsg);
|
||||||
sendNotificationOnFailure(emailLogRequest.getUserId(),emailLogRequest.getEmailType());
|
sendNotificationOnFailure(emailLogEntity.getUserId(), EmailScenarioTypeEnum.valueOf(emailLogEntity.getEmailType()));
|
||||||
|
|
||||||
if (EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED.equals(emailLogRequest.getEmailType())) {
|
if (EmailScenarioTypeEnum.APPLICATION_SUBMITTED.getValue().equals(emailLogEntity.getEmailType())) {
|
||||||
applicationDao.sendApplicationSubmissionFailureEmail(emailLogRequest);
|
applicationDao.sendApplicationSubmissionFailureEmail(emailLogEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(Exception e) {
|
} catch (Exception e) {
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE.getValue());
|
||||||
emailLogRequest.setErrorMessage(e.getMessage());
|
emailLogEntity.setErrorMessage(e.getMessage());
|
||||||
sendNotificationOnFailure(emailLogRequest.getUserId(),emailLogRequest.getEmailType());
|
sendNotificationOnFailure(emailLogEntity.getUserId(), EmailScenarioTypeEnum.valueOf(emailLogEntity.getEmailType()));
|
||||||
if (EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED.equals(emailLogRequest.getEmailType())) {
|
if (EmailScenarioTypeEnum.APPLICATION_SUBMITTED.getValue().equals(emailLogEntity.getEmailType())) {
|
||||||
applicationDao.sendApplicationSubmissionFailureEmail(emailLogRequest);
|
applicationDao.sendApplicationSubmissionFailureEmail(emailLogEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(response2 != null) {
|
if (response2 != null) {
|
||||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
emailLogEntity.setEmailServiceResponse(response2.getBody());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
}
|
||||||
emailLogDao.createEmailLog(emailLogRequest);
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE.getValue());
|
||||||
|
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
emailLogRepository.save(emailLogEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotificationOnFailure(Long userId, EmailScenarioTypeEnum emailScenarioTypeEnum) {
|
private void sendNotificationOnFailure(Long userId, EmailScenarioTypeEnum emailScenarioTypeEnum) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class PecMailSerivceImpl implements PecMailService {
|
|||||||
private PecMailDao pecMailDao;
|
private PecMailDao pecMailDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PecMailResponse sendPecMail(HttpServletRequest request, List<Long> userActionIds) {
|
public List<PecMailResponse> sendPecMail(HttpServletRequest request, List<Long> userActionIds) {
|
||||||
return pecMailDao.sendPecMail(request,userActionIds);
|
return pecMailDao.sendPecMail(request,userActionIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
|||||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||||
|
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||||
|
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.util.Validator;
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -43,19 +46,20 @@ public class SystemEmailService implements EmailService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmailLogDao emailLogDao;
|
private EmailLogDao emailLogDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmailLogRepository emailLogRepository;
|
||||||
|
|
||||||
public final Logger log = LoggerFactory.getLogger(SystemEmailService.class);
|
public final Logger log = LoggerFactory.getLogger(SystemEmailService.class);
|
||||||
|
|
||||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) {
|
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogEntity emailLogEntity,Boolean isSendEmail) {
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (Boolean.TRUE.equals(isSendEmail)) {
|
||||||
emailLogRequest.setEmailSubject(subject);
|
emailLogEntity.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||||
emailLogRequest.setEmailBody(body);
|
emailLogEntity.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE);
|
|
||||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||||
MessageResponse response = null;
|
MessageResponse response = null;
|
||||||
try {
|
try {
|
||||||
@@ -66,20 +70,23 @@ public class SystemEmailService implements EmailService {
|
|||||||
|
|
||||||
response = mailgunMessagesApi.sendMessage(mailGunDomainName, message);
|
response = mailgunMessagesApi.sendMessage(mailGunDomainName, message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE);
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||||
emailLogRequest.setErrorMessage(e.getMessage());
|
emailLogEntity.setErrorMessage(e.getMessage());
|
||||||
emailLogDao.createEmailLog(emailLogRequest);
|
emailLogRepository.save(emailLogEntity);
|
||||||
|
|
||||||
throw new RuntimeException("Failed to send email via Mailgun: " + (response != null ? response.getMessage() : "No response from Mailgun"), e);
|
throw new RuntimeException("Failed to send email via Mailgun: " + (response != null ? response.getMessage() : "No response from Mailgun"), e);
|
||||||
}
|
}
|
||||||
if(response != null) {
|
if (response != null) {
|
||||||
emailLogRequest.setEmailServiceResponse(response.toString());
|
emailLogEntity.setEmailServiceResponse(response.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
emailLogDao.createEmailLog(emailLogRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||||
|
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
|
emailLogRepository.save(emailLogEntity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public interface DashboardApi {
|
|||||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
@GetMapping(value = "",
|
@GetMapping(value = "",
|
||||||
produces = { "application/json" })
|
produces = { "application/json" })
|
||||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')")
|
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER') || hasRole('ROLE_DIRECTOR')")
|
||||||
ResponseEntity<Response<SuperAdminWidgetResponseBean>> getDashboardWidgetForSuperAdmin(HttpServletRequest request);
|
ResponseEntity<Response<SuperAdminWidgetResponseBean>> getDashboardWidgetForSuperAdmin(HttpServletRequest request);
|
||||||
|
|
||||||
@Operation(summary = "Api to get dashboard widget for beneficiary",
|
@Operation(summary = "Api to get dashboard widget for beneficiary",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public interface PecMailApi {
|
|||||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
|
||||||
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
|
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
|
||||||
@PostMapping(value = "/userAction", produces = "application/json")
|
@PostMapping(value = "/userAction", produces = "application/json")
|
||||||
ResponseEntity<Response<PecMailResponse>> sendPecMail(HttpServletRequest request,
|
ResponseEntity<Response< List<PecMailResponse>>> sendPecMail(HttpServletRequest request,
|
||||||
@Parameter(description = "The user action id", required = true) @RequestParam("userActionIds") List<Long> userActionIds);
|
@Parameter(description = "The user action id", required = true) @RequestParam("userActionIds") List<Long> userActionIds);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ public class PecMailController implements PecMailApi {
|
|||||||
private PecMailService pecMailService;
|
private PecMailService pecMailService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<PecMailResponse>> sendPecMail(HttpServletRequest request,List<Long> userActionIds) {
|
public ResponseEntity<Response< List<PecMailResponse>>> sendPecMail(HttpServletRequest request,List<Long> userActionIds) {
|
||||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.EMAIL)
|
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.EMAIL)
|
||||||
.actionContext(UserActionContextEnum.SEND_PEC_MAIL).build());
|
.actionContext(UserActionContextEnum.SEND_PEC_MAIL).build());
|
||||||
|
|
||||||
// PecMailResponse pecMailResponse=pecMailService.sendPecMail(request,userActionId);
|
List<PecMailResponse> pecMailResponse=pecMailService.sendPecMail(request,userActionIds);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.MAIL_SENT_SUCCESSFULLY)));
|
.body(new Response<>(pecMailResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.MAIL_SENT_SUCCESSFULLY)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3164,4 +3164,10 @@
|
|||||||
<column name="hub_id" value="1"/>
|
<column name="hub_id" value="1"/>
|
||||||
</insert>
|
</insert>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="10-11-2025_RK_091725" author="Rajesh Khore">
|
||||||
|
<addColumn tableName="email_log">
|
||||||
|
<column name="attachments" type="TEXT"></column>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
Reference in New Issue
Block a user