Esempio n. 1
0
  @Transactional
  public Movie getMovie(String id) throws Exception {
    MovieData md = movieRepository.getAMovie(id);
    LOG.debug("Movie data after getting a movie is {}", md);

    Movie movie = movieRepository.findById(id);
    LOG.debug(
        "Movie by id {} is {} with cast {} and directors {}",
        id,
        movie,
        movie.getActors(),
        movie.getDirectors());
    LOG.debug("Movie by id {} has roles {}", id, movie.getRoles());

    return movie;
  }
Esempio n. 2
0
  @Transactional
  public CastData getCast(String id) throws Exception {
    CastData md = movieRepository.getCast(id);
    LOG.debug("Movie data after getting a movie is {}", md);

    return md;
  }
Esempio n. 3
0
  @Transactional
  public Iterable<Movie> updateMovies(List<Movie> movies) {
    List<Movie> savedMovies = new ArrayList<>();
    for (Movie movie : movies) {
      Movie repoMovie = movieRepository.findById(movie.getId());

      LOG.info("repoMovie by id {} = {}", repoMovie.getId(), repoMovie);
      if (repoMovie != null) {
        mergeMovie(movie, repoMovie);
        savedMovies.add(movieRepository.save(repoMovie));
      } else {
        LOG.error("Movie {} not found", movie.getId());
      }
    }
    return savedMovies;
  }
Esempio n. 4
0
 @Transactional
 public List<Movie> addMovies(List<Map> movieData) throws Exception {
   List<Movie> savedMovies = new ArrayList<>();
   for (Map movieInfo : movieData) {
     Set<Genre> genres = new HashSet<>();
     Movie movie = new Movie("" + (new Random().nextInt(Integer.MAX_VALUE)), null);
     TmdbJsonMapper.mapToMovie(movieInfo, genres, movie);
     savedMovies.add(movieRepository.save(movie));
   }
   return savedMovies;
 }
Esempio n. 5
0
 @Transactional
 public List<Director> addCrew(String id, List<Director> crew) throws Exception {
   List<Director> savedDirectors = new ArrayList<>();
   for (Director director : crew) {
     director.setId("" + new Random().nextInt(Integer.MAX_VALUE));
     template.save(director);
     Movie movie = movieRepository.findById(id);
     LOG.info("Movie {} = {} ", id, movie);
     director.directed(movie);
     savedDirectors.add(directorRepository.save(director));
   }
   return savedDirectors;
 }
Esempio n. 6
0
  @Transactional
  public Collection<Rating> saveRatings(String userLogin, String id, List<Rating> rating) {

    LOG.info(
        "user {} has rated movie {} as {} commented {}",
        userLogin,
        id,
        rating.get(0).getStars(),
        rating.get(0).getComment());

    Movie movie = movieRepository.findById(id);
    User u = userRepository.findByLogin(userLogin);
    u.rate(template, movie, rating.get(0).getStars(), rating.get(0).getComment());

    return rating;
  }
Esempio n. 7
0
 @Transactional
 public List<Review> saveReviews(String userLogin, String id, List<Review> reviews) {
   Movie movie = movieRepository.findById(id);
   User user = userRepository.findByLogin(userLogin);
   Review review = template.save(reviews.get(0));
   user.addReview(review);
   review.reviewed(movie);
   template.save(review);
   template.save(user);
   ;
   return new ArrayList<Review>() {
     {
       add(review);
     }
   };
 }
Esempio n. 8
0
  @Transactional
  public List<Actor> addCast(String id, List<Actor> cast) throws Exception {
    List<Actor> savedActors = new ArrayList<>();
    Movie movie = movieRepository.findById(id);
    LOG.info("Movie {} = {} ", id, movie);

    for (Actor actor : cast) {
      Actor repoActor = actorRepository.findByName(actor.getName());
      String role = cast.get(0).getRoles().iterator().next().getName();
      if (repoActor == null) {
        actor.setId("" + new Random().nextInt(Integer.MAX_VALUE));
        actor.setRoles(new HashSet<>());
        template.save(actor);
        actor.playedIn(movie, role);
        savedActors.add(actorRepository.save(actor));
      } else {
        repoActor.playedIn(movie, role);
        Actor a = actorRepository.save(repoActor);
        LOG.info("actor saved is {}", a, a.getRoles());
        savedActors.add(a);
      }
    }
    return savedActors;
  }
Esempio n. 9
0
 @Transactional
 public Page<Movie> getMovies(Pageable pageable) throws Exception {
   return movieRepository.findAll(pageable);
 }
Esempio n. 10
0
 @Transactional
 public Page<Review> getReviews(String movieId, Pageable pageable) throws Exception {
   return movieRepository.findReviews(movieId, pageable);
 }