Skip to content

Commit

Permalink
rename federalState / worksOnPublicHoliday methods of WorkingTime
Browse files Browse the repository at this point in the history
  • Loading branch information
bseber committed Mar 17, 2024
1 parent 280eb54 commit 3555238
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,37 @@ public Optional<LocalDate> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Map<UserIdComposite, WorkingTimeCalendar> toWorkingTimeCalendar(LocalDat
final Set<FederalState> federalStates = sortedWorkingTimes.values()
.stream()
.flatMap(List::stream)
.map(WorkingTime::actualFederalState)
.map(WorkingTime::federalState)
.collect(toUnmodifiableSet());

final Map<FederalState, PublicHolidayCalendar> publicHolidayCalendars =
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit 3555238

Please sign in to comment.