1 package de.spring.webservices.rest.business.service.impl;
3 import java.io.IOException;
4 import java.util.ArrayList;
6 import java.util.concurrent.atomic.AtomicLong;
8 import org.springframework.data.domain.Page;
9 import org.springframework.data.domain.PageImpl;
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 rx.exceptions.Exceptions;
17 @Service("awesomeBusinessLogic")
18 public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic {
19 private static final String TEMPLATE = "Car: %s";
21 private final AtomicLong counter = new AtomicLong();
24 public Page<Car> findAll(Pageable pageRequest) {
25 final List<Car> cars = new ArrayList<>();
26 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 1)));
27 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 2)));
28 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 3)));
32 } catch(InterruptedException ex) {
33 Thread.currentThread().interrupt();
36 return new PageImpl<>(cars);
40 public Car findById(long id) {
44 } catch(InterruptedException ex) {
45 Thread.currentThread().interrupt();
49 return new Car(counter.incrementAndGet(), String.format(TEMPLATE, id));
53 public Car create(Car car) {
54 long count = counter.incrementAndGet();
58 } catch(InterruptedException ex) {
59 Thread.currentThread().interrupt();
62 return new Car(count, String.format(TEMPLATE, count));
66 public Car createThrowable(Car car) throws IOException {
68 throw new IOException("createThrowable FATAL ERROR");
69 // Spring sees both exceptions.
70 // It seems like calling Exceptions.propagate(ex) in RxJava code is only required
71 // for no RuntimeExceptions :/
72 // throw new RuntimeException("createThrowable FATAL ERROR");