e3e5317280ad43c1767980c444cb519542da215d
[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         
12         private 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                 stored = this.dbMngr.storeRuralHouses(rh);
39                 return stored;
40         }
41
42         public void removeHouse(RuralHouse rh, Owner owner) {
43                 Vector<RuralHouse> temp = owner.getRuralHouses();
44                 temp.remove(rh);
45                 this.dbMngr.removeHouse(rh, owner);
46         }
47
48
49
50         public Vector<RuralHouse> getHouses(String name,String town, int nBed, int nKit,
51                         int nBath, int nPark, int nLiv) {
52
53                 return this.dbMngr.getRuralHouses(name ,town, nBed, nKit, nBath, nPark, nLiv);
54         }
55
56         @Override
57         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
58                         Exception {
59                 return dbMngr.getAllRuralHouses();
60         }
61
62
63
64         // For future implementation
65         // @Override
66         // public void modifyHouse(int houseName, Owner owner, String description,
67         // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
68         // int nParkings) {
69         // // TODO Auto-generated method stub
70         //
71         // }
72
73         // Maybe returning the offer is not necessary. Depends on GUI
74         // implementation.
75
76 }