Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / BookingManager.java
index 601eb3a..3fe64f2 100644 (file)
@@ -5,13 +5,16 @@ 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 common.BookingInterface;
 import dataAccess.DB4oManager;
 import domain.Booking;
 import domain.Client;
+import domain.Offer;
 import domain.RuralHouse;
 import exceptions.OfferCanNotBeBooked;
 
@@ -23,10 +26,8 @@ public final class BookingManager extends UnicastRemoteObject implements Booking
         * 
         */
        private static final long serialVersionUID = 1L;
-       private int bookingNumber = 0;
        dataAccess.DB4oManager dbMngr;
 
-       private static BookingManager theBookingManager;
 
        public BookingManager() throws RemoteException {
                super();
@@ -37,59 +38,28 @@ public final class BookingManager extends UnicastRemoteObject implements Booking
                }
        }
 
-       /**
-        * This method returns the next Booking number
-        * 
-        * @return the book number
-        */
-
-    public int getNumber() throws RemoteException{
-               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
-        * @throws RemoteException 
-        */
 
-       public BookingManager getInstance() throws RemoteException  {
-               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) throws RemoteException{
-                               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) 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 {
+               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();
-               }*/
+               }
                
        }
        /**
@@ -107,4 +77,11 @@ public final class BookingManager extends UnicastRemoteObject implements Booking
                                client);
        }
 
+
+
+       @Override
+       public Vector<Booking> getOffersbookings(Offer o) throws RemoteException {
+               return dbMngr.getOfBok(o);
+       }
+
 }
\ No newline at end of file