Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,24 @@ public static List<ExcelRecord> parse(Sheet sheet, Set<String> 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<row.getLastCellNum(); colIndex++) {
Cell cell = row.getCell(colIndex);
if (cell != null && cell.toString().length() > 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));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Trait> 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<Trait> 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<Trait> traits = parser.parseExcel(inputStream);

assertEquals(3, traits.size(), "number of traits different than expected");
}
}
8 changes: 8 additions & 0 deletions src/test/resources/files/ontology/ontology_null_rows.csv
Original file line number Diff line number Diff line change
@@ -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,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
Binary file not shown.
Binary file not shown.