|
@@ -6,24 +6,26 @@ import akka.{Done, NotUsed}
|
6
|
6
|
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
|
|
-import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.{buildPersonModel, buildTvSerieModel}
|
10
|
|
-import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildPersonSink, buildSource, buildTvSerieFlow, buildTvSeriesSink, filterByPersonIdFlow, filterByPersonNameFlow, filterByTvSeriePrimaryTitleFlow}
|
|
9
|
+import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
|
|
10
|
+import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
|
|
11
|
+ buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow,
|
|
12
|
+ buildSource, buildTvSerieFlow, filterByPersonIdFlow, filterByPersonNameFlow, filterByTvSeriePrimaryTitleFlow}
|
11
|
13
|
import org.slf4j.LoggerFactory
|
12
|
14
|
import org.springframework.stereotype.Component
|
13
|
15
|
|
14
|
16
|
import scala.concurrent.ExecutionContext.Implicits.global
|
15
|
|
-import scala.concurrent.duration.DurationInt
|
16
|
|
-import scala.concurrent.{Await, Future}
|
|
17
|
+import scala.concurrent.Future
|
17
|
18
|
import scala.language.postfixOps
|
18
|
19
|
import scala.util.{Failure, Success}
|
19
|
20
|
|
|
21
|
+//noinspection SpellCheckingInspection
|
20
|
22
|
@Component
|
21
|
23
|
class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
22
|
24
|
|
23
|
25
|
implicit val actorSystem: ActorSystem = ActorSystem("AkkaStreamActor")
|
24
|
26
|
implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
|
25
|
27
|
|
26
|
|
- override def getAllPersons() = {
|
|
28
|
+ override def getAllPersons(): Unit = {
|
27
|
29
|
val personSource: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
28
|
30
|
//graph
|
29
|
31
|
val startTime: Long = System.currentTimeMillis()
|
|
@@ -35,7 +37,7 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
35
|
37
|
case Failure(exception) => logger.error(s"$exception")
|
36
|
38
|
case Success(value) =>
|
37
|
39
|
logger.info(s"$value")
|
38
|
|
- val time: Long =(System.currentTimeMillis()-startTime)/100
|
|
40
|
+ val time: Long = (System.currentTimeMillis() - startTime) / 100
|
39
|
41
|
logger.info(s"elapsed time: $time")
|
40
|
42
|
}
|
41
|
43
|
}
|
|
@@ -43,30 +45,26 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
43
|
45
|
override def getPersonById(nconst: String): Future[Person] = {
|
44
|
46
|
val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
45
|
47
|
|
46
|
|
- val startTime: Long = System.currentTimeMillis()
|
|
48
|
+
|
47
|
49
|
val res = source
|
48
|
50
|
.via(flow = filterByPersonIdFlow(nconst = nconst))
|
49
|
|
- .runWith(sink = buildPersonSink())
|
|
51
|
+ .runWith(Sink.head)
|
50
|
52
|
|
51
|
53
|
res.andThen {
|
52
|
|
- case Failure(exception) => logger.info(s"error!!!!!!!!!!!!!$exception")
|
|
54
|
+ case Failure(exception) => logger.info(s"$exception")
|
53
|
55
|
case Success(value) => logger.info(s"$value")
|
54
|
56
|
}
|
55
|
57
|
|
56
|
58
|
res
|
57
|
59
|
}
|
58
|
60
|
|
59
|
|
- override def getPersonByName(primaryName: String): Unit = {
|
|
61
|
+ override def getPersonByName(primaryName: String): Future[IndexedSeq[Person]] = {
|
60
|
62
|
val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
61
|
|
- source
|
62
|
|
- .via(
|
63
|
|
- flow = filterByPersonNameFlow(personName = primaryName)
|
64
|
|
- )
|
65
|
|
- .runWith(sink = buildPersonSink())
|
66
|
|
- .andThen {
|
67
|
|
- case Failure(exception) => logger.info(s"$exception")
|
68
|
|
- case Success(value) => logger.info(s"$value: Successufully processing")
|
69
|
|
- }
|
|
63
|
+ val persons: Future[IndexedSeq[Person]] = source
|
|
64
|
+ .via(flow = filterByPersonNameFlow(primaryName = primaryName))
|
|
65
|
+ .runWith(Sink.collection)
|
|
66
|
+
|
|
67
|
+ persons
|
70
|
68
|
}
|
71
|
69
|
|
72
|
70
|
override def getAllTvSeries(): Unit = {
|
|
@@ -107,90 +105,80 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
|
107
|
105
|
|
108
|
106
|
}
|
109
|
107
|
|
110
|
|
- private def getTvSerieIdByPrimaryTitle(primaryTitle: String): String = {
|
|
108
|
+ private def getTvSerieIdByPrimaryTitle(primaryTitle: String): Future[Option[String]] = {
|
111
|
109
|
val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
|
112
|
110
|
|
113
|
|
- var tvSerie: TvSeries = null
|
114
|
111
|
val res: Future[Option[String]] = source
|
115
|
112
|
.filter((rowMap: Map[String, String]) => {
|
116
|
113
|
rowMap.getOrElse(key = "primaryTitle", "") == primaryTitle
|
117
|
114
|
})
|
118
|
115
|
.map((rowMap: Map[String, String]) => {
|
119
|
|
- tvSerie = buildTvSerieModel(rowMap)
|
120
|
116
|
rowMap.get("tconst")
|
121
|
117
|
})
|
122
|
118
|
.runWith(Sink.head)
|
123
|
119
|
|
124
|
|
- Await.result(res, 1 minutes)
|
125
|
|
- val tconst: String = res.value.get.get.get
|
126
|
|
- logger.info(s"TvSerie ID: $tconst, $tvSerie")
|
127
|
|
- tconst
|
|
120
|
+ res
|
|
121
|
+
|
128
|
122
|
}
|
129
|
123
|
|
130
|
|
- private def getListOfPersonsIDByTvSerieID(tconst: String): List[Option[String]]={
|
|
124
|
+ private def getListOfPersonsIDByTvSerieID(tvSerieID: Future[Option[String]]): Future[IndexedSeq[Option[String]]]={
|
131
|
125
|
val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
|
132
|
126
|
|
133
|
|
- val startTime : Long = System.currentTimeMillis()
|
134
|
127
|
val res: Future[IndexedSeq[Option[String]]] = source
|
135
|
128
|
.filter((rowMaps: Map[String, String])=>{
|
136
|
|
- rowMaps.getOrElse(key = "tconst", default = "")==tconst
|
|
129
|
+ rowMaps.getOrElse(key = "tconst", default = "")==tvSerieID.value.get.get.get
|
137
|
130
|
})
|
138
|
131
|
.map((rowMap: Map[String, String])=>{
|
139
|
132
|
rowMap.get(key = "nconst")
|
140
|
133
|
})
|
141
|
134
|
.runWith(Sink.collection)
|
142
|
|
- .andThen {
|
143
|
|
- case Success(value) =>
|
144
|
|
- logger.info(s"$value")
|
145
|
|
- val elapsedTime : Long = (System.currentTimeMillis() - startTime)/1000
|
146
|
|
- logger.info(s"success, elapsed time: $elapsedTime")
|
147
|
|
-
|
148
|
|
- case Failure(error: Error) => logger.error(s"$error")
|
149
|
|
- }
|
150
|
|
-
|
151
|
|
- Await.result(res, 3 minutes)
|
152
|
|
- val listPersonsID: List[Option[String]] = res.value.get.get.toList
|
153
|
135
|
|
154
|
|
- listPersonsID
|
|
136
|
+ res
|
155
|
137
|
|
156
|
138
|
}
|
157
|
139
|
|
158
|
|
- private def getListOfPersonsForTvSerie(nconstList: List[Option[String]]): List[Person] = {
|
|
140
|
+ private def getListOfPersonsForTvSerie(listPersonsIDs: Future[IndexedSeq[Option[String]]]): Future[IndexedSeq[Person]] = {
|
159
|
141
|
val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
|
160
|
142
|
|
161
|
|
- val startTime: Long = System.currentTimeMillis()
|
162
|
|
-
|
163
|
143
|
val res : Future[IndexedSeq[Person]]=
|
164
|
144
|
source
|
165
|
145
|
.filter((rowMaps: Map[String, String])=>{
|
166
|
|
- nconstList.contains(rowMaps.get(key = "nconst"))
|
|
146
|
+ listPersonsIDs.value.get.get.contains(rowMaps.get(key = "nconst"))
|
167
|
147
|
})
|
168
|
148
|
.map((rowMap: Map[String, String])=>{
|
169
|
149
|
buildPersonModel(rowMap)
|
170
|
150
|
})
|
171
|
151
|
.runWith(Sink.collection)
|
172
|
|
- .andThen {
|
173
|
|
- case Failure(exception) => logger.error(s"$exception")
|
174
|
|
- case Success(value) =>
|
175
|
|
- val elapsedTime: Long = (System.currentTimeMillis()-startTime)/1000
|
176
|
|
- logger.info(s"END: Successfully, elapsed time: $elapsedTime")
|
177
|
|
- }
|
178
|
|
-
|
179
|
|
- Await.result(res, 4 minutes)
|
180
|
|
- val listPersons: List[Person] = res.value.get.get.toList
|
181
|
|
-
|
182
|
|
- listPersons
|
183
|
152
|
|
|
153
|
+ res
|
184
|
154
|
}
|
185
|
155
|
override def getPersonsTeamForTvSerie(tvSeriePrimaryTitle: String):Unit={
|
186
|
156
|
|
187
|
|
- val tvSerieID: String = getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
|
188
|
|
- val listPersonIDs: List[Option[String]] = getListOfPersonsIDByTvSerieID(tconst = tvSerieID)
|
189
|
|
- val personsTeam: List[Person] = getListOfPersonsForTvSerie(nconstList = listPersonIDs)
|
|
157
|
+ logger.info("STEP 1/3")
|
|
158
|
+ val tvSerieID = getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
|
|
159
|
+ tvSerieID.onComplete({
|
|
160
|
+ case Failure(exception) => logger.error(s"$exception")
|
|
161
|
+ case Success(value: Option[String]) =>
|
|
162
|
+ logger.info(s"TvSerie ID: $value")
|
|
163
|
+ logger.info("END STEP 1/3")
|
|
164
|
+ })
|
|
165
|
+ logger.info("STEP 2/3")
|
|
166
|
+ val listPersonIDs = getListOfPersonsIDByTvSerieID(tvSerieID = tvSerieID)
|
|
167
|
+ listPersonIDs.onComplete({
|
|
168
|
+ case Failure(exception) => logger.error(s"$exception")
|
|
169
|
+ case Success(value) =>
|
|
170
|
+ value.toList.foreach((personID: Option[String])=>logger.info(s"Person ID:$personID"))
|
|
171
|
+ logger.info("END STEP 2/3")
|
|
172
|
+ })
|
190
|
173
|
|
191
|
|
- logger.info(s"Team size:${personsTeam.size}")
|
192
|
|
- personsTeam.foreach((person: Person)=>{
|
193
|
|
- logger.info(s"${person.toString}")
|
|
174
|
+ logger.info("STEP 3/3")
|
|
175
|
+ val personsTeam= getListOfPersonsForTvSerie(listPersonsIDs = listPersonIDs)
|
|
176
|
+ personsTeam.onComplete({
|
|
177
|
+ case Failure(exception) => logger.error(s"$exception")
|
|
178
|
+ case Success(value) =>
|
|
179
|
+ logger.info(s"${value.toList}")
|
|
180
|
+ value.toList.foreach((person:Person)=>logger.info(s"${person.toString}"))
|
|
181
|
+ logger.info("END STEP 3/3")
|
194
|
182
|
})
|
195
|
183
|
|
196
|
184
|
}
|