1 package org.objectweb.petals.demo.icare.service.spring; 2 3 import java.util.Collection ; 4 import java.util.Date ; 5 import java.util.LinkedList ; 6 import java.util.List ; 7 8 import org.objectweb.petals.demo.icare.dao.CarDao; 9 import org.objectweb.petals.demo.icare.model.Car; 10 import org.objectweb.petals.demo.icare.model.Category; 11 import org.objectweb.petals.demo.icare.model.Reservation; 12 import org.objectweb.petals.demo.icare.model.dto.CarSearchDto; 13 import org.objectweb.petals.demo.icare.service.CarService; 14 15 25 public class CarServiceImpl implements CarService { 26 27 private CarDao carDao = null; 28 29 public CarServiceImpl() { 30 } 32 33 public CarDao getCarDao() { 34 return carDao; 35 } 36 37 public void setCarDao(CarDao carDao) { 38 this.carDao = carDao; 39 populate(); 40 } 41 42 private void populate() { 43 List <Car> cars; 44 List <Category> categories; 45 List <Reservation> reservations; 46 47 cars = new LinkedList <Car>(); 48 categories = new LinkedList <Category>(); 49 reservations = new LinkedList <Reservation>(); 50 51 categories.add(new Category("A")); 52 categories.add(new Category("B")); 53 categories.add(new Category("C")); 54 55 carDao.storeAllCategories(categories); 56 57 Car[] carTable = new Car[6]; 58 carTable[0] = new Car(categories.get(0), "Renault", "Clio"); 59 carTable[1] = new Car(categories.get(0), "Peugeut", "207"); 60 carTable[2] = new Car(categories.get(0), "Opel", "Corsa"); 61 carTable[3] = new Car(categories.get(1), "Peugeot", "607"); 62 carTable[4] = new Car(categories.get(1), "Mercedess", "C"); 63 carTable[5] = new Car(categories.get(1), "Audi", "A4"); 64 65 for(int i=0; i<6; i++) 66 cars.add(carTable[i]); 67 carDao.storeAllCars(cars); 68 69 Reservation[] reservationTable = new Reservation[4]; 70 reservationTable[0] = new Reservation(); 71 reservationTable[0].setClientName("anass"); 72 reservationTable[0].setStartDate(new Date (0)); 73 reservationTable[0].setEndDate(new Date (1)); 74 reservationTable[0].setCar(carTable[0]); 75 76 reservationTable[1] = new Reservation(); 77 reservationTable[1].setClientName("omar"); 78 reservationTable[1].setStartDate(new Date (2)); 79 reservationTable[1].setEndDate(new Date (3)); 80 reservationTable[1].setCar(carTable[1]); 81 82 reservationTable[2] = new Reservation(); 83 reservationTable[2].setClientName("imad"); 84 reservationTable[2].setStartDate(new Date (4)); 85 reservationTable[2].setEndDate(new Date (5)); 86 reservationTable[2].setCar(carTable[2]); 87 88 reservationTable[3] = new Reservation(); 89 reservationTable[3].setClientName("cristian"); 90 reservationTable[3].setStartDate(new Date (6)); 91 reservationTable[3].setEndDate(new Date (7)); 92 reservationTable[3].setCar(carTable[3]); 93 94 for(int i=0; i<4; i++) 95 reservations.add(reservationTable[i]); 96 97 carDao.storeAllReservation(reservations); 98 99 } 100 101 public Collection <Car> getAllCars() { 102 return carDao.loadAllCars(); 103 } 104 105 public Collection <Car> getAvailableCars(CarSearchDto carSearchDto) { 106 return carDao.loadAllCars(); 107 } 108 109 public Collection <Category> getAllCategories() { 110 return carDao.loadAllCategories(); 111 } 112 113 public Category findCategoryById(long id) { 114 return (Category) carDao.getEntityById(Category.class, id); 115 } 116 117 public Car findCarById(long id) { 118 return (Car) carDao.getEntityById(Car.class, id); 119 } 120 121 public void storeCar(Car car) { 122 carDao.storeEntity(car); 123 } 124 125 public Reservation findReservationById(long id) { 126 return (Reservation) carDao.getEntityById(Reservation.class, id); 127 } 128 129 public Collection <Reservation> getAllReservations() { 130 return carDao.loadAllReservations(); 131 } 132 133 public void storeReservation(Reservation reservation) { 134 carDao.storeEntity(reservation); 135 } 136 } 137 | Popular Tags |