implemented lacking GUIs and corrected errors
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / FacadeImplementation.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.util.Date;
6 import java.util.Vector;
7 import java.sql.SQLException;
8
9 import com.db4o.ObjectContainer;
10 import com.db4o.ObjectSet;
11
12 import configuration.Config;
13 import dataAccess.DB4oManager;
14 import domain.Booking;
15 import domain.Offer;
16 import domain.Owner;
17 import domain.RuralHouse;
18 import exceptions.OfferCanNotBeBooked;
19
20 public class FacadeImplementation extends UnicastRemoteObject implements ApplicationFacadeInterface {
21
22         private static final long serialVersionUID = 1L;
23         DB4oManager dbMngr;
24
25         public FacadeImplementation() throws RemoteException, InstantiationException,
26         IllegalAccessException, ClassNotFoundException, SQLException {
27                 dbMngr = DB4oManager.getInstance();
28         }
29
30
31         public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
32                         float price) throws RemoteException, Exception {                 
33                 return dbMngr.createOffer(ruralHouse, firstDay, lastDay, price);
34         }
35
36         /**
37          * This method obtains available offers for a concrete house in a certain period 
38          * 
39          * @param houseNumber, the house number where the offers must be obtained 
40          * @param firstDay, first day in a period range 
41          * @param lastDay, last day in a period range
42          * @return a vector of offers(Offer class)  available  in this period
43          */
44         public Vector<Offer> getOffers(RuralHouse house,Date firstDay, Date lastDay) throws RemoteException,
45         Exception {             
46                 return house.getOffers(firstDay, lastDay);
47
48         }
49         /**
50          * This method finds all existing  owners 
51          * 
52          */
53         public Vector<Owner> getOwners() throws RemoteException,
54         Exception {
55                 return dbMngr.getOwners();
56         } 
57
58         /**
59          * This method obtains an owner's rural houses 
60          * 
61          * @param owner object
62          *            
63          * @return a vector of Rural Houses
64          */
65         public Vector<RuralHouse> getRuralHouses(Owner owner)
66                         throws RemoteException {
67                 return owner.getRuralHouses();          
68         }
69
70
71         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
72         Exception {             
73                 return dbMngr.getAllRuralHouses();              
74         }
75
76         
77
78         public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
79                         throws OfferCanNotBeBooked {
80                 try {
81                         RuralHouse rh=dbMngr.getRuralHouse(ruralHouse);
82                         Offer offer = rh.findOffer(firstDate, lastDate);
83                         Booking b=dbMngr.createBooking(offer,bookTelephoneNumber);
84                         return b;
85                 } catch (Exception exc) {
86                         exc.printStackTrace();
87                         return null;
88                 }
89                 
90         }
91
92         
93
94 }
95