Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / BookingManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.util.Date;
6 import java.util.Vector;
7
8 import javax.mail.MessagingException;
9
10 import com.db4o.ObjectContainer;
11 import com.db4o.ObjectSet;
12
13 import common.BookingInterface;
14 import dataAccess.DB4oManager;
15 import domain.Booking;
16 import domain.Client;
17 import domain.Offer;
18 import domain.RuralHouse;
19 import exceptions.OfferCanNotBeBooked;
20
21
22
23 public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
24
25         /**
26          * 
27          */
28         private static final long serialVersionUID = 1L;
29         dataAccess.DB4oManager dbMngr;
30
31
32         public BookingManager() throws RemoteException {
33                 super();
34                 try {
35                         this.dbMngr = DB4oManager.getInstance();
36                 } catch (Exception e) {
37                         e.printStackTrace();
38                 }
39         }
40
41         
42
43         public void denyBooking(Booking b) throws RemoteException{
44                                 this.dbMngr.removeBooking(b);
45                                 try {
46                                         MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has not been accepted","We are sorry");
47                                 } catch (MessagingException e) {
48                                         e.printStackTrace();
49                                 }
50         }
51
52
53         public void acceptBooking(Booking b) throws RemoteException{
54                 b.getOffer().setBooked(true);
55                 b.getOffer().getBookings().clear();
56                 b.getOffer().getBookings().add(b);
57                 this.dbMngr.acceptBooking(b.getOffer());
58                 try {
59                         MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
60                 } catch (MessagingException e) {
61                         e.printStackTrace();
62                 }
63                 
64         }
65         /**
66          * This method creates a book with a corresponding parameters
67          * 
68          * @param First
69          *            day, last day, house number and telephone
70          * @return a book
71          */
72         public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
73                         Date lastDate, Client client)
74                         throws OfferCanNotBeBooked,RemoteException {
75
76                 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
77                                 client);
78         }
79
80
81
82         @Override
83         public Vector<Booking> getOffersbookings(Offer o) throws RemoteException {
84                 return dbMngr.getOfBok(o);
85         }
86
87 }