Introduced Login Manager logic by creating the LoginManager and the LoginManagerInterface
authorpinene <epinzolas001@ikasle.ehu.es>
Fri, 27 Feb 2015 11:59:29 +0000 (12:59 +0100)
committerepinzolas001 <epinzolas001@g004972.gi.ehu.es>
Fri, 27 Feb 2015 11:59:29 +0000 (12:59 +0100)
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

index 672ef19..7af26dd 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 5d768e8..502f598 100644 (file)
@@ -86,5 +86,7 @@ public class IntroduceOfferGUI extends JFrame {
                }
                return jButton;
        }
+       
+       
 
 }  //  @jve:decl-index=0:visual-constraint="222,33"