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