|
@@ -7,7 +7,8 @@ import akka.util.ByteString
|
7
|
7
|
import akka.{Done, NotUsed}
|
8
|
8
|
import com.typesafe.scalalogging.slf4j.Logger
|
9
|
9
|
import fr.natan.akkastreamfileprocessingapi.businessexceptions.FileNotFoundException
|
10
|
|
-import fr.natan.akkastreamfileprocessingapi.models.TvSeries
|
|
10
|
+import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.separator
|
|
11
|
+import fr.natan.akkastreamfileprocessingapi.models.{Person, TvSeries}
|
11
|
12
|
import fr.natan.akkastreamfileprocessingapi.valitator.Validators.fileExists
|
12
|
13
|
|
13
|
14
|
import java.io.File
|
|
@@ -18,7 +19,7 @@ object AkkaStreamComponents {
|
18
|
19
|
|
19
|
20
|
implicit val actor: ActorSystem = ActorSystem("AkkaStreamActor")
|
20
|
21
|
|
21
|
|
- private def convertToClassMovie(array: Array[String]): TvSeries = {
|
|
22
|
+ private def convertToTvSerie(array: Array[String]): TvSeries = {
|
22
|
23
|
val tvSerie: TvSeries = TvSeries(
|
23
|
24
|
array(0),
|
24
|
25
|
array(1),
|
|
@@ -33,19 +34,42 @@ object AkkaStreamComponents {
|
33
|
34
|
tvSerie
|
34
|
35
|
}
|
35
|
36
|
|
|
37
|
+ private def convertToPerson(array: Array[String]): Person ={
|
|
38
|
+ Person(
|
|
39
|
+ array(0),
|
|
40
|
+ array(1),
|
|
41
|
+ array(2),
|
|
42
|
+ array(3),
|
|
43
|
+ array(4).split(",").toList,
|
|
44
|
+ array(5).split(",").toList,
|
|
45
|
+ )
|
|
46
|
+ }
|
|
47
|
+
|
36
|
48
|
//flows
|
37
|
49
|
|
38
|
|
- def buildMovieFlow(movieID: String): Flow[String, TvSeries, NotUsed] = {
|
|
50
|
+ def buildTvSerieFlow(movieID: String): Flow[String, TvSeries, NotUsed] = {
|
39
|
51
|
|
40
|
|
- val flow: Flow[String, TvSeries, NotUsed] =
|
|
52
|
+ val tvFlow: Flow[String, TvSeries, NotUsed] =
|
41
|
53
|
Flow[String].filter(rows => !rows.contains(movieID))
|
42
|
54
|
.map(row => {
|
43
|
|
- val movie: Array[String] = row.split("\t")
|
44
|
|
- convertToClassMovie(movie)
|
|
55
|
+ val movie: Array[String] = row.split(separator)
|
|
56
|
+ convertToTvSerie(movie)
|
45
|
57
|
})
|
46
|
|
- flow
|
|
58
|
+ tvFlow
|
47
|
59
|
}
|
48
|
60
|
|
|
61
|
+ def buildPersonFlow(personID: String): Flow[String, Person, NotUsed]={
|
|
62
|
+ val personFlow: Flow[String, Person, NotUsed] =
|
|
63
|
+ Flow[String]
|
|
64
|
+ .filterNot((rows: String)=>{
|
|
65
|
+ rows.contains(personID)
|
|
66
|
+ })
|
|
67
|
+ .map((row: String)=>{
|
|
68
|
+ convertToPerson(row.split(separator))
|
|
69
|
+ })
|
|
70
|
+
|
|
71
|
+ personFlow
|
|
72
|
+ }
|
49
|
73
|
def buildfilterByMoviePrimaryTitleFlow(moviePrimaryTitle: String): Flow[String, TvSeries, NotUsed] = {
|
50
|
74
|
val filterFlow: Flow[String, TvSeries, NotUsed] =
|
51
|
75
|
Flow[String]
|
|
@@ -54,7 +78,7 @@ object AkkaStreamComponents {
|
54
|
78
|
})
|
55
|
79
|
.map(row => {
|
56
|
80
|
val movie: Array[String] = row.split("\t")
|
57
|
|
- convertToClassMovie(movie)
|
|
81
|
+ convertToTvSerie(movie)
|
58
|
82
|
})
|
59
|
83
|
|
60
|
84
|
filterFlow
|
|
@@ -93,12 +117,21 @@ object AkkaStreamComponents {
|
93
|
117
|
}
|
94
|
118
|
|
95
|
119
|
//sink
|
96
|
|
- def buildSink(logger: Logger): Sink[TvSeries, Future[Done]] = {
|
97
|
|
- val sink = Sink.foreach[TvSeries](
|
|
120
|
+ def buildTvSeriesSink(logger: Logger): Sink[TvSeries, Future[Done]] = {
|
|
121
|
+ val tvSeriesSink : Sink[TvSeries, Future[Done]]= Sink.foreach[TvSeries](
|
98
|
122
|
(movie: TvSeries) => {
|
99
|
123
|
logger.info(s"${movie.toString}")
|
100
|
124
|
}
|
101
|
125
|
)
|
102
|
|
- sink
|
|
126
|
+ tvSeriesSink
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ def buildPersonSink(logger: Logger): Sink[Person, Future[Done]] ={
|
|
130
|
+ val personSink :Sink[Person, Future[Done]] = Sink
|
|
131
|
+ .foreach[Person]((person: Person)=>{
|
|
132
|
+ logger.info(s"${person.toString}")
|
|
133
|
+ })
|
|
134
|
+
|
|
135
|
+ personSink
|
103
|
136
|
}
|
104
|
137
|
}
|