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);
}
}
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);
}
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();
}
}
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);
}
}
}
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;
}
Aggregations