UserController updated
authorMichael <Michael@Michael-LT.bfh.ch>
Wed, 18 Nov 2015 10:39:09 +0000 (11:39 +0100)
committerMichael <Michael@Michael-LT.bfh.ch>
Wed, 18 Nov 2015 10:39:09 +0000 (11:39 +0100)
- java-doc
- getReservation
- getReservationsInDateRange

src/main/java/ch/bfh/ti/srs/controller/UserController.java

index 01cc0f5..fc47669 100644 (file)
@@ -8,15 +8,18 @@
 package ch.bfh.ti.srs.controller;\r
 \r
 import java.rmi.AlreadyBoundException;\r
+import java.util.List;\r
+import java.util.UUID;\r
 \r
+import ch.bfh.ti.daterange.DateRange;\r
 import ch.bfh.ti.srs.datahandler.DataHandler;\r
+import ch.bfh.ti.srs.dataschema.Reservation;\r
 import ch.bfh.ti.srs.dataschema.User;\r
 \r
 /**\r
  * @author Michael Grossen\r
  */\r
 public class UserController {\r
-       final String filePath = "test.xls";\r
        private User currentUser;\r
        private DataHandler dh;\r
        \r
@@ -36,11 +39,12 @@ public class UserController {
        /**\r
         * Tries to logIn a user with the given credentials\r
         * \r
-        * @param userName      username\r
-        * @param password      the stored password for the given username\r
-        * @return                      <code>true</code> if the user could log in successfully;\r
-        *                                      <code>false</code> eighter the username or the password was not correct.\r
-        * @throws                      Exception\r
+        * @param userName                                      username\r
+        * @param password                                      the stored password for the given username\r
+        * @return                                                      <code>true</code> if the user could log in successfully;\r
+        *                                                                      <code>false</code> eighter the username or the password was not correct.\r
+        * @throws Exception                            no datahandler set or thrown by datahandler\r
+        * @throws AlreadyBoundException        a user is already logged in\r
         */\r
        public boolean logIn(String userName, String password) throws Exception{\r
                if(dh == null) throw new Exception("No DataHandler set");\r
@@ -129,4 +133,30 @@ public class UserController {
                if(currentUser == null) throw new Exception("No user is logged in");\r
                return currentUser.getLastname();\r
        }\r
+       \r
+       /**\r
+        * Returns all reservations overlapping the given dateRange in a List\r
+        * \r
+        * @param       dateRange\r
+        * @return\r
+        * @throws      Exception\r
+        */\r
+       public List<Reservation> getReservationsInDateRange(DateRange dateRange) throws Exception{\r
+               if(dh == null) throw new Exception("No DataHandler set");\r
+               if(dateRange == null) throw new Exception("dateRange must be defined");\r
+               return dh.overlaps(dateRange);\r
+       }\r
+       \r
+       /**\r
+        * Returns the reservation or null if no reservation was found\r
+        * \r
+        * @param id\r
+        * @return\r
+        * @throws Exception\r
+        */\r
+       public Reservation getReservation(UUID id) throws Exception{\r
+               if(dh == null) throw new Exception("No DataHandler set");\r
+               if(id == null) throw new Exception("uuid must be defined");\r
+               return dh.findReservation(id);\r
+       }\r
 }\r