| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package fr.natan.akkastreamfileprocessingapi.controller;
-
- import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureBuilder;
- import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap;
- import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessingFuture;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import play.api.libs.json.JsValue;
- import play.api.libs.json.Json;
- import scala.Option;
- import scala.collection.IndexedSeq;
- import scala.concurrent.Future;
-
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.CompletableFuture;
- import java.util.concurrent.ExecutionException;
-
-
- @SuppressWarnings("SpellCheckingInspection")
- @RestController
- public class TvSeriesController {
-
- private final AkkaStreamFileProcessingFuture akkaStreamFilesProcessing;
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- public TvSeriesController(AkkaStreamFileProcessingFuture akkaStreamFilesProcessing) {
- this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
- }
-
- @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
- private String getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
- Future<Option<ModelsAndJsonMap.Person>> futurePerson = akkaStreamFilesProcessing.getPersonByIdFuture(personID);
- CompletableFuture<ModelsAndJsonMap.Person> completableFuture = CompletableFutureBuilder
- .buildcompletableFuture1(futurePerson);
- ModelsAndJsonMap.Person person = completableFuture.get();
-
- JsValue personJs = Json.toJson(person, person.personJsonFormatter());
- return Json.prettyPrint(personJs);
- }
-
- @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
- private String getPersonByName(@PathVariable(name = "primaryName") String primaryName)
- throws ExecutionException, InterruptedException {
-
- Future<Option<ModelsAndJsonMap.Person>> personFuture = akkaStreamFilesProcessing.getPersonByNameFuture(primaryName);
- CompletableFuture<ModelsAndJsonMap.Person> personCompletableFuture = CompletableFutureBuilder
- .buildcompletableFuture1(personFuture);
- ModelsAndJsonMap.Person person = personCompletableFuture.get();
- JsValue personJs = Json.toJson(person, person.personJsonFormatter());
- return Json.prettyPrint(personJs);
- }
-
- @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
- private String getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
- throws ExecutionException, InterruptedException {
- Future<Option<ModelsAndJsonMap.TvSerie>> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieByIdFuture(tvSerieID);
- CompletableFuture<ModelsAndJsonMap.TvSerie> tvSerieCompletableFuture = CompletableFutureBuilder
- .buildcompletableFuture1(tvSerieFuture);
-
- ModelsAndJsonMap.TvSerie tvSerie = tvSerieCompletableFuture.get();
- JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
- return Json.prettyPrint(tvSerieJs);
- }
-
- @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
- private List<String> getTvserieByPrimaryTitle(
- @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) throws InterruptedException, ExecutionException {
-
- Future<IndexedSeq<ModelsAndJsonMap.TvSerie>> listFuture = akkaStreamFilesProcessing
- .getTvSeriesByPrimaryTitleFuture(tvseriePrimaryTitle);
- CompletableFuture<IndexedSeq<ModelsAndJsonMap.TvSerie>> completableFuture =
- CompletableFutureBuilder.buildcompletableFuture2(listFuture);
-
- IndexedSeq<ModelsAndJsonMap.TvSerie> tvSerieList = completableFuture.get();
- List<String> tvSeries = new ArrayList<>();
- tvSerieList.foreach(tvSerie -> {
- JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
- tvSeries.add(Json.prettyPrint(tvSerieJs));
- return null;
- });
-
- return tvSeries;
- }
-
- @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
- private List<String> getPersonsForTvSerieByTvSerieTitle(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
- throws InterruptedException, ExecutionException {
-
- Future<IndexedSeq<ModelsAndJsonMap.Person>> futurePersonSeq = akkaStreamFilesProcessing
- .getPersonsForTvSerieByTvSerieTitleFuture(tvSerieTitle);
- CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> completableFuture = CompletableFutureBuilder
- .buildcompletableFuture2(futurePersonSeq);
-
- IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = completableFuture.get();
- List<String> personList = new ArrayList<>();
- personIndexedSeq.foreach(person -> {
- JsValue personJs = Json.toJson(person, person.personJsonFormatter());
- personList.add(Json.prettyPrint(personJs));
- return null;
- });
-
- return personList;
- }
-
- @RequestMapping(value = "/persons/tvseries/id/{tvSerieID}", method = RequestMethod.GET)
- private List<String> getPersonsForTvSerieByTvSerieID(@PathVariable(name = "tvSerieID") String tvSerieID)
- throws InterruptedException, ExecutionException {
-
- Future<IndexedSeq<ModelsAndJsonMap.Person>> futureIndexedSeqPersons = akkaStreamFilesProcessing
- .getPersonsForTvSerieByTvSerieIDFuture(tvSerieID);
- CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> seqCompletableFuture = CompletableFutureBuilder
- .buildcompletableFuture2(futureIndexedSeqPersons);
-
- IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = seqCompletableFuture.get();
- List<String> personsList = new ArrayList<>();
- personIndexedSeq.foreach(person ->{
- JsValue personJsV = Json.toJson(person, person.personJsonFormatter());
- personsList.add(Json.prettyPrint(personJsV));
- return null;
- });
-
- return personsList;
- }
-
- @RequestMapping(value = "/persons", method = RequestMethod.GET)
- private List<String> getAllPersons() throws ExecutionException, InterruptedException {
- Future<IndexedSeq<ModelsAndJsonMap.Person>> indexedSeqFuture = akkaStreamFilesProcessing.getMaxPersonsFuture();
- CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> completableFuture =
- CompletableFutureBuilder.buildcompletableFuture2(indexedSeqFuture);
- IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = completableFuture.get();
- List<String> personList = new ArrayList<>();
- personIndexedSeq.foreach(person ->{
- JsValue personJsV = Json.toJson(person, person.personJsonFormatter());
- personList.add(Json.prettyPrint(personJsV));
- return null;
- });
-
- return personList;
- }
-
- @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
- private List<String> getMaxTvSeries() throws ExecutionException, InterruptedException {
- Future<IndexedSeq<ModelsAndJsonMap.TvSerie>> futureTvSeries= akkaStreamFilesProcessing.getMaxTvSeriesFuture();
- CompletableFuture<IndexedSeq<ModelsAndJsonMap.TvSerie>> seqCompletableFuture = CompletableFutureBuilder
- .buildcompletableFuture2(futureTvSeries);
-
- IndexedSeq<ModelsAndJsonMap.TvSerie> tvSerieIndexedSeq = seqCompletableFuture.get();
- List<String> tvSerieList = new ArrayList<>();
- tvSerieIndexedSeq.foreach(tvSerie ->{
- JsValue tvSerieJsV = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
- tvSerieList.add(Json.prettyPrint(tvSerieJsV));
- return null;
- });
-
- return tvSerieList;
- }
-
- @RequestMapping(value = "/episodes", method = RequestMethod.GET)
- private List<String> getMaxEpisodes() throws ExecutionException, InterruptedException {
- Future<IndexedSeq<ModelsAndJsonMap.Episode>> seqFuture = akkaStreamFilesProcessing.getMaxEpisodes();
- CompletableFuture<IndexedSeq<ModelsAndJsonMap.Episode>> completableFuture =
- CompletableFutureBuilder.buildcompletableFuture2(seqFuture);
- IndexedSeq<ModelsAndJsonMap.Episode> episodeIndexedSeq = completableFuture.get();
-
- List<String> episodeList = new ArrayList<>();
- episodeIndexedSeq.foreach(episode->{
- JsValue episodeJsV = Json.toJson(episode, episode.episodeFormatter());
- episodeList.add(Json.prettyPrint(episodeJsV));
- return null;
- });
-
- return episodeList;
- }
- }
|