Create ResourceManagerController, create Modify interface in dataschema,
authorMoritz Trittibach <tritm3@bfh.ch>
Sun, 6 Dec 2015 19:04:32 +0000 (20:04 +0100)
committerMoritz Trittibach <tritm3@bfh.ch>
Sun, 6 Dec 2015 19:04:32 +0000 (20:04 +0100)
change controller class to abstract, update Reservation + Resource.

src/main/java/ch/bfh/ti/srs/controller/Controller.java
src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java [new file with mode: 0644]
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/dataschema/Modify.java [copied from src/main/java/ch/bfh/ti/srs/dataschema/package-info.java with 56% similarity]
src/main/java/ch/bfh/ti/srs/dataschema/Reservation.java
src/main/java/ch/bfh/ti/srs/dataschema/Resource.java
src/main/java/ch/bfh/ti/srs/noTest/DataHandlerForExcel.java
src/test/java/ch/bfh/ti/srs/controller/ResourceManagerControllerTest.java [copied from src/main/java/ch/bfh/ti/srs/controller/package-info.java with 77% similarity]

index 4a81f05..786d6c7 100644 (file)
@@ -29,7 +29,7 @@ import ch.bfh.ti.srs.dataschema.User;
  * @author Michael\r
  *\r
  */\r
-public class Controller {\r
+public abstract class Controller {\r
        protected DataHandler dh;\r
        protected SessionController sc;\r
 \r
diff --git a/src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java b/src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java
new file mode 100644 (file)
index 0000000..9337355
--- /dev/null
@@ -0,0 +1,43 @@
+/*\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.controller;\r
+\r
+import ch.bfh.ti.srs.datahandler.DataHandler;\r
+import ch.bfh.ti.srs.dataschema.Resource;\r
+\r
+\r
+public class ResourceManagerController extends Controller {\r
+\r
+       public ResourceManagerController(DataHandler dh, SessionController sc) {\r
+               super(dh, sc);\r
+       }\r
+       \r
+       public boolean addResource(Resource resource) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (resource == null)\r
+                       throw new IllegalArgumentException("Resource must be defined");\r
+               return dh.addResource(resource);\r
+       }\r
+       \r
+       public boolean changeResource(Resource resource) throws Exception{\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (resource == null)\r
+                       throw new IllegalArgumentException("Resource must be defined");\r
+               return dh.editResource(resource);\r
+       }\r
+       \r
+       public boolean deleteResource(Resource resource) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (resource == null)\r
+                       throw new IllegalArgumentException("Resource must be defined");\r
+               return dh.deleteResource(resource);\r
+       }\r
+}\r
index e861f0e..c45fe73 100644 (file)
@@ -135,6 +135,10 @@ public interface DataHandler {
        public boolean editReservation(Reservation reservation);
 
        public boolean deleteReservation(Reservation reservation);
+       
+       public boolean editResource(Resource resource);
+       
+       public boolean deleteResource(Resource resource);
 
        public Set<Resource> getAllResources();
 }
index 18229b5..55a142c 100644 (file)
@@ -227,4 +227,16 @@ public class DataHandlerForTests implements DataHandler {
                return resourceList;
        }
 
+       @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;
+       }
+
 }
@@ -6,3 +6,10 @@
  * Distributable under GPL license. See terms of license at gnu.org.\r
  */\r
 package ch.bfh.ti.srs.dataschema;\r
+\r
+public interface Modify extends Cloneable{\r
+       \r
+       public boolean isModified(Object obj);\r
+       \r
+       public Object clone() throws CloneNotSupportedException;\r
+}\r
index 1588900..29689a6 100644 (file)
@@ -11,7 +11,7 @@ import java.util.UUID;
 \r
 import ch.bfh.ti.daterange.DateRange;\r
 \r
-public class Reservation implements Cloneable {\r
+public class Reservation implements Modify {\r
 \r
        private UUID id;\r
        private UUID groupId;\r
@@ -75,13 +75,15 @@ public class Reservation implements Cloneable {
                this.remark = remark;\r
        }\r
 \r
-       public boolean isModified(Reservation otherReservation) {\r
-               if (otherReservation == this) {\r
+       @Override\r
+       public boolean isModified(Object obj) {\r
+               if (obj == this) {\r
                        return false;\r
                }\r
-               if (otherReservation == null) {\r
+               if (obj == null) {\r
                        return true;\r
                }\r
+               Reservation otherReservation = (Reservation) obj;\r
                return this.user != otherReservation.getUser() || this.resource != otherReservation.getResource()\r
                                || this.dateRange.compareTo(otherReservation.getDateRange()) != 0\r
                                || this.remark != otherReservation.getRemark();\r
index ab601e6..0b740c3 100644 (file)
@@ -9,7 +9,7 @@ package ch.bfh.ti.srs.dataschema;
 \r
 import java.util.UUID;\r
 \r
-public class Resource implements Cloneable {\r
+public class Resource implements Modify {\r
 \r
        private UUID id;\r
        private String name;\r
@@ -55,13 +55,14 @@ public class Resource implements Cloneable {
                this.type = type;\r
        }\r
 \r
-       public boolean isModified(Resource otherResource) {\r
-               if (otherResource == this) {\r
+       public boolean isModified(Object obj) {\r
+               if (obj == this) {\r
                        return false;\r
                }\r
-               if (otherResource == null) {\r
+               if (obj == null) {\r
                        return true;\r
                }\r
+               Resource otherResource = (Resource) obj;\r
                return this.name != otherResource.getName() || this.type != otherResource.getType();\r
        }\r
 \r
index c507ff5..c530d87 100644 (file)
@@ -206,4 +206,16 @@ public class DataHandlerForExcel implements DataHandler {
                // 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;
+       }
 }
@@ -6,3 +6,7 @@
  * Distributable under GPL license. See terms of license at gnu.org.\r
  */\r
 package ch.bfh.ti.srs.controller;\r
+\r
+public class ResourceManagerControllerTest {\r
+\r
+}\r