use of net.sf.jasperreports.engine.JRTemplate in project midpoint by Evolveum.
the class ReportCreateTaskHandler method prepareReportParameters.
// private JasperReport loadJasperReport(ReportType reportType) throws SchemaException{
//
// if (reportType.getTemplate() == null) {
// throw new IllegalStateException("Could not create report. No jasper template defined.");
// }
// try {
// byte[] reportTemplate = Base64.decodeBase64(reportType.getTemplate());
//
// InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate);
// JasperDesign jasperDesign = JRXmlLoader.load(inputStreamJRXML);
// LOGGER.trace("load jasper design : {}", jasperDesign);
//
// if (reportType.getTemplateStyle() != null){
// JRDesignReportTemplate templateStyle = new JRDesignReportTemplate(new JRDesignExpression("$P{" + PARAMETER_TEMPLATE_STYLES + "}"));
// jasperDesign.addTemplate(templateStyle);
// JRDesignParameter parameter = new JRDesignParameter();
// parameter.setName(PARAMETER_TEMPLATE_STYLES);
// parameter.setValueClass(JRTemplate.class);
// parameter.setForPrompting(false);
// jasperDesign.addParameter(parameter);
// }
// JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
// return jasperReport;
// } catch (JRException ex){
// LOGGER.error("Couldn't create jasper report design {}", ex.getMessage());
// throw new SchemaException(ex.getMessage(), ex.getCause());
// }
//
//
// }
private Map<String, Object> prepareReportParameters(ReportType reportType, OperationResult parentResult) {
Map<String, Object> params = new HashMap<String, Object>();
if (reportType.getTemplateStyle() != null) {
byte[] reportTemplateStyleBase64 = reportType.getTemplateStyle();
byte[] reportTemplateStyle = Base64.decodeBase64(reportTemplateStyleBase64);
try {
LOGGER.trace("Style template string {}", new String(reportTemplateStyle));
InputStream inputStreamJRTX = new ByteArrayInputStream(reportTemplateStyle);
JRTemplate templateStyle = JRXmlTemplateLoader.load(inputStreamJRTX);
params.put(PARAMETER_TEMPLATE_STYLES, templateStyle);
LOGGER.trace("Style template parameter {}", templateStyle);
} catch (Exception ex) {
LOGGER.error("Error create style template parameter {}", ex.getMessage());
throw new SystemException(ex);
}
}
// for our special datasource
params.put(PARAMETER_REPORT_OID, reportType.getOid());
params.put(PARAMETER_OPERATION_RESULT, parentResult);
params.put(ReportService.PARAMETER_REPORT_SERVICE, reportService);
return params;
}
Aggregations