|
@@ -7,18 +7,7 @@ import com.typesafe.scalalogging.slf4j.Logger
|
7
|
7
|
import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
|
8
|
8
|
import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSeries}
|
9
|
9
|
import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.{buildPersonModel, buildTvSerieModel}
|
10
|
|
-import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
|
11
|
|
- buildAllPersonsSink,
|
12
|
|
- buildAndValidateSource,
|
13
|
|
- buildPersonFlow,
|
14
|
|
- buildPersonSink,
|
15
|
|
- buildSource,
|
16
|
|
- buildTvSerieFlow,
|
17
|
|
- buildTvSeriesSink,
|
18
|
|
- filterByPersonIdFlow,
|
19
|
|
- filterByPersonNameFlow,
|
20
|
|
- filterByTvSeriePrimaryTitleFlow
|
21
|
|
-}
|
|
10
|
+import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildPersonSink, buildSource, buildTvSerieFlow, buildTvSeriesSink, filterByPersonIdFlow, filterByPersonNameFlow, filterByTvSeriePrimaryTitleFlow}
|
22
|
11
|
import org.slf4j.LoggerFactory
|
23
|
12
|
import org.springframework.stereotype.Component
|
24
|
13
|
|
|
@@ -34,41 +23,37 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
34
|
23
|
implicit val actorSystem: ActorSystem = ActorSystem("AkkaStreamActor")
|
35
|
24
|
implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
|
36
|
25
|
|
37
|
|
- override def getAllPersons(): Unit = {
|
|
26
|
+ override def getAllPersons() = {
|
38
|
27
|
val personSource: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
39
|
|
- val personSink: Sink[Person, Future[Done]] = buildAllPersonsSink(logger = logger)
|
40
|
|
-
|
41
|
28
|
//graph
|
42
|
29
|
val startTime: Long = System.currentTimeMillis()
|
43
|
30
|
val result: Future[Done] = personSource
|
44
|
31
|
.via(flow = buildPersonFlow())
|
45
|
|
- .runWith(sink = personSink)
|
46
|
|
- .andThen {
|
47
|
|
- case Success(value) =>
|
48
|
|
- val elapsedTime: Long = (System.currentTimeMillis() - startTime) / 1000
|
49
|
|
- logger.info(s"$value: Successfully processed, elapsed time: $elapsedTime")
|
50
|
|
- case Failure(exception) => logger.error(s"$exception: Fail")
|
51
|
|
- }
|
|
32
|
+ .runWith(sink = buildAllPersonsSink(logger = logger))
|
|
33
|
+
|
|
34
|
+ result.onComplete {
|
|
35
|
+ case Failure(exception) => logger.error(s"$exception")
|
|
36
|
+ case Success(value) =>
|
|
37
|
+ logger.info(s"$value")
|
|
38
|
+ val time: Long =(System.currentTimeMillis()-startTime)/100
|
|
39
|
+ logger.info(s"elapsed time: $time")
|
|
40
|
+ }
|
52
|
41
|
}
|
53
|
42
|
|
54
|
|
- override def getPersonById(nconst: String): Person = {
|
|
43
|
+ override def getPersonById(nconst: String): Future[Person] = {
|
55
|
44
|
val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
56
|
45
|
|
57
|
46
|
val startTime: Long = System.currentTimeMillis()
|
58
|
47
|
val res = source
|
59
|
48
|
.via(flow = filterByPersonIdFlow(nconst = nconst))
|
60
|
49
|
.runWith(sink = buildPersonSink())
|
61
|
|
- .andThen {
|
62
|
|
- case Success(value) =>
|
63
|
|
- val elapsedTime: Long = (System.currentTimeMillis()-startTime)/1000
|
64
|
|
- logger.info(s"$value")
|
65
|
|
- logger.info(s"Successfully processed, elapsed time: $elapsedTime")
|
66
|
|
- case Failure(exception) => logger.error(s"$exception: Fail")
|
67
|
|
- }
|
68
|
50
|
|
69
|
|
- Await.result(res,1 minutes)
|
70
|
|
- val person: Person = res.value.get.get
|
71
|
|
- person
|
|
51
|
+ res.andThen {
|
|
52
|
+ case Failure(exception) => logger.info(s"error!!!!!!!!!!!!!$exception")
|
|
53
|
+ case Success(value) => logger.info(s"$value")
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ res
|
72
|
57
|
}
|
73
|
58
|
|
74
|
59
|
override def getPersonByName(primaryName: String): Unit = {
|
|
@@ -87,7 +72,7 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
87
|
72
|
override def getAllTvSeries(): Unit = {
|
88
|
73
|
|
89
|
74
|
val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
|
90
|
|
- val sink: Sink[TvSeries, Future[Done]] = buildTvSeriesSink(logger = logger)
|
|
75
|
+ val sink: Sink[TvSeries, Future[Done]] = buildAllTvSeriesSink(logger = logger)
|
91
|
76
|
|
92
|
77
|
val startingTime: Long = System.currentTimeMillis()
|
93
|
78
|
|
|
@@ -104,26 +89,21 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
104
|
89
|
|
105
|
90
|
}
|
106
|
91
|
|
107
|
|
- override def getByTvSeriePrimaryTitle(tvSeriePrimaryTitle: String): Unit = {
|
|
92
|
+ override def getByTvSeriePrimaryTitle(tvSeriePrimaryTitle: String):Future[IndexedSeq[TvSeries]] = {
|
108
|
93
|
|
109
|
94
|
val tvSeriesSource: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
|
110
|
|
- val tvSeriesSink: Sink[TvSeries, Future[Done]] = buildTvSeriesSink(logger = logger)
|
111
|
95
|
|
112
|
|
- val filterByMovieTitleFlow: Flow[Map[String, String], TvSeries, NotUsed] =
|
|
96
|
+ val filterByTvSerieTitle: Flow[Map[String, String], TvSeries, NotUsed] =
|
113
|
97
|
filterByTvSeriePrimaryTitleFlow(tvSeriePrimaryTitle = tvSeriePrimaryTitle)
|
114
|
98
|
|
115
|
|
- val startTime: Long = System.currentTimeMillis()
|
116
|
|
- val listTvSeries: Future[Done] = tvSeriesSource
|
117
|
|
- .via(flow = filterByMovieTitleFlow)
|
118
|
|
- .runWith(sink = tvSeriesSink)
|
119
|
|
- .andThen {
|
120
|
|
- case Success(value) =>
|
121
|
|
- val elapsedTime: Long = (System.currentTimeMillis() - startTime) / 1000
|
122
|
|
- logger.info(s"$value: successfully processing file, elapsed time: $elapsedTime sec")
|
123
|
|
- case Failure(error: Error) => logger.error(s"$error")
|
124
|
|
- }
|
|
99
|
+ val tvSrie :Future[IndexedSeq[TvSeries]] = tvSeriesSource
|
|
100
|
+ .via(flow = filterByTvSerieTitle)
|
|
101
|
+ .runWith(Sink.collection)
|
125
|
102
|
|
126
|
|
- getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
|
|
103
|
+ tvSrie.andThen {
|
|
104
|
+ case Failure(exception) => logger.info(s"$exception")
|
|
105
|
+ case Success(value) => logger.info(s"$value")
|
|
106
|
+ }
|
127
|
107
|
|
128
|
108
|
}
|
129
|
109
|
|
|
@@ -193,7 +173,6 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
193
|
173
|
case Failure(exception) => logger.error(s"$exception")
|
194
|
174
|
case Success(value) =>
|
195
|
175
|
val elapsedTime: Long = (System.currentTimeMillis()-startTime)/1000
|
196
|
|
- logger.info(s"$value")
|
197
|
176
|
logger.info(s"END: Successfully, elapsed time: $elapsedTime")
|
198
|
177
|
}
|
199
|
178
|
|
|
@@ -203,12 +182,17 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
203
|
182
|
listPersons
|
204
|
183
|
|
205
|
184
|
}
|
206
|
|
-
|
207
|
|
- override def generalize(tvSeriePrimaryTitle: String): Unit={
|
|
185
|
+ override def getPersonsTeamForTvSerie(tvSeriePrimaryTitle: String):Unit={
|
208
|
186
|
|
209
|
187
|
val tvSerieID: String = getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
|
210
|
188
|
val listPersonIDs: List[Option[String]] = getListOfPersonsIDByTvSerieID(tconst = tvSerieID)
|
211
|
|
- getListOfPersonsForTvSerie(nconstList = listPersonIDs)
|
|
189
|
+ val personsTeam: List[Person] = getListOfPersonsForTvSerie(nconstList = listPersonIDs)
|
|
190
|
+
|
|
191
|
+ logger.info(s"Team size:${personsTeam.size}")
|
|
192
|
+ personsTeam.foreach((person: Person)=>{
|
|
193
|
+ logger.info(s"${person.toString}")
|
|
194
|
+ })
|
|
195
|
+
|
212
|
196
|
}
|
213
|
197
|
|
214
|
198
|
}
|