use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.
the class EmailTemplatesImpl method createReportAttachments.
protected List<EmailAttachment> createReportAttachments(Map<TemplateReport, ReportWithParams> reportsWithParams) {
List<EmailAttachment> attachmentsList = new ArrayList<>();
for (Map.Entry<TemplateReport, ReportWithParams> entry : reportsWithParams.entrySet()) {
TemplateReport templateReport = entry.getKey();
ReportWithParams reportWithParams = entry.getValue();
EmailAttachment emailAttachment = createEmailAttachment(templateReport.getName(), reportWithParams);
attachmentsList.add(emailAttachment);
}
return attachmentsList;
}
use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.
the class EmailTemplatesImpl method createParamsMapForReport.
protected ReportWithParams createParamsMapForReport(Report report, Map<String, Object> params) {
ReportWithParams reportWithParams = new ReportWithParams(report);
if (MapUtils.isNotEmpty(params)) {
Map<String, Object> paramsMap = new HashMap<>();
for (ReportInputParameter parameter : report.getInputParameters()) {
paramsMap.put(parameter.getAlias(), params.get(parameter.getAlias()));
}
reportWithParams.setParams(paramsMap);
}
return reportWithParams;
}
use of io.jmix.emailtemplates.dto.ReportWithParams in project jmix by jmix-framework.
the class EmailTemplatesImpl method getReportWithParams.
private ReportWithParams getReportWithParams(TemplateReport templateReport, List<ReportWithParams> parameters) throws ReportParameterTypeChangedException {
ReportWithParams bodyReportWithParams = parametersExtractor.getReportDefaultValues(templateReport.getReport(), templateReport.getParameterValues());
ReportWithParams bodyReportExternalParams = parameters.stream().filter(e -> e.getReport().equals(templateReport.getReport())).findFirst().orElse(null);
if (bodyReportExternalParams != null) {
for (String key : bodyReportExternalParams.getParams().keySet()) {
bodyReportWithParams.put(key, bodyReportExternalParams.getParams().get(key));
}
}
return bodyReportWithParams;
}
use of io.jmix.emailtemplates.dto.ReportWithParams 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;
}
Aggregations