Some improvements done, owner deletion started, some bugs remain there
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / OfferManager.java
index 6d35620..fe9cdb1 100644 (file)
@@ -1,26 +1,30 @@
 package businessLogic;
 
 import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
 import java.sql.Date;
+import java.util.Vector;
 
-import com.db4o.ObjectContainer;
-import com.db4o.ObjectSet;
+import common.OfferInterface;
 
 import dataAccess.DB4oManager;
-import domain.Booking;
 import domain.Offer;
 import domain.RuralHouse;
 import exceptions.BadDates;
-import exceptions.OfferCanNotBeBooked;
 import exceptions.OverlappingOfferExists;
 
-public final class OfferManager {
+public final class OfferManager extends UnicastRemoteObject implements OfferInterface{
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
 
        private int offerNumber = 0;
        dataAccess.DB4oManager dbMngr;
-       private static OfferManager theOfferManager;
 
-       public OfferManager() {
+       public OfferManager() throws RemoteException {
+               super();
                try {
                        this.dbMngr = DB4oManager.getInstance();
                } catch (Exception e) {
@@ -28,31 +32,7 @@ public final class OfferManager {
                }
        }
 
-       public static int getNumber() {
-               ObjectContainer db=DB4oManager.getContainer();
-               OfferManager o=getInstance();
-               o.offerNumber++;
-               db.store(o);
-               db.commit();
-               return o.offerNumber;
-       }
 
-       /**
-        * This method returns the instance of the OfferManager class 
-        * 
-        * @return the offer manager
-        */
-       public static OfferManager getInstance()  {
-               ObjectContainer db=DB4oManager.getContainer();
-               OfferManager b = new OfferManager();
-               ObjectSet result = db.queryByExample(b);
-               if (!result.hasNext()){
-                       theOfferManager = new OfferManager();
-                       db.store(theOfferManager);
-                       db.commit();
-               } else theOfferManager=(OfferManager)result.next();
-               return theOfferManager;
-       }
        
        /**
         * This method creates an offer with a house number, first day, last day and price
@@ -63,26 +43,30 @@ public final class OfferManager {
         */
        public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
                        float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception {
-               if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
+               if (firstDay.after(lastDay)||firstDay==null||lastDay==null)
+                       throw new BadDates();
 
                boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
-               if (!b) return dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);                   
+               if (!b) {
+                       dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);
+                       return ruralHouse.createOffer(offerNumber, firstDay, lastDay, price);                   
+               }
                return null;
        }
 
-       public Offer modifyOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
-                       float price, Offer offer) throws OverlappingOfferExists, BadDates, RemoteException, Exception {
-               if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
-               offer.setFirstDay(firstDay);
-               offer.setLastDay(lastDay);
-               offer.setPrice(price);
-               
-               return dbMngr.modifyOffer(offer);                       
-               
-       }
+       
        public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException, Exception{
-               rh.offers.removeElement(o);
-               dbMngr.deleteOffer(rh, o);
+               rh.getAllOffers().removeElement(o);
+               dbMngr.deleteOffer( o);
+       }
+
+
+
+       @Override
+       public Vector<RuralHouse> getRuralHouseOffers(RuralHouse rh)
+                       throws RemoteException {
+               // TODO Auto-generated method stub
+               return null;
        }
 
 }