@PreAuthorize("isFullyAuthenticated()")
  @RequestMapping(value = "/getapplication", method = RequestMethod.GET)
  public ModelAndView getapplicationlist(
      @RequestParam(value = "page", required = false) Integer page,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    UserPrincipal user = userService.getUserByName(auth.getName());
    Status status = clientService.getStatusByName("zajavka ozhidaet obrabotku");
    if (page == null) page = 1;
    Integer pageSize = 3;
    Integer startPage = page;
    Integer endPage = page + 5;

    Number size1 = directorService.getSizeApplicationByStatus(status);
    int size = Integer.parseInt(size1.toString());

    Integer lastPage = (size + (pageSize - 1)) / pageSize;

    if (endPage >= lastPage) endPage = lastPage;
    if (endPage >= 5 && (endPage - startPage) < 5) startPage = endPage - 5;

    mav.addObject("page", page);
    mav.addObject("startpage", startPage);
    mav.addObject("endpage", endPage);

    mav.addObject("user", user);
    mav.addObject(
        "application",
        directorService.getApplicationByStatus(status, (page - 1) * pageSize, pageSize));
    mav.setViewName("director.applicationlist");
    return mav;
  };
  @RequestMapping(
      value = {"/updateapplication/{id}"},
      method = {RequestMethod.POST})
  public ModelAndView updateapplication(
      @PathVariable Long id,
      @ModelAttribute("application") Application application,
      Model model,
      BindingResult bindingResult,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    Application application1 = mechanicService.getApplicationById(id);
    applicationValidator.validate(application, bindingResult);
    if (bindingResult.hasErrors()) {

      UserPrincipal user = userService.getUserByName(auth.getName());
      Number size1 = directorService.getSizeMechanicOnSto(application1.getSto());
      int size = Integer.parseInt(size1.toString());
      mav.addObject("application", application1);
      mav.addObject("statuss", directorService.getStatus());
      mav.addObject("mechanics", directorService.getMechanicsOnSto(application1.getSto(), 0, size));
      mav.addObject("user", user);
      mav.setViewName("director.updateapplication");
      return mav;
    }

    application1.setMechanic(application.getMechanic());
    application1.setStatus(application.getStatus());
    clientService.addOrUpdateApplication(application1);
    mav.setViewName("redirect:/home");
    return mav;
  }