1 package de.spring.webservices.rest.business.service.impl;
3 import java.io.IOException;
5 import javax.inject.Inject;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.springframework.data.domain.Page;
10 import org.springframework.data.domain.Pageable;
11 import org.springframework.stereotype.Service;
13 import de.spring.webservices.domain.Car;
14 import de.spring.webservices.rest.business.service.AwesomeBusinessLogic;
15 import de.spring.webservices.rest.business.service.RxJavaBusinessLogic;
17 import rx.exceptions.Exceptions;
20 @Service("rxJavaBusinessLogic")
21 public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic {
22 private static final Logger LOGGER = LoggerFactory.getLogger(RxJavaBusinessLogicImpl.class);
24 private final AwesomeBusinessLogic awesomeBusinessLogic;
27 public RxJavaBusinessLogicImpl(AwesomeBusinessLogic awesomeBusinessLogic) {
28 this.awesomeBusinessLogic = awesomeBusinessLogic;
32 public Observable<Page<Car>> findAll(Pageable pageRequest) {
33 return Observable.create(observer -> observer.onNext( awesomeBusinessLogic.findAll(pageRequest)));
38 public Observable<Car> findById(long id) {
39 return Observable.create(observer -> observer.onNext( awesomeBusinessLogic.findById(id)));
43 public Observable<Car> create(Car car) {
44 return Observable.create(observer -> observer.onNext(awesomeBusinessLogic.create(car)));
48 public Observable<Car> createThrowable(Car car) {
49 return Observable.create(observer -> {
52 observer.onNext(awesomeBusinessLogic.createThrowable(car));
53 } catch (IOException ex) {
54 // I could use this implementation. Instead, I will wrap my exception because
55 // that is what you would be doing if you were using any other method from RxJava (like map() for example)
56 // observer.onError(ex);
58 LOGGER.error("createThrowable error: ", ex);
60 Exceptions.propagate(ex);