use of io.jmix.emailtemplates.exception.TemplateNotFoundException in project jmix by jmix-framework.
the class EmailTemplatesImpl method generateEmail.
@Override
public EmailInfo generateEmail(EmailTemplate emailTemplate, Collection<ReportWithParams> params) throws TemplateNotFoundException, ReportParameterTypeChangedException {
if (emailTemplate == null) {
throw new TemplateNotFoundException(messages.getMessage(EmailTemplates.class, "nullTemplate"));
}
List<ReportWithParams> parameters = new ArrayList<>(params);
TemplateReport bodyReport = emailTemplate.getEmailBodyReport();
ReportWithParams bodyReportWithParams = bodyReport != null ? getReportWithParams(bodyReport, parameters) : null;
Map<TemplateReport, ReportWithParams> attachmentsWithParams = new HashMap<>();
List<TemplateReport> attachedTemplateReports = emailTemplate.getAttachedTemplateReports();
if (attachedTemplateReports != null) {
for (TemplateReport templateReport : attachedTemplateReports) {
ReportWithParams reportWithParams = getReportWithParams(templateReport, parameters);
attachmentsWithParams.put(templateReport, reportWithParams);
}
}
EmailInfo emailInfo = generateEmailInfoWithoutAttachments(bodyReportWithParams);
List<EmailAttachment> templateAttachments = new ArrayList<>();
templateAttachments.addAll(createReportAttachments(attachmentsWithParams));
templateAttachments.addAll(createFilesAttachments(emailTemplate.getAttachedFiles()));
emailInfo.setSubject(Boolean.TRUE.equals(emailTemplate.getUseReportSubject()) ? emailInfo.getSubject() : emailTemplate.getSubject());
emailInfo.setAddresses(emailTemplate.getTo());
emailInfo.setCc(emailTemplate.getCc());
emailInfo.setBcc(emailTemplate.getBcc());
emailInfo.setFrom(emailTemplate.getFrom());
emailInfo.setAttachments(templateAttachments);
return emailInfo;
}
use of io.jmix.emailtemplates.exception.TemplateNotFoundException in project jmix by jmix-framework.
the class EmailTemplatesImpl method getEmailTemplateByCode.
protected EmailTemplate getEmailTemplateByCode(String emailTemplateCode) throws TemplateNotFoundException {
EmailTemplate emailTemplate = dataManager.load(EmailTemplate.class).query("select e from emltmp_EmailTemplate e where e.code = :code").parameter("code", emailTemplateCode).optional().orElse(null);
if (emailTemplate != null) {
MetaClass metaClass = metadata.getClass(emailTemplate.getClass());
emailTemplate = (EmailTemplate) dataManager.load(metaClass.getJavaClass()).query("select e from " + metaClass.getName() + " e where e.code = :code").parameter("code", emailTemplateCode).fetchPlan("emailTemplate-fetchPlan").optional().orElse(null);
} else {
throw new TemplateNotFoundException(messages.formatMessage(EmailTemplates.class, "notFoundTemplate", emailTemplateCode));
}
return emailTemplate;
}
use of io.jmix.emailtemplates.exception.TemplateNotFoundException in project jmix by jmix-framework.
the class EmailTemplatesImpl method generateEmail.
@Override
public EmailInfo generateEmail(EmailTemplate emailTemplate, Map<String, Object> params) throws TemplateNotFoundException, ReportParameterTypeChangedException {
if (emailTemplate == null) {
throw new TemplateNotFoundException(messages.getMessage(EmailTemplates.class, "nullTemplate"));
}
List<ReportWithParams> paramList = new ArrayList<>();
Report bodyReport = emailTemplate.getReport();
if (bodyReport == null && emailTemplate instanceof JsonEmailTemplate) {
bodyReport = templateConverter.convertToReport((JsonEmailTemplate) emailTemplate);
}
paramList.add(createParamsMapForReport(bodyReport, params));
for (TemplateReport templateReport : emailTemplate.getAttachedTemplateReports()) {
paramList.add(createParamsMapForReport(templateReport.getReport(), params));
}
return generateEmail(emailTemplate, paramList);
}
Aggregations