Browse Source

first commit

placidenduwayo 1 year ago
parent
commit
d64b422d9c

+ 41
- 17
src/main/java/fr/natan/akkastreamfileprocessingapi/controller/TvSeriesController.java View File

1
 package fr.natan.akkastreamfileprocessingapi.controller;
1
 package fr.natan.akkastreamfileprocessingapi.controller;
2
 
2
 
3
-import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureResult;
3
+import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureBuilder;
4
 import fr.natan.akkastreamfileprocessingapi.models.Models;
4
 import fr.natan.akkastreamfileprocessingapi.models.Models;
5
-import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessing;
5
+import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessingFuture;
6
 import org.slf4j.Logger;
6
 import org.slf4j.Logger;
7
 import org.slf4j.LoggerFactory;
7
 import org.slf4j.LoggerFactory;
8
 import org.springframework.http.HttpStatus;
8
 import org.springframework.http.HttpStatus;
27
 @RestController
27
 @RestController
28
 public class TvSeriesController {
28
 public class TvSeriesController {
29
 
29
 
30
-    private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
30
+    private final AkkaStreamFileProcessingFuture akkaStreamFilesProcessing;
31
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
31
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
32
     private static final int BORN_INF = 500, BORN_SUP = 5000;
32
     private static final int BORN_INF = 500, BORN_SUP = 5000;
33
 
33
 
34
-    public TvSeriesController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
34
+    public TvSeriesController(AkkaStreamFileProcessingFuture akkaStreamFilesProcessing) {
35
         this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
35
         this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
36
     }
36
     }
37
 
37
 
38
     @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
38
     @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
39
     private String getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
39
     private String getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
40
-        Future<Models.Person> futurePerson = akkaStreamFilesProcessing.getPersonById(personID);
41
-        CompletableFuture<Models.Person> completableFuture = CompletableFutureResult.buildcompletableFuture1(futurePerson);
40
+        Future<Models.Person> futurePerson = akkaStreamFilesProcessing.getPersonByIdFuture(personID);
41
+        CompletableFuture<Models.Person> completableFuture = CompletableFutureBuilder
42
+                .buildcompletableFuture1(futurePerson);
42
         while (!completableFuture.isDone()) {
43
         while (!completableFuture.isDone()) {
43
             logger.info("IS PROCESSING...");
44
             logger.info("IS PROCESSING...");
44
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
45
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
52
     private String getPersonByName(@PathVariable(name = "primaryName") String primaryName)
53
     private String getPersonByName(@PathVariable(name = "primaryName") String primaryName)
53
             throws ExecutionException, InterruptedException {
54
             throws ExecutionException, InterruptedException {
54
 
55
 
55
-        Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
56
-        CompletableFuture<Models.Person> personCompletableFuture = CompletableFutureResult.buildcompletableFuture1(personFuture);
56
+        Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByNameFuture(primaryName);
57
+        CompletableFuture<Models.Person> personCompletableFuture = CompletableFutureBuilder
58
+                .buildcompletableFuture1(personFuture);
57
         while (!personCompletableFuture.isDone()) {
59
         while (!personCompletableFuture.isDone()) {
58
             logger.info("IS PROCESSING...");
60
             logger.info("IS PROCESSING...");
59
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
61
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
65
     @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
67
     @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
66
     private String getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
68
     private String getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
67
             throws ExecutionException, InterruptedException {
69
             throws ExecutionException, InterruptedException {
68
-        Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
69
-        CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = CompletableFutureResult.buildcompletableFuture1(tvSerieFuture);
70
+        Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieByIdFuture(tvSerieID);
71
+        CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = CompletableFutureBuilder
72
+                .buildcompletableFuture1(tvSerieFuture);
70
         while (!tvSerieCompletableFuture.isDone()) {
73
         while (!tvSerieCompletableFuture.isDone()) {
71
             logger.info("IS PROCESSING...");
74
             logger.info("IS PROCESSING...");
72
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
75
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
79
     private List<String> getTvserieByPrimaryTitle(
82
     private List<String> getTvserieByPrimaryTitle(
80
             @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) throws InterruptedException, ExecutionException {
83
             @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) throws InterruptedException, ExecutionException {
81
 
84
 
82
-        Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
85
+        Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSeriesByPrimaryTitleFuture(tvseriePrimaryTitle);
83
         CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
86
         CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
84
-                CompletableFutureResult.buildcompletableFuture2(listFuture);
87
+                CompletableFutureBuilder.buildcompletableFuture2(listFuture);
85
         while (!completableFuture.isDone()) {
88
         while (!completableFuture.isDone()) {
86
             logger.info("IS PROCESSING...");
89
             logger.info("IS PROCESSING...");
87
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
90
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
98
     }
101
     }
99
 
102
 
100
     @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
103
     @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
101
-    private List<String> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
104
+    private List<String> getPersonsForTvSerieByTvSerieTitle(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
102
             throws InterruptedException, ExecutionException {
105
             throws InterruptedException, ExecutionException {
103
 
106
 
104
-        Future<IndexedSeq<Models.Person>> futurePersonSeq = akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
105
-        CompletableFuture<IndexedSeq<Models.Person>> completableFuture = CompletableFutureResult.buildcompletableFuture2(futurePersonSeq);
107
+        Future<IndexedSeq<Models.Person>> futurePersonSeq = akkaStreamFilesProcessing.getPersonsForTvSerieByTvSerieTitleFuture(tvSerieTitle);
108
+        CompletableFuture<IndexedSeq<Models.Person>> completableFuture = CompletableFutureBuilder.buildcompletableFuture2(futurePersonSeq);
106
         while (!completableFuture.isDone()){
109
         while (!completableFuture.isDone()){
107
             logger.info("IS PROCESSING...");
110
             logger.info("IS PROCESSING...");
108
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
111
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
119
         return persons;
122
         return persons;
120
     }
123
     }
121
 
124
 
125
+    @RequestMapping(value = "/persons/tvseries/id/{tvSerieID}", method = RequestMethod.GET)
126
+    private List<String> getPersonsForTvSerieByTvSerieID(@PathVariable(name = "tvSerieID") String tvSerieID)
127
+            throws InterruptedException, ExecutionException {
128
+
129
+        Future<IndexedSeq<Models.Person>> futureIndexedSeqPersons = akkaStreamFilesProcessing.getPersonsForTvSerieByTvSerieIdFuture(tvSerieID);
130
+        CompletableFuture<IndexedSeq<Models.Person>> seqCompletableFuture = CompletableFutureBuilder.buildcompletableFuture2(futureIndexedSeqPersons);
131
+
132
+        while (!seqCompletableFuture.isDone()){
133
+            logger.info("IS PROCESSING");
134
+            Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
135
+        }
136
+        IndexedSeq<Models.Person> personIndexedSeq = seqCompletableFuture.get();
137
+        List<String> personsList = new ArrayList<>();
138
+        personIndexedSeq.foreach(person ->{
139
+            personsList.add(Json.toJson(person, person.personFormat()).toString());
140
+            return null;
141
+        });
142
+
143
+        return personsList;
144
+    }
145
+
122
     @RequestMapping(value = "/persons", method = RequestMethod.GET)
146
     @RequestMapping(value = "/persons", method = RequestMethod.GET)
123
     private ResponseEntity<String> getAllPersons() {
147
     private ResponseEntity<String> getAllPersons() {
124
-        akkaStreamFilesProcessing.getAllPersons();
148
+        akkaStreamFilesProcessing.getAllPersonsFuture();
125
         return new ResponseEntity<>("is running", HttpStatus.OK);
149
         return new ResponseEntity<>("is running", HttpStatus.OK);
126
     }
150
     }
127
 
151
 
128
     @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
152
     @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
129
     private ResponseEntity<String> getAllvSeries() {
153
     private ResponseEntity<String> getAllvSeries() {
130
-        akkaStreamFilesProcessing.getAllTvSeries();
154
+        akkaStreamFilesProcessing.getAllTvSeriesFuture();
131
         return new ResponseEntity<>("is running", HttpStatus.OK);
155
         return new ResponseEntity<>("is running", HttpStatus.OK);
132
     }
156
     }
133
 }
157
 }

src/main/java/fr/natan/akkastreamfileprocessingapi/futurecompleteness/CompletableFutureResult.java → src/main/java/fr/natan/akkastreamfileprocessingapi/futurecompleteness/CompletableFutureBuilder.java View File

9
 
9
 
10
 
10
 
11
 
11
 
12
-public class CompletableFutureResult<T> {
12
+public class CompletableFutureBuilder<T> {
13
 
13
 
14
     public static<T> CompletableFuture<T> buildcompletableFuture1(Future<T> futureT) {
14
     public static<T> CompletableFuture<T> buildcompletableFuture1(Future<T> futureT) {
15
         CompletableFuture<T> completableFuture = new CompletableFuture<>();
15
         CompletableFuture<T> completableFuture = new CompletableFuture<>();

+ 0
- 18
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessing.scala View File

1
-package fr.natan.akkastreamfileprocessingapi.service
2
-
3
-import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
4
-
5
-import scala.concurrent.Future
6
-
7
-//noinspection SpellCheckingInspection,AccessorLikeMethodIsUnit
8
-trait AkkaStreamFileProcessing {
9
-  def getPersonById(personID: String): Future[Person]
10
-  def getPersonByName(primaryName: String): Future[Person]
11
-
12
-  def getTvSerieById(tvSerieID: String): Future[TvSerie]
13
-  def getTvSerieByPrimaryTitle(tvSerieTitle: String):Future[IndexedSeq[TvSerie]]
14
-
15
-  def getTeamOfPersonsForTvSerie(tvSeriePrimaryTitle: String): Future[IndexedSeq[Person]]
16
-  def getAllTvSeries(): Unit
17
-  def getAllPersons(): Unit
18
-}

+ 20
- 0
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingFuture.scala View File

1
+package fr.natan.akkastreamfileprocessingapi.service
2
+
3
+import akka.Done
4
+import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
5
+
6
+import scala.concurrent.Future
7
+
8
+//noinspection SpellCheckingInspection,AccessorLikeMethodIsUnit
9
+trait AkkaStreamFileProcessingFuture {
10
+  def getPersonByIdFuture(personID: String): Future[Person]
11
+  def getPersonByNameFuture(primaryName: String): Future[Person]
12
+
13
+  def getTvSerieByIdFuture(tvSerieID: String): Future[TvSerie]
14
+  def getTvSeriesByPrimaryTitleFuture(tvSerieTitle: String):Future[IndexedSeq[TvSerie]]
15
+
16
+  def getPersonsForTvSerieByTvSerieTitleFuture(tvSeriePrimaryTitle: String): Future[IndexedSeq[Person]]
17
+  def getPersonsForTvSerieByTvSerieIdFuture(tvSerieId: String): Future[IndexedSeq[Person]]
18
+  def getAllTvSeriesFuture(): Future[Done]
19
+  def getAllPersonsFuture(): Future[Done]
20
+}

+ 94
- 33
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingImpl.scala View File

4
 import akka.actor.ActorSystem
4
 import akka.actor.ActorSystem
5
 import akka.stream.scaladsl.{Sink, Source}
5
 import akka.stream.scaladsl.{Sink, Source}
6
 import com.typesafe.scalalogging.slf4j.Logger
6
 import com.typesafe.scalalogging.slf4j.Logger
7
-import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
7
+import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{
8
+  nameBasics, titleBasics, titlePrincipalsBasics
9
+}
8
 import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
10
 import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
9
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
11
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
10
-import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildSource, buildTvSerieFlow, filterPersonByIdFlow, filterPersonByNameFlow, filterTvSerieByIdFlow, filterTvSerieByPrimaryTitleFlow}
12
+import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
13
+  buildAllPersonsSink,
14
+  buildAllTvSeriesSink,
15
+  buildAndValidateSource,
16
+  buildPersonFlow,
17
+  buildSource,
18
+  buildTvSerieFlow,
19
+  filterPersonByIdFlow,
20
+  filterPersonByNameFlow,
21
+  filterTvSerieByIdFlow,
22
+  filterTvSerieByPrimaryTitleFlow
23
+}
11
 import org.slf4j.LoggerFactory
24
 import org.slf4j.LoggerFactory
12
 import org.springframework.stereotype.Component
25
 import org.springframework.stereotype.Component
13
 
26
 
18
 
31
 
19
 //noinspection SpellCheckingInspection
32
 //noinspection SpellCheckingInspection
20
 @Component
33
 @Component
21
-class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
34
+class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
22
 
35
 
23
   implicit val actorSystem: ActorSystem = ActorSystem("AkkaStreamActor")
36
   implicit val actorSystem: ActorSystem = ActorSystem("AkkaStreamActor")
24
   implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
37
   implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
25
 
38
 
26
-  override def getPersonById(personID: String): Future[Person] = {
39
+  override def getPersonByIdFuture(personID: String): Future[Person] = {
27
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
40
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
28
-    val res: Future[Person] = source
41
+    val personFuture: Future[Person] = source
29
       .via(flow = filterPersonByIdFlow(personID = personID))
42
       .via(flow = filterPersonByIdFlow(personID = personID))
30
       .runWith(Sink.head)
43
       .runWith(Sink.head)
31
 
44
 
32
-    res.andThen({
45
+    personFuture.andThen({
33
       case Failure(exception) => logger.info(s"$exception")
46
       case Failure(exception) => logger.info(s"$exception")
34
       case Success(value:Person) => logger.info(s"$value")
47
       case Success(value:Person) => logger.info(s"$value")
35
     })
48
     })
36
 
49
 
37
-    res
50
+    personFuture
38
   }
51
   }
39
 
52
 
40
-  override def getPersonByName(primaryName: String): Future[Person] = {
53
+  override def getPersonByNameFuture(primaryName: String): Future[Person] = {
41
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
54
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
42
-    val persons: Future[Person] = source
55
+    val personFuture: Future[Person] = source
43
       .via(flow = filterPersonByNameFlow(primaryName = primaryName))
56
       .via(flow = filterPersonByNameFlow(primaryName = primaryName))
44
       .runWith(Sink.head)
57
       .runWith(Sink.head)
45
 
58
 
46
-    persons.onComplete({
59
+    personFuture.onComplete({
47
       case Failure(exception) => logger.error(s"$exception")
60
       case Failure(exception) => logger.error(s"$exception")
48
       case Success(value: Person) => logger.info(s"$value")
61
       case Success(value: Person) => logger.info(s"$value")
49
         logger.info("SUCCESS")
62
         logger.info("SUCCESS")
50
     })
63
     })
51
 
64
 
52
-    persons
65
+    personFuture
53
   }
66
   }
54
 
67
 
55
-  override def getTvSerieById(tvSerieID: String): Future[TvSerie] = {
68
+  override def getTvSerieByIdFuture(tvSerieID: String): Future[TvSerie] = {
56
     val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
69
     val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
57
-    val res: Future[TvSerie] = source
70
+    val tvSerieFuture: Future[TvSerie] = source
58
       .via(flow = filterTvSerieByIdFlow(tvSerieID = tvSerieID))
71
       .via(flow = filterTvSerieByIdFlow(tvSerieID = tvSerieID))
59
       .runWith(Sink.head)
72
       .runWith(Sink.head)
60
 
73
 
61
-    res.onComplete({
74
+    tvSerieFuture.onComplete({
62
       case Failure(exception) => logger.info(s"$exception")
75
       case Failure(exception) => logger.info(s"$exception")
63
       case Success(value: TvSerie) => logger.info(s"$value")
76
       case Success(value: TvSerie) => logger.info(s"$value")
64
     })
77
     })
65
-    res
78
+    tvSerieFuture
66
   }
79
   }
67
-  override def getTvSerieByPrimaryTitle(tvSeriePrimaryTitle: String): Future[IndexedSeq[TvSerie]] = {
80
+  override def getTvSeriesByPrimaryTitleFuture(tvSeriePrimaryTitle: String): Future[IndexedSeq[TvSerie]] = {
68
 
81
 
69
     val tvSeriesSource: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
82
     val tvSeriesSource: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
70
 
83
 
71
-    val tvSries: Future[IndexedSeq[TvSerie]] = tvSeriesSource
84
+    val tvSriesFuture: Future[IndexedSeq[TvSerie]] = tvSeriesSource
72
       .via(flow = filterTvSerieByPrimaryTitleFlow(tvSeriePrimaryTitle = tvSeriePrimaryTitle))
85
       .via(flow = filterTvSerieByPrimaryTitleFlow(tvSeriePrimaryTitle = tvSeriePrimaryTitle))
73
       .runWith(Sink.collection)
86
       .runWith(Sink.collection)
74
 
87
 
75
-    tvSries.onComplete({
88
+    tvSriesFuture.onComplete({
76
       case Failure(exception) => logger.info(s"$exception")
89
       case Failure(exception) => logger.info(s"$exception")
77
       case Success(value: IndexedSeq[TvSerie]) =>
90
       case Success(value: IndexedSeq[TvSerie]) =>
78
         value.foreach((tvSrie: TvSerie) => logger.info(s"$tvSrie"))
91
         value.foreach((tvSrie: TvSerie) => logger.info(s"$tvSrie"))
79
         logger.info("SUCCESS")
92
         logger.info("SUCCESS")
80
     })
93
     })
81
 
94
 
82
-    tvSries
95
+    tvSriesFuture
83
   }
96
   }
84
 
97
 
85
 
98
 
86
   private def getTvSerieIdByPrimaryTitle(primaryTitle: String): Future[Option[String]] = {
99
   private def getTvSerieIdByPrimaryTitle(primaryTitle: String): Future[Option[String]] = {
87
     val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
100
     val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
88
 
101
 
89
-    val res: Future[Option[String]] = source
102
+    val tvSerieIdFuture: Future[Option[String]] = source
90
       .filter((rowMap: Map[String, String]) => {
103
       .filter((rowMap: Map[String, String]) => {
91
-        rowMap.getOrElse(key = "primaryTitle", "") == primaryTitle
104
+        rowMap.getOrElse(key = "primaryTitle", default = "") == primaryTitle
92
       })
105
       })
93
       .map((rowMap: Map[String, String]) => rowMap.get("tconst"))
106
       .map((rowMap: Map[String, String]) => rowMap.get("tconst"))
94
       .runWith(Sink.head)
107
       .runWith(Sink.head)
95
 
108
 
96
-    res
109
+    tvSerieIdFuture
97
   }
110
   }
98
 
111
 
99
   private def getListOfPersonsIDByTvSerieID(tvSerieIdFuture: Future[Option[String]]): Future[IndexedSeq[Option[String]]] = {
112
   private def getListOfPersonsIDByTvSerieID(tvSerieIdFuture: Future[Option[String]]): Future[IndexedSeq[Option[String]]] = {
100
     val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
113
     val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
101
-    val res: Future[IndexedSeq[Option[String]]] = source
114
+    val personsIDsFuture: Future[IndexedSeq[Option[String]]] = source
102
       .filter((rowMaps: Map[String, String]) => {
115
       .filter((rowMaps: Map[String, String]) => {
103
         rowMaps.getOrElse(key = "tconst", default = "") == tvSerieIdFuture.value.get.get.get
116
         rowMaps.getOrElse(key = "tconst", default = "") == tvSerieIdFuture.value.get.get.get
104
       })
117
       })
107
       })
120
       })
108
       .runWith(Sink.collection)
121
       .runWith(Sink.collection)
109
 
122
 
110
-    res
123
+    personsIDsFuture
111
   }
124
   }
112
 
125
 
113
-  private def getListOfPersonsForTvSerie(listPersonsIDsFuture: Future[IndexedSeq[Option[String]]]):
114
-  Future[IndexedSeq[Person]] = {
126
+  private def getListOfPersonsForTvSerie(listPersonsIDsFuture: Future[IndexedSeq[Option[String]]]): Future[IndexedSeq[Person]] = {
115
 
127
 
116
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
128
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
117
-    val res: Future[IndexedSeq[Person]] = source
129
+    val personsFuture: Future[IndexedSeq[Person]] = source
118
       .filter((rowMaps: Map[String, String]) => {
130
       .filter((rowMaps: Map[String, String]) => {
119
         listPersonsIDsFuture.value.get.get.contains(rowMaps.get(key = "nconst"))
131
         listPersonsIDsFuture.value.get.get.contains(rowMaps.get(key = "nconst"))
120
       })
132
       })
123
       })
135
       })
124
       .runWith(Sink.collection)
136
       .runWith(Sink.collection)
125
 
137
 
126
-    res
138
+    personsFuture
127
   }
139
   }
128
 
140
 
129
-  override def getTeamOfPersonsForTvSerie(tvSeriePrimaryTitle: String): Future[IndexedSeq[Person]] = {
141
+  override def getPersonsForTvSerieByTvSerieTitleFuture(tvSeriePrimaryTitle: String): Future[IndexedSeq[Person]] = {
130
 
142
 
131
     //futures chaining
143
     //futures chaining
132
     logger.info("STEP 1/3 START")
144
     logger.info("STEP 1/3 START")
150
                 logger.info("STEP 2/3 END")
162
                 logger.info("STEP 2/3 END")
151
             })
163
             })
152
               .flatMap({
164
               .flatMap({
153
-                future =>
165
+                _ =>
154
                   logger.info("STEP 3/3 START")
166
                   logger.info("STEP 3/3 START")
155
                   val personsTeamFuture: Future[IndexedSeq[Person]] = getListOfPersonsForTvSerie(listPersonsIDsFuture = listPersonIDsFuture)
167
                   val personsTeamFuture: Future[IndexedSeq[Person]] = getListOfPersonsForTvSerie(listPersonsIDsFuture = listPersonIDsFuture)
156
                   personsTeamFuture.andThen({
168
                   personsTeamFuture.andThen({
165
     finalFuture
177
     finalFuture
166
   }
178
   }
167
 
179
 
168
-  override def getAllPersons(): Unit = {
180
+  private def getTvSerieIDFuture(tvSerieId: String): Future[Option[String]] ={
181
+    val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
182
+
183
+    val tvSerieIdFuture : Future[Option[String]]= source.
184
+      filter((rowMap: Map[String, String]) => rowMap.getOrElse(key = "tconst", default = "") == tvSerieId)
185
+      .map((rowMap: Map[String, String])=>rowMap.get(key = "tconst"))
186
+      .runWith(Sink.head)
187
+
188
+    tvSerieIdFuture
189
+  }
190
+
191
+  override def getPersonsForTvSerieByTvSerieIdFuture(tvSerieId: String): Future[IndexedSeq[Person]] = {
192
+
193
+    val tvSerieIdFuture: Future[Option[String]] = getTvSerieIDFuture(tvSerieId = tvSerieId)
194
+    logger.info("STEP 1/3")
195
+    tvSerieIdFuture.andThen({
196
+      case Failure(exception) => logger.error(s"${exception.printStackTrace()}")
197
+      case Success(value:Option[String]) =>
198
+        logger.info(s"$value")
199
+        logger.info("STEP 1/3")
200
+
201
+    })
202
+      .flatMap({
203
+        _ => logger.info("STEP 2/3")
204
+          val  listOfPersonsIDsFuture : Future[IndexedSeq[Option[String]]] = getListOfPersonsIDByTvSerieID(tvSerieIdFuture = tvSerieIdFuture)
205
+          listOfPersonsIDsFuture.andThen({
206
+            case Failure(exception) => logger.error(s"${exception.printStackTrace()}")
207
+            case Success(value) =>
208
+              value.foreach((personID: Option[String]) => logger.info(s"Person ID:$personID"))
209
+              logger.info("STEP 2/3 END")
210
+          })
211
+            .flatMap({
212
+              _ => logger.info("STEP 3/3")
213
+                val personsTeamFuture: Future[IndexedSeq[Person]] = getListOfPersonsForTvSerie(listPersonsIDsFuture = listOfPersonsIDsFuture)
214
+                personsTeamFuture.andThen({
215
+                  case Failure(exception) => logger.error(s"$exception")
216
+                  case Success(value: IndexedSeq[Person]) =>
217
+                    value.foreach((person: Person) => logger.info(s"${person.toString}"))
218
+                    logger.info("STEP 3/3 END")
219
+                })
220
+            })
221
+      })
222
+
223
+  }
224
+  override def getAllPersonsFuture(): Future[Done] = {
169
     val personSource: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
225
     val personSource: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
170
     //graph
226
     //graph
171
     val startTime: Long = System.currentTimeMillis()
227
     val startTime: Long = System.currentTimeMillis()
180
         val time: Long = (System.currentTimeMillis() - startTime) / 100
236
         val time: Long = (System.currentTimeMillis() - startTime) / 100
181
         logger.info(s"elapsed time: $time")
237
         logger.info(s"elapsed time: $time")
182
     }
238
     }
239
+
240
+    result
183
   }
241
   }
184
 
242
 
185
-  override def getAllTvSeries(): Unit = {
243
+  override def getAllTvSeriesFuture(): Future[Done] = {
186
     val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
244
     val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
187
     val sink: Sink[TvSerie, Future[Done]] = buildAllTvSeriesSink(logger = logger)
245
     val sink: Sink[TvSerie, Future[Done]] = buildAllTvSeriesSink(logger = logger)
188
 
246
 
189
     val startingTime: Long = System.currentTimeMillis()
247
     val startingTime: Long = System.currentTimeMillis()
190
     //graph sink->flow->sink
248
     //graph sink->flow->sink
191
-    source
249
+    val results: Future[Done] = source
192
       .via(flow = buildTvSerieFlow())
250
       .via(flow = buildTvSerieFlow())
193
       .runWith(sink = sink)
251
       .runWith(sink = sink)
194
       .andThen {
252
       .andThen {
197
           logger.info(s"$value: successfully processing file, elapsed time $titleBasics: $elapsedTime sec")
255
           logger.info(s"$value: successfully processing file, elapsed time $titleBasics: $elapsedTime sec")
198
         case Failure(error: Error) => logger.error(s"$error")
256
         case Failure(error: Error) => logger.error(s"$error")
199
       }
257
       }
258
+
259
+    results
200
   }
260
   }
261
+
201
 }
262
 }
202
 
263
 
203
 
264
 

Powered by TurnKey Linux.