|
@@ -11,10 +11,14 @@ import org.springframework.web.bind.annotation.PathVariable;
|
11
|
11
|
import org.springframework.web.bind.annotation.RequestMapping;
|
12
|
12
|
import org.springframework.web.bind.annotation.RequestMethod;
|
13
|
13
|
import org.springframework.web.bind.annotation.RestController;
|
|
14
|
+import play.api.libs.json.JsValue;
|
14
|
15
|
import play.api.libs.json.Json;
|
15
|
16
|
import scala.collection.IndexedSeq;
|
16
|
17
|
import scala.concurrent.Future;
|
17
|
18
|
|
|
19
|
+import java.util.ArrayList;
|
|
20
|
+import java.util.List;
|
|
21
|
+import java.util.Random;
|
18
|
22
|
import java.util.concurrent.CompletableFuture;
|
19
|
23
|
import java.util.concurrent.ExecutionException;
|
20
|
24
|
|
|
@@ -26,6 +30,8 @@ public class MovieController {
|
26
|
30
|
private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
|
27
|
31
|
private final CompletableFutureResult completableFutureResult = new CompletableFutureResult();
|
28
|
32
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
33
|
+ private static final int BORN_INF = 1000, BORN_SUP = 5000;
|
|
34
|
+
|
29
|
35
|
public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
|
30
|
36
|
this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
|
31
|
37
|
}
|
|
@@ -34,9 +40,9 @@ public class MovieController {
|
34
|
40
|
private ResponseEntity<String> getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
|
35
|
41
|
Future<Models.Person> futurePerson = akkaStreamFilesProcessing.getPersonById(personID);
|
36
|
42
|
CompletableFuture<Models.Person> completableFuture = completableFutureResult.buildcompletableFuture(futurePerson);
|
37
|
|
- while (!completableFuture.isDone()){
|
38
|
|
- logger.info("IS PROCESSING...");
|
39
|
|
- Thread.sleep(5000);
|
|
43
|
+ while (!completableFuture.isDone()) {
|
|
44
|
+ logger.info("IS PROCESSING...");
|
|
45
|
+ Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
|
40
|
46
|
}
|
41
|
47
|
Models.Person person = completableFuture.get();
|
42
|
48
|
return new ResponseEntity<>(Json.toJson(person, person.personFormat()).toString(), HttpStatus.OK);
|
|
@@ -48,39 +54,71 @@ public class MovieController {
|
48
|
54
|
|
49
|
55
|
Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
|
50
|
56
|
CompletableFuture<Models.Person> personCompletableFuture = completableFutureResult.buildcompletableFuture(personFuture);
|
51
|
|
- while (!personCompletableFuture.isDone()){
|
|
57
|
+ while (!personCompletableFuture.isDone()) {
|
52
|
58
|
logger.info("IS PROCESSING...");
|
53
|
|
- Thread.sleep(5000);
|
|
59
|
+ Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
|
54
|
60
|
}
|
55
|
61
|
Models.Person person = personCompletableFuture.get();
|
56
|
62
|
return new ResponseEntity<>(Json.toJson(person, person.personFormat()).toString(), HttpStatus.OK);
|
57
|
63
|
}
|
58
|
64
|
|
59
|
65
|
@RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
|
60
|
|
- private ResponseEntity<String> getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID) throws ExecutionException, InterruptedException {
|
|
66
|
+ private ResponseEntity<String> getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID)
|
|
67
|
+ throws ExecutionException, InterruptedException {
|
61
|
68
|
Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
|
62
|
69
|
CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = completableFutureResult.buildcompletableFuture(tvSerieFuture);
|
63
|
|
- while (!tvSerieCompletableFuture.isDone()){
|
|
70
|
+ while (!tvSerieCompletableFuture.isDone()) {
|
64
|
71
|
logger.info("IS PROCESSING...");
|
65
|
|
- Thread.sleep(5000);
|
|
72
|
+ Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
|
66
|
73
|
}
|
67
|
74
|
Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
|
68
|
75
|
return new ResponseEntity<>(Json.toJson(tvSerie, tvSerie.tvSerieFormat()).toString(), HttpStatus.OK);
|
69
|
76
|
}
|
70
|
77
|
|
71
|
78
|
@RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
|
72
|
|
- private ResponseEntity<IndexedSeq<Models.TvSerie>> getTvserieByPrimaryTitle(
|
73
|
|
- @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
|
|
79
|
+ private List<String> getTvserieByPrimaryTitle(
|
|
80
|
+ @PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) throws InterruptedException, ExecutionException {
|
74
|
81
|
|
75
|
82
|
Future<IndexedSeq<Models.TvSerie>> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
|
76
|
|
- IndexedSeq<Models.TvSerie> indexedSeq = listFuture.value().get().get();
|
|
83
|
+ CompletableFuture<IndexedSeq<Models.TvSerie>> completableFuture =
|
|
84
|
+ completableFutureResult.buildcompletableFuture_(listFuture);
|
|
85
|
+ while (!completableFuture.isDone()) {
|
|
86
|
+ logger.info("IS PROCESSING...");
|
|
87
|
+ Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
|
|
88
|
+ }
|
|
89
|
+ IndexedSeq<Models.TvSerie> tvSerieList = completableFuture.get();
|
|
90
|
+ List<String> tvSeries = new ArrayList<>();
|
|
91
|
+ tvSerieList.foreach(tvSerie -> {
|
|
92
|
+ JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieFormat());
|
|
93
|
+ tvSeries.add(tvSerieJs.toString());
|
|
94
|
+ return null;
|
|
95
|
+ });
|
77
|
96
|
|
78
|
|
- return new ResponseEntity<>(indexedSeq, HttpStatus.OK);
|
|
97
|
+ return tvSeries;
|
79
|
98
|
}
|
80
|
99
|
|
|
100
|
+ ;
|
|
101
|
+
|
81
|
102
|
@RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
|
82
|
|
- private Future<IndexedSeq<Models.Person>> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle) {
|
83
|
|
- return akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
|
|
103
|
+ private List<String> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle)
|
|
104
|
+ throws InterruptedException, ExecutionException {
|
|
105
|
+
|
|
106
|
+ Future<IndexedSeq<Models.Person>> futurePersonSeq = akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
|
|
107
|
+ CompletableFuture<IndexedSeq<Models.Person>> completableFuture = completableFutureResult.buildcompletableFuture_(futurePersonSeq);
|
|
108
|
+ while (!completableFuture.isDone()){
|
|
109
|
+ logger.info("IS PROCESSING...");
|
|
110
|
+ Thread.sleep(new Random().nextInt(BORN_SUP-BORN_INF)+BORN_INF);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ IndexedSeq<Models.Person> personIndexedSeq = completableFuture.get();
|
|
114
|
+ List<String> persons = new ArrayList<>();
|
|
115
|
+ personIndexedSeq.foreach(person -> {
|
|
116
|
+ JsValue personJs = Json.toJson(person, person.personFormat());
|
|
117
|
+ persons.add(personJs.toString());
|
|
118
|
+ return null;
|
|
119
|
+ });
|
|
120
|
+
|
|
121
|
+ return persons;
|
84
|
122
|
}
|
85
|
123
|
|
86
|
124
|
@RequestMapping(value = "/persons", method = RequestMethod.GET)
|