68cf64e943e1e9a7ac3f7e951a99b538e692fdab
[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.Owner;
8 import domain.RuralHouse;
9
10 public class HouseManager implements HouseManagerInterface {
11         DB4oManager dbMngr;
12
13         public HouseManager() {
14                 try {
15                         dbMngr = DB4oManager.getInstance();
16                 } catch (Exception e) {
17
18                         e.printStackTrace();
19                 }
20         }
21
22
23         private boolean suitsRegulations(int nKitchens, int nBaths, int nLivings) {
24                 if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
25                         return false;
26                 else
27                         return true;
28         }
29
30         @Override
31         public boolean registerNewHouse(RuralHouse rh) {
32
33                 boolean stored = false;
34                 if (!suitsRegulations(rh.getFeatures().getnKitchens(), rh.getFeatures()
35                                 .getnBaths(), rh.getFeatures().getnKitchens()))
36                         return false;
37                 stored = this.dbMngr.storeRuralHouses(rh);
38                 return stored;
39         }
40
41         public void removeHouse(RuralHouse rh, Owner owner) {
42                 Vector<RuralHouse> temp = owner.getRuralHouses();
43                 temp.remove(rh);
44                 this.dbMngr.removeHouse(rh, owner);
45         }
46
47
48
49         public Vector<RuralHouse> getHouses(String name,String town, int nBed, int nKit,
50                         int nBath, int nPark, int nLiv) {
51
52                 return this.dbMngr.getRuralHouses(name ,town, nBed, nKit, nBath, nPark, nLiv);
53         }
54
55         @Override
56         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
57                         Exception {
58                 return dbMngr.getAllRuralHouses();
59         }
60
61
62
63         // For future implementation
64         // @Override
65         // public void modifyHouse(int houseName, Owner owner, String description,
66         // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
67         // int nParkings) {
68         // // TODO Auto-generated method stub
69         //
70         // }
71
72         // Maybe returning the offer is not necessary. Depends on GUI
73         // implementation.
74
75 }