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;
16 @Service("awesomeBusinessLogic")
17 public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic {
18 private static final String TEMPLATE = "Car: %s";
20 private final AtomicLong counter = new AtomicLong();
23 public Page<Car> findAll(Pageable pageRequest) {
24 final List<Car> cars = new ArrayList<>();
25 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 1)));
26 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 2)));
27 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 3)));
31 } catch(InterruptedException ex) {
32 Thread.currentThread().interrupt();
35 return new PageImpl<>(cars);
39 public Car findById(long id) {
43 } catch(InterruptedException ex) {
44 Thread.currentThread().interrupt();
48 return new Car(counter.incrementAndGet(), String.format(TEMPLATE, id));
52 public Car create(Car car) {
53 long count = counter.incrementAndGet();
57 } catch(InterruptedException ex) {
58 Thread.currentThread().interrupt();
61 return new Car(count, String.format(TEMPLATE, count));
65 public Car createThrowable(Car car) throws IOException {
67 throw new IOException("createThrowable FATAL ERROR");