@PreAuthorize("hasAuthority('ADMIN')")
  @RequestMapping(value = "/admin/media/delete/{id}", method = RequestMethod.GET)
  public String delete(@PathVariable Long id) {
    LOGGER.debug("delete media " + id);
    Media media = mediaService.getMediaById(id).get();
    String page = media.getPage();
    String type = media.getType();

    mediaService.deleteMedia(id);

    return "redirect:/admin/media/list/" + page + "/" + type;
  }
 @PreAuthorize("hasAuthority('ADMIN')")
 @RequestMapping(value = "/admin/media/list/{page}/{type}", method = RequestMethod.GET)
 public ModelAndView listMedia(@PathVariable String page, @PathVariable String type) {
   LOGGER.debug("Getting media list");
   return new ModelAndView(
       "media/medialist", "medialist", mediaService.getMediaByPageAndType(page, type));
 }
 @PreAuthorize("hasAuthority('ADMIN')")
 @RequestMapping(value = "/admin/media/update/{id}", method = RequestMethod.GET)
 public ModelAndView getMediaUpdatePage(@PathVariable Long id) {
   LOGGER.debug("Getting user update form");
   return new ModelAndView(
       "media/mediaupdate",
       "media",
       mediaService
           .getMediaById(id)
           .orElseThrow(
               () -> new NoSuchElementException(String.format("Media=%s not found", id))));
 }
 @PreAuthorize("@mediaServiceImpl.canAccessUser(principal, #id)")
 @RequestMapping("/admin/media/{id}")
 public ModelAndView getMediaPage(@PathVariable Long id) {
   LOGGER.debug("Getting Media page for Media={}", id);
   return new ModelAndView(
       "media/media",
       "media",
       mediaService
           .getMediaById(id)
           .orElseThrow(
               () -> new NoSuchElementException(String.format("Media=%s not found", id))));
 }
 @PreAuthorize("hasAuthority('ADMIN')")
 @RequestMapping(value = "/admin/media/update", method = RequestMethod.POST)
 public String handleMediaUpdateForm(
     @Valid @ModelAttribute("media") Media media, BindingResult bindingResult) {
   LOGGER.debug("Processing media update form={}, bindingResult={}", media, bindingResult);
   if (bindingResult.hasErrors()) {
     // failed validation
     return "media/mediaupdate";
   }
   try {
     mediaService.update(media);
   } catch (DataIntegrityViolationException e) {
     // probably email already exists - very rare case when multiple admins are adding same user
     // at the same time and form validation has passed for more than one of them.
     LOGGER.warn("Exception occurred when trying to save media", e);
     bindingResult.reject("media.exists", "Media already exists");
     return "media/mediaupdate";
   }
   // ok, redirect
   return "redirect:/admin/media/list/" + media.getPage() + "/" + media.getType();
 }
 @PreAuthorize("hasAuthority('ADMIN')")
 @RequestMapping(value = "/admin/media/list", method = RequestMethod.GET)
 public ModelAndView listMedia() {
   LOGGER.debug("Getting media list");
   return new ModelAndView("media/medialist", "medialist", mediaService.getAllMedia());
 }