0ad55b1050afe6d443afee6008edabec36e05e71
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / AccountManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5
6 import javax.mail.MessagingException;
7
8 import common.AccountInterface;
9 import dataAccess.DB4oManager;
10 import domain.Account;
11 import domain.Administrator;
12 import domain.Owner;
13
14 public class AccountManager extends UnicastRemoteObject implements
15                 AccountInterface {
16
17         /**
18          * 
19          */
20         private static final long serialVersionUID = 1L;
21         private DB4oManager dbMngr;
22
23         public AccountManager() throws RemoteException {
24                 try {
25                         dbMngr = DB4oManager.getInstance();
26                 } catch (Exception e) {
27
28                         e.printStackTrace();
29                 }
30         }
31
32         public boolean addAccount(int index) throws RemoteException {
33                 Account ac = Administrator.getInstance().getNewOwnerRequest()
34                                 .get(index);
35                 if (this.dbMngr.addAccount(ac)) {
36                         try {
37                                 MailManager.getInstance().Send(ac.getOwner().getMailAccount(),
38                                                 "Entered into the system", "Congratulations");
39                         } catch (MessagingException e) {
40                                 e.printStackTrace();
41                         }
42                         return true;
43                 }
44                 return false;
45
46         }
47
48         public boolean removeAccount(int index) throws RemoteException {
49                 AdminManager adm = new AdminManager();
50                 Owner own = adm.getAllOwners().get(index);
51                 try {
52                         if (this.dbMngr.removeAccount(own)) {
53                                 try {
54                                         MailManager.getInstance().Send(own.getMailAccount(), "Removed from the system", "We are sorry");
55                                 } catch (MessagingException e) {
56                                         e.printStackTrace();
57                                 }
58                                 return true;
59                         }
60                 } catch (Exception e) {
61                         e.printStackTrace();
62                 }
63                 return false;
64
65         }
66 }