Skip to content

Commit

Permalink
csv: add start and end time to csv export (#866)
Browse files Browse the repository at this point in the history
Here are some things you should have thought about:

**Multi-Tenancy**
- [ ] Extended new entities with `AbstractTenantAwareEntity`?
- [ ] New entity added to `TenantAwareDatabaseConfiguration`?
- [ ] Tested with `dev-multitenant` profile?

closes #639 

<!--

Thanks for contributing to the zeiterfassung.
Please review the following notes before submitting you pull request.

Please look for other issues or pull requests which already work on this
topic. Is somebody already on it? Do you need to synchronize?

# Security Vulnerabilities

🛑 STOP! 🛑 If your contribution fixes a security vulnerability, please do
not submit it.
Instead, please write an E-Mail to [email protected] with all the
information
to recreate the security vulnerability.

# Describing Your Changes

If, having reviewed the notes above, you're ready to submit your pull
request, please
provide a brief description of the proposed changes.

If they:
🐞 fix a bug, please describe the broken behaviour and how the changes
fix it.
    Please label with 'type: bug' and 'status: new'
    
🎁 make an enhancement, please describe the new functionality and why you
believe it's useful.
    Please label with 'type: enhancement' and 'status: new'
 
If your pull request relates to any existing issues,
please reference them by using the issue number prefixed with #.

-->
  • Loading branch information
derTobsch authored Oct 2, 2024
2 parents c698512 + 3b9600e commit 95ca583
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.PrintWriter;
import java.text.NumberFormat;
import java.time.LocalTime;
import java.time.Month;
import java.time.Year;
import java.time.YearMonth;
Expand Down Expand Up @@ -74,11 +75,13 @@ private void writeHeader(Locale locale, PrintWriter writer) {
final String date = messageSource.getMessage("report.csv.header.date", new Object[]{}, locale);
final String givenName = messageSource.getMessage("report.csv.header.person.givenName", new Object[]{}, locale);
final String familyName = messageSource.getMessage("report.csv.header.person.familyName", new Object[]{}, locale);
final String start = messageSource.getMessage("report.csv.header.start", new Object[]{}, locale);
final String end = messageSource.getMessage("report.csv.header.end", new Object[]{}, locale);
final String workedHours = messageSource.getMessage("report.csv.header.workedHours", new Object[]{}, locale);
final String comment = messageSource.getMessage("report.csv.header.comment", new Object[]{}, locale);
final String isBreak = messageSource.getMessage("report.csv.header.break", new Object[]{}, locale);

writer.println(String.format("%s;%s;%s;%s;%s;%s", date, givenName, familyName, workedHours, comment, isBreak));
writer.println(String.format("%s;%s;%s;%s;%s;%s;%s;%s", date, givenName, familyName, start, end, workedHours, comment, isBreak));
}

private void writeWeek(ReportWeek reportWeek, Locale locale, PrintWriter writer) {
Expand All @@ -99,10 +102,12 @@ private String reportDayEntryToCsvLine(ReportDayEntry reportDayEntry, NumberForm
final String date = dateFormatter.formatDate(reportDayEntry.start().toLocalDate());
final String givenName = reportDayEntry.user().givenName();
final String familyName = reportDayEntry.user().familyName();
final LocalTime start = reportDayEntry.start().toLocalTime();
final LocalTime end = reportDayEntry.end().toLocalTime();
final String hoursWorked = numberFormat.format(reportDayEntry.workDuration().hoursDoubleValue());
final String comment = reportDayEntry.comment();
final boolean isBreak = reportDayEntry.isBreak();

return String.format("%s;%s;%s;%s;%s;%s", date, givenName, familyName, hoursWorked, comment, isBreak);
return String.format("%s;%s;%s;%s;%s;%s;%s;%s", date, givenName, familyName, start, end, hoursWorked, comment, isBreak);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ report.weekly.csv.filename=zeiterfassung-bericht-{0,number,#}-kw{1}.csv
report.csv.header.date=Datum
report.csv.header.person.givenName=Vorname
report.csv.header.person.familyName=Nachname
report.csv.header.start=Von
report.csv.header.end=Bis
report.csv.header.workedHours=erfasste Stunden
report.csv.header.comment=Kommentar
report.csv.header.break=Pause
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ report.weekly.csv.filename=zeiterfassung-report-{0,number,#}-kw{1}.csv
report.csv.header.date=Date
report.csv.header.person.givenName=Given name
report.csv.header.person.familyName=Family name
report.csv.header.start=From
report.csv.header.end=To
report.csv.header.workedHours=Worked hours
report.csv.header.comment=Comment
report.csv.header.break=Break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ReportCsvServiceIT extends SingleTenantTestContainersBase {
private UserManagementService userManagementService;

@ParameterizedTest
@CsvSource({"de,Datum;Vorname;Nachname;erfasste Stunden;Kommentar;Pause", "en,Date;Given name;Family name;Worked hours;Comment;Break"})
@CsvSource({"de,Datum;Vorname;Nachname;Von;Bis;erfasste Stunden;Kommentar;Pause", "en,Date;Given name;Family name;From;To;Worked hours;Comment;Break"})
void ensureI18nHeader(String languageTag, String expectedHeader) {
final PrintWriter printWriter = mock(PrintWriter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void ensureWeekReportCsvWithEmptyReport() {
sut.writeWeekReportCsv(Year.of(2021), 1, Locale.GERMAN, new UserId("batman"), printWriter);

assertThat(stringWriter).hasToString("""
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
""");
}

Expand Down Expand Up @@ -103,8 +103,8 @@ void ensureWeekReportCsvRoundsWorkedHoursToTwoDigit() {
sut.writeWeekReportCsv(Year.of(2021), 1, Locale.GERMAN, batmanId, printWriter);

assertThat(stringWriter).hasToString("""
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;0,500;hard work;false
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;10:00;10:30;0,500;hard work;false
""");
}

Expand Down Expand Up @@ -143,10 +143,10 @@ void ensureWeekReportCsvContainsSummarizedInfoPerDay() {
sut.writeWeekReportCsv(Year.of(2021), 1, Locale.GERMAN, batmanId, printWriter);

assertThat(stringWriter).hasToString("""
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;1,000;hard work;false
04.01.2021;Bruce;Wayne;1,000;hard work;false
05.01.2021;Bruce;Wayne;8,000;hard work;false
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;10:00;11:00;1,000;hard work;false
04.01.2021;Bruce;Wayne;14:00;15:00;1,000;hard work;false
05.01.2021;Bruce;Wayne;09:00;17:00;8,000;hard work;false
""");
}

Expand All @@ -166,7 +166,7 @@ void ensureMonthReportCsvWithEmptyReport() {
sut.writeMonthReportCsv(YearMonth.of(2021, 1), Locale.GERMAN, new UserId("batman"), printWriter);

assertThat(stringWriter).hasToString("""
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
""");
}

Expand Down Expand Up @@ -200,8 +200,8 @@ void ensureMonthReportCsvRoundsWorkedHoursToTwoDigit() {
sut.writeMonthReportCsv(YearMonth.of(2021, 1), Locale.GERMAN, batmanId, printWriter);

assertThat(stringWriter).hasToString("""
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;0,500;hard work;false
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;10:00;10:30;0,500;hard work;false
""");
}

Expand Down Expand Up @@ -245,10 +245,10 @@ void ensureMonthReportCsvContainsSummarizedInfoPerDay() {
sut.writeMonthReportCsv(YearMonth.of(2021, 1), Locale.GERMAN, batmanId, printWriter);

assertThat(stringWriter).hasToString("""
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;1,000;hard work;false
04.01.2021;Bruce;Wayne;1,000;hard work;false
05.01.2021;Bruce;Wayne;8,000;hard work;false
report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break
04.01.2021;Bruce;Wayne;10:00;11:00;1,000;hard work;false
04.01.2021;Bruce;Wayne;14:00;15:00;1,000;hard work;false
05.01.2021;Bruce;Wayne;09:00;17:00;8,000;hard work;false
""");
}

Expand Down

0 comments on commit 95ca583

Please sign in to comment.