@RequestMapping(value = "/staff/{personId}/overview", method = RequestMethod.GET)
  public String showOverview(
      @PathVariable("personId") Integer personId,
      @RequestParam(value = ControllerConstants.YEAR_ATTRIBUTE, required = false) String year,
      Model model) {

    java.util.Optional<Person> optionalPerson = personService.getPersonByID(personId);

    if (!optionalPerson.isPresent()) {
      return ControllerConstants.ERROR_JSP;
    }

    Person person = optionalPerson.get();
    Person signedInUser = sessionService.getSignedInUser();

    boolean isOwnOverviewPage = person.getId().equals(signedInUser.getId());
    boolean isOffice = signedInUser.hasRole(Role.OFFICE);
    boolean isBoss = signedInUser.hasRole(Role.BOSS);
    boolean isDepartmentHead = departmentService.isDepartmentHeadOfPerson(signedInUser, person);

    if (!isOwnOverviewPage && !isOffice && !isBoss && !isDepartmentHead) {
      return ControllerConstants.ERROR_JSP;
    }

    model.addAttribute(PersonConstants.PERSON_ATTRIBUTE, person);

    Integer yearToShow = parseYearParameter(year);
    prepareApplications(person, yearToShow, model);
    prepareHolidayAccounts(person, yearToShow, model);
    prepareSickNoteList(person, yearToShow, model);

    model.addAttribute(ControllerConstants.YEAR_ATTRIBUTE, DateMidnight.now().getYear());

    return "person/overview";
  }
  @Test
  public void ensurePersonCanBeCreatedWithOnlyLoginName() {

    Person person = TestDataCreator.createPerson();

    Mockito.when(
            personService.create(
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyListOf(MailNotification.class),
                Mockito.anyListOf(Role.class)))
        .thenReturn(person);

    ldapSyncService.createPerson("murygina", Optional.empty(), Optional.empty(), Optional.empty());

    Mockito.verify(personService)
        .create(
            "murygina",
            null,
            null,
            null,
            Collections.singletonList(MailNotification.NOTIFICATION_USER),
            Collections.singletonList(Role.USER));
  }
  @Test
  public void ensurePersonIsCreatedWithCorrectAttributes() {

    Person person = TestDataCreator.createPerson();

    Mockito.when(
            personService.create(
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyListOf(MailNotification.class),
                Mockito.anyListOf(Role.class)))
        .thenReturn(person);

    ldapSyncService.createPerson(
        "murygina",
        Optional.of("Aljona"),
        Optional.of("Murygina"),
        Optional.of("*****@*****.**"));

    Mockito.verify(personService)
        .create(
            "murygina",
            "Murygina",
            "Aljona",
            "*****@*****.**",
            Collections.singletonList(MailNotification.NOTIFICATION_USER),
            Collections.singletonList(Role.USER));
  }
  private void fillModel(Model model, List<SickNote> sickNotes, FilterPeriod period) {

    model.addAttribute("today", DateMidnight.now());
    model.addAttribute("from", period.getStartDate());
    model.addAttribute("to", period.getEndDate());
    model.addAttribute("period", period);

    List<Person> persons = personService.getActivePersons();

    List<SickNote> sickNotesOfActivePersons =
        sickNotes
            .stream()
            .filter(sickNote -> persons.contains(sickNote.getPerson()) && sickNote.isActive())
            .collect(Collectors.toList());

    Map<Person, SickDays> sickDays = new HashMap<>();
    Map<Person, SickDays> childSickDays = new HashMap<>();

    for (Person person : persons) {
      sickDays.put(person, new SickDays());
      childSickDays.put(person, new SickDays());
    }

    for (SickNote sickNote : sickNotesOfActivePersons) {
      Person person = sickNote.getPerson();
      BigDecimal workDays =
          calendarService.getWorkDays(
              sickNote.getDayLength(), sickNote.getStartDate(), sickNote.getEndDate(), person);

      if (sickNote.getSickNoteType().isOfCategory(SickNoteCategory.SICK_NOTE_CHILD)) {
        childSickDays.get(person).addDays(SickDays.SickDayType.TOTAL, workDays);

        if (sickNote.isAubPresent()) {
          BigDecimal workDaysWithAUB =
              calendarService.getWorkDays(
                  sickNote.getDayLength(),
                  sickNote.getAubStartDate(),
                  sickNote.getAubEndDate(),
                  person);

          childSickDays.get(person).addDays(SickDays.SickDayType.WITH_AUB, workDaysWithAUB);
        }
      } else {
        sickDays.get(person).addDays(SickDays.SickDayType.TOTAL, workDays);

        if (sickNote.isAubPresent()) {
          BigDecimal workDaysWithAUB =
              calendarService.getWorkDays(
                  sickNote.getDayLength(),
                  sickNote.getAubStartDate(),
                  sickNote.getAubEndDate(),
                  person);

          sickDays.get(person).addDays(SickDays.SickDayType.WITH_AUB, workDaysWithAUB);
        }
      }
    }

    model.addAttribute("sickDays", sickDays);
    model.addAttribute("childSickDays", childSickDays);

    model.addAttribute(PersonConstants.PERSONS_ATTRIBUTE, persons);
  }