@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/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();
 }