@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();
    }
  }
 @AuthenticationRequired
 @RequestMapping(
     value = "fileUpload/import",
     method = {RequestMethod.POST},
     produces = {"application/json"})
 @ResponseBody
 @ResponseStatus(value = HttpStatus.OK)
 public ResourceStatus<FileUpload> importLaunchers(
     HttpServletRequest request,
     HttpServletResponse response,
     @RequestParam(value = "file") MultipartFile jsonFile,
     @RequestParam(required = false) boolean dropExisting)
     throws AccessDeniedException, UnauthorizedException, SessionTimeoutException {
   setupAuthenticatedContext(sessionUtils.getSession(request), sessionUtils.getLocale(request));
   try {
     Thread.sleep(2000);
   } catch (Exception e) {
   }
   try {
     String json = IOUtils.toString(jsonFile.getInputStream());
     if (!HypersocketUtils.isValidJSON(json)) {
       throw new ResourceException(I18NServiceImpl.USER_INTERFACE_BUNDLE, "error.incorrectJSON");
     }
     Collection<FileUpload> collects =
         resourceService.importResources(json, getCurrentRealm(), dropExisting);
     return new ResourceStatus<FileUpload>(
         true,
         I18N.getResource(
             sessionUtils.getLocale(request),
             I18NServiceImpl.USER_INTERFACE_BUNDLE,
             "resource.import.success",
             collects.size()));
   } catch (ResourceException e) {
     return new ResourceStatus<FileUpload>(false, e.getMessage());
   } catch (Exception e) {
     return new ResourceStatus<FileUpload>(
         false,
         I18N.getResource(
             sessionUtils.getLocale(request),
             I18NServiceImpl.USER_INTERFACE_BUNDLE,
             "resource.import.failure",
             e.getMessage()));
   } finally {
     clearAuthenticatedContext();
   }
 }