Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / BookingManager.java
index 017b1aa..356d3ba 100644 (file)
@@ -1,5 +1,7 @@
 package businessLogic;
 
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
 import java.util.Date;
 import java.util.Vector;
 
@@ -7,6 +9,7 @@ import javax.mail.MessagingException;
 
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
+import common.BookingInterface;
 
 import dataAccess.DB4oManager;
 import domain.Booking;
@@ -14,14 +17,19 @@ import domain.Client;
 import domain.RuralHouse;
 import exceptions.OfferCanNotBeBooked;
 
-public final class BookingManager {
 
-       private int bookingNumber = 0;
+
+public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
        dataAccess.DB4oManager dbMngr;
 
-       private static BookingManager theBookingManager;
 
-       public BookingManager() {
+       public BookingManager() throws RemoteException {
+               super();
                try {
                        this.dbMngr = DB4oManager.getInstance();
                } catch (Exception e) {
@@ -29,55 +37,26 @@ public final class BookingManager {
                }
        }
 
-       /**
-        * This method returns the next Booking number
-        * 
-        * @return the book number
-        */
-       public static int getNumber() {
-               ObjectContainer db = DB4oManager.getContainer();
-               BookingManager b = getInstance();
-               b.bookingNumber++;
-               db.store(b);
-               db.commit();
-               return b.bookingNumber;
-       }
+       
 
-       /**
-        * This method returns the instance of the BookingManager class
-        * 
-        * @return the booking manager
-        */
-       public static BookingManager getInstance() {
-               ObjectContainer db = DB4oManager.getContainer();
-               BookingManager b = new BookingManager();
-               ObjectSet<BookingManager> result = db.queryByExample(b);
-               if (!result.hasNext()) {
-                       theBookingManager = new BookingManager();
-                       db.store(theBookingManager);
-                       db.commit();
-               } else
-                       theBookingManager = (BookingManager) result.next();
-               return theBookingManager;
-       }
-
-       public void removeDenyBooking(Booking b){
-                               b.getOffer().getBookings().remove(b);
+       public void denyBooking(Booking b) throws RemoteException{
                                this.dbMngr.removeBooking(b);
+                               try {
+                                       MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has not been accepted","We are sorry");
+                               } catch (MessagingException e) {
+                                       e.printStackTrace();
+                               }
        }
 
 
-       public void acceptBooking(Booking b){
+       public void acceptBooking(Booking b) throws RemoteException{
                b.getOffer().setBooked(true);
-               for(Booking boo : b.getOffer().getBookings()){
-                       if(!boo.equals(b))
-                               b.getOffer().getBookings().remove(b);
-               }
+               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) {
-                       // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
@@ -91,7 +70,7 @@ public final class BookingManager {
         */
        public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
                        Date lastDate, Client client)
-                       throws OfferCanNotBeBooked {
+                       throws OfferCanNotBeBooked,RemoteException {
 
                return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
                                client);