The bug found in the presentation that we forgot to review has been fixed
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / AdminManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.util.Vector;
6
7 import common.AdminInterface;
8
9 import dataAccess.DB4oManager;
10 import domain.Account;
11 import domain.Administrator;
12 import domain.Owner;
13 import domain.RuralHouse;
14
15 public class AdminManager extends UnicastRemoteObject implements AdminInterface {
16         /**
17          * 
18          */
19         private static final long serialVersionUID = 1L;
20
21         public AdminManager() throws RemoteException {
22
23         }
24
25         public Vector<RuralHouse> getAdditionRequests() throws RemoteException {
26                 return new Vector<RuralHouse>(Administrator.getInstance()
27                                 .getAddRequest());
28         }
29
30         public Vector<RuralHouse> getDeletionRequests() throws RemoteException {
31                 return new Vector<RuralHouse>(Administrator.getInstance()
32                                 .getRemoveRequest());
33         }
34
35         public Vector<Account> getOwnerAdditionRequests() throws RemoteException {
36                 return new Vector<Account>(Administrator.getInstance()
37                                 .getNewOwnerRequest());
38         }
39
40         public Vector<Owner> getAllOwners() throws RemoteException {
41                 try {
42                         return new Vector<Owner>(DB4oManager.getInstance().getOwners());
43                 } catch (Exception e) {
44                         e.printStackTrace();
45                 }
46                 return null;
47         }
48
49         public void removeHouseAdditionRequests(RuralHouse house)
50                         throws RemoteException {
51                 Administrator.getInstance().getAddRequest().remove(house);
52         }
53
54         public void removeHouseDeletionRequests(RuralHouse house)
55                         throws RemoteException {
56                 Administrator.getInstance().getRemoveRequest().remove(house);
57         }
58
59         public void removeOwnerAdditionRequests(int index) throws RemoteException {
60                 Administrator.getInstance().getNewOwnerRequest().remove(index);
61         }
62
63         public boolean addAdditionRequest(RuralHouse rh) throws RemoteException {
64                 if (this.getAdditionRequests().contains(rh)
65                                 || !suitsRegulations(rh.getFeatures().getnKitchens(), rh
66                                                 .getFeatures().getnBaths(),rh
67                                                 .getFeatures().getnLivings())) {
68                         return false;
69                 }
70                 return Administrator.getInstance().getAddRequest().add(rh);
71
72         }
73
74         public boolean addDeletionRequest(RuralHouse rh) throws RemoteException {
75                 if (this.getDeletionRequests().contains(rh))
76                         return false;
77
78                 return Administrator.getInstance().getRemoveRequest().add(rh);
79
80         }
81
82         public boolean addAccountRequest(String usr, String pss, Owner ow)
83                         throws RemoteException {
84
85                 Account acc = new Account(usr, pss, ow);
86                 if (this.getOwnerAdditionRequests().contains(acc)) {
87                         return false;
88                 }
89                 return Administrator.getInstance().getNewOwnerRequest().add(acc);
90         }
91
92         @Override
93         public void saveInstance() throws RemoteException {
94                 Administrator.saveInstance();
95
96         }
97
98         private boolean suitsRegulations(int nKitchens, int nBaths, int nLivings) {
99                 if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
100                         return false;
101                 else
102                         return true;
103         }
104
105         // public boolean removeAccount(Account acc) {
106         // if (this.getDeletionRequests().contains(acc))
107         // return false;
108         // return Administrator.getInstance().getNewOwnerRequest().add(acc);
109         // }
110 }