From: camjan Date: Wed, 15 Apr 2015 15:47:17 +0000 (+0200) Subject: Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/ba6020dbbdae8fddc57edd4723eb0b3a4a530e14?hp=-c Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code Conflicts: ruralHouses/src/dataAccess/DB4oManager.java ruralHouses/src/gui/ModifyHouseGUI.java --- ba6020dbbdae8fddc57edd4723eb0b3a4a530e14 diff --combined ruralHouses/src/dataAccess/DB4oManager.java index a2bcfde,cb923e1..eb80b86 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@@ -4,8 -4,12 +4,15 @@@ import java.io.File //import java.util.Enumeration; //import java.util.Vector; import java.rmi.RemoteException; - import java.util.*; ++ ++ + import java.util.Date; + import java.util.LinkedList; + import java.util.List; + import java.util.ListIterator; + import java.util.Vector; + + import com.db4o.Db4oEmbedded; import com.db4o.ObjectContainer; import com.db4o.ObjectSet; @@@ -16,6 -20,7 +23,7 @@@ import com.db4o.query.Predicate import configuration.ConfigXML; import domain.Account; + import domain.Administrator; import domain.Booking; import domain.HouseFeatures; import domain.Offer; @@@ -111,24 -116,28 +119,30 @@@ public class DB4oManager try { Owner jon = new Owner("Jon"); Owner alfredo = new Owner("Alfredo"); - jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3, 3, - 3); - jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4, 4, - 4, 4); + jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3, + 3, 3); + jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4, + 4, 4, 4); jon.setBankAccount("1349 5677 21 2133567777"); - alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, - 5, 5, 5, 5); + 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("userJon", "passJon", jon); Account alfredoAcc = new Account("userAlfredo", "passAlfredo", alfredo); ++ + Account admin = new Account("admin","admin", true); + db.store(Administrator.giveAdmin()); + db.store(jon); + db.store(alfredo); db.store(jonAcc); db.store(alfredoAcc); + db.store(admin); db.commit(); } finally { - db.close(); + db.close(); } } @@@ -153,6 -162,8 +167,6 @@@ db.close(); } } - - public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, float price) throws RemoteException, Exception { @@@ -167,7 -178,7 +181,7 @@@ RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null, null, null, null); - ObjectSet result = db.queryByExample(proto); + ObjectSet result = db.queryByExample(proto); RuralHouse rh = (RuralHouse) result.next(); o = rh.createOffer(theDB4oManagerAux.offerNumber++, firstDay, lastDay, price); @@@ -185,8 -196,27 +199,8 @@@ return o; } - public Offer modifyOffer(Offer offer) throws RemoteException, Exception { - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - - db.store(offer); - db.commit(); - - } catch (com.db4o.ext.ObjectNotStorableException e) { - System.out - .println("Error: com.db4o.ext.ObjectNotStorableException in createOffer"); - } finally { - db.close(); - } - return offer; - } - - public void deleteOffer(RuralHouse rh, Offer offer) throws RemoteException, + + public void deleteOffer(Offer offer) throws RemoteException, Exception { if (c.isDatabaseLocal() == false) openSDB(); @@@ -194,10 -224,9 +208,10 @@@ openDB(); try { - + ObjectSet of = db.queryByExample(offer); + RuralHouse rh =of.get(0).getRuralHouse(); + System.out.println(rh.offers.remove(of.get(0))); db.store(rh); - db.delete(offer); db.commit(); } catch (com.db4o.ext.ObjectNotStorableException e) { @@@ -208,6 -237,62 +222,62 @@@ } } + + public LinkedList[] getAdminData(){ + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + LinkedList[] ret = new LinkedList[2]; + + try { + + List admL = db.query(new Predicate(){ + public boolean match(Administrator admin){ + return true; + } + }); + + ret[0] = admL.get(0).getAddRequest(); + ret[1] = admL.get(0).getRemoveRequest(); + return ret; + } + finally { + db.close(); + + } + + } + + public void storeAdmin() { + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + try { + + List admL = db.query(new Predicate(){ + public boolean match(Administrator admin){ + return true; + } + }); + + admL.get(0).setAddRequest(Administrator.getAddRequest()); + admL.get(0).setRemoveRequest(Administrator.getRemoveRequest()); + db.commit(); + + } + catch(Exception e){ + + } + finally { + db.close(); + } + + + } + + /** * This method creates a book with a corresponding parameters * @@@ -225,6 -310,7 +295,7 @@@ openDB(); Booking bok = null; + try { @@@ -273,7 -359,7 +344,7 @@@ try { Owner proto = new Owner(null, null); - ObjectSet result = db.queryByExample(proto); + ObjectSet result = db.queryByExample(proto); Vector owners = new Vector(); while (result.hasNext()) owners.add((Owner) result.next()); @@@ -354,7 -440,7 +425,7 @@@ openDB(); try { - Account proto = new Account(usr, pwd, new Owner(null, null)); + Account proto = new Account(usr, pwd, null); ObjectSet result = db.queryByExample(proto); Vector accounts = new Vector(); while (result.hasNext()) @@@ -384,11 -470,6 +455,11 @@@ db.store(rh); db.commit(); stored = true; + } else { + db.delete(result.get(0)); + db.store(rh); + db.commit(); + stored = true; } } finally { db.close(); @@@ -403,12 -484,12 +474,12 @@@ else openDB(); try { - ObjectSet result = db.queryByExample(rh); - if (!result.isEmpty()) { - RuralHouse found = (RuralHouse) result.get(0); - // db.delete(found.getOwner()); - db.store(owner); - db.delete(found); + ObjectSet result = db.queryByExample(owner); + ObjectSet rhs = db.queryByExample(rh); + if (!rhs.isEmpty()) { + Owner found = result.get(0); + found.getRuralHouses().remove(rhs.get(0)); + db.store(found); db.commit(); } } catch (Exception exc) { @@@ -419,11 -500,54 +490,11 @@@ } - public Vector getRuralHousesByTown(String town) { - RuralHouse rh = new RuralHouse(null, null, null, town, null); - - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - ObjectSet result = db.queryByExample(rh); - Vector ruralHouses = new Vector(); - while (result.hasNext()) - ruralHouses.add(result.next()); - return ruralHouses; - } finally { - db.close(); - } - - } - - public RuralHouse getRuralHouseByName(String name) { - RuralHouse rh = new RuralHouse(name, null, null, null, null); - - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - ObjectSet result = db.queryByExample(rh); - Vector ruralHouses = new Vector(); - while (result.hasNext()) - ruralHouses.add(result.next()); - db.close(); - if (!ruralHouses.isEmpty()) - return ruralHouses.get(0); - else - return null; - } catch (NullPointerException e) { - return null; - } - - } - public Vector getRuralHouses(String town, int nBed, int nKit, - int nBath, int nPark, int nLiv) { + public Vector getRuralHouses(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(null, null, null, town, fea); + RuralHouse rh = new RuralHouse(name, null, null, town, fea); if (c.isDatabaseLocal() == false) openSDB(); else @@@ -441,4 -565,6 +512,6 @@@ } } + + } diff --combined ruralHouses/src/gui/ModifyHouseGUI.java index 0fc99a9,29bc627..e7bd38d --- a/ruralHouses/src/gui/ModifyHouseGUI.java +++ b/ruralHouses/src/gui/ModifyHouseGUI.java @@@ -18,7 -18,6 +18,7 @@@ import javax.swing.SwingConstants import javax.swing.border.EmptyBorder; import businessLogic.HouseManager; +import domain.HouseFeatures; import domain.Owner; import domain.RuralHouse; @@@ -32,7 -31,6 +32,7 @@@ public class ModifyHouseGUI extends JFr private Owner owner; private JLabel lblDistrict; private JTextField District_f; + private JLabel feedback; private JLabel lblDescription; private JTextField description_f; private JLabel lblKitchen; @@@ -49,6 -47,7 +49,6 @@@ private JComboBox houseBox; private RuralHouse rh; - /** * Create the frame. */ @@@ -59,142 -58,191 +59,143 @@@ contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); - + JLabel lblCode = new JLabel("House Name:"); + lblCode.setBounds(15, 88, 64, 14); lblCode.setHorizontalAlignment(SwingConstants.RIGHT); - + lblDistrict = new JLabel("District:"); + lblDistrict.setBounds(39, 119, 70, 14); lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT); - + District_f = new JTextField(); + District_f.setBounds(127, 116, 86, 20); District_f.setColumns(10); - + lblDescription = new JLabel("Description:"); + lblDescription.setBounds(231, 88, 90, 14); lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); - + description_f = new JTextField(); + description_f.setBounds(241, 113, 178, 129); description_f.setColumns(10); - + lblKitchen = new JLabel("Kitchens:"); + lblKitchen.setBounds(230, 316, 70, 14); lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT); - + kitchens_f = new JTextField(); + kitchens_f.setBounds(318, 313, 86, 20); kitchens_f.setColumns(10); - + lblRooms = new JLabel("Rooms:"); + lblRooms.setBounds(39, 316, 70, 14); lblRooms.setHorizontalAlignment(SwingConstants.RIGHT); - + rooms_f = new JTextField(); + rooms_f.setBounds(127, 313, 86, 20); rooms_f.setColumns(10); - + lblLivings = new JLabel("Living rooms:"); + lblLivings.setBounds(237, 354, 63, 14); lblLivings.setHorizontalAlignment(SwingConstants.RIGHT); - + lRooms_f = new JTextField(); + lRooms_f.setBounds(318, 351, 86, 20); lRooms_f.setColumns(10); - + lblParkings = new JLabel("Parkings:"); + lblParkings.setBounds(39, 404, 70, 14); lblParkings.setHorizontalAlignment(SwingConstants.RIGHT); - + parkings_f = new JTextField(); + parkings_f.setBounds(127, 401, 86, 20); parkings_f.setColumns(10); - + lblBaths = new JLabel("Baths:"); + lblBaths.setBounds(39, 354, 70, 14); lblBaths.setHorizontalAlignment(SwingConstants.RIGHT); - + baths_f = new JTextField(); + baths_f.setBounds(127, 351, 86, 20); baths_f.setColumns(10); - + btnConfirm = new JButton("Confirm"); + btnConfirm.setBounds(145, 462, 69, 23); btnConfirm.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - - + + RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner, + description_f.getText(), District_f.getText(), + new HouseFeatures(new Integer(rooms_f.getText()), + new Integer(kitchens_f.getText()), new Integer( + baths_f.getText()), new Integer( + lRooms_f.getText()), new Integer( + parkings_f.getText()))); HouseManager hm = new HouseManager(); - hm.removeHouse(rh, owner); - //TODO registernewhouse must check before if the house is created to delete it before creating it. - hm.registerNewHouse(rh.getHouseName(), - owner, - description_f.getText(), - District_f.getText(), - new Integer(rooms_f.getText()), - new Integer(kitchens_f.getText()), - new Integer(baths_f.getText()), - new Integer(lRooms_f.getText()), - new Integer(parkings_f.getText()) - ); ++ + if (hm.registerNewHouse(newRh)) { + feedback.setText("House properly modified"); + } else + feedback.setText("Imposible to modify the house"); + } }); - + houseBox = new JComboBox(o.getRuralHouses()); - + if (!o.getRuralHouses().isEmpty()) { + rh = (RuralHouse) houseBox.getSelectedItem(); + District_f.setText(rh.getDistrict()); + description_f.setText(rh.getDescription()); + kitchens_f.setText(Integer + .toString(rh.getFeatures().getnKitchens())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); + parkings_f.setText(Integer + .toString(rh.getFeatures().getnParkings())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + houseBox.setBounds(89, 85, 124, 20); + }else{ + feedback.setText("Not available houses"); + } houseBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - rh = (RuralHouse)houseBox.getSelectedItem(); - District_f.setText(rh.getDistrict()); - description_f.setText(rh.getDescription()); - kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens())); - rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); - lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); - parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings())); - baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); - - } - }); - - GroupLayout gl_contentPane = new GroupLayout(contentPane); - gl_contentPane.setHorizontalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addContainerGap() - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblCode) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblDistrict, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(17) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblLivings) - .addGap(18) - .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(18) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(10) - .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)) - .addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE))))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(140) - .addComponent(btnConfirm))) - .addContainerGap()) - ); - gl_contentPane.setVerticalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(20) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(60) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(lblCode) - .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(lblDistrict))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(63) - .addComponent(lblDescription) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE))) - .addGap(71) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblRooms)) - .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblKitchen)) - .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(18) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblBaths)) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(lblLivings))) - .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(30) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblParkings)) - .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(41) - .addComponent(btnConfirm) - .addGap(54)) - ); - contentPane.setLayout(gl_contentPane); + @Override + public void itemStateChanged(ItemEvent e) { + rh = (RuralHouse) houseBox.getSelectedItem(); + District_f.setText(rh.getDistrict()); + description_f.setText(rh.getDescription()); + kitchens_f.setText(Integer.toString(rh.getFeatures() + .getnKitchens())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + lRooms_f.setText(Integer.toString(rh.getFeatures() + .getnLivings())); + parkings_f.setText(Integer.toString(rh.getFeatures() + .getnParkings())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + + } + }); + contentPane.setLayout(null); + contentPane.add(lblParkings); + contentPane.add(parkings_f); + contentPane.add(lblRooms); + contentPane.add(rooms_f); + contentPane.add(lblCode); + contentPane.add(houseBox); + contentPane.add(lblBaths); + contentPane.add(baths_f); + contentPane.add(lblDistrict); + contentPane.add(District_f); + contentPane.add(lblLivings); + contentPane.add(lRooms_f); + contentPane.add(lblKitchen); + contentPane.add(kitchens_f); + contentPane.add(description_f); + contentPane.add(lblDescription); + contentPane.add(btnConfirm); + + feedback = new JLabel(""); + feedback.setBounds(189, 510, 195, 23); + contentPane.add(feedback); } }