Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / BookingManager.java
index b9fa7bd..f0d0a54 100644 (file)
@@ -1,37 +1,51 @@
 package businessLogic;
 
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
 import java.util.Date;
+import java.util.Vector;
+
+import javax.mail.MessagingException;
 
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
+import common.BookingInterface;
 
 import dataAccess.DB4oManager;
 import domain.Booking;
+import domain.Client;
 import domain.RuralHouse;
 import exceptions.OfferCanNotBeBooked;
 
 
-public final class BookingManager {
 
+public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
        private int bookingNumber = 0;
        dataAccess.DB4oManager dbMngr;
 
        private static BookingManager theBookingManager;
 
-       public BookingManager() {
+       public BookingManager() throws RemoteException {
+               super();
                try {
                        this.dbMngr = DB4oManager.getInstance();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
-       
+
        /**
-        * This method returns the next Booking number 
+        * This method returns the next Booking number
         * 
         * @return the book number
         */
-    public static int getNumber(){
+
+    public int getNumber() throws RemoteException{
                ObjectContainer db=DB4oManager.getContainer();
        BookingManager b=getInstance();
        b.bookingNumber++;
@@ -41,11 +55,13 @@ public final class BookingManager {
     }
        
        /**
-        * This method returns the instance of the BookingManager class 
+        * This method returns the instance of the BookingManager class
         * 
         * @return the booking manager
+        * @throws RemoteException 
         */
-       public static BookingManager getInstance()  {
+
+       public BookingManager getInstance() throws RemoteException  {
                ObjectContainer db=DB4oManager.getContainer();
            BookingManager b = new BookingManager();
            ObjectSet<BookingManager> result = db.queryByExample(b);
@@ -56,7 +72,24 @@ public final class BookingManager {
            } else theBookingManager=(BookingManager)result.next();
                return theBookingManager;
        }
-       
+
+       public void denyBooking(Booking b) throws RemoteException{
+                               this.dbMngr.removeBooking(b);
+       }
+
+
+       public void acceptBooking(Booking b) throws RemoteException{
+               b.getOffer().setBooked(true);
+               b.getOffer().getBookings().clear();
+               b.getOffer().getBookings().add(b);
+               this.dbMngr.acceptBooking(b.getOffer());
+               try {
+                       MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
+               } catch (MessagingException e) {
+                       e.printStackTrace();
+               }
+               
+       }
        /**
         * This method creates a book with a corresponding parameters
         * 
@@ -64,10 +97,12 @@ public final class BookingManager {
         *            day, last day, house number and telephone
         * @return a book
         */
-       public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
-                       throws OfferCanNotBeBooked {
+       public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
+                       Date lastDate, Client client)
+                       throws OfferCanNotBeBooked,RemoteException {
 
-               return dbMngr.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber);
+               return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
+                               client);
        }
-       
+
 }
\ No newline at end of file