Search in sources :

Example 1 with Application

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());
}
Also used : WorkingTime(org.synyx.urlaubsverwaltung.workingtime.WorkingTime) FederalState(org.synyx.urlaubsverwaltung.workingtime.FederalState) SickNote(org.synyx.urlaubsverwaltung.sicknote.sicknote.SickNote) Application(org.synyx.urlaubsverwaltung.application.application.Application)

Example 2 with Application

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());
}
Also used : WorkingTime(org.synyx.urlaubsverwaltung.workingtime.WorkingTime) SickNote(org.synyx.urlaubsverwaltung.sicknote.sicknote.SickNote) WorkingTime(org.synyx.urlaubsverwaltung.workingtime.WorkingTime) Autowired(org.springframework.beans.factory.annotation.Autowired) ACTIVE(org.synyx.urlaubsverwaltung.sicknote.sicknote.SickNoteStatus.ACTIVE) PublicHoliday(org.synyx.urlaubsverwaltung.publicholiday.PublicHoliday) PublicHolidaysService(org.synyx.urlaubsverwaltung.publicholiday.PublicHolidaysService) Service(org.springframework.stereotype.Service) ListUtils(org.apache.commons.collections4.ListUtils) Application(org.synyx.urlaubsverwaltung.application.application.Application) ApplicationStatus(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus) SickNoteService(org.synyx.urlaubsverwaltung.sicknote.sicknote.SickNoteService) Comparator.comparing(java.util.Comparator.comparing) ALLOWED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED) WAITING(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.WAITING) Person(org.synyx.urlaubsverwaltung.person.Person) Predicate(java.util.function.Predicate) SettingsService(org.synyx.urlaubsverwaltung.settings.SettingsService) DayLength(org.synyx.urlaubsverwaltung.period.DayLength) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) WorkingTimeService(org.synyx.urlaubsverwaltung.workingtime.WorkingTimeService) Stream(java.util.stream.Stream) ALLOWED_CANCELLATION_REQUESTED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED_CANCELLATION_REQUESTED) LocalDate(java.time.LocalDate) Optional(java.util.Optional) SickNoteStatus(org.synyx.urlaubsverwaltung.sicknote.sicknote.SickNoteStatus) ApplicationService(org.synyx.urlaubsverwaltung.application.application.ApplicationService) FederalState(org.synyx.urlaubsverwaltung.workingtime.FederalState) TEMPORARY_ALLOWED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.TEMPORARY_ALLOWED) LocalDate(java.time.LocalDate) Person(org.synyx.urlaubsverwaltung.person.Person)

Example 3 with Application

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;
}
Also used : Person(org.synyx.urlaubsverwaltung.person.Person) DateUtil.getLastDayOfMonth(org.synyx.urlaubsverwaltung.util.DateUtil.getLastDayOfMonth) DateUtil.isBeforeApril(org.synyx.urlaubsverwaltung.util.DateUtil.isBeforeApril) Autowired(org.springframework.beans.factory.annotation.Autowired) ZERO(java.math.BigDecimal.ZERO) APRIL(java.time.Month.APRIL) BigDecimal(java.math.BigDecimal) DateUtil.getFirstDayOfMonth(org.synyx.urlaubsverwaltung.util.DateUtil.getFirstDayOfMonth) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ALLOWED_CANCELLATION_REQUESTED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED_CANCELLATION_REQUESTED) MARCH(java.time.Month.MARCH) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) Clock(java.time.Clock) Optional(java.util.Optional) Application(org.synyx.urlaubsverwaltung.application.application.Application) JANUARY(java.time.Month.JANUARY) HOLIDAY(org.synyx.urlaubsverwaltung.application.vacationtype.VacationCategory.HOLIDAY) ApplicationService(org.synyx.urlaubsverwaltung.application.application.ApplicationService) WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) DECEMBER(java.time.Month.DECEMBER) ALLOWED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED) WAITING(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.WAITING) Application(org.synyx.urlaubsverwaltung.application.application.Application) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 4 with Application

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);
}
Also used : ArrayList(java.util.ArrayList) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Person(org.synyx.urlaubsverwaltung.person.Person) Application(org.synyx.urlaubsverwaltung.application.application.Application) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with Application

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);
}
Also used : Department(org.synyx.urlaubsverwaltung.department.Department) ArrayList(java.util.ArrayList) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Person(org.synyx.urlaubsverwaltung.person.Person) Application(org.synyx.urlaubsverwaltung.application.application.Application) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Application (org.synyx.urlaubsverwaltung.application.application.Application)75 Person (org.synyx.urlaubsverwaltung.person.Person)66 LocalDate (java.time.LocalDate)59 Test (org.junit.jupiter.api.Test)58 TestDataCreator.createApplication (org.synyx.urlaubsverwaltung.TestDataCreator.createApplication)32 TestDataCreator.anyApplication (org.synyx.urlaubsverwaltung.TestDataCreator.anyApplication)18 SickNote (org.synyx.urlaubsverwaltung.sicknote.sicknote.SickNote)14 ArrayList (java.util.ArrayList)13 WorkingTime (org.synyx.urlaubsverwaltung.workingtime.WorkingTime)13 VacationTypeEntity (org.synyx.urlaubsverwaltung.application.vacationtype.VacationTypeEntity)7 DayLength (org.synyx.urlaubsverwaltung.period.DayLength)7 Settings (org.synyx.urlaubsverwaltung.settings.Settings)6 BigDecimal (java.math.BigDecimal)5 TestDataCreator.anySickNote (org.synyx.urlaubsverwaltung.TestDataCreator.anySickNote)5 List (java.util.List)4 Optional (java.util.Optional)4 Collectors.toList (java.util.stream.Collectors.toList)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (org.springframework.stereotype.Service)4 TestDataCreator.createSickNote (org.synyx.urlaubsverwaltung.TestDataCreator.createSickNote)4