From 85d983a413115168906ba44fa7b17c5781e418e7 Mon Sep 17 00:00:00 2001 From: camjan Date: Wed, 20 May 2015 11:05:53 +0200 Subject: [PATCH] Booking deletion fixed some minor problems remain --- .../src/gui/DeleteOfferGUI.java | 21 +++++++++--- .../src/gui/listOfBookingRequestsGUI.java | 21 ++++++------ .../src/gui/listOfOwnerAddittionRequests.java | 1 + .../src/gui/listOfRemovalRequestsGUI.java | 2 +- .../src/businessLogic/LoginManager.java | 1 - ruralHouses/src/dataAccess/DB4oManager.java | 30 +++++++++------- ruralHouses/src/domain/Booking.java | 34 +++++++++++-------- 7 files changed, 66 insertions(+), 44 deletions(-) diff --git a/ruralHouses client/src/gui/DeleteOfferGUI.java b/ruralHouses client/src/gui/DeleteOfferGUI.java index 0ed19e8..7c1903d 100644 --- a/ruralHouses client/src/gui/DeleteOfferGUI.java +++ b/ruralHouses client/src/gui/DeleteOfferGUI.java @@ -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.rmi.RemoteException; 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 common.HouseInterface; import common.OfferInterface; - 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 Owner owner; private JLabel feedback; private JComboBox comboBox; private JComboBox comboBox_1; private JButton btnDelete; + private Vector Hlist = null; + private HouseInterface hm = null; /** * 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); - comboBox = new JComboBox(this.owner.getRuralHouses()); + comboBox = new JComboBox(this.Hlist); comboBox.setBounds(101, 38, 314, 20); comboBox_1 = new JComboBox(); diff --git a/ruralHouses client/src/gui/listOfBookingRequestsGUI.java b/ruralHouses client/src/gui/listOfBookingRequestsGUI.java index f0cb7db..423ea4d 100644 --- a/ruralHouses client/src/gui/listOfBookingRequestsGUI.java +++ b/ruralHouses client/src/gui/listOfBookingRequestsGUI.java @@ -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); - 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); @@ -141,16 +136,22 @@ public class listOfBookingRequestsGUI extends JFrame { } ((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); diff --git a/ruralHouses client/src/gui/listOfOwnerAddittionRequests.java b/ruralHouses client/src/gui/listOfOwnerAddittionRequests.java index d72bd98..b3297b4 100644 --- a/ruralHouses client/src/gui/listOfOwnerAddittionRequests.java +++ b/ruralHouses client/src/gui/listOfOwnerAddittionRequests.java @@ -119,6 +119,7 @@ public class listOfOwnerAddittionRequests extends JFrame { } ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); + } } }); diff --git a/ruralHouses client/src/gui/listOfRemovalRequestsGUI.java b/ruralHouses client/src/gui/listOfRemovalRequestsGUI.java index 071ee51..a85c246 100644 --- a/ruralHouses client/src/gui/listOfRemovalRequestsGUI.java +++ b/ruralHouses client/src/gui/listOfRemovalRequestsGUI.java @@ -109,11 +109,11 @@ public class listOfRemovalRequestsGUI extends JFrame { am.removeHouseDeletionRequests(rh); am.saveInstance(); } catch (RemoteException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } ((DefaultTableModel) table.getModel()).removeRow(houses .indexOf(rh)); + houses.remove(rh); } } diff --git a/ruralHouses/src/businessLogic/LoginManager.java b/ruralHouses/src/businessLogic/LoginManager.java index e0f0439..f3c4600 100644 --- a/ruralHouses/src/businessLogic/LoginManager.java +++ b/ruralHouses/src/businessLogic/LoginManager.java @@ -24,7 +24,6 @@ public class LoginManager extends UnicastRemoteObject implements LoginInterface try { dbMngr = DB4oManager.getInstance(); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } } diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 0f17aeb..a677c95 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -85,8 +85,7 @@ public class DB4oManager { 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()); @@ -222,14 +221,15 @@ public class DB4oManager { } } - public Vector getRHsOffer(String name){ + public Vector getRHsOffer(String name) { 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 result = db.queryByExample(proto); return new Vector(result); @@ -237,8 +237,8 @@ public class DB4oManager { db.close(); } } - - public Administrator getAdminData(){ + + public Administrator getAdminData() { if (c.isDatabaseLocal() == false) openSDB(); @@ -374,7 +374,6 @@ public class DB4oManager { } } - public Vector getAllRuralHouses() throws RemoteException, Exception { @@ -511,8 +510,8 @@ public class DB4oManager { } - public Vector getRuralHouses(Owner ow, String name, String town, - int nBed, int nKit, int nBath, int nPark, int nLiv) { + public Vector 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) @@ -607,10 +606,15 @@ public class DB4oManager { else openDB(); try { - ObjectSet 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 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(); diff --git a/ruralHouses/src/domain/Booking.java b/ruralHouses/src/domain/Booking.java index cdde621..60cfd2f 100644 --- a/ruralHouses/src/domain/Booking.java +++ b/ruralHouses/src/domain/Booking.java @@ -3,7 +3,7 @@ package domain; 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; - - - 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.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(offer); + System.out.println(offer); } public int getBookNumber() { @@ -49,7 +53,7 @@ public class Booking implements Serializable { public float getPrice() { return this.offer.getPrice(); } - + public void setBookDate(Date bookDate) { this.bookingDate = bookDate; } @@ -57,7 +61,7 @@ public class Booking implements Serializable { public Date getBookDate() { return this.bookingDate; } - + public Client getClient() { return client; } @@ -65,5 +69,5 @@ public class Booking implements Serializable { public void setClient(Client client) { this.client = client; } - + } \ No newline at end of file -- 2.20.1