@Test void testWriteToExcelTooManyCells() throws Exception { when(dataService.count("sys_set_thousandgenomes", query)).thenReturn(2500001L); when(dataService.getEntityType("sys_set_thousandgenomes")).thenReturn(entityType); when(entityType.getAtomicAttributes()).thenReturn(asList(attribute1, attribute2, attribute3)); when(attribute1.getName()).thenReturn("attr1"); when(attribute2.getName()).thenReturn("attr2"); when(attribute3.getName()).thenReturn("attr3"); DataRequest dataRequest = new DataRequest(); dataRequest.setEntityName("sys_set_thousandgenomes"); dataRequest.setQuery(query); dataRequest.setAttributeNames(asList("attr1", "attr2")); dataRequest.setColNames(DataRequest.ColNames.ATTRIBUTE_NAMES); dataRequest.setEntityValues(DataRequest.EntityValues.ENTITY_LABELS); Exception exception = assertThrows( MolgenisDataException.class, () -> dataExplorerDownloadHandler.writeToExcel(dataRequest, mock(OutputStream.class))); assertThat(exception.getMessage()) .containsPattern( "Total number of cells for this download exceeds the maximum of 500000 for .xlsx downloads, please use .csv instead"); }
public void writeToExcel(DataRequest dataRequest, OutputStream outputStream) throws IOException { String entityTypeId = dataRequest.getEntityName(); List<Attribute> attributes = filterAttributes(dataRequest); checkNumberOfCells(dataRequest, entityTypeId, attributes.size()); AttributeWriteMode attributeWriteMode = getAttributeWriteMode(dataRequest.getColNames()); try (ExcelWriter excelWriter = new ExcelWriter(outputStream, attrMetaFactory, FileFormat.XLSX); ExcelSheetWriter excelSheetWriter = excelWriter.createWritable(entityTypeId, attributes, attributeWriteMode)) { excelSheetWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues())); excelSheetWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery())); } }
DataExplorerDownloadHandler { public void writeToExcel(DataRequest dataRequest, OutputStream outputStream) throws IOException { String entityTypeId = dataRequest.getEntityName(); List<Attribute> attributes = filterAttributes(dataRequest); checkNumberOfCells(dataRequest, entityTypeId, attributes.size()); AttributeWriteMode attributeWriteMode = getAttributeWriteMode(dataRequest.getColNames()); try (ExcelWriter excelWriter = new ExcelWriter(outputStream, attrMetaFactory, FileFormat.XLSX); ExcelSheetWriter excelSheetWriter = excelWriter.createWritable(entityTypeId, attributes, attributeWriteMode)) { excelSheetWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues())); excelSheetWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery())); } } }
DataExplorerDownloadHandler { public void writeToExcel(DataRequest dataRequest, OutputStream outputStream) throws IOException { String entityTypeId = dataRequest.getEntityName(); List<Attribute> attributes = filterAttributes(dataRequest); checkNumberOfCells(dataRequest, entityTypeId, attributes.size()); AttributeWriteMode attributeWriteMode = getAttributeWriteMode(dataRequest.getColNames()); try (ExcelWriter excelWriter = new ExcelWriter(outputStream, attrMetaFactory, FileFormat.XLSX); ExcelSheetWriter excelSheetWriter = excelWriter.createWritable(entityTypeId, attributes, attributeWriteMode)) { excelSheetWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues())); excelSheetWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery())); } } DataExplorerDownloadHandler(DataService dataService, AttributeFactory attrMetaFactory); }
DataExplorerDownloadHandler { public void writeToExcel(DataRequest dataRequest, OutputStream outputStream) throws IOException { String entityTypeId = dataRequest.getEntityName(); List<Attribute> attributes = filterAttributes(dataRequest); checkNumberOfCells(dataRequest, entityTypeId, attributes.size()); AttributeWriteMode attributeWriteMode = getAttributeWriteMode(dataRequest.getColNames()); try (ExcelWriter excelWriter = new ExcelWriter(outputStream, attrMetaFactory, FileFormat.XLSX); ExcelSheetWriter excelSheetWriter = excelWriter.createWritable(entityTypeId, attributes, attributeWriteMode)) { excelSheetWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues())); excelSheetWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery())); } } DataExplorerDownloadHandler(DataService dataService, AttributeFactory attrMetaFactory); void writeToExcel(DataRequest dataRequest, OutputStream outputStream); void writeToCsv(DataRequest request, OutputStream outputStream, char separator); void writeToCsv(
      DataRequest dataRequest, OutputStream outputStream, char separator, boolean noQuotes); }
DataExplorerDownloadHandler { public void writeToExcel(DataRequest dataRequest, OutputStream outputStream) throws IOException { String entityTypeId = dataRequest.getEntityName(); List<Attribute> attributes = filterAttributes(dataRequest); checkNumberOfCells(dataRequest, entityTypeId, attributes.size()); AttributeWriteMode attributeWriteMode = getAttributeWriteMode(dataRequest.getColNames()); try (ExcelWriter excelWriter = new ExcelWriter(outputStream, attrMetaFactory, FileFormat.XLSX); ExcelSheetWriter excelSheetWriter = excelWriter.createWritable(entityTypeId, attributes, attributeWriteMode)) { excelSheetWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues())); excelSheetWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery())); } } DataExplorerDownloadHandler(DataService dataService, AttributeFactory attrMetaFactory); void writeToExcel(DataRequest dataRequest, OutputStream outputStream); void writeToCsv(DataRequest request, OutputStream outputStream, char separator); void writeToCsv(
      DataRequest dataRequest, OutputStream outputStream, char separator, boolean noQuotes);  }