Revize e3637ab0
Přidáno uživatelem Lukas Cerny před téměř 6 roky(ů)
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.business; |
2 | 2 |
|
3 | 3 |
import cz.zcu.yamanager.domain.User; |
4 |
import cz.zcu.yamanager.domain.Vacation; |
|
4 | 5 |
import cz.zcu.yamanager.dto.*; |
5 | 6 |
import cz.zcu.yamanager.repository.RequestRepository; |
6 | 7 |
import cz.zcu.yamanager.repository.UserRepository; |
... | ... | |
134 | 135 |
|
135 | 136 |
@Override |
136 | 137 |
public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
138 |
|
|
139 |
if (vacationDay.getDate().isBefore(LocalDate.now())) { |
|
140 |
throw new RESTFullException("Vacation cannot be token in past.", "vacation.past.error"); |
|
141 |
} |
|
142 |
|
|
137 | 143 |
try { |
138 | 144 |
User user = userRepository.getUser(userId); |
139 | 145 |
vacationDay.setStatus(user.getRole() == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING); |
140 | 146 |
|
141 |
cz.zcu.yamanager.domain.VacationDay vacation = new cz.zcu.yamanager.domain.VacationDay();
|
|
147 |
Vacation vacation = new Vacation();
|
|
142 | 148 |
vacation.setDate(vacationDay.getDate()); |
143 | 149 |
vacation.setFrom(vacationDay.getFrom()); |
144 | 150 |
vacation.setTo(vacationDay.getTo()); |
... | ... | |
221 | 227 |
@Override |
222 | 228 |
public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
223 | 229 |
try { |
224 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacation = vacationRepository.getVacationDay(vacationDay.getId());
|
|
230 |
Optional<Vacation> vacation = vacationRepository.getVacationDay(vacationDay.getId());
|
|
225 | 231 |
if (vacation.isPresent()) { |
226 | 232 |
vacation.get().setDate(vacationDay.getDate()); |
227 | 233 |
vacation.get().setStatus(vacationDay.getStatus()); |
... | ... | |
241 | 247 |
switch (type) { |
242 | 248 |
case VACATION: { |
243 | 249 |
|
244 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacationDayOpt = vacationRepository.getVacationDay(request.getId());
|
|
250 |
Optional<Vacation> vacationDayOpt = vacationRepository.getVacationDay(request.getId());
|
|
245 | 251 |
|
246 | 252 |
if (!vacationDayOpt.isPresent()) { |
247 | 253 |
throw new RESTFullException("", ""); |
248 | 254 |
} |
249 | 255 |
|
250 |
cz.zcu.yamanager.domain.VacationDay vacationDay = vacationDayOpt.get();
|
|
256 |
Vacation vacation = vacationDayOpt.get();
|
|
251 | 257 |
|
252 | 258 |
if (request.getStatus().equals(Status.REJECTED)) { |
253 |
User user = userRepository.getUser(vacationDay.getUserId());
|
|
259 |
User user = userRepository.getUser(vacation.getUserId()); |
|
254 | 260 |
|
255 |
switch (vacationDay.getType()) {
|
|
261 |
switch (vacation.getType()) { |
|
256 | 262 |
case VACATION: { |
257 |
user.addVacationCount(vacationDay.getFrom(), vacationDay.getTo());
|
|
263 |
user.addVacationCount(vacation.getFrom(), vacation.getTo());
|
|
258 | 264 |
userRepository.updateUserTakenVacation(user); |
259 | 265 |
} break; |
260 | 266 |
case SICK_DAY: { |
... | ... | |
264 | 270 |
} |
265 | 271 |
} |
266 | 272 |
|
267 |
requestRepository.updateVacationRequest(vacationDay.getId(), request.getStatus());
|
|
273 |
requestRepository.updateVacationRequest(vacation.getId(), request.getStatus()); |
|
268 | 274 |
|
269 | 275 |
} break; |
270 | 276 |
case AUTHORIZATION: { |
... | ... | |
283 | 289 |
public void deleteVacation(Long userId, Long vacationId) throws RESTFullException { |
284 | 290 |
try { |
285 | 291 |
User user = userRepository.getUser(userId); |
286 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacation = vacationRepository.getVacationDay(vacationId);
|
|
292 |
Optional<Vacation> vacation = vacationRepository.getVacationDay(vacationId);
|
|
287 | 293 |
|
288 | 294 |
if (!vacation.isPresent()) { |
289 | 295 |
throw new RESTFullException("", ""); |
290 | 296 |
} |
291 | 297 |
|
292 |
cz.zcu.yamanager.domain.VacationDay vacationDay = vacation.get();
|
|
298 |
Vacation vacationDay = vacation.get();
|
|
293 | 299 |
|
294 | 300 |
if (vacationDay.getDate().isAfter(LocalDate.now())) { |
295 | 301 |
if (!vacationDay.getStatus().equals(Status.REJECTED)) { |
server/src/main/java/cz/zcu/yamanager/domain/Vacation.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.VacationType; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
|
|
8 |
import java.time.LocalDate; |
|
9 |
import java.time.LocalDateTime; |
|
10 |
import java.time.LocalTime; |
|
11 |
|
|
12 |
/** |
|
13 |
* The domain class {@code Vacation} represents a single record in the 'vacation_day' table of a database. |
|
14 |
* Class holds informations of an overtime or a sick day taken by a user. |
|
15 |
*/ |
|
16 |
public class Vacation { |
|
17 |
/** |
|
18 |
* The logger. |
|
19 |
*/ |
|
20 |
private static final Logger log = LoggerFactory.getLogger(Vacation.class); |
|
21 |
|
|
22 |
/** |
|
23 |
* The ID of this vacation. |
|
24 |
*/ |
|
25 |
private Long id; |
|
26 |
|
|
27 |
/** |
|
28 |
* The date of this vacation. |
|
29 |
*/ |
|
30 |
private LocalDate date; |
|
31 |
|
|
32 |
/** |
|
33 |
* The starting time of this vacation. |
|
34 |
*/ |
|
35 |
private LocalTime from; |
|
36 |
|
|
37 |
/** |
|
38 |
* The ending time of this vacation. |
|
39 |
*/ |
|
40 |
private LocalTime to; |
|
41 |
|
|
42 |
/** |
|
43 |
* The date and time of a creation of this vacation. |
|
44 |
*/ |
|
45 |
private LocalDateTime creationDate; |
|
46 |
|
|
47 |
/** |
|
48 |
* The approval status of this vacation. |
|
49 |
*/ |
|
50 |
private Status status; |
|
51 |
|
|
52 |
/** |
|
53 |
* The type of this vacation. |
|
54 |
*/ |
|
55 |
private VacationType type; |
|
56 |
|
|
57 |
private Long userId; |
|
58 |
|
|
59 |
/** |
|
60 |
* Returns the ID of this vacation. |
|
61 |
* |
|
62 |
* @return the ID of this vacation |
|
63 |
*/ |
|
64 |
public long getId() { |
|
65 |
return this.id; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Replaces the ID of this vacation with the given one. |
|
70 |
* |
|
71 |
* @param id the given ID |
|
72 |
*/ |
|
73 |
public void setId(final Long id) { |
|
74 |
Vacation.log.debug("Setting a new id: {}", id); |
|
75 |
|
|
76 |
this.id = id; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Returns the date of this vacation. |
|
81 |
* |
|
82 |
* @return the date of this vacation |
|
83 |
*/ |
|
84 |
public LocalDate getDate() { |
|
85 |
return this.date; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Replaces the date of this vacation with the specified date. |
|
90 |
* If the given date is null the method throws an exception. |
|
91 |
* |
|
92 |
* @param date the new date |
|
93 |
* @throws IllegalArgumentException when the given date is null |
|
94 |
*/ |
|
95 |
public void setDate(final LocalDate date) throws IllegalArgumentException { |
|
96 |
Vacation.log.debug("Settings a new value of a date: {}", date); |
|
97 |
|
|
98 |
if (date == null) { |
|
99 |
Vacation.log.warn("The given date must not be null."); |
|
100 |
throw new IllegalArgumentException("date.null.error"); |
|
101 |
} |
|
102 |
|
|
103 |
this.date = date; |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Returns the starting time of this vacation. |
|
108 |
* |
|
109 |
* @return the starting time of this vacation |
|
110 |
*/ |
|
111 |
public LocalTime getFrom() { |
|
112 |
return this.from; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Replaces the starting time of this vacation with the given time. |
|
117 |
* If the given time is later or equals the ending time of this vacation the method throws an exception. |
|
118 |
* |
|
119 |
* @param from the new starting time |
|
120 |
* @throws IllegalArgumentException when the given time is later or equals the ending time of this vacation |
|
121 |
*/ |
|
122 |
public void setFrom(final LocalTime from) throws IllegalArgumentException { |
|
123 |
Vacation.log.debug("Settings a new value of the starting time of this vacation: {}", from); |
|
124 |
|
|
125 |
if (from != null && this.type == VacationType.SICK_DAY) { |
|
126 |
Vacation.log.warn("A sick day must not have a starting or an ending time"); |
|
127 |
throw new IllegalArgumentException("time.sick.day.error"); |
|
128 |
} else if(from == null && this.type == VacationType.VACATION) { |
|
129 |
Vacation.log.warn("A vacation has to have a starting and an ending time"); |
|
130 |
throw new IllegalArgumentException("time.vacation.error"); |
|
131 |
} else if (from != null && this.to != null && from.compareTo(this.to) >= 0) { |
|
132 |
Vacation.log.warn("A vacation must not start after it ends. from={}, to={}", from, this.to); |
|
133 |
throw new IllegalArgumentException("time.order.error"); |
|
134 |
} |
|
135 |
|
|
136 |
this.from = from; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Returns the ending time of this vacation. |
|
141 |
* |
|
142 |
* @return the ending time of this vacation |
|
143 |
*/ |
|
144 |
public LocalTime getTo() { |
|
145 |
return this.to; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Replaces the ending time of this vacation with the provided time. |
|
150 |
* If the given time is earlier or equals the starting time of this vacation the method throws an exception. |
|
151 |
* |
|
152 |
* @param to the new ending time |
|
153 |
* @throws IllegalArgumentException when the given time is earlier or equals the starting time of this vacation |
|
154 |
*/ |
|
155 |
public void setTo(final LocalTime to) throws IllegalArgumentException { |
|
156 |
Vacation.log.debug("Settings a new value of the ending time of this vacation: {}", to); |
|
157 |
|
|
158 |
if (to != null && this.type == VacationType.SICK_DAY) { |
|
159 |
Vacation.log.warn("A sick day must not have a starting or an ending time"); |
|
160 |
throw new IllegalArgumentException("time.sick_day.error"); |
|
161 |
} else if(to == null && this.type == VacationType.VACATION) { |
|
162 |
Vacation.log.warn("A vacation has to have a starting and an ending time"); |
|
163 |
throw new IllegalArgumentException("time.vacation.error"); |
|
164 |
} else if (to != null && this.from != null && to.compareTo(this.from) <= 0) { |
|
165 |
Vacation.log.warn("A vacation must not end after it starts. from={}, to={}", this.from, to); |
|
166 |
throw new IllegalArgumentException("time.order.error"); |
|
167 |
} |
|
168 |
|
|
169 |
this.to = to; |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Replaces the starting and ending time of this vacation with the provided values. |
|
174 |
* If the starting time is later or equals the ending time the method throws an exception. |
|
175 |
* |
|
176 |
* @param from the new starting time |
|
177 |
* @param to the new ending time |
|
178 |
* @throws IllegalArgumentException when the ending time is earlier or equals the starting time |
|
179 |
*/ |
|
180 |
public void setTime(final LocalTime from, final LocalTime to) throws IllegalArgumentException { |
|
181 |
Vacation.log.debug("Settings a new value of the starting {} and the ending {} time of this vacation.", from, to); |
|
182 |
|
|
183 |
if ((from != null || to != null) && this.type == VacationType.SICK_DAY) { |
|
184 |
Vacation.log.warn("A sick day must not have a starting or an ending time"); |
|
185 |
throw new IllegalArgumentException("time.sick.day_error"); |
|
186 |
} else if((from == null || to == null) && this.type == VacationType.VACATION) { |
|
187 |
Vacation.log.warn("A vacation has to have a starting and an ending time"); |
|
188 |
throw new IllegalArgumentException("time.vacation.error"); |
|
189 |
} else if (from != null && to != null && from.compareTo(to) >= 0) { |
|
190 |
Vacation.log.warn("A vacation must not start after it ends. from={}, to={}", from, to); |
|
191 |
throw new IllegalArgumentException("time.order.error"); |
|
192 |
} |
|
193 |
|
|
194 |
this.from = from; |
|
195 |
this.to = to; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Returns the date and time of a creation of this vacation. |
|
200 |
* |
|
201 |
* @return the date and time of the creation of this vacation |
|
202 |
*/ |
|
203 |
public LocalDateTime getCreationDate() { |
|
204 |
return this.creationDate; |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Replaces the creation date of this vacation with the given date and time. |
|
209 |
* |
|
210 |
* @param creationDate the new creation date |
|
211 |
*/ |
|
212 |
public void setCreationDate(final LocalDateTime creationDate) { |
|
213 |
Vacation.log.debug("Setting a new creation date of this vacation: {}", creationDate); |
|
214 |
|
|
215 |
this.creationDate = creationDate; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Returns the approval status of this vacation. |
|
220 |
* |
|
221 |
* @return the approval status of this vacation |
|
222 |
*/ |
|
223 |
public Status getStatus() { |
|
224 |
return this.status; |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Replaces the approval status of this vacation with the given value. |
|
229 |
* If the given status is null the method throws an exception. |
|
230 |
* |
|
231 |
* @param status the new approval status |
|
232 |
* @throws IllegalArgumentException when the given status is null |
|
233 |
*/ |
|
234 |
public void setStatus(final Status status) throws IllegalArgumentException { |
|
235 |
Vacation.log.debug("Setting a new approval status: {}", status); |
|
236 |
|
|
237 |
if (status == null) { |
|
238 |
Vacation.log.warn("The given status must not be null"); |
|
239 |
throw new IllegalArgumentException("status.null.error"); |
|
240 |
} |
|
241 |
|
|
242 |
this.status = status; |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Returns the type of this vacation. |
|
247 |
* |
|
248 |
* @return the type of this vacation |
|
249 |
*/ |
|
250 |
public VacationType getType() { |
|
251 |
return this.type; |
|
252 |
} |
|
253 |
|
|
254 |
/** |
|
255 |
* Replaces the type of this vacation with the handed type. |
|
256 |
* If the given type is SICK_DAY the method sets the starting and the ending time to null. |
|
257 |
* If the given type is null the method throws an exception. |
|
258 |
* |
|
259 |
* @param type the new type |
|
260 |
* @throws IllegalArgumentException when the given type is null |
|
261 |
*/ |
|
262 |
public void setType(final VacationType type) throws IllegalArgumentException { |
|
263 |
Vacation.log.debug("Setting a new type of this vacation: {}", type); |
|
264 |
|
|
265 |
if(type == VacationType.SICK_DAY) { |
|
266 |
this.from = null; |
|
267 |
this.to = null; |
|
268 |
} else if (type == null) { |
|
269 |
Vacation.log.warn("The given type of a vacation must not be null"); |
|
270 |
throw new IllegalArgumentException("type.null.error"); |
|
271 |
} |
|
272 |
|
|
273 |
this.type = type; |
|
274 |
} |
|
275 |
|
|
276 |
public Long getUserId() { |
|
277 |
return userId; |
|
278 |
} |
|
279 |
|
|
280 |
public void setUserId(Long userId) { |
|
281 |
this.userId = userId; |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* Gets a string representation of this vacation. The representation consists of its id, date, starting time, ending time, creation date, status and type. |
|
286 |
* |
|
287 |
* @return the string representation of this vacation |
|
288 |
*/ |
|
289 |
@Override |
|
290 |
public String toString() { |
|
291 |
return "Vacation{" + |
|
292 |
"id=" + this.id + |
|
293 |
", date=" + this.date + |
|
294 |
", from=" + this.from + |
|
295 |
", to=" + this.to + |
|
296 |
", creationDate=" + this.creationDate + |
|
297 |
", status=" + this.status + |
|
298 |
", type=" + this.type + |
|
299 |
'}'; |
|
300 |
} |
|
301 |
} |
server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.VacationType; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
|
|
8 |
import java.time.LocalDate; |
|
9 |
import java.time.LocalDateTime; |
|
10 |
import java.time.LocalTime; |
|
11 |
|
|
12 |
/** |
|
13 |
* The domain class {@code VacationDay} represents a single record in the 'vacation_day' table of a database. |
|
14 |
* Class holds informations of an overtime or a sick day taken by a user. |
|
15 |
*/ |
|
16 |
public class VacationDay { |
|
17 |
/** |
|
18 |
* The logger. |
|
19 |
*/ |
|
20 |
private static final Logger log = LoggerFactory.getLogger(VacationDay.class); |
|
21 |
|
|
22 |
/** |
|
23 |
* The ID of this vacation. |
|
24 |
*/ |
|
25 |
private Long id; |
|
26 |
|
|
27 |
/** |
|
28 |
* The date of this vacation. |
|
29 |
*/ |
|
30 |
private LocalDate date; |
|
31 |
|
|
32 |
/** |
|
33 |
* The starting time of this vacation. |
|
34 |
*/ |
|
35 |
private LocalTime from; |
|
36 |
|
|
37 |
/** |
|
38 |
* The ending time of this vacation. |
|
39 |
*/ |
|
40 |
private LocalTime to; |
|
41 |
|
|
42 |
/** |
|
43 |
* The date and time of a creation of this vacation. |
|
44 |
*/ |
|
45 |
private LocalDateTime creationDate; |
|
46 |
|
|
47 |
/** |
|
48 |
* The approval status of this vacation. |
|
49 |
*/ |
|
50 |
private Status status; |
|
51 |
|
|
52 |
/** |
|
53 |
* The type of this vacation. |
|
54 |
*/ |
|
55 |
private VacationType type; |
|
56 |
|
|
57 |
private Long userId; |
|
58 |
|
|
59 |
/** |
|
60 |
* Returns the ID of this vacation. |
|
61 |
* |
|
62 |
* @return the ID of this vacation |
|
63 |
*/ |
|
64 |
public long getId() { |
|
65 |
return this.id; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Replaces the ID of this vacation with the given one. |
|
70 |
* |
|
71 |
* @param id the given ID |
|
72 |
*/ |
|
73 |
public void setId(final Long id) { |
|
74 |
VacationDay.log.debug("Setting a new id: {}", id); |
|
75 |
|
|
76 |
this.id = id; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Returns the date of this vacation. |
|
81 |
* |
|
82 |
* @return the date of this vacation |
|
83 |
*/ |
|
84 |
public LocalDate getDate() { |
|
85 |
return this.date; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Replaces the date of this vacation with the specified date. |
|
90 |
* If the given date is null the method throws an exception. |
|
91 |
* |
|
92 |
* @param date the new date |
|
93 |
* @throws IllegalArgumentException when the given date is null |
|
94 |
*/ |
|
95 |
public void setDate(final LocalDate date) throws IllegalArgumentException { |
|
96 |
VacationDay.log.debug("Settings a new value of a date: {}", date); |
|
97 |
|
|
98 |
if (date == null) { |
|
99 |
VacationDay.log.warn("The given date must not be null."); |
|
100 |
throw new IllegalArgumentException("date.null.error"); |
|
101 |
} |
|
102 |
|
|
103 |
this.date = date; |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Returns the starting time of this vacation. |
|
108 |
* |
|
109 |
* @return the starting time of this vacation |
|
110 |
*/ |
|
111 |
public LocalTime getFrom() { |
|
112 |
return this.from; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Replaces the starting time of this vacation with the given time. |
|
117 |
* If the given time is later or equals the ending time of this vacation the method throws an exception. |
|
118 |
* |
|
119 |
* @param from the new starting time |
|
120 |
* @throws IllegalArgumentException when the given time is later or equals the ending time of this vacation |
|
121 |
*/ |
|
122 |
public void setFrom(final LocalTime from) throws IllegalArgumentException { |
|
123 |
VacationDay.log.debug("Settings a new value of the starting time of this vacation: {}", from); |
|
124 |
|
|
125 |
if (from != null && this.type == VacationType.SICK_DAY) { |
|
126 |
VacationDay.log.warn("A sick day must not have a starting or an ending time"); |
|
127 |
throw new IllegalArgumentException("time.sick.day.error"); |
|
128 |
} else if(from == null && this.type == VacationType.VACATION) { |
|
129 |
VacationDay.log.warn("A vacation has to have a starting and an ending time"); |
|
130 |
throw new IllegalArgumentException("time.vacation.error"); |
|
131 |
} else if (from != null && this.to != null && from.compareTo(this.to) >= 0) { |
|
132 |
VacationDay.log.warn("A vacation must not start after it ends. from={}, to={}", from, this.to); |
|
133 |
throw new IllegalArgumentException("time.order.error"); |
|
134 |
} |
|
135 |
|
|
136 |
this.from = from; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Returns the ending time of this vacation. |
|
141 |
* |
|
142 |
* @return the ending time of this vacation |
|
143 |
*/ |
|
144 |
public LocalTime getTo() { |
|
145 |
return this.to; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Replaces the ending time of this vacation with the provided time. |
|
150 |
* If the given time is earlier or equals the starting time of this vacation the method throws an exception. |
|
151 |
* |
|
152 |
* @param to the new ending time |
|
153 |
* @throws IllegalArgumentException when the given time is earlier or equals the starting time of this vacation |
|
154 |
*/ |
|
155 |
public void setTo(final LocalTime to) throws IllegalArgumentException { |
|
156 |
VacationDay.log.debug("Settings a new value of the ending time of this vacation: {}", to); |
|
157 |
|
|
158 |
if (to != null && this.type == VacationType.SICK_DAY) { |
|
159 |
VacationDay.log.warn("A sick day must not have a starting or an ending time"); |
|
160 |
throw new IllegalArgumentException("time.sick_day.error"); |
|
161 |
} else if(to == null && this.type == VacationType.VACATION) { |
|
162 |
VacationDay.log.warn("A vacation has to have a starting and an ending time"); |
|
163 |
throw new IllegalArgumentException("time.vacation.error"); |
|
164 |
} else if (to != null && this.from != null && to.compareTo(this.from) <= 0) { |
|
165 |
VacationDay.log.warn("A vacation must not end after it starts. from={}, to={}", this.from, to); |
|
166 |
throw new IllegalArgumentException("time.order.error"); |
|
167 |
} |
|
168 |
|
|
169 |
this.to = to; |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Replaces the starting and ending time of this vacation with the provided values. |
|
174 |
* If the starting time is later or equals the ending time the method throws an exception. |
|
175 |
* |
|
176 |
* @param from the new starting time |
|
177 |
* @param to the new ending time |
|
178 |
* @throws IllegalArgumentException when the ending time is earlier or equals the starting time |
|
179 |
*/ |
|
180 |
public void setTime(final LocalTime from, final LocalTime to) throws IllegalArgumentException { |
|
181 |
VacationDay.log.debug("Settings a new value of the starting {} and the ending {} time of this vacation.", from, to); |
|
182 |
|
|
183 |
if ((from != null || to != null) && this.type == VacationType.SICK_DAY) { |
|
184 |
VacationDay.log.warn("A sick day must not have a starting or an ending time"); |
|
185 |
throw new IllegalArgumentException("time.sick.day_error"); |
|
186 |
} else if((from == null || to == null) && this.type == VacationType.VACATION) { |
|
187 |
VacationDay.log.warn("A vacation has to have a starting and an ending time"); |
|
188 |
throw new IllegalArgumentException("time.vacation.error"); |
|
189 |
} else if (from != null && to != null && from.compareTo(to) >= 0) { |
|
190 |
VacationDay.log.warn("A vacation must not start after it ends. from={}, to={}", from, to); |
|
191 |
throw new IllegalArgumentException("time.order.error"); |
|
192 |
} |
|
193 |
|
|
194 |
this.from = from; |
|
195 |
this.to = to; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Returns the date and time of a creation of this vacation. |
|
200 |
* |
|
201 |
* @return the date and time of the creation of this vacation |
|
202 |
*/ |
|
203 |
public LocalDateTime getCreationDate() { |
|
204 |
return this.creationDate; |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Replaces the creation date of this vacation with the given date and time. |
|
209 |
* |
|
210 |
* @param creationDate the new creation date |
|
211 |
*/ |
|
212 |
public void setCreationDate(final LocalDateTime creationDate) { |
|
213 |
VacationDay.log.debug("Setting a new creation date of this vacation: {}", creationDate); |
|
214 |
|
|
215 |
this.creationDate = creationDate; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Returns the approval status of this vacation. |
|
220 |
* |
|
221 |
* @return the approval status of this vacation |
|
222 |
*/ |
|
223 |
public Status getStatus() { |
|
224 |
return this.status; |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Replaces the approval status of this vacation with the given value. |
|
229 |
* If the given status is null the method throws an exception. |
|
230 |
* |
|
231 |
* @param status the new approval status |
|
232 |
* @throws IllegalArgumentException when the given status is null |
|
233 |
*/ |
|
234 |
public void setStatus(final Status status) throws IllegalArgumentException { |
|
235 |
VacationDay.log.debug("Setting a new approval status: {}", status); |
|
236 |
|
|
237 |
if (status == null) { |
|
238 |
VacationDay.log.warn("The given status must not be null"); |
|
239 |
throw new IllegalArgumentException("status.null.error"); |
|
240 |
} |
|
241 |
|
|
242 |
this.status = status; |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Returns the type of this vacation. |
|
247 |
* |
|
248 |
* @return the type of this vacation |
|
249 |
*/ |
|
250 |
public VacationType getType() { |
|
251 |
return this.type; |
|
252 |
} |
|
253 |
|
|
254 |
/** |
|
255 |
* Replaces the type of this vacation with the handed type. |
|
256 |
* If the given type is SICK_DAY the method sets the starting and the ending time to null. |
|
257 |
* If the given type is null the method throws an exception. |
|
258 |
* |
|
259 |
* @param type the new type |
|
260 |
* @throws IllegalArgumentException when the given type is null |
|
261 |
*/ |
|
262 |
public void setType(final VacationType type) throws IllegalArgumentException { |
|
263 |
VacationDay.log.debug("Setting a new type of this vacation: {}", type); |
|
264 |
|
|
265 |
if(type == VacationType.SICK_DAY) { |
|
266 |
this.from = null; |
|
267 |
this.to = null; |
|
268 |
} else if (type == null) { |
|
269 |
VacationDay.log.warn("The given type of a vacation must not be null"); |
|
270 |
throw new IllegalArgumentException("type.null.error"); |
|
271 |
} |
|
272 |
|
|
273 |
this.type = type; |
|
274 |
} |
|
275 |
|
|
276 |
public Long getUserId() { |
|
277 |
return userId; |
|
278 |
} |
|
279 |
|
|
280 |
public void setUserId(Long userId) { |
|
281 |
this.userId = userId; |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* Gets a string representation of this vacation. The representation consists of its id, date, starting time, ending time, creation date, status and type. |
|
286 |
* |
|
287 |
* @return the string representation of this vacation |
|
288 |
*/ |
|
289 |
@Override |
|
290 |
public String toString() { |
|
291 |
return "VacationDay{" + |
|
292 |
"id=" + this.id + |
|
293 |
", date=" + this.date + |
|
294 |
", from=" + this.from + |
|
295 |
", to=" + this.to + |
|
296 |
", creationDate=" + this.creationDate + |
|
297 |
", status=" + this.status + |
|
298 |
", type=" + this.type + |
|
299 |
'}'; |
|
300 |
} |
|
301 |
} |
server/src/main/java/cz/zcu/yamanager/dto/VacationDay.java | ||
---|---|---|
4 | 4 |
import java.time.LocalTime; |
5 | 5 |
|
6 | 6 |
/** |
7 |
* The messenger class {@code VacationDay} holds informations of an overtime or a sick day taken by a user.
|
|
7 |
* The messenger class {@code Vacation} holds informations of an overtime or a sick day taken by a user. |
|
8 | 8 |
* This class is used in communication with a frontend. |
9 | 9 |
*/ |
10 | 10 |
public class VacationDay { |
server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.repository; |
2 | 2 |
|
3 | 3 |
import cz.zcu.yamanager.domain.User; |
4 |
import cz.zcu.yamanager.domain.Vacation; |
|
4 | 5 |
import cz.zcu.yamanager.dto.*; |
5 | 6 |
|
6 | 7 |
import org.slf4j.Logger; |
... | ... | |
23 | 24 |
@Repository |
24 | 25 |
public class VacationRepository { |
25 | 26 |
/** |
26 |
* The mapper maps a row from a result of a query to an VacationDay.
|
|
27 |
* The mapper maps a row from a result of a query to an Vacation. |
|
27 | 28 |
*/ |
28 | 29 |
private class VacationDayMapper implements RowMapper<VacationDay> { |
29 | 30 |
|
30 | 31 |
/** |
31 |
* Maps a row from a result of a query to an VacationDay.
|
|
32 |
* Maps a row from a result of a query to an Vacation. |
|
32 | 33 |
* @param resultSet the row from the result |
33 | 34 |
* @param i the index of the row |
34 |
* @return the VacationDay object
|
|
35 |
* @return the Vacation object |
|
35 | 36 |
* @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set |
36 | 37 |
*/ |
37 | 38 |
@Override |
... | ... | |
116 | 117 |
new Object[]{userId, from, to, status.name()}, new VacationDayMapper()); |
117 | 118 |
} |
118 | 119 |
|
119 |
public Optional<cz.zcu.yamanager.domain.VacationDay> getVacationDay(final long id) {
|
|
120 |
public Optional<Vacation> getVacationDay(final long id) {
|
|
120 | 121 |
return ofNullable(jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type, user_id " + |
121 | 122 |
"FROM vacation_day WHERE id = ?", new Object[]{id}, |
122 | 123 |
(ResultSet rs, int rowNum) -> { |
123 |
cz.zcu.yamanager.domain.VacationDay vacationDay = new cz.zcu.yamanager.domain.VacationDay();
|
|
124 |
vacationDay.setId(rs.getLong("id"));
|
|
125 |
vacationDay.setDate(rs.getDate("vacation_date").toLocalDate());
|
|
124 |
Vacation vacation = new Vacation();
|
|
125 |
vacation.setId(rs.getLong("id")); |
|
126 |
vacation.setDate(rs.getDate("vacation_date").toLocalDate()); |
|
126 | 127 |
/* |
127 | 128 |
When a result contains a sick day it doesn't have specified a start and end time because |
128 | 129 |
it can be taken only as a whole day. In this case the v.time_from and v.time_to are null. |
... | ... | |
130 | 131 |
*/ |
131 | 132 |
final Time timeFrom = rs.getTime("time_from"); |
132 | 133 |
if (timeFrom != null) { |
133 |
vacationDay.setFrom(timeFrom.toLocalTime());
|
|
134 |
vacation.setFrom(timeFrom.toLocalTime()); |
|
134 | 135 |
} |
135 | 136 |
|
136 | 137 |
final Time timeTo = rs.getTime("time_to"); |
137 | 138 |
if (timeTo != null) { |
138 |
vacationDay.setTo(timeTo.toLocalTime());
|
|
139 |
vacation.setTo(timeTo.toLocalTime()); |
|
139 | 140 |
} |
140 | 141 |
|
141 |
vacationDay.setCreationDate(rs.getTimestamp("creation_date").toLocalDateTime());
|
|
142 |
vacationDay.setStatus(getStatus(rs.getString("status")));
|
|
143 |
vacationDay.setType(VacationType.getVacationType(rs.getString("vacation_type")));
|
|
144 |
vacationDay.setUserId(rs.getLong("user_id"));
|
|
145 |
return vacationDay;
|
|
142 |
vacation.setCreationDate(rs.getTimestamp("creation_date").toLocalDateTime()); |
|
143 |
vacation.setStatus(getStatus(rs.getString("status"))); |
|
144 |
vacation.setType(VacationType.getVacationType(rs.getString("vacation_type"))); |
|
145 |
vacation.setUserId(rs.getLong("user_id")); |
|
146 |
return vacation; |
|
146 | 147 |
})); |
147 | 148 |
} |
148 | 149 |
|
149 |
public void insertVacationDay(final Long userId, final cz.zcu.yamanager.domain.VacationDay day) {
|
|
150 |
public void insertVacationDay(final Long userId, final Vacation day) {
|
|
150 | 151 |
jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)", |
151 | 152 |
day.getDate(), day.getFrom(), day.getTo(), day.getStatus().name(), day.getType().name(), userId); |
152 | 153 |
} |
153 | 154 |
|
154 |
public void updateVacationDay(final cz.zcu.yamanager.domain.VacationDay item) {
|
|
155 |
public void updateVacationDay(final Vacation item) {
|
|
155 | 156 |
jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?", |
156 | 157 |
item.getDate(), item.getFrom(), item.getTo(), item.getStatus().name(), item.getType().name(), item.getId()); |
157 | 158 |
} |
server/src/main/resources/Message_cs.properties | ||
---|---|---|
22 | 22 |
notification.null.error = Datum upozorn\u011Bn\u00ED mus\u00ED b\u00FDt zad\u00E1n. |
23 | 23 |
vacation.null.error = Po\u010Det hodin dovolen\u00E9 mus\u00ED b\u00FDt zad\u00E1n. |
24 | 24 |
role.null.error = Role mus\u00ED b\u00FDt zad\u00E1n. |
25 |
database.error = Vyskytl se probl\u00E9m s datab\u00E1z\u00ED. |
|
25 |
database.error = Vyskytl se probl\u00E9m s datab\u00E1z\u00ED. |
|
26 |
vacation.past.error = Nelze vybrat volno v minulosti. |
server/src/main/resources/Message_en.properties | ||
---|---|---|
22 | 22 |
notification.null.error = The date of a notification has to be filled in. |
23 | 23 |
vacation.null.error = The number of overtime hours has to be filled in. |
24 | 24 |
role.null.error = The role has to be filled in. |
25 |
database.error = There was a problem with the database. |
|
25 |
database.error = There was a problem with the database. |
|
26 |
vacation.past.error = You cannot take a vacation in past. |
server/src/test/java/cz/zcu/yamanager/domain/VacationDayTest.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.VacationType; |
|
5 |
import org.junit.jupiter.api.BeforeEach; |
|
6 |
import org.junit.jupiter.api.Test; |
|
7 |
|
|
8 |
import java.time.LocalDate; |
|
9 |
import java.time.LocalDateTime; |
|
10 |
import java.time.LocalTime; |
|
11 |
|
|
12 |
import static org.junit.jupiter.api.Assertions.*; |
|
13 |
|
|
14 |
/** |
|
15 |
* This class tests methods of the {@code VacationDay} class. |
|
16 |
* @see VacationDay |
|
17 |
*/ |
|
18 |
class VacationDayTest { |
|
19 |
/** |
|
20 |
* The empty instance of the {@code VacationDay}. |
|
21 |
*/ |
|
22 |
private VacationDay vacationDay; |
|
23 |
|
|
24 |
/** |
|
25 |
* Prepares the instance of the {@code VacationDay}. |
|
26 |
*/ |
|
27 |
@BeforeEach |
|
28 |
void setUp() { |
|
29 |
this.vacationDay = new VacationDay(); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Tests the method {@code setDate} with common values where no problem should occur. |
|
34 |
*/ |
|
35 |
@Test |
|
36 |
void setDate_valid() { |
|
37 |
LocalDate date = LocalDate.of(2000,10,12); |
|
38 |
this.vacationDay.setDate(date); |
|
39 |
assertEquals(date, this.vacationDay.getDate()); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* Tests the method {@code setDate} with null input value. |
|
44 |
*/ |
|
45 |
@Test |
|
46 |
void setDate_nullInput() { |
|
47 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setDate(null)); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* Tests the method {@code setFrom} with a null input, null ending time and null vacation type. |
|
52 |
*/ |
|
53 |
@Test |
|
54 |
void setFrom_nullFrom_nullTo_nullType_valid() { |
|
55 |
this.vacationDay.setFrom(null); |
|
56 |
assertNull(this.vacationDay.getFrom()); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Tests the method {@code setFrom} with a null input, ending time and null vacation type. |
|
61 |
*/ |
|
62 |
@Test |
|
63 |
void setFrom_nullFrom_to_nullType_valid() { |
|
64 |
this.vacationDay.setTo(LocalTime.of(20, 0)); |
|
65 |
this.vacationDay.setFrom(null); |
|
66 |
assertNull(this.vacationDay.getFrom()); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Tests the method {@code setFrom} with an input, null ending time and null vacation type. |
|
71 |
*/ |
|
72 |
@Test |
|
73 |
void setFrom_from_nullTo_nullType_valid() { |
|
74 |
LocalTime from = LocalTime.of(10,0); |
|
75 |
this.vacationDay.setFrom(from); |
|
76 |
assertEquals(from, this.vacationDay.getFrom()); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Tests the method {@code setFrom} with an input, ending time and null vacation type. |
|
81 |
*/ |
|
82 |
@Test |
|
83 |
void setFrom_from_to_nullType_valid() { |
|
84 |
LocalTime to = LocalTime.of(20, 0); |
|
85 |
this.vacationDay.setTo(to); |
|
86 |
LocalTime from = LocalTime.of(10,0); |
|
87 |
this.vacationDay.setFrom(from); |
|
88 |
assertEquals(from, this.vacationDay.getFrom()); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Tests the method {@code setFrom} with same input and ending time and null vacation type. |
|
93 |
*/ |
|
94 |
@Test |
|
95 |
void setFrom_from_to_nullType_same() { |
|
96 |
LocalTime to = LocalTime.of(10, 0); |
|
97 |
this.vacationDay.setTo(to); |
|
98 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(to)); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Tests the method {@code setFrom} with same input and ending time and null vacation type. |
|
103 |
*/ |
|
104 |
@Test |
|
105 |
void setFrom_from_to_nullType_wrongOrder() { |
|
106 |
LocalTime to = LocalTime.of(10, 0); |
|
107 |
this.vacationDay.setTo(to); |
|
108 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(20,0))); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Tests the method {@code setFrom} with a null input, null ending time and sick day vacation type. |
|
113 |
*/ |
|
114 |
@Test |
|
115 |
void setFrom_nullFrom_nullTo_sickDay_valid() { |
|
116 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
117 |
this.vacationDay.setFrom(null); |
|
118 |
assertNull(this.vacationDay.getFrom()); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Tests the method {@code setFrom} with an input and sick day vacation type. |
|
123 |
*/ |
|
124 |
@Test |
|
125 |
void setFrom_from_sickDay() { |
|
126 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
127 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(20,0))); |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Tests the method {@code setFrom} with a null input, null ending time and vacation vacation type. |
|
132 |
*/ |
|
133 |
@Test |
|
134 |
void setFrom_nullFrom_vacation_valid() { |
|
135 |
this.vacationDay.setFrom(null); |
|
136 |
assertNull(this.vacationDay.getFrom()); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Tests the method {@code setFrom} with an input, null ending time and vacation vacation type. |
|
141 |
*/ |
|
142 |
@Test |
|
143 |
void setFrom_from_nullTo_vacation_valid() { |
|
144 |
this.vacationDay.setType(VacationType.VACATION); |
|
145 |
LocalTime from = LocalTime.of(10,0); |
|
146 |
this.vacationDay.setFrom(from); |
|
147 |
assertEquals(from, this.vacationDay.getFrom()); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Tests the method {@code setFrom} with an input, ending time and vacation vacation type. |
|
152 |
*/ |
|
153 |
@Test |
|
154 |
void setFrom_from_to_vacation_valid() { |
|
155 |
this.vacationDay.setType(VacationType.VACATION); |
|
156 |
LocalTime to = LocalTime.of(20, 0); |
|
157 |
this.vacationDay.setTo(to); |
|
158 |
LocalTime from = LocalTime.of(10,0); |
|
159 |
this.vacationDay.setFrom(from); |
|
160 |
assertEquals(from, this.vacationDay.getFrom()); |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* Tests the method {@code setFrom} with same input and ending time and vacation vacation type. |
|
165 |
*/ |
|
166 |
@Test |
|
167 |
void setFrom_from_to_vacation_same() { |
|
168 |
this.vacationDay.setType(VacationType.VACATION); |
|
169 |
LocalTime to = LocalTime.of(10, 0); |
|
170 |
this.vacationDay.setTo(to); |
|
171 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(10,0))); |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* Tests the method {@code setFrom} with same input and ending time and vacation vacation type. |
|
176 |
*/ |
|
177 |
@Test |
|
178 |
void setFrom_from_to_vacation_wrongOrder() { |
|
179 |
this.vacationDay.setType(VacationType.VACATION); |
|
180 |
LocalTime to = LocalTime.of(10, 0); |
|
181 |
this.vacationDay.setTo(to); |
|
182 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(20,0))); |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Tests the method {@code setTo} with a null input, null starting time and null vacation type. |
|
187 |
*/ |
|
188 |
@Test |
|
189 |
void setTo_nullTo_nullFrom_nullType_valid() { |
|
190 |
this.vacationDay.setTo(null); |
|
191 |
assertNull(this.vacationDay.getTo()); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Tests the method {@code setTo} with a null input, starting time and null vacation type. |
|
196 |
*/ |
|
197 |
@Test |
|
198 |
void setTo_nullTo_from_nullType_valid() { |
|
199 |
this.vacationDay.setFrom(LocalTime.of(20, 0)); |
|
200 |
this.vacationDay.setTo(null); |
|
201 |
assertNull(this.vacationDay.getTo()); |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* Tests the method {@code setTo} with an input, null starting time and null vacation type. |
|
206 |
*/ |
|
207 |
@Test |
|
208 |
void setTo_to_nullFrom_nullType_valid() { |
|
209 |
LocalTime to = LocalTime.of(10,0); |
|
210 |
this.vacationDay.setTo(to); |
|
211 |
assertEquals(to, this.vacationDay.getTo()); |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* Tests the method {@code setTo} with an input, starting time and null vacation type. |
|
216 |
*/ |
|
217 |
@Test |
|
218 |
void setTo_to_from_nullType_valid() { |
|
219 |
LocalTime from = LocalTime.of(10, 0); |
|
220 |
this.vacationDay.setFrom(from); |
|
221 |
LocalTime to = LocalTime.of(20,0); |
|
222 |
this.vacationDay.setTo(to); |
|
223 |
assertEquals(to, this.vacationDay.getTo()); |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* Tests the method {@code setTo} with same input and starting time and null vacation type. |
|
228 |
*/ |
|
229 |
@Test |
|
230 |
void setTo_to_from_nullType_same() { |
|
231 |
LocalTime from = LocalTime.of(10, 0); |
|
232 |
this.vacationDay.setFrom(from); |
|
233 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(10,0))); |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* Tests the method {@code setTo} with same input and starting time and null vacation type. |
|
238 |
*/ |
|
239 |
@Test |
|
240 |
void setTo_to_from_nullType_wrongOrder() { |
|
241 |
LocalTime from = LocalTime.of(20, 0); |
|
242 |
this.vacationDay.setFrom(from); |
|
243 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(10,0))); |
|
244 |
} |
|
245 |
|
|
246 |
/** |
|
247 |
* Tests the method {@code setTo} with a null input, null starting time and sick day vacation type. |
|
248 |
*/ |
|
249 |
@Test |
|
250 |
void setTo_nullTo_nullFrom_sickDay_valid() { |
|
251 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
252 |
this.vacationDay.setTo(null); |
|
253 |
assertNull(this.vacationDay.getTo()); |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* Tests the method {@code setTo} with an input and sick day vacation type. |
|
258 |
*/ |
|
259 |
@Test |
|
260 |
void setTo_to_sickDay() { |
|
261 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
262 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(20,0))); |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Tests the method {@code setTo} with a null input, null starting time and vacation vacation type. |
|
267 |
*/ |
|
268 |
@Test |
|
269 |
void setTo_nullTo_vacation_valid() { |
|
270 |
this.vacationDay.setTo(null); |
|
271 |
assertNull(this.vacationDay.getTo()); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* Tests the method {@code setTo} with an input, null starting time and vacation vacation type. |
|
276 |
*/ |
|
277 |
@Test |
|
278 |
void setTo_to_nullFrom_vacation_valid() { |
|
279 |
this.vacationDay.setType(VacationType.VACATION); |
|
280 |
LocalTime to = LocalTime.of(10,0); |
|
281 |
this.vacationDay.setTo(to); |
|
282 |
assertEquals(to, this.vacationDay.getTo()); |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Tests the method {@code setTo} with an input, starting time and vacation vacation type. |
|
287 |
*/ |
|
288 |
@Test |
|
289 |
void setTo_to_from_vacation_valid() { |
|
290 |
this.vacationDay.setType(VacationType.VACATION); |
|
291 |
LocalTime from = LocalTime.of(10, 0); |
|
292 |
this.vacationDay.setFrom(from); |
|
293 |
LocalTime to = LocalTime.of(20,0); |
|
294 |
this.vacationDay.setTo(to); |
|
295 |
assertEquals(to, this.vacationDay.getTo()); |
|
296 |
} |
|
297 |
|
|
298 |
/** |
|
299 |
* Tests the method {@code setTo} with same input and starting time and vacation vacation type. |
|
300 |
*/ |
|
301 |
@Test |
|
302 |
void setTo_to_from_vacation_same() { |
|
303 |
this.vacationDay.setType(VacationType.VACATION); |
|
304 |
LocalTime from = LocalTime.of(10, 0); |
|
305 |
this.vacationDay.setFrom(from); |
|
306 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(from)); |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* Tests the method {@code setTo} with same input and starting time and vacation vacation type. |
|
311 |
*/ |
|
312 |
@Test |
|
313 |
void setTo_to_from_vacation_wrongOrder() { |
|
314 |
this.vacationDay.setType(VacationType.VACATION); |
|
315 |
LocalTime from = LocalTime.of(20, 0); |
|
316 |
this.vacationDay.setFrom(from); |
|
317 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(10,0))); |
|
318 |
} |
|
319 |
|
|
320 |
/** |
|
321 |
* Tests the method {@code setTime} with common values where no problem should occur. |
|
322 |
*/ |
|
323 |
@Test |
|
324 |
void setTime_nullType_valid() { |
|
325 |
LocalTime from = LocalTime.of(10,0); |
|
326 |
LocalTime to = LocalTime.of(20,0); |
|
327 |
this.vacationDay.setTime(from, to); |
|
328 |
assertEquals(from, this.vacationDay.getFrom()); |
|
329 |
assertEquals(to, this.vacationDay.getTo()); |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* Tests the method {@code setTime} with the same times. |
|
334 |
*/ |
|
335 |
@Test |
|
336 |
void setTime_nullType_same() { |
|
337 |
LocalTime from = LocalTime.of(10,0); |
|
338 |
LocalTime to = LocalTime.of(10,0); |
|
339 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to)); |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Tests the method {@code setTime} with later start. |
|
344 |
*/ |
|
345 |
@Test |
|
346 |
void setTime_nullType_wrongOrder() { |
|
347 |
LocalTime from = LocalTime.of(20,0); |
|
348 |
LocalTime to = LocalTime.of(10,0); |
|
349 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to)); |
|
350 |
} |
|
351 |
|
|
352 |
/** |
|
353 |
* Tests the method {@code setTime} with null {@code from} input. |
|
354 |
*/ |
|
355 |
@Test |
|
356 |
void setTime_nullFrom_nullType_valid() { |
|
357 |
LocalTime to = LocalTime.of(10,0); |
|
358 |
this.vacationDay.setTime(null, to); |
|
359 |
assertNull(this.vacationDay.getFrom()); |
|
360 |
assertEquals(to, this.vacationDay.getTo()); |
|
361 |
} |
|
362 |
|
|
363 |
/** |
|
364 |
* Tests the method {@code setTime} with null {@code to} input. |
|
365 |
*/ |
|
366 |
@Test |
|
367 |
void setTime_nullTo_nullType_valid() { |
|
368 |
LocalTime from = LocalTime.of(20,0); |
|
369 |
this.vacationDay.setTime(from, null); |
|
370 |
assertNull(this.vacationDay.getTo()); |
|
371 |
assertEquals(from, this.vacationDay.getFrom()); |
|
372 |
} |
|
373 |
|
|
374 |
/** |
|
375 |
* Tests the method {@code setTime} with null input. |
|
376 |
*/ |
|
377 |
@Test |
|
378 |
void setTime_nullFrom_nullTo_nullType_valid() { |
|
379 |
this.vacationDay.setTime(null, null); |
|
380 |
assertNull(this.vacationDay.getFrom()); |
|
381 |
assertNull(this.vacationDay.getTo()); |
|
382 |
} |
|
383 |
|
|
384 |
/** |
|
385 |
* Tests the method {@code setTime} with null input and sick day vacation type. |
|
386 |
*/ |
|
387 |
@Test |
|
388 |
void setTime_nullFrom_nullTo_sickDay_valid() { |
|
389 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
390 |
this.vacationDay.setTime(null, null); |
|
391 |
assertNull(this.vacationDay.getFrom()); |
|
392 |
assertNull(this.vacationDay.getTo()); |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* Tests the method {@code setTime} with from, null to and sick day vacation type. |
|
397 |
*/ |
|
398 |
@Test |
|
399 |
void setTime_from_nullTo_sickDay() { |
|
400 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
401 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(LocalTime.of(10,0), null)); |
|
402 |
} |
|
403 |
|
|
404 |
/** |
|
405 |
* Tests the method {@code setTime} with null from, to and sick day vacation type. |
|
406 |
*/ |
|
407 |
@Test |
|
408 |
void setTime_nullFrom_to_sickDay() { |
|
409 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
410 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(null, LocalTime.of(10,0))); |
|
411 |
} |
|
412 |
|
|
413 |
/** |
|
414 |
* Tests the method {@code setTime} with from, to and sick day vacation type. |
|
415 |
*/ |
|
416 |
@Test |
|
417 |
void setTime_from_to_sickDay() { |
|
418 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
419 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(LocalTime.of(10,0), LocalTime.of(20,0))); |
|
420 |
} |
|
421 |
|
|
422 |
/** |
|
423 |
* Tests the method {@code setTime} with null input and vacation vacation type. |
|
424 |
*/ |
|
425 |
@Test |
|
426 |
void setTime_nullFrom_nullTo_vacation() { |
|
427 |
this.vacationDay.setType(VacationType.VACATION); |
|
428 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(null, null)); |
|
429 |
} |
|
430 |
|
|
431 |
/** |
|
432 |
* Tests the method {@code setTime} with from, null to and vacation vacation type. |
|
433 |
*/ |
|
434 |
@Test |
|
435 |
void setTime_from_nullTo_vacation() { |
|
436 |
this.vacationDay.setType(VacationType.VACATION); |
|
437 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(LocalTime.of(10,0), null)); |
|
438 |
} |
|
439 |
|
|
440 |
/** |
|
441 |
* Tests the method {@code setTime} with null from, to and vacation vacation type. |
|
442 |
*/ |
|
443 |
@Test |
|
444 |
void setTime_nullFrom_to_vacation() { |
|
445 |
this.vacationDay.setType(VacationType.VACATION); |
|
446 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(null, LocalTime.of(10,0))); |
|
447 |
} |
|
448 |
|
|
449 |
/** |
|
450 |
* Tests the method {@code setTime} with from, to and vacation vacation type. |
|
451 |
*/ |
|
452 |
@Test |
|
453 |
void setTime_from_to_vacation_valid() { |
|
454 |
this.vacationDay.setType(VacationType.VACATION); |
|
455 |
LocalTime from = LocalTime.of(10,0); |
|
456 |
LocalTime to = LocalTime.of(20,0); |
|
457 |
this.vacationDay.setTime(from, to); |
|
458 |
assertEquals(from, this.vacationDay.getFrom()); |
|
459 |
assertEquals(to, this.vacationDay.getTo()); |
|
460 |
} |
|
461 |
|
|
462 |
/** |
|
463 |
* Tests the method {@code setTime} with same from and to and vacation vacation type. |
|
464 |
*/ |
|
465 |
@Test |
|
466 |
void setTime_from_to_vacation_same() { |
|
467 |
this.vacationDay.setType(VacationType.VACATION); |
|
468 |
LocalTime from = LocalTime.of(10,0); |
|
469 |
LocalTime to = LocalTime.of(10,0); |
|
470 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to)); |
|
471 |
} |
|
472 |
|
|
473 |
/** |
|
474 |
* Tests the method {@code setTime} with later from than to and vacation vacation type. |
|
475 |
*/ |
|
476 |
@Test |
|
477 |
void setTime_from_to_vacation_wrongOrder() { |
|
478 |
this.vacationDay.setType(VacationType.VACATION); |
|
479 |
LocalTime from = LocalTime.of(20,0); |
|
480 |
LocalTime to = LocalTime.of(10,0); |
|
481 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to)); |
|
482 |
} |
|
483 |
|
|
484 |
/** |
|
485 |
* Tests the method {@code setStatus} with common values where no problem should occur. |
|
486 |
*/ |
|
487 |
@Test |
|
488 |
void setStatus_valid() { |
|
489 |
this.vacationDay.setStatus(Status.ACCEPTED); |
|
490 |
assertEquals(Status.ACCEPTED, this.vacationDay.getStatus()); |
|
491 |
} |
|
492 |
|
|
493 |
/** |
|
494 |
* Tests the method {@code setStatus} with null value. |
|
495 |
*/ |
|
496 |
@Test |
|
497 |
void setStatus_nullInput() { |
|
498 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setStatus(null)); |
|
499 |
} |
|
500 |
|
|
501 |
/** |
|
502 |
* Tests the method {@code setType} with with vacation input. |
|
503 |
*/ |
|
504 |
@Test |
|
505 |
void setType_valid() { |
|
506 |
this.vacationDay.setType(VacationType.VACATION); |
|
507 |
assertEquals(VacationType.VACATION, this.vacationDay.getType()); |
|
508 |
} |
|
509 |
|
|
510 |
/** |
|
511 |
* Tests the method {@code setType} with sick day input. |
|
512 |
*/ |
|
513 |
@Test |
|
514 |
void setType_sickDay_valid() { |
|
515 |
this.vacationDay.setType(VacationType.SICK_DAY); |
|
516 |
assertEquals(VacationType.SICK_DAY, this.vacationDay.getType()); |
|
517 |
assertNull(this.vacationDay.getFrom()); |
|
518 |
assertNull(this.vacationDay.getTo()); |
|
519 |
} |
|
520 |
|
|
521 |
/** |
|
522 |
* Tests the method {@code setType} with null value. |
|
523 |
*/ |
|
524 |
@Test |
|
525 |
void setType_nullInput() { |
|
526 |
assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setType(null)); |
|
527 |
} |
|
528 |
|
|
529 |
/** |
|
530 |
* Tests the method {@code toString}. |
|
531 |
*/ |
|
532 |
@Test |
|
533 |
void toString_valid() { |
|
534 |
VacationDay vacationDay = new VacationDay(); |
|
535 |
vacationDay.setId(5L); |
|
536 |
vacationDay.setDate(LocalDate.of(2010,1,9)); |
|
537 |
vacationDay.setFrom(LocalTime.of(12,15)); |
|
538 |
vacationDay.setTo(LocalTime.of(22,30)); |
|
539 |
vacationDay.setCreationDate(LocalDateTime.of(2008,10,30,20,0)); |
|
540 |
vacationDay.setStatus(Status.ACCEPTED); |
|
541 |
vacationDay.setType(VacationType.VACATION); |
|
542 |
assertEquals("VacationDay{id=5, date=2010-01-09, from=12:15, to=22:30, creationDate=2008-10-30T20:00, status=ACCEPTED, type=VACATION}", vacationDay.toString()); |
|
543 |
} |
|
544 |
|
|
545 |
/** |
|
546 |
* Tests the method {@code toString} for a sick day. |
|
547 |
*/ |
|
548 |
@Test |
|
549 |
void toString_null() { |
|
550 |
VacationDay vacationDay = new VacationDay(); |
|
551 |
assertEquals("VacationDay{id=null, date=null, from=null, to=null, creationDate=null, status=null, type=null}", vacationDay.toString()); |
|
552 |
} |
|
553 |
} |
server/src/test/java/cz/zcu/yamanager/domain/VacationTest.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.VacationType; |
|
5 |
import org.junit.jupiter.api.BeforeEach; |
|
6 |
import org.junit.jupiter.api.Test; |
|
7 |
|
|
8 |
import java.time.LocalDate; |
|
9 |
import java.time.LocalDateTime; |
|
10 |
import java.time.LocalTime; |
|
11 |
|
|
12 |
import static org.junit.jupiter.api.Assertions.*; |
|
13 |
|
|
14 |
/** |
|
15 |
* This class tests methods of the {@code Vacation} class. |
|
16 |
* @see Vacation |
|
17 |
*/ |
|
18 |
class VacationTest { |
|
19 |
/** |
|
20 |
* The empty instance of the {@code Vacation}. |
|
21 |
*/ |
|
22 |
private Vacation vacation; |
|
23 |
|
|
24 |
/** |
|
25 |
* Prepares the instance of the {@code Vacation}. |
|
26 |
*/ |
|
27 |
@BeforeEach |
|
28 |
void setUp() { |
|
29 |
this.vacation = new Vacation(); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Tests the method {@code setDate} with common values where no problem should occur. |
|
34 |
*/ |
|
35 |
@Test |
|
36 |
void setDate_valid() { |
|
37 |
LocalDate date = LocalDate.of(2000,10,12); |
|
38 |
this.vacation.setDate(date); |
|
39 |
assertEquals(date, this.vacation.getDate()); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* Tests the method {@code setDate} with null input value. |
|
44 |
*/ |
|
45 |
@Test |
|
46 |
void setDate_nullInput() { |
|
47 |
assertThrows(IllegalArgumentException.class, () -> this.vacation.setDate(null)); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* Tests the method {@code setFrom} with a null input, null ending time and null vacation type. |
|
52 |
*/ |
|
53 |
@Test |
|
54 |
void setFrom_nullFrom_nullTo_nullType_valid() { |
|
55 |
this.vacation.setFrom(null); |
|
56 |
assertNull(this.vacation.getFrom()); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Tests the method {@code setFrom} with a null input, ending time and null vacation type. |
|
61 |
*/ |
|
62 |
@Test |
|
63 |
void setFrom_nullFrom_to_nullType_valid() { |
|
64 |
this.vacation.setTo(LocalTime.of(20, 0)); |
|
65 |
this.vacation.setFrom(null); |
|
66 |
assertNull(this.vacation.getFrom()); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Tests the method {@code setFrom} with an input, null ending time and null vacation type. |
|
71 |
*/ |
|
72 |
@Test |
|
73 |
void setFrom_from_nullTo_nullType_valid() { |
|
74 |
LocalTime from = LocalTime.of(10,0); |
|
75 |
this.vacation.setFrom(from); |
|
76 |
assertEquals(from, this.vacation.getFrom()); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Tests the method {@code setFrom} with an input, ending time and null vacation type. |
|
81 |
*/ |
|
82 |
@Test |
|
83 |
void setFrom_from_to_nullType_valid() { |
|
84 |
LocalTime to = LocalTime.of(20, 0); |
|
85 |
this.vacation.setTo(to); |
|
86 |
LocalTime from = LocalTime.of(10,0); |
|
87 |
this.vacation.setFrom(from); |
|
88 |
assertEquals(from, this.vacation.getFrom()); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Tests the method {@code setFrom} with same input and ending time and null vacation type. |
|
93 |
*/ |
|
94 |
@Test |
|
95 |
void setFrom_from_to_nullType_same() { |
|
96 |
LocalTime to = LocalTime.of(10, 0); |
|
97 |
this.vacation.setTo(to); |
|
98 |
assertThrows(IllegalArgumentException.class, () -> this.vacation.setFrom(to)); |
|
99 |
} |
|
100 |
|
Také k dispozici: Unified diff
Cannot take a vacation in past, refactor VacationDay to Vacation in domain package