House Features added and logic for adding options to the owner
authorcamjan <jcampos004@ikasle.ehu.es>
Wed, 4 Mar 2015 18:42:47 +0000 (19:42 +0100)
committercamjan <jcampos004@ikasle.ehu.es>
Wed, 4 Mar 2015 18:42:47 +0000 (19:42 +0100)
ruralHouses/src/businessLogic/ApplicationFacadeInterface.java
ruralHouses/src/businessLogic/FacadeImplementation.java
ruralHouses/src/businessLogic/HouseManager.java
ruralHouses/src/businessLogic/HouseManagerInterface.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Owner.java
ruralHouses/src/domain/RuralHouse.java
ruralHouses/src/gui/LoginGUI.java [moved from ruralHouses/src/gui/IntroduceOfferGUI.java with 70% similarity]
ruralHouses/src/gui/StartWindow.java

index 8863af3..ef3cad2 100644 (file)
@@ -1,7 +1,6 @@
 package businessLogic;
 
 import java.rmi.*;
-
 import java.util.Vector;
 import java.util.Date;
 
@@ -9,23 +8,13 @@ import domain.Booking;
 import domain.Offer;
 import domain.Owner;
 import domain.RuralHouse;
-
-import exceptions.OfferCanNotBeBooked; 
+import exceptions.OfferCanNotBeBooked;
 
 public interface ApplicationFacadeInterface extends Remote {
 
        /**
-        * This method obtains an owner's rural houses 
-        * 
-        * @param owner object
-        *            
-        * @return a vector of Rural Houses
-        */
-       Vector<RuralHouse> getRuralHouses(Owner owner)
-                       throws RemoteException;
-
-       /**
-        * This method creates an offer with a house number, first day, last day and price
+        * This method creates an offer with a house number, first day, last day and
+        * price
         * 
         * @param House
         *            number, start day, last day and price
@@ -46,26 +35,38 @@ public interface ApplicationFacadeInterface extends Remote {
                        String telephoneNumber) throws RemoteException, OfferCanNotBeBooked;
 
        /**
-        * This method obtains available offers for a concrete house in a certain period 
+        * This method obtains available offers for a concrete house in a certain
+        * period
         * 
-        * @param houseNumber, the house number where the offers must be obtained 
-        * @param firstDay, first day in a period range 
-        * @param lastDay, last day in a period range
-        * @return a vector of offers(Offer class)  available  in this period
+        * @param houseNumber
+        *            , the house number where the offers must be obtained
+        * @param firstDay
+        *            , first day in a period range
+        * @param lastDay
+        *            , last day in a period range
+        * @return a vector of offers(Offer class) available in this period
         */
-       Vector<Offer> getOffers(RuralHouse houseNumber, Date firstDay, Date lastDay) 
+       Vector<Offer> getOffers(RuralHouse houseNumber, Date firstDay, Date lastDay)
                        throws RemoteException, Exception;
-       
+
        /**
-        * This method finds existing  owners 
+        * This method finds existing owners
         * 
         */
-       public Vector<Owner> getOwners() throws RemoteException,
+       public Vector<Owner> getOwners() throws RemoteException, Exception;
+
+       /**
+        * This method obtains an owner's rural houses
+        * 
+        * @param owner
+        *            object
+        * 
+        * @return a vector of Rural Houses
+        */
+       public Vector<RuralHouse> getRuralHouses(Owner owner)
+                       throws RemoteException;
+
+       public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
                        Exception;
-       
-       
-       
-       public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
-       Exception;
-       
+
 }
\ No newline at end of file
index 162a38b..9c2e8b1 100644 (file)
@@ -2,23 +2,19 @@ package businessLogic;
 
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
-
 import java.util.Date;
 import java.util.Vector;
-
 import java.sql.SQLException;
 
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
-import configuration.Config;
 
+import configuration.Config;
 import dataAccess.DB4oManager;
-
 import domain.Booking;
 import domain.Offer;
 import domain.Owner;
 import domain.RuralHouse;
-
 import exceptions.OfferCanNotBeBooked;
 
 public class FacadeImplementation extends UnicastRemoteObject implements ApplicationFacadeInterface {
@@ -31,17 +27,6 @@ public class FacadeImplementation extends UnicastRemoteObject implements Applica
                dbMngr = DB4oManager.getInstance();
        }
 
-       /**
-        * This method obtains an owner's rural houses 
-        * 
-        * @param owner object
-        *            
-        * @return a vector of Rural Houses
-        */
-       public Vector<RuralHouse> getRuralHouses(Owner owner)
-                       throws RemoteException {
-               return owner.getRuralHouses();          
-       }
 
        public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
                        float price) throws RemoteException, Exception {                 
@@ -70,11 +55,23 @@ public class FacadeImplementation extends UnicastRemoteObject implements Applica
                return dbMngr.getOwners();
        } 
 
+       /**
+        * This method obtains an owner's rural houses 
+        * 
+        * @param owner object
+        *            
+        * @return a vector of Rural Houses
+        */
+       public Vector<RuralHouse> getRuralHouses(Owner owner)
+                       throws RemoteException {
+               return owner.getRuralHouses();          
+       }
+
+
        public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
        Exception {             
                return dbMngr.getAllRuralHouses();              
        }
-
        
 
        public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
index a876bcd..21b8925 100644 (file)
@@ -1,10 +1,12 @@
 package businessLogic;
 
+import java.rmi.RemoteException;
 import java.util.Date;
 import java.util.Vector;
 
 import dataAccess.DB4oManager;
 import domain.Account;
+import domain.HouseFeatures;
 import domain.Offer;
 import domain.Owner;
 import domain.RuralHouse;
@@ -25,16 +27,14 @@ public class HouseManager implements HouseManagerInterface {
        public boolean registerNewHouse(int houseNumber, Owner owner, String town,
                        int nRooms, int nKitchens, int nBaths, int nLivings, int nParkings) {
                // TODO Auto-generated method stub
+               boolean stored = false;
                if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
                        return false;
-               try {
-                       this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber, owner,
-                                       town, nRooms, nKitchens, nBaths, nLivings, nParkings));
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-               return true;
+               HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths,
+                               nLivings, nParkings);
+               stored = this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber,
+                               owner, town, feature));
+               return stored;
 
        }
 
@@ -43,39 +43,30 @@ public class HouseManager implements HouseManagerInterface {
                        String description, String town, int nRooms, int nKitchens,
                        int nBaths, int nLivings, int nParkings) {
                // TODO Auto-generated method stub
+               boolean stored = false;
                if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
                        return false;
-               try {
-                       this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber, owner,
-                                       description, town, nRooms, nKitchens, nBaths, nLivings,
-                                       nParkings));
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-               return true;
+               HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths,
+                               nLivings, nParkings);
+               stored = this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber,
+                               owner, description, town, feature));
+               return stored;
        }
 
-       @Override
-       public void modifyHouse(int houseNumber, Owner owner, String description,
-                       String town, int nRooms, int nKitchens, int nBaths, int nLivings,
-                       int nParkings) {
-               // TODO Auto-generated method stub
-               
-       }
-       
-       //Maybe returning the offer is not necessary. Depends on GUI implementation.
-       @Override
-       public Offer setOffers(RuralHouse ruralHouse, Date firstDay, Date lastDay,
-                       float price) {
-               // TODO Auto-generated method stub
-               try {
-                       return this.dbMngr.createOffer(ruralHouse, firstDay, lastDay, price);
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-               return null;
+       public void removeHouse(int houseNumber) {
+               this.dbMngr.removeHouse(houseNumber);
        }
 
+       // For future implementation
+       // @Override
+       // public void modifyHouse(int houseNumber, Owner owner, String description,
+       // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
+       // int nParkings) {
+       // // TODO Auto-generated method stub
+       //
+       // }
+
+       // Maybe returning the offer is not necessary. Depends on GUI
+       // implementation.
+
 }
index 29c97d5..7a0656f 100644 (file)
@@ -1,6 +1,8 @@
 package businessLogic;
 
+import java.rmi.RemoteException;
 import java.util.Date;
+import java.util.Vector;
 
 import domain.Offer;
 import domain.Owner;
@@ -15,11 +17,12 @@ public interface HouseManagerInterface {
                        String description, String town, int nRooms, int nKitchens,
                        int nBaths, int nLivings, int nParkings);
 
-       public void modifyHouse(int houseNumber, Owner owner,
-                       String description, String town, int nRooms, int nKitchens,
-                       int nBaths, int nLivings, int nParkings);
+       // For future implementation
+       // public void modifyHouse(int houseNumber, Owner owner,
+       // String description, String town, int nRooms, int nKitchens,
+       // int nBaths, int nLivings, int nParkings);
+
+       public void removeHouse(int houseNumber);
 
-       public Offer setOffers(RuralHouse ruralHouse, Date firstDay, Date lastDay,
-                       float price);
 
 }
index 295af73..26fa6f3 100644 (file)
@@ -79,15 +79,23 @@ public class DB4oManager {
        /**
         * @param rh
         */
-       public void storeRuralHouses(RuralHouse rh) {
+       public boolean storeRuralHouses(RuralHouse rh) {
                DB4oManager.openDatabase("open");
+               boolean stored = false;
                ObjectContainer db = DB4oManager.getContainer();
+               RuralHouse house = new RuralHouse(rh.getHouseNumber(), null, null,
+                               null, null);
                try {
-                       db.store(rh);
-                       db.commit();
+                       ObjectSet<Owner> result = db.queryByExample(house);
+                       if (result.isEmpty()) {
+                               db.store(rh);
+                               db.commit();
+                               stored = true;
+                       }
                } finally {
                        db.close();
                }
+               return stored;
        }
 
        /**
@@ -144,8 +152,7 @@ public class DB4oManager {
                DB4oManager.openDatabase("open");
                ObjectContainer db = DB4oManager.getContainer();
                try {
-                       RuralHouse proto = new RuralHouse(0, null, null, null, 0, 0, 0, 0,
-                                       0);
+                       RuralHouse proto = new RuralHouse(0, null, null, null, null);
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
                        while (result.hasNext())
@@ -171,8 +178,8 @@ public class DB4oManager {
                Offer o;
                try {
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
-                                       null, ruralHouse.getDescription(), ruralHouse.getTown(), 0,
-                                       0, 0, 0, 0);
+                                       null, ruralHouse.getDescription(), ruralHouse.getTown(),
+                                       ruralHouse.getFeatures());
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        RuralHouse rh = (RuralHouse) result.next();
                        o = rh.createOffer(firstDay, lastDay, price);
@@ -194,7 +201,7 @@ public class DB4oManager {
                try {
                        ObjectContainer db = DB4oManager.getContainer();
                        RuralHouse proto = new RuralHouse(rh.getHouseNumber(), null,
-                                       rh.getDescription(), rh.getTown(), 0, 0, 0, 0, 0);
+                                       rh.getDescription(), rh.getTown(), rh.getFeatures());
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        return rh = (RuralHouse) result.next();
                } catch (Exception exc) {
@@ -231,6 +238,24 @@ public class DB4oManager {
                }
        }
 
+       public void removeHouse(int houseNumber) {
+               ObjectContainer db = DB4oManager.getContainer();
+               RuralHouse house = new RuralHouse(houseNumber, null, null, null, null);
+               try {
+                       ObjectSet<RuralHouse> result = db.queryByExample(house);
+                       if (!result.isEmpty()) {
+                               RuralHouse found = (RuralHouse) result.get(0);
+                               db.delete(found);
+                               db.commit();
+                       }
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+               } finally {
+                       db.close();
+               }
+
+       }
+
        /**
         * This method returns the instance of the DB4oManager class
         * 
index 9a34067..35b0296 100644 (file)
@@ -43,8 +43,8 @@ public class Owner implements Serializable {
 
        public RuralHouse addRuralHouse(int houseNumber, String town, int nRooms,
                        int nKitchens, int nBaths, int nLivings, int nParkings) {
-               RuralHouse rh = new RuralHouse(houseNumber, this, town, nRooms,
-                               nKitchens, nBaths, nLivings, nParkings);
+               HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, nLivings, nParkings);
+               RuralHouse rh = new RuralHouse(houseNumber, this, town,feature);
                ruralHouses.add(rh);
                return rh;
        }
@@ -52,8 +52,8 @@ public class Owner implements Serializable {
        public RuralHouse addRuralHouse(int houseNumber, String description,
                        String town, int nRooms, int nKitchens, int nBaths, int nLivings,
                        int nParkings) {
-               RuralHouse rh = new RuralHouse(houseNumber, this, description, town,
-                               nRooms, nKitchens, nBaths, nLivings, nParkings);
+               HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, nLivings, nParkings);
+               RuralHouse rh = new RuralHouse(houseNumber, this, description, town,feature);
                ruralHouses.add(rh);
                return rh;
        }
index d499c88..50e46fa 100644 (file)
@@ -20,23 +20,21 @@ public class RuralHouse implements Serializable {
                super();
        }
 
-       public RuralHouse(int houseNumber, Owner owner, String description, String town , int nRooms,int nKitchens,int nBaths, 
-                       int nLivings,int nParkings) {
+       public RuralHouse(int houseNumber, Owner owner, String description, String town ,HouseFeatures features) {
                this.houseNumber = houseNumber;
                this.description = description;
                this.owner = owner;
                this.town = town;
-               this.features = new HouseFeatures(nRooms,nKitchens,nBaths,nLivings,nParkings);
+               this.features = features;
                offers=new Vector<Offer>();
        }
        
-       public RuralHouse(int houseNumber, Owner owner, String town , int nRooms,int nKitchens,int nBaths, 
-                       int nLivings,int nParkings) {
+       public RuralHouse(int houseNumber, Owner owner, String town , HouseFeatures features) {
                this.houseNumber = houseNumber;
                this.description = null;
                this.owner = owner;
                this.town = town;
-               this.features = new HouseFeatures(nRooms,nKitchens,nBaths,nLivings,nParkings);
+               this.features = features;
                offers=new Vector<Offer>();
        }
 
@@ -71,7 +69,13 @@ public class RuralHouse implements Serializable {
        public void setTown(String town) {
                this.town=town;
        }
-       
+       public HouseFeatures getFeatures() {
+               return features;
+       }
+
+       public void setFeatures(HouseFeatures features) {
+               this.features = features;
+       }       
        public String toString() {
                return this.houseNumber + ": " + this.town;
        }
@@ -136,6 +140,7 @@ public class RuralHouse implements Serializable {
                return availableOffers;
        }
        
+       
        /**
         * This method obtains the offer that match exactly with a given dates that has not been booked
         * 
similarity index 70%
rename from ruralHouses/src/gui/IntroduceOfferGUI.java
rename to ruralHouses/src/gui/LoginGUI.java
index ee56946..ef333d6 100644 (file)
@@ -14,7 +14,7 @@ import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
 import java.awt.Color;
 
-public class IntroduceOfferGUI extends JFrame {
+public class LoginGUI extends JFrame {
 
        private static final long serialVersionUID= 1L;
        private JPanel jContentPane = null;
@@ -23,7 +23,7 @@ public class IntroduceOfferGUI extends JFrame {
        private LoginManagerInterface loginManager = new LoginManager();
        private JLabel loginFeedback;
 
-       public IntroduceOfferGUI() {
+       public LoginGUI() {
                super();
                initialize();
        }
@@ -60,25 +60,8 @@ public class IntroduceOfferGUI extends JFrame {
                        JButton loginButton = new JButton("Login");
                        loginButton.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
-                                       Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
-                                       if(owner==null){
-                                               loginFeedback.setText("Incorrect username or password");
-                                       }else{
-                                               Vector<RuralHouse> ownerHouseList=null;
-                                               try{
-                                                       ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
-                                               }catch (Exception e){
-                                                       e.printStackTrace();
-                                               }
-                                               if(!ownerHouseList.isEmpty()){
-                                                       Frame a = new IntroduceOffer2GUI(ownerHouseList);       
-                                                       a.setVisible(true);
-                                               }
-                                               else if(ownerHouseList.isEmpty())
-                                                       loginFeedback.setText("Login OK , but no houses in your name");
-                                       }
-
-                               }
+                               jButton_ActionPerformed(arg0);  
+                               }                                       
                        });
                        loginButton.setBounds(164, 179, 117, 25);
                        jContentPane.add(loginButton);
@@ -91,7 +74,28 @@ public class IntroduceOfferGUI extends JFrame {
                }
                return jContentPane;
        }
+       
+       private void jButton_ActionPerformed(ActionEvent e){
+               Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
+               if(owner==null){
+                       loginFeedback.setText("Incorrect username or password");
+               }else{
+                       Vector<RuralHouse> ownerHouseList=null;
+                       try{
+                               ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
+                       }catch (Exception e1){
+                               e1.printStackTrace();
+                       }
+                       if(!ownerHouseList.isEmpty()){
+                               this.setVisible(false);
+                               Frame a = new IntroduceOffer2GUI(ownerHouseList);
+                               a.setVisible(true);
+                       }
+                       else if(ownerHouseList.isEmpty())
+                               loginFeedback.setText("Login OK , but no houses in your name");
+               }
 
+       }
 
 }  // @jve:decl-index=0:visual-constraint="222,33"
 
index f5e5b10..54fe389 100644 (file)
@@ -87,7 +87,7 @@ public class StartWindow extends JFrame {
                        createOfferButton.setAlignmentX(Component.CENTER_ALIGNMENT);
                        createOfferButton.addActionListener(new java.awt.event.ActionListener() {
                                public void actionPerformed(java.awt.event.ActionEvent e) {
-                                       JFrame a = new IntroduceOfferGUI();
+                                       JFrame a = new LoginGUI();
                                        a.setVisible(true);
                                }
                        });