7de62a4d6862fdcf2aea34b0de5dd81887bdf309
[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                 rh.getOwner().getRuralHouses().add(rh);
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 }