1 package org.objectweb.rentacar.centraloffice.services.update; 2 3 import java.util.Date ; 4 import java.util.HashSet ; 5 import java.util.Set ; 6 7 import javax.jws.WebMethod; 8 import javax.jws.WebParam; 9 import javax.jws.WebService; 10 11 import org.apache.log4j.Logger; 12 import org.objectweb.rentacar.centraloffice.services.CentralOfficeException; 13 import org.objectweb.rentacar.persistance.bo.Agency; 14 import org.objectweb.rentacar.persistance.bo.Car; 15 import org.objectweb.rentacar.persistance.bo.Contact; 16 import org.objectweb.rentacar.persistance.bo.Reservation; 17 import org.objectweb.rentacar.persistance.dao.AgencyDAO; 18 import org.objectweb.rentacar.persistance.dao.CarDAO; 19 import org.objectweb.rentacar.persistance.dao.ContactDAO; 20 import org.objectweb.rentacar.persistance.dao.DAOException; 21 import org.objectweb.rentacar.persistance.dao.ReservationDAO; 22 23 28 @WebService 29 public class UpdateCentralDBImpl { 30 31 private Logger logger = Logger.getLogger(UpdateCentralDBImpl.class); 32 33 38 @WebMethod 39 public void addReservationInCentralDB( 40 @WebParam(name="customerId") String customerId, 41 @WebParam(name="carId") String carId, 42 @WebParam(name="startingDate") Date startingDate, 43 @WebParam(name="endingDate") Date endingDate, 44 @WebParam(name="startingAgencyId") String startingAgencyId, 45 @WebParam(name="endingAgencyId") String endingAgencyId) 46 throws CentralOfficeException{ 47 48 logger.info("Central Office . addReservationInCentralDB : "+ customerId+", "+ 49 carId+", "+startingDate.toString()+", "+endingDate.toString()+", "+ 50 startingAgencyId+", "+endingAgencyId); 51 AgencyDAO agencyDAO = AgencyDAO.getInstance(); 52 ContactDAO contactDAO = ContactDAO.getInstance(); 53 CarDAO carDAO = CarDAO.getInstance(); 54 55 Car car = null; 56 Contact customer = null; 57 Agency startingAgency = null; 58 Agency endingAgency = null; 59 try { 60 car = (Car) carDAO.retrieveById(Car.class, carId); 61 customer = (Contact) contactDAO.retrieveById(Contact.class, customerId); 62 startingAgency = (Agency) agencyDAO.retrieveById(Agency.class, startingAgencyId); 63 endingAgency = (Agency) agencyDAO.retrieveById(Agency.class, endingAgencyId); 64 } catch (DAOException e) { 65 logger.error("Error when retrieving object in database", e); 66 throw new CentralOfficeException("Error when retrieving object in database", e); 67 } 68 Set <Car> cars = new HashSet <Car>(); 69 cars.add(car); 70 Reservation reservationBO = new Reservation(customer, cars, startingDate, endingDate, startingAgency, endingAgency); 71 try { 72 ReservationDAO.getInstance().create(reservationBO); 73 } catch (DAOException e1) { 74 logger.error("Error when creating a reservation in central office DB", e1); 75 throw new CentralOfficeException("Error when creating a reservation in central office DB", e1); 76 } 77 78 } 79 80 } 81 | Popular Tags |