use of net.sf.jasperreports.engine.JRException 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());
}
}
use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.
the class JasperReportService method compileReport.
/**
* Compiles the given {@link JasperDesign} (*.jrxml) to a {@link JasperReport} (*.jasper)
*
* @param jasperDesign The Design (*.jrxml) to compile
* @return The compiled report (*.jasper)
* @throws ReportException If the design could not be compiled.
*/
private JasperReport compileReport(JasperDesign jasperDesign) throws ReportException {
try {
JasperReport report;
// If the target report is written in Java, use our custom JDT compiler
if (JRReport.LANGUAGE_JAVA.equals(jasperDesign.getLanguage())) {
JasperReportsContext reportsContext = new SimpleJasperReportsContext();
JRPropertiesUtil.getInstance(reportsContext).setProperty(JRCompiler.COMPILER_PREFIX + JRReport.LANGUAGE_JAVA, CustomJRJdtCompiler.class.getCanonicalName());
JasperCompileManager jasperCompilerManager = JasperCompileManager.getInstance(reportsContext);
report = jasperCompilerManager.compile(jasperDesign);
} else {
// Otherwise, use the default that Jasper providers
report = JasperCompileManager.compileReport(jasperDesign);
}
for (Object eachKey : System.getProperties().keySet()) {
String eachStringKey = (String) eachKey;
if (eachStringKey.startsWith("net.sf.jasperreports")) {
report.setProperty(eachStringKey, System.getProperty(eachStringKey));
}
}
compileSubreportsRecursively(report);
return report;
} catch (final JRException e) {
LOG.error("unable to compile jasper report {}", e);
throw new ReportException("unable to compile jasperReport", e);
}
}
use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.
the class AbstractMeasurementQueryExecutorTest method fill.
protected JasperPrint fill(final JasperReport jasperReport, final ReportFiller filler) throws JRException {
try {
Map<String, Object> params = new HashMap<String, Object>();
filler.fill(params);
return JasperFillManager.fillReport(jasperReport, params);
} catch (Exception ex) {
if (ex instanceof JRException) {
throw (JRException) ex;
}
throw new JRException(ex);
}
}
use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.
the class LocalMeasurementDataSourceWrapper method createDataSource.
@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
Objects.requireNonNull(query);
QueryRequest queryRequest = unmarshal(query);
Objects.requireNonNull(queryRequest);
// Enforce relaxed mode
queryRequest.setRelaxed(true);
try {
QueryResponse response = fetchService.query(queryRequest);
return new MeasurementDataSource(response);
} catch (ResourceNotFoundException rnfe) {
LOG.warn("A attribute or resource was not found", rnfe);
return new EmptyJRDataSource();
} catch (Exception e) {
LOG.error("An error occurred while fetching the measurement results", e);
throw new JRException(e);
}
}
use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.
the class RemoteMeasurementDataSourceWrapper method createDataSource.
@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
try {
QueryRequest queryRequest = unmarshal(query);
// enforce relaxed mode
queryRequest.setRelaxed(true);
query = marshal(queryRequest);
Result result = connector.execute(useSsl, url, username, password, query);
// therefore do not allow redirection at all.
if (result.wasRedirection()) {
throw new IOException("Request was redirected. This is not supported.");
}
// if there is no data
if (404 == result.getResponseCode()) {
LOG.warn("Got a 404 (Not Found) response. This might be due to a wrong url or the resource does not exist. Requested URL was: '{}'", url);
return new EmptyJRDataSource();
}
// OK
if (result.wasSuccessful() && result.getInputStream() != null) {
return new MeasurementDataSource(result.getInputStream());
}
// Error
ByteArrayOutputStream errorMessageStream = new ByteArrayOutputStream();
if (result.getErrorStream() != null) {
ByteStreams.copy(result.getErrorStream(), errorMessageStream);
}
throw new JRException("Invalid request. Response was : " + result.getResponseCode() + " (" + result.getResponseMessage() + ")\n" + errorMessageStream.toString());
} catch (IOException ioException) {
throw new JRException(ioException);
}
}
Aggregations