Skip to content

Commit

Permalink
#354 handle restricted users -> no working hours law validation
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausRicharz committed Jul 4, 2024
1 parent 7b25336 commit c1d5417
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/org/tb/dailyreport/service/TimereportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ private void validateParametersAndFillTimereport(long employeeContractId, long e
DataValidation.isTrue(durationHours >= 0, TR_DURATION_HOURS_INVALID);
DataValidation.isTrue(durationMinutes >= 0, TR_DURATION_MINUTES_INVALID);

if (isRelevantForWorkingTimeValidation(employeeorder.getSuborder().getCustomerorder().getOrderType())) {
// TODO maybe move to validation like business rules validations
if (needsWorkingHoursLawValidation(employeeContractId) && isRelevantForWorkingTimeValidation(employeeorder.getSuborder().getCustomerorder().getOrderType())) {
Workingday workingDay = workingdayDAO.getWorkingdayByDateAndEmployeeContractId(referenceDay, employeeContractId);
DataValidation.notNull(workingDay, TR_WORKING_DAY_START_NULL);
DataValidation.notNull(workingDay.getStartOfWorkingDay(), TR_WORKING_DAY_START_NULL);
Expand All @@ -330,6 +331,11 @@ private void validateParametersAndFillTimereport(long employeeContractId, long e
timereport.setDurationminutes((int) durationMinutes);
}

private boolean needsWorkingHoursLawValidation(long employeeContractId) {
Employeecontract contract = employeecontractDAO.getEmployeeContractById(employeeContractId);
return contract != null && !contract.getEmployee().isRestricted();
}

private void setSequencenumber(Timereport timereport) {
BusinessRuleChecks.isTrue(timereport.getSequencenumber() == 0, TR_SEQUENCE_NUMBER_ALREADY_SET);
List<TimereportDTO> existingTimereports = timereportDAO.getTimereportsByDateAndEmployeeContractId(
Expand Down Expand Up @@ -498,11 +504,19 @@ private void validateTimeReportingBusinessRules(List<Timereport> timereports) {
}

public WorkingDayValidationError validateBreakTime(LocalDate date, long employeeContractId) {
if(!needsWorkingHoursLawValidation(employeeContractId)) {
return null; // restricted/external users are not in scope of regulations by law
}

var timeReports = timereportDAO.getTimereportsByDateAndEmployeeContractId(employeeContractId, date);
return validateBreakTime(date, employeeContractId, timeReports);
}

private WorkingDayValidationError validateBreakTime(LocalDate date, long employeeContractId, List<TimereportDTO> timeReports) {
if(!needsWorkingHoursLawValidation(employeeContractId)) {
return null; // restricted/external users are not in scope of regulations by law
}

Workingday workingDay = workingdayDAO.getWorkingdayByDateAndEmployeeContractId(date, employeeContractId);
Duration workDurationSum = timeReports.stream()
.filter(timeReport -> isRelevantForWorkingTimeValidation(timeReport.getOrderType()))
Expand All @@ -520,6 +534,10 @@ private WorkingDayValidationError validateBreakTime(LocalDate date, long employe
}

private WorkingDayValidationError validateRestTime(LocalDate date, long employeeContractId) {
if(!needsWorkingHoursLawValidation(employeeContractId)) {
return null; // restricted/external users are not in scope of regulations by law
}

Workingday workingDay = workingdayDAO.getWorkingdayByDateAndEmployeeContractId(date, employeeContractId);
Workingday theDayBefore = workingdayDAO.getWorkingdayByDateAndEmployeeContractId(date.minusDays(1), employeeContractId);
if (theDayBefore == null) {
Expand All @@ -540,6 +558,10 @@ private WorkingDayValidationError validateRestTime(LocalDate date, long employee
}

public WorkingDayValidationError validateBeginOfWorkingDay(LocalDate date, long employeeContractId) {
if(!needsWorkingHoursLawValidation(employeeContractId)) {
return null; // restricted/external users are not in scope of regulations by law
}

Duration workDurationSum = timereportDAO.getTimereportsByDateAndEmployeeContractId(employeeContractId, date).stream()
.filter(timeReport -> isRelevantForWorkingTimeValidation(timeReport.getOrderType()))
.map(TimereportDTO::getDuration)
Expand Down

0 comments on commit c1d5417

Please sign in to comment.