Booking deletion fixed some minor problems remain
authorcamjan <jcampos004@ikasle.ehu.es>
Wed, 20 May 2015 09:05:53 +0000 (11:05 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Wed, 20 May 2015 09:05:53 +0000 (11:05 +0200)
ruralHouses client/src/gui/DeleteOfferGUI.java
ruralHouses client/src/gui/listOfBookingRequestsGUI.java
ruralHouses client/src/gui/listOfOwnerAddittionRequests.java
ruralHouses client/src/gui/listOfRemovalRequestsGUI.java
ruralHouses/src/businessLogic/LoginManager.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Booking.java

index 0ed19e8..7c1903d 100644 (file)
@@ -5,6 +5,7 @@ import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.rmi.Naming;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.rmi.Naming;
+import java.rmi.RemoteException;
 import java.util.Vector;
 
 import javax.swing.JButton;
 import java.util.Vector;
 
 import javax.swing.JButton;
@@ -15,8 +16,8 @@ import javax.swing.JPanel;
 import javax.swing.JRadioButton;
 import javax.swing.border.EmptyBorder;
 
 import javax.swing.JRadioButton;
 import javax.swing.border.EmptyBorder;
 
+import common.HouseInterface;
 import common.OfferInterface;
 import common.OfferInterface;
-
 import configuration.___IntNames;
 import domain.Offer;
 import domain.Owner;
 import configuration.___IntNames;
 import domain.Offer;
 import domain.Owner;
@@ -29,23 +30,35 @@ public class DeleteOfferGUI extends JFrame {
         */
        private static final long serialVersionUID = 1L;
        private JPanel contentPane;
         */
        private static final long serialVersionUID = 1L;
        private JPanel contentPane;
-       private Owner owner;
        private JLabel feedback;
        private JComboBox<RuralHouse> comboBox;
        private JComboBox<Offer> comboBox_1;
        private JButton btnDelete;
        private JLabel feedback;
        private JComboBox<RuralHouse> comboBox;
        private JComboBox<Offer> comboBox_1;
        private JButton btnDelete;
+       private Vector<RuralHouse> Hlist = null;
+       private HouseInterface hm = null;
 
        /**
         * Create the frame.
         */
        public DeleteOfferGUI(Owner o) {
 
        /**
         * Create the frame.
         */
        public DeleteOfferGUI(Owner o) {
-               this.owner = o;
+               try {
+                       hm = (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               try {
+                       Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
+               } catch (RemoteException e1) {
+                       e1.printStackTrace();
+               }       
                setBounds(100, 100, 450, 300);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
 
                setBounds(100, 100, 450, 300);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
 
-               comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
+               comboBox = new JComboBox<RuralHouse>(this.Hlist);
                comboBox.setBounds(101, 38, 314, 20);
 
                comboBox_1 = new JComboBox<Offer>();
                comboBox.setBounds(101, 38, 314, 20);
 
                comboBox_1 = new JComboBox<Offer>();
index f0cb7db..423ea4d 100644 (file)
@@ -67,11 +67,6 @@ public class listOfBookingRequestsGUI extends JFrame {
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
-               if (bookings.isEmpty())
-                       lblNewLabel
-                                       .setText("There are not bookings to be confirmed or denied");
-               else
-                       lblNewLabel.setText("List of bookings:");
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
@@ -141,16 +136,22 @@ public class listOfBookingRequestsGUI extends JFrame {
                                        }
                                        ((DefaultTableModel) table.getModel()).removeRow(table
                                                        .getSelectedRow());
                                        }
                                        ((DefaultTableModel) table.getModel()).removeRow(table
                                                        .getSelectedRow());
+                                       bookings.remove(book);
 
                                }
                        }
                });
 
                                }
                        }
                });
-
-               if (this.bookings.get(0).getOffer().isBooked()) {
-                       btnDenyAddition.setEnabled(false);
-                       btnNewButton.setEnabled(false);
+               if (bookings.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not bookings to be confirmed or denied");
+               else {
+                       lblNewLabel.setText("List of bookings:");
+                       if (this.bookings.get(0).getOffer().isBooked()) {
+                               btnDenyAddition.setEnabled(false);
+                               btnNewButton.setEnabled(false);
+                       }
                }
                }
-
+               
                btnDenyAddition.setBounds(390, 395, 169, 25);
                contentPane.add(btnDenyAddition);
 
                btnDenyAddition.setBounds(390, 395, 169, 25);
                contentPane.add(btnDenyAddition);
 
index d72bd98..b3297b4 100644 (file)
@@ -119,6 +119,7 @@ public class listOfOwnerAddittionRequests extends JFrame {
                                        }
                                        
                                        ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
                                        }
                                        
                                        ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
+                                       
                                }
                        }
                });
                                }
                        }
                });
index 071ee51..a85c246 100644 (file)
@@ -109,11 +109,11 @@ public class listOfRemovalRequestsGUI extends JFrame {
                                                am.removeHouseDeletionRequests(rh);
                                                am.saveInstance();
                                        } catch (RemoteException e1) {
                                                am.removeHouseDeletionRequests(rh);
                                                am.saveInstance();
                                        } catch (RemoteException e1) {
-                                               // TODO Auto-generated catch block
                                                e1.printStackTrace();
                                        }
                                        ((DefaultTableModel) table.getModel()).removeRow(houses
                                                        .indexOf(rh));
                                                e1.printStackTrace();
                                        }
                                        ((DefaultTableModel) table.getModel()).removeRow(houses
                                                        .indexOf(rh));
+                                       houses.remove(rh);
 
                                }
                        }
 
                                }
                        }
index e0f0439..f3c4600 100644 (file)
@@ -24,7 +24,6 @@ public class LoginManager extends UnicastRemoteObject implements LoginInterface
                try {
                        dbMngr = DB4oManager.getInstance();
                } catch (Exception e) {
                try {
                        dbMngr = DB4oManager.getInstance();
                } catch (Exception e) {
-                       // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
                        e.printStackTrace();
                }
        }
index 0f17aeb..a677c95 100644 (file)
@@ -85,8 +85,7 @@ public class DB4oManager {
                configuration.common().objectClass(Booking.class).cascadeOnDelete(true);
                configuration.common().objectClass(RuralHouse.class)
                                .cascadeOnDelete(true);
                configuration.common().objectClass(Booking.class).cascadeOnDelete(true);
                configuration.common().objectClass(RuralHouse.class)
                                .cascadeOnDelete(true);
-               configuration.common().objectClass(Account.class)
-               .cascadeOnDelete(true);
+               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());
                configuration.common().objectClass(Offer.class).cascadeOnDelete(true);
                configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
                db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
@@ -222,14 +221,15 @@ public class DB4oManager {
                }
        }
 
                }
        }
 
-       public Vector<Offer> getRHsOffer(String name){
+       public Vector<Offer> getRHsOffer(String name) {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
 
                try {
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                        openDB();
 
                try {
-                       RuralHouse rh = (RuralHouse)db.queryByExample(new RuralHouse(name, null, null, null, null)).get(0);
+                       RuralHouse rh = (RuralHouse) db.queryByExample(
+                                       new RuralHouse(name, null, null, null, null)).get(0);
                        Offer proto = new Offer(0, rh, null, null, 0);
                        ObjectSet<Offer> result = db.queryByExample(proto);
                        return new Vector<Offer>(result);
                        Offer proto = new Offer(0, rh, null, null, 0);
                        ObjectSet<Offer> result = db.queryByExample(proto);
                        return new Vector<Offer>(result);
@@ -237,8 +237,8 @@ public class DB4oManager {
                        db.close();
                }
        }
                        db.close();
                }
        }
-       
-       public Administrator getAdminData(){
+
+       public Administrator getAdminData() {
 
                if (c.isDatabaseLocal() == false)
                        openSDB();
 
                if (c.isDatabaseLocal() == false)
                        openSDB();
@@ -374,7 +374,6 @@ public class DB4oManager {
                }
        }
 
                }
        }
 
-       
        public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
                        Exception {
 
        public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
                        Exception {
 
@@ -511,8 +510,8 @@ public class DB4oManager {
 
        }
 
 
        }
 
-       public Vector<RuralHouse> getRuralHouses(Owner ow, String name, String town,
-                       int nBed, int nKit, int nBath, int nPark, int nLiv) {
+       public Vector<RuralHouse> getRuralHouses(Owner ow, String name,
+                       String town, int nBed, int nKit, int nBath, int nPark, int nLiv) {
                HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
                RuralHouse rh = new RuralHouse(name, ow, null, town, fea);
                if (c.isDatabaseLocal() == false)
                HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
                RuralHouse rh = new RuralHouse(name, ow, null, town, fea);
                if (c.isDatabaseLocal() == false)
@@ -607,10 +606,15 @@ public class DB4oManager {
                else
                        openDB();
                try {
                else
                        openDB();
                try {
-                       ObjectSet<Booking> result = db.queryByExample(b);
-                       result.get(0).getOffer().getBookings().remove(b);
-                       db.store(result.get(0).getOffer());
-                       db.delete(result.get(0));
+                       Booking book = new Booking(b.getBookNumber(), new Offer(b
+                                       .getOffer().getOfferNumber(), new RuralHouse(b.getOffer()
+                                       .getRuralHouse().getHouseName(), null, null, null, null),
+                                       null, null, 0), b.getClient(), b.getBookDate());
+
+                       ObjectSet<Booking> result = db.queryByExample(book);
+                       Offer of = result.get(0).getOffer();
+                       of.getBookings().remove(result.get(0));
+                       db.store(of);
                        db.commit();
                } catch (Exception e) {
                        e.printStackTrace();
                        db.commit();
                } catch (Exception e) {
                        e.printStackTrace();
index cdde621..60cfd2f 100644 (file)
@@ -3,7 +3,7 @@ package domain;
 import java.io.Serializable;
 import java.util.Date;
 
 import java.io.Serializable;
 import java.util.Date;
 
-public class Booking implements Serializable  {
+public class Booking implements Serializable {
 
        /**
         * 
 
        /**
         * 
@@ -13,25 +13,29 @@ public class Booking implements Serializable  {
        private Date bookingDate;
        private Client client;
        private Offer offer;
        private Date bookingDate;
        private Client client;
        private Offer offer;
-       
-       
-       public Booking() {
+
+       public Booking(int bN, Offer offer, Client client, Date date) {
+               this.bookingNumber = bN;
+               this.offer = offer;
+               this.client = client;
+               // Booking date is assigned to actual date
+               this.bookingDate = date;
        }
 
        }
 
-       public Booking(int bN , Offer offer,Client client) {
-               
+       public Booking(int bN, Offer offer, Client client) {
+
                this.bookingNumber = bN;
                this.offer = offer;
                this.bookingNumber = bN;
                this.offer = offer;
-               this.client=client;
-               //Booking date is assigned to actual date
-               this.bookingDate= new java.util.Date(System.currentTimeMillis());
+               this.client = client;
+               // Booking date is assigned to actual date
+               this.bookingDate = new java.util.Date(System.currentTimeMillis());
        }
        }
-       
-       public void imprimete(){
+
+       public void imprimete() {
                System.out.println(bookingNumber);
                System.out.println(bookingDate);
                System.out.println(client.toString());
                System.out.println(bookingNumber);
                System.out.println(bookingDate);
                System.out.println(client.toString());
-               System.out.println(offer);      
+               System.out.println(offer);
        }
 
        public int getBookNumber() {
        }
 
        public int getBookNumber() {
@@ -49,7 +53,7 @@ public class Booking implements Serializable  {
        public float getPrice() {
                return this.offer.getPrice();
        }
        public float getPrice() {
                return this.offer.getPrice();
        }
-       
+
        public void setBookDate(Date bookDate) {
                this.bookingDate = bookDate;
        }
        public void setBookDate(Date bookDate) {
                this.bookingDate = bookDate;
        }
@@ -57,7 +61,7 @@ public class Booking implements Serializable  {
        public Date getBookDate() {
                return this.bookingDate;
        }
        public Date getBookDate() {
                return this.bookingDate;
        }
-       
+
        public Client getClient() {
                return client;
        }
        public Client getClient() {
                return client;
        }
@@ -65,5 +69,5 @@ public class Booking implements Serializable  {
        public void setClient(Client client) {
                this.client = client;
        }
        public void setClient(Client client) {
                this.client = client;
        }
-       
+
 }
\ No newline at end of file
 }
\ No newline at end of file