@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/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(); } }
@AuthenticationRequired @RequestMapping( value = "fileUpload/metainfo/{uuid}", method = RequestMethod.GET, produces = {"application/json"}) @ResponseBody @ResponseStatus(value = HttpStatus.OK) public ResourceStatus<FileUpload> getFile( final HttpServletRequest request, HttpServletResponse response, @PathVariable String uuid) throws AccessDeniedException, UnauthorizedException, SessionTimeoutException { setupAuthenticatedContext(sessionUtils.getSession(request), sessionUtils.getLocale(request)); try { return new ResourceStatus<FileUpload>(resourceService.getFileByUuid(uuid)); } catch (ResourceException ex) { return new ResourceStatus<FileUpload>(false, ex.getMessage()); } finally { clearAuthenticatedContext(); } }