placidenduwayo 1 рік тому
джерело
коміт
e918d47606

+ 1
- 1
pom.xml Переглянути файл

@@ -65,7 +65,7 @@
65 65
             <artifactId>scala-logging-slf4j_2.11</artifactId>
66 66
             <version>2.1.2</version>
67 67
         </dependency>
68
-
68
+        
69 69
     </dependencies>
70 70
 
71 71
     <build>

+ 2
- 2
src/main/java/fr/natan/akkastreamfileprocessingapi/controller/MovieController.java Переглянути файл

@@ -20,12 +20,12 @@ public class MovieController {
20 20
     @RequestMapping(value = "/movies", method = RequestMethod.GET)
21 21
     private ResponseEntity<String> getAllMovies() {
22 22
         akkaStreamFilesProcessing.getAllMovies();
23
-        return new ResponseEntity<>("IS RUNNING", HttpStatus.OK);
23
+        return new ResponseEntity<>("is running", HttpStatus.OK);
24 24
     }
25 25
 
26 26
     @RequestMapping(value = "/movies/{movieTitle}", method = RequestMethod.GET)
27 27
     private ResponseEntity<String> getMovieByTitle(@PathVariable(name ="movieTitle" ) String movieTitle){
28 28
         akkaStreamFilesProcessing.getMoviesByTitle(movieTitle);
29
-        return new ResponseEntity<>("IS RUNNING", HttpStatus.OK);
29
+        return new ResponseEntity<>("is running", HttpStatus.OK);
30 30
     }
31 31
 }

+ 9
- 0
src/main/scala/fr/natan/akkastreamfileprocessingapi/models/Person.scala Переглянути файл

@@ -0,0 +1,9 @@
1
+package fr.natan.akkastreamfileprocessingapi.models
2
+
3
+final case class Person(nconst: String,
4
+                  primaryName: String,
5
+                  birthYear: String,
6
+                  dearthYear: String,
7
+                  primaryProfession: String,
8
+                  knownForTitles: List[String]
9
+                 )

+ 1
- 1
src/main/scala/fr/natan/akkastreamfileprocessingapi/models/TvSeries.scala Переглянути файл

@@ -1,6 +1,6 @@
1 1
 package fr.natan.akkastreamfileprocessingapi.models
2 2
 
3
-case class TvSeries(
3
+final case class TvSeries(
4 4
                      tconst: String,
5 5
                      titleType: String,
6 6
                      primaryTitle: String,

+ 16
- 6
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamComponents.scala Переглянути файл

@@ -19,8 +19,18 @@ object AkkaStreamComponents {
19 19
   implicit val actor: ActorSystem = ActorSystem("AkkaStreamActor")
20 20
 
21 21
   private def convertToClassMovie(array: Array[String]): TvSeries = {
22
-    val movie: TvSeries = TvSeries(array(0), array(1), array(2), array(3), array(4), array(5), array(6), array(7), array(8))
23
-    movie
22
+    val tvSerie: TvSeries = TvSeries(
23
+      array(0),
24
+      array(1),
25
+      array(2),
26
+      array(3),
27
+      array(4),
28
+      array(5),
29
+      array(6),
30
+      array(7),
31
+      array(8))
32
+
33
+    tvSerie
24 34
   }
25 35
 
26 36
   //flows
@@ -34,10 +44,9 @@ object AkkaStreamComponents {
34 44
           convertToClassMovie(movie)
35 45
         })
36 46
     flow
37
-
38 47
   }
39 48
 
40
-  def filterByMoviePrimaryTitleFlow(moviePrimaryTitle: String): Flow[String, TvSeries, NotUsed] = {
49
+  def buildfilterByMoviePrimaryTitleFlow(moviePrimaryTitle: String): Flow[String, TvSeries, NotUsed] = {
41 50
     val filterFlow: Flow[String, TvSeries, NotUsed] =
42 51
       Flow[String]
43 52
         .filter((rows: String) => {
@@ -80,14 +89,15 @@ object AkkaStreamComponents {
80 89
     if (source == null) {
81 90
       throw new FileNotFoundException(filename = inputFile.getPath)
82 91
     }
83
-
84 92
     source
85 93
   }
86 94
 
87 95
   //sink
88 96
   def buildSink(logger: Logger): Sink[TvSeries, Future[Done]] = {
89 97
     val sink = Sink.foreach[TvSeries](
90
-      (movie: TvSeries) => logger.info(s"${movie.toString}")
98
+      (movie: TvSeries) => {
99
+        logger.info(s"${movie.toString}")
100
+      }
91 101
     )
92 102
     sink
93 103
   }

+ 11
- 9
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingImpl.scala Переглянути файл

@@ -6,7 +6,7 @@ import akka.{Done, NotUsed}
6 6
 import com.typesafe.scalalogging.slf4j.Logger
7 7
 import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.titleBasics
8 8
 import fr.natan.akkastreamfileprocessingapi.models.TvSeries
9
-import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAndValidateSource, buildMovieFlow, buildSink, filterByMoviePrimaryTitleFlow}
9
+import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAndValidateSource, buildMovieFlow, buildSink, buildfilterByMoviePrimaryTitleFlow}
10 10
 import org.slf4j.LoggerFactory
11 11
 import org.springframework.stereotype.Component
12 12
 
@@ -20,7 +20,7 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
20 20
   implicit val actorSystem: ActorSystem = ActorSystem("AkkaStreamActor")
21 21
   implicit val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
22 22
 
23
-  override def getAllMovies() = {
23
+  override def getAllMovies(): Unit = {
24 24
 
25 25
     val source: Source[String, NotUsed] = buildAndValidateSource(inputFile = titleBasics)
26 26
     val sink: Sink[TvSeries, Future[Done]] = buildSink(logger = logger)
@@ -28,6 +28,7 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
28 28
 
29 29
     val startingTime: Long = System.currentTimeMillis()
30 30
 
31
+    //graph sink->flow->sink
31 32
     source
32 33
       .via(flow = buildMovieFlow(movieID = "tconst"))
33 34
       .runWith(sink = sink)
@@ -46,17 +47,18 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
46 47
     val sink: Sink[TvSeries, Future[Done]] = buildSink(logger = logger)
47 48
 
48 49
     val filterByMovieTitleFlow: Flow[String, TvSeries, NotUsed] =
49
-      filterByMoviePrimaryTitleFlow(moviePrimaryTitle = moviePrimaryTitle)
50
+      buildfilterByMoviePrimaryTitleFlow(moviePrimaryTitle = moviePrimaryTitle)
50 51
 
51 52
     val startTime: Long = System.currentTimeMillis()
52
-    source.via(flow = filterByMovieTitleFlow).runWith(sink = sink).andThen {
53
+    val listTvSeries: Future[Done]= source.via(flow = filterByMovieTitleFlow)
54
+      .runWith(sink = sink)
55
+    .andThen {
53 56
       case Success(value) =>
54 57
         val elapsedTime: Long = (System.currentTimeMillis() - startTime) / 1000
55
-        logger.info(s"$value : successfully processing file, elapsed time $elapsedTime sec")
56
-
57
-      case Failure(err: Error) => logger.error(s"$err")
58
+        logger.info(s"$value: successfully processing file, elapsed time $titleBasics: $elapsedTime sec")
59
+      case Failure(error: Error) => logger.error(s"$error")
58 60
     }
59
-
60 61
   }
61
-
62 62
 }
63
+
64
+

Powered by TurnKey Linux.