-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShiftManServer.java
More file actions
279 lines (256 loc) · 9.92 KB
/
Copy pathShiftManServer.java
File metadata and controls
279 lines (256 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package shiftman.server;
import java.util.Arrays;
import java.util.List;
/**
* The server side implementation of ShiftMan. Holds the roster object.
* @author Raymond Yang
*
*/
public class ShiftManServer implements ShiftMan {
private Roster _roster;
public ShiftManServer() {
}
/**
* Creates a new roster object with the specified name. It will catch
* an InvalidNameException if the specified name is empty or null.
* @param shopName The name of the shop the roster is for
* @return String Returns an empty string if there are no problems or a message
* relaying what the problem is.
*/
@Override
public String newRoster(String shopName){
try {
Roster roster = new Roster(shopName);
_roster = roster;
return "";
}
catch(InvalidNameException e) {
return e.getMessage();
}
}
/**
* Sets the working hours for the specified day. It will return an error message
* if a roster object has yet to be created. It will catch an InvalidTimeException if the
* dayOfWeek variable does not match one of the day strings given in ShiftMan documentation, or
* if the times given are invalid.
* @param dayOfWeek The day of the week to set working hours for
* startTime The opening time for the day
* endTime The closing time for the day
* @return String Returns an empty string if there are no problems or a message
* relaying what the problem is.
*/
@Override
public String setWorkingHours(String dayOfWeek, String startTime, String endTime) {
if(_roster == null) {
return "ERROR: no roster has been created";
}
try {
DateTime date = new DateTime(dayOfWeek,startTime,endTime);
_roster.addWorkingHours(date);
}
catch (InvalidTimeException e) {
return e.getMessage();
}
return "";
}
/**
* Adds a shift to the specified day with the specified start and end times, with a
* minimum number of workers needed to man the shift. It will catch an InvalidTimeException if the
* dayOfWeek variable does not match one of the day strings given in ShiftMan documentation, or
* if the times given are invalid.
* @param dayOfWeek The day to add the shift for
* startTime The start time of the shift
* endTime The end time of the shift
* minimumWorkers The minimum number of workers needed for the shift
* @return String Returns an empty string if there are no problems or a message
* relaying what the problem is.
*/
@Override
public String addShift(String dayOfWeek, String startTime, String endTime, String minimumWorkers) {
if(_roster == null) {
return "ERROR: no roster has been created";
}
try {
Shift shift = new Shift(dayOfWeek,startTime,endTime, minimumWorkers);
_roster.addShift(shift);
}
catch (InvalidTimeException e) {
return e.getMessage();
}
return "";
}
/**
* Registers a person to the shop as a staff member with the specified given name and
* family name. Catches InvalidNameException if either the givenname or familyName are
* empty or null.
* @param givenname The given name of the staff member
* familyName The family name of the staff member
* @return String Returns an empty string if there are no problems or a message
* relaying what the problem is.
*/
@Override
public String registerStaff(String givenname, String familyName) {
if(_roster == null) {
return "ERROR: no roster has been created";
}
try {
Staff staff = new Staff(givenname, familyName);
_roster.addStaff(staff);
}
catch(InvalidNameException e) {
return e.getMessage();
}
return "";
}
/**
* Assign a specific staff member given by two parameters to a specified shift given by 3
* parameters, and also assigns them as either worker or manager.
* @param dayOfWeek The day of the shift
* startTime The start time of the shift
* endTime The end time of the shift
* givenName The given name of the staff member
* familyName The family name of the staff member
* isManager True = staff is to be a manager, False = staff is to be a worker
* @return String Returns an empty string if there are no problems or an error message
* if the roster has not been created.
*/
@Override
public String assignStaff(String dayOfWeek, String startTime, String endTime, String givenName, String familyName,
boolean isManager) {
if(_roster == null) {
return "ERROR: no roster has been created";
}
Shift shift = _roster.findShift(dayOfWeek, startTime, endTime);
Staff staff = _roster.findStaff(givenName, familyName);
_roster.assignStaff(shift, staff, isManager);
return "";
}
/**
* Get a list of the registered staff ordered by their family names
* @return List<String> Returns a list of string which each entry in the list being 1 staff member or
* a list with one entry containing an error message if the roster has not been created
*/
@Override
public List<String> getRegisteredStaff() {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
FormatStaff registeredStaff = new FormatStaff(_roster.listOfStaff());
return registeredStaff.displayStaffList();
}
/**
* Get a list of the registered but unassigned staff ordered by their family names
* @return List<String> Returns a list of string which each entry in the list being 1 staff member or a list
* with one entry containing an error message if the roster has not been created
*/
@Override
public List<String> getUnassignedStaff() {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
FormatStaff unassignedStaff = new FormatStaff( _roster.unassignedStaffList());
return unassignedStaff.displayStaffList();
}
/**
* Get a list of the shifts that do not have managers
* @return List<String> Returns a list of string which each entry in the list being 1 shift or a list with one
* entry containing an error message if the roster has not been created
*/
@Override
public List<String> shiftsWithoutManagers() {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
FormatShift shiftList = new FormatShift(_roster.getShiftsWithoutManagers());
List<String> shiftString = shiftList.displayShiftList();
return shiftString;
}
/**
* Get a list of understaffed shifts
* @return List<String> Returns a list of string which each entry in the list being 1 shift or a list with one
* entry containing an error message if the roster has not been created
*/
@Override
public List<String> understaffedShifts() {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
FormatShift shiftList = new FormatShift(_roster.getUnderstaffedShifts());
List<String> shiftString = shiftList.displayShiftList();
return shiftString;
}
/**
* Get a list of overstaffed shifts
* @return List<String> Returns a list of string which each entry in the list being 1 shift or a list with one
* entry containing an error message if the roster has not been created
*/
@Override
public List<String> overstaffedShifts() {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
FormatShift shiftList = new FormatShift(_roster.getOverstaffedShifts());
List<String> shiftString = shiftList.displayShiftList();
return shiftString;
}
/**
* Get a roster for the day
* @return List<String> Return a list of string with the first entry being the name of the shop, the second entry
* being the working hours of the day, and the remaining entries being the shifts with 1 entry
* per shift containing shift times, manager name and worker names. Returns a list with one
* entry containing an error message if the roster has not been created
*/
@Override
public List<String> getRosterForDay(String dayOfWeek) {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
return _roster.getRosterForDay(dayOfWeek);
}
/**
* Get a roster for the specified worker
* @return List<String> Returns a list of string with the first entry being the name of the worker. The remaining entries
* (one entry per shift) will be the shifts the worker is assigned to. Returns a list with one
* entry containing an error message if the roster has not been created
*/
@Override
public List<String> getRosterForWorker(String workerName) {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
//Split the name into the given name and family name
String[] splitName = workerName.split(" ");
return _roster.getRosterForWorker(splitName[0], splitName[1]);
}
/**
* Get the shifts managed by the specified manager
* @return List<String> Return a list of string with the first entry being the name of the manager. The remaining entries
* (one entry per shift) will be the shifts the manager is assigned to. Returns a list with one entry
* containing an error message if the roster has not been created
*/
@Override
public List<String> getShiftsManagedBy(String managerName) {
if(_roster == null) {
//Creates a list with one entry
return Arrays.asList("ERROR: no roster has been created");
}
//Split the name into the given name and family name
String[] splitName = managerName.split(" ");
return _roster.getShiftsManagedBy(splitName[0], splitName[1]);
}
@Override
public String reportRosterIssues() {
return "";
}
@Override
public String displayRoster() {
return "";
}
}