<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/additionalLibs/jcalendar.jar"/>
<classpathentry kind="lib" path="lib/db4o/lib/db4o-8.0.249.16098-all-java5.jar"/>
+ <classpathentry kind="lib" path="lib/javax.mail.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<databaseNode>localhost</databaseNode>
<db4oFilename>db/casas.db4o</db4oFilename>
<dataBaseOpenMode>initialize</dataBaseOpenMode>
- <activationDepth>8</activationDepth>
+ <activationDepth>10</activationDepth>
<updateDepth>8</updateDepth>
<databasePort>8100</databasePort>
<user>softEng</user>
package businessLogic;
+import javax.mail.MessagingException;
+
import dataAccess.DB4oManager;
import domain.Account;
}
public boolean addAccount(Account ac){
- if(this.dbMngr.addAccount(ac))
+ if(this.dbMngr.addAccount(ac)){
+ try {
+ MailManager.getInstance().Send(ac.getOwner().getMailAccount(), "Entered into the system", "Congratulations");
+ } catch (MessagingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
return true;
+ }
return false;
}
import java.util.Date;
import java.util.Vector;
+import javax.mail.MessagingException;
+
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import dataAccess.DB4oManager;
import domain.Booking;
-import domain.Offer;
-import domain.Owner;
+import domain.Client;
import domain.RuralHouse;
import exceptions.OfferCanNotBeBooked;
return theBookingManager;
}
- public void removeBooking(Booking B) {
- // TODO
-
+ public void removeDenyBooking(Booking b){
+ b.getOffer().getBookings().remove(b);
+ this.dbMngr.removeBooking(b);
}
+ public void acceptBooking(Booking b){
+ b.getOffer().setBooked(true);
+ for(Booking boo : b.getOffer().getBookings()){
+ if(!boo.equals(b))
+ b.getOffer().getBookings().remove(b);
+ }
+ this.dbMngr.acceptBooking(b.getOffer());
+ try {
+ MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
+ } catch (MessagingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
/**
* 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 Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
+ Date lastDate, Client client)
throws OfferCanNotBeBooked {
return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
- bookTelephoneNumber);
+ client);
}
}
\ No newline at end of file
--- /dev/null
+package businessLogic;
+
+import java.security.Security;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import com.sun.mail.smtp.SMTPTransport;
+
+public class MailManager {
+
+ private String user = "ruralhousesrh";
+ private String password = "RHRHRHRHRH";
+ private static MailManager mm = null;
+
+ public static MailManager getInstance() {
+ if (mm == null)
+ return new MailManager();
+ else
+ return mm;
+ }
+
+
+ public void Send( String recipientEmail, String title, String message) throws AddressException, MessagingException {
+
+ Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
+ final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
+
+
+ Properties props = System.getProperties();
+ props.setProperty("mail.smtps.host", "smtp.gmail.com");
+ props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
+ props.setProperty("mail.smtp.socketFactory.fallback", "false");
+ props.setProperty("mail.smtp.port", "465");
+ props.setProperty("mail.smtp.socketFactory.port", "465");
+ props.setProperty("mail.smtps.auth", "true");
+
+ props.put("mail.smtps.quitwait", "false");
+
+ Session session = Session.getInstance(props, null);
+
+ // -- Create a new message --
+ final MimeMessage msg = new MimeMessage(session);
+
+ // -- Set the FROM and TO fields --
+ msg.setFrom(new InternetAddress(user + "@gmail.com"));
+ msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail, false));
+
+
+ msg.setSubject(title);
+ msg.setText(message, "utf-8");
+ msg.setSentDate(new Date());
+
+ SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
+
+ t.connect("smtp.gmail.com", user, password);
+ t.sendMessage(msg, msg.getAllRecipients());
+ t.close();
+ }
+}
\ No newline at end of file
//import java.util.Vector;
import java.rmi.RemoteException;
import java.util.Date;
-import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
import domain.Account;
import domain.Administrator;
import domain.Booking;
+import domain.Client;
import domain.HouseFeatures;
import domain.Offer;
//import dataModel.Offer;
}
- @SuppressWarnings("static-access")
public void storeAdmin() {
if (c.isDatabaseLocal() == false)
openSDB();
* day, last day, house number and telephone
* @return a book
*/
- public Booking createBooking(RuralHouse ruralHouse, Date firstDate,
- Date lastDate, String bookTelephoneNumber)
- throws OfferCanNotBeBooked {
+ public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
+ Date lastDate, Client cl) throws OfferCanNotBeBooked {
if (c.isDatabaseLocal() == false)
openSDB();
else
openDB();
- Booking bok = null;
+ Vector<Booking> book = new Vector<Booking>() ;
try {
offer = rh.findOffer(firstDate, lastDate);
if (offer != null) {
- offer.createBooking(theDB4oManagerAux.bookingNumber++,
- bookTelephoneNumber);
+ offer.createBooking(theDB4oManagerAux.bookingNumber++, cl);
db.store(theDB4oManagerAux); // To store the new value for
// bookingNumber
+
db.store(offer);
db.commit();
- bok = offer.getBooking();
+ book = offer.getBookings();
+
}
} catch (com.db4o.ext.ObjectNotStorableException e) {
} finally {
db.close();
}
- return bok;
+ return book;
}
/**
openDB();
try {
- //TODO realize if there is another account with same username. Quite difficult with the f***ing salt
- db.store(acc);
- db.commit();
+ // TODO realize if there is another account with same username.
+ // Quite difficult with the f***ing salt
+ db.store(acc);
+ db.commit();
} catch (Exception exc) {
exc.printStackTrace();
} finally {
}
return true;
}
-
- //TODO remove account
+
+ // TODO remove account
public boolean removeAccount(Account acc) {
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());
+ if (c.isDatabaseLocal() == false)
+ openSDB();
+ else
+ openDB();
+ try {
+ ObjectSet<Offer> result = db.queryByExample(off);
+ this.deleteOffer(result.get(0));
+ db.store(of);
+ db.close();
+
+ } catch (Exception e) {
+ e.printStackTrace();;
+ }
+ }
+
+ public void removeBooking(Booking b){
+ if (c.isDatabaseLocal() == false)
+ openSDB();
+ else
+ openDB();
+ try {
+ ObjectSet<Booking> result = db.queryByExample(b);
+ ObjectSet<Client> result2= db.queryByExample(b.getClient());
+ db.delete(result.get(0));
+ db.delete(result2.get(0));
+ db.commit();
+ } catch (Exception e) {
+ e.printStackTrace();;
+ }finally{
+ db.close();
+ }
+
+
+ }
}
private Date bookingDate;
private Client client;
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(isPaid);
System.out.println(bookingDate);
System.out.println(client.toString());
- System.out.println(offer);
- System.out.println(this.isAccepted);
+ System.out.println(offer);
}
public int getBookNumber() {
return isPaid;
}
- public boolean isAccepted(){
- return this.isAccepted;
- }
+
public Client getClient() {
return client;
import java.io.Serializable;
import java.util.Date;
-import java.util.LinkedList;
import java.util.Vector;
private int offerNumber;
private Date firstDay; // Dates are stored as java.util.Date objects instead of java.sql.Date objects
private Date lastDay; // because, they are not well stored in db4o as java.util.Date objects
- private float price; // This is coherent because objects of java.sql.Date are objects of java.util.Date
- private Vector<Booking> bookings; // That is: java.sql.Date is a subclass (or extends) java.util.Date
+ private float price; // This is coherent because objects of java.sql.Date are objects of java.util.Date ç
+ private boolean isBooked;
+ private Vector<Booking> bookings = new Vector<Booking>(); // That is: java.sql.Date is a subclass (or extends) java.util.Date
private RuralHouse ruralHouse;
* @param First day, last day, house number and telephone
* @return a book
*/
- public Booking createBooking(int numBooking,String bookTelephoneNumber,String name , String mail) {
- Client client = new Client(name,mail,bookTelephoneNumber);
+ public Vector<Booking> createBooking(int numBooking,Client client) {
Booking b = new Booking(numBooking,this,client);
this.bookings.add(b);
- return b;
+ return this.bookings;
}
public void setBookings(Vector<Booking> bookings) {
this.bookings = bookings;
}
+ public boolean isBooked() {
+ return isBooked;
+ }
+ public void setBooked(boolean isBooked) {
+ this.isBooked = isBooked;
+ }
}
\ No newline at end of file
offer = e.next();
if ((offer.getFirstDay().compareTo(firstDay) >= 0)
&& (offer.getLastDay().compareTo(lastDay) <= 0)
- && (offer.getBooking() == null))
+ && (!offer.isBooked()))
availableOffers.add(offer);
}
return availableOffers;
return this.offers;
}
-// /**
-// * This method obtains the offer that match exactly with a given dates that
-// * has not been booked
-// *
-// * @param firstDay
-// * , first day in a period range
-// * @param lastDay
-// * , last day in a period range
-// * @return the offer(Offer class) available for a this period
-// */
-// public Offer findOffer(Date firstDay, Date lastDay) {
-// Iterator<Offer> e = offers.iterator();
-// Offer offer = null;
-// while (e.hasNext()) {
-// offer = e.next();
-// if ((offer.getFirstDay().compareTo(firstDay) == 0)
-// && (offer.getLastDay().compareTo(lastDay) == 0)
-// && (offer.getBooking() == null))
-// return offer;
-// }
-// return null;
-// }
+ /**
+ * This method obtains the offer that match exactly with a given dates that
+ * has not been booked
+ *
+ * @param firstDay
+ * , first day in a period range
+ * @param lastDay
+ * , last day in a period range
+ * @return the offer(Offer class) available for a this period
+ */
+ public Offer findOffer(Date firstDay, Date lastDay) {
+ Iterator<Offer> e = offers.iterator();
+ Offer offer = null;
+ while (e.hasNext()) {
+ offer = e.next();
+ if ((offer.getFirstDay().compareTo(firstDay) == 0)
+ && (offer.getLastDay().compareTo(lastDay) == 0)
+ && (!offer.isBooked()))
+ return offer;
+ }
+ return null;
+ }
public Offer overlapsWith(Date firstDay, Date lastDay) {
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
+
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import businessLogic.BookingManager;
import domain.Booking;
+import domain.Client;
import domain.Offer;
import domain.RuralHouse;
private JTextField telIn;
private int row;
private JLabel labelPhone;
+ private JLabel lblName;
+ private JTextField nameField;
+ private JLabel lblEmail;
+ private JTextField mailField;
/**
* Create the frame.
final Date LastDay) {
this.rh = RH;
this.getContentPane().setLayout(null);
- setBounds(100, 100, 500, 583);
+ setBounds(100, 100, 500, 700);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
scrollPane.setViewportView(table);
JButton btnBookSelected = new JButton("Book SelectedOffer");
- btnBookSelected.setBounds(238, 505, 178, 23);
+ btnBookSelected.setBounds(238, 614, 178, 23);
contentPane.add(btnBookSelected);
btnBookSelected.addActionListener(new ActionListener() {
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Telephone num:");
- lblNewLabel_1.setBounds(10, 509, 83, 14);
+ lblNewLabel_1.setBounds(10, 618, 83, 14);
contentPane.add(lblNewLabel_1);
telIn = new JTextField();
- telIn.setBounds(99, 505, 129, 20);
+ telIn.setBounds(103, 615, 129, 20);
contentPane.add(telIn);
telIn.setColumns(10);
labelPhone.setBounds(238, 252, 178, 14);
contentPane.add(labelPhone);
+ lblName = new JLabel("Name:");
+ lblName.setBounds(10, 516, 46, 14);
+ contentPane.add(lblName);
+
+ nameField = new JTextField();
+ nameField.setBounds(103, 513, 178, 20);
+ contentPane.add(nameField);
+ nameField.setColumns(10);
+
+ lblEmail = new JLabel("E-mail:");
+ lblEmail.setBounds(10, 565, 46, 14);
+ contentPane.add(lblEmail);
+
+ mailField = new JTextField();
+ mailField.setBounds(103, 562, 178, 20);
+ contentPane.add(mailField);
+ mailField.setColumns(10);
+
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
Enumeration<Offer> rhs = rh.getAllOffers().elements();
while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
- if (of.getBookings().size()==1&&of.getBookings().get(0).isAccepted()) {
+ if (of.getBookings() == null
+ || !(of.getBookings().size() == 1 && of.isBooked())) {
Vector<Object> row = new Vector<Object>();
row.add(of.getOfferNumber());
row.add(of.getFirstDay());
private void jButton_ActionPerformed(ActionEvent arg0) {
BookingManager bookingM = new BookingManager();
- // RegExp to see if telephone number is correct??TODO
- if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) {
+
+ if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")
+ && mailField
+ .getText()
+ .matches(
+ "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
+ && !nameField.getText().isEmpty()) {
labelPhone.setText("");
- Booking book = null;
+ Vector<Booking> book = null;
try {
- if (table.getRowCount() != 0)
+ if (table.getRowCount() != 0) {
+ Client cl = new Client(nameField.getText(),
+ mailField.getText(), telIn.getText());
book = bookingM.createBooking(rh, rh.offers.get(row)
- .getFirstDay(), rh.offers.get(row).getLastDay(),
- telIn.getText());
+ .getFirstDay(), rh.offers.get(row).getLastDay(),cl);
+ }
} catch (Exception e) {
e.printStackTrace();
}
if (book != null) {
BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
- book);
+ book.lastElement());
confirmWindow.setVisible(true);
}
} else {
- labelPhone.setText("Phone format is wrong");
+ labelPhone.setText("Bad formatted data.");
}
}
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import domain.Owner;
-import javax.swing.LayoutStyle.ComponentPlacement;
public class OwnerMenuGUI extends JFrame {
package gui;
-import java.awt.BorderLayout;
-import java.awt.EventQueue;
-import java.awt.Frame;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.JButton;
import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
+import javax.swing.JPanel;
import javax.swing.JTextField;
-import javax.swing.JButton;
+import javax.swing.border.EmptyBorder;
import businessLogic.AdminManager;
import domain.Account;
import domain.Owner;
-import java.awt.Color;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
public class OwnerRegistrationGUI extends JFrame {
private JPanel panel;
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 businessLogic.BookingManager;
import domain.Booking;
import domain.Offer;
-import domain.Owner;
-import domain.RuralHouse;
public class listOfBookingRequestsGUI extends JFrame {
}
private void init() throws Exception {
- setBounds(100, 100, 600, 450);
+ setBounds(100, 100, 600, 500);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
};
scrollPane.setViewportView(table);
tableModel = new DefaultTableModel(null, new String[] {
- "Booking Number", "Is paid", "Booking Date", "Telephone",
- "Offer" });
+ "Booking Number", "Is paid", "Booking Date","Name","E-mail", "Telephone" });
// Maybe there is a better way to avoid interaction.
// table.setEnabled(false);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
-
+ if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+ Booking book = bookings.get(table.getSelectedRow());
+ bookM.acceptBooking(book);
+ }
}
}
});
- btnNewButton.setBounds(88, 396, 169, 25);
+ btnNewButton.setBounds(33, 396, 169, 25);
contentPane.add(btnNewButton);
JButton btnDenyAddition = new JButton("Deny Booking");
btnDenyAddition.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
-
+ Booking book = bookings.get(table.getSelectedRow());
+ bookM.removeDenyBooking(book);
}
}
});
- btnDenyAddition.setBounds(300, 396, 169, 25);
+ btnDenyAddition.setBounds(390, 395, 169, 25);
contentPane.add(btnDenyAddition);
+
+ JButton btnSetAsPaid = new JButton("Set as paid");
+ btnSetAsPaid.setBounds(239, 395, 89, 23);
+ btnSetAsPaid.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+
+ }
+ });
+ contentPane.add(btnSetAsPaid);
Enumeration<Booking> en = this.bookings.elements();
Booking book;
while (en.hasMoreElements()) {
row.add(book.getBookNumber());
row.add(book.isPaid());
row.add(book.getBookDate());
- row.add(book.getClient());
- row.add(book.getOffer());
+ row.add(book.getClient().getName());
+ row.add(book.getClient().getMailAccount());
+ row.add(book.getClient().getTelephone());
tableModel.addRow(row);
}
import java.awt.Font;
import java.awt.Rectangle;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.Enumeration;
-import java.util.LinkedList;
import java.util.Vector;
-import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
-import businessLogic.BookingManager;
-import domain.Booking;
import domain.Offer;
import domain.Owner;
-import domain.RuralHouse;
public class listOfOffers extends JFrame {
private JPanel contentPane;
private JTable table;
private Owner owner;
- private BookingManager bookM = new BookingManager();
+
private DefaultTableModel tableModel;
private Vector<Offer> offers = new Vector<Offer>();
lblNewLabel
.setText("There are not bookings to be confirmed or denied");
else
- lblNewLabel.setText("List of bookings:");
+ lblNewLabel.setText("List of offers:");
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;
return false;
};
};
+
scrollPane.setViewportView(table);
tableModel = new DefaultTableModel(null, new String[] { "Offer #",
- "FirstDay", "LastDay", "Price" });
+ "FirstDay", "LastDay", "Price" ,"RuralHouse"});
// Maybe there is a better way to avoid interaction.
// table.setEnabled(false);
table.setModel(tableModel);
-
- JButton btnNewButton = new JButton("Confirm Booking");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
-
- }
- }
- });
- btnNewButton.setBounds(88, 396, 169, 25);
- contentPane.add(btnNewButton);
-
- JButton btnDenyAddition = new JButton("Deny Booking");
- btnDenyAddition.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
-
- }
+ table.addMouseListener( new MouseAdapter(){
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ int row = table.getSelectedRow();
+ listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row));
+ feat.setVisible(true);
}
});
- btnDenyAddition.setBounds(300, 396, 169, 25);
- contentPane.add(btnDenyAddition);
Enumeration<Offer> rhs = this.offers.elements();
while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
row.add(of.getFirstDay());
row.add(of.getLastDay());
row.add(of.getPrice());
+ row.add(of.getRuralHouse().getHouseName());
tableModel.addRow(row);
}