package businessLogic;
import java.rmi.*;
-
import java.util.Vector;
import java.util.Date;
import domain.Offer;
import domain.Owner;
import domain.RuralHouse;
-
-import exceptions.OfferCanNotBeBooked;
+import exceptions.OfferCanNotBeBooked;
public interface ApplicationFacadeInterface extends Remote {
/**
- * This method obtains an owner's rural houses
- *
- * @param owner object
- *
- * @return a vector of Rural Houses
- */
- Vector<RuralHouse> getRuralHouses(Owner owner)
- throws RemoteException;
-
- /**
- * This method creates an offer with a house number, first day, last day and price
+ * This method creates an offer with a house number, first day, last day and
+ * price
*
* @param House
* number, start day, last day and price
String telephoneNumber) throws RemoteException, OfferCanNotBeBooked;
/**
- * This method obtains available offers for a concrete house in a certain period
+ * This method obtains available offers for a concrete house in a certain
+ * period
*
- * @param houseNumber, the house number where the offers must be obtained
- * @param firstDay, first day in a period range
- * @param lastDay, last day in a period range
- * @return a vector of offers(Offer class) available in this period
+ * @param houseNumber
+ * , the house number where the offers must be obtained
+ * @param firstDay
+ * , first day in a period range
+ * @param lastDay
+ * , last day in a period range
+ * @return a vector of offers(Offer class) available in this period
*/
- Vector<Offer> getOffers(RuralHouse houseNumber, Date firstDay, Date lastDay)
+ Vector<Offer> getOffers(RuralHouse houseNumber, Date firstDay, Date lastDay)
throws RemoteException, Exception;
-
+
/**
- * This method finds existing owners
+ * This method finds existing owners
*
*/
- public Vector<Owner> getOwners() throws RemoteException,
+ public Vector<Owner> getOwners() throws RemoteException, Exception;
+
+ /**
+ * This method obtains an owner's rural houses
+ *
+ * @param owner
+ * object
+ *
+ * @return a vector of Rural Houses
+ */
+ public Vector<RuralHouse> getRuralHouses(Owner owner)
+ throws RemoteException;
+
+ public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
Exception;
-
-
-
- public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
- Exception;
-
+
}
\ No newline at end of file
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
-
import java.util.Date;
import java.util.Vector;
-
import java.sql.SQLException;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
-import configuration.Config;
+import configuration.Config;
import dataAccess.DB4oManager;
-
import domain.Booking;
import domain.Offer;
import domain.Owner;
import domain.RuralHouse;
-
import exceptions.OfferCanNotBeBooked;
public class FacadeImplementation extends UnicastRemoteObject implements ApplicationFacadeInterface {
dbMngr = DB4oManager.getInstance();
}
- /**
- * This method obtains an owner's rural houses
- *
- * @param owner object
- *
- * @return a vector of Rural Houses
- */
- public Vector<RuralHouse> getRuralHouses(Owner owner)
- throws RemoteException {
- return owner.getRuralHouses();
- }
public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
float price) throws RemoteException, Exception {
return dbMngr.getOwners();
}
+ /**
+ * This method obtains an owner's rural houses
+ *
+ * @param owner object
+ *
+ * @return a vector of Rural Houses
+ */
+ public Vector<RuralHouse> getRuralHouses(Owner owner)
+ throws RemoteException {
+ return owner.getRuralHouses();
+ }
+
+
public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
Exception {
return dbMngr.getAllRuralHouses();
}
-
public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
package businessLogic;
+import java.rmi.RemoteException;
import java.util.Date;
import java.util.Vector;
import dataAccess.DB4oManager;
import domain.Account;
+import domain.HouseFeatures;
import domain.Offer;
import domain.Owner;
import domain.RuralHouse;
public boolean registerNewHouse(int houseNumber, Owner owner, String town,
int nRooms, int nKitchens, int nBaths, int nLivings, int nParkings) {
// TODO Auto-generated method stub
+ boolean stored = false;
if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
return false;
- try {
- this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber, owner,
- town, nRooms, nKitchens, nBaths, nLivings, nParkings));
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
+ HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths,
+ nLivings, nParkings);
+ stored = this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber,
+ owner, town, feature));
+ return stored;
}
String description, String town, int nRooms, int nKitchens,
int nBaths, int nLivings, int nParkings) {
// TODO Auto-generated method stub
+ boolean stored = false;
if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
return false;
- try {
- this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber, owner,
- description, town, nRooms, nKitchens, nBaths, nLivings,
- nParkings));
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
+ HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths,
+ nLivings, nParkings);
+ stored = this.dbMngr.storeRuralHouses(new RuralHouse(houseNumber,
+ owner, description, town, feature));
+ return stored;
}
- @Override
- public void modifyHouse(int houseNumber, Owner owner, String description,
- String town, int nRooms, int nKitchens, int nBaths, int nLivings,
- int nParkings) {
- // TODO Auto-generated method stub
-
- }
-
- //Maybe returning the offer is not necessary. Depends on GUI implementation.
- @Override
- public Offer setOffers(RuralHouse ruralHouse, Date firstDay, Date lastDay,
- float price) {
- // TODO Auto-generated method stub
- try {
- return this.dbMngr.createOffer(ruralHouse, firstDay, lastDay, price);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
+ public void removeHouse(int houseNumber) {
+ this.dbMngr.removeHouse(houseNumber);
}
+ // For future implementation
+ // @Override
+ // public void modifyHouse(int houseNumber, Owner owner, String description,
+ // String town, int nRooms, int nKitchens, int nBaths, int nLivings,
+ // int nParkings) {
+ // // TODO Auto-generated method stub
+ //
+ // }
+
+ // Maybe returning the offer is not necessary. Depends on GUI
+ // implementation.
+
}
package businessLogic;
+import java.rmi.RemoteException;
import java.util.Date;
+import java.util.Vector;
import domain.Offer;
import domain.Owner;
String description, String town, int nRooms, int nKitchens,
int nBaths, int nLivings, int nParkings);
- public void modifyHouse(int houseNumber, Owner owner,
- String description, String town, int nRooms, int nKitchens,
- int nBaths, int nLivings, int nParkings);
+ // For future implementation
+ // public void modifyHouse(int houseNumber, Owner owner,
+ // String description, String town, int nRooms, int nKitchens,
+ // int nBaths, int nLivings, int nParkings);
+
+ public void removeHouse(int houseNumber);
- public Offer setOffers(RuralHouse ruralHouse, Date firstDay, Date lastDay,
- float price);
}
/**
* @param rh
*/
- public void storeRuralHouses(RuralHouse rh) {
+ public boolean storeRuralHouses(RuralHouse rh) {
DB4oManager.openDatabase("open");
+ boolean stored = false;
ObjectContainer db = DB4oManager.getContainer();
+ RuralHouse house = new RuralHouse(rh.getHouseNumber(), null, null,
+ null, null);
try {
- db.store(rh);
- db.commit();
+ ObjectSet<Owner> result = db.queryByExample(house);
+ if (result.isEmpty()) {
+ db.store(rh);
+ db.commit();
+ stored = true;
+ }
} finally {
db.close();
}
+ return stored;
}
/**
DB4oManager.openDatabase("open");
ObjectContainer db = DB4oManager.getContainer();
try {
- RuralHouse proto = new RuralHouse(0, null, null, null, 0, 0, 0, 0,
- 0);
+ RuralHouse proto = new RuralHouse(0, null, null, null, null);
ObjectSet<RuralHouse> result = db.queryByExample(proto);
Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
while (result.hasNext())
Offer o;
try {
RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
- null, ruralHouse.getDescription(), ruralHouse.getTown(), 0,
- 0, 0, 0, 0);
+ null, ruralHouse.getDescription(), ruralHouse.getTown(),
+ ruralHouse.getFeatures());
ObjectSet<RuralHouse> result = db.queryByExample(proto);
RuralHouse rh = (RuralHouse) result.next();
o = rh.createOffer(firstDay, lastDay, price);
try {
ObjectContainer db = DB4oManager.getContainer();
RuralHouse proto = new RuralHouse(rh.getHouseNumber(), null,
- rh.getDescription(), rh.getTown(), 0, 0, 0, 0, 0);
+ rh.getDescription(), rh.getTown(), rh.getFeatures());
ObjectSet<RuralHouse> result = db.queryByExample(proto);
return rh = (RuralHouse) result.next();
} catch (Exception exc) {
}
}
+ public void removeHouse(int houseNumber) {
+ ObjectContainer db = DB4oManager.getContainer();
+ RuralHouse house = new RuralHouse(houseNumber, null, null, null, null);
+ try {
+ ObjectSet<RuralHouse> result = db.queryByExample(house);
+ if (!result.isEmpty()) {
+ RuralHouse found = (RuralHouse) result.get(0);
+ db.delete(found);
+ db.commit();
+ }
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ } finally {
+ db.close();
+ }
+
+ }
+
/**
* This method returns the instance of the DB4oManager class
*
public RuralHouse addRuralHouse(int houseNumber, String town, int nRooms,
int nKitchens, int nBaths, int nLivings, int nParkings) {
- RuralHouse rh = new RuralHouse(houseNumber, this, town, nRooms,
- nKitchens, nBaths, nLivings, nParkings);
+ HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, nLivings, nParkings);
+ RuralHouse rh = new RuralHouse(houseNumber, this, town,feature);
ruralHouses.add(rh);
return rh;
}
public RuralHouse addRuralHouse(int houseNumber, String description,
String town, int nRooms, int nKitchens, int nBaths, int nLivings,
int nParkings) {
- RuralHouse rh = new RuralHouse(houseNumber, this, description, town,
- nRooms, nKitchens, nBaths, nLivings, nParkings);
+ HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, nLivings, nParkings);
+ RuralHouse rh = new RuralHouse(houseNumber, this, description, town,feature);
ruralHouses.add(rh);
return rh;
}
super();
}
- public RuralHouse(int houseNumber, Owner owner, String description, String town , int nRooms,int nKitchens,int nBaths,
- int nLivings,int nParkings) {
+ public RuralHouse(int houseNumber, Owner owner, String description, String town ,HouseFeatures features) {
this.houseNumber = houseNumber;
this.description = description;
this.owner = owner;
this.town = town;
- this.features = new HouseFeatures(nRooms,nKitchens,nBaths,nLivings,nParkings);
+ this.features = features;
offers=new Vector<Offer>();
}
- public RuralHouse(int houseNumber, Owner owner, String town , int nRooms,int nKitchens,int nBaths,
- int nLivings,int nParkings) {
+ public RuralHouse(int houseNumber, Owner owner, String town , HouseFeatures features) {
this.houseNumber = houseNumber;
this.description = null;
this.owner = owner;
this.town = town;
- this.features = new HouseFeatures(nRooms,nKitchens,nBaths,nLivings,nParkings);
+ this.features = features;
offers=new Vector<Offer>();
}
public void setTown(String town) {
this.town=town;
}
-
+ public HouseFeatures getFeatures() {
+ return features;
+ }
+
+ public void setFeatures(HouseFeatures features) {
+ this.features = features;
+ }
public String toString() {
return this.houseNumber + ": " + this.town;
}
return availableOffers;
}
+
/**
* This method obtains the offer that match exactly with a given dates that has not been booked
*
import java.awt.event.ActionEvent;
import java.awt.Color;
-public class IntroduceOfferGUI extends JFrame {
+public class LoginGUI extends JFrame {
private static final long serialVersionUID= 1L;
private JPanel jContentPane = null;
private LoginManagerInterface loginManager = new LoginManager();
private JLabel loginFeedback;
- public IntroduceOfferGUI() {
+ public LoginGUI() {
super();
initialize();
}
JButton loginButton = new JButton("Login");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
- if(owner==null){
- loginFeedback.setText("Incorrect username or password");
- }else{
- Vector<RuralHouse> ownerHouseList=null;
- try{
- ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
- }catch (Exception e){
- e.printStackTrace();
- }
- if(!ownerHouseList.isEmpty()){
- Frame a = new IntroduceOffer2GUI(ownerHouseList);
- a.setVisible(true);
- }
- else if(ownerHouseList.isEmpty())
- loginFeedback.setText("Login OK , but no houses in your name");
- }
-
- }
+ jButton_ActionPerformed(arg0);
+ }
});
loginButton.setBounds(164, 179, 117, 25);
jContentPane.add(loginButton);
}
return jContentPane;
}
+
+ private void jButton_ActionPerformed(ActionEvent e){
+ Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
+ if(owner==null){
+ loginFeedback.setText("Incorrect username or password");
+ }else{
+ Vector<RuralHouse> ownerHouseList=null;
+ try{
+ ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
+ }catch (Exception e1){
+ e1.printStackTrace();
+ }
+ if(!ownerHouseList.isEmpty()){
+ this.setVisible(false);
+ Frame a = new IntroduceOffer2GUI(ownerHouseList);
+ a.setVisible(true);
+ }
+ else if(ownerHouseList.isEmpty())
+ loginFeedback.setText("Login OK , but no houses in your name");
+ }
+ }
} // @jve:decl-index=0:visual-constraint="222,33"
createOfferButton.setAlignmentX(Component.CENTER_ALIGNMENT);
createOfferButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
- JFrame a = new IntroduceOfferGUI();
+ JFrame a = new LoginGUI();
a.setVisible(true);
}
});