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