Done ticket GEPAFINBE-6141
This commit is contained in:
@@ -143,23 +143,9 @@ public class EmailNotificationDao {
|
||||
applicationAmendmentRequest = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
|
||||
}
|
||||
List<AttachmentRequest> attachmentRequests =new ArrayList<>();
|
||||
S3DocxProcessor processor = new S3DocxProcessor(s3Client);
|
||||
List<String> urls=new ArrayList<>();
|
||||
Map<String, String> replacements=new HashMap<>();
|
||||
List<DocumentEntity> documentEntities=new ArrayList<>();
|
||||
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()))){
|
||||
documentEntities=documentRepository.findBySourceInAndIsDeletedFalse(List.of(applicationAmendmentRequest.getAmendmentDocumentType(),"MODELLO_AUTOCERTIFICAZIONE","MODELLO_PRIVACY"));
|
||||
}else {
|
||||
@@ -192,20 +178,7 @@ public class EmailNotificationDao {
|
||||
urls = documentEntities.stream()
|
||||
.map(DocumentEntity::getFilePath) // or getUrl()
|
||||
.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());
|
||||
String companyEmail = userWithCompany.getEmail();
|
||||
String contactEmail = userWithCompany.getContactEmail();
|
||||
@@ -217,22 +190,25 @@ public class EmailNotificationDao {
|
||||
recipientEmails.add(userWithCompany.getPec());
|
||||
}
|
||||
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);
|
||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails, emailLogRequest);
|
||||
EmailLogEntity emailLogEntity=emailLogDao.createEmailLog(emailLogRequest,urls);
|
||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails, emailLogEntity);
|
||||
}
|
||||
else {
|
||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||
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);
|
||||
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)) {
|
||||
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);
|
||||
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();
|
||||
}
|
||||
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);
|
||||
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) {
|
||||
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());
|
||||
beneficiaryEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||
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){
|
||||
String hubEmails = userEntity.getHub().getEmail();
|
||||
@@ -264,19 +242,21 @@ public class EmailNotificationDao {
|
||||
hubEmail = hubEmail.trim();
|
||||
if (!hubEmail.isEmpty()) {
|
||||
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);
|
||||
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)) {
|
||||
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
|
||||
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()) {
|
||||
Long preInstructorId = applicationEvaluationEntity.get().getUserId(); // Assuming UserEntity has an email field
|
||||
@@ -284,9 +264,10 @@ public class EmailNotificationDao {
|
||||
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());
|
||||
preInstructorEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId(),subject,body);
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
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))) {
|
||||
|
||||
emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
||||
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
|
||||
emailService.sendEmail(subject, body, recipientEmails, emailConfig,emailLogEntity,isSendEmail);
|
||||
} else {
|
||||
emailConfig = retrieveEmailConfig(hubId);
|
||||
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) {
|
||||
@@ -554,4 +548,19 @@ public class EmailNotificationDao {
|
||||
EmailContentResponse emailContentResponse= new EmailContentResponse(subject, body, systemEmailTemplateResponse);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user