Username is saved hashed and password hashed and salted
authorcamjan <jcampos004@ikasle.ehu.es>
Sat, 16 May 2015 14:34:49 +0000 (16:34 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Sat, 16 May 2015 14:34:49 +0000 (16:34 +0200)
15 files changed:
ruralHouses/config.out.xml [new file with mode: 0644]
ruralHouses/config.xml
ruralHouses/src/businessLogic/AdminManager.java
ruralHouses/src/businessLogic/BookingManager.java
ruralHouses/src/businessLogic/LoginManager.java
ruralHouses/src/businessLogic/SecurityManager.java [new file with mode: 0644]
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Account.java
ruralHouses/src/domain/Administrator.java
ruralHouses/src/domain/Booking.java
ruralHouses/src/domain/RuralHouse.java
ruralHouses/src/gui/AdminMenuGUI.java
ruralHouses/src/gui/HouseFeaturesGUI.java
ruralHouses/src/gui/OwnerMenuGUI.java
ruralHouses/src/gui/listOfBookingRequestsGUI.java

diff --git a/ruralHouses/config.out.xml b/ruralHouses/config.out.xml
new file mode 100644 (file)
index 0000000..e69de29
index e431b73..b97aa1b 100644 (file)
@@ -9,8 +9,8 @@
        <databaseNode>localhost</databaseNode>
        <db4oFilename>db/casas.db4o</db4oFilename>
        <dataBaseOpenMode>initialize</dataBaseOpenMode>
-       <activationDepth>5</activationDepth>
-       <updateDepth>5</updateDepth>
+       <activationDepth>8</activationDepth>
+       <updateDepth>8</updateDepth>
        <databasePort>8100</databasePort>
        <user>softEng</user>
        <password>i4softwEngin2matx</password>
index 6ddda72..fe56a5b 100644 (file)
@@ -6,31 +6,38 @@ import domain.Administrator;
 import domain.RuralHouse;
 
 public class AdminManager {
-       public AdminManager (){
-               
+       public AdminManager() {
+
        }
-       public Vector<RuralHouse> getAdditionRequests(){
-               return new Vector<RuralHouse>(Administrator.getAddRequest());
+
+       public Vector<RuralHouse> getAdditionRequests() {
+               return new Vector<RuralHouse>(Administrator.getInstance()
+                               .getAddRequest());
        }
-       
-       public Vector<RuralHouse> getDeletionRequests(){
-               return new Vector<RuralHouse>(Administrator.getRemoveRequest());
+
+       public Vector<RuralHouse> getDeletionRequests() {
+               return new Vector<RuralHouse>(Administrator.getInstance()
+                               .getRemoveRequest());
        }
-       public void removeHouseAdditionRequests(RuralHouse house){
-               Administrator.getAddRequest().remove(house);
+
+       public void removeHouseAdditionRequests(RuralHouse house) {
+               Administrator.getInstance().getAddRequest().remove(house);
        }
-       public void removeHouseDeletionRequests(RuralHouse house){
-               Administrator.getRemoveRequest().remove(house);
-               }
-       public boolean addAdditionRequest(RuralHouse rh){
-               if(this.getAdditionRequests().contains(rh)){
+
+       public void removeHouseDeletionRequests(RuralHouse house) {
+               Administrator.getInstance().getRemoveRequest().remove(house);
+       }
+
+       public boolean addAdditionRequest(RuralHouse rh) {
+               if (this.getAdditionRequests().contains(rh)) {
                        return false;
                }
-               return Administrator.getAddRequest().add(rh);
+               return Administrator.getInstance().getAddRequest().add(rh);
        }
-       public boolean addDeletionRequest(RuralHouse rh){
-               if(this.getDeletionRequests().contains(rh))
+
+       public boolean addDeletionRequest(RuralHouse rh) {
+               if (this.getDeletionRequests().contains(rh))
                        return false;
-               return Administrator.getRemoveRequest().add(rh);
+               return Administrator.getInstance().getRemoveRequest().add(rh);
        }
 }
index b9fa7bd..32fc3be 100644 (file)
@@ -1,16 +1,18 @@
 package businessLogic;
 
 import java.util.Date;
+import java.util.Vector;
 
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
 
 import dataAccess.DB4oManager;
 import domain.Booking;
+import domain.Offer;
+import domain.Owner;
 import domain.RuralHouse;
 import exceptions.OfferCanNotBeBooked;
 
-
 public final class BookingManager {
 
        private int bookingNumber = 0;
@@ -25,38 +27,59 @@ public final class BookingManager {
                        e.printStackTrace();
                }
        }
-       
+
        /**
-        * This method returns the next Booking number 
+        * This method returns the next Booking number
         * 
         * @return the book number
         */
-    public static int getNumber(){
-               ObjectContainer db=DB4oManager.getContainer();
-       BookingManager b=getInstance();
-       b.bookingNumber++;
-       db.store(b);
-       db.commit();
-       return b.bookingNumber;
-    }
-       
+       public static int getNumber() {
+               ObjectContainer db = DB4oManager.getContainer();
+               BookingManager b = getInstance();
+               b.bookingNumber++;
+               db.store(b);
+               db.commit();
+               return b.bookingNumber;
+       }
+
        /**
-        * This method returns the instance of the BookingManager class 
+        * This method returns the instance of the BookingManager class
         * 
         * @return the booking manager
         */
-       public static BookingManager getInstance()  {
-               ObjectContainer db=DB4oManager.getContainer();
-           BookingManager b = new BookingManager();
-           ObjectSet<BookingManager> result = db.queryByExample(b);
-           if (!result.hasNext()){
-               theBookingManager = new BookingManager();
-               db.store(theBookingManager);
-               db.commit();
-           } else theBookingManager=(BookingManager)result.next();
+       public static BookingManager getInstance() {
+               ObjectContainer db = DB4oManager.getContainer();
+               BookingManager b = new BookingManager();
+               ObjectSet<BookingManager> result = db.queryByExample(b);
+               if (!result.hasNext()) {
+                       theBookingManager = new BookingManager();
+                       db.store(theBookingManager);
+                       db.commit();
+               } else
+                       theBookingManager = (BookingManager) result.next();
                return theBookingManager;
        }
-       
+
+       public void removeBooking(Booking B) {
+               // TODO
+
+       }
+
+       public Vector<Booking> getAllBookings(Owner ow) {
+               Vector<Booking> books = new Vector<Booking>();
+               for (RuralHouse rh : ow.getRuralHouses()) {
+                       Vector<Offer> off = rh.getAllOffers();
+                       for (Offer of : off) {
+                               System.out.print(of.toString());
+                               if (of.getBooking() != null) {
+                                       
+                                       books.add(of.getBooking());
+                               }
+                       }
+               }
+               return books;
+       }
+
        /**
         * This method creates a book with a corresponding parameters
         * 
@@ -64,10 +87,12 @@ public final class BookingManager {
         *            day, last day, house number and telephone
         * @return a book
         */
-       public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
+       public Booking createBooking(RuralHouse ruralHouse, Date firstDate,
+                       Date lastDate, String bookTelephoneNumber)
                        throws OfferCanNotBeBooked {
 
-               return dbMngr.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber);
+               return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
+                               bookTelephoneNumber);
        }
-       
+
 }
\ No newline at end of file
index 8064310..950f683 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Vector;
 import dataAccess.DB4oManager;
 import domain.Account;
 
+
 public class LoginManager implements LoginManagerInterface {
 
        DB4oManager dbMngr;
@@ -22,12 +23,15 @@ public class LoginManager implements LoginManagerInterface {
 
        @Override
        public Account checkCredentials(String usr, String pwd) {
+               Account ac = new Account(usr);
                try {
-                       Vector<Account> account = dbMngr.getAccount(usr, pwd);
-                       if (account.isEmpty())
-                               return null;
-                       else
+                       Vector<Account> account = dbMngr.getAccount(ac);
+                       if (SecurityManager.getInstance().isExpectedPassword(pwd.toCharArray(), account
+                                       .get(0).getSalt(), account.get(0).getPassword())) {
+                               
                                return account.get(0);
+                       }
+                       return null;
 
                } catch (Exception e) {
                        // TODO Auto-generated catch block
@@ -35,7 +39,4 @@ public class LoginManager implements LoginManagerInterface {
                }
                return null;
        }
-       
-
-
 }
diff --git a/ruralHouses/src/businessLogic/SecurityManager.java b/ruralHouses/src/businessLogic/SecurityManager.java
new file mode 100644 (file)
index 0000000..61c1514
--- /dev/null
@@ -0,0 +1,72 @@
+package businessLogic;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
+import java.util.Arrays;
+
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+
+public class SecurityManager {
+
+       private static SecurityManager secMan = null;
+
+       private SecurityManager() {
+       }
+
+       public static SecurityManager getInstance() {
+               if (secMan == null)
+                       return new SecurityManager();
+               else
+                       return secMan;
+       }
+
+       public byte[] generateSalt() {
+               SecureRandom random = new SecureRandom();
+               byte bytes[] = new byte[20];
+               random.nextBytes(bytes);
+               return bytes;
+       }
+
+       public byte[] calculateHash(String password) {
+               byte[] hash = {};
+               try {
+                       MessageDigest md = MessageDigest.getInstance("SHA1");
+                       md.update(password.getBytes());
+                       hash = md.digest();
+               } catch (Exception e) {
+                       System.out.println("Exception: " + e);
+               }
+               return hash;
+       }
+
+       public byte[] calculateSaltedHash(char[] password, byte[] salt) {
+               PBEKeySpec spec = new PBEKeySpec(password, salt, 10000, 256);
+               Arrays.fill(password, Character.MIN_VALUE);
+               try {
+                       SecretKeyFactory skf = SecretKeyFactory
+                                       .getInstance("PBKDF2WithHmacSHA1");
+                       return skf.generateSecret(spec).getEncoded();
+               } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
+                       throw new AssertionError("Error while hashing a password: "
+                                       + e.getMessage(), e);
+               } finally {
+                       spec.clearPassword();
+               }
+       }
+
+       public boolean isExpectedPassword(char[] password, byte[] salt,
+                       byte[] expectedHash) {
+               byte[] pwdHash = calculateSaltedHash(password, salt);
+               Arrays.fill(password, Character.MIN_VALUE);
+               if (pwdHash.length != expectedHash.length)
+                       return false;
+               for (int i = 0; i < pwdHash.length; i++) {
+                       if (pwdHash[i] != expectedHash[i])
+                               return false;
+               }
+               return true;
+       }
+}
index c594b1c..5ccfda4 100644 (file)
@@ -69,7 +69,8 @@ public class DB4oManager {
                } else // c.getDataBaseOpenMode().equals("open")
 
                {
-                       ObjectSet<DB4oManagerAux> res = db.queryByExample(DB4oManagerAux.class);
+                       ObjectSet<DB4oManagerAux> res = db
+                                       .queryByExample(DB4oManagerAux.class);
                        ListIterator<DB4oManagerAux> listIter = res.listIterator();
                        if (listIter.hasNext())
                                theDB4oManagerAux = (DB4oManagerAux) res.next();
@@ -82,7 +83,8 @@ public class DB4oManager {
                configuration.common().updateDepth(c.getUpdateDepth());
                configuration.common().objectClass(Owner.class).cascadeOnUpdate(true);
                configuration.common().objectClass(Owner.class).cascadeOnDelete(true);
-               configuration.common().objectClass(RuralHouse.class).cascadeOnUpdate(true);
+               configuration.common().objectClass(RuralHouse.class)
+                               .cascadeOnUpdate(true);
                configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
                db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
        }
@@ -126,21 +128,21 @@ public class DB4oManager {
                        jon.setBankAccount("1349 5677 21 2133567777");
                        alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, 5,
                                        5, 5, 5);
-                       
+
                        alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6);
                        alfredo.setBankAccount("4144 0087 23 9700002133");
                        Account jonAcc = new Account("1", "1", jon);
                        Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
                                        alfredo);
 
-                       Account admin = new Account("admin","admin", true);
-                       db.store(Administrator.giveAdmin());
+                       Account admin = new Account("admin", "admin", true);
+                       db.store(Administrator.getInstance());
                        db.store(jonAcc);
                        db.store(alfredoAcc);
                        db.store(admin);
                        db.commit();
                } finally {
-                       db.close();     
+                       db.close();
                }
        }
 
@@ -196,9 +198,7 @@ public class DB4oManager {
                return o;
        }
 
-       
-       public void deleteOffer(Offer offer) throws RemoteException,
-                       Exception {
+       public void deleteOffer(Offer offer) throws RemoteException, Exception {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
@@ -206,7 +206,7 @@ public class DB4oManager {
 
                try {
                        ObjectSet<Offer> of = db.queryByExample(offer);
-                       RuralHouse rh =of.get(0).getRuralHouse();
+                       RuralHouse rh = of.get(0).getRuralHouse();
                        System.out.println(rh.offers.remove(of.get(0)));
                        db.store(rh);
                        db.commit();
@@ -219,75 +219,67 @@ public class DB4oManager {
                }
        }
 
-       
-       @SuppressWarnings("static-access")
-       public LinkedList<RuralHouse>[] getAdminData(){
+
+       public Administrator getAdminData() {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
-               @SuppressWarnings("unchecked")
-               LinkedList<RuralHouse>[] ret =  new LinkedList[2];
-               
+
                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){
+                               public boolean match(Administrator admin) {
                                        return true;
                                }
                        });
-                       
-                       ret[0] = admL.get(0).getAddRequest();
-                       ret[1] = admL.get(0).getRemoveRequest();
-                       return ret;
-               }
-               finally {
+
+                       return admL.get(0);
+               } finally {
                        db.close();
-                       
+
                }
-               
+
        }
-       
+
        @SuppressWarnings("static-access")
        public void storeAdmin() {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
-                       openDB();               
+                       openDB();
                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){
+                               public boolean match(Administrator admin) {
                                        return true;
                                }
                        });
+
                        
-                       admL.get(0).setAddRequest(Administrator.getAddRequest());
-                       admL.get(0).setRemoveRequest(Administrator.getRemoveRequest());
+                       admL.get(0).setAddRequest(Administrator.getInstance().getAddRequest());
+                       admL.get(0).setRemoveRequest(Administrator.getInstance().getRemoveRequest());
+                       admL.get(0).setNewOwnerRequest(Administrator.getInstance().getNewOwnerRequest());
                        db.commit();
-                       
-               }
-               catch(Exception e){
-                       
-               }
-               finally {
+
+               } catch (Exception e) {
+
+               } finally {
                        db.close();
                }
-               
-               
+
        }
-       
-       
+
        /**
         * This method creates a book with a corresponding parameters
         * 
@@ -305,7 +297,6 @@ public class DB4oManager {
                        openDB();
 
                Booking bok = null;
-               
 
                try {
 
@@ -421,12 +412,12 @@ public class DB4oManager {
 
        /**
         * @param usr
-        * @param pwd
+        * @param ps
         * @return
         * @throws RemoteException
         * @throws Exception
         */
-       public Vector<Account> getAccount(String usr, String pwd)
+       public Vector<Account> getAccount(Account proto)
                        throws RemoteException, Exception {
 
                if (c.isDatabaseLocal() == false)
@@ -435,7 +426,6 @@ public class DB4oManager {
                        openDB();
 
                try {
-                       Account proto = new Account(usr, pwd, null);
                        ObjectSet<Account> result = db.queryByExample(proto);
                        Vector<Account> accounts = new Vector<Account>();
                        while (result.hasNext())
@@ -490,7 +480,7 @@ public class DB4oManager {
                        ObjectSet<Owner> result = db.queryByExample(owner);
                        ObjectSet<RuralHouse> rhs = db.queryByExample(rh);
                        if (!rhs.isEmpty()) {
-                               Owner found =  result.get(0);
+                               Owner found = result.get(0);
                                found.getRuralHouses().remove(rhs.get(0));
                                db.delete(rhs.get(0));
                                db.store(found);
@@ -504,7 +494,6 @@ public class DB4oManager {
 
        }
 
-
        public Vector<RuralHouse> getRuralHouses(String name, String town,
                        int nBed, int nKit, int nBath, int nPark, int nLiv) {
                HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
@@ -527,5 +516,4 @@ public class DB4oManager {
 
        }
 
-       
 }
index e0727a1..53dff45 100644 (file)
@@ -1,33 +1,48 @@
 package domain;
 
+import businessLogic.SecurityManager;
+
 public class Account {
 
-       private String username = "";
-       private String password = "";
+       private byte[] username;
+       private byte[] password;
+       private byte[] salt;
+
        private Owner owner;
        private boolean admin = false;
 
-       public Account(String usr, String pass, boolean admin) {
-               this.username = usr;
-               this.password = pass;
+       
+       public Account(String usr){
+               this.username = SecurityManager.getInstance().calculateHash(usr);
+               this.salt =null;
+               this.password = null;
                this.owner = null;
-               this.admin = admin;
+               
+       }
+       public Account(String usr, String pass, boolean isAdmin) {
+               this.username = SecurityManager.getInstance().calculateHash(usr);
+               this.salt = SecurityManager.getInstance().generateSalt();
+               this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt);
+               this.owner = null;
+               this.admin = isAdmin;
 
        }
 
        public Account(String usr, String pass, Owner ow) {
-               this.username = usr;
-               this.password = pass;
+               this.username = SecurityManager.getInstance().calculateHash(usr);
+               this.salt = SecurityManager.getInstance().generateSalt();
+               this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(),
+                               this.salt);
                this.owner = ow;
                this.admin = false;
 
        }
 
-       public String getUsername() {
+       public byte[] getUsername() {
                return username;
        }
 
-       public String getPassword() {
+       public byte[] getPassword() {
                return password;
        }
 
@@ -43,4 +58,12 @@ public class Account {
                this.admin = admin;
        }
 
+       public byte[] getSalt() {
+               return salt;
+       }
+
+       public void setSalt(byte[] salt) {
+               this.salt = salt;
+       }
+
 }
index 6102430..9efed03 100644 (file)
@@ -2,34 +2,45 @@ package domain;
 
 import java.util.LinkedList;
 
+import configuration.ConfigXML;
 import dataAccess.DB4oManager;
 
 public class Administrator {
 
+       private static Administrator admin = null;
        private static LinkedList<RuralHouse> addRequest;
        private static LinkedList<RuralHouse> removeRequest;
-       private Administrator(){
+       private static LinkedList<Owner> newOwnerRequest;
+       static ConfigXML c;
+
+       private Administrator() {
                addRequest = new LinkedList<RuralHouse>();
-               removeRequest  = new LinkedList<RuralHouse>();
+               removeRequest = new LinkedList<RuralHouse>();
+               newOwnerRequest = new LinkedList<Owner>();
        }
 
-       public static Administrator giveAdmin(){
-               return new Administrator();
-       }
-       
-       public static void getInstance(){
-               try {
-                       DB4oManager db4o = DB4oManager.getInstance();
-                       LinkedList<RuralHouse>[] temp = db4o.getAdminData();
-                       addRequest = temp[0];
-                       removeRequest = temp[1];
-               } catch (Exception e) {
-                       e.printStackTrace();
+       public static Administrator getInstance() {
+               c = ConfigXML.getInstance();
+               if (admin == null) {
+                       if (c.getDataBaseOpenMode().equals("initialize")) {
+                               admin = new Administrator();
+                       } else {
+                               DB4oManager db4o;
+                               try {
+                                       db4o = DB4oManager.getInstance();
+                                       admin = db4o.getAdminData();
+                               } catch (Exception e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
                }
                
+               return admin;
+
        }
-       
-       public static void saveInstance(){
+
+       public static void saveInstance() {
                try {
                        DB4oManager.getInstance().storeAdmin();
                } catch (Exception e) {
@@ -37,20 +48,29 @@ public class Administrator {
                        e.printStackTrace();
                }
        }
-       
-       public static LinkedList<RuralHouse> getAddRequest() {
+
+       public LinkedList<RuralHouse> getAddRequest() {
                return addRequest;
        }
-       public static LinkedList<RuralHouse> getRemoveRequest() {
+
+       public LinkedList<RuralHouse> getRemoveRequest() {
                return removeRequest;
        }
 
-       public static void setAddRequest(LinkedList<RuralHouse> addRequest) {
+       public void setAddRequest(LinkedList<RuralHouse> addRequest) {
                Administrator.addRequest = addRequest;
        }
 
-       public static void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
+       public void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
                Administrator.removeRequest = removeRequest;
        }
 
+       public LinkedList<Owner> getNewOwnerRequest() {
+               return newOwnerRequest;
+       }
+
+       public void setNewOwnerRequest(LinkedList<Owner> newOwnerRequest) {
+               Administrator.newOwnerRequest = newOwnerRequest;
+       }
+
 }
index 0ce0ddc..fd72de6 100644 (file)
@@ -10,6 +10,7 @@ public class Booking implements Serializable {
        private Date bookingDate;
        private String telephone;
        private Offer offer;
+       private boolean isAccepted;
        
        
        public Booking() {
@@ -24,6 +25,7 @@ public class Booking implements Serializable {
                //Booking date is assigned to actual date
                this.bookingDate= new java.util.Date(System.currentTimeMillis());
                this.isPaid=false;
+               this.isAccepted=false;
        }
        
        public void imprimete(){
@@ -32,6 +34,7 @@ public class Booking implements Serializable {
                System.out.println(bookingDate);
                System.out.println(telephone);
                System.out.println(offer);              
+               System.out.println(this.isAccepted);    
        }
 
        public int getBookNumber() {
@@ -78,4 +81,8 @@ public class Booking implements Serializable {
                return isPaid;
        }
        
+       public boolean isAccepted(){
+               return this.isAccepted;
+       }
+       
 }
\ No newline at end of file
index 4f73bb9..2f846eb 100644 (file)
@@ -82,8 +82,6 @@ public class RuralHouse implements Serializable {
                return off;
        }
 
-
-
        @Override
        public boolean equals(Object obj) {
                if (this == obj)
@@ -128,15 +126,8 @@ public class RuralHouse implements Serializable {
        }
 
        public Vector<Offer> getAllOffers() {
-               Vector<Offer> availableOffers = new Vector<Offer>();
-               Iterator<Offer> e = offers.iterator();
-               Offer offer;
-               while (e.hasNext()) {
-                       offer = e.next();
-                       if ((offer.getBooking() == null))
-                               availableOffers.add(offer);
-               }
-               return availableOffers;
+
+               return this.offers;
        }
 
        /**
@@ -176,5 +167,4 @@ public class RuralHouse implements Serializable {
 
        }
 
-
 }
index 0c82313..a185a21 100644 (file)
@@ -55,14 +55,17 @@ public class AdminMenuGUI extends JFrame {
                                a.setVisible(true);
                        }
                });
+               
+               JButton btnOwneraddition = new JButton("OwnerAddition");
                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.LEADING)
-                                               .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
-                                               .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
+                                       .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(
@@ -72,9 +75,10 @@ public class AdminMenuGUI extends JFrame {
                                        .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
                                        .addGap(58)
                                        .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
-                                       .addContainerGap(142, Short.MAX_VALUE))
+                                       .addGap(52)
+                                       .addComponent(btnOwneraddition, GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
+                                       .addContainerGap())
                );
                contentPane.setLayout(gl_contentPane);
        }
-
 }
index 28097a7..5237f93 100644 (file)
@@ -54,12 +54,12 @@ public class HouseFeaturesGUI extends JFrame {
        private int row;
        private JLabel labelPhone;
 
-
        /**
         * Create the frame.
         */
 
-       public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay, final Date LastDay) {
+       public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay,
+                       final Date LastDay) {
                this.rh = RH;
                this.getContentPane().setLayout(null);
                setBounds(100, 100, 500, 583);
@@ -187,11 +187,11 @@ public class HouseFeaturesGUI extends JFrame {
                lblNewLabel.setEnabled(false);
                lblNewLabel.setBounds(170, 282, 261, 23);
                contentPane.add(lblNewLabel);
-               
+
                JLabel lblNewLabel_1 = new JLabel("Telephone num:");
                lblNewLabel_1.setBounds(10, 509, 83, 14);
                contentPane.add(lblNewLabel_1);
-               
+
                telIn = new JTextField();
                telIn.setBounds(99, 505, 129, 20);
                contentPane.add(telIn);
@@ -201,7 +201,7 @@ public class HouseFeaturesGUI extends JFrame {
                labelPhone.setBounds(238, 252, 178, 14);
                contentPane.add(labelPhone);
 
-               table.addMouseListener( new MouseAdapter(){                     
+               table.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent arg0) {
                                row = table.getSelectedRow();
@@ -210,13 +210,14 @@ public class HouseFeaturesGUI extends JFrame {
                Enumeration<Offer> rhs = rh.getAllOffers().elements();
                while (rhs.hasMoreElements()) {
                        Offer of = rhs.nextElement();
-                       Vector<Object> row = new Vector<Object>();
-                       row.add(of.getOfferNumber());
-                       row.add(of.getFirstDay());
-                       row.add(of.getLastDay());
-                       row.add(of.getPrice());
-                       tableModel.addRow(row);
-
+                       if (of.getBooking() == null) {
+                               Vector<Object> row = new Vector<Object>();
+                               row.add(of.getOfferNumber());
+                               row.add(of.getFirstDay());
+                               row.add(of.getLastDay());
+                               row.add(of.getPrice());
+                               tableModel.addRow(row);
+                       }
                }
                table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
                        /**
@@ -235,7 +236,7 @@ public class HouseFeaturesGUI extends JFrame {
                                Date firstDay = (Date) table.getModel().getValueAt(row, 1);
                                Date lastDay = (Date) table.getModel().getValueAt(row, 2);
                                if (FirstDay != null && LastDay != null) {
-                                       if (LastDay.before(lastDay)  ||  FirstDay.after(firstDay)) {
+                                       if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
                                                setBackground(Color.RED);
                                                setForeground(Color.BLACK);
                                        } else {
@@ -250,16 +251,18 @@ public class HouseFeaturesGUI extends JFrame {
 
        private void jButton_ActionPerformed(ActionEvent arg0) {
                BookingManager bookingM = new BookingManager();
-               //RegExp to see if telephone number is correct??TODO
+               // RegExp to see if telephone number is correct??TODO
                if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) {
                        labelPhone.setText("");
                        Booking book = null;
                        try {
-                               if (table.getRowCount()!=0)
-                                       book = bookingM.createBooking(rh, rh.offers.get(row).getFirstDay(), rh.offers.get(row).getLastDay(), telIn.getText());
+                               if (table.getRowCount() != 0)
+                                       book = bookingM.createBooking(rh, rh.offers.get(row)
+                                                       .getFirstDay(), rh.offers.get(row).getLastDay(),
+                                                       telIn.getText());
                        } catch (Exception e) {
                                e.printStackTrace();
-                       } 
+                       }
                        if (book != null) {
                                BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
                                                book);
@@ -268,7 +271,6 @@ public class HouseFeaturesGUI extends JFrame {
                } else {
                        labelPhone.setText("Phone format is wrong");
 
-               
                }
        }
 }
index 59f7542..8f97c1e 100644 (file)
@@ -12,6 +12,7 @@ import javax.swing.JPanel;
 import javax.swing.border.EmptyBorder;
 
 import domain.Owner;
+import javax.swing.LayoutStyle.ComponentPlacement;
 
 public class OwnerMenuGUI extends JFrame {
 
@@ -42,7 +43,7 @@ public class OwnerMenuGUI extends JFrame {
                                a.setVisible(true);
                        }
                });
-               
+
                JButton btnOffers = new JButton("Offers");
                btnOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
@@ -50,14 +51,23 @@ public class OwnerMenuGUI extends JFrame {
                                a.setVisible(true);
                        }
                });
+               
+               JButton btnBookings = new JButton("Bookings");
+               btnBookings.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               Frame a = new listOfBookingRequestsGUI(owner);
+                               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.LEADING)
-                                               .addComponent(btnOffers, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
-                                               .addComponent(btnHouses, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
+                                       .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
+                                               .addComponent(btnBookings, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                               .addComponent(btnOffers, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
+                                               .addComponent(btnHouses, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                                        .addContainerGap(145, Short.MAX_VALUE))
                );
                gl_contentPane.setVerticalGroup(
@@ -67,7 +77,9 @@ public class OwnerMenuGUI extends JFrame {
                                        .addComponent(btnHouses, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
                                        .addGap(58)
                                        .addComponent(btnOffers, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
-                                       .addContainerGap(142, Short.MAX_VALUE))
+                                       .addPreferredGap(ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
+                                       .addComponent(btnBookings, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
+                                       .addContainerGap())
                );
                contentPane.setLayout(gl_contentPane);
        }
index 7495777..80e1800 100644 (file)
@@ -5,6 +5,7 @@ import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.Enumeration;
+import java.util.LinkedList;
 import java.util.Vector;
 
 import javax.swing.JButton;
@@ -16,10 +17,10 @@ import javax.swing.JTable;
 import javax.swing.border.EmptyBorder;
 import javax.swing.table.DefaultTableModel;
 
-import businessLogic.AdminManager;
-import businessLogic.HouseManager;
-import businessLogic.HouseManagerInterface;
-import domain.Administrator;
+import businessLogic.BookingManager;
+import domain.Booking;
+import domain.Offer;
+import domain.Owner;
 import domain.RuralHouse;
 
 public class listOfBookingRequestsGUI extends JFrame {
@@ -30,16 +31,19 @@ public class listOfBookingRequestsGUI extends JFrame {
        private static final long serialVersionUID = 1L;
        private JPanel contentPane;
        private JTable table;
+       private Owner own;
+       private BookingManager bookM = new BookingManager();
        private DefaultTableModel tableModel;
-       private AdminManager am = new AdminManager();
-       private Vector<RuralHouse> houses;
-       /**
+       private Vector<Booking> bookings = new Vector<Booking>();
+
+       /**
         * Create the frame.
         */
-       public listOfBookingRequestsGUI() {
-               setTitle("Adding requests");
+       public listOfBookingRequestsGUI(Owner own) {
+               setTitle("Adding requests");
+               this.own = own;
                try {
-                       this.houses= am.getAdditionRequests();
+
                        init();
                } catch (Exception e) {
                        e.printStackTrace();
@@ -52,80 +56,69 @@ public class listOfBookingRequestsGUI extends JFrame {
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                contentPane.setLayout(null);
-
+               
+               this.bookings= this.bookM.getAllBookings(own);
                JLabel lblNewLabel = new JLabel();
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
-               if (houses.isEmpty())
-                       lblNewLabel.setText("There are not houses to be added");
+               if (bookings.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not bookings to be confirmed or denied");
                else
-                       lblNewLabel.setText("List of houses to be added:");
+                       lblNewLabel.setText("List of bookings:");
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
                contentPane.add(scrollPane);
 
                table = new JTable() {
-               private static final long serialVersionUID = 1L;
+                       private static final long serialVersionUID = 1L;
 
-               public boolean isCellEditable(int row, int column) {                
-                       return false;               
-               };
-           };
+                       public boolean isCellEditable(int row, int column) {
+                               return false;
+                       };
+               };
                scrollPane.setViewportView(table);
                tableModel = new DefaultTableModel(null, new String[] {
-                               "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
-                               "Livings" });
-               
-               //Maybe there is a better way to avoid interaction.
-               //table.setEnabled(false);
+                               "Booking Number", "Is paid", "Booking Date", "Telephone",
+                               "Offer" });
+
+               // Maybe there is a better way to avoid interaction.
+               // table.setEnabled(false);
                table.setModel(tableModel);
-               
-               JButton btnNewButton = new JButton("Confirm Addition");
+
+               JButton btnNewButton = new JButton("Confirm Booking");
                btnNewButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
-                                       HouseManagerInterface hm = new HouseManager();
-                                       RuralHouse rh = houses.get(table.getSelectedRow());
-                                       //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
-                                       hm.registerNewHouse(rh);
-                                       am.removeHouseAdditionRequests(rh);
-                                       Administrator.saveInstance();
-                                       ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
-                                       houses.remove(rh);
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+
                                }
                        }
                });
                btnNewButton.setBounds(88, 396, 169, 25);
                contentPane.add(btnNewButton);
-               
-               JButton btnDenyAddition = new JButton("Deny Addition");
+
+               JButton btnDenyAddition = new JButton("Deny Booking");
                btnDenyAddition.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
-                               if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
-                                       RuralHouse rh = houses.get(table.getSelectedRow());
-                                       am.removeHouseAdditionRequests(rh);
-                                       Administrator.saveInstance();
-                                       ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
-                                       houses.remove(rh);
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+
                                }
                        }
                });
                btnDenyAddition.setBounds(300, 396, 169, 25);
                contentPane.add(btnDenyAddition);
-               Enumeration<RuralHouse> en = houses.elements();
-               RuralHouse rh;
-               
+               Enumeration<Booking> en = this.bookings.elements();
+               Booking book;
                while (en.hasMoreElements()) {
-                       rh = en.nextElement();
+                       book = en.nextElement();
                        Vector<Object> row = new Vector<Object>();
-                       row.add(rh.getHouseName());
-                       row.add(rh.getFeatures().getnRooms());
-                       row.add(rh.getFeatures().getnKitchens());
-                       row.add(rh.getFeatures().getnBaths());
-                       row.add(rh.getFeatures().getnParkings());
-                       row.add(rh.getFeatures().getnLivings());
+                       row.add(book.getBookNumber());
+                       row.add(book.isPaid());
+                       row.add(book.getBookDate());
+                       row.add(book.getTelephone());
+                       row.add(book.getOffer());
                        tableModel.addRow(row);
                }