From: pinene Date: Tue, 19 May 2015 19:44:47 +0000 (+0200) Subject: Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/c92b616b1406bb5ff52624836f0608e8c5062451?hp=-c Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code Conflicts: ruralHouses client/src/gui/ModifyOfferGUI.java ruralHouses/src/dataAccess/DB4oManager.java --- c92b616b1406bb5ff52624836f0608e8c5062451 diff --combined ruralHouses client/src/gui/ModifyOfferGUI.java index 82efb8d,7cb5b85..9259130 --- a/ruralHouses client/src/gui/ModifyOfferGUI.java +++ b/ruralHouses client/src/gui/ModifyOfferGUI.java @@@ -12,7 -12,6 +12,7 @@@ import java.awt.event.ItemListener import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.rmi.Naming; +import java.rmi.RemoteException; import java.sql.Date; import java.text.DateFormat; import java.util.Calendar; @@@ -26,12 -25,10 +26,12 @@@ import javax.swing.JLabel import javax.swing.JTextField; import com.toedter.calendar.JCalendar; -import common.OfferInterface; +import common.HouseInterface; +import common.OfferInterface; import configuration.___IntNames; import domain.Offer; +import domain.Owner; import domain.RuralHouse; import exceptions.BadDates; @@@ -57,41 -54,22 +57,44 @@@ public class ModifyOfferGUI extends JFr private JLabel jLabel5 = new JLabel(); private final JLabel jLabel1_o = new JLabel(); private JComboBox comboBox_o; + private Vector Hlist = null; + private OfferInterface om = null; + private HouseInterface hm = null; + - public ModifyOfferGUI(Vector v) { + public ModifyOfferGUI(Owner o) { try { - jbInit(v); + jbInit(o); } catch (Exception e) { e.printStackTrace(); } } - private void jbInit(Vector v) throws Exception { + private void jbInit(Owner o) throws Exception { this.getContentPane().setLayout(null); this.setSize(new Dimension(513, 433)); this.setTitle("Set availability"); ++<<<<<<< HEAD + + try { + om = (OfferInterface) Naming + .lookup(___IntNames.OfferManager); + 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(); + } ++======= ++>>>>>>> 25898b619dd708c9f15a44200b545cac11404b73 - jComboBox1 = new JComboBox(v); + jComboBox1 = new JComboBox(Hlist); comboBox_o = new JComboBox( ((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers()); @@@ -145,15 -123,10 +148,15 @@@ @Override public void itemStateChanged(ItemEvent arg0) { - Vector vo = ((RuralHouse) jComboBox1.getSelectedItem()).offers; + Vector vo= null; + try { + vo = om.getRuralHouseOffers((RuralHouse) jComboBox1.getSelectedItem()); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } comboBox_o.removeAllItems(); - if (!((RuralHouse) jComboBox1.getSelectedItem()).offers - .isEmpty()) { + if (!vo.isEmpty()) { jCalendar1.setEnabled(true); jCalendar2.setEnabled(true); jButton1.setEnabled(true); diff --combined ruralHouses/src/dataAccess/DB4oManager.java index 0fb0c74,6089a74..d8a59f2 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@@ -135,7 -135,6 +135,6 @@@ public class DB4oManager Account alfredoAcc = new Account("userAlfredo", "passAlfredo", alfredo); - Account admin = new Account("admin", "admin", true); db.store(Administrator.getInstance()); db.store(jonAcc); @@@ -220,23 -219,7 +219,24 @@@ } } - public Administrator getAdminData() { + 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); + Offer proto = new Offer(0, rh, null, null, 0); + ObjectSet result = db.queryByExample(proto); + return new Vector(result); + } finally { + db.close(); + } + } + + public Administrator getAdminData(){ ++ if (c.isDatabaseLocal() == false) openSDB(); else @@@ -244,8 -227,7 +244,7 @@@ try { - - List admL = db.query(new Predicate(){ + List admL = db.query(new Predicate() { private static final long serialVersionUID = 1L; public boolean match(Administrator admin) { @@@ -253,11 -235,8 +252,8 @@@ } }); - - return admL.get(0); - } - finally { + } finally { db.close(); } @@@ -315,7 -294,7 +311,7 @@@ else openDB(); - Vector book = new Vector() ; + Vector book = new Vector(); try { @@@ -334,11 -313,11 +330,11 @@@ offer.createBooking(theDB4oManagerAux.bookingNumber++, cl); db.store(theDB4oManagerAux); // To store the new value for // bookingNumber - + db.store(offer); db.commit(); book = offer.getBookings(); - + } } catch (com.db4o.ext.ObjectNotStorableException e) { @@@ -375,7 -354,6 +371,7 @@@ } } + public Vector getAllRuralHouses() throws RemoteException, Exception { @@@ -387,7 -365,10 +383,7 @@@ try { RuralHouse proto = new RuralHouse(null, null, null, null, null); ObjectSet result = db.queryByExample(proto); - Vector ruralHouses = new Vector(); - while (result.hasNext()) - ruralHouses.add((RuralHouse) result.next()); - return ruralHouses; + return new Vector(result); } finally { db.close(); } @@@ -512,10 -493,10 +508,10 @@@ } - public Vector getRuralHouses(String name, String town, + 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, null, null, town, fea); + RuralHouse rh = new RuralHouse(name, ow, null, town, fea); if (c.isDatabaseLocal() == false) openSDB(); else @@@ -541,27 -522,50 +537,50 @@@ openDB(); try { - // TODO realize if there is another account with same username. - // Quite difficult with the f***ing salt - db.store(acc); - db.commit(); + ObjectSet result = db.queryByExample(new Account(acc + .getUsername())); + if (result.isEmpty()) { + db.store(acc); + db.commit(); + return true; + } } catch (Exception exc) { exc.printStackTrace(); } finally { db.close(); } - return true; + return false; } // TODO remove account public boolean removeAccount(Account acc) { + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + + try { + ObjectSet result = db.queryByExample(new Account(acc + .getUsername())); + if (!result.isEmpty()) { + db.delete(result.get(0)); + ; + db.commit(); + return true; + } + } catch (Exception exc) { + exc.printStackTrace(); + } finally { + db.close(); + } return false; } - - //TODO this method should be improved. - public void acceptBooking(Offer of){ - Offer off = new Offer(of.getOfferNumber(),of.getRuralHouse(),of.getFirstDay(),of.getLastDay(),of.getPrice()); + + // TODO this method should be improved. + public void acceptBooking(Offer of) { + Offer off = new Offer(of.getOfferNumber(), of.getRuralHouse(), + of.getFirstDay(), of.getLastDay(), of.getPrice()); if (c.isDatabaseLocal() == false) openSDB(); else @@@ -572,29 -576,30 +591,30 @@@ this.deleteOffer(result.get(0)); db.store(of); db.close(); - + } catch (Exception e) { - e.printStackTrace();; - } + e.printStackTrace(); + ; + } } - - public void removeBooking(Booking b){ + + public void removeBooking(Booking b) { if (c.isDatabaseLocal() == false) openSDB(); else openDB(); try { ObjectSet result = db.queryByExample(b); - ObjectSet result2= db.queryByExample(b.getClient()); + ObjectSet result2 = db.queryByExample(b.getClient()); db.delete(result.get(0)); db.delete(result2.get(0)); db.commit(); } catch (Exception e) { - e.printStackTrace();; - }finally{ + e.printStackTrace(); + ; + } finally { db.close(); } - } } diff --combined ruralHouses/src/domain/Account.java index ce6bd9e,0a724c3..ff19267 --- a/ruralHouses/src/domain/Account.java +++ b/ruralHouses/src/domain/Account.java @@@ -22,8 -22,8 +22,8 @@@ public class Account implements Seriali private boolean admin = false; - public Account(String usr){ - this.username = SecurityManager.getInstance().calculateHash(usr); + public Account(byte[] usr){ + this.username = usr; this.salt =null; this.password = null; this.owner = null; @@@ -48,6 -48,7 +48,7 @@@ } + public byte[] getUsername() { return username; } @@@ -64,7 -65,6 +65,7 @@@ return admin; } + public void setAdmin(boolean admin) { this.admin = admin; } @@@ -87,8 -87,6 +88,6 @@@ if (getClass() != obj.getClass()) return false; Account other = (Account) obj; - if (!Arrays.equals(password, other.password)) - return false; if (!Arrays.equals(username, other.username)) return false; return true;