diff --git a/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeAccountController.java b/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeAccountController.java index 19707b74f..12c7a08d4 100644 --- a/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeAccountController.java +++ b/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeAccountController.java @@ -115,7 +115,7 @@ private WorkingTimeListEntryDto workingTimeListEntryDto(WorkingTime workingTime) final Date validFrom = workingTime.validFrom().map(from -> Date.from(from.atStartOfDay().toInstant(UTC))).orElse(null); final Date validTo = workingTime.validTo().map(to -> Date.from(to.atStartOfDay().toInstant(UTC))).orElse(null); final Boolean validFromIsPast = workingTime.validFrom().map(from -> from.isBefore(today)).orElse(true); - final String federalStateMessageKey = federalStateMessageKey(workingTime.federalState()); + final String federalStateMessageKey = federalStateMessageKey(workingTime.individualFederalState()); return new WorkingTimeListEntryDto( workingTime.id().value(), diff --git a/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeController.java b/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeController.java index ef817ea61..cc7c41f73 100644 --- a/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeController.java +++ b/src/main/java/de/focusshift/zeiterfassung/usermanagement/WorkingTimeController.java @@ -335,8 +335,8 @@ private static WorkingTimeDto workingTimeToDto(WorkingTime workingTime) { dto.setValidFrom(workingTime.validFrom().orElse(null)); dto.setMinValidFrom(workingTime.minValidFrom().orElse(null)); dto.setMaxValidFrom(workingTime.validTo().orElse(null)); - dto.setFederalState(workingTime.federalState()); - dto.setWorksOnPublicHoliday(workingTime.worksOnPublicHoliday().asBoolean()); + dto.setFederalState(workingTime.individualFederalState()); + dto.setWorksOnPublicHoliday(workingTime.individualWorksOnPublicHoliday().asBoolean()); dto.setUserId(workingTime.userIdComposite().localId().value()); dto.setWorkday(workingTime.actualWorkingDays().stream().map(DayOfWeek::name).map(String::toLowerCase).toList()); diff --git a/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImpl.java b/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImpl.java index eaa260db3..1dccac4d6 100644 --- a/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImpl.java +++ b/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImpl.java @@ -418,8 +418,8 @@ private WorkingTimeEntity workingTimeToEntity(WorkingTime workingTime) { entity.setUserId(workingTime.userLocalId().value()); entity.setValidFrom(workingTime.validFrom().orElse(null)); - entity.setFederalState(workingTime.federalState()); - entity.setWorksOnPublicHoliday(workingTime.worksOnPublicHoliday().asBoolean()); + entity.setFederalState(workingTime.individualFederalState()); + entity.setWorksOnPublicHoliday(workingTime.individualWorksOnPublicHoliday().asBoolean()); entity.setMonday(workdayToDurationString(workingTime.getMonday())); entity.setTuesday(workdayToDurationString(workingTime.getTuesday())); entity.setWednesday(workdayToDurationString(workingTime.getWednesday())); diff --git a/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTime.java b/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTime.java index d8b27a050..751bab12a 100644 --- a/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTime.java +++ b/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTime.java @@ -105,33 +105,37 @@ public Optional minValidFrom() { } /** - * The individual set federalState which can be {@linkplain FederalState#GLOBAL}. - * Use {@linkplain WorkingTime#actualFederalState()} to get the resolved federalState value. + * The individual federalState if this {@linkplain WorkingTime} which can be {@linkplain FederalState#GLOBAL}. + * Use {@linkplain WorkingTime#federalState()} to get the resolved federalState value in this case when needed. * * @return the individual set {@linkplain FederalState} (e.g. {@linkplain FederalState#GLOBAL}, {@linkplain FederalState#NONE}, ...) */ - public FederalState federalState() { + public FederalState individualFederalState() { return federalState; } /** - * This method handles resolving a possible {@linkplain FederalState#GLOBAL} value to the globally set value. - * - * @return the resolved {@linkplain FederalState} for this {@linkplain WorkingTime}, - * never {@linkplain FederalState#GLOBAL}, can be {@linkplain FederalState#NONE} + * @return {@linkplain FederalState} value of this {@linkplain WorkingTime}, never {@linkplain FederalState#GLOBAL}. + * resolves to global setting when individual equals {@linkplain FederalState#GLOBAL}. */ - public FederalState actualFederalState() { + public FederalState federalState() { return federalState.equals(GLOBAL) ? federalStateSettingsSupplier.get().federalState() : federalState; } /** - * Whether the related person works on public holidays or not. + * @return the {@linkplain WorksOnPublicHoliday} type */ - public WorksOnPublicHoliday worksOnPublicHoliday() { + public WorksOnPublicHoliday individualWorksOnPublicHoliday() { return worksOnPublicHoliday; } - public boolean actualWorksOnPublicHoliday() { + /** + * + * @return {@code true} when the individual settings is {@linkplain WorksOnPublicHoliday#YES}, + * {@code false} when individual setting is {@linkplain WorksOnPublicHoliday#NO}, + * resolves to global setting otherwise. + */ + public boolean worksOnPublicHoliday() { return requireNonNullElseGet(worksOnPublicHoliday.asBoolean(), () -> federalStateSettingsSupplier.get().worksOnPublicHoliday()); } diff --git a/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTimeCalendarServiceImpl.java b/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTimeCalendarServiceImpl.java index ede0379e8..cca7595c5 100644 --- a/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTimeCalendarServiceImpl.java +++ b/src/main/java/de/focusshift/zeiterfassung/workingtime/WorkingTimeCalendarServiceImpl.java @@ -52,7 +52,7 @@ private Map toWorkingTimeCalendar(LocalDat final Set federalStates = sortedWorkingTimes.values() .stream() .flatMap(List::stream) - .map(WorkingTime::actualFederalState) + .map(WorkingTime::federalState) .collect(toUnmodifiableSet()); final Map publicHolidayCalendars = @@ -80,7 +80,7 @@ private WorkingTimeCalendar toWorkingTimeCalendar(LocalDate from, LocalDate toEx final DateRange workingTimeDateRange = getDateRange(from, workingTime, nextEnd); for (LocalDate localDate : workingTimeDateRange) { - if (workingTime.actualWorksOnPublicHoliday() || !isPublicHoliday.test(localDate, workingTime.actualFederalState())) { + if (workingTime.worksOnPublicHoliday() || !isPublicHoliday.test(localDate, workingTime.federalState())) { plannedWorkingHoursByDate.put(localDate, workingTime.getForDayOfWeek(localDate.getDayOfWeek())); } else { plannedWorkingHoursByDate.put(localDate, PlannedWorkingHours.ZERO); diff --git a/src/test/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImplTest.java b/src/test/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImplTest.java index 59f302b80..fc75de983 100644 --- a/src/test/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImplTest.java +++ b/src/test/java/de/focusshift/zeiterfassung/workingtime/WorkTimeServiceImplTest.java @@ -110,8 +110,8 @@ void returnsWorkingTime() { assertThat(workingTime.validFrom()).isEmpty(); assertThat(workingTime.validTo()).isEmpty(); assertThat(workingTime.minValidFrom()).isEmpty(); - assertThat(workingTime.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); + assertThat(workingTime.individualFederalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); }); } @@ -170,9 +170,9 @@ void returnsDefaultAndPersistsIt() { assertThat(workingTime.id()).isEqualTo(new WorkingTimeId(workingTimeId)); assertThat(workingTime.userIdComposite()).isEqualTo(user.userIdComposite()); assertThat(workingTime.validFrom()).isEmpty(); - assertThat(workingTime.federalState()).isEqualTo(GLOBAL); - assertThat(workingTime.actualFederalState()).isEqualTo(GERMANY_BERLIN); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.GLOBAL); + assertThat(workingTime.individualFederalState()).isEqualTo(GLOBAL); + assertThat(workingTime.federalState()).isEqualTo(GERMANY_BERLIN); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.GLOBAL); assertThat(workingTime.getMonday()).isEqualTo(PlannedWorkingHours.EIGHT); assertThat(workingTime.getTuesday()).isEqualTo(PlannedWorkingHours.EIGHT); assertThat(workingTime.getWednesday()).isEqualTo(PlannedWorkingHours.EIGHT); @@ -415,8 +415,8 @@ void ensureGetWorkingTimeByUsers() { assertThat(workingTimes.getFirst()).satisfies(workingTime -> { assertThat(workingTime.userIdComposite()).isEqualTo(userIdComposite_1); assertThat(workingTime.id()).isEqualTo(new WorkingTimeId(workingTimeId_1)); - assertThat(workingTime.federalState()).isEqualTo(NONE); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.NO); + assertThat(workingTime.individualFederalState()).isEqualTo(NONE); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.NO); assertThat(workingTime.getMonday().duration()).isEqualTo(Duration.ofHours(1)); assertThat(workingTime.getTuesday().duration()).isEqualTo(Duration.ofHours(2)); assertThat(workingTime.getWednesday().duration()).isEqualTo(Duration.ofHours(3)); @@ -431,8 +431,8 @@ void ensureGetWorkingTimeByUsers() { assertThat(workingTimes.getFirst()).satisfies(workingTime -> { assertThat(workingTime.userIdComposite()).isEqualTo(userIdComposite_2); assertThat(workingTime.id()).isEqualTo(new WorkingTimeId(workingTimeId_2)); - assertThat(workingTime.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); + assertThat(workingTime.individualFederalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); assertThat(workingTime.getMonday().duration()).isEqualTo(Duration.ofHours(7)); assertThat(workingTime.getTuesday().duration()).isEqualTo(Duration.ofHours(6)); assertThat(workingTime.getWednesday().duration()).isEqualTo(Duration.ofHours(5)); @@ -468,9 +468,9 @@ void ensureGetWorkingTimeByUsersAddsDefaultWorkingTimeForUsersWithoutExplicitOne assertThat(workingTimes).hasSize(1); assertThat(workingTimes.getFirst()).satisfies(workingTime -> { assertThat(workingTime.userIdComposite()).isEqualTo(userIdComposite_1); - assertThat(workingTime.federalState()).isEqualTo(GLOBAL); - assertThat(workingTime.actualFederalState()).isEqualTo(GERMANY_BERLIN); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.GLOBAL); + assertThat(workingTime.individualFederalState()).isEqualTo(GLOBAL); + assertThat(workingTime.federalState()).isEqualTo(GERMANY_BERLIN); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.GLOBAL); assertThat(workingTime.getMonday().duration()).isEqualTo(Duration.ofHours(8)); assertThat(workingTime.getTuesday().duration()).isEqualTo(Duration.ofHours(8)); assertThat(workingTime.getWednesday().duration()).isEqualTo(Duration.ofHours(8)); @@ -536,8 +536,8 @@ void ensureGetAllWorkingTimeByUsers() { assertThat(workingTimes.getFirst()).satisfies(workingTime -> { assertThat(workingTime.userIdComposite()).isEqualTo(userIdComposite_1); assertThat(workingTime.id()).isEqualTo(new WorkingTimeId(workingTimeId_1)); - assertThat(workingTime.federalState()).isEqualTo(NONE); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.NO); + assertThat(workingTime.individualFederalState()).isEqualTo(NONE); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.NO); assertThat(workingTime.getMonday().duration()).isEqualTo(Duration.ofHours(1)); assertThat(workingTime.getTuesday().duration()).isEqualTo(Duration.ofHours(2)); assertThat(workingTime.getWednesday().duration()).isEqualTo(Duration.ofHours(3)); @@ -552,8 +552,8 @@ void ensureGetAllWorkingTimeByUsers() { assertThat(workingTimes.getFirst()).satisfies(workingTime -> { assertThat(workingTime.userIdComposite()).isEqualTo(userIdComposite_2); assertThat(workingTime.id()).isEqualTo(new WorkingTimeId(workingTimeId_2)); - assertThat(workingTime.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); + assertThat(workingTime.individualFederalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); assertThat(workingTime.getMonday().duration()).isEqualTo(Duration.ofHours(7)); assertThat(workingTime.getTuesday().duration()).isEqualTo(Duration.ofHours(6)); assertThat(workingTime.getWednesday().duration()).isEqualTo(Duration.ofHours(5)); @@ -585,8 +585,8 @@ void ensureGetAllWorkingTimesByUsersAddsDefaultWorkingTimeForUsersWithoutExplici assertThat(workingTimes).hasSize(1); assertThat(workingTimes.getFirst()).satisfies(workingTime -> { assertThat(workingTime.userIdComposite()).isEqualTo(userIdComposite_1); - assertThat(workingTime.federalState()).isEqualTo(GLOBAL); - assertThat(workingTime.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.GLOBAL); + assertThat(workingTime.individualFederalState()).isEqualTo(GLOBAL); + assertThat(workingTime.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.GLOBAL); assertThat(workingTime.getMonday().duration()).isEqualTo(Duration.ofHours(8)); assertThat(workingTime.getTuesday().duration()).isEqualTo(Duration.ofHours(8)); assertThat(workingTime.getWednesday().duration()).isEqualTo(Duration.ofHours(8)); @@ -688,8 +688,8 @@ void ensureUpdateWorkingTime() { assertThat(actual.userIdComposite()).isEqualTo(userIdComposite); assertThat(actual.isCurrent()).isTrue(); - assertThat(actual.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); - assertThat(actual.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); + assertThat(actual.individualFederalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); + assertThat(actual.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); assertThat(actual.getMonday()).isEqualTo(new PlannedWorkingHours(Duration.ofHours(1))); assertThat(actual.getTuesday()).isEqualTo(new PlannedWorkingHours(Duration.ofHours(2))); assertThat(actual.getWednesday()).isEqualTo(new PlannedWorkingHours(Duration.ofHours(3))); @@ -745,8 +745,8 @@ void ensureCreateWorkingTimeWithNullableDays() { final WorkingTime actual = sut.createWorkingTime(userLocalId, LocalDate.of(2023, 12, 9), GERMANY_BADEN_WUERTTEMBERG, true, durations); assertThat(actual.id()).isEqualTo(new WorkingTimeId(uuid)); assertThat(actual.userIdComposite()).isEqualTo(userIdComposite); - assertThat(actual.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); - assertThat(actual.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); + assertThat(actual.individualFederalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); + assertThat(actual.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); assertThat(actual.validFrom()).hasValue(LocalDate.of(2023, 12, 9)); assertThat(actual.getMonday()).isEqualTo(new PlannedWorkingHours(Duration.ofHours(1))); assertThat(actual.getTuesday()).isEqualTo(new PlannedWorkingHours(Duration.ZERO)); @@ -793,8 +793,8 @@ void ensureCreateWorkingTime() { final WorkingTime actual = sut.createWorkingTime(userLocalId, LocalDate.of(2023, 12, 9), GERMANY_BADEN_WUERTTEMBERG, true, durations); assertThat(actual.id()).isEqualTo(new WorkingTimeId(uuid)); assertThat(actual.userIdComposite()).isEqualTo(userIdComposite); - assertThat(actual.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); - assertThat(actual.worksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); + assertThat(actual.individualFederalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG); + assertThat(actual.individualWorksOnPublicHoliday()).isEqualTo(WorksOnPublicHoliday.YES); assertThat(actual.validFrom()).hasValue(LocalDate.of(2023, 12, 9)); assertThat(actual.getMonday()).isEqualTo(new PlannedWorkingHours(Duration.ofHours(1))); assertThat(actual.getTuesday()).isEqualTo(new PlannedWorkingHours(Duration.ofHours(2)));