DataHandler updated
authorMatthias <balmm1@bfh.ch>
Tue, 17 Nov 2015 09:37:11 +0000 (10:37 +0100)
committerMatthias <balmm1@bfh.ch>
Tue, 17 Nov 2015 09:37:11 +0000 (10:37 +0100)
src/main/java/ch/bfh/ti/srs/datahandler/DataHandler.java
src/main/java/ch/bfh/ti/srs/datahandler/DataHandlerForTests.java
src/main/java/ch/bfh/ti/srs/noTest/DataHandlerForExcel.java

index a0b79ed..4cbf576 100644 (file)
@@ -1,33 +1,71 @@
-/*\r
- * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
- *\r
- * Project Smart Reservation System.\r
- *\r
- * Distributable under GPL license. See terms of license at gnu.org.\r
- */\r
-package ch.bfh.ti.srs.datahandler;\r
-\r
-import ch.bfh.ti.srs.dataschema.User;\r
-\r
-/**\r
- * @author Michael Grossen\r
- */\r
-public interface DataHandler {\r
-       \r
-       /**\r
-        * Finds the user by userName param in the Datacontext and returns the User object or null if not found\r
-        * \r
-        * @param userName      userName of the user you are looking for\r
-        * @return                      <code>User</code>user object\r
-        *                                      <code>null</code>if no user found with this userName\r
-        */\r
-       public User findUser(String userName);\r
-       \r
-       /**\r
-        * Adds a user to the Datacontext from a given user object\r
-        * \r
-        * @param user                  User object\r
-        * @throws Exception\r
-        */\r
-       public void addUser(User user) throws Exception;\r
-}\r
+/*
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.
+ *
+ * Project Smart Reservation System.
+ *
+ * Distributable under GPL license. See terms of license at gnu.org.
+ */
+package ch.bfh.ti.srs.datahandler;
+
+import ch.bfh.ti.daterange.DateRange;
+import ch.bfh.ti.srs.dataschema.Reservation;
+import ch.bfh.ti.srs.dataschema.Resource;
+import ch.bfh.ti.srs.dataschema.User;
+
+/**
+ * @author Michael Grossen
+ */
+public interface DataHandler {
+       
+       /**
+        * Finds the user by userName param in the Datacontext and returns the User object or null if not found
+        * 
+        * @param userName      userName of the user you are looking for
+        * @return                      <code>User</code>user object
+        *                                      <code>null</code>if no user found with this userName
+        */
+       public User findUser(String userName);
+       
+       /**
+        * Adds a user to the Datacontext from a given User object
+        * 
+        * @param user                  User object
+        * @throws Exception
+        */
+       public void addUser(User user) throws Exception;
+       
+       /**
+        * Finds the resourceName in the Datacontext and returns the Resource object or null if not found
+        * 
+        * @param resourceName  resource name of the recource you are looking for
+        * @return                              <code>Resource</code>resource object
+        *                                              <code>null</code>if no resource found with this recourceName
+        */
+       public Resource findResource(String resourceName);
+       
+       /**
+        * Adds a resource to the Datacontext from a given Recource object
+        * 
+        * @param resource                      Resource object
+        * @throws Exception
+        */
+       public void addResource(Resource resource) throws Exception;
+       
+       /**
+        * Finds the reservation by resource and daterange param in the Datacontext and returns the Reservation object or null if not found
+        * 
+        * @param       resource        resource of the Reservation you are looking for
+        *                      daterange       daterange of the Reservation you are looking for
+        * @return                              <code>Reservation</code>reservation object
+        *                                              <code>null</code>if no reservation found with this resource and this daterange
+        */
+       public Reservation findReservation(Resource resource, DateRange daterange);
+       
+       /**
+        * Adds a reservation to the Datacontext from a given Reservation object
+        * 
+        * @param reservation                   Reservation object
+        * @throws Exception
+        */
+       public void addReservation(Reservation reservation)throws Exception;
+}
index dcd7579..65199a6 100644 (file)
@@ -1,41 +1,87 @@
-/*\r
- * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
- *\r
- * Project Smart Reservation System.\r
- *\r
- * Distributable under GPL license. See terms of license at gnu.org.\r
- */\r
-package ch.bfh.ti.srs.datahandler;\r
-\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import ch.bfh.ti.srs.dataschema.User;\r
-\r
-public class DataHandlerForTests implements DataHandler{\r
-       Set<User> userList = new HashSet<User>();\r
-       \r
-       public DataHandlerForTests(){\r
-               \r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see ch.bfh.ti.srs.core.DataHandler#findUser(java.lang.String)\r
-        */\r
-       @Override\r
-       public User findUser(String userName) {\r
-               for (User user : userList) {\r
-                       if(user.getUserName().equals(userName)) return user;\r
-               }\r
-               return null;\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see ch.bfh.ti.srs.core.DataHandler#addUser(ch.bfh.ti.srs.core.User)\r
-        */\r
-       @Override\r
-       public void addUser(User user) throws Exception {\r
-               if(user == null) throw new IllegalArgumentException("User object must not be null!");\r
-               userList.add(user);\r
-       }\r
-}\r
+/*
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.
+ *
+ * Project Smart Reservation System.
+ *
+ * Distributable under GPL license. See terms of license at gnu.org.
+ */
+package ch.bfh.ti.srs.datahandler;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import ch.bfh.ti.daterange.DateRange;
+import ch.bfh.ti.srs.dataschema.Reservation;
+import ch.bfh.ti.srs.dataschema.Resource;
+import ch.bfh.ti.srs.dataschema.User;
+
+public class DataHandlerForTests implements DataHandler{
+       Set<User> userList = new HashSet<User>();
+       Set<Resource> resourceList = new HashSet<Resource>();
+       Set<Reservation> reservationList = new HashSet<Reservation>();
+       
+       public DataHandlerForTests(){
+               
+       }
+
+       /* (non-Javadoc)
+        * @see ch.bfh.ti.srs.dataschema.DataHandler#findUser(java.lang.String)
+        */
+       @Override
+       public User findUser(String userName) {
+               for (User user : userList) {
+                       if(user.getUserName().equals(userName)) return user;
+               }
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see ch.bfh.ti.srs.dataschema.DataHandler#addUser(ch.bfh.ti.srs.dataschema.User)
+        */
+       @Override
+       public void addUser(User user) throws Exception {
+               if(user == null) throw new IllegalArgumentException("User object must not be null!");
+               if(userList.contains(user)) throw new IllegalArgumentException("User already  exists!");
+               userList.add(user);
+       }
+
+       /* (non-Javadoc)
+        * @see ch.bfh.ti.srs.dataschema.DataHandler#findResource(java.lang.String)
+        */
+       @Override
+       public Resource findResource(String resourceName) {
+               for (Resource resource : resourceList) {
+                       if(resource.getName().equals(resourceName)) return resource;
+               }
+               return null;
+       }
+       /* (non-Javadoc)
+        * @see ch.bfh.ti.srs.dataschema.DataHandler#addResource(ch.bfh.ti.srs.dataschema.Resource)
+        */
+       @Override
+       public void addResource(Resource resource) throws Exception {
+               if(resource == null) throw new IllegalArgumentException("Resource object must not be null!");
+               if(resourceList.contains(resource)) throw new IllegalArgumentException("Resource already  exists!");
+               resourceList.add(resource);
+       }
+
+       /* (non-Javadoc)
+        * @see ch.bfh.ti.srs.dataschema.DataHandler#findReservation(java.lang.String)
+        */
+       @Override
+       public Reservation findReservation(Resource resource, DateRange daterange) {
+               for (Reservation reservation : reservationList) {
+                       if(reservation.getResource().equals(resource) && reservation.getDateRange().equals(daterange)) return reservation;
+               }
+               return null;
+       }
+       /* (non-Javadoc)
+        * @see ch.bfh.ti.srs.dataschema.DataHandler#addReservation(ch.bfh.ti.srs.dataschema.Reservation)
+        */
+       @Override
+       public void addReservation(Reservation reservation) throws Exception {
+               if(reservation == null) throw new IllegalArgumentException("Reservation object must not be null!");
+               if(resourceList.contains(reservation)) throw new IllegalArgumentException("Reservation already  exists!");
+               reservationList.add(reservation);       
+       }
+}
index e8a609b..9e08681 100644 (file)
-package ch.bfh.ti.srs.noTest;\r
-\r
-import java.sql.Connection;\r
-import java.sql.DriverManager;\r
-import java.sql.ResultSet;\r
-import java.sql.Statement;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import ch.bfh.ti.srs.datahandler.DataHandler;\r
-import ch.bfh.ti.srs.dataschema.User;\r
-/**\r
- * @author Michael Grossen\r
- */\r
-public class DataHandlerForExcel implements DataHandler{\r
-       String filePath;\r
-       Set<User> userList = new HashSet<User>();\r
-       \r
-       static\r
-       {\r
-               try  { \r
-            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");\r
-        } \r
-        catch (Exception e) {\r
-            System.err.println(e);\r
-        }\r
-       }\r
-       \r
-       public DataHandlerForExcel(String filePath) throws Exception{\r
-               this.filePath = filePath;\r
-               updateUserList();\r
-       }\r
-       \r
-       @Override\r
-       public User findUser(String userName) {\r
-               if(userName == null) throw new IllegalArgumentException("Username must not be null");\r
-               for (User user : userList) {\r
-                       if(user.getUserName().equals(userName)) return user;\r
-               }\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public void addUser(User user) throws Exception {\r
-               if(findUser(user.getUserName()) != null) throw new Exception("User already exists!");\r
-               insertNewUser(user);\r
-               updateUserList();\r
-       }\r
-\r
-       private void updateUserList() throws Exception\r
-       {\r
-               Connection conn=null;\r
-        Statement stmt=null;\r
-        String sql="";\r
-        ResultSet rs=null;\r
\r
-        userList.clear();\r
-        \r
-        try {\r
-            conn=DriverManager.getConnection("jdbc:odbc:excel","","");\r
-            stmt=conn.createStatement();\r
-            sql="select * from [User$]";\r
-            rs=stmt.executeQuery(sql);\r
-\r
-            while(rs.next()){\r
-               User user = new User(rs.getString("USERNAME"),\r
-                               rs.getString("PASSWORD"),\r
-                               rs.getString("MAIL"),\r
-                               rs.getString("NAME"),\r
-                               rs.getString("LASTNAME"));\r
-                userList.add(user);\r
-            }\r
-        } \r
-        catch (Exception e){\r
-            System.err.println(e);\r
-        } \r
-        finally {\r
-            try{\r
-                rs.close();\r
-                stmt.close();\r
-                conn.close();\r
-                rs=null;\r
-                stmt=null;\r
-                conn=null; \r
-            }\r
-            catch(Exception e){}\r
-        }\r
-       }\r
-\r
-       private void insertNewUser(User user) throws Exception{\r
-               Connection conn=null;\r
-        Statement stmt=null;\r
-        String sql="";\r
-        ResultSet rs=null;\r
\r
-        sql = "insert into [User$] values (" +         user.getUserName() + "," +\r
-                                                                                       user.getEncryptedPassword() + "," +\r
-                                                                                       user.getMail() + "," +\r
-                                                                                       user.getName() + "," +\r
-                                                                                       user.getLastname() + ")";\r
-        \r
-        try {\r
-            conn=DriverManager.getConnection("jdbc:odbc:excel","","");\r
-            stmt=conn.createStatement();\r
-            stmt.executeQuery(sql);\r
-        } \r
-        catch (Exception e){\r
-            System.err.println(e);\r
-        } \r
-        finally {\r
-            try{\r
-                rs.close();\r
-                stmt.close();\r
-                conn.close();\r
-                rs=null;\r
-                stmt=null;\r
-                conn=null; \r
-            }\r
-            catch(Exception e){}\r
-        }\r
-       }\r
-}\r
+package ch.bfh.ti.srs.noTest;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Set;
+
+import ch.bfh.ti.daterange.DateRange;
+import ch.bfh.ti.srs.datahandler.DataHandler;
+import ch.bfh.ti.srs.dataschema.Reservation;
+import ch.bfh.ti.srs.dataschema.Resource;
+import ch.bfh.ti.srs.dataschema.User;
+/**
+ * @author Michael Grossen
+ */
+public class DataHandlerForExcel implements DataHandler{
+       String filePath;
+       Set<User> userList = new HashSet<User>();
+       
+       static
+       {
+               try  { 
+            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
+        } 
+        catch (Exception e) {
+            System.err.println(e);
+        }
+       }
+       
+       public DataHandlerForExcel(String filePath) throws Exception{
+               this.filePath = filePath;
+               updateUserList();
+       }
+       
+       @Override
+       public User findUser(String userName) {
+               if(userName == null) throw new IllegalArgumentException("Username must not be null");
+               for (User user : userList) {
+                       if(user.getUserName().equals(userName)) return user;
+               }
+               return null;
+       }
+
+       @Override
+       public void addUser(User user) throws Exception {
+               if(findUser(user.getUserName()) != null) throw new Exception("User already exists!");
+               insertNewUser(user);
+               updateUserList();
+       }
+
+       private void updateUserList() throws Exception
+       {
+               Connection conn=null;
+        Statement stmt=null;
+        String sql="";
+        ResultSet rs=null;
+        userList.clear();
+        
+        try {
+            conn=DriverManager.getConnection("jdbc:odbc:excel","","");
+            stmt=conn.createStatement();
+            sql="select * from [User$]";
+            rs=stmt.executeQuery(sql);
+
+            while(rs.next()){
+               User user = new User(rs.getString("USERNAME"),
+                               rs.getString("PASSWORD"),
+                               rs.getString("MAIL"),
+                               rs.getString("NAME"),
+                               rs.getString("LASTNAME"));
+                userList.add(user);
+            }
+        } 
+        catch (Exception e){
+            System.err.println(e);
+        } 
+        finally {
+            try{
+                rs.close();
+                stmt.close();
+                conn.close();
+                rs=null;
+                stmt=null;
+                conn=null; 
+            }
+            catch(Exception e){}
+        }
+       }
+
+       private void insertNewUser(User user) throws Exception{
+               Connection conn=null;
+        Statement stmt=null;
+        String sql="";
+        ResultSet rs=null;
+        sql = "insert into [User$] values (" +         user.getUserName() + "," +
+                                                                                       user.getEncryptedPassword() + "," +
+                                                                                       user.getMail() + "," +
+                                                                                       user.getName() + "," +
+                                                                                       user.getLastname() + ")";
+        
+        try {
+            conn=DriverManager.getConnection("jdbc:odbc:excel","","");
+            stmt=conn.createStatement();
+            stmt.executeQuery(sql);
+        } 
+        catch (Exception e){
+            System.err.println(e);
+        } 
+        finally {
+            try{
+                rs.close();
+                stmt.close();
+                conn.close();
+                rs=null;
+                stmt=null;
+                conn=null; 
+            }
+            catch(Exception e){}
+        }
+       }
+
+       @Override
+       public Resource findResource(String resourceName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void addResource(Resource resource) throws Exception {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public Reservation findReservation(Resource resource, DateRange daterange) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void addReservation(Reservation reservation) throws Exception {
+               // TODO Auto-generated method stub
+               
+       }
+}