02574fc23f2b0355b557cbf566263e03e0f2f056
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / HouseManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.util.Vector;
5
6 import dataAccess.DB4oManager;
7 import domain.HouseFeatures;
8 import domain.Owner;
9 import domain.RuralHouse;
10
11 public class HouseManager implements HouseManagerInterface {
12         DB4oManager dbMngr;
13
14         public HouseManager() {
15                 try {
16                         dbMngr = DB4oManager.getInstance();
17                 } catch (Exception e) {
18
19                         e.printStackTrace();
20                 }
21         }
22
23
24
25         @Override
26         public boolean registerNewHouse(String houseName, Owner owner,
27                         String description, String district, int nRooms, int nKitchens,
28                         int nBaths, int nLivings, int nParkings) {
29                 
30                 boolean stored = false;
31                 if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
32                         return false;
33                 HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths,
34                                 nLivings, nParkings);
35                 RuralHouse rh = new RuralHouse(houseName,
36                                 owner, description, district, feature);
37                 owner.getRuralHouses().add(rh);
38                 stored = this.dbMngr.storeRuralHouses(rh);
39                 return stored;
40         }
41         
42         @Override
43
44         public boolean registerNewHouse(RuralHouse rh) {
45                 
46                 boolean stored = false;
47                 
48                 rh.getOwner().getRuralHouses().add(rh);
49                 stored = this.dbMngr.storeRuralHouses(rh);
50                 return stored;
51         }
52         
53
54         public void removeHouse(RuralHouse rh , Owner owner) {
55                 Vector<RuralHouse>  temp = owner.getRuralHouses();
56                 temp.remove(rh);
57                 this.dbMngr.removeHouse(rh, owner);
58         }
59
60
61
62         @Override
63         public Vector<RuralHouse> getHousesByDistrict(String town) {
64                 
65                 return this.dbMngr.getRuralHousesByTown(town);
66         }
67         
68         public Vector<RuralHouse> getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) {
69                 
70                 return this.dbMngr.getRuralHouses(town, nBed, nKit, nBath, nPark, nLiv);
71         }
72
73
74
75         @Override
76         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
77                         Exception {
78                 return dbMngr.getAllRuralHouses();
79         }
80
81
82
83         @Override
84         public RuralHouse getHouseByName(String Name) {
85                 return this.dbMngr.getRuralHouseByName(Name);
86         }
87
88
89
90
91
92         // For future implementation
93         // @Override
94         // public void modifyHouse(int houseName, Owner owner, String description,
95         // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
96         // int nParkings) {
97         // // TODO Auto-generated method stub
98         //
99         // }
100
101         // Maybe returning the offer is not necessary. Depends on GUI
102         // implementation.
103
104 }