public void updateShare(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    try {
      request = wrapRequest(request);
      User user = securityService.getCurrentUser(request);
      int id = ServletRequestUtils.getRequiredIntParameter(request, "id");

      Share share = shareService.getShareById(id);
      if (share == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Shared media not found.");
        return;
      }
      if (!user.isAdminRole() && !share.getUsername().equals(user.getUsername())) {
        error(
            request, response, ErrorCode.NOT_AUTHORIZED, "Not authorized to modify shared media.");
        return;
      }

      share.setDescription(request.getParameter("description"));
      String expiresString = request.getParameter("expires");
      if (expiresString != null) {
        long expires = Long.parseLong(expiresString);
        share.setExpires(expires == 0L ? null : new Date(expires));
      }
      shareService.updateShare(share);
      XMLBuilder builder = createXMLBuilder(request, response, true).endAll();
      response.getWriter().print(builder);

    } catch (ServletRequestBindingException x) {
      error(request, response, ErrorCode.MISSING_PARAMETER, getErrorMessage(x));
    } catch (Exception x) {
      LOG.warn("Error in REST API.", x);
      error(request, response, ErrorCode.GENERIC, getErrorMessage(x));
    }
  }
  public void deleteShare(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    try {
      request = wrapRequest(request);
      User user = securityService.getCurrentUser(request);
      int id = ServletRequestUtils.getRequiredIntParameter(request, "id");

      Share share = shareService.getShareById(id);
      if (share == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Shared media not found.");
        return;
      }
      if (!user.isAdminRole() && !share.getUsername().equals(user.getUsername())) {
        error(
            request, response, ErrorCode.NOT_AUTHORIZED, "Not authorized to delete shared media.");
        return;
      }

      shareService.deleteShare(id);
      XMLBuilder builder = createXMLBuilder(request, response, true).endAll();
      response.getWriter().print(builder);

    } catch (ServletRequestBindingException x) {
      error(request, response, ErrorCode.MISSING_PARAMETER, getErrorMessage(x));
    } catch (Exception x) {
      LOG.warn("Error in REST API.", x);
      error(request, response, ErrorCode.GENERIC, getErrorMessage(x));
    }
  }