Нет описания

TvSeriesController.java 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package fr.natan.akkastreamfileprocessingapi.controller;
  2. import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureBuilder;
  3. import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap;
  4. import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessingFuture;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.web.bind.annotation.PathVariable;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import play.api.libs.json.JsValue;
  12. import play.api.libs.json.Json;
  13. import scala.Option;
  14. import scala.collection.IndexedSeq;
  15. import scala.concurrent.Future;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.concurrent.CompletableFuture;
  19. import java.util.concurrent.ExecutionException;
  20. @SuppressWarnings("SpellCheckingInspection")
  21. @RestController
  22. public class TvSeriesController {
  23. private final AkkaStreamFileProcessingFuture akkaStreamFilesProcessing;
  24. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  25. public TvSeriesController(AkkaStreamFileProcessingFuture akkaStreamFilesProcessing) {
  26. this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
  27. }
  28. @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
  29. private String getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
  30. Future<Option<ModelsAndJsonMap.Person>> futurePerson = akkaStreamFilesProcessing.getPersonByIdFuture(personID);
  31. CompletableFuture<ModelsAndJsonMap.Person> completableFuture = CompletableFutureBuilder
  32. .buildcompletableFuture1(futurePerson);
  33. ModelsAndJsonMap.Person person = completableFuture.get();
  34. JsValue personJs = Json.toJson(person, person.personJsonFormatter());
  35. return Json.prettyPrint(personJs);
  36. }
  37. @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
  38. private String getPersonByName(@PathVariable(name = "primaryName") String primaryName)
  39. throws ExecutionException, InterruptedException {
  40. Future<Option<ModelsAndJsonMap.Person>> personFuture = akkaStreamFilesProcessing.getPersonByNameFuture(primaryName);
  41. CompletableFuture<ModelsAndJsonMap.Person> personCompletableFuture = CompletableFutureBuilder
  42. .buildcompletableFuture1(personFuture);
  43. ModelsAndJsonMap.Person person = personCompletableFuture.get();
  44. JsValue personJs = Json.toJson(person, person.personJsonFormatter());
  45. return Json.prettyPrint(personJs);
  46. }
  47. @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
  48. private String getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
  49. throws ExecutionException, InterruptedException {
  50. Future<Option<ModelsAndJsonMap.TvSerie>> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieByIdFuture(tvSerieID);
  51. CompletableFuture<ModelsAndJsonMap.TvSerie> tvSerieCompletableFuture = CompletableFutureBuilder
  52. .buildcompletableFuture1(tvSerieFuture);
  53. ModelsAndJsonMap.TvSerie tvSerie = tvSerieCompletableFuture.get();
  54. JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
  55. return Json.prettyPrint(tvSerieJs);
  56. }
  57. @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
  58. private List<String> getTvserieByPrimaryTitle(
  59. @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) throws InterruptedException, ExecutionException {
  60. Future<IndexedSeq<ModelsAndJsonMap.TvSerie>> listFuture = akkaStreamFilesProcessing
  61. .getTvSeriesByPrimaryTitleFuture(tvseriePrimaryTitle);
  62. CompletableFuture<IndexedSeq<ModelsAndJsonMap.TvSerie>> completableFuture =
  63. CompletableFutureBuilder.buildcompletableFuture2(listFuture);
  64. IndexedSeq<ModelsAndJsonMap.TvSerie> tvSerieList = completableFuture.get();
  65. List<String> tvSeries = new ArrayList<>();
  66. tvSerieList.foreach(tvSerie -> {
  67. JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
  68. tvSeries.add(Json.prettyPrint(tvSerieJs));
  69. return null;
  70. });
  71. return tvSeries;
  72. }
  73. @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
  74. private List<String> getPersonsForTvSerieByTvSerieTitle(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
  75. throws InterruptedException, ExecutionException {
  76. Future<IndexedSeq<ModelsAndJsonMap.Person>> futurePersonSeq = akkaStreamFilesProcessing
  77. .getPersonsForTvSerieByTvSerieTitleFuture(tvSerieTitle);
  78. CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> completableFuture = CompletableFutureBuilder
  79. .buildcompletableFuture2(futurePersonSeq);
  80. IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = completableFuture.get();
  81. List<String> personList = new ArrayList<>();
  82. personIndexedSeq.foreach(person -> {
  83. JsValue personJs = Json.toJson(person, person.personJsonFormatter());
  84. personList.add(Json.prettyPrint(personJs));
  85. return null;
  86. });
  87. return personList;
  88. }
  89. @RequestMapping(value = "/persons/tvseries/id/{tvSerieID}", method = RequestMethod.GET)
  90. private List<String> getPersonsForTvSerieByTvSerieID(@PathVariable(name = "tvSerieID") String tvSerieID)
  91. throws InterruptedException, ExecutionException {
  92. Future<IndexedSeq<ModelsAndJsonMap.Person>> futureIndexedSeqPersons = akkaStreamFilesProcessing
  93. .getPersonsForTvSerieByTvSerieIDFuture(tvSerieID);
  94. CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> seqCompletableFuture = CompletableFutureBuilder
  95. .buildcompletableFuture2(futureIndexedSeqPersons);
  96. IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = seqCompletableFuture.get();
  97. List<String> personsList = new ArrayList<>();
  98. personIndexedSeq.foreach(person ->{
  99. JsValue personJsV = Json.toJson(person, person.personJsonFormatter());
  100. personsList.add(Json.prettyPrint(personJsV));
  101. return null;
  102. });
  103. return personsList;
  104. }
  105. @RequestMapping(value = "/persons", method = RequestMethod.GET)
  106. private List<String> getAllPersons() throws ExecutionException, InterruptedException {
  107. Future<IndexedSeq<ModelsAndJsonMap.Person>> indexedSeqFuture = akkaStreamFilesProcessing.getMaxPersonsFuture();
  108. CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> completableFuture =
  109. CompletableFutureBuilder.buildcompletableFuture2(indexedSeqFuture);
  110. IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = completableFuture.get();
  111. List<String> personList = new ArrayList<>();
  112. personIndexedSeq.foreach(person ->{
  113. JsValue personJsV = Json.toJson(person, person.personJsonFormatter());
  114. personList.add(Json.prettyPrint(personJsV));
  115. return null;
  116. });
  117. return personList;
  118. }
  119. @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
  120. private List<String> getMaxTvSeries() throws ExecutionException, InterruptedException {
  121. Future<IndexedSeq<ModelsAndJsonMap.TvSerie>> futureTvSeries= akkaStreamFilesProcessing.getMaxTvSeriesFuture();
  122. CompletableFuture<IndexedSeq<ModelsAndJsonMap.TvSerie>> seqCompletableFuture = CompletableFutureBuilder
  123. .buildcompletableFuture2(futureTvSeries);
  124. IndexedSeq<ModelsAndJsonMap.TvSerie> tvSerieIndexedSeq = seqCompletableFuture.get();
  125. List<String> tvSerieList = new ArrayList<>();
  126. tvSerieIndexedSeq.foreach(tvSerie ->{
  127. JsValue tvSerieJsV = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
  128. tvSerieList.add(Json.prettyPrint(tvSerieJsV));
  129. return null;
  130. });
  131. return tvSerieList;
  132. }
  133. @RequestMapping(value = "/episodes", method = RequestMethod.GET)
  134. private List<String> getMaxEpisodes() throws ExecutionException, InterruptedException {
  135. Future<IndexedSeq<ModelsAndJsonMap.Episode>> seqFuture = akkaStreamFilesProcessing.getMaxEpisodes();
  136. CompletableFuture<IndexedSeq<ModelsAndJsonMap.Episode>> completableFuture =
  137. CompletableFutureBuilder.buildcompletableFuture2(seqFuture);
  138. IndexedSeq<ModelsAndJsonMap.Episode> episodeIndexedSeq = completableFuture.get();
  139. List<String> episodeList = new ArrayList<>();
  140. episodeIndexedSeq.foreach(episode->{
  141. JsValue episodeJsV = Json.toJson(episode, episode.episodeFormatter());
  142. episodeList.add(Json.prettyPrint(episodeJsV));
  143. return null;
  144. });
  145. return episodeList;
  146. }
  147. }

Powered by TurnKey Linux.