|
@@ -3,16 +3,16 @@ package fr.natan.akkastreamfileprocessingapi.controller;
|
3
|
3
|
import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureResult;
|
4
|
4
|
import fr.natan.akkastreamfileprocessingapi.models.Models;
|
5
|
5
|
import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessing;
|
|
6
|
+import org.slf4j.Logger;
|
|
7
|
+import org.slf4j.LoggerFactory;
|
6
|
8
|
import org.springframework.http.HttpStatus;
|
7
|
9
|
import org.springframework.http.ResponseEntity;
|
8
|
10
|
import org.springframework.web.bind.annotation.PathVariable;
|
9
|
11
|
import org.springframework.web.bind.annotation.RequestMapping;
|
10
|
12
|
import org.springframework.web.bind.annotation.RequestMethod;
|
11
|
13
|
import org.springframework.web.bind.annotation.RestController;
|
12
|
|
-import play.api.libs.json.JsValue;
|
13
|
14
|
import play.api.libs.json.Json;
|
14
|
15
|
import scala.collection.IndexedSeq;
|
15
|
|
-import scala.collection.immutable.List;
|
16
|
16
|
import scala.concurrent.Future;
|
17
|
17
|
|
18
|
18
|
import java.util.concurrent.CompletableFuture;
|
|
@@ -24,19 +24,22 @@ import java.util.concurrent.ExecutionException;
|
24
|
24
|
public class MovieController {
|
25
|
25
|
|
26
|
26
|
private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
|
27
|
|
- private final CompletableFutureResult completableFutureResult;
|
|
27
|
+ private final CompletableFutureResult completableFutureResult = new CompletableFutureResult();
|
|
28
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
28
|
29
|
public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
|
29
|
30
|
this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
|
30
|
|
- completableFutureResult = new CompletableFutureResult();
|
31
|
31
|
}
|
32
|
32
|
|
33
|
33
|
@RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
|
34
|
34
|
private ResponseEntity<String> getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
|
35
|
|
- Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonById(personID);
|
36
|
|
- CompletableFuture<Models.Person> personCompletableFuture = this.completableFutureResult.buildcompletableFuture(personFuture);
|
37
|
|
- Models.Person person = personCompletableFuture.get();
|
38
|
|
- JsValue personJs = Json.toJson(person, person.personFormat());
|
39
|
|
- return new ResponseEntity<>(personJs.toString(), HttpStatus.OK);
|
|
35
|
+ Future<Models.Person> futurePerson = akkaStreamFilesProcessing.getPersonById(personID);
|
|
36
|
+ CompletableFuture<Models.Person> completableFuture = completableFutureResult.buildcompletableFuture(futurePerson);
|
|
37
|
+ while (!completableFuture.isDone()){
|
|
38
|
+ logger.info("IS PROCESSING...");
|
|
39
|
+ Thread.sleep(5000);
|
|
40
|
+ }
|
|
41
|
+ Models.Person person = completableFuture.get();
|
|
42
|
+ return new ResponseEntity<>(Json.toJson(person, person.personFormat()).toString(), HttpStatus.OK);
|
40
|
43
|
}
|
41
|
44
|
|
42
|
45
|
@RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
|
|
@@ -44,27 +47,35 @@ public class MovieController {
|
44
|
47
|
throws ExecutionException, InterruptedException {
|
45
|
48
|
|
46
|
49
|
Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
|
47
|
|
- CompletableFuture completableFutureResult = this.completableFutureResult.buildcompletableFuture(personFuture);
|
48
|
|
- Models.Person person = (Models.Person) completableFutureResult.get();
|
49
|
|
- JsValue personJs = Json.toJson(person, person.personFormat());
|
50
|
|
- return new ResponseEntity<>(personJs.toString(), HttpStatus.OK);
|
|
50
|
+ CompletableFuture<Models.Person> personCompletableFuture = completableFutureResult.buildcompletableFuture(personFuture);
|
|
51
|
+ while (!personCompletableFuture.isDone()){
|
|
52
|
+ logger.info("IS PROCESSING...");
|
|
53
|
+ Thread.sleep(5000);
|
|
54
|
+ }
|
|
55
|
+ Models.Person person = personCompletableFuture.get();
|
|
56
|
+ return new ResponseEntity<>(Json.toJson(person, person.personFormat()).toString(), HttpStatus.OK);
|
51
|
57
|
}
|
52
|
58
|
|
53
|
59
|
@RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
|
54
|
60
|
private ResponseEntity<String> getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID) throws ExecutionException, InterruptedException {
|
55
|
61
|
Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
|
56
|
|
- CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = this.completableFutureResult.buildcompletableFuture(tvSerieFuture);
|
|
62
|
+ CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = completableFutureResult.buildcompletableFuture(tvSerieFuture);
|
|
63
|
+ while (!tvSerieCompletableFuture.isDone()){
|
|
64
|
+ logger.info("IS PROCESSING...");
|
|
65
|
+ Thread.sleep(5000);
|
|
66
|
+ }
|
57
|
67
|
Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
|
58
|
|
- JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieFormat());
|
59
|
|
-
|
60
|
|
- return new ResponseEntity<>(tvSerieJs.toString(), HttpStatus.OK);
|
|
68
|
+ return new ResponseEntity<>(Json.toJson(tvSerie, tvSerie.tvSerieFormat()).toString(), HttpStatus.OK);
|
61
|
69
|
}
|
62
|
70
|
|
63
|
71
|
@RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
|
64
|
|
- private ResponseEntity<Future<List<Models.TvSerie>>> getTvserieByPrimaryTitle(@PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
|
65
|
|
- Future<List<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
|
|
72
|
+ private ResponseEntity<IndexedSeq<Models.TvSerie>> getTvserieByPrimaryTitle(
|
|
73
|
+ @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
|
|
74
|
+
|
|
75
|
+ Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
|
|
76
|
+ IndexedSeq<Models.TvSerie> indexedSeq = listFuture.value().get().get();
|
66
|
77
|
|
67
|
|
- return new ResponseEntity<>(listFuture, HttpStatus.OK);
|
|
78
|
+ return new ResponseEntity<>(indexedSeq, HttpStatus.OK);
|
68
|
79
|
}
|
69
|
80
|
|
70
|
81
|
@RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
|