| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package fr.natan.akkastreamfileprocessingapi.service
-
- import akka.stream.scaladsl.{Sink, Source}
- import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
- import fr.natan.akkastreamfileprocessingapi.models.Models.Person
- import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
- import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{actorSystem, buildSource}
-
- import scala.concurrent.Future
-
- object UtilitiesClass {
-
- def getTvSerieIdByPrimaryTitle(primaryTitle: String): Future[Option[String]] = {
- val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
- val tvSerieIdFuture: Future[Option[String]] = source
- .filter((rowMap: Map[String, String]) => {
- rowMap.getOrElse(key = "primaryTitle", default = "") == primaryTitle
- })
- .map((rowMap: Map[String, String]) => rowMap.get("tconst"))
- .runWith(Sink.head)
-
- tvSerieIdFuture
- }
-
- def getListOfPersonsIDByTvSerieID(tvSerieIdFuture: Future[Option[String]]): Future[IndexedSeq[Option[String]]] = {
- val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
- val personsIDsFuture: Future[IndexedSeq[Option[String]]] = source
- .filter((rowMaps: Map[String, String]) => {
- rowMaps.getOrElse(key = "tconst", default = "") == tvSerieIdFuture.value.get.get.get
- })
- .map((rowMap: Map[String, String]) => {
- rowMap.get(key = "nconst")
- })
- .runWith(Sink.collection)
-
- personsIDsFuture
- }
-
- def getListOfPersonsForTvSerie(listPersonsIDsFuture: Future[IndexedSeq[Option[String]]]): Future[IndexedSeq[Person]] = {
-
- val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
- val personsFuture: Future[IndexedSeq[Person]] = source
- .filter((rowMaps: Map[String, String]) => {
- listPersonsIDsFuture.value.get.get.contains(rowMaps.get(key = "nconst"))
- })
- .map((rowMap: Map[String, String]) => {
- buildPersonModel(rowMap)
- })
- .runWith(Sink.collection)
-
- personsFuture
- }
-
- def getTvSerieIDFuture(tvSerieId: String): Future[Option[String]] = {
- val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
-
- val tvSerieIdFuture: Future[Option[String]] = source.
- filter((rowMap: Map[String, String]) => rowMap.getOrElse(key = "tconst", default = "") == tvSerieId)
- .map((rowMap: Map[String, String]) => rowMap.get(key = "tconst"))
- .runWith(Sink.head)
-
- tvSerieIdFuture
- }
-
- }
|