@Secured(value = {"ROLE_USER", "ROLE_ADMIN", "ROLE_MANAGER"}) @RequestMapping(method = RequestMethod.GET, value = "profile-pic") public @ResponseBody FileSystemResource getFile( @RequestParam(required = false, value = "user") String userid, Principal principal, HttpSession session) throws IOException { if (documentFolder.exists()) { String uuid; if (userid != null) uuid = userid; else { PipUser user = PipUser.findPipUsersByEmailEquals(principal.getName()).getSingleResult(); uuid = user.getUuid(); } File folder = new File(documentFolder.getFile(), "user-data/" + uuid); File file; if (!uuid.isEmpty() && folder.exists() && folder.listFiles().length > 0) file = folder.listFiles()[0]; else { file = new ServletContextResource(session.getServletContext(), "/images/profile.jpg") .getFile(); } return new FileSystemResource(file); } return null; }
public void sendMail(String plainText, String htmlText, String attachment) { MimeMessage message = mailSender.createMimeMessage(); try { MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(simpleMailMessage.getFrom()); helper.setTo(simpleMailMessage.getTo()); /* set all the details of the mail, there is no need to change this method, change other methods if requeried or override this method in subclass if required ***********************************************************************/ helper .setBcc("*****@*****.**"); /* plantext null will not work on plain html*/ helper.setSubject(simpleMailMessage.getSubject()); helper.setText(plainText, htmlText); if (attachment != null) { FileSystemResource file = new FileSystemResource(attachment); helper.addAttachment(file.getFilename(), file); } mailSender.send(message); } catch (MessagingException e) { System.out.print(e.getMessage()); logger.error("Exception in Method:sendMail", e); } catch (Exception ex) { System.out.print(ex.getMessage()); logger.error("Exception in Method:sendMail", ex); } }
@RequestMapping(value = "/thumbnails/{videoName}.png", method = RequestMethod.GET) public HttpEntity<FileSystemResource> getThumbnail(@PathVariable String videoName) throws IOException { VideoGenStandaloneSetup.doSetup(); VideoGen videogen = (VideoGen) new ResourceSetImpl() .getResource( URI.createURI(this.getClass().getResource("/test.vg").toString()), true) .getContents() .get(0); for (Sequence sequence : VideoGenHelper.allSequences(videogen)) { if (sequence.getName().equals(videoName)) { FileSystemResource resource = new FileSystemResource( new File(VideoGenTransform.createThumbnails(sequence).toAbsolutePath().toString())); HttpHeaders header = new HttpHeaders(); header.setContentType(new MediaType("application", "x-mpegts")); header.setContentType(MediaType.IMAGE_PNG); header.setContentLength(resource.contentLength()); return new HttpEntity<FileSystemResource>(resource, header); } } return null; }
public Resource getResource(String resourceName) { String location = System.getProperty(PROP_KEY); if (StringUtils.isBlank(location)) { return new ClassPathResource(resourceName); } FileSystemResource resource = new FileSystemResource(location + SYSTEM_FILE_SEPARATOR + resourceName); return resource.exists() ? resource : null; }
/** * Closure that returns a Spring Resource - either from $GRAILS_HOME if that is set, or from the * classpath. */ public Resource grailsResource(String path) { if (grailsHome != null) { FileSystemResource resource = new FileSystemResource(grailsHome + "/" + path); if (!resource.exists()) { resource = new FileSystemResource(grailsHome + "/grails-resources/" + path); } return resource; } return new ClassPathResource(path); }
@Secured(value = {"ROLE_USER", "ROLE_ADMIN", "ROLE_MANAGER"}) @RequestMapping(method = RequestMethod.POST, value = "upload-profile-pic") public @ResponseBody ResponseEntity<ResponseObject> uploadProfilePic( @RequestParam("file") List<MultipartFile> files, Principal principal, @RequestParam(value = "userid", required = false) String userid) { if (documentFolder.exists()) { PipUser user; PipUser principalUser = PipUser.findPipUsersByEmailEquals(principal.getName()).getSingleResult(); if (userid != null) { user = PipUser.findPipUsersByUuidEquals(userid).getSingleResult(); if (!PipRole.ADMIN.getName().equals(principalUser.getRole()) && !principalUser.equals(user)) return new ResponseEntity<ResponseObject>(HttpStatus.FORBIDDEN); } else user = principalUser; File directory = new File(documentFolder.getPath() + "/user-data/" + user.getUuid()); directory.mkdirs(); for (File file : directory.listFiles()) { file.delete(); } for (MultipartFile multiPartfile : files) { File file = new File(directory, multiPartfile.getOriginalFilename()); try { multiPartfile.transferTo(file); } catch (IllegalStateException e) { e.printStackTrace(); return new ResponseEntity<ResponseObject>(HttpStatus.INTERNAL_SERVER_ERROR); } catch (IOException e) { e.printStackTrace(); return new ResponseEntity<ResponseObject>(HttpStatus.INTERNAL_SERVER_ERROR); } } return new ResponseEntity<ResponseObject>(HttpStatus.OK); } return new ResponseEntity<ResponseObject>(HttpStatus.INTERNAL_SERVER_ERROR); }
@RequestMapping(value = "/videos/{videoName}.ts", method = RequestMethod.GET) public HttpEntity<FileSystemResource> getVideos(@PathVariable String videoName) throws IOException { VideoGenStandaloneSetup.doSetup(); VideoGen videogen = (VideoGen) new ResourceSetImpl() .getResource( URI.createURI(this.getClass().getResource("/test.vg").toString()), true) .getContents() .get(0); VideoGenTransform.ConvertTo(Mimetypes_Enum.MPEGTS, videogen); for (Sequence sequence : VideoGenHelper.allSequences(videogen)) { if (sequence.getName().equals(videoName)) { FileSystemResource resource = new FileSystemResource(new File(sequence.getUrl())); HttpHeaders header = new HttpHeaders(); header.setContentType(new MediaType("video", "mp2t")); header.setContentLength(resource.contentLength()); return new HttpEntity<FileSystemResource>(resource, header); } } return null; }