@AuthenticationRequired
  @RequestMapping(
      value = "fileUpload/file/{uuid}",
      method = RequestMethod.DELETE,
      produces = {"application/json"})
  @ResponseBody
  @ResponseStatus(value = HttpStatus.OK)
  public ResourceStatus<FileUpload> deleteFile(
      final HttpServletRequest request, HttpServletResponse response, @PathVariable String uuid)
      throws AccessDeniedException, UnauthorizedException, SessionTimeoutException {

    setupAuthenticatedContext(sessionUtils.getSession(request), sessionUtils.getLocale(request));
    try {
      FileUpload fileUpload = resourceService.getFileByUuid(uuid);
      if (fileUpload == null) {
        return new ResourceStatus<FileUpload>(
            false,
            I18N.getResource(
                sessionUtils.getLocale(request),
                FileUploadServiceImpl.RESOURCE_BUNDLE,
                "fileUpload.cannotFindFile",
                uuid));
      }

      String preDeletedName = fileUpload.getFileName();
      resourceService.deleteFile(fileUpload);
      return new ResourceStatus<FileUpload>(
          true,
          I18N.getResource(
              sessionUtils.getLocale(request),
              FileUploadServiceImpl.RESOURCE_BUNDLE,
              "fileUpload.deleted",
              preDeletedName));

    } catch (ResourceException e) {
      log.error("File upload failed", e);
      return new ResourceStatus<FileUpload>(false, e.getMessage());
    } catch (Throwable e) {
      log.error("File upload failed", e);
      return new ResourceStatus<FileUpload>(
          false,
          I18N.getResource(
              sessionUtils.getLocale(request),
              FileUploadServiceImpl.RESOURCE_BUNDLE,
              "fileUpload.error",
              e.getMessage()));

    } finally {
      clearAuthenticatedContext();
    }
  }
  @AuthenticationRequired
  @RequestMapping(
      value = "fileUpload/file",
      method = RequestMethod.POST,
      produces = {"application/json"})
  @ResponseBody
  @ResponseStatus(value = HttpStatus.OK)
  public ResourceStatus<FileUpload> createFile(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestPart(value = "file") MultipartFile file)
      throws AccessDeniedException, UnauthorizedException, SessionTimeoutException {

    setupAuthenticatedContext(sessionUtils.getSession(request), sessionUtils.getLocale(request));
    try {

      FileUpload fileUpload;

      Realm realm = sessionUtils.getCurrentRealm(request);
      fileUpload = resourceService.createFile(file, realm, "upload");

      return new ResourceStatus<FileUpload>(
          fileUpload,
          I18N.getResource(
              sessionUtils.getLocale(request),
              FileUploadServiceImpl.RESOURCE_BUNDLE,
              "fileUpload.uploaded.info",
              fileUpload.getName()));

    } catch (ResourceCreationException e) {
      log.error("File upload failed", e);
      return new ResourceStatus<FileUpload>(false, e.getMessage());
    } catch (Throwable e) {
      log.error("File upload failed", e);
      return new ResourceStatus<FileUpload>(
          false,
          I18N.getResource(
              sessionUtils.getLocale(request),
              FileUploadServiceImpl.RESOURCE_BUNDLE,
              "fileUpload.error",
              e.getMessage()));

    } finally {
      clearAuthenticatedContext();
    }
  }