f41af5dc45a84769f45340e0453e78bc4df4c92b
[JavaForFun] /
1 package de.spring.webservices.rest.business.service.impl;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.concurrent.atomic.AtomicLong;
7
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;
12
13 import de.spring.webservices.domain.Car;
14 import de.spring.webservices.rest.business.service.AwesomeBusinessLogic;
15
16 @Service("awesomeBusinessLogic")
17 public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic {
18         private static final String TEMPLATE = "Car: %s";
19         
20     private final AtomicLong counter = new AtomicLong();
21         
22         @Override
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)));
28         
29         try {
30             Thread.sleep(10000);
31         } catch(InterruptedException ex) {
32             Thread.currentThread().interrupt();
33         }
34                 
35                 return new PageImpl<>(cars);    
36         }
37
38         @Override
39         public Car findById(long id) {
40                 
41         try {
42             Thread.sleep(10000);
43         } catch(InterruptedException ex) {
44             Thread.currentThread().interrupt();
45         }
46                 
47                 
48                 return new Car(counter.incrementAndGet(), String.format(TEMPLATE, id));
49         }
50
51         @Override
52         public Car create(Car car) {
53                 long count = counter.incrementAndGet();
54                 
55         try {
56             Thread.sleep(10000);
57         } catch(InterruptedException ex) {
58             Thread.currentThread().interrupt();
59         }
60         
61                 return new Car(count, String.format(TEMPLATE, count));
62         }
63         
64         @Override
65         public Car createThrowable(Car car) throws IOException {
66                 
67                 throw new IOException("createThrowable FATAL ERROR");
68         }
69 }