626038f153670b36c280aa4309c4c04e9083a16d
[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
10 import dataAccess.DB4oManager;
11 import domain.Account;
12 import domain.Administrator;
13
14 public class AccountManager extends UnicastRemoteObject implements AccountInterface {
15         
16         /**
17          * 
18          */
19         private static final long serialVersionUID = 1L;
20         private DB4oManager dbMngr;
21         
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().get(index);
34                 if(this.dbMngr.addAccount(ac)){
35                         try {
36                                 MailManager.getInstance().Send(ac.getOwner().getMailAccount(), "Entered into the system", "Congratulations");
37                         } catch (MessagingException e) {
38                                 e.printStackTrace();
39                         }
40                         return true;
41                         }
42                 return false;
43                 
44         }
45         
46         public boolean removeAccount(int index)throws RemoteException {
47                 OwnerManager own = new OwnerManager();
48                 try {
49                         if(this.dbMngr.removeAccount(own.getOwners().get(index)))
50                                 return true;
51                 } catch (Exception e) {
52                         // TODO Auto-generated catch block
53                         e.printStackTrace();
54                 }
55                 return false;
56                 
57         }
58 }