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