Skip to content

Commit

Permalink
#461 ignore comment lines in CSV files
Browse files Browse the repository at this point in the history
  • Loading branch information
hvohbt committed Dec 26, 2024
1 parent f8806ae commit 7fab685
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public List<DailyWorkingReportData> read(@Nullable Class<? extends List<DailyWor
@SneakyThrows
private static List<DailyWorkingReportData> fromRows(List<CsvRow> rows) {
return rows.stream()
.filter(not(CsvRow.EMPTY::equals))
.filter(not(DailyWorkingReportCsvConverter::isEmptyRow))
.collect(groupingBy(CsvRow::getDate)).entrySet().stream()
.map(entry -> Map.entry(getUniqueWorkingDayRow(entry.getKey(), entry.getValue()), entry.getValue()))
.map(entry -> DailyWorkingReportData.builder()
Expand All @@ -114,8 +114,11 @@ private static CsvRow getUniqueWorkingDayRow(LocalDate day, List<CsvRow> rows) {
return workingDayRows.getFirst();
}

private static boolean isEmptyRow(CsvRow row) {
return row.getDate() == null;
}

private static boolean isEmptyWorkingDayRow(CsvRow row) {
if(row.getDate() == null) return true; // date is empty
if(row.getType() == WorkingDayType.NOT_WORKED) return false; // only date required for NOT_WORKED

// if start time or break time is missing, it is considered empty for other work types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static Stream<Arguments> readCsv() {
Arguments.of(
"""
date,type,startTime,breakTime,employeeorderId,orderSign,orderLabel,suborderSign,suborderLabel,workingTime,comment
,,,,,,,,,,some comment
2024-11-04,WORKED,09:00,00:30,183209,111,Rumsitzen,111.01,Stuhlpolsterung,00:30,Team-Mittag
2024-11-04,,,,183209,111,Rumsitzen,111.01,Stuhlpolsterung,07:30,Daily
""",
Expand Down

0 comments on commit 7fab685

Please sign in to comment.