Search in sources :

Example 6 with TemplateReport

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

the class JsonEmailTemplateDetachListener method onBeforeDetach.

@Override
public void onBeforeDetach(JsonEmailTemplate entity) {
    if (entityStates.isLoaded(entity, "reportJson") && StringUtils.isNotBlank(entity.getReportJson())) {
        Report reportFromXml = templateConverter.convertToReport(entity);
        entity.setReport(reportFromXml);
        TemplateReport templateReport = metadata.create(TemplateReport.class);
        templateReport.setReport(reportFromXml);
        templateReport.setEmailTemplate(entity);
        templateReport.setParameterValues(new ArrayList<>());
        entity.setEmailBodyReport(templateReport);
    }
}
Also used : TemplateReport(io.jmix.emailtemplates.entity.TemplateReport) Report(io.jmix.reports.entity.Report) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 7 with TemplateReport

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

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

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

the class ReportEmailTemplateEdit method onPreCommit.

@Subscribe(target = Target.DATA_CONTEXT)
protected void onPreCommit(DataContext.PreCommitEvent event) {
    TemplateReport templateReport = emailBodyReportDc.getItemOrNull();
    if (entityStates.isNew(getEditedEntity())) {
        if (templateReport != null) {
            event.getSource().merge(templateReport);
        }
    } else {
        ReportEmailTemplate original = dataManager.load(ReportEmailTemplate.class).id(getEditedEntity().getId()).fetchPlan("emailTemplate-fetchPlan").one();
        TemplateReport originalEmailBodyReport = original.getEmailBodyReport();
        if (originalEmailBodyReport != null && !originalEmailBodyReport.equals(templateReport)) {
            event.getSource().remove(originalEmailBodyReport);
        }
    }
}
Also used : ReportEmailTemplate(io.jmix.emailtemplates.entity.ReportEmailTemplate) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 10 with TemplateReport

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

the class EmailTemplateBuilderImpl method addAttachmentReport.

@Override
public EmailTemplateBuilder addAttachmentReport(Report report) {
    TemplateReport templateReport = metadata.create(TemplateReport.class);
    templateReport.setReport(report);
    emailTemplate.getAttachedTemplateReports().add(templateReport);
    return this;
}
Also used : TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

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