Merge remote-tracking branch 'origin/development'
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / controller / ResourceManagerController.java
CommitLineData
5fca88b4
MT
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
8package ch.bfh.ti.srs.controller;\r
9\r
10import ch.bfh.ti.srs.datahandler.DataHandler;\r
11import ch.bfh.ti.srs.dataschema.Resource;\r
12\r
5fca88b4
MT
13public class ResourceManagerController extends Controller {\r
14\r
15 public ResourceManagerController(DataHandler dh, SessionController sc) {\r
16 super(dh, sc);\r
17 }\r
73469283 18\r
50c09002
MT
19 /**\r
20 * Creates new resource in the set <code>DataHandler</code>\r
73469283
D
21 * @param name\r
22 * name of resource\r
23 * @param type\r
24 * type of resource\r
50c09002
MT
25 * @return <code>True</code> Changes saved <code>False</code> Changes could\r
26 * not be saved\r
27 * @throws IllegalArgumentException\r
28 * if name is null\r
29 * @throws Exception\r
30 * if no <code>DataHandler</code> is set\r
31 */\r
32 public boolean addResource(String name, String type) throws Exception {\r
5fca88b4
MT
33 if (dh == null)\r
34 throw new Exception("No DataHandler set");\r
50c09002 35 if (name == null)\r
5fca88b4 36 throw new IllegalArgumentException("Resource must be defined");\r
50c09002
MT
37\r
38 Resource resource = new Resource(name, type);\r
5fca88b4
MT
39 return dh.addResource(resource);\r
40 }\r
73469283 41\r
50c09002 42 /**\r
73469283
D
43 * Replaces the given resource in the set <code>DataHandler</code> referring\r
44 * to the resource id\r
50c09002
MT
45 * @param resource\r
46 * Copy of the resource to edit\r
47 * @return <code>True</code> Changes saved <code>False</code> Changes could\r
48 * not be saved\r
49 * @throws IllegalArgumentException\r
50 * if resource is null\r
51 * @throws Exception\r
52 * if no <code>DataHandler</code> is set\r
53 */\r
73469283 54 public boolean changeResource(Resource resource) throws Exception {\r
5fca88b4
MT
55 if (dh == null)\r
56 throw new Exception("No DataHandler set");\r
57 if (resource == null)\r
58 throw new IllegalArgumentException("Resource must be defined");\r
59 return dh.editResource(resource);\r
60 }\r
73469283 61\r
50c09002 62 /**\r
73469283
D
63 * Deletes the given resource in the set <code>DataHandler</code> referring\r
64 * to the resource id\r
50c09002
MT
65 * @param resource\r
66 * Copy of the resource to edit\r
67 * @return <code>True</code> Changes saved <code>False</code> Changes could\r
68 * not be saved\r
69 * @throws IllegalArgumentException\r
70 * if resource is null\r
71 * @throws Exception\r
72 * if no <code>DataHandler</code> is set\r
73 */\r
5fca88b4
MT
74 public boolean deleteResource(Resource resource) throws Exception {\r
75 if (dh == null)\r
76 throw new Exception("No DataHandler set");\r
77 if (resource == null)\r
78 throw new IllegalArgumentException("Resource must be defined");\r
79 return dh.deleteResource(resource);\r
80 }\r
81}\r