@@ -0,0 +1,1668 @@
+package de.springbootbuch.reactive.filmstore.support;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport de.springbootbuch.reactive.filmstore.Film;%0Aimport de.springbootbuch.reactive.filmstore.FilmRepository;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.boot.CommandLineRunner;%0Aimport org.springframework.core.io.ResourceLoader;%0Aimport org.springframework.stereotype.Component;%0Aimport reactor.core.publisher.Flux;%0A%0A/**%0A * Part of springbootbuch.de.%0A *%0A * @author Michael J. Simons%0A * @author @rotnroll666%0A */%0A@Component%0Apublic class FilmRepositoryPopulator implements CommandLineRunner %7B%0A%0A%09static final Logger LOG = LoggerFactory%0A%09%09.getLogger(FilmRepositoryPopulator.class);%0A%0A%09private final ResourceLoader resourceLoader;%0A%0A%09private final ObjectMapper objectMapper;%0A%0A%09private final FilmRepository filmRepository;%0A%0A%09public FilmRepositoryPopulator(ResourceLoader resourceLoader, ObjectMapper objectMapper, FilmRepository filmRepository) %7B%0A%09%09this.resourceLoader = resourceLoader;%0A%09%09this.objectMapper = objectMapper;%0A%09%09this.filmRepository = filmRepository;%0A%09%7D%0A%0A%09@Override%0A%09public void run(String... strings) throws Exception %7B%0A%09%09// This is a blocking operation...%0A%09%09// Didn't find a simple way to present it in the book.%0A%09%09// Feel free to send me a PR :)%0A%09%09final Film%5B%5D films = this.objectMapper.readValue(%0A%09%09%09this.resourceLoader.getResource(%22classpath:/data.json%22).getInputStream(),%0A%09%09%09Film%5B%5D.class);%0A%0A%09%09this.filmRepository%0A%09%09%09.deleteAll()%0A%09%09%09.thenMany(Flux.just(films))%0A%09%09%09.flatMap(m -%3E this.filmRepository.save((Film)m))%0A%09%09%09.doOnNext(m -%3E LOG.info(%22Film '%7B%7D' (id=%7B%7D) saved%22, m.getTitle(), m.getId()))%0A%09%09%09.blockLast();%0A%09%7D%0A%7D%0A

Add FilmRepositoryPopulator