diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index d8877015..f4656197 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -2132,45 +2132,7 @@ public class ApplicationDao { tableDataByApp.put(appId, flattenedAll); } } - - - public void sendApplicationSubmissionFailureEmail(EmailLogRequest emailLogRequest){ - - Long callId = emailLogRequest.getCallId(); - CallEntity call = callService.validateCall(callId); - HubEntity hub = call.getHub(); - Long userId = emailLogRequest.getUserId(); - UserEntity user = userService.validateUser(userId); - Long applicationId = emailLogRequest.getApplicatioId(); - ApplicationEntity applicationEntity = validateApplication(applicationId); - CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); - - - SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService - .retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_FAILURE_NOTIFICATION, - hub, null); - - Map subjectPlaceholders = new HashMap<>(); - subjectPlaceholders.put("{{call_name}}", call.getName()); - - Map bodyPlaceholders = new HashMap<>(); - bodyPlaceholders.put("{{scenario}}",emailLogRequest.getEmailType().getValue()); - bodyPlaceholders.put("{{call_name}}", call.getName()); - bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString()); - bodyPlaceholders.put("{{company_name}}", company.getCompanyName()); - bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString()); - bodyPlaceholders.put("{{user_action_id}}",emailLogRequest.getUserActionId().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.setRecipientEmails(GepafinConstant.RINALDO_EMAIL); - emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest); - } - - public ApplicationResponse readmitApplication(HttpServletRequest request, Long applicationId) { + public ApplicationResponse readmitApplication(HttpServletRequest request, Long applicationId) { log.info("Re-admiting the Application with id : {}", applicationId); ApplicationEntity applicationEntity = fetchRejectedApplication(applicationId); @@ -2249,4 +2211,40 @@ public class ApplicationDao { } + public void sendApplicationSubmissionFailureEmail(EmailLogRequest emailLogRequest){ + + Long callId = emailLogRequest.getCallId(); + CallEntity call = callService.validateCall(callId); + HubEntity hub = call.getHub(); + Long userId = emailLogRequest.getUserId(); + UserEntity user = userService.validateUser(userId); + Long applicationId = emailLogRequest.getApplicatioId(); + ApplicationEntity applicationEntity = validateApplication(applicationId); + CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId()); + + + SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService + .retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_FAILURE_NOTIFICATION, + hub, null); + + Map subjectPlaceholders = new HashMap<>(); + subjectPlaceholders.put("{{call_name}}", call.getName()); + + Map bodyPlaceholders = new HashMap<>(); + bodyPlaceholders.put("{{scenario}}",emailLogRequest.getEmailType().getValue()); + bodyPlaceholders.put("{{call_name}}", call.getName()); + bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString()); + bodyPlaceholders.put("{{company_name}}", company.getCompanyName()); + bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString()); + bodyPlaceholders.put("{{user_action_id}}",emailLogRequest.getUserActionId().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.setRecipientEmails(GepafinConstant.RINALDO_EMAIL); + emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest); + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java b/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java index 95939082..0cc64b89 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/SystemEmailService.java @@ -73,7 +73,10 @@ public class SystemEmailService implements EmailService { throw new RuntimeException("Failed to send email via Mailgun: " + (response != null ? response.getMessage() : "No response from Mailgun"), e); } - emailLogRequest.setEmailServiceResponse(response.toString()); + if(response != null) { + emailLogRequest.setEmailServiceResponse(response.toString()); + } + emailLogDao.createEmailLog(emailLogRequest); } }