Owner deletion added
authorcamjan <jcampos004@ikasle.ehu.es>
Tue, 19 May 2015 19:39:31 +0000 (21:39 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Tue, 19 May 2015 19:39:31 +0000 (21:39 +0200)
12 files changed:
ruralHouses client/src/common/AccountInterface.java
ruralHouses client/src/domain/Owner.java
ruralHouses client/src/gui/AdminMenuGUI.java
ruralHouses client/src/gui/DeleteOwnerGUI.java
ruralHouses client/src/gui/listOfAdditionRequestsGUI.java
ruralHouses client/src/gui/listOfBookingRequestsGUI.java
ruralHouses client/src/gui/listOfOffers.java
ruralHouses client/src/gui/listOfOwnerAddittionRequests.java
ruralHouses/src/businessLogic/AccountManager.java
ruralHouses/src/common/AccountInterface.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Account.java

index 67e02d4..5de6948 100644 (file)
@@ -10,5 +10,5 @@ public interface AccountInterface extends Remote{
 
        public boolean addAccount(int index) throws RemoteException;
        
-       public boolean removeAccount(Account ac) throws RemoteException;
+       public boolean removeAccount(int index) throws RemoteException;
 }
index 550aceb..0c4fa4b 100644 (file)
@@ -14,10 +14,6 @@ public class Owner implements Serializable {
        private String mailAccount = "";
        private Vector<RuralHouse> ruralHouses;
 
-//     public Owner(String name) {
-//             this.name = name;
-//             ruralHouses = new Vector<RuralHouse>();
-//     }
 
        public Owner(String name, String bankAccount,String mail) {
                this.bankAccount = bankAccount;
index eef2ba4..cfd6922 100644 (file)
@@ -10,6 +10,7 @@ import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.border.EmptyBorder;
+import javax.swing.LayoutStyle.ComponentPlacement;
 
 public class AdminMenuGUI extends JFrame {
 
@@ -29,12 +30,13 @@ public class AdminMenuGUI extends JFrame {
                
                this.setTitle("Administrator Menu");
                this.getContentPane().setLayout(null);
-               setBounds(100, 100, 450, 473);
+               setBounds(100, 100, 450, 500);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                //TODO BOTH BUTTONS ARE TO MODIFY
                JButton btnAdd = new JButton("Add requests");
+               btnAdd.setBounds(120, 67, 164, 81);
                btnAdd.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                Frame a = new listOfAdditionRequestsGUI();
@@ -43,6 +45,7 @@ public class AdminMenuGUI extends JFrame {
                });
                
                JButton btnDel = new JButton("Delete Requests");
+               btnDel.setBounds(120, 159, 164, 73);
                btnDel.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                Frame a = new listOfRemovalRequestsGUI();
@@ -51,34 +54,26 @@ public class AdminMenuGUI extends JFrame {
                });
                
                JButton btnOwneraddition = new JButton("OwnerAddition");
+               btnOwneraddition.setBounds(120, 243, 164, 73);
                btnOwneraddition.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                Frame a = new listOfOwnerAddittionRequests();
                                a.setVisible(true);
                        }
                });
-               GroupLayout gl_contentPane = new GroupLayout(contentPane);
-               gl_contentPane.setHorizontalGroup(
-                       gl_contentPane.createParallelGroup(Alignment.LEADING)
-                               .addGroup(gl_contentPane.createSequentialGroup()
-                                       .addGap(115)
-                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
-                                               .addComponent(btnOwneraddition, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-                                               .addComponent(btnDel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
-                                               .addComponent(btnAdd, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
-                                       .addContainerGap(145, Short.MAX_VALUE))
-               );
-               gl_contentPane.setVerticalGroup(
-                       gl_contentPane.createParallelGroup(Alignment.LEADING)
-                               .addGroup(gl_contentPane.createSequentialGroup()
-                                       .addGap(62)
-                                       .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
-                                       .addGap(58)
-                                       .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
-                                       .addGap(52)
-                                       .addComponent(btnOwneraddition, GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
-                                       .addContainerGap())
-               );
-               contentPane.setLayout(gl_contentPane);
+               contentPane.setLayout(null);
+               contentPane.add(btnOwneraddition);
+               contentPane.add(btnDel);
+               contentPane.add(btnAdd);
+       
+               JButton btnOwnerDeletion = new JButton("Owner Deletion");
+               btnOwnerDeletion.setBounds(120, 331, 164, 73);
+               btnOwnerDeletion.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new DeleteOwnerGUI();
+                               a.setVisible(true);
+                       }
+               });
+               contentPane.add(btnOwnerDeletion);
        }
 }
index ac471ed..75305dc 100644 (file)
@@ -1,5 +1,144 @@
 package gui;
 
-public class DeleteOwnerGUI {
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.util.Enumeration;
+import java.util.Vector;
 
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableModel;
+
+
+
+import common.AccountInterface;
+import common.OwnerInterface;
+import configuration.___IntNames;
+import domain.Owner;
+
+public class DeleteOwnerGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+
+       private DefaultTableModel tableModel;
+       private OwnerInterface Own = null;
+       private Vector<Owner> owners = new Vector<Owner>();
+
+       /**
+        * Create the frame.
+        */
+       public DeleteOwnerGUI() {
+               setTitle("Current owners:");
+               try {
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 500);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+               try {
+                       Own = (OwnerInterface) Naming
+                                       .lookup(___IntNames.OwnerManager);
+               } catch (Exception e1) {
+                       System.out
+                                       .println("Error accessing remote authentication: "
+                                                       + e1.toString());
+               }
+               this.owners = Own.getOwners();
+               JLabel lblNewLabel = new JLabel();
+               lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+               lblNewLabel.setBounds(23, 41, 536, 33);
+               contentPane.add(lblNewLabel);
+               if (this.owners.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not owners in the system");
+               else
+                       lblNewLabel.setText("List of owners:");
+               JScrollPane scrollPane = new JScrollPane();
+               scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+               scrollPane.setBounds(23, 113, 536, 271);
+               contentPane.add(scrollPane);
+               JLabel feedback = new JLabel("");
+               feedback.setBounds(134, 447, 307, 14);
+               contentPane.add(feedback);
+               JButton btnNewButton = new JButton("Delete from the system");
+               btnNewButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+                                       AccountInterface acm = null;
+                                       
+                                       try {
+                                               acm = (AccountInterface) Naming
+                                                               .lookup(___IntNames.AccountManager);
+                                       } catch (Exception e1) {
+                                               System.out.println("Error accessing remote authentication: "
+                                                               + e1.toString());
+                                       }
+
+                                       try {
+                                               if(acm.removeAccount(table.getSelectedRow()))
+                                                       {
+                                                       feedback.setText("Deleted from the system");
+                                                       }
+                                       } catch (RemoteException e1) {
+                                               e1.printStackTrace();
+                                       }
+                                       
+                                       ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
+                               }
+                       }
+               });
+               btnNewButton.setBounds(88, 396, 428, 40);
+               contentPane.add(btnNewButton);
+               table = new JTable() {
+                       private static final long serialVersionUID = 1L;
+
+                       public boolean isCellEditable(int row, int column) {
+                               return false;
+                       };
+               };
+               
+               scrollPane.setViewportView(table);      
+               tableModel = new DefaultTableModel(null, new String[] {
+                               "Name", "E-mail", "Bank Account" });
+
+               table.setModel(tableModel);
+               
+               
+               Enumeration<Owner> rhs = this.owners.elements();
+               while (rhs.hasMoreElements()) {
+                       Owner own = rhs.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(own.getName());
+                       row.add(own.getMailAccount());
+                       row.add(own.getBankAccount());
+                       tableModel.addRow(row);
+               }
+               
+               
+       }
 }
index d112532..30e5e66 100644 (file)
@@ -118,7 +118,6 @@ public class listOfAdditionRequestsGUI extends JFrame {
                                        }
                                        
                                        ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
-                                       houses.remove(rh);
                                }
                        }
                });
index 3db660d..85d86e1 100644 (file)
@@ -112,6 +112,8 @@ public class listOfBookingRequestsGUI extends JFrame {
                                                } catch (RemoteException e1) {
                                                        e1.printStackTrace();
                                                }
+                                               contentPane.setVisible(false);
+
                                        }
 
                                }
@@ -138,11 +140,18 @@ public class listOfBookingRequestsGUI extends JFrame {
                                        } catch (RemoteException e) {
                                                e.printStackTrace();
                                        }
-                                       bookings.remove(book);
+                                       ((DefaultTableModel) table.getModel()).removeRow(table
+                                                       .getSelectedRow());
 
                                }
                        }
                });
+
+               if (this.bookings.get(0).getOffer().isBooked()) {
+                       btnDenyAddition.setEnabled(false);
+                       btnNewButton.setEnabled(false);
+               }
+
                btnDenyAddition.setBounds(390, 395, 169, 25);
                contentPane.add(btnDenyAddition);
 
@@ -164,10 +173,6 @@ public class listOfBookingRequestsGUI extends JFrame {
                         */
                        private static final long serialVersionUID = 1L;
 
-                       public int daysBetween(Date d1, Date d2) {
-                               return (int) ((d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
-                       }
-
                        @Override
                        public Component getTableCellRendererComponent(JTable table,
                                        Object value, boolean isSelected, boolean hasFocus,
@@ -176,10 +181,7 @@ public class listOfBookingRequestsGUI extends JFrame {
                                super.getTableCellRendererComponent(table, value, isSelected,
                                                hasFocus, row, col);
 
-                               Date bookDay = (Date) table.getModel().getValueAt(row, 1);
-                               Date currentDay = new java.util.Date(System.currentTimeMillis());
-
-                               if (daysBetween(bookDay, currentDay) > 3) {
+                               if (!bookings.get(row).getOffer().isBooked()) {
                                        setBackground(Color.RED);
                                        setForeground(Color.BLACK);
                                } else {
index 0792540..4651ff8 100644 (file)
@@ -1,5 +1,7 @@
 package gui;
 
+import java.awt.Color;
+import java.awt.Component;
 import java.awt.Font;
 import java.awt.Rectangle;
 import java.awt.event.MouseAdapter;
@@ -13,6 +15,7 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;
 
 import domain.Offer;
@@ -101,6 +104,32 @@ public class listOfOffers extends JFrame {
                        row.add(of.getRuralHouse().getHouseName());
                        tableModel.addRow(row);
                }
+               
+               table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+                       /**
+                        * 
+                        */
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public Component getTableCellRendererComponent(JTable table,
+                                       Object value, boolean isSelected, boolean hasFocus,
+                                       int row, int col) {
+
+                               super.getTableCellRendererComponent(table, value, isSelected,
+                                               hasFocus, row, col);
+
+                               if (!offers.get(row).isBooked()) {
+                                       setBackground(Color.ORANGE);
+                                       setForeground(Color.BLACK);
+                               } else {
+                                       setBackground(Color.GREEN);
+                                       setForeground(Color.BLACK);
+                               }
+
+                               return this;
+                       }
+               });
 
        }
 }
index 01aaf8f..d72bd98 100644 (file)
@@ -117,7 +117,7 @@ public class listOfOwnerAddittionRequests extends JFrame {
                                        } catch (RemoteException e1) {
                                                e1.printStackTrace();
                                        }
-                       
+                                       
                                        ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
                                }
                        }
index ae57126..d86cb48 100644 (file)
@@ -6,7 +6,6 @@ import java.rmi.server.UnicastRemoteObject;
 import javax.mail.MessagingException;
 
 import common.AccountInterface;
-
 import dataAccess.DB4oManager;
 import domain.Account;
 import domain.Administrator;
@@ -43,9 +42,15 @@ public class AccountManager extends UnicastRemoteObject implements AccountInterf
                
        }
        
-       public boolean removeAccount(Account ac)throws RemoteException {
-               if(this.dbMngr.removeAccount(ac))
-                       return true;
+       public boolean removeAccount(int index)throws RemoteException {
+               OwnerManager own = new OwnerManager();
+               try {
+                       if(this.dbMngr.removeAccount(own.getOwners().get(index)))
+                               return true;
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
                return false;
                
        }
index 67e02d4..5de6948 100644 (file)
@@ -10,5 +10,5 @@ public interface AccountInterface extends Remote{
 
        public boolean addAccount(int index) throws RemoteException;
        
-       public boolean removeAccount(Account ac) throws RemoteException;
+       public boolean removeAccount(int index) throws RemoteException;
 }
index 4a1a964..e189e95 100644 (file)
@@ -85,8 +85,9 @@ public class DB4oManager {
                configuration.common().objectClass(Booking.class).cascadeOnDelete(true);
                configuration.common().objectClass(RuralHouse.class)
                                .cascadeOnDelete(true);
-               configuration.common().objectClass(Offer.class)
+               configuration.common().objectClass(Account.class)
                .cascadeOnDelete(true);
+               configuration.common().objectClass(Offer.class).cascadeOnDelete(true);
                configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
                db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
        }
@@ -539,20 +540,16 @@ public class DB4oManager {
                return false;
        }
 
-       // TODO remove account
-
-       public boolean removeAccount(Account acc) {
+       public boolean removeAccount(Owner own) {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
 
                try {
-                       ObjectSet<Account> result = db.queryByExample(new Account(acc
-                                       .getUsername()));
+                       ObjectSet<Account> result = db.queryByExample(new Account(own));
                        if (!result.isEmpty()) {
                                db.delete(result.get(0));
-                               ;
                                db.commit();
                                return true;
                        }
@@ -598,10 +595,10 @@ public class DB4oManager {
                        ObjectSet<Booking> result = db.queryByExample(b);
                        result.get(0).getOffer().getBookings().remove(b);
                        db.store(result.get(0).getOffer());
+                       db.delete(result.get(0));
                        db.commit();
                } catch (Exception e) {
                        e.printStackTrace();
-                       ;
                } finally {
                        db.close();
                }
index 0a724c3..ee67f15 100644 (file)
@@ -28,6 +28,13 @@ public class Account implements Serializable {
                this.password = null;
                this.owner = null;
                
+       }
+       public Account(Owner own){
+               this.username = null;
+               this.salt =null;
+               this.password = null;
+               this.owner = own;
+               
        }
        public Account(String usr, String pass, boolean isAdmin) {
                this.username = SecurityManager.getInstance().calculateHash(usr);