Search in sources :

Example 1 with JRDesignParameter

use of net.sf.jasperreports.engine.design.JRDesignParameter 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 JRDesignParameter

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

the class MeasurementParameterFilterTest method createParameter.

private static JRParameter createParameter(String name) {
    JRDesignParameter parameter = new JRDesignParameter();
    parameter.setName(name);
    return parameter;
}
Also used : JRDesignParameter(net.sf.jasperreports.engine.design.JRDesignParameter)

Example 3 with JRDesignParameter

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

the class JasperReportDto method getTemplate.

public byte[] getTemplate() {
    try {
        //			design.remadgetFields().
        design.getFieldsList().clear();
        design.getParametersList().clear();
        design.getFieldsMap().clear();
        design.getParametersMap().clear();
        for (JasperReportFieldDto field : fields) {
            if (field.isEmpty()) {
                continue;
            }
            JRDesignField f = new JRDesignField();
            f.setValueClassName(field.getTypeAsString());
            f.setValueClass(Class.forName(field.getTypeAsString()));
            f.setName(field.getName());
            design.addField(f);
        }
        for (JasperReportParameterDto param : parameters) {
            if (param.isEmpty()) {
                continue;
            }
            JRDesignParameter p = new JRDesignParameter();
            p.setValueClassName(param.getTypeAsString());
            p.setValueClass(Class.forName(param.getTypeAsString()));
            p.setName(param.getName());
            p.setForPrompting(param.isForPrompting());
            p.setDescription(param.getDescription());
            p.setNestedTypeName(param.getNestedTypeAsString());
            p.setNestedType(param.getNestedType());
            p.getPropertiesMap().setBaseProperties(param.getJRProperties());
            //			p.getPropertiesMap().setProperty(propName, value);
            design.addParameter(p);
        }
        JasperDesign oldDesign = ReportTypeUtil.loadJasperDesign(jasperReportXml);
        oldDesign.getParametersList().clear();
        oldDesign.getParametersList().addAll(design.getParametersList());
        oldDesign.getFieldsList().clear();
        oldDesign.getFieldsList().addAll(design.getFieldsList());
        JRDesignQuery q = new JRDesignQuery();
        q.setLanguage("mql");
        q.setText(query);
        oldDesign.setQuery(q);
        String reportAsString = JRXmlWriter.writeReport(oldDesign, "UTF-8");
        return Base64.encodeBase64(reportAsString.getBytes("UTF-8"));
    } catch (JRException | ClassNotFoundException | SchemaException | UnsupportedEncodingException ex) {
        throw new IllegalStateException(ex.getMessage(), ex.getCause());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) JRException(net.sf.jasperreports.engine.JRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JRDesignField(net.sf.jasperreports.engine.design.JRDesignField) JRDesignParameter(net.sf.jasperreports.engine.design.JRDesignParameter) JRDesignQuery(net.sf.jasperreports.engine.design.JRDesignQuery)

Aggregations

JRDesignParameter (net.sf.jasperreports.engine.design.JRDesignParameter)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 JRException (net.sf.jasperreports.engine.JRException)2 JasperDesign (net.sf.jasperreports.engine.design.JasperDesign)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 JasperReport (net.sf.jasperreports.engine.JasperReport)1 JRDesignExpression (net.sf.jasperreports.engine.design.JRDesignExpression)1 JRDesignField (net.sf.jasperreports.engine.design.JRDesignField)1 JRDesignQuery (net.sf.jasperreports.engine.design.JRDesignQuery)1 JRDesignReportTemplate (net.sf.jasperreports.engine.design.JRDesignReportTemplate)1