DataHandler updated
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / noTest / DataHandlerForExcel.java
index 8f05d06..01d308b 100644 (file)
-package ch.bfh.ti.srs.noTest;\r
-\r
-import java.sql.*;\r
-import java.util.ArrayList;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import ch.bfh.ti.srs.core.DataHandler;\r
-import ch.bfh.ti.srs.core.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
+/*
+ * 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.noTest;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+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
+ */
+/**
+ * @author Michael
+ */
+public class DataHandlerForExcel implements DataHandler {
+       private String filePath;
+       private 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 boolean addUser(User user) throws Exception {
+               if (findUser(user.getUserName()) != null)
+                       throw new Exception("User already exists!");
+               else {
+                       insertNewUser(user);
+                       updateUserList();
+                       return true;
+               }
+       }
+
+       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 boolean addResource(Resource resource) throws Exception {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean addReservation(Reservation reservation) throws Exception {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public Reservation findReservation(UUID id) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public List<Reservation> findGroupReservations(UUID groupID) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public List<Reservation> overlaps(DateRange range) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public List<Reservation> userReservations(User user) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public List<Reservation> findAllReservations() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void saveChanges() {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public void refresh(boolean discardChanges) throws Exception {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public boolean editReservation(Reservation reservation) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean deleteReservation(Reservation reservation) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public Set<Resource> getAllResources() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public boolean editResource(Resource resource) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean deleteResource(Resource resource) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean editUser(User user) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+}