@Override public void export(OutputStream output) throws Exception { try { final GlobalExportData data = prepareData(); ExportTemplate template = null; switch (exportFormat) { case XLS: { template = new GlobalExportExcelTemplate(data); } break; case ODS: { template = new GlobalExportCalcTemplate(data); } break; default: LOG.error("[export] The export format '" + exportFormat + "' is unknown."); throw new ServletException("The export format '" + exportFormat + "' is unknown."); } template.write(output); } catch (Throwable e) { LOG.error("[export] Error during the workbook writing.", e); throw new Exception("Error during the workbook writing."); } }
@Override public void export(OutputStream output) throws Exception { // The project id. final String idString = requireParameter(RequestParameter.ID); final Integer projectId; try { projectId = Integer.parseInt(idString); } catch (NumberFormatException e) { LOG.error("[export] The id '" + idString + "' is invalid.", e); throw new Exception("The id '" + idString + "' is invalid.", e); } try { // data final ProjectSynthesisData synthesisData = prepareSynthesisData(projectId); LogFrameExportData logFrameData = null; IndicatorEntryData indicatorData = null; // appending options final String typeString = requireParameter(RequestParameter.TYPE); final ExportUtils.ExportType type = ExportUtils.ExportType.valueOfOrNull(typeString); switch (type) { case PROJECT_SYNTHESIS_LOGFRAME: { final Project project = injector.getInstance(EntityManager.class).find(Project.class, projectId); logFrameData = SpreadsheetDataUtil.prepareLogFrameData(project, this); } break; case PROJECT_SYNTHESIS_INDICATORS: { indicatorData = SpreadsheetDataUtil.prepareIndicatorsData(projectId, this); } break; case PROJECT_SYNTHESIS_LOGFRAME_INDICATORS: { // logframe data final Project project = injector.getInstance(EntityManager.class).find(Project.class, projectId); logFrameData = SpreadsheetDataUtil.prepareLogFrameData(project, this); logFrameData.setIndicatorsSheetExist(true); // indicator data indicatorData = SpreadsheetDataUtil.prepareIndicatorsData(projectId, this); } break; default: // TODO Throw exception ? break; } ExportTemplate template = null; switch (exportFormat) { case XLS: { final HSSFWorkbook wb = new HSSFWorkbook(); template = new ProjectSynthesisExcelTemplate( synthesisData, wb, getContext(), getI18ntranslator(), getLanguage()); if (logFrameData != null) template = new LogFrameExcelTemplate(logFrameData, wb); if (indicatorData != null) template = new IndicatorEntryExcelTemplate(indicatorData, wb); } break; case ODS: { final SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument(); template = new ProjectSynthesisCalcTemplate( synthesisData, doc, getContext(), getI18ntranslator(), getLanguage()); if (logFrameData != null) template = new LogFrameCalcTemplate(logFrameData, doc); if (indicatorData != null) template = new IndicatorEntryCalcTemplate(indicatorData, doc); } break; default: LOG.error("[export] The export format '" + exportFormat + "' is unknown."); throw new ServletException("The export format '" + exportFormat + "' is unknown."); } template.write(output); } catch (Throwable e) { LOG.error("[export] Error during the workbook writing.", e); throw new Exception("Error during the workbook writing.", e); } }