use of io.jmix.emailtemplates.dto.ReportWithParams 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.dto.ReportWithParams in project jmix by jmix-framework.
the class TemplateParametersExtractor method getTemplateDefaultValues.
public List<ReportWithParams> getTemplateDefaultValues(EmailTemplate emailTemplate) throws ReportParameterTypeChangedException {
List<TemplateReport> templateReports = createParamsCollectionByTemplate(emailTemplate);
List<ReportWithParams> reportWithParams = new ArrayList<>();
List<String> exceptionMessages = new ArrayList<>();
for (TemplateReport templateReport : templateReports) {
try {
List<ParameterValue> parameterValues = null;
if (templateReport != null) {
parameterValues = templateReport.getParameterValues();
reportWithParams.add(getReportDefaultValues(templateReport.getReport(), parameterValues));
}
} catch (ReportParameterTypeChangedException e) {
exceptionMessages.add(e.getMessage());
}
}
if (!exceptionMessages.isEmpty()) {
StringBuilder messages = new StringBuilder();
exceptionMessages.forEach(m -> {
messages.append(m);
messages.append("\n");
});
throw new ReportParameterTypeChangedException(messages.toString());
}
return reportWithParams;
}
use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.
the class EmailTemplateParametersFragment method createComponents.
public EmailTemplateParametersFragment createComponents() {
clearComponents();
try {
List<ReportWithParams> parameters = getTemplateDefaultValues();
List<Report> reports = parameters.stream().map(ReportWithParams::getReport).collect(Collectors.toList());
parametersGrid.setRows(getRowCountForParameters(reports));
int currentGridRow = 0;
for (ReportWithParams reportData : parameters) {
Report report = reportData.getReport();
if (report != null && !report.getIsTmp()) {
report = dataManager.load(Report.class).id(report.getId()).fetchPlan("report.edit").one();
}
if (report != null) {
if (CollectionUtils.isNotEmpty(report.getInputParameters())) {
if (BooleanUtils.isNotTrue(hideReportCaption)) {
createReportNameLabel(report, currentGridRow);
currentGridRow++;
}
Map<String, Field> componentsMap = new HashMap<>();
for (ReportInputParameter parameter : report.getInputParameters()) {
if (BooleanUtils.isNotTrue(parameter.getHidden())) {
componentsMap.put(parameter.getAlias(), createComponent(parameter, reportData.getParams(), currentGridRow));
currentGridRow++;
}
}
parameterComponents.add(new ReportWithParamField(report, componentsMap));
}
}
}
} catch (ReportParameterTypeChangedException e) {
notifications.create(Notifications.NotificationType.ERROR).withCaption(e.getMessage()).show();
}
return this;
}
use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.
the class EmailTemplateBuilderImpl method setAttachmentParameters.
@Override
public EmailTemplateBuilder setAttachmentParameters(ReportWithParams reportWithParams) {
Report report = reportWithParams.getReport();
ReportWithParams existsParams = reportParams.stream().filter(e -> e.getReport().equals(report)).findFirst().orElse(null);
if (existsParams != null) {
reportParams.remove(existsParams);
}
reportParams.add(reportWithParams);
return this;
}
use of io.jmix.emailtemplates.dto.ReportWithParams 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