70e89853daf1d89e9e6e3d5be4882ac0ab602696
[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         
46         
47
48         public void removeHouse(RuralHouse rh , Owner owner) {
49                 Vector<RuralHouse>  temp = owner.getRuralHouses();
50                 temp.remove(rh);
51                 this.dbMngr.removeHouse(rh, owner);
52         }
53
54
55
56         @Override
57         public Vector<RuralHouse> getHousesByDistrict(String town) {
58                 
59                 return this.dbMngr.getRuralHousesByTown(town);
60         }
61         
62         public Vector<RuralHouse> getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) {
63                 
64                 return this.dbMngr.getRuralHouses(town, nBed, nKit, nBath, nPark, nLiv);
65         }
66
67
68
69         @Override
70         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
71                         Exception {
72                 return dbMngr.getAllRuralHouses();
73         }
74
75
76
77         @Override
78         public RuralHouse getHouseByName(String Name) {
79                 return this.dbMngr.getRuralHouseByName(Name);
80         }
81
82
83
84
85
86         // For future implementation
87         // @Override
88         // public void modifyHouse(int houseName, Owner owner, String description,
89         // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
90         // int nParkings) {
91         // // TODO Auto-generated method stub
92         //
93         // }
94
95         // Maybe returning the offer is not necessary. Depends on GUI
96         // implementation.
97
98 }