|
@@ -6,12 +6,14 @@ import akka.{Done, NotUsed}
|
6
|
6
|
import com.typesafe.scalalogging.slf4j.Logger
|
7
|
7
|
import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics}
|
8
|
8
|
import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSeries}
|
9
|
|
-import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAndValidateSource, buildPersonFlow, buildPersonSink, buildSource, buildTvSerieFlow, buildTvSeriesSink, filterByMoviePrimaryTitleFlow, filterByPersonIdFlow, filterByPersonNameFlow}
|
|
9
|
+import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildTvSerieModel
|
|
10
|
+import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAllPersonsSink, buildAndValidateSource, buildPersonFlow, buildPersonSink, buildSource, buildTvSerieFlow, buildTvSeriesSink, filterByPersonIdFlow, filterByPersonNameFlow, filterByTvSeriePrimaryTitleFlow}
|
10
|
11
|
import org.slf4j.LoggerFactory
|
11
|
12
|
import org.springframework.stereotype.Component
|
12
|
13
|
|
13
|
14
|
import scala.concurrent.ExecutionContext.Implicits.global
|
14
|
|
-import scala.concurrent.Future
|
|
15
|
+import scala.concurrent.duration.DurationInt
|
|
16
|
+import scala.concurrent.{Await, Future}
|
15
|
17
|
import scala.util.{Failure, Success}
|
16
|
18
|
|
17
|
19
|
@Component
|
|
@@ -20,9 +22,58 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
20
|
22
|
implicit val actorSystem: ActorSystem = ActorSystem("AkkaStreamActor")
|
21
|
23
|
implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
|
22
|
24
|
|
23
|
|
- override def getAllMovies(): Unit = {
|
|
25
|
+ override def getAllPersons(): Unit = {
|
|
26
|
+ val personSource: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
|
27
|
+ val personSink: Sink[Person, Future[Done]] = buildAllPersonsSink(logger = logger)
|
|
28
|
+
|
|
29
|
+ //graph
|
|
30
|
+ val startTime: Long = System.currentTimeMillis()
|
|
31
|
+ val result: Future[Done] = personSource
|
|
32
|
+ .via(flow = buildPersonFlow())
|
|
33
|
+ .runWith(sink = personSink)
|
|
34
|
+ .andThen {
|
|
35
|
+ case Success(value) =>
|
|
36
|
+ val elapsedTime: Long = (System.currentTimeMillis() - startTime) / 1000
|
|
37
|
+ logger.info(s"$value: Successfully processed, elapsed time: $elapsedTime")
|
|
38
|
+ case Failure(exception) => logger.error(s"$exception: Fail")
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ override def getPersonById(nconst: String): Person = {
|
|
43
|
+ val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
|
44
|
+
|
|
45
|
+ val startTime: Long = System.currentTimeMillis()
|
|
46
|
+ val res = source
|
|
47
|
+ .via(flow = filterByPersonIdFlow(nconst = nconst))
|
|
48
|
+ .runWith(sink = buildPersonSink())
|
|
49
|
+ .andThen {
|
|
50
|
+ case Success(value) =>
|
|
51
|
+ val elapsedTime: Long = (System.currentTimeMillis()-startTime)/1000
|
|
52
|
+ logger.info(s"$value: Successfully processed, elapsed time: $elapsedTime")
|
|
53
|
+ case Failure(exception) => logger.error(s"$exception: Fail")
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ Await.result(res,1 minutes)
|
|
57
|
+ val person: Person = res.value.get.get
|
|
58
|
+ person
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ override def getPersonByName(primaryName: String): Unit = {
|
|
62
|
+ val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
|
63
|
+ source
|
|
64
|
+ .via(
|
|
65
|
+ flow = filterByPersonNameFlow(personName = primaryName)
|
|
66
|
+ )
|
|
67
|
+ .runWith(sink = buildPersonSink())
|
|
68
|
+ .andThen {
|
|
69
|
+ case Failure(exception) => logger.info(s"$exception")
|
|
70
|
+ case Success(value) => logger.info(s"$value: Successufully processing")
|
|
71
|
+ }
|
|
72
|
+ }
|
24
|
73
|
|
25
|
|
- val source: Source[Map[String, String], NotUsed] = buildAndValidateSource(inputFile = titleBasics)
|
|
74
|
+ override def getAllTvSeries(): Unit = {
|
|
75
|
+
|
|
76
|
+ val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
|
26
|
77
|
val sink: Sink[TvSeries, Future[Done]] = buildTvSeriesSink(logger = logger)
|
27
|
78
|
|
28
|
79
|
val startingTime: Long = System.currentTimeMillis()
|
|
@@ -40,13 +91,13 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
40
|
91
|
|
41
|
92
|
}
|
42
|
93
|
|
43
|
|
- override def getMoviesByTitle(moviePrimaryTitle: String): Unit = {
|
|
94
|
+ override def getByTvSeriePrimaryTitle(tvSeriePrimaryTitle: String): Unit = {
|
44
|
95
|
|
45
|
|
- val tvSeriesSource: Source[Map[String, String], NotUsed] = buildAndValidateSource(inputFile = titleBasics)
|
|
96
|
+ val tvSeriesSource: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
|
46
|
97
|
val tvSeriesSink: Sink[TvSeries, Future[Done]] = buildTvSeriesSink(logger = logger)
|
47
|
98
|
|
48
|
99
|
val filterByMovieTitleFlow: Flow[Map[String, String], TvSeries, NotUsed] =
|
49
|
|
- filterByMoviePrimaryTitleFlow(moviePrimaryTitle = moviePrimaryTitle)
|
|
100
|
+ filterByTvSeriePrimaryTitleFlow(tvSeriePrimaryTitle = tvSeriePrimaryTitle)
|
50
|
101
|
|
51
|
102
|
val startTime: Long = System.currentTimeMillis()
|
52
|
103
|
val listTvSeries: Future[Done] = tvSeriesSource
|
|
@@ -58,52 +109,30 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
58
|
109
|
logger.info(s"$value: successfully processing file, elapsed time: $elapsedTime sec")
|
59
|
110
|
case Failure(error: Error) => logger.error(s"$error")
|
60
|
111
|
}
|
61
|
|
- }
|
62
|
112
|
|
63
|
|
- override def getAllPersons(): Unit = {
|
64
|
|
- val personSource: Source[Map[String, String], NotUsed] = buildSource(inputFile = nameBasics)
|
65
|
|
- val personSink: Sink[Person, Future[Done]] = buildPersonSink(logger = logger)
|
66
|
|
-
|
67
|
|
- //graph
|
68
|
|
- val startTime: Long = System.currentTimeMillis()
|
69
|
|
- personSource
|
70
|
|
- .via(flow = buildPersonFlow())
|
71
|
|
- .runWith(sink = personSink)
|
72
|
|
- .andThen {
|
73
|
|
- case Success(value) =>
|
74
|
|
- val elapsedTime: Long = (System.currentTimeMillis() - startTime) / 1000
|
75
|
|
- logger.info(s"$value: successfully processing, elapsed time: $elapsedTime sec")
|
76
|
|
- case Failure(error: Error) => logger.error(s"$error")
|
77
|
|
- }
|
|
113
|
+ getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
|
78
|
114
|
}
|
79
|
115
|
|
80
|
|
- override def getPersonById(nconst: String): Unit = {
|
81
|
|
- val source: Source[Map[String, String], NotUsed] = buildSource(inputFile = nameBasics)
|
82
|
|
-
|
83
|
|
- val startTime: Long = System.currentTimeMillis()
|
84
|
|
- source
|
85
|
|
- .via(flow = filterByPersonIdFlow(nconst = nconst))
|
86
|
|
- .runWith(sink = buildPersonSink(logger = logger))
|
87
|
|
- .andThen {
|
88
|
|
- case Success(value) =>
|
89
|
|
- val elapsedTime: Long = (System.currentTimeMillis()-startTime)/1000
|
90
|
|
- logger.info(s"$value: Successfully processed, elapsed time: $elapsedTime")
|
91
|
|
- case Failure(exception) => logger.error(s"$exception: Fail")
|
92
|
|
- }
|
|
116
|
+ private def getTvSerieIdByPrimaryTitle(primaryTitle: String): String ={
|
|
117
|
+ val source: Source[Map[String, String],_]= buildSource(inputFile = titleBasics)
|
|
118
|
+
|
|
119
|
+ var tvSerie: TvSeries =null
|
|
120
|
+ val res : Future[Option[String]]= source
|
|
121
|
+ .filter((rowMap: Map[String, String]) =>{
|
|
122
|
+ rowMap.getOrElse(key = "primaryTitle","")==primaryTitle
|
|
123
|
+ })
|
|
124
|
+ .map((rowMap: Map[String, String])=>{
|
|
125
|
+ tvSerie = buildTvSerieModel(rowMap)
|
|
126
|
+ rowMap.get("tconst")
|
|
127
|
+ })
|
|
128
|
+ .runWith(Sink.head)
|
|
129
|
+
|
|
130
|
+ Await.result(res,1 minutes)
|
|
131
|
+ val tconst:String = res.value.get.get.get
|
|
132
|
+ tconst
|
93
|
133
|
}
|
94
|
134
|
|
95
|
|
- override def getPersonByName(primaryName: String): Unit = {
|
96
|
|
- val source: Source[Map[String, String], NotUsed] = buildSource(inputFile = nameBasics)
|
97
|
|
- source
|
98
|
|
- .via(
|
99
|
|
- flow = filterByPersonNameFlow(personName = primaryName)
|
100
|
|
- )
|
101
|
|
- .runWith(sink = buildPersonSink(logger = logger))
|
102
|
|
- .andThen {
|
103
|
|
- case Failure(exception) => logger.info(s"$exception")
|
104
|
|
- case Success(value) => logger.info(s"$value: Successufully processing")
|
105
|
|
- }
|
106
|
|
- }
|
|
135
|
+
|
107
|
136
|
}
|
108
|
137
|
|
109
|
138
|
|