ProcurementActivityByYearController extends ExcelChartOCDSController { @ApiOperation(value = "Exports *Procurement activity by year* dashboard in Excel format.") @RequestMapping(value = "/api/ocds/procurementActivityExcelChart", method = {RequestMethod.GET, RequestMethod.POST}) public void procurementActivityExcelChart(@ModelAttribute @Valid final LangYearFilterPagingRequest filter, final HttpServletResponse response) throws IOException { final String chartTitle = translationService.getValue(filter.getLanguage(), "charts:overview:title"); final List<DBObject> countAwardsByYear = countPlansTendersAwardsController.countAwardsByYear(filter); final List<DBObject> countTendersByYear = countPlansTendersAwardsController.countTendersByYear(filter); final List<DBObject> countBidPlansByYear = countPlansTendersAwardsController.countBidPlansByYear(filter); final List<?> categories = excelChartHelper.getCategoriesFromDBObject( getExportYearMonthXAxis(filter), countAwardsByYear, countTendersByYear, countBidPlansByYear); final List<List<? extends Number>> values = new ArrayList<>(); final List<Number> valueAwards = excelChartHelper.getValuesFromDBObject(countAwardsByYear, categories, getExportYearMonthXAxis(filter), CountPlansTendersAwardsController.Keys.COUNT); final List<Number> valueTenders = excelChartHelper.getValuesFromDBObject(countTendersByYear, categories, getExportYearMonthXAxis(filter), CountPlansTendersAwardsController.Keys.COUNT); final List<Number> valueBidPlans = excelChartHelper.getValuesFromDBObject(countBidPlansByYear, categories, getExportYearMonthXAxis(filter), CountPlansTendersAwardsController.Keys.COUNT); if (!valueAwards.isEmpty()) { values.add(valueAwards); } if (!valueTenders.isEmpty()) { values.add(valueTenders); } if (!valueBidPlans.isEmpty()) { values.add(valueBidPlans); } final List<String> seriesTitle; if (!values.isEmpty()) { seriesTitle = Arrays.asList( translationService.getValue(filter.getLanguage(), "charts:overview:traces:award"), translationService.getValue(filter.getLanguage(), "charts:overview:traces:tender"), translationService.getValue(filter.getLanguage(), "charts:overview:traces:bidplan")); } else { seriesTitle = new ArrayList<>(); } response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=" + chartTitle + ".xlsx"); response.getOutputStream().write( excelChartGenerator.getExcelChart( ChartType.line, chartTitle, seriesTitle, categories, values)); }  @ApiOperation(value = "Exports *Procurement activity by year* dashboard in Excel format.") @RequestMapping(value = "/api/ocds/procurementActivityExcelChart", method = {RequestMethod.GET, RequestMethod.POST}) void procurementActivityExcelChart(@ModelAttribute @Valid final LangYearFilterPagingRequest filter,
                                              final HttpServletResponse response);  }
@Test public void procurementActivityExcelChart() throws Exception { LangYearFilterPagingRequest filter = getLangYearFilterMockRequest(); procurementActivityByYearController.procurementActivityExcelChart( filter, mockHttpServletResponse); final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray(); final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput)); Assert.assertNotNull(workbook); final Sheet sheet = workbook.getSheet(ChartType.line.toString()); Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet); final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch(); final List<XSSFChart> charts = drawing.getCharts(); Assert.assertEquals("number of charts", 1, charts.size()); final XSSFChart chart = charts.get(0); Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:overview:title"), chart.getTitle().getString()); final List<? extends XSSFChartAxis> axis = chart.getAxis(); Assert.assertEquals("number of axis", 2, axis.size()); final CTChart ctChart = chart.getCTChart(); Assert.assertEquals("Check if we have 1 line chart", 1, ctChart.getPlotArea().getLineChartArray().length); }