Account adding and deleting fixed
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / OfferManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.sql.Date;
6 import java.util.Vector;
7
8 import common.OfferInterface;
9
10 import dataAccess.DB4oManager;
11 import domain.Offer;
12 import domain.RuralHouse;
13 import exceptions.BadDates;
14 import exceptions.OverlappingOfferExists;
15
16 public final class OfferManager extends UnicastRemoteObject implements OfferInterface{
17
18         /**
19          * 
20          */
21         private static final long serialVersionUID = 1L;
22
23         private int offerNumber = 0;
24         dataAccess.DB4oManager dbMngr;
25
26         public OfferManager() throws RemoteException {
27                 super();
28                 try {
29                         this.dbMngr = DB4oManager.getInstance();
30                 } catch (Exception e) {
31                         e.printStackTrace();
32                 }
33         }
34
35
36         
37         /**
38          * This method creates an offer with a house number, first day, last day and price
39          * 
40          * @param House
41          *            number, start day, last day and price
42          * @return the created offer, or null, or an exception
43          */
44         public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
45                         float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception {
46                 if (firstDay.after(lastDay)||firstDay==null||lastDay==null)
47                         throw new BadDates();
48
49                 boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
50                 if (!b) {
51                         dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);
52                         return ruralHouse.createOffer(offerNumber, firstDay, lastDay, price);                   
53                 }
54                 return null;
55         }
56
57         
58         public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException, Exception{
59                 rh.offers.removeElement(o);
60                 dbMngr.deleteOffer( o);
61         }
62
63
64
65         @Override
66         public Vector<RuralHouse> getRuralHouseOffers(RuralHouse rh)
67                         throws RemoteException {
68                 // TODO Auto-generated method stub
69                 return null;
70         }
71
72 }