Browse Source

first commit

placidenduwayo 1 year ago
parent
commit
9cb72270fe

+ 1
- 1
src/main/java/fr/natan/akkastreamfileprocessingapi/controller/MovieController.java View File

50
     }
50
     }
51
 
51
 
52
     @RequestMapping(value = "/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
52
     @RequestMapping(value = "/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
53
-    private ResponseEntity<String> getListOfPersonsByTvSerieitle(@PathVariable(name = "tvSerieTitle") String tvSerieTitle){
53
+    private ResponseEntity<String> getListOfPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle){
54
       akkaStreamFilesProcessing.getPersonsTeamForTvSerie(tvSerieTitle);
54
       akkaStreamFilesProcessing.getPersonsTeamForTvSerie(tvSerieTitle);
55
        return new ResponseEntity<>("is running", HttpStatus.OK);
55
        return new ResponseEntity<>("is running", HttpStatus.OK);
56
     }
56
     }

+ 3
- 7
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessing.scala View File

6
 
6
 
7
 //noinspection SpellCheckingInspection
7
 //noinspection SpellCheckingInspection
8
 trait AkkaStreamFileProcessing {
8
 trait AkkaStreamFileProcessing {
9
-  def getAllPersons(): Unit
10
-
11
   def getPersonById(nconst: String): Future[Person]
9
   def getPersonById(nconst: String): Future[Person]
12
   def getPersonByName(primaryName: String): Future[IndexedSeq[Person]]
10
   def getPersonByName(primaryName: String): Future[IndexedSeq[Person]]
13
 
11
 
14
-  def getAllTvSeries(): Unit
15
-
16
   def getByTvSeriePrimaryTitle(tvSerieTitle: String):Future[Seq[TvSeries]]
12
   def getByTvSeriePrimaryTitle(tvSerieTitle: String):Future[Seq[TvSeries]]
17
 
13
 
18
-  def getPersonsTeamForTvSerie(tvSeriePrimaryTitle: String)
19
-
20
-
14
+  def getPersonsTeamForTvSerie(tvSeriePrimaryTitle: String): Future[List[Person]]
15
+  def getAllTvSeries(): Unit
16
+  def getAllPersons(): Unit
21
 }
17
 }

+ 19
- 27
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingImpl.scala View File

44
 
44
 
45
   override def getPersonById(nconst: String): Future[Person] = {
45
   override def getPersonById(nconst: String): Future[Person] = {
46
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
46
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
47
-
48
-
49
     val res = source
47
     val res = source
50
       .via(flow = filterByPersonIdFlow(nconst = nconst))
48
       .via(flow = filterByPersonIdFlow(nconst = nconst))
51
       .runWith(Sink.head)
49
       .runWith(Sink.head)
102
       case Failure(exception) => logger.info(s"$exception")
100
       case Failure(exception) => logger.info(s"$exception")
103
       case Success(value) => logger.info(s"$value")
101
       case Success(value) => logger.info(s"$value")
104
     }
102
     }
105
-
106
   }
103
   }
107
 
104
 
108
   private def getTvSerieIdByPrimaryTitle(primaryTitle: String): Future[Option[String]] = {
105
   private def getTvSerieIdByPrimaryTitle(primaryTitle: String): Future[Option[String]] = {
112
       .filter((rowMap: Map[String, String]) => {
109
       .filter((rowMap: Map[String, String]) => {
113
         rowMap.getOrElse(key = "primaryTitle", "") == primaryTitle
110
         rowMap.getOrElse(key = "primaryTitle", "") == primaryTitle
114
       })
111
       })
115
-      .map((rowMap: Map[String, String]) => {
116
-        rowMap.get("tconst")
117
-      })
112
+      .map((rowMap: Map[String, String]) => rowMap.get("tconst"))
118
       .runWith(Sink.head)
113
       .runWith(Sink.head)
119
 
114
 
120
     res
115
     res
121
-
122
   }
116
   }
123
 
117
 
124
-  private def getListOfPersonsIDByTvSerieID(tvSerieID: Future[Option[String]]): Future[IndexedSeq[Option[String]]]={
118
+  private def getListOfPersonsIDByTvSerieID(tvSerieID: Future[Option[String]]): Future[List[Option[String]]]={
125
     val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
119
     val source: Source[Map[String, String], _] = buildSource(inputFile = titlePrincipalsBasics)
126
 
120
 
127
-    val res: Future[IndexedSeq[Option[String]]] = source
121
+    val res: Future[List[Option[String]]] = source
128
       .filter((rowMaps: Map[String, String])=>{
122
       .filter((rowMaps: Map[String, String])=>{
129
         rowMaps.getOrElse(key = "tconst", default = "")==tvSerieID.value.get.get.get
123
         rowMaps.getOrElse(key = "tconst", default = "")==tvSerieID.value.get.get.get
130
       })
124
       })
132
         rowMap.get(key = "nconst")
126
         rowMap.get(key = "nconst")
133
       })
127
       })
134
       .runWith(Sink.collection)
128
       .runWith(Sink.collection)
135
-
136
     res
129
     res
137
-
138
   }
130
   }
139
 
131
 
140
-  private def getListOfPersonsForTvSerie(listPersonsIDs: Future[IndexedSeq[Option[String]]]): Future[IndexedSeq[Person]] = {
132
+  private def getListOfPersonsForTvSerie(listPersonsIDs: Future[List[Option[String]]]): Future[List[Person]] = {
141
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
133
     val source: Source[Map[String, String], _] = buildSource(inputFile = nameBasics)
142
 
134
 
143
-    val res : Future[IndexedSeq[Person]]=
135
+    val res : Future[List[Person]]=
144
       source
136
       source
145
         .filter((rowMaps: Map[String, String])=>{
137
         .filter((rowMaps: Map[String, String])=>{
146
           listPersonsIDs.value.get.get.contains(rowMaps.get(key = "nconst"))
138
           listPersonsIDs.value.get.get.contains(rowMaps.get(key = "nconst"))
152
 
144
 
153
     res
145
     res
154
   }
146
   }
155
-  override def getPersonsTeamForTvSerie(tvSeriePrimaryTitle: String):Unit={
147
+  override def getPersonsTeamForTvSerie(tvSeriePrimaryTitle: String):Future[List[Person]]={
156
 
148
 
157
     logger.info("STEP 1/3")
149
     logger.info("STEP 1/3")
158
     val tvSerieID = getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
150
     val tvSerieID = getTvSerieIdByPrimaryTitle(primaryTitle = tvSeriePrimaryTitle)
159
-    tvSerieID.onComplete({
160
-      case Failure(exception) => logger.error(s"$exception")
151
+    tvSerieID.andThen({
152
+      case Failure(exception) => logger.error(s"!!!!!!!!!!!!!!!!!!!!1$exception")
161
       case Success(value: Option[String]) =>
153
       case Success(value: Option[String]) =>
162
         logger.info(s"TvSerie ID: $value")
154
         logger.info(s"TvSerie ID: $value")
163
         logger.info("END STEP 1/3")
155
         logger.info("END STEP 1/3")
164
     })
156
     })
165
     logger.info("STEP 2/3")
157
     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"))
158
+    val listPersonIDs: Future[List[Option[String]]] = getListOfPersonsIDByTvSerieID(tvSerieID = tvSerieID)
159
+    listPersonIDs.andThen({
160
+      case Failure(exception) => logger.error(s"!!!!!!!!!!!!!!!!!!!!!2$exception")
161
+      case Success(value: List[Option[String]]) =>
162
+        value.foreach((personID:Option[String])=>logger.info(s"Person ID:$personID"))
171
         logger.info("END STEP 2/3")
163
         logger.info("END STEP 2/3")
172
     })
164
     })
173
 
165
 
174
     logger.info("STEP 3/3")
166
     logger.info("STEP 3/3")
175
-    val personsTeam= getListOfPersonsForTvSerie(listPersonsIDs = listPersonIDs)
176
-    personsTeam.onComplete({
177
-      case Failure(exception) => logger.error(s"$exception")
167
+    val personsTeam: Future[List[Person]] = getListOfPersonsForTvSerie(listPersonsIDs = listPersonIDs)
168
+    personsTeam.andThen({
169
+      case Failure(exception) => logger.error(s"!!!!!!!!!!!!!!!!!!!!!!!3$exception")
178
       case Success(value) =>
170
       case Success(value) =>
179
-        logger.info(s"${value.toList}")
180
-        value.toList.foreach((person:Person)=>logger.info(s"${person.toString}"))
171
+        logger.info(s"$value")
172
+        value.foreach((person:Person)=>logger.info(s"${person.toString}"))
181
         logger.info("END STEP 3/3")
173
         logger.info("END STEP 3/3")
182
     })
174
     })
183
 
175
 
176
+   null
184
   }
177
   }
185
-
186
 }
178
 }
187
 
179
 
188
 
180
 

Powered by TurnKey Linux.