138484be53bb8136eca6b709520b8cb0e868a691
[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         }
45
46
47         public void acceptBooking(Booking b) throws RemoteException{
48                 b.getOffer().setBooked(true);
49                 b.getOffer().getBookings().clear();
50                 b.getOffer().getBookings().add(b);
51                 this.dbMngr.acceptBooking(b.getOffer());
52                 try {
53                         MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
54                 } catch (MessagingException e) {
55                         e.printStackTrace();
56                 }
57                 
58         }
59         /**
60          * This method creates a book with a corresponding parameters
61          * 
62          * @param First
63          *            day, last day, house number and telephone
64          * @return a book
65          */
66         public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
67                         Date lastDate, Client client)
68                         throws OfferCanNotBeBooked,RemoteException {
69
70                 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
71                                 client);
72         }
73
74 }