1 package de.spring.webservices.rest.business.service.impl;
3 import java.util.ArrayList;
5 import java.util.concurrent.atomic.AtomicLong;
7 import org.springframework.data.domain.Page;
8 import org.springframework.data.domain.PageImpl;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.stereotype.Service;
12 import de.spring.webservices.domain.Car;
13 import de.spring.webservices.rest.business.service.AwesomeBusinessLogic;
15 @Service("awesomeBusinessLogic")
16 public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic {
17 private static final String TEMPLATE = "Car: %s";
19 private final AtomicLong counter = new AtomicLong();
22 public Page<Car> findAll(Pageable pageRequest) {
23 final List<Car> cars = new ArrayList<>();
24 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 1)));
25 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 2)));
26 cars.add(new Car(counter.incrementAndGet(), String.format(TEMPLATE, 3)));
30 } catch(InterruptedException ex) {
31 Thread.currentThread().interrupt();
34 return new PageImpl<>(cars);
38 public Car findById(long id) {
42 } catch(InterruptedException ex) {
43 Thread.currentThread().interrupt();
47 return new Car(counter.incrementAndGet(), String.format(TEMPLATE, id));
51 public Car create(Car resource) {
52 long count = counter.incrementAndGet();
56 } catch(InterruptedException ex) {
57 Thread.currentThread().interrupt();
60 return new Car(count, String.format(TEMPLATE, count));