From: camjan Date: Wed, 20 May 2015 21:26:51 +0000 (+0200) Subject: Started with the separated DB with the given code X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/08aaf3b19060c67249a3f3e206690c260e881713 Started with the separated DB with the given code --- diff --git a/ruralHouses client/src/domain/Administrator.java b/ruralHouses client/src/domain/Administrator.java index d1ea781..3bf7db2 100644 --- a/ruralHouses client/src/domain/Administrator.java +++ b/ruralHouses client/src/domain/Administrator.java @@ -3,7 +3,6 @@ package domain; import java.io.Serializable; import java.util.LinkedList; -import configuration.ConfigXML; public class Administrator implements Serializable { @@ -12,11 +11,9 @@ public class Administrator implements Serializable { */ private static final long serialVersionUID = 1L; - private static Administrator admin = null; private static LinkedList addRequest; private static LinkedList removeRequest; private static LinkedList newOwnerRequest; - static ConfigXML c; private Administrator() { addRequest = new LinkedList(); diff --git a/ruralHouses client/src/gui/StartWindow.java b/ruralHouses client/src/gui/StartWindow.java index e938084..3129bad 100644 --- a/ruralHouses client/src/gui/StartWindow.java +++ b/ruralHouses client/src/gui/StartWindow.java @@ -19,7 +19,6 @@ import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.UIManager; -import configuration.ConfigXML; @SuppressWarnings("deprecation") public class StartWindow extends JFrame { @@ -29,7 +28,6 @@ public class StartWindow extends JFrame { private JPanel jContentPane = null; private JButton boton2 = null; private JButton boton3 = null; - private static configuration.ConfigXML c; private JLabel lblNewLabel; public static void main(String[] args) { @@ -42,16 +40,12 @@ public class StartWindow extends JFrame { try { - c = ConfigXML.getInstance(); - - System.setProperty("java.security.policy", c.getJavaPolicyPath()); + System.setProperty("java.security.policy", "java.policy"); System.setSecurityManager(new RMISecurityManager()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - c = configuration.ConfigXML.getInstance(); - } catch (com.db4o.ext.DatabaseFileLockedException e) { a.lblNewLabel .setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!"); diff --git a/ruralHouses client/src/gui/listOfBookingRequestsGUI.java b/ruralHouses client/src/gui/listOfBookingRequestsGUI.java index 2106e88..ba96f0d 100644 --- a/ruralHouses client/src/gui/listOfBookingRequestsGUI.java +++ b/ruralHouses client/src/gui/listOfBookingRequestsGUI.java @@ -22,8 +22,7 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import common.BookingInterface; -import common.HouseInterface; -import common.OfferInterface; + import configuration.___IntNames; import domain.Booking; import domain.Offer; diff --git a/ruralHouses/config.out.xml b/ruralHouses/config.out.xml deleted file mode 100644 index e69de29..0000000 diff --git a/ruralHouses/config.xml b/ruralHouses/config.xml index 0ce7502..d71d8fb 100644 --- a/ruralHouses/config.xml +++ b/ruralHouses/config.xml @@ -5,7 +5,7 @@ 1099 RuralHouses - + localhost db/casas.db4o initialize diff --git a/ruralHouses/src/businessLogic/AccountManager.java b/ruralHouses/src/businessLogic/AccountManager.java index 0ad55b1..2536474 100644 --- a/ruralHouses/src/businessLogic/AccountManager.java +++ b/ruralHouses/src/businessLogic/AccountManager.java @@ -6,6 +6,7 @@ import java.rmi.server.UnicastRemoteObject; import javax.mail.MessagingException; import common.AccountInterface; + import dataAccess.DB4oManager; import domain.Account; import domain.Administrator; diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java index 3fe64f2..f5b993d 100644 --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@ -7,10 +7,8 @@ import java.util.Vector; import javax.mail.MessagingException; -import com.db4o.ObjectContainer; -import com.db4o.ObjectSet; - import common.BookingInterface; + import dataAccess.DB4oManager; import domain.Booking; import domain.Client; diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 4553f48..fa85cfa 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -103,6 +103,18 @@ public class DB4oManager { configurationCS.common().activationDepth(c.getActivationDepth()); configurationCS.common().updateDepth(c.getUpdateDepth()); configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true); + configurationCS.common().objectClass(Booking.class).cascadeOnDelete(true); + configurationCS.common().objectClass(RuralHouse.class) + .cascadeOnDelete(true); + configurationCS.common().objectClass(Account.class).cascadeOnDelete(true); + configurationCS.common().objectClass(Offer.class).cascadeOnDelete(true); + configurationCS.common().objectClass(Owner.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(Booking.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(RuralHouse.class) + .cascadeOnUpdate(true); + configurationCS.common().objectClass(Account.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(Offer.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(Account.class).cascadeOnUpdate(true); db = Db4oClientServer.openClient(configurationCS, c.getDatabaseNode(), c.getDatabasePort(), c.getUser(), c.getPassword()); @@ -548,7 +560,7 @@ public class DB4oManager { openDB(); try { - ObjectSet result = db.queryByExample(new Account(null,null,own)); + ObjectSet result = db.queryByExample(new Account(own)); if (!result.isEmpty()) { db.delete(result.get(0)); db.commit(); diff --git a/ruralHouses/src/domain/Account.java b/ruralHouses/src/domain/Account.java index 7fb472c..989440c 100644 --- a/ruralHouses/src/domain/Account.java +++ b/ruralHouses/src/domain/Account.java @@ -2,6 +2,7 @@ package domain; import java.io.Serializable; import java.util.Arrays; + import businessLogic.SecurityManager; @@ -16,17 +17,15 @@ public class Account implements Serializable { private byte[] username; private byte[] password; private byte[] salt; - - private Owner owner; private boolean admin = false; + public Account(byte[] usr){ this.username = usr; this.salt =null; this.password = null; this.owner = null; - } public Account(String usr, String pass, boolean isAdmin) { this.username = SecurityManager.getInstance().calculateHash(usr); @@ -34,7 +33,13 @@ public class Account implements Serializable { this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt); this.owner = null; this.admin = isAdmin; - + } + + public Account(Owner own){ + this.username = null; + this.salt =null; + this.password = null; + this.owner = own; } public Account(String usr, String pass, Owner ow) { diff --git a/ruralHousesDB/.DS_Store b/ruralHousesDB/.DS_Store new file mode 100644 index 0000000..4eec472 Binary files /dev/null and b/ruralHousesDB/.DS_Store differ diff --git a/ruralHousesDB/.classpath b/ruralHousesDB/.classpath new file mode 100644 index 0000000..4a939f6 --- /dev/null +++ b/ruralHousesDB/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ruralHousesDB/.gitignore b/ruralHousesDB/.gitignore new file mode 100644 index 0000000..b83f20a --- /dev/null +++ b/ruralHousesDB/.gitignore @@ -0,0 +1,5 @@ +/bin +/lib +!lib/mail/ +/db +/src/*/*.class diff --git a/ruralHousesDB/.project b/ruralHousesDB/.project new file mode 100644 index 0000000..0a88c12 --- /dev/null +++ b/ruralHousesDB/.project @@ -0,0 +1,17 @@ + + + ruralHousesDB + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ruralHouses client/config.xml b/ruralHousesDB/config.xml similarity index 71% rename from ruralHouses client/config.xml rename to ruralHousesDB/config.xml index d80475a..0ce7502 100644 --- a/ruralHouses client/config.xml +++ b/ruralHousesDB/config.xml @@ -1,12 +1,11 @@ - - localhost - 1099 - RuralHouses - + + localhost + 1099 + RuralHouses + - localhost db/casas.db4o initialize @@ -17,5 +16,4 @@ i4softwEngin2matx java.policy - \ No newline at end of file diff --git a/ruralHousesDB/java.policy b/ruralHousesDB/java.policy new file mode 100644 index 0000000..a38bc88 --- /dev/null +++ b/ruralHousesDB/java.policy @@ -0,0 +1,9 @@ +grant { +permission java.security.AllPermission; +}; +// If there problems with permissions: +// permission java.security.AllPermission; +//permission java.net.SocketPermission "localhost:1099", "connect,resolve"; +//permission java.net.SocketPermission "*", "accept,resolve"; +//permission java.io.FilePermission "casas.db4o", "delete,read,write"; +//permission java.util.PropertyPermission "*", "read"; \ No newline at end of file diff --git a/ruralHousesDB/src/configuration/.DS_Store b/ruralHousesDB/src/configuration/.DS_Store new file mode 100644 index 0000000..02896dc Binary files /dev/null and b/ruralHousesDB/src/configuration/.DS_Store differ diff --git a/ruralHouses client/src/configuration/ConfigXML.java b/ruralHousesDB/src/configuration/ConfigXML.java similarity index 100% rename from ruralHouses client/src/configuration/ConfigXML.java rename to ruralHousesDB/src/configuration/ConfigXML.java diff --git a/ruralHousesDB/src/dataAccess/.DS_Store b/ruralHousesDB/src/dataAccess/.DS_Store new file mode 100644 index 0000000..de29268 Binary files /dev/null and b/ruralHousesDB/src/dataAccess/.DS_Store differ diff --git a/ruralHousesDB/src/dataAccess/DB4oServerManager.java b/ruralHousesDB/src/dataAccess/DB4oServerManager.java new file mode 100644 index 0000000..ea75334 --- /dev/null +++ b/ruralHousesDB/src/dataAccess/DB4oServerManager.java @@ -0,0 +1,128 @@ +package dataAccess; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.border.EmptyBorder; + +import com.db4o.ObjectServer; +import com.db4o.cs.Db4oClientServer; +import com.db4o.cs.config.ServerConfiguration; + +import configuration.ConfigXML; +import domain.Account; +import domain.Booking; +import domain.Offer; +import domain.Owner; +import domain.RuralHouse; + +public class DB4oServerManager extends JDialog { + + /** + * + */ + private static final long serialVersionUID = 1L; + private final JPanel contentPanel = new JPanel(); + JTextArea textArea; + ObjectServer server; + private ServerConfiguration configurationCS; + + /** + * Launch the application. + */ + public static void main(String[] args) { + try { + DB4oServerManager dialog = new DB4oServerManager (); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Create the dialog. + */ + public DB4oServerManager () { + setTitle("DB4oManagerServer: running the database server"); + setBounds(100, 100, 486, 180); + getContentPane().setLayout(new BorderLayout()); + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(contentPanel, BorderLayout.CENTER); + contentPanel.setLayout(new BorderLayout(0, 0)); + { + textArea = new JTextArea(); + contentPanel.add(textArea); + } + { + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton okButton = new JButton("OK"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + textArea.append("\n\n\nClosing the database... "); + try { + server.close(); + } catch (Exception e1) { + } + System.exit(1); + } + }); + okButton.setActionCommand("OK"); + buttonPane.add(okButton); + getRootPane().setDefaultButton(okButton); + } + { + JButton cancelButton = new JButton("Cancel"); + cancelButton.setActionCommand("Cancel"); + buttonPane.add(cancelButton); + } + } + + ConfigXML c=ConfigXML.getInstance(); + + + try{ + + if (c.getDataBaseOpenMode().equals("initialize")) new File(c.getDb4oFilename()).delete(); + + configurationCS = Db4oClientServer.newServerConfiguration(); + configurationCS.common().activationDepth(c.getActivationDepth()); + configurationCS.common().updateDepth(c.getUpdateDepth()); + configurationCS.common().objectClass(Owner.class).cascadeOnDelete(true); + configurationCS.common().objectClass(Booking.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(RuralHouse.class) + .cascadeOnUpdate(true); + configurationCS.common().objectClass(Account.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(Offer.class).cascadeOnUpdate(true); + configurationCS.common().objectClass(Account.class).cascadeOnUpdate(true); + + server = Db4oClientServer.openServer(configurationCS, + c.getDb4oFilename(),c.getDatabasePort()); + + textArea.append("\nConnection to the database '"+c.getDb4oFilename()+"' opened in port "+c.getDatabasePort()); + + server.grantAccess(c.getUser(),c.getPassword()); + + textArea.append("\nAccess granted to: "+c.getUser()); + + + + textArea.append("\nPress button to exit this database server... "); + + } catch (Exception e) { + textArea.append("Something has happened in DB4oManagerServer: "+e.toString()); + + } + } +} + diff --git a/ruralHousesDB/src/domain/Account.java b/ruralHousesDB/src/domain/Account.java new file mode 100644 index 0000000..f401391 --- /dev/null +++ b/ruralHousesDB/src/domain/Account.java @@ -0,0 +1,84 @@ +package domain; + +import java.io.Serializable; +import java.util.Arrays; + + +public class Account implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + private byte[] username; + private byte[] password; + private byte[] salt; + + + private Owner owner; + private boolean admin = false; + + public Account(byte[] usr){ + + + } + public Account(String usr, String pass, boolean isAdmin) { + + + } + + public Account(String usr, String pass, Owner ow) { + + + } + + + + + public byte[] getUsername() { + return username; + } + + public byte[] getPassword() { + return password; + } + + public Owner getOwner() { + return owner; + } + + public boolean getAdmin() { + return admin; + } + + + public void setAdmin(boolean admin) { + this.admin = admin; + } + + public byte[] getSalt() { + return salt; + } + + public void setSalt(byte[] salt) { + this.salt = salt; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Account other = (Account) obj; + if (!Arrays.equals(username, other.username)) + return false; + return true; + } + +} diff --git a/ruralHousesDB/src/domain/Administrator.java b/ruralHousesDB/src/domain/Administrator.java new file mode 100644 index 0000000..25d51d4 --- /dev/null +++ b/ruralHousesDB/src/domain/Administrator.java @@ -0,0 +1,61 @@ +package domain; + +import java.io.Serializable; +import java.util.LinkedList; + +import configuration.ConfigXML; + +public class Administrator implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private static Administrator admin = null; + private static LinkedList addRequest; + private static LinkedList removeRequest; + private static LinkedList newOwnerRequest; + static ConfigXML c; + + private Administrator() { + addRequest = new LinkedList(); + removeRequest = new LinkedList(); + newOwnerRequest = new LinkedList(); + } + + public static Administrator getInstance() { + + return admin; + + } + + public static void saveInstance() { + } + + public LinkedList getAddRequest() { + return addRequest; + } + + public LinkedList getRemoveRequest() { + return removeRequest; + } + + public void setAddRequest(LinkedList addRequest) { + Administrator.addRequest = addRequest; + } + + public void setRemoveRequest(LinkedList removeRequest) { + Administrator.removeRequest = removeRequest; + + } + + public LinkedList getNewOwnerRequest() { + return newOwnerRequest; + } + + public void setNewOwnerRequest(LinkedList newOwnerRequest) { + Administrator.newOwnerRequest = newOwnerRequest; + } + +} diff --git a/ruralHousesDB/src/domain/Booking.java b/ruralHousesDB/src/domain/Booking.java new file mode 100644 index 0000000..4b68a70 --- /dev/null +++ b/ruralHousesDB/src/domain/Booking.java @@ -0,0 +1,65 @@ +package domain; + +import java.io.Serializable; +import java.util.Date; + +public class Booking implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + private int bookingNumber; + private Date bookingDate; + private Client client; + private Offer offer; + + + + public Booking(int bN , Offer offer,Client client) { + + this.bookingNumber = bN; + this.offer = offer; + this.client=client; + //Booking date is assigned to actual date + this.bookingDate= new java.util.Date(System.currentTimeMillis()); + } + + + public Booking(int bN , Offer offer,Client client, Date bookDate) { + this.bookingNumber = bN; + this.offer = offer; + this.client=client; + this.bookingDate= bookDate; } + + + public int getBookNumber() { + return this.bookingNumber; + } + + public void setOffer(Offer offer) { + this.offer = offer; + } + + public Offer getOffer() { + return this.offer; + } + + + public void setBookDate(Date bookDate) { + this.bookingDate = bookDate; + } + + public Date getBookDate() { + return this.bookingDate; + } + + public Client getClient() { + return client; + } + + public void setClient(Client client) { + this.client = client; + } + +} \ No newline at end of file diff --git a/ruralHousesDB/src/domain/Client.java b/ruralHousesDB/src/domain/Client.java new file mode 100644 index 0000000..a4c0baf --- /dev/null +++ b/ruralHousesDB/src/domain/Client.java @@ -0,0 +1,46 @@ +package domain; + +import java.io.Serializable; + +public class Client implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + private String name; + private String mailAccount; + private String telephone; + + public Client(String name, String mailAccount, String telephone) { + super(); + this.name = name; + this.mailAccount = mailAccount; + this.telephone = telephone; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMailAccount() { + return mailAccount; + } + + public void setMailAccount(String mailAccount) { + this.mailAccount = mailAccount; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + +} diff --git a/ruralHousesDB/src/domain/Districs.java b/ruralHousesDB/src/domain/Districs.java new file mode 100644 index 0000000..2866692 --- /dev/null +++ b/ruralHousesDB/src/domain/Districs.java @@ -0,0 +1,34 @@ +package domain; + +import java.io.Serializable; + +public enum Districs implements Serializable { + + /** + * + */ + BEA("Beatriz"), GUA("Guazate"), VEG("Vegas"), FAR("Farallón"), CED("Cedro"), MOT( + "Monte LLano"), RIN("Rincón"), PUE("Pueblo"), QUA("Quebrada Arriba"), QEB( + "Quebrada Abajo"), TOI("Toita"), MAB("Matón Abajo"), MAA( + "Matón Arriba"), PIE("Piedras"), PAV("Pasto Viejo"), PEA( + "PedroAvila"), SUM("Sumido"), LAP("Lapa"), CER("Cercadillo"), JAJ( + "JójomeAlto"), CUL("CulebrasAbajo"); + + private static final long serialVersionUID = 1L; + + + private final String longName; + + Districs(String longName) { + this.longName = longName; + } + + public static String[] longNames() { + String[] result = new String[Districs.values().length]; + for (Districs d : Districs.values()) { + result[d.ordinal()] = d.longName; + } + return result; + + } +} diff --git a/ruralHousesDB/src/domain/HouseFeatures.java b/ruralHousesDB/src/domain/HouseFeatures.java new file mode 100644 index 0000000..52502cb --- /dev/null +++ b/ruralHousesDB/src/domain/HouseFeatures.java @@ -0,0 +1,56 @@ +package domain; + +import java.io.Serializable; + +public class HouseFeatures implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + private int nRooms; + private int nKitchens; + private int nBaths; + private int nLivings; + private int nParkings; + + public HouseFeatures(int nRooms, int nKitchens, int nBaths, int nLivings, + int nParkings) { + super(); + this.nRooms = nRooms; + this.nKitchens = nKitchens; + this.nBaths = nBaths; + this.nLivings = nLivings; + this.nParkings = nParkings; + } + + public int getnRooms() { + return nRooms; + } + + + + public int getnKitchens() { + return nKitchens; + } + + + + public int getnBaths() { + return nBaths; + } + + + + public int getnLivings() { + return nLivings; + } + + + + public int getnParkings() { + return nParkings; + } + + +} diff --git a/ruralHousesDB/src/domain/Offer.java b/ruralHousesDB/src/domain/Offer.java new file mode 100644 index 0000000..3442a6a --- /dev/null +++ b/ruralHousesDB/src/domain/Offer.java @@ -0,0 +1,143 @@ +package domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.Vector; + + +@SuppressWarnings("serial") +public class Offer implements Serializable { + + + 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 boolean isBooked; + private Vector bookings = new Vector(); // That is: java.sql.Date is a subclass (or extends) java.util.Date + private RuralHouse ruralHouse; + + + public Offer(int offerNumber,RuralHouse ruralHouse, Date firstDay, Date lastDay, float price){ + this.firstDay=firstDay; + this.lastDay=lastDay; + this.price=price; + this.ruralHouse=ruralHouse; + this.offerNumber=offerNumber; + } + /** + * Get the house number of the offer + * + * @return the house number + */ + public RuralHouse getRuralHouse() { + return this.ruralHouse; + } + + /** + * Set the house number to a offer + * + * @param house number + */ + public void setRuralHouse(RuralHouse ruralHouse) { + this.ruralHouse = ruralHouse; + } + + + /** + * Get the offer number + * + * @return offer number + */ + public int getOfferNumber() { + return this.offerNumber; + } + + + + /** + * Get the first day of the offer + * + * @return the first day + */ + public Date getFirstDay() { + return this.firstDay; + } + + /** + * Set the first day of the offer + * + * @param firstDay + * The first day + */ + public void setFirstDay(Date firstDay) { + this.firstDay = firstDay; + } + + /** + * Get the last day of the offer + * + * @return the last day + */ + public Date getLastDay() { + return this.lastDay; + } + + /** + * Set the last day of the offer + * + * @param lastDay + * The last day + */ + public void setLastDay(Date lastDay) { + this.lastDay = lastDay; + } + + /** + * Get the price + * + * @return price + */ + public float getPrice() { + return this.price; + } + + /** + * Set the price + * + * @param price + */ + public void setPrice(float price) { + this.price = price; + } + + + /** + * This method creates a book with a corresponding parameters + * + * @param First day, last day, house number and telephone + * @return a book + */ + public Vector createBooking(int numBooking,Client client) { + Booking b = new Booking(numBooking,this,client); + this.bookings.add(b); + return this.bookings; + + } + + public String toString(){ + return firstDay.toString()+", "+lastDay.toString()+", "+price; + } + public Vector getBookings() { + return bookings; + } + public void setBookings(Vector bookings) { + this.bookings = bookings; + } + public boolean isBooked() { + return isBooked; + } + public void setBooked(boolean isBooked) { + this.isBooked = isBooked; + } +} \ No newline at end of file diff --git a/ruralHousesDB/src/domain/Owner.java b/ruralHousesDB/src/domain/Owner.java new file mode 100644 index 0000000..6bf0f97 --- /dev/null +++ b/ruralHousesDB/src/domain/Owner.java @@ -0,0 +1,75 @@ +package domain; + +import java.io.Serializable; +import java.util.Vector; + +public class Owner implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + private String bankAccount = ""; + private String name = ""; + private String mailAccount = ""; + private Vector ruralHouses; + + + public Owner(String name, String bankAccount,String mail) { + this.bankAccount = bankAccount; + this.name = name; + this.mailAccount = mail; + ruralHouses = new Vector(); + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBankAccount() { + return this.bankAccount; + } + + public void setBankAccount(String bankAccount) { + this.bankAccount = bankAccount; + } + + public Vector getRuralHouses(){ + return this.ruralHouses; + } + + + + public RuralHouse addRuralHouse(String houseName, String description, + String town, int nRooms, int nKitchens, int nBaths, int nLivings, + int nParkings) { + HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, nLivings, nParkings); + RuralHouse rh = new RuralHouse(houseName, this, description, town,feature); + ruralHouses.add(rh); + return rh; + } + + public RuralHouse addRuralHouse(RuralHouse rh) { + ruralHouses.add(rh); + return rh; + } + + public String toString() { + return name; + } + + public String getMailAccount() { + return mailAccount; + } + + public void setMailAccount(String mailAccount) { + this.mailAccount = mailAccount; + } + + + +} \ No newline at end of file diff --git a/ruralHousesDB/src/domain/RuralHouse.java b/ruralHousesDB/src/domain/RuralHouse.java new file mode 100644 index 0000000..0c7fbb7 --- /dev/null +++ b/ruralHousesDB/src/domain/RuralHouse.java @@ -0,0 +1,125 @@ +package domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.Iterator; +import java.util.Vector; + +public class RuralHouse implements Serializable { + + private static final long serialVersionUID = 1L; + + private String houseName; + private String description; + private Owner owner; + private String district; + private HouseFeatures features; + public Vector offers; + + + public RuralHouse() { + super(); + } + + public RuralHouse(String houseName, Owner owner, String description, + String ds, HouseFeatures features) { + this.houseName = houseName; + this.description = description; + this.owner = owner; + this.district = ds; + this.features = features; + offers = new Vector(); + } + + public String getHouseName() { + return houseName; + } + + public void setHouseName(String houseName) { + this.houseName = houseName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Owner getOwner() { + return owner; + } + + public void setOwner(Owner owner) { + this.owner = owner; + } + + public String getDistrict() { + return district; + } + + public void setDistrict(String ds) { + this.district = ds; + } + + public HouseFeatures getFeatures() { + return features; + } + + public void setFeatures(HouseFeatures features) { + this.features = features; + } + + public String toString() { + return this.houseName + ": " + this.district; + } + + public Offer createOffer(int offerNumber, Date firstDay, Date lastDay, + float price) { + Offer off = new Offer(offerNumber, this, firstDay, lastDay, price); + offers.add(off); + return off; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RuralHouse other = (RuralHouse) obj; + if (houseName == null) { + if (other.houseName != null) + return false; + } else if (!houseName.equals(other.houseName)) + return false; + return true; + } + + + + public Offer overlapsWith(Date firstDay, Date lastDay) { + + Iterator e = offers.iterator(); + Offer offer = null; + while (e.hasNext()) { + offer = e.next(); + if ((offer.getFirstDay().compareTo(lastDay) < 0) + && (offer.getLastDay().compareTo(firstDay) > 0)) + return offer; + } + return null; + + } + + + public Vector getAllOffers() { + + return this.offers; + } + + +} diff --git a/ruralHousesDB/src/exceptions/.DS_Store b/ruralHousesDB/src/exceptions/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/ruralHousesDB/src/exceptions/.DS_Store differ diff --git a/ruralHousesDB/src/exceptions/BadDates.java b/ruralHousesDB/src/exceptions/BadDates.java new file mode 100644 index 0000000..9cf6915 --- /dev/null +++ b/ruralHousesDB/src/exceptions/BadDates.java @@ -0,0 +1,17 @@ +package exceptions; +public class BadDates extends Exception { + private static final long serialVersionUID = 1L; + + public BadDates() + { + super(); + } + /**This exception is triggered if first date is greater than last date in offers + *@param String + *@return None + */ + public BadDates(String s) + { + super(s); + } +} \ No newline at end of file diff --git a/ruralHousesDB/src/exceptions/DB4oManagerCreationException.java b/ruralHousesDB/src/exceptions/DB4oManagerCreationException.java new file mode 100644 index 0000000..4b49471 --- /dev/null +++ b/ruralHousesDB/src/exceptions/DB4oManagerCreationException.java @@ -0,0 +1,17 @@ +package exceptions; +public class DB4oManagerCreationException extends Exception { + private static final long serialVersionUID = 1L; + + public DB4oManagerCreationException() + { + super(); + } + /**This exception is triggered if there is a problem when constructor of DB4oManager is executed + *@param String + *@return None + */ + public DB4oManagerCreationException(String s) + { + super(s); + } +} \ No newline at end of file diff --git a/ruralHousesDB/src/exceptions/OfferCanNotBeBooked.java b/ruralHousesDB/src/exceptions/OfferCanNotBeBooked.java new file mode 100644 index 0000000..b4539d0 --- /dev/null +++ b/ruralHousesDB/src/exceptions/OfferCanNotBeBooked.java @@ -0,0 +1,17 @@ +package exceptions; +public class OfferCanNotBeBooked extends Exception { + private static final long serialVersionUID = 1L; + + public OfferCanNotBeBooked() { + super(); + } + + /**This exception is triggered if an offer cannot be booked + *@param String + *@return None + */ + public OfferCanNotBeBooked(String s) + { + super(s); + } +} \ No newline at end of file diff --git a/ruralHousesDB/src/exceptions/OverlappingOfferExists.java b/ruralHousesDB/src/exceptions/OverlappingOfferExists.java new file mode 100644 index 0000000..c776a3b --- /dev/null +++ b/ruralHousesDB/src/exceptions/OverlappingOfferExists.java @@ -0,0 +1,17 @@ +package exceptions; +public class OverlappingOfferExists extends Exception { + private static final long serialVersionUID = 1L; + + public OverlappingOfferExists() + { + super(); + } + /**This exception is triggered if there exists an overlapping offer + *@param String + *@return None + */ + public OverlappingOfferExists(String s) + { + super(s); + } +} \ No newline at end of file