if (reportFormat == ReportFormat.TRENDING) {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JasperScanReport(applicationIdList, scanDao, null));
} else if (reportFormat == ReportFormat.TWELVE_MONTH_SUMMARY) {
jasperPrint = getXMonthReport(applicationIdList, parameters, jasperReport, 12);
if (jasperPrint == null) {
return new ReportCheckResultBean(ReportCheckResult.NO_APPLICATIONS);
}
} else if (reportFormat == ReportFormat.MONTHLY_PROGRESS_REPORT) {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,
new JasperMonthlyScanReport(applicationIdList, scanDao));
} else if (reportFormat == ReportFormat.VULNERABILITY_PROGRESS_BY_TYPE) {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,
new JasperCWEReport(applicationIdList,vulnerabilityDao));
} else if (reportFormat == ReportFormat.CHANNEL_COMPARISON_SUMMARY) {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,
new JasperScannerComparisonReport(applicationIdList, vulnerabilityDao));
} else {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
}
if (jasperPrint == null) {
return null;
}
if(format.equals("PDF")) {
byte[] pdfByteArray = JasperExportManager.exportReportToPdf(jasperPrint);
if (pdfByteArray != null) {
return new ReportCheckResultBean(ReportCheckResult.VALID, null, pdfByteArray);
} else {
return null;
}
}
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER,
report);
exporter.setParameter(
JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR,
Boolean.FALSE);
String mapKey = getMapKey(reportFormat.ordinal(), applicationIdList);
Map<Object, Object> imagesMap = new HashMap<>();
request.getSession().setAttribute(mapKey, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(
JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,
Boolean.TRUE);
String imagesPath = request.getContextPath() + "/jasperimage/" + mapKey + "/";
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,
imagesPath);
exporter.exportReport();
} catch (JRException ex) {
log.error("Encountered a Jasper exception, the report was probably not exported correctly.",ex);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
log.warn("Failed to close an InputStream", e);
}
}
log.debug("Returning report.");
return new ReportCheckResultBean(ReportCheckResult.VALID, report, null);
}