use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.
the class MeasurementQueryExecutorRemoteIT method testReportHwForecast.
@Test
public void testReportHwForecast() throws IOException, JRException {
createReport("Forecast", new ReportFiller() {
@Override
public void fill(Map<String, Object> params) throws Exception {
params.put(JRParameter.IS_IGNORE_PAGINATION, true);
params.put("MEASUREMENT_URL", "http://localhost:9999/opennms/rest/measurements");
params.put("dsName", "ifInOctets");
params.put("startDate", "1414602000000");
params.put("endDate", "1417046400000");
}
});
// Verify the results of the generated report
Table<Integer, String, Double> forecasts = TreeBasedTable.create();
FileReader reader = new FileReader(createFileName("Forecast", "csv"));
CSVParser parser = new CSVParser(reader, CSVFormat.RFC4180.withHeader());
int k = 0;
for (CSVRecord record : parser) {
try {
Double fit = Double.parseDouble(record.get("HWFit"));
Double lwr = Double.parseDouble(record.get("HWLwr"));
Double upr = Double.parseDouble(record.get("HWUpr"));
if (Double.isNaN(fit)) {
continue;
}
forecasts.put(k, "fit", fit);
forecasts.put(k, "lwr", lwr);
forecasts.put(k, "upr", upr);
k++;
} catch (NumberFormatException e) {
// pass
}
}
Assert.assertEquals(340, forecasts.rowKeySet().size());
// First fitted value
Assert.assertEquals(432.526086422424, forecasts.get(0, "fit"), 0.00001);
// Last fitted value for which there is a known data point
Assert.assertEquals(24079.4692522087, forecasts.get(327, "fit"), 0.00001);
// First forecasted value
Assert.assertEquals(22245.5417010936, forecasts.get(328, "fit"), 0.00001);
}
use of net.sf.jasperreports.engine.JRException in project opennms by OpenNMS.
the class DefaultReportService method runReport.
/** {@inheritDoc}
* @throws ReportRunException */
@Override
public synchronized String runReport(Report report, String reportDirectory) throws ReportRunException {
String outputFile = null;
try {
outputFile = generateReportName(reportDirectory, report.getReportName(), report.getReportFormat());
JasperPrint print = runAndRender(report);
outputFile = saveReport(print, report, outputFile);
} catch (JRException e) {
LOG.error("Error running report: {}", e.getMessage(), e);
throw new ReportRunException("Caught JRException: " + e.getMessage());
} catch (Throwable e) {
LOG.error("Unexpected exception: {}", e.getMessage(), e);
throw new ReportRunException("Caught unexpected " + e.getClass().getName() + ": " + e.getMessage());
}
return outputFile;
}
use of net.sf.jasperreports.engine.JRException in project Asqatasun by Asqatasun.
the class AuditExportResultController method prepareSuccessfullAuditDataToExport.
/**
*
* @param page
* @param model
* @param locale
* @param exportFormat
* @param request
* @param response
* @return
* @throws IOException
*/
private void prepareSuccessfullAuditDataToExport(WebResource webResource, Model model, Locale locale, String exportFormat, HttpServletRequest request, HttpServletResponse response) throws NotSupportedExportFormatException {
model.addAttribute(TgolKeyStore.LOCALE_KEY, locale);
Scope scope = getSiteScope();
if (webResource instanceof Page) {
scope = getPageScope();
}
List<TestResult> testResultList = TestResultFactory.getInstance().getTestResultList(webResource, scope, getLocaleResolver().resolveLocale(request));
AuditStatistics auditStatistics = getAuditStatistics(webResource, model, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE, //TODO a revoir dans le cas manuel
false);
model.addAttribute(TgolKeyStore.STATISTICS_KEY, auditStatistics);
try {
exportService.export(response, webResource.getId(), auditStatistics, testResultList, locale, exportFormat);
} catch (ColumnBuilderException | ClassNotFoundException | JRException ex) {
LOGGER.error(ex);
}
}
use of net.sf.jasperreports.engine.JRException in project midpoint by Evolveum.
the class JasperReports method getData.
public static byte[] getData(JasperPrint print) {
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
try {
exporter.exportReport();
} catch (JRException e) {
e.printStackTrace();
}
return os.toByteArray();
}
use of net.sf.jasperreports.engine.JRException 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());
}
}
Aggregations