Merge branch 'master' of https://xp-dev.com/git/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 import common.BookingInterface;
13
14 import dataAccess.DB4oManager;
15 import domain.Booking;
16 import domain.Client;
17 import domain.RuralHouse;
18 import exceptions.OfferCanNotBeBooked;
19
20
21
22 public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
23
24         /**
25          * 
26          */
27         private static final long serialVersionUID = 1L;
28         dataAccess.DB4oManager dbMngr;
29
30
31         public BookingManager() throws RemoteException {
32                 super();
33                 try {
34                         this.dbMngr = DB4oManager.getInstance();
35                 } catch (Exception e) {
36                         e.printStackTrace();
37                 }
38         }
39
40         
41
42         public void denyBooking(Booking b) throws RemoteException{
43                                 this.dbMngr.removeBooking(b);
44                                 try {
45                                         MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has not been accepted","We are sorry");
46                                 } catch (MessagingException e) {
47                                         e.printStackTrace();
48                                 }
49         }
50
51
52         public void acceptBooking(Booking b) throws RemoteException{
53                 b.getOffer().setBooked(true);
54                 b.getOffer().getBookings().clear();
55                 b.getOffer().getBookings().add(b);
56                 this.dbMngr.acceptBooking(b.getOffer());
57                 try {
58                         MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
59                 } catch (MessagingException e) {
60                         e.printStackTrace();
61                 }
62                 
63         }
64         /**
65          * This method creates a book with a corresponding parameters
66          * 
67          * @param First
68          *            day, last day, house number and telephone
69          * @return a book
70          */
71         public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
72                         Date lastDate, Client client)
73                         throws OfferCanNotBeBooked,RemoteException {
74
75                 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
76                                 client);
77         }
78
79 }