use of org.synyx.urlaubsverwaltung.application.application.Application in project urlaubsverwaltung by synyx.
the class AbsenceServiceImpl method getOpenAbsences.
@Override
public List<AbsencePeriod> getOpenAbsences(List<Person> persons, LocalDate start, LocalDate end) {
final DateRange askedDateRange = new DateRange(start, end);
final List<WorkingTime> workingTimeList = workingTimeService.getByPersons(persons);
final FederalState systemDefaultFederalState = workingTimeService.getSystemDefaultFederalState();
final List<Application> openApplications = applicationService.getForStatesAndPerson(APPLICATION_STATUSES, persons, start, end);
final List<AbsencePeriod> applicationAbsences = generateAbsencePeriodFromApplication(openApplications, askedDateRange, workingTimeList, systemDefaultFederalState);
final List<SickNote> openSickNotes = sickNoteService.getForStatesAndPerson(SICK_NOTE_STATUSES, persons, start, end);
final List<AbsencePeriod> sickNoteAbsences = generateAbsencePeriodFromSickNotes(openSickNotes, askedDateRange, workingTimeList, systemDefaultFederalState);
return Stream.concat(applicationAbsences.stream(), sickNoteAbsences.stream()).collect(toList());
}
use of org.synyx.urlaubsverwaltung.application.application.Application in project urlaubsverwaltung by synyx.
the class AbsenceServiceImpl method days.
private List<AbsencePeriod.Record> days(Application application, DateRange askedDateRange, List<WorkingTime> workingTimeList, FederalState systemDefaultFederalState) {
final LocalDate start = maxDate(application.getStartDate(), askedDateRange.getStartDate());
final LocalDate end = minDate(application.getEndDate(), askedDateRange.getEndDate());
final Person person = application.getPerson();
final List<WorkingTime> personWorkingTimeList = workingTimeList.stream().filter(workingTime -> workingTime.getPerson().equals(person)).sorted(comparing(WorkingTime::getValidFrom).reversed()).collect(toList());
return new DateRange(start, end).stream().map(date -> new DateDayLengthTuple(date, publicHolidayAbsence(date, workingTimeList, systemDefaultFederalState))).filter(tuple -> !tuple.publicHolidayDayLength.equals(DayLength.FULL)).filter(tuple -> isWorkday(tuple.date, personWorkingTimeList)).map(tuple -> toVacationAbsencePeriodRecord(tuple, application)).collect(toList());
}
use of org.synyx.urlaubsverwaltung.application.application.Application in project urlaubsverwaltung by synyx.
the class VacationDaysService method getUsedDaysBetweenTwoMilestones.
BigDecimal getUsedDaysBetweenTwoMilestones(Person person, LocalDate firstMilestone, LocalDate lastMilestone) {
// get all applications for leave for a person
final List<Application> allApplicationsForLeave = applicationService.getApplicationsForACertainPeriodAndPerson(firstMilestone, lastMilestone, person);
// filter them since only WAITING, ALLOWED and ALLOWED_CANCELLATION_REQUESTED applications for leave of type holiday are relevant
final List<Application> applicationsForLeave = allApplicationsForLeave.stream().filter(application -> HOLIDAY.equals(application.getVacationType().getCategory()) && // TODO and what is with the TEMPORARY_ALLOWED?
(application.hasStatus(WAITING) || application.hasStatus(ALLOWED) || application.hasStatus(ALLOWED_CANCELLATION_REQUESTED))).collect(toList());
BigDecimal usedDays = ZERO;
for (Application applicationForLeave : applicationsForLeave) {
LocalDate startDate = applicationForLeave.getStartDate();
LocalDate endDate = applicationForLeave.getEndDate();
if (startDate.isBefore(firstMilestone)) {
startDate = firstMilestone;
}
if (endDate.isAfter(lastMilestone)) {
endDate = lastMilestone;
}
usedDays = usedDays.add(workDaysCountService.getWorkDaysCount(applicationForLeave.getDayLength(), startDate, endDate, person));
}
return usedDays;
}
use of org.synyx.urlaubsverwaltung.application.application.Application in project urlaubsverwaltung by synyx.
the class VacationApiController method getVacations.
@Operation(deprecated = true, summary = "Get all allowed vacations for a person and a certain period of time", description = "Get all allowed vacations for a person and a certain period of time. " + "Information only reachable for users with role office and for your own data.")
@GetMapping
@PreAuthorize(IS_OFFICE + " or @userApiMethodSecurity.isSamePersonId(authentication, #personId)")
public VacationsDto getVacations(@Parameter(description = "ID of the person") @PathVariable("id") Integer personId, @Parameter(description = "end of interval to get vacations from (inclusive)") @RequestParam("from") @DateTimeFormat(iso = ISO.DATE) LocalDate startDate, @Parameter(description = "end of interval to get vacations from (inclusive)") @RequestParam("to") @DateTimeFormat(iso = ISO.DATE) LocalDate endDate) {
if (startDate.isAfter(endDate)) {
throw new ResponseStatusException(BAD_REQUEST, "Parameter 'from' must be before or equals to 'to' parameter");
}
final Person person = getPerson(personId);
final List<Application> applications = new ArrayList<>();
applications.addAll(applicationService.getApplicationsForACertainPeriodAndPersonAndState(startDate, endDate, person, ALLOWED));
applications.addAll(applicationService.getApplicationsForACertainPeriodAndPersonAndState(startDate, endDate, person, ALLOWED_CANCELLATION_REQUESTED));
return mapToVacationResponse(applications);
}
use of org.synyx.urlaubsverwaltung.application.application.Application in project urlaubsverwaltung by synyx.
the class VacationApiController method getVacationsOfOthersOrDepartmentColleagues.
@Operation(summary = "Get all allowed vacations for department members for the given person and the certain period", description = "Get all allowed vacations for department members for the given person and the certain period. " + "All the waiting and allowed vacations of the departments the person is assigned to, are fetched. " + "Information only reachable for users with role office and for your own data.")
@GetMapping(params = "ofDepartmentMembers")
@PreAuthorize(IS_OFFICE + " or @userApiMethodSecurity.isSamePersonId(authentication, #personId)")
public VacationsDto getVacationsOfOthersOrDepartmentColleagues(@Parameter(description = "ID of the person") @PathVariable("id") Integer personId, @Parameter(description = "Start date with pattern yyyy-MM-dd") @RequestParam("from") @DateTimeFormat(iso = ISO.DATE) LocalDate startDate, @Parameter(description = "End date with pattern yyyy-MM-dd") @RequestParam("to") @DateTimeFormat(iso = ISO.DATE) LocalDate endDate, @Parameter(description = "If defined returns only the vacations of the department members of the person") @RequestParam(value = "ofDepartmentMembers", defaultValue = "true") boolean ofDepartmentMembers) {
if (startDate.isAfter(endDate)) {
throw new ResponseStatusException(BAD_REQUEST, "Parameter 'from' must be before or equals to 'to' parameter");
}
final Person person = getPerson(personId);
final List<Application> applications = new ArrayList<>();
final List<Department> departments = departmentService.getAssignedDepartmentsOfMember(person);
if (departments.isEmpty()) {
applications.addAll(applicationService.getApplicationsForACertainPeriodAndState(startDate, endDate, ALLOWED));
applications.addAll(applicationService.getApplicationsForACertainPeriodAndState(startDate, endDate, ALLOWED_CANCELLATION_REQUESTED));
} else {
applications.addAll(departmentService.getApplicationsForLeaveOfMembersInDepartmentsOfPerson(person, startDate, endDate));
}
return mapToVacationResponse(applications);
}
Aggregations