-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/de/focusshift/zeiterfassung/workingtime/WorksOnPublicHoliday.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.focusshift.zeiterfassung.workingtime; | ||
|
||
import de.focusshift.zeiterfassung.settings.FederalStateSettings; | ||
import jakarta.annotation.Nullable; | ||
|
||
import static java.lang.Boolean.TRUE; | ||
|
||
/** | ||
* Defines whether a person works on a public holiday or not, or if the global setting should be used. | ||
*/ | ||
public enum WorksOnPublicHoliday { | ||
|
||
/** | ||
* global settings should be considered. can be obtained by {@linkplain FederalStateSettings#worksOnPublicHoliday()} | ||
*/ | ||
GLOBAL(null), | ||
|
||
/** | ||
* overrides global settings with `true` | ||
*/ | ||
YES(TRUE), | ||
|
||
/** | ||
* overrides global settings with `false` | ||
*/ | ||
NO(Boolean.FALSE); | ||
|
||
private final Boolean boolValue; | ||
|
||
WorksOnPublicHoliday(Boolean boolValue) { | ||
this.boolValue = boolValue; | ||
} | ||
|
||
/** | ||
* @return the boolean value for this enum, {@code null} when {@linkplain WorksOnPublicHoliday#GLOBAL} | ||
*/ | ||
@Nullable | ||
public Boolean asBoolean() { | ||
return boolValue; | ||
} | ||
|
||
public boolean isTrue() { | ||
return YES.equals(this); | ||
} | ||
|
||
public static WorksOnPublicHoliday fromBoolean(@Nullable Boolean boolValue) { | ||
return switch (boolValue) { | ||
case null -> GLOBAL; | ||
case Boolean b -> TRUE.equals(b) ? YES : NO; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import de.focusshift.zeiterfassung.workingtime.WorkingTime; | ||
import de.focusshift.zeiterfassung.workingtime.WorkingTimeId; | ||
import de.focusshift.zeiterfassung.workingtime.WorkingTimeService; | ||
import de.focusshift.zeiterfassung.workingtime.WorksOnPublicHoliday; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
@@ -36,6 +37,7 @@ | |
import java.util.UUID; | ||
|
||
import static de.focusshift.zeiterfassung.publicholiday.FederalState.GERMANY_BADEN_WUERTTEMBERG; | ||
import static de.focusshift.zeiterfassung.publicholiday.FederalState.GERMANY_BAYERN; | ||
import static de.focusshift.zeiterfassung.publicholiday.FederalState.GERMANY_BERLIN; | ||
import static java.time.DayOfWeek.FRIDAY; | ||
import static java.time.DayOfWeek.MONDAY; | ||
|
@@ -247,7 +249,7 @@ void ensureGetEditPage() throws Exception { | |
.thenReturn(new FederalStateSettings(GERMANY_BERLIN, true)); | ||
|
||
final WorkingTimeId workingTimeId = new WorkingTimeId(UUID.randomUUID()); | ||
final WorkingTime workingTime = WorkingTime.builder(userIdComposite, workingTimeId).build(); | ||
final WorkingTime workingTime = WorkingTime.builder(userIdComposite, workingTimeId).worksOnPublicHoliday(WorksOnPublicHoliday.GLOBAL).build(); | ||
when(workingTimeService.getWorkingTimeById(workingTimeId)).thenReturn(Optional.of(workingTime)); | ||
|
||
perform( | ||
|
@@ -280,6 +282,7 @@ void ensureGetEditPage(boolean globalWorksOnPublicHoliday, Integer expectedValue | |
|
||
final WorkingTimeId workingTimeId = new WorkingTimeId(UUID.randomUUID()); | ||
final WorkingTime workingTime = WorkingTime.builder(userIdComposite, workingTimeId) | ||
.worksOnPublicHoliday(WorksOnPublicHoliday.GLOBAL) | ||
.build(); | ||
|
||
when(workingTimeService.getWorkingTimeById(workingTimeId)).thenReturn(Optional.of(workingTime)); | ||
|
@@ -414,7 +417,6 @@ void ensureEditWithValidationError() throws Exception { | |
))) | ||
.andExpect(model().attribute("selectedUser", new UserDto(42, "Clark", "Kent", "Clark Kent", "[email protected]"))) | ||
.andExpect(model().attribute("workingTime", expectedWorkingTimeDto)) | ||
.andExpect(model().attribute("globalFederalState", GERMANY_BERLIN)) | ||
.andExpect(model().attribute("globalFederalStateMessageKey", "federalState.GERMANY_BERLIN")) | ||
.andExpect(model().attribute("personSearchFormAction", is("/users/42"))); | ||
|
||
|
@@ -470,7 +472,7 @@ void ensureEditWithValidationErrorAllowedToEditX(String authority, boolean editW | |
@Test | ||
void ensureEditWithValidationErrorJavaScript() throws Exception { | ||
|
||
when(federalStateSettingsService.getFederalStateSettings()).thenReturn(federalStateSettings(GERMANY_BERLIN)); | ||
when(federalStateSettingsService.getFederalStateSettings()).thenReturn(federalStateSettings(GERMANY_BAYERN)); | ||
|
||
final WorkingTimeId workingTimeId = new WorkingTimeId(UUID.randomUUID()); | ||
|
||
|
@@ -518,8 +520,7 @@ void ensureEditWithValidationErrorJavaScript() throws Exception { | |
))) | ||
.andExpect(model().attribute("selectedUser", new UserDto(42, "Clark", "Kent", "Clark Kent", "[email protected]"))) | ||
.andExpect(model().attribute("workingTime", expectedWorkingTimeDto)) | ||
.andExpect(model().attribute("globalFederalState", GERMANY_BERLIN)) | ||
.andExpect(model().attribute("globalFederalStateMessageKey", "federalState.GERMANY_BERLIN")) | ||
.andExpect(model().attribute("globalFederalStateMessageKey", "federalState.GERMANY_BAYERN")) | ||
.andExpect(model().attribute("personSearchFormAction", is("/users/42"))); | ||
|
||
verifyNoInteractions(workingTimeService); | ||
|
Oops, something went wrong.