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