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

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

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

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

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

6
 import akka.{Done, NotUsed}
6
 import akka.{Done, NotUsed}
7
 import com.typesafe.scalalogging.slf4j.Logger
7
 import com.typesafe.scalalogging.slf4j.Logger
8
 import fr.natan.akkastreamfileprocessingapi.businessexceptions.FileNotFoundException
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
 import fr.natan.akkastreamfileprocessingapi.valitator.Validators.fileExists
10
 import fr.natan.akkastreamfileprocessingapi.valitator.Validators.fileExists
11
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.{buildPersonModel, buildTvSerieModel}
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
 package fr.natan.akkastreamfileprocessingapi.service
1
 package fr.natan.akkastreamfileprocessingapi.service
2
 
2
 
3
 import akka.Done
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
 import scala.concurrent.Future
6
 import scala.concurrent.Future
7
 
7
 

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

4
 import akka.stream.scaladsl.{Sink, Source}
4
 import akka.stream.scaladsl.{Sink, Source}
5
 import com.typesafe.scalalogging.slf4j.Logger
5
 import com.typesafe.scalalogging.slf4j.Logger
6
 import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics}
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
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
8
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{
9
   actorSystem, buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildSource,
9
   actorSystem, buildAllPersonsSink, buildAllTvSeriesSink, buildAndValidateSource, buildPersonFlow, buildSource,
10
   buildTvSerieFlow, filterPersonByIdFlow, filterPersonByNameFlow, filterTvSerieByIdFlow, filterTvSerieByPrimaryTitleFlow}
10
   buildTvSerieFlow, filterPersonByIdFlow, filterPersonByNameFlow, filterTvSerieByIdFlow, filterTvSerieByPrimaryTitleFlow}

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

2
 
2
 
3
 import akka.stream.scaladsl.{Sink, Source}
3
 import akka.stream.scaladsl.{Sink, Source}
4
 import fr.natan.akkastreamfileprocessingapi.datasource.Datasource.{nameBasics, titleBasics, titlePrincipalsBasics}
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
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
6
 import fr.natan.akkastreamfileprocessingapi.models.ModelsBuilder.buildPersonModel
7
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{actorSystem, buildSource}
7
 import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamComponents.{actorSystem, buildSource}
8
 
8
 

Powered by TurnKey Linux.