Search in sources :

Example 1 with JRDesignExpression

use of net.sf.jasperreports.engine.design.JRDesignExpression in project midpoint by Evolveum.

the class ReportTypeUtil method loadJasperReport.

public static 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);
        //JRXmlLoader.load(inputStreamJRXML);
        JasperDesign jasperDesign = loadJasperDesign(reportType.getTemplate());
        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);
        }
        //			 if (StringUtils.isNotEmpty(finalQuery)){
        JRDesignParameter parameter = new JRDesignParameter();
        parameter.setName("finalQuery");
        parameter.setValueClass(Object.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());
    }
}
Also used : JRDesignExpression(net.sf.jasperreports.engine.design.JRDesignExpression) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) JRException(net.sf.jasperreports.engine.JRException) JRDesignReportTemplate(net.sf.jasperreports.engine.design.JRDesignReportTemplate) JRDesignParameter(net.sf.jasperreports.engine.design.JRDesignParameter) JasperReport(net.sf.jasperreports.engine.JasperReport)

Example 2 with JRDesignExpression

use of net.sf.jasperreports.engine.design.JRDesignExpression in project opennms by OpenNMS.

the class JasperReportServiceTest method testEvaluateToString.

@Test
public void testEvaluateToString() throws JRException {
    final JasperReport report = JasperCompileManager.compileReport(getClass().getResourceAsStream("/etc/report-templates/subreport-expression-visitor-test.jrxml"));
    Assert.assertEquals("/home/ulf/opennms-reports", JasperReportService.evaluateToString(report, new JRDesignExpression("$P{ONMS_REPORT_DIR}")));
    Assert.assertEquals("/home/ulf/opennms-reports/subreports/", JasperReportService.evaluateToString(report, new JRDesignExpression("$P{SUBREPORT_DIR}")));
    Assert.assertEquals("This is a test with number 10", JasperReportService.evaluateToString(report, new JRDesignExpression("$P{COMPLEX}")));
}
Also used : JRDesignExpression(net.sf.jasperreports.engine.design.JRDesignExpression) JasperReport(net.sf.jasperreports.engine.JasperReport) Test(org.junit.Test)

Aggregations

JasperReport (net.sf.jasperreports.engine.JasperReport)2 JRDesignExpression (net.sf.jasperreports.engine.design.JRDesignExpression)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 JRException (net.sf.jasperreports.engine.JRException)1 JRDesignParameter (net.sf.jasperreports.engine.design.JRDesignParameter)1 JRDesignReportTemplate (net.sf.jasperreports.engine.design.JRDesignReportTemplate)1 JasperDesign (net.sf.jasperreports.engine.design.JasperDesign)1 Test (org.junit.Test)1