use of org.glassfish.jersey.examples.rx.domain.Recommendation in project jersey by jersey.
the class ObservableAgentResource method recommended.
private Observable<List<Recommendation>> recommended(final Queue<String> errors) {
destination.register(RxObservableInvokerProvider.class);
// Recommended places.
final Observable<Destination> recommended = destination.path("recommended").request().header("Rx-User", "RxJava").rx(RxObservableInvoker.class).get(new GenericType<List<Destination>>() {
}).onErrorReturn(throwable -> {
errors.offer("Recommended: " + throwable.getMessage());
return Collections.emptyList();
}).flatMap(Observable::from).cache();
forecast.register(RxObservableInvokerProvider.class);
// Forecasts. (depend on recommended destinations)
final Observable<Forecast> forecasts = recommended.flatMap(destination -> forecast.resolveTemplate("destination", destination.getDestination()).request().rx(RxObservableInvoker.class).get(Forecast.class).onErrorReturn(throwable -> {
errors.offer("Forecast: " + throwable.getMessage());
return new Forecast(destination.getDestination(), "N/A");
}));
calculation.register(RxObservableInvokerProvider.class);
// Calculations. (depend on recommended destinations)
final Observable<Calculation> calculations = recommended.flatMap(destination -> calculation.resolveTemplate("from", "Moon").resolveTemplate("to", destination.getDestination()).request().rx(RxObservableInvoker.class).get(Calculation.class).onErrorReturn(throwable -> {
errors.offer("Calculation: " + throwable.getMessage());
return new Calculation("Moon", destination.getDestination(), -1);
}));
return Observable.zip(recommended, forecasts, calculations, Recommendation::new).toList();
}
Aggregations