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