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