placidenduwayo 2 роки тому
джерело
коміт
b9afd85bba

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

@@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
8 8
 import org.springframework.web.bind.annotation.RequestMethod;
9 9
 import org.springframework.web.bind.annotation.RestController;
10 10
 
11
+import java.util.Collection;
12
+import java.util.List;
13
+
11 14
 @RestController
12 15
 public class MovieController {
13 16
 
@@ -47,4 +50,10 @@ public class MovieController {
47 50
         akkaStreamFilesProcessing.getByTvSeriePrimaryTitle(movieTitle);
48 51
         return new ResponseEntity<>("is running", HttpStatus.OK);
49 52
     }
53
+
54
+    @RequestMapping(value = "/movies/id/{tvSerieID}", method = RequestMethod.GET)
55
+    private ResponseEntity<String> getListOfPersonsIDByTvSerieID(@PathVariable(name = "tvSerieID") String tvSerieID){
56
+       akkaStreamFilesProcessing.getListOfPersonsIDByTvSerieID(tvSerieID);
57
+       return new ResponseEntity<>("is running", HttpStatus.OK);
58
+    }
50 59
 }

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

@@ -6,6 +6,6 @@ object Datasource {
6 6
 
7 7
   val titleBasics: File = new File("../title.basics.tsv.gz")
8 8
   val nameBasics: File = new File("../name.basics.tsv.gz")
9
-  val titlePrincipalsBasics: File = new File("../title.basics.tsv.gz")
9
+  val titlePrincipalsBasics: File = new File("../title.principals.tsv.gz")
10 10
   val separator: String = "\t"
11 11
 }

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

@@ -12,6 +12,7 @@ import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.{buildPersonMod
12 12
 
13 13
 import java.io.File
14 14
 import java.nio.file.Paths
15
+import java.util
15 16
 import scala.concurrent.Future
16 17
 
17 18
 object AkkaStreamComponents {
@@ -102,7 +103,7 @@ object AkkaStreamComponents {
102 103
       }
103 104
       )
104 105
       .via(Compression.gunzip())
105
-      .via(CsvParsing.lineScanner(CsvParsing.Tab, CsvParsing.DoubleQuote))
106
+      .via(CsvParsing.lineScanner(CsvParsing.Tab, CsvParsing.DoubleQuote, CsvParsing.DoubleQuote))
106 107
       .via(CsvToMap.toMapAsStrings())
107 108
 
108 109
     datasource

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

@@ -11,4 +11,6 @@ trait AkkaStreamFileProcessing {
11 11
   def getAllTvSeries(): Unit
12 12
 
13 13
   def getByTvSeriePrimaryTitle(tvSerieTitle: String): Unit
14
+
15
+  def getListOfPersonsIDByTvSerieID(tconst: String): List[Option[String]]
14 16
 }

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

@@ -1,10 +1,12 @@
1 1
 package fr.natan.akkastreamfileprocessingapi.service
2 2
 
3 3
 import akka.actor.ActorSystem
4
+import akka.stream.ActorAttributes.supervisionStrategy
5
+import akka.stream.Supervision.resumingDecider
4 6
 import akka.stream.scaladsl.{Flow, Sink, Source}
5 7
 import akka.{Done, NotUsed}
6 8
 import com.typesafe.scalalogging.slf4j.Logger
7
-import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics}
9
+import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
8 10
 import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSeries}
9 11
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildTvSerieModel
10 12
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{buildAllPersonsSink, buildAndValidateSource, buildPersonFlow, buildPersonSink, buildSource, buildTvSerieFlow, buildTvSeriesSink, filterByPersonIdFlow, filterByPersonNameFlow, filterByTvSeriePrimaryTitleFlow}
@@ -14,7 +16,9 @@ import org.springframework.stereotype.Component
14 16
 import scala.concurrent.ExecutionContext.Implicits.global
15 17
 import scala.concurrent.duration.DurationInt
16 18
 import scala.concurrent.{Await, Future}
19
+import scala.language.postfixOps
17 20
 import scala.util.{Failure, Success}
21
+import scala.collection.immutable.Iterable
18 22
 
19 23
 @Component
20 24
 class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
@@ -49,7 +53,8 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
49 53
      .andThen {
50 54
         case Success(value) =>
51 55
           val elapsedTime: Long = (System.currentTimeMillis()-startTime)/1000
52
-          logger.info(s"$value: Successfully processed, elapsed time: $elapsedTime")
56
+          logger.info(s"$value")
57
+          logger.info(s"Successfully processed, elapsed time: $elapsedTime")
53 58
         case Failure(exception) => logger.error(s"$exception: Fail")
54 59
       }
55 60
 
@@ -111,27 +116,59 @@ class AkkaStreamFileProcessingImpl extends AkkaStreamFileProcessing {
111 116
       }
112 117
 
113 118
     getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
119
+
114 120
   }
115 121
 
116
-  private def getTvSerieIdByPrimaryTitle(primaryTitle: String): String ={
117
-    val source: Source[Map[String, String],_]= buildSource(inputFile = titleBasics)
122
+  private def getTvSerieIdByPrimaryTitle(primaryTitle: String): String = {
123
+    val source: Source[Map[String, String], _] = buildSource(inputFile = titleBasics)
118 124
 
119
-    var tvSerie: TvSeries =null
120
-    val res : Future[Option[String]]= source
121
-      .filter((rowMap: Map[String, String]) =>{
122
-        rowMap.getOrElse(key = "primaryTitle","")==primaryTitle
125
+    var tvSerie: TvSeries = null
126
+    val res: Future[Option[String]] = source
127
+      .filter((rowMap: Map[String, String]) => {
128
+        rowMap.getOrElse(key = "primaryTitle", "") == primaryTitle
123 129
       })
124
-      .map((rowMap: Map[String, String])=>{
130
+      .map((rowMap: Map[String, String]) => {
125 131
         tvSerie = buildTvSerieModel(rowMap)
126 132
         rowMap.get("tconst")
127 133
       })
128 134
       .runWith(Sink.head)
129 135
 
130
-   Await.result(res,1 minutes)
131
-    val tconst:String = res.value.get.get.get
136
+    Await.result(res, 1 minutes)
137
+    val tconst: String = res.value.get.get.get
138
+    logger.info(s"TvSerie ID: $tconst, $tvSerie")
132 139
     tconst
133 140
   }
134 141
 
142
+  def getListOfPersonsIDByTvSerieID(tconst: String): List[Option[String]]={
143
+    val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
144
+    var tvSeries: Iterable[TvSeries]=null
145
+
146
+    val startTime : Long = System.currentTimeMillis()
147
+    val res: Future[IndexedSeq[Option[String]]] = source
148
+      .filter((rowMaps: Map[String, String])=>{
149
+        rowMaps.getOrElse(key = "tconst", default = "")==tconst
150
+      })
151
+      .map((rowMap: Map[String, String])=>{
152
+        rowMap.get(key = "nconst")
153
+      })
154
+      .withAttributes(supervisionStrategy(resumingDecider))
155
+      .runWith(Sink.collection)
156
+      .andThen {
157
+        case Success(value) =>
158
+          logger.info(s"$value")
159
+          val elapsedTime : Long = (System.currentTimeMillis() - startTime)/1000
160
+          logger.info(s"success, elapsed time: $elapsedTime")
161
+
162
+        case Failure(error: Error) => logger.error(s"$error")
163
+      }
164
+
165
+    Await.result(res,5 minutes)
166
+    val listPersonsID: List[Option[String]] = res.value.get.get.toList
167
+
168
+    listPersonsID
169
+
170
+  }
171
+
135 172
 
136 173
 }
137 174
 

Powered by TurnKey Linux.