Started with the separated DB with the given code
authorcamjan <jcampos004@ikasle.ehu.es>
Wed, 20 May 2015 21:26:51 +0000 (23:26 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Wed, 20 May 2015 21:26:51 +0000 (23:26 +0200)
33 files changed:
ruralHouses client/src/domain/Administrator.java
ruralHouses client/src/gui/StartWindow.java
ruralHouses client/src/gui/listOfBookingRequestsGUI.java
ruralHouses/config.out.xml [deleted file]
ruralHouses/config.xml
ruralHouses/src/businessLogic/AccountManager.java
ruralHouses/src/businessLogic/BookingManager.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Account.java
ruralHousesDB/.DS_Store [new file with mode: 0644]
ruralHousesDB/.classpath [new file with mode: 0644]
ruralHousesDB/.gitignore [new file with mode: 0644]
ruralHousesDB/.project [new file with mode: 0644]
ruralHousesDB/config.xml [moved from ruralHouses client/config.xml with 71% similarity]
ruralHousesDB/java.policy [new file with mode: 0644]
ruralHousesDB/src/configuration/.DS_Store [new file with mode: 0644]
ruralHousesDB/src/configuration/ConfigXML.java [moved from ruralHouses client/src/configuration/ConfigXML.java with 100% similarity]
ruralHousesDB/src/dataAccess/.DS_Store [new file with mode: 0644]
ruralHousesDB/src/dataAccess/DB4oServerManager.java [new file with mode: 0644]
ruralHousesDB/src/domain/Account.java [new file with mode: 0644]
ruralHousesDB/src/domain/Administrator.java [new file with mode: 0644]
ruralHousesDB/src/domain/Booking.java [new file with mode: 0644]
ruralHousesDB/src/domain/Client.java [new file with mode: 0644]
ruralHousesDB/src/domain/Districs.java [new file with mode: 0644]
ruralHousesDB/src/domain/HouseFeatures.java [new file with mode: 0644]
ruralHousesDB/src/domain/Offer.java [new file with mode: 0644]
ruralHousesDB/src/domain/Owner.java [new file with mode: 0644]
ruralHousesDB/src/domain/RuralHouse.java [new file with mode: 0644]
ruralHousesDB/src/exceptions/.DS_Store [new file with mode: 0644]
ruralHousesDB/src/exceptions/BadDates.java [new file with mode: 0644]
ruralHousesDB/src/exceptions/DB4oManagerCreationException.java [new file with mode: 0644]
ruralHousesDB/src/exceptions/OfferCanNotBeBooked.java [new file with mode: 0644]
ruralHousesDB/src/exceptions/OverlappingOfferExists.java [new file with mode: 0644]

index d1ea781..3bf7db2 100644 (file)
@@ -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<RuralHouse> addRequest;
        private static LinkedList<RuralHouse> removeRequest;
        private static LinkedList<Account> newOwnerRequest;
-       static ConfigXML c;
 
        private Administrator() {
                addRequest = new LinkedList<RuralHouse>();
index e938084..3129bad 100644 (file)
@@ -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!!");
index 2106e88..ba96f0d 100644 (file)
@@ -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 (file)
index e69de29..0000000
index 0ce7502..d71d8fb 100644 (file)
@@ -5,7 +5,7 @@
        <portRMI>1099</portRMI>
        <serviceRMI>RuralHouses</serviceRMI>
 </businessLogic>
-       <database local="true">
+       <database local="false">
        <databaseNode>localhost</databaseNode>
        <db4oFilename>db/casas.db4o</db4oFilename>
        <dataBaseOpenMode>initialize</dataBaseOpenMode>
index 0ad55b1..2536474 100644 (file)
@@ -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;
index 3fe64f2..f5b993d 100644 (file)
@@ -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;
index 4553f48..fa85cfa 100644 (file)
@@ -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<Account> result = db.queryByExample(new Account(null,null,own));
+                       ObjectSet<Account> result = db.queryByExample(new Account(own));
                        if (!result.isEmpty()) {
                                db.delete(result.get(0));
                                db.commit();
index 7fb472c..989440c 100644 (file)
@@ -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 (file)
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 (file)
index 0000000..4a939f6
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <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/mail/javax.mail.jar"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/ruralHousesDB/.gitignore b/ruralHousesDB/.gitignore
new file mode 100644 (file)
index 0000000..b83f20a
--- /dev/null
@@ -0,0 +1,5 @@
+/bin
+/lib
+!lib/mail/
+/db
+/src/*/*.class
diff --git a/ruralHousesDB/.project b/ruralHousesDB/.project
new file mode 100644 (file)
index 0000000..0a88c12
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>ruralHousesDB</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
similarity index 71%
rename from ruralHouses client/config.xml
rename to ruralHousesDB/config.xml
index d80475a..0ce7502 100644 (file)
@@ -1,12 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <config>
-       <businessLogic local="true">
-               <businessLogicNode>localhost</businessLogicNode>
-               <portRMI>1099</portRMI>
-               <serviceRMI>RuralHouses</serviceRMI>
-       </businessLogic>
+<businessLogic local="true"> 
+       <businessLogicNode>localhost</businessLogicNode>
+       <portRMI>1099</portRMI>
+       <serviceRMI>RuralHouses</serviceRMI>
+</businessLogic>
        <database local="true">
-
        <databaseNode>localhost</databaseNode>
        <db4oFilename>db/casas.db4o</db4oFilename>
        <dataBaseOpenMode>initialize</dataBaseOpenMode>
@@ -17,5 +16,4 @@
        <password>i4softwEngin2matx</password>
 </database>
 <javaPolicyPath>java.policy</javaPolicyPath>
-
 </config>
\ No newline at end of file
diff --git a/ruralHousesDB/java.policy b/ruralHousesDB/java.policy
new file mode 100644 (file)
index 0000000..a38bc88
--- /dev/null
@@ -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 (file)
index 0000000..02896dc
Binary files /dev/null and b/ruralHousesDB/src/configuration/.DS_Store differ
diff --git a/ruralHousesDB/src/dataAccess/.DS_Store b/ruralHousesDB/src/dataAccess/.DS_Store
new file mode 100644 (file)
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 (file)
index 0000000..ea75334
--- /dev/null
@@ -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 (file)
index 0000000..f401391
--- /dev/null
@@ -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 (file)
index 0000000..25d51d4
--- /dev/null
@@ -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<RuralHouse> addRequest;
+       private static LinkedList<RuralHouse> removeRequest;
+       private static LinkedList<Account> newOwnerRequest;
+       static ConfigXML c;
+
+       private Administrator() {
+               addRequest = new LinkedList<RuralHouse>();
+               removeRequest = new LinkedList<RuralHouse>();
+               newOwnerRequest = new LinkedList<Account>();
+       }
+
+       public static Administrator getInstance() {
+
+               return admin;
+
+       }
+
+       public static void saveInstance() {
+       }
+
+       public LinkedList<RuralHouse> getAddRequest() {
+               return addRequest;
+       }
+
+       public LinkedList<RuralHouse> getRemoveRequest() {
+               return removeRequest;
+       }
+
+       public void setAddRequest(LinkedList<RuralHouse> addRequest) {
+               Administrator.addRequest = addRequest;
+       }
+
+       public void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
+               Administrator.removeRequest = removeRequest;
+
+       }
+
+       public LinkedList<Account> getNewOwnerRequest() {
+               return newOwnerRequest;
+       }
+
+       public void setNewOwnerRequest(LinkedList<Account> newOwnerRequest) {
+               Administrator.newOwnerRequest = newOwnerRequest;
+       }
+
+}
diff --git a/ruralHousesDB/src/domain/Booking.java b/ruralHousesDB/src/domain/Booking.java
new file mode 100644 (file)
index 0000000..4b68a70
--- /dev/null
@@ -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 (file)
index 0000000..a4c0baf
--- /dev/null
@@ -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 (file)
index 0000000..2866692
--- /dev/null
@@ -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 (file)
index 0000000..52502cb
--- /dev/null
@@ -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 (file)
index 0000000..3442a6a
--- /dev/null
@@ -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<Booking> bookings = new Vector<Booking>();  // 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<Booking> 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<Booking> getBookings() {
+               return 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
diff --git a/ruralHousesDB/src/domain/Owner.java b/ruralHousesDB/src/domain/Owner.java
new file mode 100644 (file)
index 0000000..6bf0f97
--- /dev/null
@@ -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<RuralHouse> ruralHouses;
+
+
+       public Owner(String name, String bankAccount,String mail) {
+               this.bankAccount = bankAccount;
+               this.name = name;
+               this.mailAccount = mail;
+               ruralHouses = new Vector<RuralHouse>();
+       }
+
+       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<RuralHouse> 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 (file)
index 0000000..0c7fbb7
--- /dev/null
@@ -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<Offer> 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<Offer>();
+       }
+
+       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<Offer> 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<Offer> getAllOffers() {
+
+               return this.offers;
+       }
+
+
+}
diff --git a/ruralHousesDB/src/exceptions/.DS_Store b/ruralHousesDB/src/exceptions/.DS_Store
new file mode 100644 (file)
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 (file)
index 0000000..9cf6915
--- /dev/null
@@ -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 (file)
index 0000000..4b49471
--- /dev/null
@@ -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 (file)
index 0000000..b4539d0
--- /dev/null
@@ -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 (file)
index 0000000..c776a3b
--- /dev/null
@@ -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