Template issue.
This commit is contained in:
@@ -9,9 +9,13 @@ import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
|
|||||||
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
|
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||||
|
import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse;
|
||||||
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.HubRepository;
|
import net.gepafin.tendermanagement.repositories.HubRepository;
|
||||||
import net.gepafin.tendermanagement.service.*;
|
import net.gepafin.tendermanagement.service.*;
|
||||||
@@ -27,6 +31,8 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao.filterByName;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class EmailNotificationDao {
|
public class EmailNotificationDao {
|
||||||
|
|
||||||
@@ -59,87 +65,129 @@ public class EmailNotificationDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompanyService companyService;
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationFormRepository applicationFormRepository;
|
||||||
|
|
||||||
private void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType,
|
@Autowired
|
||||||
Map<String, String> bodyPlaceholders, List<String> additionalRecipients,Long amendmentId) {
|
private ApplicationFormFieldRepository applicationFormFieldRepository;
|
||||||
|
|
||||||
|
private void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType, Map<String, String> bodyPlaceholders,
|
||||||
|
List<String> additionalRecipients, Long amendmentId) {
|
||||||
|
|
||||||
HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId());
|
HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId());
|
||||||
String service = determineService(applicationEntity.getHubId());
|
// String service = determineService(applicationEntity.getHubId());
|
||||||
String legalMail = service.equals("Gepafin S.p.a.") ? "bandi.gepafin@legalmail.it" : "bandi.sviluppumbria@legalmail.it";
|
// String legalMail = service.equals("Gepafin S.p.a.") ? "bandi.gepafin@legalmail.it" : "bandi.sviluppumbria@legalmail.it";
|
||||||
|
|
||||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, hubEntity, null);
|
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService.retrieveTemplateByTypeAndCall(templateType, hubEntity, null);
|
||||||
Map<String, String> subjectPlaceholders = new HashMap<>();
|
Map<String, String> subjectPlaceholders = new HashMap<>();
|
||||||
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
subjectPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||||
subjectPlaceholders.put("{{company_name}}", company.getCompanyName());
|
subjectPlaceholders.put("{{company_name}}", company.getCompanyName());
|
||||||
bodyPlaceholders.put("{{legal_mail}}", legalMail);
|
// bodyPlaceholders.put("{{legal_mail}}", legalMail);
|
||||||
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);
|
||||||
|
|
||||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||||
List<String> recipientEmails = getRecipientEmails(applicationEntity, userEntity, additionalRecipients);
|
List<String> recipientEmails = getRecipientEmails(applicationEntity, userEntity, additionalRecipients);
|
||||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY,userEntity.getBeneficiary().getId(),Utils.listToCommaSeparatedString(recipientEmails),userEntity.getId(),applicationEntity.getId(),amendmentId ,applicationEntity.getCall().getId());
|
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY, 1L,
|
||||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails,emailLogRequest);
|
Utils.listToCommaSeparatedString(recipientEmails), userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
|
||||||
|
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails, emailLogRequest);
|
||||||
}
|
}
|
||||||
private List<String> getRecipientEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients) {
|
private List<String> getRecipientEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients) {
|
||||||
|
|
||||||
List<String> recipientEmails = new ArrayList<>();
|
List<String> recipientEmails = new ArrayList<>();
|
||||||
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
|
||||||
String companyEmail = company.getEmail();
|
// String companyEmail = company.getEmail();
|
||||||
String contactEmail = company.getContactEmail();
|
// String contactEmail = company.getContactEmail();
|
||||||
|
//
|
||||||
if (companyEmail != null && !companyEmail.isEmpty()) {
|
// if (companyEmail != null && !companyEmail.isEmpty()) {
|
||||||
recipientEmails.add(companyEmail);
|
// recipientEmails.add(companyEmail);
|
||||||
}
|
// }
|
||||||
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
// if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
||||||
recipientEmails.add(contactEmail);
|
// recipientEmails.add(contactEmail);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (userEntity.getBeneficiary().getEmail() != null) {
|
// if (userEntity.getBeneficiary().getEmail() != null) {
|
||||||
recipientEmails.add(userEntity.getBeneficiary().getEmail());
|
// recipientEmails.add(userEntity.getBeneficiary().getEmail());
|
||||||
}
|
// }
|
||||||
if (additionalRecipients != null) {
|
// if (additionalRecipients != null) {
|
||||||
recipientEmails.addAll(additionalRecipients);
|
// recipientEmails.addAll(additionalRecipients);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
recipientEmails.add("piyush1.kag1@gmail.com");
|
||||||
return recipientEmails;
|
return recipientEmails;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// private String determineService(Long hubId) {
|
||||||
|
//
|
||||||
|
// HubEntity hub = hubRepository.findById(hubId).orElseThrow(() -> new IllegalArgumentException("Invalid Hub ID: " + hubId));
|
||||||
|
// return hub.getEmailServiceType().equalsIgnoreCase("MAILGUN_SERVICE") ? "Sviluppumbria" : "Gepafin S.p.a.";
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void sendMailToNotifyBeneficiaryRegardingNewAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||||
|
|
||||||
private String determineService(Long hubId) {
|
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequestEntity.getApplicationId());
|
||||||
|
|
||||||
HubEntity hub = hubRepository.findById(hubId).orElseThrow(() -> new IllegalArgumentException("Invalid Hub ID: " + hubId));
|
|
||||||
return hub.getEmailServiceType().equalsIgnoreCase("MAILGUN_SERVICE") ? "Gepafin S.p.a." : "Sviluppumbria";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMailToNotifyBeneficiaryRegardingNewAmendment(ApplicationAmendmentRequestEntity applicationAmendmentRequest) {
|
|
||||||
|
|
||||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationAmendmentRequest.getApplicationId());
|
|
||||||
Map<String, String> bodyPlaceholders = new HashMap<>();
|
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||||
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||||
bodyPlaceholders.put("{{protocol_number}}", applicationAmendmentRequest.getProtocol().getProtocolNumber().toString());
|
bodyPlaceholders.put("{{protocol_number}}", applicationAmendmentRequestEntity.getProtocol().getProtocolNumber().toString());
|
||||||
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatLocalDateTime(applicationAmendmentRequest.getProtocol().getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatLocalDateTime(applicationAmendmentRequestEntity.getProtocol().getCreatedDate(), GepafinConstant.DD_MM_YYYY));
|
||||||
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationAmendmentRequest.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationAmendmentRequestEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
||||||
String formFieldsJson = applicationAmendmentRequest.getFormFields();
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Map<String, Object>> formFields = objectMapper.readValue(formFieldsJson, new TypeReference<List<Map<String, Object>>>() {
|
// Retrieve forms and initialize required collections
|
||||||
});
|
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
||||||
//•
|
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
||||||
StringBuilder bulletPoints = new StringBuilder();
|
StringBuilder bulletPoints = new StringBuilder();
|
||||||
for (Map<String, Object> field : formFields) {
|
|
||||||
String label = (String) field.get("label");
|
// Extract data from forms
|
||||||
boolean selected = (boolean) field.get("selected");
|
for (ApplicationFormEntity form : forms) {
|
||||||
if (!selected) {
|
String content = form.getForm().getContent();
|
||||||
bulletPoints.append("• ").append(label).append("\n");
|
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
||||||
}
|
allFormFields.addAll(getIdAndLabelFromResult(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process allFormFields and generate bullet points
|
||||||
|
for (AmendmentFormFieldResponse field : allFormFields) {
|
||||||
|
// Build bullet points
|
||||||
|
bulletPoints.append(field.getLabel());
|
||||||
|
bulletPoints.append("\n");
|
||||||
|
}
|
||||||
|
// Add the generated bullet points to placeholders
|
||||||
bodyPlaceholders.put("{{form_dataInput}}", bulletPoints.toString());
|
bodyPlaceholders.put("{{form_dataInput}}", bulletPoints.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to parse form fields JSON: ", e);
|
log.error("Failed to process form fields: ", e);
|
||||||
}
|
}
|
||||||
bodyPlaceholders.put("{{note}}", applicationAmendmentRequest.getNote());
|
|
||||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,applicationAmendmentRequest.getId());
|
|
||||||
|
bodyPlaceholders.put("{{note}}", applicationAmendmentRequestEntity.getNote());
|
||||||
|
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,
|
||||||
|
applicationAmendmentRequestEntity.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AmendmentFormFieldResponse> getIdAndLabelFromResult(List<Map<String, Object>> result) {
|
||||||
|
List<AmendmentFormFieldResponse> formFieldResponses = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map<String, Object> item : result) {
|
||||||
|
AmendmentFormFieldResponse formFieldResponse = new AmendmentFormFieldResponse();
|
||||||
|
formFieldResponse.setFieldId((String) item.get("id"));
|
||||||
|
|
||||||
|
// Extract "label" value from the "settings" array
|
||||||
|
List<Map<String, Object>> settings = (List<Map<String, Object>>) item.get("settings");
|
||||||
|
String label = settings.stream()
|
||||||
|
.filter(setting -> "label".equals(setting.get("name")))
|
||||||
|
.map(setting -> (String) setting.get("value"))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(""); // Default to empty string if not found
|
||||||
|
|
||||||
|
if (label == null || label.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
formFieldResponse.setLabel(label); // Set the label as fieldValue
|
||||||
|
formFieldResponses.add(formFieldResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
return formFieldResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendApplicationFailureNotificationEmail(ApplicationAmendmentRequestEntity amendmentRequest) {
|
public void sendApplicationFailureNotificationEmail(ApplicationAmendmentRequestEntity amendmentRequest) {
|
||||||
|
|||||||
@@ -1962,4 +1962,9 @@
|
|||||||
</addColumn>
|
</addColumn>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="03-12-2024_1" author="Piyush">
|
||||||
|
<sqlFile dbms="postgresql"
|
||||||
|
path="db/dump/update_system_email_template_for_updating_amendment_mail_notification_mail_03_12_2024_1.sql"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
UPDATE gepafin_schema.system_email_template
|
||||||
|
SET html_content = '<html>
|
||||||
|
<body style="font-family: Arial, sans-serif; color: #000; line-height: 1.6;">
|
||||||
|
<div style="padding: 20px; border: 1px solid #ddd; border-radius: 8px; max-width: 600px; margin: auto;">
|
||||||
|
<p><strong>RICHIESTA INTEGRAZIONE DOCUMENTALE</strong></p>
|
||||||
|
<p>Buongiorno,</p>
|
||||||
|
<p>In riferimento alla domanda di concessione di Finanziamento agevolato a valere sul Fondo prestiti
|
||||||
|
<strong>{{call_name}}</strong> di cui al <strong>Protocollo n. {{protocol_number}} del
|
||||||
|
{{protocol_date}} e {{protocol_time}}</strong>, alla luce dell''attività istruttoria svolta,
|
||||||
|
segnaliamo quanto segue:</p>
|
||||||
|
<ul>
|
||||||
|
<li>{{form_dataInput}}</li>
|
||||||
|
</ul>
|
||||||
|
<p>{{note}}</p>
|
||||||
|
<p>Vi invitiamo a fornire quanto sopra richiesto integrando la documentazione sia caricandola all''interno dello sportello
|
||||||
|
online <a href="{{platform_link}}">{{platform_link}}</a> che inviandola a mezzo PEC all''indirizzo
|
||||||
|
{{legal_mail}} entro e <strong>non oltre 10 giorni</strong> dal ricevimento della presente comunicazione,
|
||||||
|
precisando che, in caso di mancata ricezione nei termini indicati, saremo costretti a non prendere in considerazione la Vostra richiesta di finanziamento.</p>
|
||||||
|
<p>Vi informiamo che per la ricezione della PEC farà fede la ricevuta di avvenuta consegna che attesterà il buon esito
|
||||||
|
dell''invio. La documentazione trasmessa e le informazioni fornite saranno processate dall''istruttore assegnatario della pratica.</p>
|
||||||
|
<p>Distinti Saluti,</p>
|
||||||
|
<p><strong>{{email_signature}}</strong></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>'
|
||||||
|
WHERE "type" = 'DOCUMENTATION_INTEGRATION_REQUEST' AND "system" = true;
|
||||||
Reference in New Issue
Block a user