@RolesAllowed(value = {"ROLE_USER"}) @RequestMapping(method = RequestMethod.POST, value = "/uploadMeta", produces = "application/json") @ResponseBody public Map<String, Object> saveUploadMetadata( HttpServletRequest request, @RequestBody PresentationMetaDTO presentationData) { Map<String, Object> result = null; Presentation data = new Presentation( presentationData.getTitle(), presentationData.getDescription(), presentationData.getSlideDuration()); try { if (data.isValidData()) { Cathegory cat = getCathegoryByName(presentationData.getCathegory()); data.setUser(getCurrentUser()); data.setCathegory(cat); HttpSession session = request.getSession(); session.setAttribute(UPLOAD_METADATA, data); result = JsonUtils.successJson(); } else { result = JsonUtils.failureJson( messages.getMessage("validation.upload.data.is.incorect", null, null)); } } catch (PresentationException e) { result = JsonUtils.failureJson( messages.getMessage("validation.upload.data.is.incorect", null, null)); } return result; }
private Presentation uploadFileToRepo(CommonsMultipartFile uploadedFile, HttpSession session) throws IOException, UploadedDataNotFoundException, IncorectFileException { Presentation data = (Presentation) session.getAttribute(UPLOAD_METADATA); if (data != null) { String fileExtension = FilenameUtils.getExtension(uploadedFile.getOriginalFilename()); if (isCorectFileExtension(fileExtension)) { checkPreviousUploads(data); data.setRepositoryName(UUID.randomUUID().toString()); data.setRepositoryPath(REPO_UPLOAD_LOCATION); data.setOriginalExtension(fileExtension); File file = createFile(data, fileExtension); uploadedFile.transferTo(file); return data; } else { throw new IncorectFileException(); } } else { throw new UploadedDataNotFoundException(); } }
private File createFile(Presentation data, String fileExtension) { File file = new File( REPO_HOME + "/" + REPO_UPLOAD_LOCATION + "/" + data.getRepositoryName() + "." + fileExtension); return file; }
private void checkPreviousUploads(Presentation data) { File file = createFile(data, data.getOriginalExtension()); FileUtils.deleteQuietly(file); }