private ReportOutputSearchDto createSearchDto() { ReportOutputSearchDto dto = new ReportOutputSearchDto(); Map<String, String> reportTypeMap = dto.getReportTypeMap(); List<PrismObject<ReportType>> reportTypes = WebModelUtils.searchObjects(ReportType.class, null, null, getPageBase()); LOGGER.debug("Found {} report types.", reportTypes.size()); for (PrismObject o : reportTypes) { ReportType reportType = (ReportType) o.asObjectable(); if (reportType.isParent()) { String name = WebMiscUtil.getName(o); reportTypeMap.put(name, reportType.getOid()); } } StringValue param = getPage().getPageParameters().get(OnePageParameterEncoder.PARAMETER); if (param != null) { for (String key : dto.getReportTypeMap().keySet()) { if (reportTypeMap.get(key).equals(param.toString())) { dto.setReportType(key); } } } return dto; }
public static InputStream createReport( ReportOutputType report, AjaxDownloadBehaviorFromStream ajaxDownloadBehaviorFromStream, PageBase pageBase) { OperationResult result = new OperationResult(OPERATION_DOWNLOAD_REPORT); ReportManager reportManager = pageBase.getReportManager(); if (report == null) { return null; } String contentType = reportExportTypeMap.get(report.getExportType()); if (StringUtils.isEmpty(contentType)) { contentType = "multipart/mixed; charset=UTF-8"; } ajaxDownloadBehaviorFromStream.setContentType(contentType); InputStream input = null; try { input = reportManager.getReportOutputData(report.getOid(), result); } catch (Exception e) { pageBase.error( pageBase.getString("pageCreatedReports.message.downloadError") + " " + e.getMessage()); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't download report.", e); LOGGER.trace(result.debugDump()); } finally { result.computeStatusIfUnknown(); } if (WebComponentUtil.showResultInPage(result)) { pageBase.showResult(result); } return input; }
static { reportExportTypeMap.put(ExportType.CSV, "text/csv; charset=UTF-8"); reportExportTypeMap.put( ExportType.DOCX, "application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=UTF-8"); reportExportTypeMap.put(ExportType.HTML, "text/html; charset=UTF-8"); reportExportTypeMap.put( ExportType.ODS, "application/vnd.oasis.opendocument.spreadsheet; charset=UTF-8"); reportExportTypeMap.put( ExportType.ODT, "application/vnd.oasis.opendocument.text; charset=UTF-8"); reportExportTypeMap.put(ExportType.PDF, "application/pdf; charset=UTF-8"); reportExportTypeMap.put( ExportType.PPTX, "application/vnd.openxmlformats-officedocument.presentationml.presentation; charset=UTF-8"); reportExportTypeMap.put(ExportType.RTF, "application/rtf; charset=UTF-8"); reportExportTypeMap.put(ExportType.XHTML, "application/xhtml+xml; charset=UTF-8"); reportExportTypeMap.put(ExportType.XLS, "application/vnd.ms-excel; charset=UTF-8"); reportExportTypeMap.put( ExportType.XLSX, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8"); reportExportTypeMap.put(ExportType.XML, "application/xml; charset=UTF-8"); reportExportTypeMap.put(ExportType.XML_EMBED, "text/xml; charset=UTF-8"); }