diff --git a/src/main/java/org/breedinginsight/services/parsers/excel/ExcelParser.java b/src/main/java/org/breedinginsight/services/parsers/excel/ExcelParser.java index bee8dae82..4536d4aa6 100644 --- a/src/main/java/org/breedinginsight/services/parsers/excel/ExcelParser.java +++ b/src/main/java/org/breedinginsight/services/parsers/excel/ExcelParser.java @@ -87,11 +87,24 @@ public static List parse(Sheet sheet, Set columns) throws P throw new ParsingException(ParsingExceptionType.EMPTY_ROW); } + // Flag for empty rows; for CSV, empty cells are empty string ("") rather than null. + boolean emptyRow = true; for(int colIndex=0; colIndex 0) + { + // There is at least one value in this row, set emptyRow flag false. + emptyRow = false; + } data.put(indexColNameMap.get(colIndex), cell); } + // If the row has no cells with values, skip it. + if (data.isEmpty() || emptyRow) + { + continue; + } + records.add(new ExcelRecord(data)); } diff --git a/src/test/java/org/breedinginsight/services/parsers/TraitFileParserUnitTest.java b/src/test/java/org/breedinginsight/services/parsers/TraitFileParserUnitTest.java index 17bd289b9..af195b790 100644 --- a/src/test/java/org/breedinginsight/services/parsers/TraitFileParserUnitTest.java +++ b/src/test/java/org/breedinginsight/services/parsers/TraitFileParserUnitTest.java @@ -334,4 +334,33 @@ void parseXlsxMultipleRowsSuccess() { assertEquals(3, traits.size(), "number of traits different than expected"); } + @Test + @SneakyThrows + void parseCsvNullRowsSuccess() { + File file = new File("src/test/resources/files/ontology/ontology_null_rows.csv"); + InputStream inputStream = new FileInputStream(file); + List traits = parser.parseCsv(inputStream); + + assertEquals(3, traits.size(), "number of traits different than expected"); + } + + @Test + @SneakyThrows + void parseXlsNullRowsSuccess() { + File file = new File("src/test/resources/files/ontology/ontology_null_rows.xls"); + InputStream inputStream = new FileInputStream(file); + List traits = parser.parseExcel(inputStream); + + assertEquals(3, traits.size(), "number of traits different than expected"); + } + + @Test + @SneakyThrows + void parseXlsxNullRowsSuccess() { + File file = new File("src/test/resources/files/ontology/ontology_null_rows.xlsx"); + InputStream inputStream = new FileInputStream(file); + List traits = parser.parseExcel(inputStream); + + assertEquals(3, traits.size(), "number of traits different than expected"); + } } diff --git a/src/test/resources/files/ontology/ontology_null_rows.csv b/src/test/resources/files/ontology/ontology_null_rows.csv new file mode 100644 index 000000000..975f648ae --- /dev/null +++ b/src/test/resources/files/ontology/ontology_null_rows.csv @@ -0,0 +1,8 @@ +Name,Full Name,Term Type,Description,Synonyms,Status,Tags,Trait Entity,Trait Attribute,Method Description,Method Class,Method Formula,Scale Class,Units,Scale Decimal Places,Scale Lower Limit,Scale Upper Limit,Scale Categories +Pheno 1,,,Pheno 1,,,,Pheno,1,,Measurement,,Numerical,cm,,,, +Pheno 2,,,Pheno 2,,,,Pheno,2,,Measurement,,Numerical,ug/ml,,,, +Pheno 3,,,Pheno 3,,,,Pheno,3,,Observation,,Date,,,,, +,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,, \ No newline at end of file diff --git a/src/test/resources/files/ontology/ontology_null_rows.xls b/src/test/resources/files/ontology/ontology_null_rows.xls new file mode 100644 index 000000000..5c5adf1f6 Binary files /dev/null and b/src/test/resources/files/ontology/ontology_null_rows.xls differ diff --git a/src/test/resources/files/ontology/ontology_null_rows.xlsx b/src/test/resources/files/ontology/ontology_null_rows.xlsx new file mode 100644 index 000000000..3ecc30358 Binary files /dev/null and b/src/test/resources/files/ontology/ontology_null_rows.xlsx differ