Search in sources :

Example 1 with WorkDaysCountService

use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.

the class ApplicationForLeaveDetailsViewController method prepareDetailView.

private void prepareDetailView(Application application, int year, String action, boolean shortcut, Model model, Person signedInUser) {
    // signed in user
    model.addAttribute("signedInUser", signedInUser);
    // COMMENTS
    final List<ApplicationComment> comments = commentService.getCommentsByApplication(application);
    model.addAttribute("comment", new ApplicationCommentForm());
    model.addAttribute("comments", comments);
    model.addAttribute("lastComment", comments.get(comments.size() - 1));
    // SPECIAL ATTRIBUTES FOR BOSSES / DEPARTMENT HEADS
    boolean isNotYetAllowed = application.hasStatus(WAITING) || application.hasStatus(TEMPORARY_ALLOWED);
    boolean isPrivilegedUser = signedInUser.hasRole(BOSS) || signedInUser.hasRole(DEPARTMENT_HEAD) || signedInUser.hasRole(SECOND_STAGE_AUTHORITY);
    if (isNotYetAllowed && isPrivilegedUser) {
        model.addAttribute("bosses", personService.getActivePersonsByRole(BOSS));
        model.addAttribute("referredPerson", new ReferredPerson());
    }
    // APPLICATION FOR LEAVE
    model.addAttribute("application", new ApplicationForLeave(application, workDaysCountService));
    final Map<DateRange, WorkingTime> workingTime = workingTimeService.getWorkingTimesByPersonAndDateRange(application.getPerson(), new DateRange(application.getStartDate(), application.getEndDate())).entrySet().stream().sorted(Map.Entry.comparingByKey(comparing(DateRange::getStartDate))).collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue, LinkedHashMap::new));
    model.addAttribute("dateRangeWorkingTimes", workingTime);
    // DEPARTMENT APPLICATIONS FOR LEAVE
    final List<Application> departmentApplications = departmentService.getApplicationsForLeaveOfMembersInDepartmentsOfPerson(application.getPerson(), application.getStartDate(), application.getEndDate());
    model.addAttribute("departmentApplications", departmentApplications);
    // HOLIDAY ACCOUNT
    final Optional<Account> account = accountService.getHolidaysAccount(year, application.getPerson());
    if (account.isPresent()) {
        final Account acc = account.get();
        final Optional<Account> accountNextYear = accountService.getHolidaysAccount(year + 1, application.getPerson());
        model.addAttribute("vacationDaysLeft", vacationDaysService.getVacationDaysLeft(account.get(), accountNextYear));
        model.addAttribute("account", acc);
        model.addAttribute(BEFORE_APRIL_ATTRIBUTE, DateUtil.isBeforeApril(LocalDate.now(clock), acc.getYear()));
    }
    // Signed in person is allowed to manage
    final boolean isDepartmentHead = departmentService.isDepartmentHeadAllowedToManagePerson(signedInUser, application.getPerson());
    model.addAttribute("isDepartmentHeadOfPerson", isDepartmentHead);
    final boolean isSecondStageAuthority = departmentService.isSecondStageAuthorityAllowedToManagePerson(signedInUser, application.getPerson());
    model.addAttribute("isSecondStageAuthorityOfPerson", isSecondStageAuthority);
    model.addAttribute("isBoss", signedInUser.hasRole(BOSS));
    model.addAttribute("isOffice", signedInUser.hasRole(OFFICE));
    // UNSPECIFIC ATTRIBUTES
    model.addAttribute("year", year);
    model.addAttribute("action", action);
    model.addAttribute("shortcut", shortcut);
}
Also used : WorkingTime(org.synyx.urlaubsverwaltung.workingtime.WorkingTime) PathVariable(org.springframework.web.bind.annotation.PathVariable) Errors(org.springframework.validation.Errors) RequestParam(org.springframework.web.bind.annotation.RequestParam) UnknownPersonException(org.synyx.urlaubsverwaltung.person.UnknownPersonException) WorkingTime(org.synyx.urlaubsverwaltung.workingtime.WorkingTime) DateRange(org.synyx.urlaubsverwaltung.absence.DateRange) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApplicationCommentService(org.synyx.urlaubsverwaltung.application.comment.ApplicationCommentService) Controller(org.springframework.stereotype.Controller) IS_BOSS_OR_DEPARTMENT_HEAD_OR_SECOND_STAGE_AUTHORITY(org.synyx.urlaubsverwaltung.security.SecurityRules.IS_BOSS_OR_DEPARTMENT_HEAD_OR_SECOND_STAGE_AUTHORITY) LinkedHashMap(java.util.LinkedHashMap) Model(org.springframework.ui.Model) DateUtil(org.synyx.urlaubsverwaltung.util.DateUtil) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) DEPARTMENT_HEAD(org.synyx.urlaubsverwaltung.person.Role.DEPARTMENT_HEAD) AccountService(org.synyx.urlaubsverwaltung.account.AccountService) Collectors.toMap(java.util.stream.Collectors.toMap) PersonService(org.synyx.urlaubsverwaltung.person.PersonService) ApplicationCommentValidator(org.synyx.urlaubsverwaltung.application.comment.ApplicationCommentValidator) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) Comparator.comparing(java.util.Comparator.comparing) Account(org.synyx.urlaubsverwaltung.account.Account) ApplicationComment(org.synyx.urlaubsverwaltung.application.comment.ApplicationComment) ALLOWED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED) WAITING(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.WAITING) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) PostMapping(org.springframework.web.bind.annotation.PostMapping) Person(org.synyx.urlaubsverwaltung.person.Person) AccessDeniedException(org.springframework.security.access.AccessDeniedException) String.format(java.lang.String.format) BOSS(org.synyx.urlaubsverwaltung.person.Role.BOSS) List(java.util.List) WorkingTimeService(org.synyx.urlaubsverwaltung.workingtime.WorkingTimeService) ALLOWED_CANCELLATION_REQUESTED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED_CANCELLATION_REQUESTED) OFFICE(org.synyx.urlaubsverwaltung.person.Role.OFFICE) ApplicationCommentForm(org.synyx.urlaubsverwaltung.application.comment.ApplicationCommentForm) LocalDate(java.time.LocalDate) Clock(java.time.Clock) Optional(java.util.Optional) DepartmentService(org.synyx.urlaubsverwaltung.department.DepartmentService) WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) VacationDaysService(org.synyx.urlaubsverwaltung.account.VacationDaysService) TEMPORARY_ALLOWED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.TEMPORARY_ALLOWED) SECOND_STAGE_AUTHORITY(org.synyx.urlaubsverwaltung.person.Role.SECOND_STAGE_AUTHORITY) Account(org.synyx.urlaubsverwaltung.account.Account) DateRange(org.synyx.urlaubsverwaltung.absence.DateRange) ApplicationComment(org.synyx.urlaubsverwaltung.application.comment.ApplicationComment) ApplicationCommentForm(org.synyx.urlaubsverwaltung.application.comment.ApplicationCommentForm) LinkedHashMap(java.util.LinkedHashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Example 2 with WorkDaysCountService

use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.

the class VacationDaysServiceTest method testGetUsedDaysBeforeApril.

@Test
void testGetUsedDaysBeforeApril() {
    final String expectedUsedDays = "4";
    final Person person = new Person("muster", "Muster", "Marlene", "muster@example.org");
    when(applicationService.getApplicationsForACertainPeriodAndPerson(any(), any(), eq(person))).thenReturn(Collections.singletonList(getSomeApplication(person)));
    final WorkDaysCountService workDaysCountService = mock(WorkDaysCountService.class);
    when(workDaysCountService.getWorkDaysCount(any(), any(), any(), eq(person))).thenReturn(new BigDecimal(expectedUsedDays));
    final Clock clock = Clock.systemUTC();
    VacationDaysService sut = new VacationDaysService(workDaysCountService, applicationService, clock);
    final Account account = new Account();
    account.setPerson(person);
    account.setValidFrom(LocalDate.now(clock));
    account.setValidTo(ZonedDateTime.now(clock).plusDays(10).toLocalDate());
    final BigDecimal usedDaysBeforeApril = sut.getUsedDaysBeforeApril(account);
    assertThat(usedDaysBeforeApril).isEqualTo(new BigDecimal(expectedUsedDays));
}
Also used : WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) Clock(java.time.Clock) Person(org.synyx.urlaubsverwaltung.person.Person) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 3 with WorkDaysCountService

use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.

the class VacationDaysServiceTest method testGetUsedDaysAfterApril.

@Test
void testGetUsedDaysAfterApril() {
    final String expectedUsedDays = "4";
    final Person person = new Person("muster", "Muster", "Marlene", "muster@example.org");
    when(applicationService.getApplicationsForACertainPeriodAndPerson(any(), any(), eq(person))).thenReturn(Collections.singletonList(getSomeApplication(person)));
    final WorkDaysCountService workDaysCountService = mock(WorkDaysCountService.class);
    when(workDaysCountService.getWorkDaysCount(any(), any(), any(), eq(person))).thenReturn(new BigDecimal(expectedUsedDays));
    final Clock clock = Clock.systemUTC();
    VacationDaysService sut = new VacationDaysService(workDaysCountService, applicationService, clock);
    final Account account = new Account();
    account.setPerson(person);
    account.setValidFrom(LocalDate.now(clock));
    account.setValidTo(ZonedDateTime.now(clock).plusDays(10).toLocalDate());
    final BigDecimal usedDaysAfterApril = sut.getUsedDaysAfterApril(account);
    assertThat(usedDaysAfterApril).isEqualTo(new BigDecimal(expectedUsedDays));
}
Also used : WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) Clock(java.time.Clock) Person(org.synyx.urlaubsverwaltung.person.Person) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with WorkDaysCountService

use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.

the class CalculationServiceTest method setUp.

@BeforeEach
void setUp() {
    final PublicHolidaysService publicHolidaysService = new PublicHolidaysServiceImpl(settingsService, Map.of("de", getHolidayManager()));
    final WorkDaysCountService workDaysCountService = new WorkDaysCountService(publicHolidaysService, workingTimeService);
    sut = new CalculationService(vacationDaysService, accountService, accountInteractionService, workDaysCountService, new OverlapService(null, null), applicationService);
}
Also used : WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) PublicHolidaysServiceImpl(org.synyx.urlaubsverwaltung.publicholiday.PublicHolidaysServiceImpl) OverlapService(org.synyx.urlaubsverwaltung.overlap.OverlapService) PublicHolidaysService(org.synyx.urlaubsverwaltung.publicholiday.PublicHolidaysService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with WorkDaysCountService

use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.

the class VacationDaysServiceTest method setUp.

@BeforeEach
void setUp() {
    workDaysCountService = new WorkDaysCountService(new PublicHolidaysServiceImpl(settingsService, Map.of("de", getHolidayManager())), workingTimeService);
    sut = new VacationDaysService(workDaysCountService, applicationService, Clock.systemUTC());
}
Also used : WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) PublicHolidaysServiceImpl(org.synyx.urlaubsverwaltung.publicholiday.PublicHolidaysServiceImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

WorkDaysCountService (org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService)6 Person (org.synyx.urlaubsverwaltung.person.Person)4 BigDecimal (java.math.BigDecimal)3 Clock (java.time.Clock)3 Test (org.junit.jupiter.api.Test)3 LocalDate (java.time.LocalDate)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 String.format (java.lang.String.format)1 Comparator.comparing (java.util.Comparator.comparing)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Controller (org.springframework.stereotype.Controller)1 Model (org.springframework.ui.Model)1 Errors (org.springframework.validation.Errors)1