@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; }
@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; }
private void mergeMovie(Movie movie, Movie repoMovie) { repoMovie.setTitle(movie.getTitle()); repoMovie.setGenre(movie.getGenre()); }