Search in sources :

Example 1 with JRTemplate

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;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JRTemplate(net.sf.jasperreports.engine.JRTemplate) PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) JRException(net.sf.jasperreports.engine.JRException)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 JRException (net.sf.jasperreports.engine.JRException)1 JRTemplate (net.sf.jasperreports.engine.JRTemplate)1