|
@@ -3,13 +3,13 @@ package fr.natan.akkastreamfileprocessingapi.service
|
3
|
3
|
import akka.Done
|
4
|
4
|
import akka.stream.scaladsl.{Sink, Source}
|
5
|
5
|
import com.typesafe.scalalogging.slf4j.Logger
|
6
|
|
-import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics}
|
|
6
|
+import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
|
7
|
7
|
import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap.{Person, TvSerie}
|
8
|
8
|
import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
|
9
|
|
- actorSystem, buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildSource,
|
10
|
|
- buildTvSerieFlow, filterPersonByIdFlow, filterPersonByNameFlow, filterTvSerieByIdFlow, filterTvSerieByPrimaryTitleFlow}
|
11
|
|
-import fr.natan.akkastreamfileprocessingapi.service.UtilitiesClass.{
|
12
|
|
- getListOfPersonsForTvSerie, getListOfPersonsIDByTvSerieID, getTvSerieIDFuture, getTvSerieIdByPrimaryTitle}
|
|
9
|
+ actorSystem, buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildTvSerieFlow,
|
|
10
|
+ filterPersonByIdFlow, filterPersonByNameFlow, filterTvSerieByIdFlow, filterTvSerieByPrimaryTitleFlow}
|
|
11
|
+import fr.natan.akkastreamfileprocessingapi.service.UtilitiesClass.{getListOfPersonsForTvSerie, getListOfPersonsIDByTvSerieID,
|
|
12
|
+ getTvSerieIDFuture, getTvSerieIdByPrimaryTitle}
|
13
|
13
|
import org.slf4j.LoggerFactory
|
14
|
14
|
import org.springframework.stereotype.Component
|
15
|
15
|
|
|
@@ -24,46 +24,43 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
24
|
24
|
|
25
|
25
|
implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
|
26
|
26
|
|
27
|
|
- override def getPersonByIdFuture(personID: String): Future[Option[Person]] = {
|
28
|
|
- val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
|
27
|
+ override def getPersonByIdFuture(personID: String): Future[Person] = {
|
|
28
|
+ val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = nameBasics)
|
29
|
29
|
|
30
|
30
|
val start: Long = System.currentTimeMillis()
|
31
|
|
- val personFuture: Future[Option[Person]] = source
|
|
31
|
+ val personFuture: Future[Person] = source
|
32
|
32
|
.via(flow = filterPersonByIdFlow(personID = personID))
|
33
|
|
- .runWith(Sink.headOption[Person])
|
|
33
|
+ .runWith(Sink.head[Person])
|
34
|
34
|
|
35
|
35
|
personFuture.andThen({
|
36
|
|
- case Failure(exception) => logger.info(s"$exception")
|
37
|
|
- case Success(value: Option[Person]) =>
|
38
|
|
- logger.info(s"$value")
|
39
|
|
- logger.info(s"SUCCESS, elapsed time:${(System.currentTimeMillis() - start) / 1000} sec")
|
|
36
|
+ case Failure(exception) => logger.error(s"!${exception.printStackTrace()}")
|
40
|
37
|
})
|
41
|
38
|
|
42
|
39
|
personFuture
|
43
|
40
|
}
|
44
|
41
|
|
45
|
|
- override def getPersonByNameFuture(primaryName: String): Future[Option[Person]] = {
|
46
|
|
- val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
|
42
|
+ override def getPersonByNameFuture(primaryName: String): Future[Person] = {
|
|
43
|
+ val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = nameBasics)
|
47
|
44
|
|
48
|
45
|
val start: Long = System.currentTimeMillis()
|
49
|
|
- val personFuture: Future[Option[Person]] = source
|
|
46
|
+ val personFuture: Future[Person] = source
|
50
|
47
|
.via(flow = filterPersonByNameFlow(primaryName = primaryName))
|
51
|
|
- .runWith(Sink.headOption[Person])
|
|
48
|
+ .runWith(Sink.head[Person])
|
52
|
49
|
|
53
|
50
|
personFuture
|
54
|
51
|
}
|
55
|
52
|
|
56
|
|
- override def getTvSerieByIdFuture(tvSerieID: String): Future[Option[TvSerie]] = {
|
57
|
|
- val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
|
|
53
|
+ override def getTvSerieByIdFuture(tvSerieID: String): Future[TvSerie] = {
|
|
54
|
+ val source: Source[Map[String, String], _] = buildAndValidateSource(inputFile = titleBasics)
|
58
|
55
|
|
59
|
56
|
val start: Long = System.currentTimeMillis()
|
60
|
|
- val tvSerieFuture: Future[Option[TvSerie]] = source
|
|
57
|
+ val tvSerieFuture: Future[TvSerie] = source
|
61
|
58
|
.via(flow = filterTvSerieByIdFlow(tvSerieID = tvSerieID))
|
62
|
|
- .runWith(Sink.headOption[TvSerie])
|
|
59
|
+ .runWith(Sink.head[TvSerie])
|
63
|
60
|
|
64
|
61
|
tvSerieFuture.onComplete({
|
65
|
62
|
case Failure(exception) => logger.info(s"$exception")
|
66
|
|
- case Success(value: Option[TvSerie]) =>
|
|
63
|
+ case Success(value: TvSerie) =>
|
67
|
64
|
logger.info(s"$value")
|
68
|
65
|
logger.info(s"SUCCESS, elapsed time:${(System.currentTimeMillis() - start) / 1000} sec")
|
69
|
66
|
})
|
|
@@ -91,13 +88,15 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
91
|
88
|
override def getPersonsForTvSerieByTvSerieTitleFuture(tvSeriePrimaryTitle: String): Future[IndexedSeq[Person]] = {
|
92
|
89
|
|
93
|
90
|
//futures chaining
|
94
|
|
- logger.info("STEP 1/3 START")
|
|
91
|
+ logger.info("STEP 1/3 ...")
|
95
|
92
|
val start1: Long = System.currentTimeMillis()
|
96
|
|
- val tvSerieIDFuture: Future[Option[String]] = getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
|
|
93
|
+ val tvSerieIDFuture: Future[Option[String]] = getTvSerieIdByPrimaryTitle(
|
|
94
|
+ primaryTitle = tvSeriePrimaryTitle,
|
|
95
|
+ inputFile = titleBasics
|
|
96
|
+ )
|
97
|
97
|
|
98
|
98
|
val finalFuture: Future[IndexedSeq[Person]] =
|
99
|
99
|
tvSerieIDFuture.andThen({
|
100
|
|
- case Failure(exception) => logger.error(s"$exception")
|
101
|
100
|
case Success(value: Option[String]) =>
|
102
|
101
|
logger.info(s"TvSerie ID: $value")
|
103
|
102
|
logger.info(s"STEP 1/3 END, elapsed time:${(System.currentTimeMillis() - start1) / 1000} sec")
|
|
@@ -105,24 +104,23 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
105
|
104
|
})
|
106
|
105
|
.flatMap({
|
107
|
106
|
_ =>
|
108
|
|
- logger.info("STEP 2/3 START")
|
|
107
|
+ logger.info("STEP 2/3 ...")
|
109
|
108
|
val start2: Long = System.currentTimeMillis()
|
110
|
109
|
val listPersonIDsFuture: Future[IndexedSeq[Option[String]]] = getListOfPersonsIDByTvSerieID(
|
111
|
|
- tvSerieIdFuture = tvSerieIDFuture)
|
|
110
|
+ tvSerieIdFuture = tvSerieIDFuture, inputFile = titlePrincipalsBasics
|
|
111
|
+ )
|
112
|
112
|
listPersonIDsFuture.andThen({
|
113
|
|
- case Failure(exception) => logger.error(s"$exception")
|
114
|
113
|
case Success(value) =>
|
115
|
114
|
value.foreach((personID: Option[String]) => logger.info(s"Person ID:$personID"))
|
116
|
115
|
logger.info(s"STEP 2/3 END, elapsed time:${(System.currentTimeMillis() - start2) / 1000} sec")
|
117
|
116
|
})
|
118
|
117
|
.flatMap({
|
119
|
118
|
_ =>
|
120
|
|
- logger.info("STEP 3/3 START")
|
|
119
|
+ logger.info("STEP 3/3 ...")
|
121
|
120
|
val start3: Long = System.currentTimeMillis()
|
122
|
121
|
val personsTeamFuture: Future[IndexedSeq[Person]] = getListOfPersonsForTvSerie(
|
123
|
|
- listPersonsIDsFuture = listPersonIDsFuture)
|
|
122
|
+ listPersonsIDsFuture = listPersonIDsFuture, inputFile = nameBasics)
|
124
|
123
|
personsTeamFuture.andThen({
|
125
|
|
- case Failure(exception) => logger.error(s"$exception")
|
126
|
124
|
case Success(value: IndexedSeq[Person]) =>
|
127
|
125
|
value.foreach((person: Person) => logger.info(s"${person.toString}"))
|
128
|
126
|
logger.info(s"STEP 3/3 END, elapsed time:${(System.currentTimeMillis() - start3) / 1000} sec")
|
|
@@ -136,8 +134,9 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
136
|
134
|
override def getPersonsForTvSerieByTvSerieIDFuture(tvSerieId: String): Future[IndexedSeq[Person]] = {
|
137
|
135
|
|
138
|
136
|
val start1: Long = System.currentTimeMillis()
|
139
|
|
- logger.info("STEP 1/3")
|
140
|
|
- val tvSerieIdFuture: Future[Option[String]] = getTvSerieIDFuture(tvSerieId = tvSerieId)
|
|
137
|
+ logger.info("STEP 1/3 ...")
|
|
138
|
+ val tvSerieIdFuture: Future[Option[String]] = getTvSerieIDFuture(
|
|
139
|
+ tvSerieID = tvSerieId, logger = logger, inputFile = titleBasics)
|
141
|
140
|
tvSerieIdFuture.andThen({
|
142
|
141
|
case Failure(exception) => logger.error(s"${exception.printStackTrace()}")
|
143
|
142
|
case Success(value: Option[String]) =>
|
|
@@ -147,10 +146,10 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
147
|
146
|
})
|
148
|
147
|
.flatMap({
|
149
|
148
|
_ =>
|
150
|
|
- logger.info("STEP 2/3")
|
|
149
|
+ logger.info("STEP 2/3 ...")
|
151
|
150
|
val start2: Long = System.currentTimeMillis()
|
152
|
151
|
val listOfPersonsIDsFuture: Future[IndexedSeq[Option[String]]] = getListOfPersonsIDByTvSerieID(
|
153
|
|
- tvSerieIdFuture = tvSerieIdFuture)
|
|
152
|
+ tvSerieIdFuture = tvSerieIdFuture, inputFile = titlePrincipalsBasics)
|
154
|
153
|
listOfPersonsIDsFuture.andThen({
|
155
|
154
|
case Failure(exception) => logger.error(s"${exception.printStackTrace()}")
|
156
|
155
|
case Success(value: IndexedSeq[Option[String]]) =>
|
|
@@ -159,10 +158,10 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
159
|
158
|
})
|
160
|
159
|
.flatMap({
|
161
|
160
|
_ =>
|
162
|
|
- logger.info("STEP 3/3")
|
|
161
|
+ logger.info("STEP 3/3 ...")
|
163
|
162
|
val start3: Long = System.currentTimeMillis()
|
164
|
163
|
val personsTeamFuture: Future[IndexedSeq[Person]] = getListOfPersonsForTvSerie(
|
165
|
|
- listPersonsIDsFuture = listOfPersonsIDsFuture)
|
|
164
|
+ listPersonsIDsFuture = listOfPersonsIDsFuture, inputFile = nameBasics)
|
166
|
165
|
personsTeamFuture.andThen({
|
167
|
166
|
case Failure(exception) => logger.error(s"$exception")
|
168
|
167
|
case Success(value: IndexedSeq[Person]) =>
|
|
@@ -175,7 +174,7 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
175
|
174
|
}
|
176
|
175
|
|
177
|
176
|
override def getAllPersonsFuture: Future[Done] = {
|
178
|
|
- val personSource: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
|
177
|
+ val personSource: Source[Map[String, String], _] = buildAndValidateSource(inputFile = nameBasics)
|
179
|
178
|
//graph
|
180
|
179
|
val startTime: Long = System.currentTimeMillis()
|
181
|
180
|
val result: Future[Done] = personSource
|
|
@@ -189,7 +188,6 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
189
|
188
|
val time: Long = (System.currentTimeMillis() - startTime) / 100
|
190
|
189
|
logger.info(s"elapsed time: $time")
|
191
|
190
|
}
|
192
|
|
-
|
193
|
191
|
result
|
194
|
192
|
}
|
195
|
193
|
|
|
@@ -211,7 +209,6 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessingFuture {
|
211
|
209
|
|
212
|
210
|
results
|
213
|
211
|
}
|
214
|
|
-
|
215
|
212
|
}
|
216
|
213
|
|
217
|
214
|
|