4601b883ea2490d6563e6992f52e4c37b9f1c57d
[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         private boolean suitsRegulations(int nKitchens, int nBaths, int nLivings) {
25                 if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
26                         return false;
27                 else
28                         return true;
29         }
30
31         @Override
32         public boolean registerNewHouse(RuralHouse rh) {
33
34                 boolean stored = false;
35                 if (!suitsRegulations(rh.getFeatures().getnKitchens(), rh.getFeatures()
36                                 .getnBaths(), rh.getFeatures().getnKitchens()))
37                         return false;
38                 rh.getOwner().getRuralHouses().add(rh);
39                 stored = this.dbMngr.storeRuralHouses(rh);
40                 return stored;
41         }
42
43         public void removeHouse(RuralHouse rh, Owner owner) {
44                 Vector<RuralHouse> temp = owner.getRuralHouses();
45                 temp.remove(rh);
46                 this.dbMngr.removeHouse(rh, owner);
47         }
48
49
50
51         public Vector<RuralHouse> getHouses(String name,String town, int nBed, int nKit,
52                         int nBath, int nPark, int nLiv) {
53
54                 return this.dbMngr.getRuralHouses(name ,town, nBed, nKit, nBath, nPark, nLiv);
55         }
56
57         @Override
58         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
59                         Exception {
60                 return dbMngr.getAllRuralHouses();
61         }
62
63
64
65         // For future implementation
66         // @Override
67         // public void modifyHouse(int houseName, Owner owner, String description,
68         // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
69         // int nParkings) {
70         // // TODO Auto-generated method stub
71         //
72         // }
73
74         // Maybe returning the offer is not necessary. Depends on GUI
75         // implementation.
76
77 }