Search in sources :

Example 6 with ReportWithParams

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;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) EmailAttachment(io.jmix.email.EmailAttachment) EmailTemplates(io.jmix.emailtemplates.EmailTemplates) TemplateNotFoundException(io.jmix.emailtemplates.exception.TemplateNotFoundException) EmailInfo(io.jmix.email.EmailInfo)

Example 7 with ReportWithParams

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;
}
Also used : ParameterValue(io.jmix.emailtemplates.entity.ParameterValue) ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) ReportParameterTypeChangedException(io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)

Example 8 with 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;
}
Also used : ReportWithParamField(io.jmix.emailtemplatesui.dto.ReportWithParamField) ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) Report(io.jmix.reports.entity.Report) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter) ReportWithParamField(io.jmix.emailtemplatesui.dto.ReportWithParamField) ReportParameterTypeChangedException(io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)

Example 9 with ReportWithParams

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;
}
Also used : TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) Report(io.jmix.reports.entity.Report) ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams)

Example 10 with ReportWithParams

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);
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) Report(io.jmix.reports.entity.Report) EmailTemplates(io.jmix.emailtemplates.EmailTemplates) TemplateNotFoundException(io.jmix.emailtemplates.exception.TemplateNotFoundException)

Aggregations

ReportWithParams (io.jmix.emailtemplates.dto.ReportWithParams)14 TemplateReport (io.jmix.emailtemplates.entity.TemplateReport)6 Report (io.jmix.reports.entity.Report)4 ReportParameterTypeChangedException (io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)3 ReportInputParameter (io.jmix.reports.entity.ReportInputParameter)3 EmailAttachment (io.jmix.email.EmailAttachment)2 EmailTemplates (io.jmix.emailtemplates.EmailTemplates)2 ParameterValue (io.jmix.emailtemplates.entity.ParameterValue)2 TemplateNotFoundException (io.jmix.emailtemplates.exception.TemplateNotFoundException)2 ReportWithParamField (io.jmix.emailtemplatesui.dto.ReportWithParamField)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 EmailInfo (io.jmix.email.EmailInfo)1