Search in sources :

Example 1 with ReportParameterTypeChangedException

use of io.jmix.emailtemplates.exception.ReportParameterTypeChangedException 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 2 with ReportParameterTypeChangedException

use of io.jmix.emailtemplates.exception.ReportParameterTypeChangedException 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 3 with ReportParameterTypeChangedException

use of io.jmix.emailtemplates.exception.ReportParameterTypeChangedException 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)3 TemplateReport (io.jmix.emailtemplates.entity.TemplateReport)3 ReportParameterTypeChangedException (io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)3 ParameterValue (io.jmix.emailtemplates.entity.ParameterValue)2 Report (io.jmix.reports.entity.Report)2 ReportInputParameter (io.jmix.reports.entity.ReportInputParameter)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 ReportWithParamField (io.jmix.emailtemplatesui.dto.ReportWithParamField)1