Guest User

Untitled

a guest
Jun 19th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. @Component
  2. public class MysqlESSync {
  3.  
  4. private static final Logger logger = LoggerFactory.getLogger(MysqlESSync.class);
  5.  
  6. @Autowired
  7. private RecipeRepositoryES recipeRepositoryES;
  8.  
  9. @Autowired
  10. private RecipeRepository recipeRepository;
  11.  
  12. @Transactional
  13. public void run() throws Exception {
  14. logger.info("Sync started");
  15. int nrecords = 0;
  16. for (RecipeEntity recipeEntity : recipeRepository.findAll()) {
  17. nrecords++;
  18.  
  19. RecipeEntityES recipeEntityES = new RecipeEntityES();
  20. recipeEntityES.setAuthor(recipeEntity.getAuthor());
  21. recipeEntityES.setCategories(recipeEntity.getCategories().stream().map(CategoryEntity::getName).collect(Collectors.toList()));
  22. recipeEntityES.setImages(recipeEntity.getImages().getUrl());
  23.  
  24.  
  25. recipeRepositoryES.save(recipeEntityES);
  26.  
  27. logger.info("Record {} saved", recipeEntityES);
  28. }
  29.  
  30. logger.info("Sync ended with {} records", nrecords);
  31. }
  32.  
  33. }
Add Comment
Please, Sign In to add comment