Search in sources :

Example 11 with ReportWithParams

use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.

the class EmailTemplatesImpl method createReportAttachments.

protected List<EmailAttachment> createReportAttachments(Map<TemplateReport, ReportWithParams> reportsWithParams) {
    List<EmailAttachment> attachmentsList = new ArrayList<>();
    for (Map.Entry<TemplateReport, ReportWithParams> entry : reportsWithParams.entrySet()) {
        TemplateReport templateReport = entry.getKey();
        ReportWithParams reportWithParams = entry.getValue();
        EmailAttachment emailAttachment = createEmailAttachment(templateReport.getName(), reportWithParams);
        attachmentsList.add(emailAttachment);
    }
    return attachmentsList;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) EmailAttachment(io.jmix.email.EmailAttachment)

Example 12 with ReportWithParams

use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.

the class EmailTemplatesImpl method createParamsMapForReport.

protected ReportWithParams createParamsMapForReport(Report report, Map<String, Object> params) {
    ReportWithParams reportWithParams = new ReportWithParams(report);
    if (MapUtils.isNotEmpty(params)) {
        Map<String, Object> paramsMap = new HashMap<>();
        for (ReportInputParameter parameter : report.getInputParameters()) {
            paramsMap.put(parameter.getAlias(), params.get(parameter.getAlias()));
        }
        reportWithParams.setParams(paramsMap);
    }
    return reportWithParams;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter)

Example 13 with ReportWithParams

use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.

the class EmailTemplatesImpl method getReportWithParams.

private ReportWithParams getReportWithParams(TemplateReport templateReport, List<ReportWithParams> parameters) throws ReportParameterTypeChangedException {
    ReportWithParams bodyReportWithParams = parametersExtractor.getReportDefaultValues(templateReport.getReport(), templateReport.getParameterValues());
    ReportWithParams bodyReportExternalParams = parameters.stream().filter(e -> e.getReport().equals(templateReport.getReport())).findFirst().orElse(null);
    if (bodyReportExternalParams != null) {
        for (String key : bodyReportExternalParams.getParams().keySet()) {
            bodyReportWithParams.put(key, bodyReportExternalParams.getParams().get(key));
        }
    }
    return bodyReportWithParams;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams)

Example 14 with ReportWithParams

use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.

the class TemplateParametersExtractor method getReportDefaultValues.

public ReportWithParams getReportDefaultValues(Report report, List<ParameterValue> parameterValues) throws ReportParameterTypeChangedException {
    ReportWithParams paramsData = new ReportWithParams(report);
    List<String> exceptionMessages = new ArrayList<>();
    if (parameterValues != null) {
        Report reportFromXml = reportsSerialization.convertToReport(report.getXml());
        for (ParameterValue paramValue : parameterValues) {
            String alias = paramValue.getAlias();
            String stringValue = paramValue.getDefaultValue();
            ReportInputParameter inputParameter = reportFromXml.getInputParameters().stream().filter(e -> e.getAlias().equals(alias)).findFirst().orElse(null);
            if (inputParameter != null) {
                try {
                    emailTemplates.checkParameterTypeChanged(inputParameter, paramValue);
                } catch (ReportParameterTypeChangedException e) {
                    exceptionMessages.add(e.getMessage());
                }
                Class parameterClass = resolveClass(inputParameter);
                Object value = convertFromString(inputParameter.getType(), parameterClass, stringValue);
                paramsData.put(alias, value);
            }
        }
    }
    if (!exceptionMessages.isEmpty()) {
        StringBuilder messages = new StringBuilder();
        exceptionMessages.forEach(m -> {
            messages.append(m);
            messages.append("\n");
        });
        throw new ReportParameterTypeChangedException(messages.toString());
    }
    return paramsData;
}
Also used : ParameterValue(io.jmix.emailtemplates.entity.ParameterValue) ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) Report(io.jmix.reports.entity.Report) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter) MetaClass(io.jmix.core.metamodel.model.MetaClass) ReportParameterTypeChangedException(io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)

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