Merge pull request #369 from Kitzanos/feature/GEPAFINBE-6141
GEPAFINBE-6141 (Created Director profile and managed PEC email handling)
This commit is contained in:
@@ -1295,8 +1295,9 @@ public class ApplicationAmendmentRequestDao {
|
||||
if (Boolean.TRUE.equals(amendment.getIsEmail()) && email != null && !email.isEmpty()) {
|
||||
log.info("Sending reminder email to: {}", email);
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, beneficiaryUser.getId(), email,
|
||||
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId());
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLogRequest);
|
||||
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId(),subject,body);
|
||||
EmailLogEntity emailLog=emailLogDao.createEmailLog(emailLogRequest,null);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLog);
|
||||
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
|
||||
List<EmailSendResponse> responses = List.of(emailSendResponse);
|
||||
if (!Boolean.TRUE.equals(emailSendResponse.getIsEmailSend())){
|
||||
|
||||
@@ -1232,7 +1232,7 @@ public class ApplicationDao {
|
||||
// Replace placeholders in the subject and body
|
||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||
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();
|
||||
if (userEntity.getBeneficiary() != null) {
|
||||
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
||||
@@ -1245,12 +1245,14 @@ public class ApplicationDao {
|
||||
}
|
||||
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) {
|
||||
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
||||
email = userEntity.getBeneficiary().getEmail();
|
||||
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<>();
|
||||
// recipientEmails.add(email);
|
||||
@@ -1277,7 +1279,8 @@ public class ApplicationDao {
|
||||
emailLogRequest.setRecipientType(RecipientTypeEnum.COMPANY);
|
||||
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) {
|
||||
CallEntity call = applicationEntity.getCall();
|
||||
@@ -1319,7 +1322,7 @@ public class ApplicationDao {
|
||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||
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(","))
|
||||
.map(String::trim)
|
||||
@@ -1327,9 +1330,11 @@ public class ApplicationDao {
|
||||
.toList();
|
||||
|
||||
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);
|
||||
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,
|
||||
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);
|
||||
HubEntity hub = call.getHub();
|
||||
Long userId = emailLogRequest.getUserId();
|
||||
Long userId = emailLogEntity.getUserId();
|
||||
UserEntity user = userService.validateUser(userId);
|
||||
Long applicationId = emailLogRequest.getApplicatioId();
|
||||
Long applicationId = emailLogEntity.getApplicationId();
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||
|
||||
@@ -2467,7 +2472,7 @@ public class ApplicationDao {
|
||||
subjectPlaceholders.put("{{call_name}}", call.getName());
|
||||
|
||||
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("{{application_id}}", applicationEntity.getId().toString());
|
||||
bodyPlaceholders.put("{{company_name}}", company.getCompanyName());
|
||||
@@ -2476,15 +2481,16 @@ public class ApplicationDao {
|
||||
protocolNumber= String.valueOf(applicationEntity.getProtocol().getProtocolNumber());
|
||||
}
|
||||
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 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);
|
||||
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) {
|
||||
|
||||
@@ -73,8 +73,9 @@ public class EmailDao {
|
||||
log.getUserId(),
|
||||
log.getApplicationId(),
|
||||
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());
|
||||
CallEntity call = callService.validateCall(log.getCallId());
|
||||
@@ -83,7 +84,7 @@ public class EmailDao {
|
||||
log.getEmailSubject(),
|
||||
log.getEmailBody(),
|
||||
recipients,
|
||||
emailLogRequest
|
||||
emailLogEntity
|
||||
);
|
||||
}
|
||||
EmailSendResponse emailSendResponse = buildEmailSendResponseFromRequest(request);
|
||||
|
||||
@@ -10,10 +10,12 @@ import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class EmailLogDao {
|
||||
@@ -28,7 +30,7 @@ public class EmailLogDao {
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
|
||||
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest) {
|
||||
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest,List<String> attachments) {
|
||||
|
||||
EmailLogEntity emailLogEntity = new EmailLogEntity();
|
||||
emailLogEntity.setEmailType(emailLogRequest.getEmailType().getValue());
|
||||
@@ -37,17 +39,17 @@ public class EmailLogDao {
|
||||
emailLogEntity.setEmailSubject(emailLogRequest.getEmailSubject());
|
||||
emailLogEntity.setEmailBody(emailLogRequest.getEmailBody());
|
||||
emailLogEntity.setSendStatus(emailLogRequest.getSendStatus());
|
||||
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); // Set to now if null
|
||||
emailLogEntity.setErrorMessage(emailLogRequest.getErrorMessage());
|
||||
emailLogEntity.setUserId(emailLogRequest.getUserId());
|
||||
emailLogEntity.setEmailServiceResponse(emailLogRequest.getEmailServiceResponse());
|
||||
emailLogEntity.setRecipientEmails(emailLogRequest.getRecipientEmails());
|
||||
emailLogEntity.setEmailServiceType(emailLogRequest.getEmailServiceType().getValue());
|
||||
emailLogEntity.setIsDeleted(false);
|
||||
emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId());
|
||||
emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId());
|
||||
emailLogEntity.setCallId(emailLogRequest.getCallId());
|
||||
emailLogEntity.setUserAction(loggingUtil.getUserActionLogById(emailLogRequest.getUserActionId()));
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.PENDING.getValue());
|
||||
emailLogEntity.setAttachments(Utils.convertListToJsonString(attachments));
|
||||
emailLogEntity = saveEmailLogEntity(emailLogEntity);
|
||||
return emailLogEntity;
|
||||
}
|
||||
@@ -55,7 +57,7 @@ public class EmailLogDao {
|
||||
return emailLogRepository.save(emailLogEntity);
|
||||
}
|
||||
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();
|
||||
Long userActionId =(Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
|
||||
emailLogRequest.setEmailType(emailType);
|
||||
@@ -67,6 +69,8 @@ public class EmailLogDao {
|
||||
emailLogRequest.setAmendmentId(amendmentId);
|
||||
emailLogRequest.setCallId(callId);
|
||||
emailLogRequest.setUserActionId(userActionId);
|
||||
emailLogRequest.setEmailSubject(subject);
|
||||
emailLogRequest.setEmailBody(body);
|
||||
return emailLogRequest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -50,24 +50,28 @@ public class PecMailDao {
|
||||
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) {
|
||||
List<EmailLogEntity> emailLogs = getEmailLogEntities(request, userActionId);
|
||||
for (EmailLogEntity log : emailLogs) {
|
||||
List<String> recipients = Utils.commaSeparatedStringToList(log.getRecipientEmails());
|
||||
CallEntity call = callService.validateCall(log.getCallId());
|
||||
emailNotificationDao.sendMail(
|
||||
emailNotificationDao.sendPendingMail(
|
||||
call.getHub().getId(),
|
||||
log.getEmailSubject(),
|
||||
log.getEmailBody(),
|
||||
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) {
|
||||
@@ -77,7 +81,7 @@ public class PecMailDao {
|
||||
}
|
||||
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()) {
|
||||
log.info("No emails found for given userActionId: {}", userActionId);
|
||||
|
||||
@@ -192,19 +192,19 @@ public class UserDao {
|
||||
: SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.USER_ONBOARDING_BANDI;
|
||||
|
||||
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);
|
||||
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(
|
||||
userEntity.getHub().getId(),
|
||||
emailTemplate.getSubject(),
|
||||
body,
|
||||
List.of(userEntity.getEmail()),
|
||||
emailLogRequest
|
||||
emailLogEntity
|
||||
);
|
||||
}
|
||||
|
||||
@@ -545,15 +545,7 @@ public class UserDao {
|
||||
redirectUrl = user.getHub().getDomainName();
|
||||
}
|
||||
|
||||
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(
|
||||
emailTemplate.getEmailScenario(),
|
||||
RecipientTypeEnum.USER,
|
||||
user.getId(),
|
||||
user.getEmail(),
|
||||
user.getId(),
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
|
||||
redirectUrl = String.format(
|
||||
user.getHub().getDomainName() + GepafinConstant.RESET_PASSWORD_URL_FORMAT,
|
||||
token,
|
||||
@@ -569,12 +561,22 @@ public class UserDao {
|
||||
"{{user_name}}", userName,
|
||||
"{{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(
|
||||
user.getHub().getId(),
|
||||
subject,
|
||||
body,
|
||||
List.of(user.getEmail()),
|
||||
emailLogRequest
|
||||
emailLogEntity
|
||||
);
|
||||
|
||||
log.info("Password reset token email sent to: {}", user.getEmail());
|
||||
|
||||
@@ -59,5 +59,8 @@ public class EmailLogEntity extends BaseEntity{
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_action_id")
|
||||
private UserActionEntity userAction;
|
||||
|
||||
@Column(name = "ATTACHMENTS")
|
||||
private String attachments;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,11 @@ public interface EmailLogRepository extends JpaRepository<EmailLogEntity,Long> {
|
||||
String sendStatus
|
||||
);
|
||||
|
||||
List<EmailLogEntity> findByUserActionIdAndSendStatusAndIsDeletedFalse(Long userActionId,String status);
|
||||
|
||||
|
||||
@Query(value = """
|
||||
SELECT DISTINCT ON (user_action_id) * FROM gepafin_schema.email_log WHERE send_status = 'PENDING' AND is_deleted = false """, 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();
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
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.EmailLogRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.model.request.EmailConfig;
|
||||
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.Validator;
|
||||
|
||||
@@ -15,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,8 +33,11 @@ public class MailgunEmailService implements EmailService {
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
@Autowired
|
||||
private EmailLogRepository emailLogRepository;
|
||||
|
||||
@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))) {
|
||||
return;
|
||||
@@ -45,10 +51,8 @@ public class MailgunEmailService implements EmailService {
|
||||
// Send email via Mailgun API
|
||||
HttpResponse<String> response2=null;
|
||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||
emailLogRequest.setEmailSubject(subject);
|
||||
emailLogRequest.setEmailBody(body);
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogEntity.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||
try {
|
||||
Unirest.setTimeouts(0, 0);
|
||||
response2 = Unirest.post(url)
|
||||
@@ -60,16 +64,17 @@ public class MailgunEmailService implements EmailService {
|
||||
.field("html", body)
|
||||
.asString();
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE.getValue());
|
||||
emailLogEntity.setErrorMessage(e.getMessage());
|
||||
emailLogRepository.save(emailLogEntity);
|
||||
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 emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE.getValue());
|
||||
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
emailLogRepository.save(emailLogEntity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.EmailLogDao;
|
||||
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.EmailServiceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.request.PecEmailRequest;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||
import net.gepafin.tendermanagement.service.CompanyService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.S3DocxProcessor;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
@@ -25,6 +30,9 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -51,29 +59,71 @@ public class PecEmailService implements EmailService {
|
||||
@Autowired
|
||||
private ApplicationDao applicationDao;
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
private AmazonS3Client s3Client;
|
||||
|
||||
@Autowired
|
||||
private EmailLogRepository emailLogRepository;
|
||||
|
||||
@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))) {
|
||||
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();
|
||||
emailRequest.setSender(emailConfig.getSender());
|
||||
emailRequest.setSubject(subject);
|
||||
emailRequest.setBody(body);
|
||||
emailRequest.setUsername(emailConfig.getUsername());
|
||||
emailRequest.setPassword(emailConfig.getPassword());
|
||||
emailRequest.setAttachments(emailLogRequest.getAttachments());
|
||||
emailRequest.setAttachments(attachmentRequests);
|
||||
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();
|
||||
HttpResponse<String> response2=null;
|
||||
HttpResponse<String> response2 = null;
|
||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||
emailLogRequest.setEmailSubject(emailRequest.getSubject());
|
||||
emailLogRequest.setEmailBody(emailRequest.getBody());
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient()));
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogEntity.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient()));
|
||||
try {
|
||||
if (Boolean.TRUE.equals(Boolean.parseBoolean(isPecServiceEnabled))) {
|
||||
Unirest.setTimeouts(0, 0);
|
||||
@@ -85,31 +135,33 @@ public class PecEmailService implements EmailService {
|
||||
|
||||
if (!isSuccessfulPecResponse(response2.getBody())) {
|
||||
String errorMsg = "PEC sending failed: " + response2.getBody();
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
emailLogRequest.setErrorMessage(errorMsg);
|
||||
sendNotificationOnFailure(emailLogRequest.getUserId(),emailLogRequest.getEmailType());
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE.getValue());
|
||||
emailLogEntity.setErrorMessage(errorMsg);
|
||||
sendNotificationOnFailure(emailLogEntity.getUserId(), EmailScenarioTypeEnum.valueOf(emailLogEntity.getEmailType()));
|
||||
|
||||
if (EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED.equals(emailLogRequest.getEmailType())) {
|
||||
applicationDao.sendApplicationSubmissionFailureEmail(emailLogRequest);
|
||||
if (EmailScenarioTypeEnum.APPLICATION_SUBMITTED.getValue().equals(emailLogEntity.getEmailType())) {
|
||||
applicationDao.sendApplicationSubmissionFailureEmail(emailLogEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
sendNotificationOnFailure(emailLogRequest.getUserId(),emailLogRequest.getEmailType());
|
||||
if (EmailScenarioTypeEnum.SPECIAL_APPLICATION_AMENDMENT_REQUESTED.equals(emailLogRequest.getEmailType())) {
|
||||
applicationDao.sendApplicationSubmissionFailureEmail(emailLogRequest);
|
||||
} catch (Exception e) {
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE.getValue());
|
||||
emailLogEntity.setErrorMessage(e.getMessage());
|
||||
sendNotificationOnFailure(emailLogEntity.getUserId(), EmailScenarioTypeEnum.valueOf(emailLogEntity.getEmailType()));
|
||||
if (EmailScenarioTypeEnum.APPLICATION_SUBMITTED.getValue().equals(emailLogEntity.getEmailType())) {
|
||||
applicationDao.sendApplicationSubmissionFailureEmail(emailLogEntity);
|
||||
}
|
||||
}
|
||||
if(response2 != null) {
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
if (response2 != null) {
|
||||
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) {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PecMailSerivceImpl implements PecMailService {
|
||||
private PecMailDao pecMailDao;
|
||||
|
||||
@Override
|
||||
public PecMailResponse sendPecMail(HttpServletRequest request, List<Long> userActionIds) {
|
||||
public List<PecMailResponse> sendPecMail(HttpServletRequest request, List<Long> 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.model.request.EmailConfig;
|
||||
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.Validator;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@@ -43,19 +46,20 @@ public class SystemEmailService implements EmailService {
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
@Autowired
|
||||
private EmailLogRepository emailLogRepository;
|
||||
|
||||
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))) {
|
||||
return;
|
||||
}
|
||||
|
||||
emailLogRequest.setEmailSubject(subject);
|
||||
emailLogRequest.setEmailBody(body);
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE);
|
||||
if (Boolean.TRUE.equals(isSendEmail)) {
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogEntity.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||
MessageResponse response = null;
|
||||
try {
|
||||
@@ -66,20 +70,23 @@ public class SystemEmailService implements EmailService {
|
||||
|
||||
response = mailgunMessagesApi.sendMessage(mailGunDomainName, message);
|
||||
} catch (Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
emailLogDao.createEmailLog(emailLogRequest);
|
||||
|
||||
emailLogEntity.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogEntity.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
|
||||
emailLogEntity.setErrorMessage(e.getMessage());
|
||||
emailLogRepository.save(emailLogEntity);
|
||||
throw new RuntimeException("Failed to send email via Mailgun: " + (response != null ? response.getMessage() : "No response from Mailgun"), e);
|
||||
}
|
||||
if(response != null) {
|
||||
emailLogRequest.setEmailServiceResponse(response.toString());
|
||||
if (response != null) {
|
||||
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) })) })
|
||||
@GetMapping(value = "",
|
||||
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);
|
||||
|
||||
@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 =
|
||||
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
|
||||
@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);
|
||||
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@ public class PecMailController implements PecMailApi {
|
||||
private PecMailService pecMailService;
|
||||
|
||||
@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)
|
||||
.actionContext(UserActionContextEnum.SEND_PEC_MAIL).build());
|
||||
|
||||
// PecMailResponse pecMailResponse=pecMailService.sendPecMail(request,userActionId);
|
||||
List<PecMailResponse> pecMailResponse=pecMailService.sendPecMail(request,userActionIds);
|
||||
|
||||
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"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="10-11-2025_RK_091725" author="Rajesh Khore">
|
||||
<addColumn tableName="email_log">
|
||||
<column name="attachments" type="TEXT"></column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
||||
Reference in New Issue
Block a user