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