Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
authorepinzolas001 <epinzolas001@g004972.gi.ehu.es>
Fri, 27 Feb 2015 12:08:52 +0000 (13:08 +0100)
committerepinzolas001 <epinzolas001@g004972.gi.ehu.es>
Fri, 27 Feb 2015 12:08:52 +0000 (13:08 +0100)
Conflicts:
ruralHouses/db/DBjcampos004.yap
ruralHouses/src/gui/IntroduceOfferGUI.java

ruralHouses/.gitignore
ruralHouses/db/DBjcampos004.yap
ruralHouses/src/businessLogic/ApplicationFacadeInterface.java
ruralHouses/src/businessLogic/LoginManager.java [new file with mode: 0644]
ruralHouses/src/businessLogic/LoginManagerInterface.java [new file with mode: 0644]
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/gui/IntroduceOfferGUI.java
ruralHouses/src/gui/StartWindow.java

index 5cb9637..d9084f3 100644 (file)
@@ -1,2 +1,3 @@
 /bin
-/lib
+/lib/*
+/db/DBjcampos004.yap
index a4f2ba5..64beb5c 100644 (file)
Binary files a/ruralHouses/db/DBjcampos004.yap and b/ruralHouses/db/DBjcampos004.yap differ
index a438bee..215e60b 100644 (file)
@@ -63,6 +63,8 @@ public interface ApplicationFacadeInterface extends Remote {
        public Vector<Owner> getOwners() throws RemoteException,
                        Exception;
        
+       
+       
        public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
        Exception;
        
diff --git a/ruralHouses/src/businessLogic/LoginManager.java b/ruralHouses/src/businessLogic/LoginManager.java
new file mode 100644 (file)
index 0000000..9710fec
--- /dev/null
@@ -0,0 +1,43 @@
+package businessLogic;
+
+import gui.StartWindow;
+
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import dataAccess.DB4oManager;
+import domain.Owner;
+
+public class LoginManager implements LoginManagerInterface {
+       //owners to be separated to accounts later on
+       DB4oManager dbMngr;
+       
+       
+       public LoginManager() {
+               
+               try {
+                       dbMngr = DB4oManager.getInstance();
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       }
+
+
+       @Override
+       public Owner checkCredentials(String usr, String pwd) {
+               try {
+                       Vector<Owner> owner = dbMngr.getSingleOwner(usr, pwd);
+                       if(owner.isEmpty()) return null;
+                       else return owner.get(0);
+                       
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               return null;
+       }
+       
+       
+        
+}
diff --git a/ruralHouses/src/businessLogic/LoginManagerInterface.java b/ruralHouses/src/businessLogic/LoginManagerInterface.java
new file mode 100644 (file)
index 0000000..57b070a
--- /dev/null
@@ -0,0 +1,11 @@
+package businessLogic;
+
+import domain.*;
+
+public interface LoginManagerInterface {
+       
+       public Owner checkCredentials(String usr, String pwd);
+       
+       
+       
+}
index 0049a4e..8388435 100644 (file)
@@ -85,7 +85,23 @@ public class DB4oManager {
                        //db.close();
                }
        } 
+       
+       public Vector<Owner> getSingleOwner(String usr, String pwd) throws RemoteException,
+       Exception {
+               ObjectContainer db=DB4oManager.getContainer();
 
+               try {
+                       Owner proto = new Owner(null,usr,pwd,null);
+                       ObjectSet result = db.queryByExample(proto);
+                       Vector<Owner> owners=new Vector<Owner>();
+                       while(result.hasNext())                          
+                               owners.add((Owner)result.next());
+                       return owners;
+               } finally {
+                       //db.close();
+               }
+       }
+       
        public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
        Exception {
                ObjectContainer db=DB4oManager.getContainer();
index 77d1488..616e873 100644 (file)
@@ -6,7 +6,7 @@ import java.awt.Frame;
 import java.awt.Rectangle;
 import java.util.Vector;
 
-import businessLogic.ApplicationFacadeInterface;
+import businessLogic.*;
 import domain.Owner;
 import domain.RuralHouse;
 
@@ -20,7 +20,7 @@ public class IntroduceOfferGUI extends JFrame {
        private JTextField usernameField;
        private JPasswordField passwordField;
        private JTextField textField;
-       private LoginManager loginManager = new LoginManagerInterface();
+       private LoginManagerInterface loginManager = new LoginManager();
 
        public IntroduceOfferGUI() {
                super();
@@ -59,7 +59,7 @@ public class IntroduceOfferGUI extends JFrame {
                        JButton loginButton = new JButton("Login");
                        loginButton.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
-                                       Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword());
+                                       Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
                                        if(owner==null){
                                                textField.setText("Incorrect username or password");
                                        }else{
@@ -89,4 +89,7 @@ public class IntroduceOfferGUI extends JFrame {
                }
                return jContentPane;
        }
-} // @jve:decl-index=0:visual-constraint="222,33"
+
+
+}  // @jve:decl-index=0:visual-constraint="222,33"
+
index 4c0ec76..98b912e 100644 (file)
@@ -30,7 +30,7 @@ public class StartWindow extends JFrame {
        public StartWindow() {
                super();
                initialize();
-               //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+               this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        
        public static ApplicationFacadeInterface getBusinessLogic(){