private File createTemp(MultipartFile multipartFile, User posteur) { String[] s = multipartFile.getOriginalFilename().split("\\."); String extention = ""; if (s.length > 1) { extention = s[s.length - 1]; } String chemin = "tmp"; chemin += posteur.getLogin(); chemin += "_" + new Date().getTime(); chemin += new Random().nextInt(10000); chemin += "." + extention; File temporaire = new File(chemin); try { multipartFile.transferTo(temporaire); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return temporaire; }
public static User getUtilisateurToutDroit() { User user = new User(); user.setLogin("krack"); Set<Role> roles = new HashSet<Role>(); Role roleAuth = new Role(); roleAuth.setRole(RoleEnum.ROLE_AUTHENTIFIER.toString()); roles.add(roleAuth); Role roleForum = new Role(); roleForum.setRole(RoleEnum.ROLE_ADMINISTRATEUR_FORUM.toString()); roles.add(roleForum); user.setRoles(roles); return user; }
public boolean equals(User user) { if (user == null) { return false; } boolean egal = true; egal = egal && this.getLogin().toLowerCase().equals(user.getLogin().toLowerCase()); return egal; }
@Override public List<Media> getMediaReadForAlbum(Album album, User utilisateurCourant) { String request = "SELECT m " + " FROM Media as m" + " WHERE m.album.id=? " + " and exists (" + " from LectureAlbum as l where l.utilisateur.login=? and l.mediaVu = m" + " )"; List<Media> medias = this.getHibernateTemplate().find(request, album.getId(), utilisateurCourant.getLogin()); return medias; }
@Override public boolean isAlbumHasNotSeeMedia(Album album, User utilisateurCourant) { String request = "SELECT m " + " FROM Media as m" + " WHERE m.album.id=? " + " and not exists (" + " from LectureAlbum as l where l.utilisateur.login=? and l.mediaVu = m" + " )"; List<Media> medias = this.getHibernateTemplate().find(request, album.getId(), utilisateurCourant.getLogin()); return !medias.isEmpty(); }
public static User getUtilisateurSansDroit() { User user = new User(); user.setLogin("loulou"); return user; }