Browse Source

first commit

placidenduwayo 2 years ago
parent
commit
3a6b35d8b7

+ 25
- 27
src/main/java/fr/natan/akkastreamfileprocessingapi/controller/TvSeriesController.java View File

@@ -1,7 +1,7 @@
1 1
 package fr.natan.akkastreamfileprocessingapi.controller;
2 2
 
3 3
 import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureBuilder;
4
-import fr.natan.akkastreamfileprocessingapi.models.Models;
4
+import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap;
5 5
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessingFuture;
6 6
 import org.slf4j.Logger;
7 7
 import org.slf4j.LoggerFactory;
@@ -23,8 +23,6 @@ import java.util.Random;
23 23
 import java.util.concurrent.CompletableFuture;
24 24
 import java.util.concurrent.ExecutionException;
25 25
 
26
-import java.util.concurrent.TimeoutException;
27
-
28 26
 
29 27
 @SuppressWarnings("SpellCheckingInspection")
30 28
 @RestController
@@ -40,16 +38,16 @@ public class TvSeriesController {
40 38
 
41 39
     @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
42 40
     private String getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
43
-        Future<Option<Models.Person>> futurePerson = akkaStreamFilesProcessing.getPersonByIdFuture(personID);
44
-        CompletableFuture<Models.Person> completableFuture = CompletableFutureBuilder
41
+        Future<Option<ModelsAndJsonMap.Person>> futurePerson = akkaStreamFilesProcessing.getPersonByIdFuture(personID);
42
+        CompletableFuture<ModelsAndJsonMap.Person> completableFuture = CompletableFutureBuilder
45 43
                 .buildcompletableFuture1(futurePerson);
46 44
         while (!completableFuture.isDone()) {
47 45
             logger.info("IS PROCESSING...");
48 46
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
49 47
         }
50
-        Models.Person person = completableFuture.get();
48
+        ModelsAndJsonMap.Person person = completableFuture.get();
51 49
 
52
-        JsValue personJs = Json.toJson(person, person.personFormat());
50
+        JsValue personJs = Json.toJson(person, person.personJsonFormatter());
53 51
         return Json.prettyPrint(personJs);
54 52
     }
55 53
 
@@ -57,30 +55,30 @@ public class TvSeriesController {
57 55
     private String getPersonByName(@PathVariable(name = "primaryName") String primaryName)
58 56
             throws ExecutionException, InterruptedException {
59 57
 
60
-        Future<Option<Models.Person>> personFuture = akkaStreamFilesProcessing.getPersonByNameFuture(primaryName);
61
-        CompletableFuture<Models.Person> personCompletableFuture = CompletableFutureBuilder
58
+        Future<Option<ModelsAndJsonMap.Person>> personFuture = akkaStreamFilesProcessing.getPersonByNameFuture(primaryName);
59
+        CompletableFuture<ModelsAndJsonMap.Person> personCompletableFuture = CompletableFutureBuilder
62 60
                 .buildcompletableFuture1(personFuture);
63 61
         while (!personCompletableFuture.isDone()) {
64 62
             logger.info("IS PROCESSING...");
65 63
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
66 64
         }
67
-        Models.Person person = personCompletableFuture.get();
68
-        JsValue personJs = Json.toJson(person, person.personFormat());
65
+        ModelsAndJsonMap.Person person = personCompletableFuture.get();
66
+        JsValue personJs = Json.toJson(person, person.personJsonFormatter());
69 67
         return Json.prettyPrint(personJs);
70 68
     }
71 69
 
72 70
     @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
73 71
     private String getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
74 72
             throws ExecutionException, InterruptedException {
75
-        Future<Option<Models.TvSerie>> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieByIdFuture(tvSerieID);
76
-        CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = CompletableFutureBuilder
73
+        Future<Option<ModelsAndJsonMap.TvSerie>> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieByIdFuture(tvSerieID);
74
+        CompletableFuture<ModelsAndJsonMap.TvSerie> tvSerieCompletableFuture = CompletableFutureBuilder
77 75
                 .buildcompletableFuture1(tvSerieFuture);
78 76
         while (!tvSerieCompletableFuture.isDone()) {
79 77
             logger.info("IS PROCESSING...");
80 78
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
81 79
         }
82
-        Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
83
-        JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieFormat());
80
+        ModelsAndJsonMap.TvSerie tvSerie = tvSerieCompletableFuture.get();
81
+        JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
84 82
         return Json.prettyPrint(tvSerieJs);
85 83
     }
86 84
 
@@ -88,18 +86,18 @@ public class TvSeriesController {
88 86
     private List<String> getTvserieByPrimaryTitle(
89 87
             @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) throws InterruptedException, ExecutionException {
90 88
 
91
-        Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing
89
+        Future<IndexedSeq<ModelsAndJsonMap.TvSerie>> listFuture = akkaStreamFilesProcessing
92 90
                 .getTvSeriesByPrimaryTitleFuture(tvseriePrimaryTitle);
93
-        CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
91
+        CompletableFuture<IndexedSeq<ModelsAndJsonMap.TvSerie>> completableFuture =
94 92
                 CompletableFutureBuilder.buildcompletableFuture2(listFuture);
95 93
         while (!completableFuture.isDone()) {
96 94
             logger.info("IS PROCESSING...");
97 95
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
98 96
         }
99
-        IndexedSeq<Models.TvSerie> tvSerieList = completableFuture.get();
97
+        IndexedSeq<ModelsAndJsonMap.TvSerie> tvSerieList = completableFuture.get();
100 98
         List<String> tvSeries = new ArrayList<>();
101 99
         tvSerieList.foreach(tvSerie -> {
102
-            JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieFormat());
100
+            JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieJsonFormatter());
103 101
             tvSeries.add(Json.prettyPrint(tvSerieJs));
104 102
             return null;
105 103
         });
@@ -111,19 +109,19 @@ public class TvSeriesController {
111 109
     private List<String> getPersonsForTvSerieByTvSerieTitle(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
112 110
             throws InterruptedException, ExecutionException {
113 111
 
114
-        Future<IndexedSeq<Models.Person>> futurePersonSeq = akkaStreamFilesProcessing
112
+        Future<IndexedSeq<ModelsAndJsonMap.Person>> futurePersonSeq = akkaStreamFilesProcessing
115 113
                 .getPersonsForTvSerieByTvSerieTitleFuture(tvSerieTitle);
116
-        CompletableFuture<IndexedSeq<Models.Person>> completableFuture = CompletableFutureBuilder
114
+        CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> completableFuture = CompletableFutureBuilder
117 115
                 .buildcompletableFuture2(futurePersonSeq);
118 116
         while (!completableFuture.isDone()){
119 117
             logger.info("IS PROCESSING...");
120 118
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
121 119
         }
122 120
 
123
-        IndexedSeq<Models.Person> personIndexedSeq = completableFuture.get();
121
+        IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = completableFuture.get();
124 122
         List<String> personList = new ArrayList<>();
125 123
         personIndexedSeq.foreach(person -> {
126
-            JsValue personJs = Json.toJson(person, person.personFormat());
124
+            JsValue personJs = Json.toJson(person, person.personJsonFormatter());
127 125
             personList.add(Json.prettyPrint(personJs));
128 126
             return null;
129 127
         });
@@ -135,19 +133,19 @@ public class TvSeriesController {
135 133
     private List<String> getPersonsForTvSerieByTvSerieID(@PathVariable(name = "tvSerieID") String tvSerieID)
136 134
             throws InterruptedException, ExecutionException {
137 135
 
138
-        Future<IndexedSeq<Models.Person>> futureIndexedSeqPersons = akkaStreamFilesProcessing
136
+        Future<IndexedSeq<ModelsAndJsonMap.Person>> futureIndexedSeqPersons = akkaStreamFilesProcessing
139 137
                 .getPersonsForTvSerieByTvSerieIDFuture(tvSerieID);
140
-        CompletableFuture<IndexedSeq<Models.Person>> seqCompletableFuture = CompletableFutureBuilder
138
+        CompletableFuture<IndexedSeq<ModelsAndJsonMap.Person>> seqCompletableFuture = CompletableFutureBuilder
141 139
                 .buildcompletableFuture2(futureIndexedSeqPersons);
142 140
 
143 141
         while (!seqCompletableFuture.isDone()){
144 142
             logger.info("IS PROCESSING...");
145 143
             Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
146 144
         }
147
-        IndexedSeq<Models.Person> personIndexedSeq = seqCompletableFuture.get();
145
+        IndexedSeq<ModelsAndJsonMap.Person> personIndexedSeq = seqCompletableFuture.get();
148 146
         List<String> personsList = new ArrayList<>();
149 147
         personIndexedSeq.foreach(person ->{
150
-            JsValue personJs = Json.toJson(person, person.personFormat());
148
+            JsValue personJs = Json.toJson(person, person.personJsonFormatter());
151 149
             personsList.add(Json.prettyPrint(personJs));
152 150
             return null;
153 151
         });

+ 0
- 54
src/main/scala/fr/natan/akkastreamfileprocessingapi/models/Models.scala View File

@@ -1,54 +0,0 @@
1
-package fr.natan.akkastreamfileprocessingapi.models
2
-
3
-import play.api.libs.json.{JsValue, Json, Writes}
4
-
5
-object Models {
6
-
7
-  //noinspection TypeAnnotation
8
-  final case class Person(
9
-                           personID: String,
10
-                           primaryName: String,
11
-                           birthYear: String,
12
-                           deathYear: String,
13
-                           primaryProfession: List[String],
14
-                           knownForTitles: List[String]
15
-                         ) {
16
-
17
-    implicit val personFormat = new Writes[Person] {
18
-      override def writes(person: Person): JsValue = Json.obj(
19
-        "person id" -> person.personID,
20
-        "primary name" -> person.primaryName,
21
-        "birth year" -> person.birthYear,
22
-        "death year" -> person.deathYear,
23
-        "primary profession" -> person.primaryProfession,
24
-        "known for titles" -> person.knownForTitles
25
-      )
26
-    }
27
-  }
28
-
29
-  //noinspection TypeAnnotation
30
-  final case class TvSerie(
31
-                            tvSerieID: String,
32
-                            titleType: String,
33
-                            primaryTitle: String,
34
-                            originalTitle: String,
35
-                            startYear: String,
36
-                            endYear: String,
37
-                            runtimeMinutes: String,
38
-                            genres: List[String]
39
-                          ) {
40
-
41
-    implicit val tvSerieFormat = new Writes[TvSerie] {
42
-      override def writes(tvSerie: TvSerie): JsValue = Json.obj(
43
-        "tv serie id" -> tvSerie.tvSerieID,
44
-        "tv serie type" -> tvSerie.titleType,
45
-        "primary title" -> tvSerie.primaryTitle,
46
-        "original title" -> tvSerie.originalTitle,
47
-        "start year" -> tvSerie.startYear,
48
-        "end year" -> tvSerie.endYear,
49
-        "runtime minutes" -> tvSerie.runtimeMinutes,
50
-        "genres" -> tvSerie.genres
51
-      )
52
-    }
53
-  }
54
-}

+ 49
- 0
src/main/scala/fr/natan/akkastreamfileprocessingapi/models/ModelsAndJsonMap.scala View File

@@ -0,0 +1,49 @@
1
+package fr.natan.akkastreamfileprocessingapi.models
2
+
3
+import play.api.libs.json.{Json, Writes}
4
+
5
+object ModelsAndJsonMap {
6
+
7
+  final case class Person(personID: String,
8
+                          primaryName: String,
9
+                          birthYear: String,
10
+                          deathYear: String,
11
+                          primaryProfession: List[String],
12
+                          knownForTitles: List[String]
13
+                         ) {
14
+
15
+    implicit val personJsonFormatter: Writes[Person] =
16
+      (person: Person) => Json.obj(
17
+        "person id" -> person.personID,
18
+        "primary name" -> person.primaryName,
19
+        "birth year" -> person.birthYear,
20
+        "death year" -> person.deathYear,
21
+        "primary profession" -> person.primaryProfession,
22
+        "known for titles" -> person.knownForTitles
23
+      )
24
+  }
25
+
26
+  final case class TvSerie(tvSerieID: String,
27
+                           titleType: String,
28
+                           primaryTitle: String,
29
+                           originalTitle: String,
30
+                           startYear: String,
31
+                           endYear: String,
32
+                           runtimeMinutes: String,
33
+                           genres: List[String]
34
+                          ) {
35
+
36
+    implicit val tvSerieJsonFormatter: Writes[TvSerie] =
37
+      (tvSerie: TvSerie) => Json.obj(
38
+        "tv serie id" -> tvSerie.tvSerieID,
39
+        "tv serie type" -> tvSerie.titleType,
40
+        "primary title" -> tvSerie.primaryTitle,
41
+        "original title" -> tvSerie.originalTitle,
42
+        "start year" -> tvSerie.startYear,
43
+        "end year" -> tvSerie.endYear,
44
+        "runtime minutes" -> tvSerie.runtimeMinutes,
45
+        "genres" -> tvSerie.genres
46
+      )
47
+
48
+  }
49
+}

+ 5
- 3
src/main/scala/fr/natan/akkastreamfileprocessingapi/models/ModelsBuilder.scala View File

@@ -1,8 +1,9 @@
1 1
 package fr.natan.akkastreamfileprocessingapi.models
2
-import Models.{Person, TvSerie}
2
+import ModelsAndJsonMap.{Person, TvSerie}
3 3
 object ModelsBuilder {
4 4
 
5
-  def buildPersonModel(personMap: Map[String, String]): Person = {
5
+  def buildPersonModel(personMap: Map[String, String]): Person =
6
+  {
6 7
     Person(
7 8
       personMap("nconst"),
8 9
       personMap("primaryName"),
@@ -13,7 +14,8 @@ object ModelsBuilder {
13 14
     )
14 15
   }
15 16
 
16
-  def buildTvSerieModel(tvSerieMap: Map[String, String]): TvSerie = {
17
+  def buildTvSerieModel(tvSerieMap: Map[String, String]): TvSerie =
18
+  {
17 19
     val tvSerie: TvSerie = TvSerie(
18 20
       tvSerieMap("tconst"),
19 21
       tvSerieMap("titleType"),

+ 1
- 1
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamComponents.scala View File

@@ -6,7 +6,7 @@ import akka.stream.scaladsl.{Compression, FileIO, Flow, Sink, Source}
6 6
 import akka.{Done, NotUsed}
7 7
 import com.typesafe.scalalogging.slf4j.Logger
8 8
 import fr.natan.akkastreamfileprocessingapi.businessexceptions.FileNotFoundException
9
-import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
9
+import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap.{Person, TvSerie}
10 10
 import fr.natan.akkastreamfileprocessingapi.valitator.Validators.fileExists
11 11
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.{buildPersonModel, buildTvSerieModel}
12 12
 

+ 1
- 1
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/AkkaStreamFileProcessingFuture.scala View File

@@ -1,7 +1,7 @@
1 1
 package fr.natan.akkastreamfileprocessingapi.service
2 2
 
3 3
 import akka.Done
4
-import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
4
+import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap.{Person, TvSerie}
5 5
 
6 6
 import scala.concurrent.Future
7 7
 

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

@@ -4,7 +4,7 @@ import akka.Done
4 4
 import akka.stream.scaladsl.{Sink, Source}
5 5
 import com.typesafe.scalalogging.slf4j.Logger
6 6
 import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics}
7
-import fr.natan.akkastreamfileprocessingapi.models.Models.{Person, TvSerie}
7
+import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap.{Person, TvSerie}
8 8
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
9 9
   actorSystem, buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildSource,
10 10
   buildTvSerieFlow, filterPersonByIdFlow, filterPersonByNameFlow, filterTvSerieByIdFlow, filterTvSerieByPrimaryTitleFlow}

+ 1
- 1
src/main/scala/fr/natan/akkastreamfileprocessingapi/service/UtilitiesClass.scala View File

@@ -2,7 +2,7 @@ package fr.natan.akkastreamfileprocessingapi.service
2 2
 
3 3
 import akka.stream.scaladsl.{Sink, Source}
4 4
 import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
5
-import fr.natan.akkastreamfileprocessingapi.models.Models.Person
5
+import fr.natan.akkastreamfileprocessingapi.models.ModelsAndJsonMap.Person
6 6
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
7 7
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{actorSystem, buildSource}
8 8
 

Powered by TurnKey Linux.