Search in sources :

Example 26 with Report

use of io.jmix.reports.entity.Report 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 27 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class EmailTemplateParametersFragment method updateDefaultValue.

private void updateDefaultValue(ReportInputParameter parameter, Object fieldValue) {
    String alias = parameter.getAlias();
    Report report = parameter.getReport();
    TemplateReport templateReport = templateReports.stream().filter(e -> e.getReport().equals(report)).findFirst().orElse(null);
    if (fieldValue == null && templateReport == null) {
        return;
    }
    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(parameter.getType());
        parameterValue.setTemplateReport(templateReport);
        templateReport.getParameterValues().add(parameterValue);
    }
    Class parameterClass = parameterClassResolver.resolveClass(parameter);
    String stringValue = templateParametersExtractor.convertToString(parameter.getType(), parameterClass, fieldValue);
    parameterValue.setDefaultValue(stringValue);
}
Also used : ParameterValue(io.jmix.emailtemplates.entity.ParameterValue) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) Report(io.jmix.reports.entity.Report) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 28 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class ReportEmailTemplateEdit method updateParametersComponents.

private void updateParametersComponents() {
    Report value = emailBody.getValue();
    if (value != null) {
        if (value.getDefaultTemplate() != null) {
            if (ReportOutputType.HTML == value.getDefaultTemplate().getReportOutputType()) {
                TemplateReport templateReport = metadata.create(TemplateReport.class);
                templateReport.setParameterValues(new ArrayList<>());
                templateReport.setReport(value);
                emailBodyReportDc.setItem(templateReport);
                getEditedEntity().setEmailBodyReport(templateReport);
                bodyParametersFragment.setTemplateReport(getEditedEntity().getEmailBodyReport());
                bodyParametersFragment.createComponents();
            } else {
                resetTemplateReport();
                emailBody.setValue(null);
                notifications.create(Notifications.NotificationType.ERROR).withDescription(messageBundle.getMessage("notification.reportIsNotHtml")).show();
            }
        } else {
            resetTemplateReport();
            emailBody.setValue(null);
            notifications.create(Notifications.NotificationType.ERROR).withDescription(messageBundle.getMessage("notification.reportHasNoDefaultTemplate")).show();
        }
    } else {
        resetTemplateReport();
    }
}
Also used : TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) Report(io.jmix.reports.entity.Report) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 29 with Report

use of io.jmix.reports.entity.Report 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 30 with Report

use of io.jmix.reports.entity.Report 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

Report (io.jmix.reports.entity.Report)45 ReportTemplate (io.jmix.reports.entity.ReportTemplate)13 Subscribe (io.jmix.ui.screen.Subscribe)8 ReportOutputDocument (com.haulmont.yarg.reporting.ReportOutputDocument)7 TemplateReport (io.jmix.emailtemplates.entity.TemplateReport)7 MetaClass (io.jmix.core.metamodel.model.MetaClass)6 FluentUiReportRunner (io.jmix.reportsui.runner.FluentUiReportRunner)5 ReportWithParams (io.jmix.emailtemplates.dto.ReportWithParams)4 ReportInputParameter (io.jmix.reports.entity.ReportInputParameter)4 UiReportRunContext (io.jmix.reportsui.runner.UiReportRunContext)4 List (java.util.List)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 DataManager (io.jmix.core.DataManager)3 ParameterPrototype (io.jmix.reports.app.ParameterPrototype)3 ReportingException (io.jmix.reports.exception.ReportingException)3 ReportRunContext (io.jmix.reports.runner.ReportRunContext)3 LiteratureType (reports.ex2.entity.LiteratureType)3 Id (io.jmix.core.Id)2 CurrentUserSubstitution (io.jmix.core.usersubstitution.CurrentUserSubstitution)2 ParameterValue (io.jmix.emailtemplates.entity.ParameterValue)2