Account adding and deleting fixed
authorcamjan <jcampos004@ikasle.ehu.es>
Mon, 18 May 2015 15:26:01 +0000 (17:26 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Mon, 18 May 2015 15:26:01 +0000 (17:26 +0200)
18 files changed:
ruralHouses client/src/common/AccountInterface.java
ruralHouses client/src/domain/Administrator.java
ruralHouses client/src/domain/Booking.java
ruralHouses client/src/gui/ModifyOfferGUI.java
ruralHouses client/src/gui/OwnerRegistrationGUI.java
ruralHouses client/src/gui/StartWindow.java
ruralHouses client/src/gui/listOfBookingRequestsGUI.java
ruralHouses client/src/gui/listOfOwnerAddittionRequests.java
ruralHouses/.classpath
ruralHouses/src/businessLogic/AccountManager.java
ruralHouses/src/businessLogic/AdminManager.java
ruralHouses/src/businessLogic/LoginManager.java
ruralHouses/src/businessLogic/OfferManager.java
ruralHouses/src/common/AccountInterface.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Account.java
ruralHouses/src/domain/Booking.java
ruralHouses/src/launcher/RMILauncher.java

index 9d489d4..67e02d4 100644 (file)
@@ -4,7 +4,6 @@ import java.rmi.Remote;
 import java.rmi.RemoteException;
 
 import domain.Account;
-import domain.Owner;
 
 public interface AccountInterface extends Remote{
        
index d6e9d79..845d089 100644 (file)
@@ -12,7 +12,6 @@ public class Administrator implements Serializable {
         */
        private static final long serialVersionUID = 1L;
 
-       private static Administrator admin = null;
        private static LinkedList<RuralHouse> addRequest;
        private static LinkedList<RuralHouse> removeRequest;
        private static LinkedList<Account> newOwnerRequest;
index 0f72a6c..13bc007 100644 (file)
@@ -10,7 +10,6 @@ public class Booking implements Serializable  {
         */
        private static final long serialVersionUID = 1L;
        private int bookingNumber;
-       private boolean isPaid;
        private Date bookingDate;
        private Client client;
        private Offer offer;
@@ -26,12 +25,10 @@ public class Booking implements Serializable  {
                this.client=client;
                //Booking date is assigned to actual date
                this.bookingDate= new java.util.Date(System.currentTimeMillis());
-               this.isPaid=false;
        }
        
        public void imprimete(){
                System.out.println(bookingNumber);
-               System.out.println(isPaid);
                System.out.println(bookingDate);
                System.out.println(client.toString());
                System.out.println(offer);      
@@ -60,20 +57,6 @@ public class Booking implements Serializable  {
        public Date getBookDate() {
                return this.bookingDate;
        }
-       
-       public void paid() {
-               this.isPaid = true;
-       }
-
-       public void notPaid() {
-               this.isPaid=false;
-       }
-
-       public boolean isPaid() {
-               return isPaid;
-       }
-       
-
 
        public Client getClient() {
                return client;
index a0751ca..7cb5b85 100644 (file)
@@ -68,7 +68,6 @@ public class ModifyOfferGUI extends JFrame {
                this.setSize(new Dimension(513, 433));
                this.setTitle("Set availability");
 
-               OfferInterface  om = null;
                
                jComboBox1 = new JComboBox<RuralHouse>(v);
 
index b547b82..5a4ffe9 100644 (file)
@@ -16,11 +16,14 @@ import javax.swing.border.EmptyBorder;
 import common.AdminInterface;
 
 import configuration.___IntNames;
-import domain.Account;
 import domain.Owner;
 
 public class OwnerRegistrationGUI extends JFrame {
 
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
        private JPanel panel;
        private JTextField nameField;
        private JTextField userNameField;
index 5325d56..e938084 100644 (file)
@@ -30,8 +30,6 @@ public class StartWindow extends JFrame {
        private JButton boton2 = null;
        private JButton boton3 = null;
        private static configuration.ConfigXML c;
-
-       // public static ApplicationFacadeInterface facadeInterface;
        private JLabel lblNewLabel;
 
        public static void main(String[] args) {
index 1df8f2a..982d7f2 100644 (file)
@@ -81,7 +81,7 @@ public class listOfBookingRequestsGUI extends JFrame {
                };
                scrollPane.setViewportView(table);
                tableModel = new DefaultTableModel(null, new String[] {
-                               "Booking Number", "Is paid", "Booking Date","Name","E-mail", "Telephone" });
+                               "Booking Number", "Booking Date","Name","E-mail", "Telephone" });
 
                // Maybe there is a better way to avoid interaction.
                // table.setEnabled(false);
@@ -123,21 +123,12 @@ public class listOfBookingRequestsGUI extends JFrame {
                btnDenyAddition.setBounds(390, 395, 169, 25);
                contentPane.add(btnDenyAddition);
                
-               JButton btnSetAsPaid = new JButton("Set as paid");
-               btnSetAsPaid.setBounds(239, 395, 89, 23);
-               btnSetAsPaid.addActionListener(new ActionListener() {
-                       public void actionPerformed(ActionEvent arg0) {
-                               
-                       }
-               });
-               contentPane.add(btnSetAsPaid);
                Enumeration<Booking> en = this.bookings.elements();
                Booking book;
                while (en.hasMoreElements()) {
                        book = en.nextElement();
                        Vector<Object> row = new Vector<Object>();
                        row.add(book.getBookNumber());
-                       row.add(book.isPaid());
                        row.add(book.getBookDate());
                        row.add(book.getClient().getName());
                        row.add(book.getClient().getMailAccount());
index 1d78a53..01aaf8f 100644 (file)
@@ -94,8 +94,6 @@ public class listOfOwnerAddittionRequests extends JFrame {
                tableModel = new DefaultTableModel(null, new String[] {
                                "Name", "E-mail", "Bank Account" });
                
-               //Maybe there is a better way to avoid interaction.
-               //table.setEnabled(false);
                table.setModel(tableModel);
                
                JButton btnNewButton = new JButton("Confirm Addition");
@@ -117,7 +115,6 @@ public class listOfOwnerAddittionRequests extends JFrame {
                                                am.removeOwnerAdditionRequests(table.getSelectedRow());
                                                am.saveInstance();
                                        } catch (RemoteException e1) {
-                                               // TODO Auto-generated catch block
                                                e1.printStackTrace();
                                        }
                        
@@ -136,12 +133,10 @@ public class listOfOwnerAddittionRequests extends JFrame {
                                                am.removeOwnerAdditionRequests(table.getSelectedRow());
                                                am.saveInstance();
                                        } catch (RemoteException e) {
-                                               // TODO Auto-generated catch block
                                                e.printStackTrace();
                                        }
                                        
                                        ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
-                                       accounts.remove(table.getSelectedRow());
                                }
                        }
                });
index 4a939f6..833b790 100644 (file)
@@ -4,6 +4,6 @@
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="lib/additionalLibs/jcalendar.jar"/>
        <classpathentry kind="lib" path="lib/db4o/lib/db4o-8.0.249.16098-all-java5.jar"/>
-       <classpathentry kind="lib" path="lib/mail/javax.mail.jar"/>
+       <classpathentry kind="lib" path="lib/javax.mail.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 3747973..ae57126 100644 (file)
@@ -6,6 +6,7 @@ import java.rmi.server.UnicastRemoteObject;
 import javax.mail.MessagingException;
 
 import common.AccountInterface;
+
 import dataAccess.DB4oManager;
 import domain.Account;
 import domain.Administrator;
index a344f2c..e7b38c9 100644 (file)
@@ -5,6 +5,7 @@ import java.rmi.server.UnicastRemoteObject;
 import java.util.Vector;
 
 import common.AdminInterface;
+
 import domain.Account;
 import domain.Administrator;
 import domain.Owner;
index 1f766a3..e0f0439 100644 (file)
@@ -31,7 +31,7 @@ public class LoginManager extends UnicastRemoteObject implements LoginInterface
 
        @Override
        public Account checkCredentials(String usr, String pwd) {
-               Account ac = new Account(usr);
+               Account ac = new Account(SecurityManager.getInstance().calculateHash(usr));
                try {
                        Vector<Account> account = dbMngr.getAccount(ac);
                        if (SecurityManager.getInstance().isExpectedPassword(pwd.toCharArray(), account
index d3b2a87..4c01cc0 100644 (file)
@@ -6,6 +6,7 @@ import java.sql.Date;
 import java.util.Vector;
 
 import common.OfferInterface;
+
 import dataAccess.DB4oManager;
 import domain.Offer;
 import domain.RuralHouse;
index 8e48aeb..67e02d4 100644 (file)
@@ -2,6 +2,7 @@ package common;
 
 import java.rmi.Remote;
 import java.rmi.RemoteException;
+
 import domain.Account;
 
 public interface AccountInterface extends Remote{
index 096a17b..6089a74 100644 (file)
@@ -135,7 +135,6 @@ public class DB4oManager {
                        Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
                                        alfredo);
 
-
                        Account admin = new Account("admin", "admin", true);
                        db.store(Administrator.getInstance());
                        db.store(jonAcc);
@@ -220,9 +219,7 @@ public class DB4oManager {
                }
        }
 
-
-       
-       public Administrator getAdminData(){
+       public Administrator getAdminData() {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
@@ -230,8 +227,7 @@ public class DB4oManager {
 
                try {
 
-                       
-                       List<Administrator> admL = db.query(new Predicate<Administrator>(){
+                       List<Administrator> admL = db.query(new Predicate<Administrator>() {
                                private static final long serialVersionUID = 1L;
 
                                public boolean match(Administrator admin) {
@@ -239,11 +235,8 @@ public class DB4oManager {
                                }
                        });
 
-                       
-                       
                        return admL.get(0);
-               }
-               finally {
+               } finally {
                        db.close();
 
                }
@@ -301,7 +294,7 @@ public class DB4oManager {
                else
                        openDB();
 
-               Vector<Booking> book = new Vector<Booking>() ;
+               Vector<Booking> book = new Vector<Booking>();
 
                try {
 
@@ -320,11 +313,11 @@ public class DB4oManager {
                                offer.createBooking(theDB4oManagerAux.bookingNumber++, cl);
                                db.store(theDB4oManagerAux); // To store the new value for
                                                                                                // bookingNumber
-                               
+
                                db.store(offer);
                                db.commit();
                                book = offer.getBookings();
-                               
+
                        }
 
                } catch (com.db4o.ext.ObjectNotStorableException e) {
@@ -529,27 +522,50 @@ public class DB4oManager {
                        openDB();
 
                try {
-                       // TODO realize if there is another account with same username.
-                       // Quite difficult with the f***ing salt
-                       db.store(acc);
-                       db.commit();
+                       ObjectSet<Account> result = db.queryByExample(new Account(acc
+                                       .getUsername()));
+                       if (result.isEmpty()) {
+                               db.store(acc);
+                               db.commit();
+                               return true;
+                       }
                } catch (Exception exc) {
                        exc.printStackTrace();
                } finally {
                        db.close();
                }
-               return true;
+               return false;
        }
 
        // TODO remove account
 
        public boolean removeAccount(Account acc) {
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+
+               try {
+                       ObjectSet<Account> result = db.queryByExample(new Account(acc
+                                       .getUsername()));
+                       if (!result.isEmpty()) {
+                               db.delete(result.get(0));
+                               ;
+                               db.commit();
+                               return true;
+                       }
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+               } finally {
+                       db.close();
+               }
                return false;
        }
-       
-       //TODO this method should be improved.
-       public void acceptBooking(Offer of){
-               Offer off = new Offer(of.getOfferNumber(),of.getRuralHouse(),of.getFirstDay(),of.getLastDay(),of.getPrice());
+
+       // TODO this method should be improved.
+       public void acceptBooking(Offer of) {
+               Offer off = new Offer(of.getOfferNumber(), of.getRuralHouse(),
+                               of.getFirstDay(), of.getLastDay(), of.getPrice());
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
@@ -560,29 +576,30 @@ public class DB4oManager {
                        this.deleteOffer(result.get(0));
                        db.store(of);
                        db.close();
-                       
+
                } catch (Exception e) {
-                       e.printStackTrace();;
-               }               
+                       e.printStackTrace();
+                       ;
+               }
        }
-       
-       public void removeBooking(Booking b){
+
+       public void removeBooking(Booking b) {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
                try {
                        ObjectSet<Booking> result = db.queryByExample(b);
-                       ObjectSet<Client> result2= db.queryByExample(b.getClient());
+                       ObjectSet<Client> result2 = db.queryByExample(b.getClient());
                        db.delete(result.get(0));
                        db.delete(result2.get(0));
                        db.commit();
                } catch (Exception e) {
-                       e.printStackTrace();;
-               }finally{
+                       e.printStackTrace();
+                       ;
+               } finally {
                        db.close();
                }
 
-               
        }
 }
index 90f3a23..0a724c3 100644 (file)
@@ -22,8 +22,8 @@ public class Account implements Serializable {
        private boolean admin = false;
 
        
-       public Account(String usr){
-               this.username = SecurityManager.getInstance().calculateHash(usr);
+       public Account(byte[] usr){
+               this.username = usr;
                this.salt =null;
                this.password = null;
                this.owner = null;
@@ -48,6 +48,7 @@ public class Account implements Serializable {
 
        }
 
+       
        public byte[] getUsername() {
                return username;
        }
@@ -86,8 +87,6 @@ public class Account implements Serializable {
                if (getClass() != obj.getClass())
                        return false;
                Account other = (Account) obj;
-               if (!Arrays.equals(password, other.password))
-                       return false;
                if (!Arrays.equals(username, other.username))
                        return false;
                return true;
index 0f72a6c..cdde621 100644 (file)
@@ -10,7 +10,6 @@ public class Booking implements Serializable  {
         */
        private static final long serialVersionUID = 1L;
        private int bookingNumber;
-       private boolean isPaid;
        private Date bookingDate;
        private Client client;
        private Offer offer;
@@ -26,12 +25,10 @@ public class Booking implements Serializable  {
                this.client=client;
                //Booking date is assigned to actual date
                this.bookingDate= new java.util.Date(System.currentTimeMillis());
-               this.isPaid=false;
        }
        
        public void imprimete(){
                System.out.println(bookingNumber);
-               System.out.println(isPaid);
                System.out.println(bookingDate);
                System.out.println(client.toString());
                System.out.println(offer);      
@@ -61,20 +58,6 @@ public class Booking implements Serializable  {
                return this.bookingDate;
        }
        
-       public void paid() {
-               this.isPaid = true;
-       }
-
-       public void notPaid() {
-               this.isPaid=false;
-       }
-
-       public boolean isPaid() {
-               return isPaid;
-       }
-       
-
-
        public Client getClient() {
                return client;
        }
index 167f1e0..008e371 100644 (file)
@@ -12,6 +12,7 @@ import businessLogic.LoginManager;
 import businessLogic.OfferManager;
 import businessLogic.OwnerManager;
 
+@SuppressWarnings("deprecation")
 public class RMILauncher {
 
        public static void main(String[] args) {