Search in sources :

Example 1 with TemplateReport

use of io.jmix.emailtemplates.entity.TemplateReport in project jmix by jmix-framework.

the class EmailTemplateSendScreen method setParameter.

public void setParameter(String alias, Object value) {
    List<TemplateReport> templateReports = new ArrayList<>();
    if (emailTemplate.getEmailBodyReport() != null) {
        templateReports.add(emailTemplate.getEmailBodyReport());
    }
    templateReports.addAll(emailTemplate.getAttachedTemplateReports());
    for (TemplateReport templateReport : templateReports) {
        ReportInputParameter inputParameter = templateReport.getReport().getInputParameters().stream().filter(e -> alias.equals(e.getAlias())).findFirst().orElse(null);
        if (inputParameter != null) {
            ParameterValue parameterValue = templateReport.getParameterValues().stream().filter(pv -> pv.getAlias().equals(alias)).findFirst().orElse(null);
            if (parameterValue == null) {
                parameterValue = metadata.create(ParameterValue.class);
                parameterValue.setAlias(alias);
                parameterValue.setParameterType(inputParameter.getType());
                parameterValue.setTemplateReport(templateReport);
                templateReport.getParameterValues().add(parameterValue);
            }
            Class parameterClass = classResolver.resolveClass(inputParameter);
            if (!ParameterType.ENTITY_LIST.equals(inputParameter.getType())) {
                String stringValue = objectToStringConverter.convertToString(parameterClass, value);
                parameterValue.setDefaultValue(stringValue);
            }
        }
    }
}
Also used : ParameterValue(io.jmix.emailtemplates.entity.ParameterValue) ArrayList(java.util.ArrayList) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 2 with TemplateReport

use of io.jmix.emailtemplates.entity.TemplateReport in project jmix by jmix-framework.

the class EmailTemplateBuilderImpl method setAttachmentParameters.

@Override
public EmailTemplateBuilder setAttachmentParameters(Collection<ReportWithParams> reportsWithParams) {
    TemplateReport emailBodyReport = emailTemplate.getEmailBodyReport();
    ReportWithParams reportWithParams = reportParams.stream().filter(e -> e.getReport().equals(emailBodyReport.getReport())).findFirst().orElse(null);
    reportParams.clear();
    if (reportWithParams != null) {
        reportParams.add(reportWithParams);
    }
    reportParams.addAll(reportsWithParams);
    return this;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 3 with TemplateReport

use of io.jmix.emailtemplates.entity.TemplateReport in project jmix by jmix-framework.

the class EmailTemplateBuilderImpl method cloneTemplate.

protected EmailTemplate cloneTemplate(EmailTemplate emailTemplate) {
    EmailTemplate clonedTemplate = metadataTools.deepCopy(emailTemplate);
    if (clonedTemplate instanceof JsonEmailTemplate) {
        clonedTemplate.setEmailBodyReport(emailTemplate.getEmailBodyReport());
        ((JsonEmailTemplate) clonedTemplate).setReport(emailTemplate.getReport());
    }
    List<TemplateReport> attachedTemplateReports = new ArrayList<>();
    List<TemplateReport> templateAttachedTemplateReports = emailTemplate.getAttachedTemplateReports();
    if (templateAttachedTemplateReports != null) {
        for (TemplateReport templateReport : templateAttachedTemplateReports) {
            TemplateReport newTemplateReport = metadataTools.deepCopy(templateReport);
            attachedTemplateReports.add(newTemplateReport);
        }
    }
    clonedTemplate.setAttachedTemplateReports(attachedTemplateReports);
    return clonedTemplate;
}
Also used : JsonEmailTemplate(io.jmix.emailtemplates.entity.JsonEmailTemplate) ArrayList(java.util.ArrayList) JsonEmailTemplate(io.jmix.emailtemplates.entity.JsonEmailTemplate) EmailTemplate(io.jmix.emailtemplates.entity.EmailTemplate) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 4 with TemplateReport

use of io.jmix.emailtemplates.entity.TemplateReport in project jmix by jmix-framework.

the class EmailTemplateBuilderImpl method setBodyParameter.

@Override
public EmailTemplateBuilder setBodyParameter(String key, Object value) {
    TemplateReport emailBodyReport = emailTemplate.getEmailBodyReport();
    ReportWithParams reportWithParams = reportParams.stream().filter(e -> e.getReport().equals(emailBodyReport.getReport())).findFirst().orElse(null);
    if (reportWithParams == null) {
        reportWithParams = new ReportWithParams(emailBodyReport.getReport());
        reportParams.add(reportWithParams);
    }
    reportWithParams.put(key, value);
    return this;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 5 with TemplateReport

use of io.jmix.emailtemplates.entity.TemplateReport 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)

Aggregations

TemplateReport (io.jmix.emailtemplates.entity.TemplateReport)12 Report (io.jmix.reports.entity.Report)4 ReportWithParams (io.jmix.emailtemplates.dto.ReportWithParams)3 ParameterValue (io.jmix.emailtemplates.entity.ParameterValue)3 ArrayList (java.util.ArrayList)2 EmailTemplate (io.jmix.emailtemplates.entity.EmailTemplate)1 JsonEmailTemplate (io.jmix.emailtemplates.entity.JsonEmailTemplate)1 ReportEmailTemplate (io.jmix.emailtemplates.entity.ReportEmailTemplate)1 ReportParameterTypeChangedException (io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)1 ReportInputParameter (io.jmix.reports.entity.ReportInputParameter)1