<databaseNode>localhost</databaseNode>
<db4oFilename>db/casas.db4o</db4oFilename>
<dataBaseOpenMode>initialize</dataBaseOpenMode>
- <activationDepth>5</activationDepth>
- <updateDepth>5</updateDepth>
+ <activationDepth>8</activationDepth>
+ <updateDepth>8</updateDepth>
<databasePort>8100</databasePort>
<user>softEng</user>
<password>i4softwEngin2matx</password>
import domain.RuralHouse;
public class AdminManager {
- public AdminManager (){
-
+ public AdminManager() {
+
}
- public Vector<RuralHouse> getAdditionRequests(){
- return new Vector<RuralHouse>(Administrator.getAddRequest());
+
+ public Vector<RuralHouse> getAdditionRequests() {
+ return new Vector<RuralHouse>(Administrator.getInstance()
+ .getAddRequest());
}
-
- public Vector<RuralHouse> getDeletionRequests(){
- return new Vector<RuralHouse>(Administrator.getRemoveRequest());
+
+ public Vector<RuralHouse> getDeletionRequests() {
+ return new Vector<RuralHouse>(Administrator.getInstance()
+ .getRemoveRequest());
}
- public void removeHouseAdditionRequests(RuralHouse house){
- Administrator.getAddRequest().remove(house);
+
+ public void removeHouseAdditionRequests(RuralHouse house) {
+ Administrator.getInstance().getAddRequest().remove(house);
}
- public void removeHouseDeletionRequests(RuralHouse house){
- Administrator.getRemoveRequest().remove(house);
- }
- public boolean addAdditionRequest(RuralHouse rh){
- if(this.getAdditionRequests().contains(rh)){
+
+ public void removeHouseDeletionRequests(RuralHouse house) {
+ Administrator.getInstance().getRemoveRequest().remove(house);
+ }
+
+ public boolean addAdditionRequest(RuralHouse rh) {
+ if (this.getAdditionRequests().contains(rh)) {
return false;
}
- return Administrator.getAddRequest().add(rh);
+ return Administrator.getInstance().getAddRequest().add(rh);
}
- public boolean addDeletionRequest(RuralHouse rh){
- if(this.getDeletionRequests().contains(rh))
+
+ public boolean addDeletionRequest(RuralHouse rh) {
+ if (this.getDeletionRequests().contains(rh))
return false;
- return Administrator.getRemoveRequest().add(rh);
+ return Administrator.getInstance().getRemoveRequest().add(rh);
}
}
package businessLogic;
import java.util.Date;
+import java.util.Vector;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import dataAccess.DB4oManager;
import domain.Booking;
+import domain.Offer;
+import domain.Owner;
import domain.RuralHouse;
import exceptions.OfferCanNotBeBooked;
-
public final class BookingManager {
private int bookingNumber = 0;
e.printStackTrace();
}
}
-
+
/**
- * This method returns the next Booking number
+ * This method returns the next Booking number
*
* @return the book number
*/
- public static int getNumber(){
- ObjectContainer db=DB4oManager.getContainer();
- BookingManager b=getInstance();
- b.bookingNumber++;
- db.store(b);
- db.commit();
- return b.bookingNumber;
- }
-
+ public static int getNumber() {
+ ObjectContainer db = DB4oManager.getContainer();
+ BookingManager b = getInstance();
+ b.bookingNumber++;
+ db.store(b);
+ db.commit();
+ return b.bookingNumber;
+ }
+
/**
- * This method returns the instance of the BookingManager class
+ * This method returns the instance of the BookingManager class
*
* @return the booking manager
*/
- public static BookingManager getInstance() {
- ObjectContainer db=DB4oManager.getContainer();
- BookingManager b = new BookingManager();
- ObjectSet<BookingManager> result = db.queryByExample(b);
- if (!result.hasNext()){
- theBookingManager = new BookingManager();
- db.store(theBookingManager);
- db.commit();
- } else theBookingManager=(BookingManager)result.next();
+ public static BookingManager getInstance() {
+ ObjectContainer db = DB4oManager.getContainer();
+ BookingManager b = new BookingManager();
+ ObjectSet<BookingManager> result = db.queryByExample(b);
+ if (!result.hasNext()) {
+ theBookingManager = new BookingManager();
+ db.store(theBookingManager);
+ db.commit();
+ } else
+ theBookingManager = (BookingManager) result.next();
return theBookingManager;
}
-
+
+ public void removeBooking(Booking B) {
+ // TODO
+
+ }
+
+ public Vector<Booking> getAllBookings(Owner ow) {
+ Vector<Booking> books = new Vector<Booking>();
+ for (RuralHouse rh : ow.getRuralHouses()) {
+ Vector<Offer> off = rh.getAllOffers();
+ for (Offer of : off) {
+ System.out.print(of.toString());
+ if (of.getBooking() != null) {
+
+ books.add(of.getBooking());
+ }
+ }
+ }
+ return books;
+ }
+
/**
* This method creates a book with a corresponding parameters
*
* day, last day, house number and telephone
* @return a book
*/
- public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
+ public Booking createBooking(RuralHouse ruralHouse, Date firstDate,
+ Date lastDate, String bookTelephoneNumber)
throws OfferCanNotBeBooked {
- return dbMngr.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber);
+ return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
+ bookTelephoneNumber);
}
-
+
}
\ No newline at end of file
import dataAccess.DB4oManager;
import domain.Account;
+
public class LoginManager implements LoginManagerInterface {
DB4oManager dbMngr;
@Override
public Account checkCredentials(String usr, String pwd) {
+ Account ac = new Account(usr);
try {
- Vector<Account> account = dbMngr.getAccount(usr, pwd);
- if (account.isEmpty())
- return null;
- else
+ Vector<Account> account = dbMngr.getAccount(ac);
+ if (SecurityManager.getInstance().isExpectedPassword(pwd.toCharArray(), account
+ .get(0).getSalt(), account.get(0).getPassword())) {
+
return account.get(0);
+ }
+ return null;
} catch (Exception e) {
// TODO Auto-generated catch block
}
return null;
}
-
-
-
}
--- /dev/null
+package businessLogic;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
+import java.util.Arrays;
+
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+
+public class SecurityManager {
+
+ private static SecurityManager secMan = null;
+
+ private SecurityManager() {
+ }
+
+ public static SecurityManager getInstance() {
+ if (secMan == null)
+ return new SecurityManager();
+ else
+ return secMan;
+ }
+
+ public byte[] generateSalt() {
+ SecureRandom random = new SecureRandom();
+ byte bytes[] = new byte[20];
+ random.nextBytes(bytes);
+ return bytes;
+ }
+
+ public byte[] calculateHash(String password) {
+ byte[] hash = {};
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA1");
+ md.update(password.getBytes());
+ hash = md.digest();
+ } catch (Exception e) {
+ System.out.println("Exception: " + e);
+ }
+ return hash;
+ }
+
+ public byte[] calculateSaltedHash(char[] password, byte[] salt) {
+ PBEKeySpec spec = new PBEKeySpec(password, salt, 10000, 256);
+ Arrays.fill(password, Character.MIN_VALUE);
+ try {
+ SecretKeyFactory skf = SecretKeyFactory
+ .getInstance("PBKDF2WithHmacSHA1");
+ return skf.generateSecret(spec).getEncoded();
+ } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
+ throw new AssertionError("Error while hashing a password: "
+ + e.getMessage(), e);
+ } finally {
+ spec.clearPassword();
+ }
+ }
+
+ public boolean isExpectedPassword(char[] password, byte[] salt,
+ byte[] expectedHash) {
+ byte[] pwdHash = calculateSaltedHash(password, salt);
+ Arrays.fill(password, Character.MIN_VALUE);
+ if (pwdHash.length != expectedHash.length)
+ return false;
+ for (int i = 0; i < pwdHash.length; i++) {
+ if (pwdHash[i] != expectedHash[i])
+ return false;
+ }
+ return true;
+ }
+}
} else // c.getDataBaseOpenMode().equals("open")
{
- ObjectSet<DB4oManagerAux> res = db.queryByExample(DB4oManagerAux.class);
+ ObjectSet<DB4oManagerAux> res = db
+ .queryByExample(DB4oManagerAux.class);
ListIterator<DB4oManagerAux> listIter = res.listIterator();
if (listIter.hasNext())
theDB4oManagerAux = (DB4oManagerAux) res.next();
configuration.common().updateDepth(c.getUpdateDepth());
configuration.common().objectClass(Owner.class).cascadeOnUpdate(true);
configuration.common().objectClass(Owner.class).cascadeOnDelete(true);
- configuration.common().objectClass(RuralHouse.class).cascadeOnUpdate(true);
+ configuration.common().objectClass(RuralHouse.class)
+ .cascadeOnUpdate(true);
configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
}
jon.setBankAccount("1349 5677 21 2133567777");
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("1", "1", jon);
Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
alfredo);
- Account admin = new Account("admin","admin", true);
- db.store(Administrator.giveAdmin());
+ Account admin = new Account("admin", "admin", true);
+ db.store(Administrator.getInstance());
db.store(jonAcc);
db.store(alfredoAcc);
db.store(admin);
db.commit();
} finally {
- db.close();
+ db.close();
}
}
return o;
}
-
- public void deleteOffer(Offer offer) throws RemoteException,
- Exception {
+ public void deleteOffer(Offer offer) throws RemoteException, Exception {
if (c.isDatabaseLocal() == false)
openSDB();
else
try {
ObjectSet<Offer> of = db.queryByExample(offer);
- RuralHouse rh =of.get(0).getRuralHouse();
+ RuralHouse rh = of.get(0).getRuralHouse();
System.out.println(rh.offers.remove(of.get(0)));
db.store(rh);
db.commit();
}
}
-
- @SuppressWarnings("static-access")
- public LinkedList<RuralHouse>[] getAdminData(){
+
+ public Administrator getAdminData() {
if (c.isDatabaseLocal() == false)
openSDB();
else
openDB();
- @SuppressWarnings("unchecked")
- LinkedList<RuralHouse>[] ret = new LinkedList[2];
-
+
try {
-
- List<Administrator> admL = db.query(new Predicate<Administrator>(){
+
+ List<Administrator> admL = db.query(new Predicate<Administrator>() {
/**
*
*/
private static final long serialVersionUID = 1L;
- public boolean match(Administrator admin){
+ public boolean match(Administrator admin) {
return true;
}
});
-
- ret[0] = admL.get(0).getAddRequest();
- ret[1] = admL.get(0).getRemoveRequest();
- return ret;
- }
- finally {
+
+ return admL.get(0);
+ } finally {
db.close();
-
+
}
-
+
}
-
+
@SuppressWarnings("static-access")
public void storeAdmin() {
if (c.isDatabaseLocal() == false)
openSDB();
else
- openDB();
+ openDB();
try {
-
- List<Administrator> admL = db.query(new Predicate<Administrator>(){
+
+ List<Administrator> admL = db.query(new Predicate<Administrator>() {
/**
*
*/
private static final long serialVersionUID = 1L;
- public boolean match(Administrator admin){
+ public boolean match(Administrator admin) {
return true;
}
});
+
- admL.get(0).setAddRequest(Administrator.getAddRequest());
- admL.get(0).setRemoveRequest(Administrator.getRemoveRequest());
+ admL.get(0).setAddRequest(Administrator.getInstance().getAddRequest());
+ admL.get(0).setRemoveRequest(Administrator.getInstance().getRemoveRequest());
+ admL.get(0).setNewOwnerRequest(Administrator.getInstance().getNewOwnerRequest());
db.commit();
-
- }
- catch(Exception e){
-
- }
- finally {
+
+ } catch (Exception e) {
+
+ } finally {
db.close();
}
-
-
+
}
-
-
+
/**
* This method creates a book with a corresponding parameters
*
openDB();
Booking bok = null;
-
try {
/**
* @param usr
- * @param pwd
+ * @param ps
* @return
* @throws RemoteException
* @throws Exception
*/
- public Vector<Account> getAccount(String usr, String pwd)
+ public Vector<Account> getAccount(Account proto)
throws RemoteException, Exception {
if (c.isDatabaseLocal() == false)
openDB();
try {
- Account proto = new Account(usr, pwd, null);
ObjectSet<Account> result = db.queryByExample(proto);
Vector<Account> accounts = new Vector<Account>();
while (result.hasNext())
ObjectSet<Owner> result = db.queryByExample(owner);
ObjectSet<RuralHouse> rhs = db.queryByExample(rh);
if (!rhs.isEmpty()) {
- Owner found = result.get(0);
+ Owner found = result.get(0);
found.getRuralHouses().remove(rhs.get(0));
db.delete(rhs.get(0));
db.store(found);
}
-
public Vector<RuralHouse> getRuralHouses(String name, String town,
int nBed, int nKit, int nBath, int nPark, int nLiv) {
HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
}
-
}
package domain;
+import businessLogic.SecurityManager;
+
public class Account {
- private String username = "";
- private String password = "";
+ private byte[] username;
+ private byte[] password;
+ private byte[] salt;
+
private Owner owner;
private boolean admin = false;
- public Account(String usr, String pass, boolean admin) {
- this.username = usr;
- this.password = pass;
+
+ public Account(String usr){
+ this.username = SecurityManager.getInstance().calculateHash(usr);
+ this.salt =null;
+ this.password = null;
this.owner = null;
- this.admin = admin;
+
+ }
+ public Account(String usr, String pass, boolean isAdmin) {
+ this.username = SecurityManager.getInstance().calculateHash(usr);
+ this.salt = SecurityManager.getInstance().generateSalt();
+ this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt);
+ this.owner = null;
+ this.admin = isAdmin;
}
public Account(String usr, String pass, Owner ow) {
- this.username = usr;
- this.password = pass;
+ this.username = SecurityManager.getInstance().calculateHash(usr);
+ this.salt = SecurityManager.getInstance().generateSalt();
+ this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(),
+ this.salt);
this.owner = ow;
this.admin = false;
}
- public String getUsername() {
+ public byte[] getUsername() {
return username;
}
- public String getPassword() {
+ public byte[] getPassword() {
return password;
}
this.admin = admin;
}
+ public byte[] getSalt() {
+ return salt;
+ }
+
+ public void setSalt(byte[] salt) {
+ this.salt = salt;
+ }
+
}
import java.util.LinkedList;
+import configuration.ConfigXML;
import dataAccess.DB4oManager;
public class Administrator {
+ private static Administrator admin = null;
private static LinkedList<RuralHouse> addRequest;
private static LinkedList<RuralHouse> removeRequest;
- private Administrator(){
+ private static LinkedList<Owner> newOwnerRequest;
+ static ConfigXML c;
+
+ private Administrator() {
addRequest = new LinkedList<RuralHouse>();
- removeRequest = new LinkedList<RuralHouse>();
+ removeRequest = new LinkedList<RuralHouse>();
+ newOwnerRequest = new LinkedList<Owner>();
}
- public static Administrator giveAdmin(){
- return new Administrator();
- }
-
- public static void getInstance(){
- try {
- DB4oManager db4o = DB4oManager.getInstance();
- LinkedList<RuralHouse>[] temp = db4o.getAdminData();
- addRequest = temp[0];
- removeRequest = temp[1];
- } catch (Exception e) {
- e.printStackTrace();
+ public static Administrator getInstance() {
+ c = ConfigXML.getInstance();
+ if (admin == null) {
+ if (c.getDataBaseOpenMode().equals("initialize")) {
+ admin = new Administrator();
+ } else {
+ DB4oManager db4o;
+ try {
+ db4o = DB4oManager.getInstance();
+ admin = db4o.getAdminData();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
+ return admin;
+
}
-
- public static void saveInstance(){
+
+ public static void saveInstance() {
try {
DB4oManager.getInstance().storeAdmin();
} catch (Exception e) {
e.printStackTrace();
}
}
-
- public static LinkedList<RuralHouse> getAddRequest() {
+
+ public LinkedList<RuralHouse> getAddRequest() {
return addRequest;
}
- public static LinkedList<RuralHouse> getRemoveRequest() {
+
+ public LinkedList<RuralHouse> getRemoveRequest() {
return removeRequest;
}
- public static void setAddRequest(LinkedList<RuralHouse> addRequest) {
+ public void setAddRequest(LinkedList<RuralHouse> addRequest) {
Administrator.addRequest = addRequest;
}
- public static void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
+ public void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
Administrator.removeRequest = removeRequest;
}
+ public LinkedList<Owner> getNewOwnerRequest() {
+ return newOwnerRequest;
+ }
+
+ public void setNewOwnerRequest(LinkedList<Owner> newOwnerRequest) {
+ Administrator.newOwnerRequest = newOwnerRequest;
+ }
+
}
private Date bookingDate;
private String telephone;
private Offer offer;
+ private boolean isAccepted;
public Booking() {
//Booking date is assigned to actual date
this.bookingDate= new java.util.Date(System.currentTimeMillis());
this.isPaid=false;
+ this.isAccepted=false;
}
public void imprimete(){
System.out.println(bookingDate);
System.out.println(telephone);
System.out.println(offer);
+ System.out.println(this.isAccepted);
}
public int getBookNumber() {
return isPaid;
}
+ public boolean isAccepted(){
+ return this.isAccepted;
+ }
+
}
\ No newline at end of file
return off;
}
-
-
@Override
public boolean equals(Object obj) {
if (this == obj)
}
public Vector<Offer> getAllOffers() {
- Vector<Offer> availableOffers = new Vector<Offer>();
- Iterator<Offer> e = offers.iterator();
- Offer offer;
- while (e.hasNext()) {
- offer = e.next();
- if ((offer.getBooking() == null))
- availableOffers.add(offer);
- }
- return availableOffers;
+
+ return this.offers;
}
/**
}
-
}
a.setVisible(true);
}
});
+
+ JButton btnOwneraddition = new JButton("OwnerAddition");
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(115)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
- .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
+ .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
+ .addComponent(btnOwneraddition, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(btnDel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
+ .addComponent(btnAdd, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
.addContainerGap(145, Short.MAX_VALUE))
);
gl_contentPane.setVerticalGroup(
.addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
.addGap(58)
.addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
- .addContainerGap(142, Short.MAX_VALUE))
+ .addGap(52)
+ .addComponent(btnOwneraddition, GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
+ .addContainerGap())
);
contentPane.setLayout(gl_contentPane);
}
-
}
private int row;
private JLabel labelPhone;
-
/**
* Create the frame.
*/
- public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay, final Date LastDay) {
+ public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay,
+ final Date LastDay) {
this.rh = RH;
this.getContentPane().setLayout(null);
setBounds(100, 100, 500, 583);
lblNewLabel.setEnabled(false);
lblNewLabel.setBounds(170, 282, 261, 23);
contentPane.add(lblNewLabel);
-
+
JLabel lblNewLabel_1 = new JLabel("Telephone num:");
lblNewLabel_1.setBounds(10, 509, 83, 14);
contentPane.add(lblNewLabel_1);
-
+
telIn = new JTextField();
telIn.setBounds(99, 505, 129, 20);
contentPane.add(telIn);
labelPhone.setBounds(238, 252, 178, 14);
contentPane.add(labelPhone);
- table.addMouseListener( new MouseAdapter(){
+ table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
row = table.getSelectedRow();
Enumeration<Offer> rhs = rh.getAllOffers().elements();
while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
- Vector<Object> row = new Vector<Object>();
- row.add(of.getOfferNumber());
- row.add(of.getFirstDay());
- row.add(of.getLastDay());
- row.add(of.getPrice());
- tableModel.addRow(row);
-
+ if (of.getBooking() == null) {
+ Vector<Object> row = new Vector<Object>();
+ row.add(of.getOfferNumber());
+ row.add(of.getFirstDay());
+ row.add(of.getLastDay());
+ row.add(of.getPrice());
+ tableModel.addRow(row);
+ }
}
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
/**
Date firstDay = (Date) table.getModel().getValueAt(row, 1);
Date lastDay = (Date) table.getModel().getValueAt(row, 2);
if (FirstDay != null && LastDay != null) {
- if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
+ if (LastDay.before(lastDay) || FirstDay.after(firstDay)) {
setBackground(Color.RED);
setForeground(Color.BLACK);
} else {
private void jButton_ActionPerformed(ActionEvent arg0) {
BookingManager bookingM = new BookingManager();
- //RegExp to see if telephone number is correct??TODO
+ // RegExp to see if telephone number is correct??TODO
if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) {
labelPhone.setText("");
Booking book = null;
try {
- if (table.getRowCount()!=0)
- book = bookingM.createBooking(rh, rh.offers.get(row).getFirstDay(), rh.offers.get(row).getLastDay(), telIn.getText());
+ if (table.getRowCount() != 0)
+ book = bookingM.createBooking(rh, rh.offers.get(row)
+ .getFirstDay(), rh.offers.get(row).getLastDay(),
+ telIn.getText());
} catch (Exception e) {
e.printStackTrace();
- }
+ }
if (book != null) {
BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
book);
} else {
labelPhone.setText("Phone format is wrong");
-
}
}
}
import javax.swing.border.EmptyBorder;
import domain.Owner;
+import javax.swing.LayoutStyle.ComponentPlacement;
public class OwnerMenuGUI extends JFrame {
a.setVisible(true);
}
});
-
+
JButton btnOffers = new JButton("Offers");
btnOffers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
a.setVisible(true);
}
});
+
+ JButton btnBookings = new JButton("Bookings");
+ btnBookings.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ Frame a = new listOfBookingRequestsGUI(owner);
+ a.setVisible(true);
+ }
+ });
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(115)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addComponent(btnOffers, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
- .addComponent(btnHouses, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE))
+ .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
+ .addComponent(btnBookings, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(btnOffers, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
+ .addComponent(btnHouses, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
.addContainerGap(145, Short.MAX_VALUE))
);
gl_contentPane.setVerticalGroup(
.addComponent(btnHouses, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
.addGap(58)
.addComponent(btnOffers, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
- .addContainerGap(142, Short.MAX_VALUE))
+ .addPreferredGap(ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
+ .addComponent(btnBookings, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
+ .addContainerGap())
);
contentPane.setLayout(gl_contentPane);
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
+import java.util.LinkedList;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
-import businessLogic.AdminManager;
-import businessLogic.HouseManager;
-import businessLogic.HouseManagerInterface;
-import domain.Administrator;
+import businessLogic.BookingManager;
+import domain.Booking;
+import domain.Offer;
+import domain.Owner;
import domain.RuralHouse;
public class listOfBookingRequestsGUI extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
+ private Owner own;
+ private BookingManager bookM = new BookingManager();
private DefaultTableModel tableModel;
- private AdminManager am = new AdminManager();
- private Vector<RuralHouse> houses;
- /**
+ private Vector<Booking> bookings = new Vector<Booking>();
+
+ /**
* Create the frame.
*/
- public listOfBookingRequestsGUI() {
- setTitle("Adding requests");
+ public listOfBookingRequestsGUI(Owner own) {
+ setTitle("Adding requests");
+ this.own = own;
try {
- this.houses= am.getAdditionRequests();
+
init();
} catch (Exception e) {
e.printStackTrace();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
-
+
+ this.bookings= this.bookM.getAllBookings(own);
JLabel lblNewLabel = new JLabel();
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
lblNewLabel.setBounds(23, 41, 536, 33);
contentPane.add(lblNewLabel);
- if (houses.isEmpty())
- lblNewLabel.setText("There are not houses to be added");
+ if (bookings.isEmpty())
+ lblNewLabel
+ .setText("There are not bookings to be confirmed or denied");
else
- lblNewLabel.setText("List of houses to be added:");
+ lblNewLabel.setText("List of bookings:");
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
scrollPane.setBounds(23, 113, 536, 271);
contentPane.add(scrollPane);
table = new JTable() {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- public boolean isCellEditable(int row, int column) {
- return false;
- };
- };
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ };
+ };
scrollPane.setViewportView(table);
tableModel = new DefaultTableModel(null, new String[] {
- "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
- "Livings" });
-
- //Maybe there is a better way to avoid interaction.
- //table.setEnabled(false);
+ "Booking Number", "Is paid", "Booking Date", "Telephone",
+ "Offer" });
+
+ // Maybe there is a better way to avoid interaction.
+ // table.setEnabled(false);
table.setModel(tableModel);
-
- JButton btnNewButton = new JButton("Confirm Addition");
+
+ JButton btnNewButton = new JButton("Confirm Booking");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
- HouseManagerInterface hm = new HouseManager();
- RuralHouse rh = houses.get(table.getSelectedRow());
- //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
- hm.registerNewHouse(rh);
- am.removeHouseAdditionRequests(rh);
- Administrator.saveInstance();
- ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
- houses.remove(rh);
+ if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+
}
}
});
btnNewButton.setBounds(88, 396, 169, 25);
contentPane.add(btnNewButton);
-
- JButton btnDenyAddition = new JButton("Deny Addition");
+
+ JButton btnDenyAddition = new JButton("Deny Booking");
btnDenyAddition.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
- RuralHouse rh = houses.get(table.getSelectedRow());
- am.removeHouseAdditionRequests(rh);
- Administrator.saveInstance();
- ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
- houses.remove(rh);
+ if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+
}
}
});
btnDenyAddition.setBounds(300, 396, 169, 25);
contentPane.add(btnDenyAddition);
- Enumeration<RuralHouse> en = houses.elements();
- RuralHouse rh;
-
+ Enumeration<Booking> en = this.bookings.elements();
+ Booking book;
while (en.hasMoreElements()) {
- rh = en.nextElement();
+ book = en.nextElement();
Vector<Object> row = new Vector<Object>();
- row.add(rh.getHouseName());
- row.add(rh.getFeatures().getnRooms());
- row.add(rh.getFeatures().getnKitchens());
- row.add(rh.getFeatures().getnBaths());
- row.add(rh.getFeatures().getnParkings());
- row.add(rh.getFeatures().getnLivings());
+ row.add(book.getBookNumber());
+ row.add(book.isPaid());
+ row.add(book.getBookDate());
+ row.add(book.getTelephone());
+ row.add(book.getOffer());
tableModel.addRow(row);
}