Revize 6b50e2ca
Přidáno uživatelem Dominik Poch před téměř 6 roky(ů)
server/init.sql | ||
---|---|---|
65 | 65 |
OUT out_no_sick_days INT, |
66 | 66 |
OUT out_taken_sick_days INT, |
67 | 67 |
OUT out_alert DATETIME, |
68 |
OUT out_token TEXT, |
|
68 | 69 |
OUT out_email VARCHAR(100), |
69 | 70 |
OUT out_photo TEXT, |
70 | 71 |
OUT out_creation_date DATETIME, |
... | ... | |
75 | 76 |
DECLARE notification DATETIME; |
76 | 77 |
|
77 | 78 |
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1; |
78 |
SELECT id, first_name, last_name, no_vacations, IFNULL(no_sick_days, sickDaysCount), taken_sick_days, IFNULL(alert, notification), email, photo, creation_date, user_role, status |
|
79 |
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_sick_days, out_alert, out_email, out_photo, out_creation_date, out_role, out_status |
|
79 |
SELECT id, first_name, last_name, no_vacations, IFNULL(no_sick_days, sickDaysCount), taken_sick_days, IFNULL(alert, notification), token, email, photo, creation_date, user_role, status
|
|
80 |
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_sick_days, out_alert, out_token, out_email, out_photo, out_creation_date, out_role, out_status
|
|
80 | 81 |
FROM end_user |
81 | 82 |
WHERE id=in_id; |
82 | 83 |
END $$ |
... | ... | |
91 | 92 |
OUT out_no_sick_days INT, |
92 | 93 |
OUT out_taken_sick_days INT, |
93 | 94 |
OUT out_alert DATETIME, |
95 |
OUT out_token TEXT, |
|
94 | 96 |
OUT out_email VARCHAR(100), |
95 | 97 |
OUT out_photo TEXT, |
96 | 98 |
OUT out_creation_date DATETIME, |
... | ... | |
101 | 103 |
DECLARE notification DATETIME; |
102 | 104 |
|
103 | 105 |
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1; |
104 |
SELECT id, first_name, last_name, no_vacations, IFNULL(no_sick_days, sickDaysCount), taken_sick_days, IFNULL(alert, notification), email, photo, creation_date, user_role, status |
|
105 |
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_sick_days, out_alert, out_email, out_photo, out_creation_date, out_role, out_status |
|
106 |
SELECT id, first_name, last_name, no_vacations, IFNULL(no_sick_days, sickDaysCount), taken_sick_days, IFNULL(alert, notification), token, email, photo, creation_date, user_role, status
|
|
107 |
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_sick_days, out_alert, out_token, out_email, out_photo, out_creation_date, out_role, out_status
|
|
106 | 108 |
FROM end_user |
107 | 109 |
WHERE token=in_token; |
108 | 110 |
END $$ |
... | ... | |
112 | 114 |
-- ----------------------------------------------------- |
113 | 115 |
-- Insert table end_user |
114 | 116 |
-- ----------------------------------------------------- |
115 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('admin', 'admin', 0, NULL, 0, NULL, '', '', '', 'employer', 'accepted');
|
|
116 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('Jan', 'Novák', 0, 10, 0, '2019-12-6 16:30:00.000', '', '', '', 'employee', 'pending');
|
|
117 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('Josef', 'Svoboda', 2, NULL, 3, NULL, '', '', '', 'employee', 'rejected');
|
|
117 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('admin', 'admin', 0, NULL, 0, NULL, '', '', '', 'EMPLOYER', 'ACCEPTED');
|
|
118 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('Jan', 'Novák', 0, 10, 0, '2019-12-6 16:30:00.000', '', '', '', 'EMPLOYEE', 'PENDING');
|
|
119 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES ('Josef', 'Svoboda', 2, NULL, 3, NULL, '', '', '', 'EMPLOYEE', 'REJECTED');
|
|
118 | 120 |
|
119 | 121 |
-- ----------------------------------------------------- |
120 | 122 |
-- Insert table vacation_day |
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.business; |
2 | 2 |
|
3 |
import cz.zcu.yamanager.domain.User; |
|
3 | 4 |
import cz.zcu.yamanager.dto.*; |
4 | 5 |
import cz.zcu.yamanager.repository.RequestRepository; |
5 | 6 |
import cz.zcu.yamanager.repository.UserRepository; |
... | ... | |
28 | 29 |
*/ |
29 | 30 |
private static final Logger log = LoggerFactory.getLogger(UserRepository.class); |
30 | 31 |
|
31 |
private static final int DAYS_IN_WEEK = 7;
|
|
32 |
private static final int WEEK_LENGTH = 7;
|
|
32 | 33 |
|
33 | 34 |
private RequestRepository requestRepository; |
34 | 35 |
private UserRepository userRepository; |
... | ... | |
51 | 52 |
} |
52 | 53 |
|
53 | 54 |
LocalDate today = LocalDate.now(); |
54 |
LocalDate weekBefore = today.minusDays(ApiManager.DAYS_IN_WEEK);
|
|
55 |
LocalDate weekAfter = today.plusDays(ApiManager.DAYS_IN_WEEK);
|
|
55 |
LocalDate weekBefore = today.minusDays(ApiManager.WEEK_LENGTH);
|
|
56 |
LocalDate weekAfter = today.plusDays(ApiManager.WEEK_LENGTH);
|
|
56 | 57 |
for (BasicProfileUser user : users) { |
57 | 58 |
user.setCalendar(this.vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter)); |
58 | 59 |
} |
59 | 60 |
|
60 | 61 |
return users; |
61 |
|
|
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
@Override |
... | ... | |
114 | 114 |
|
115 | 115 |
@Override |
116 | 116 |
public void createSettings(DefaultSettings settings) throws RESTFullException { |
117 |
this.userRepository.insertSettings(settings);
|
|
117 |
this.userRepository.insertSettings(new cz.zcu.yamanager.domain.DefaultSettings(settings.getSickDayCount(), settings.getNotification()));
|
|
118 | 118 |
} |
119 | 119 |
|
120 | 120 |
@Override |
121 | 121 |
public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
122 |
UserRole role = this.userRepository.getUserRole(userId); |
|
123 |
vacationDay.setStatus(role == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING); |
|
122 |
cz.zcu.yamanager.domain.VacationDay vacation = new cz.zcu.yamanager.domain.VacationDay(vacationDay.getDate(), vacationDay.getFrom(), vacationDay.getTo(), vacationDay.getStatus(), vacationDay.getType()); |
|
123 |
|
|
124 |
User user = this.userRepository.getUser(userId); |
|
125 |
vacation.setStatus(user.getRole() == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING); |
|
124 | 126 |
|
125 |
if(vacationDay.getType() == VacationType.VACATION) {
|
|
126 |
this.userRepository.decreaseVacationCount(userId, vacationDay.getFrom().until(vacationDay.getTo(), MINUTES) / 60f);
|
|
127 |
if(vacation.getType() == VacationType.VACATION) { |
|
128 |
user.takeVacation(vacation.getFrom(), vacation.getTo());
|
|
127 | 129 |
} else { |
128 |
this.userRepository.increaseTakenSickdays(userId);
|
|
130 |
user.takeSickDay();
|
|
129 | 131 |
} |
130 | 132 |
|
131 |
this.vacationRepository.insertVacationDay(userId, vacationDay); |
|
133 |
this.vacationRepository.insertVacationDay(userId, vacation); |
|
134 |
this.userRepository.updateUser(user); |
|
132 | 135 |
} |
133 | 136 |
|
134 | 137 |
@Override |
135 | 138 |
public void changeSettings(Long userId, UserSettings settings) throws RESTFullException { |
136 |
settings.setId(userId); |
|
139 |
User user = this.userRepository.getUser(userId); |
|
140 |
|
|
137 | 141 |
if(settings.getRole() == null && settings.getSickDayCount() == null && settings.getVacationCount() == null) { |
138 |
this.userRepository.updateNotification(settings);
|
|
142 |
user.setNotification(settings.getNotification());
|
|
139 | 143 |
} else { |
140 |
this.userRepository.updateUserSettings(settings); |
|
144 |
user.setVacationCount(settings.getVacationCount()); |
|
145 |
user.setTotalSickDayCount(settings.getSickDayCount()); |
|
146 |
user.setRole(settings.getRole()); |
|
141 | 147 |
} |
148 |
|
|
149 |
this.userRepository.updateUser(user); |
|
142 | 150 |
} |
143 | 151 |
|
144 | 152 |
@Override |
145 | 153 |
public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
146 |
this.vacationRepository.updateVacationDay(vacationDay); |
|
154 |
cz.zcu.yamanager.domain.VacationDay vacation = this.vacationRepository.getVacationDay(vacationDay.getId()); |
|
155 |
vacation.setDate(vacationDay.getDate()); |
|
156 |
vacation.setStatus(vacationDay.getStatus()); |
|
157 |
vacation.setType(vacationDay.getType()); |
|
158 |
vacation.setTime(vacationDay.getFrom(), vacationDay.getTo()); |
|
159 |
this.vacationRepository.updateVacationDay(vacation); |
|
147 | 160 |
} |
148 | 161 |
|
149 | 162 |
@Override |
server/src/main/java/cz/zcu/yamanager/business/mock/ManagerMock.java | ||
---|---|---|
47 | 47 |
vacationDay.setStatus(status); |
48 | 48 |
|
49 | 49 |
switch (vacationType) { |
50 |
case SICKDAY: { |
|
50 |
case SICK_DAY: {
|
|
51 | 51 |
vacationDay.setFrom(null); |
52 | 52 |
vacationDay.setTo(null); |
53 | 53 |
} break; |
... | ... | |
72 | 72 |
request.setTimestamp(LocalDateTime.now()); |
73 | 73 |
|
74 | 74 |
switch (vacationType) { |
75 |
case SICKDAY: { |
|
75 |
case SICK_DAY: {
|
|
76 | 76 |
request.setFrom(null); |
77 | 77 |
request.setTo(null); |
78 | 78 |
} break; |
server/src/main/java/cz/zcu/yamanager/domain/DefaultSettings.java | ||
---|---|---|
41 | 41 |
this.id = 0; |
42 | 42 |
} |
43 | 43 |
|
44 |
/** |
|
45 |
* Creates a new default settings with the specified number of available sick days, date and time of a notification. |
|
46 |
* |
|
47 |
* @param sickDayCount the default number of available sick days |
|
48 |
* @param notification the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
|
49 |
* @throws IllegalArgumentException when the given sickDayCount value is negative |
|
50 |
*/ |
|
51 |
public DefaultSettings(final Integer sickDayCount, final LocalDateTime notification) throws IllegalArgumentException { |
|
52 |
this(0, sickDayCount, notification); |
|
53 |
} |
|
54 |
|
|
44 | 55 |
/** |
45 | 56 |
* Creates a new default settings with the specified id, number of available sick days, date and time of a notification. |
46 | 57 |
* |
... | ... | |
49 | 60 |
* @param notification the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
50 | 61 |
* @throws IllegalArgumentException when the given sickDayCount value is negative |
51 | 62 |
*/ |
52 |
public DefaultSettings(final long id, final int sickDayCount, final LocalDateTime notification) throws IllegalArgumentException {
|
|
53 |
DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings.");
|
|
63 |
public DefaultSettings(final long id, final Integer sickDayCount, final LocalDateTime notification) throws IllegalArgumentException {
|
|
64 |
DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings"); |
|
54 | 65 |
DefaultSettings.log.debug("DefaultSettings: id={}, sickDayCount={}, notification={}", id, sickDayCount, notification); |
55 | 66 |
|
56 | 67 |
this.id = id; |
57 | 68 |
this.setSickDayCount(sickDayCount); |
58 |
this.notification = notification;
|
|
69 |
this.setNotification(notification);
|
|
59 | 70 |
} |
60 | 71 |
|
61 | 72 |
/** |
... | ... | |
78 | 89 |
|
79 | 90 |
/** |
80 | 91 |
* Replaces the default number of available sick days in this default settings with the given one. |
81 |
* If the given number is negative the method throws an exception. |
|
92 |
* If the given number is negative or null the method throws an exception.
|
|
82 | 93 |
* |
83 | 94 |
* @param sickDayCount the new default number of available sick days |
84 |
* @throws IllegalArgumentException when the given value is negative |
|
95 |
* @throws IllegalArgumentException when the given value is negative or null
|
|
85 | 96 |
*/ |
86 |
public void setSickDayCount(final int sickDayCount) throws IllegalArgumentException { |
|
87 |
DefaultSettings.log.debug("Setting a new number of available sick days: {}.", sickDayCount); |
|
88 |
|
|
89 |
if (sickDayCount < 0) { |
|
90 |
DefaultSettings.log.warn("The number of available sick days was negative."); |
|
97 |
public void setSickDayCount(final Integer sickDayCount) { |
|
98 |
DefaultSettings.log.debug("Setting a new number of available sick days: {}", sickDayCount); |
|
99 |
|
|
100 |
if (sickDayCount == null) { |
|
101 |
DefaultSettings.log.warn("The given number of available sick days must not be null"); |
|
102 |
throw new IllegalArgumentException("sick.day.null.error"); |
|
103 |
} else if (sickDayCount < 0) { |
|
104 |
DefaultSettings.log.warn("The number of available sick days was negative"); |
|
91 | 105 |
throw new IllegalArgumentException("sick.day.count.error"); |
92 | 106 |
} |
93 | 107 |
|
... | ... | |
105 | 119 |
|
106 | 120 |
/** |
107 | 121 |
* Replaces the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days with the specified one. |
122 |
* If the given notification is null the method throws an exception. |
|
108 | 123 |
* |
109 | 124 |
* @param notification the new default date and time |
125 |
* @throws IllegalArgumentException when the given notification is null |
|
110 | 126 |
*/ |
111 |
public void setNotification(final LocalDateTime notification) { |
|
112 |
DefaultSettings.log.debug("Setting a new default date and time of sending an email warning: {}.", notification); |
|
127 |
public void setNotification(final LocalDateTime notification) throws IllegalArgumentException { |
|
128 |
DefaultSettings.log.debug("Setting a new default date and time of sending an email warning: {}", notification); |
|
129 |
|
|
130 |
if (notification == null) { |
|
131 |
DefaultSettings.log.warn("The notification must not be null"); |
|
132 |
throw new IllegalArgumentException("notification.null.error"); |
|
133 |
} |
|
134 |
|
|
113 | 135 |
this.notification = notification; |
114 | 136 |
} |
115 | 137 |
|
server/src/main/java/cz/zcu/yamanager/domain/User.java | ||
---|---|---|
6 | 6 |
import org.slf4j.LoggerFactory; |
7 | 7 |
|
8 | 8 |
import java.time.LocalDateTime; |
9 |
import java.time.LocalTime; |
|
10 |
|
|
11 |
import static java.time.temporal.ChronoUnit.MINUTES; |
|
9 | 12 |
|
10 | 13 |
/** |
11 | 14 |
* The domain class {@code User} represents a single record in the 'end_user' table of a database. |
... | ... | |
99 | 102 |
public User() { |
100 | 103 |
User.log.trace("Creating a new instance of the class User."); |
101 | 104 |
this.id = 0; |
102 |
this.creationDate = LocalDateTime.now(); |
|
105 |
this.creationDate = null; |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Creates a new user and sets attributes known during an insertion. |
|
110 |
* |
|
111 |
* @param firstName the user's first name |
|
112 |
* @param lastName the user's last name. |
|
113 |
* @param vacationCount the number of user's remaining hours of an overtime |
|
114 |
* @param totalSickDayCount the number of user's sick days available during a year |
|
115 |
* @param takenSickDayCount the number of user's taken sick days |
|
116 |
* @param notification the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
|
117 |
* @param token the token for the Google oAuth |
|
118 |
* @param email the user's email address |
|
119 |
* @param photo the URL of a user's photo |
|
120 |
* @param role the user's role |
|
121 |
* @param status the user's authorization status |
|
122 |
* @throws IllegalArgumentException when the vacationCount, totalSickDayCount or takenSickDayCount are negative or first name, last name or email exceed the maximal permitted number of characters |
|
123 |
*/ |
|
124 |
public User(final String firstName, final String lastName, final Float vacationCount, final Integer totalSickDayCount, final Integer takenSickDayCount, final LocalDateTime notification, final String token, final String email, final String photo, final UserRole role, final Status status) throws IllegalArgumentException { |
|
125 |
this(0, firstName, lastName, vacationCount, totalSickDayCount, takenSickDayCount, notification, token, email, photo, null, role, status); |
|
103 | 126 |
} |
104 | 127 |
|
105 | 128 |
/** |
106 |
* Creates a new user and sets all its attributes.
|
|
129 |
* Creates a new user and sets all his/hers attributes.
|
|
107 | 130 |
* |
108 | 131 |
* @param id the user's ID |
109 | 132 |
* @param firstName the user's first name |
... | ... | |
120 | 143 |
* @param status the user's authorization status |
121 | 144 |
* @throws IllegalArgumentException when the vacationCount, totalSickDayCount or takenSickDayCount are negative or first name, last name or email exceed the maximal permitted number of characters |
122 | 145 |
*/ |
123 |
public User(final long id, final String firstName, final String lastName, final float vacationCount, final int totalSickDayCount, final int takenSickDayCount, final LocalDateTime notification, final String token, final String email, final String photo, final LocalDateTime creationDate, final UserRole role, final Status status) throws IllegalArgumentException {
|
|
146 |
public User(final long id, final String firstName, final String lastName, final Float vacationCount, final Integer totalSickDayCount, final Integer takenSickDayCount, final LocalDateTime notification, final String token, final String email, final String photo, final LocalDateTime creationDate, final UserRole role, final Status status) throws IllegalArgumentException {
|
|
124 | 147 |
User.log.trace("Creating a new instance of the class User."); |
125 | 148 |
User.log.debug("User: id={}, firstName={}, lastName={}, vacationCount={}, totalSickDayCount={}, takenSickDayCount={}, notification={}, token={}, email={}, photo={}, creationDate={}, role={}, status={}", id, firstName, lastName, vacationCount, totalSickDayCount, takenSickDayCount, notification, token, email, photo, creationDate, role, status); |
126 | 149 |
|
... | ... | |
130 | 153 |
this.setVacationCount(vacationCount); |
131 | 154 |
this.setTotalSickDayCount(totalSickDayCount); |
132 | 155 |
this.setTakenSickDayCount(takenSickDayCount); |
133 |
this.notification = notification;
|
|
156 |
this.setNotification(notification);
|
|
134 | 157 |
this.token = token; |
135 | 158 |
this.setEmail(email); |
136 | 159 |
this.photo = photo; |
137 | 160 |
this.creationDate = creationDate; |
138 |
this.role = role;
|
|
139 |
this.status = status;
|
|
161 |
this.setRole(role);
|
|
162 |
this.setStatus(status);
|
|
140 | 163 |
} |
141 | 164 |
|
142 | 165 |
/** |
... | ... | |
168 | 191 |
User.log.debug("Setting a new first name: {}", firstName); |
169 | 192 |
|
170 | 193 |
if (firstName.length() > User.NAME_LENGTH) { |
171 |
User.log.warn("The length of the given first name exceeded the limit.");
|
|
194 |
User.log.warn("The length of the given first name exceeded a limit");
|
|
172 | 195 |
throw new IllegalArgumentException("name.length.error"); |
173 | 196 |
} |
174 | 197 |
|
... | ... | |
195 | 218 |
User.log.debug("Setting a new last name: {}", lastName); |
196 | 219 |
|
197 | 220 |
if (lastName.length() > User.NAME_LENGTH) { |
198 |
User.log.warn("The length of the given last name exceeded the limit.");
|
|
221 |
User.log.warn("The length of the given last name exceeded a limit");
|
|
199 | 222 |
throw new IllegalArgumentException("name.length.error"); |
200 | 223 |
} |
201 | 224 |
|
... | ... | |
213 | 236 |
|
214 | 237 |
/** |
215 | 238 |
* Replaces the number of user's remaining hours of an overtime with the specified value. |
216 |
* If the given number is negative the method throws an exception. |
|
239 |
* If the given number is negative or null the method throws an exception.
|
|
217 | 240 |
* |
218 | 241 |
* @param vacationCount the new number of remaining hours of the overtime. |
219 | 242 |
* @throws IllegalArgumentException when the given value is negative |
220 | 243 |
*/ |
221 |
public void setVacationCount(final float vacationCount) throws IllegalArgumentException {
|
|
244 |
public void setVacationCount(final Float vacationCount) throws IllegalArgumentException {
|
|
222 | 245 |
User.log.debug("Setting a new number of remaining overtime: {}", vacationCount); |
223 | 246 |
|
224 |
if (vacationCount < 0) { |
|
225 |
User.log.warn("The given number of remaining overtime must not be negative."); |
|
226 |
throw new IllegalArgumentException("vacation.count.error"); |
|
247 |
if(vacationCount == null) { |
|
248 |
User.log.warn("The number of remaining overtime must not be null"); |
|
249 |
throw new IllegalArgumentException("vacation.null.error"); |
|
250 |
}else if (vacationCount < 0) { |
|
251 |
User.log.warn("The number of remaining overtime must not be negative"); |
|
252 |
throw new IllegalArgumentException("negative.vacation.error"); |
|
227 | 253 |
} |
228 | 254 |
|
229 | 255 |
this.vacationCount = vacationCount; |
230 | 256 |
} |
231 | 257 |
|
232 |
/** |
|
233 |
* Increases the number of user's remaining hours of an overtime by the given amount. |
|
234 |
* |
|
235 |
* @param amount the amount of hours |
|
236 |
*/ |
|
237 |
public void increaseVacationCount(final float amount) { |
|
238 |
User.log.debug("Increasing the number of remaining overtime by {}", amount); |
|
239 |
this.vacationCount += amount; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Decreases the number of user's remaining hours of an overtime by the given amount. |
|
244 |
* If the new number of remaining hours is below zero the method throws an exception. |
|
245 |
* |
|
246 |
* @param amount the amount of hours |
|
247 |
* @throws IllegalArgumentException when the result of the subtraction is negative |
|
248 |
*/ |
|
249 |
public void decreaseVacationCount(final float amount) throws IllegalArgumentException { |
|
250 |
User.log.debug("Decreasing the number of remaining overtime by {}", amount); |
|
251 |
|
|
252 |
if (this.vacationCount - amount < 0) { |
|
253 |
User.log.warn("The result of the decrease must not be negative."); |
|
254 |
throw new IllegalArgumentException("vacation.count.error"); |
|
255 |
} |
|
256 |
|
|
257 |
this.vacationCount -= amount; |
|
258 |
} |
|
259 |
|
|
260 | 258 |
/** |
261 | 259 |
* Returns the number of user's sick days available during a year. |
262 | 260 |
* |
... | ... | |
268 | 266 |
|
269 | 267 |
/** |
270 | 268 |
* Replaces the number of user's sick days available during a year with the new value. |
271 |
* If the given number is negative the method throws an exception. |
|
269 |
* If the given number is negative or null the method throws an exception.
|
|
272 | 270 |
* |
273 | 271 |
* @param totalSickDayCount the new number of sick days available during the year |
274 | 272 |
* @throws IllegalArgumentException when the given value is negative |
275 | 273 |
*/ |
276 |
public void setTotalSickDayCount(final int totalSickDayCount) throws IllegalArgumentException {
|
|
274 |
public void setTotalSickDayCount(final Integer totalSickDayCount) throws IllegalArgumentException {
|
|
277 | 275 |
User.log.debug("Setting a new number of user's sick days available during a year: {}", totalSickDayCount); |
278 | 276 |
|
279 |
if (totalSickDayCount < 0) { |
|
280 |
User.log.warn("The given number of user's sick days available during a year must not be negative."); |
|
281 |
throw new IllegalArgumentException("sick.day.count.error"); |
|
277 |
if (totalSickDayCount == null) { |
|
278 |
User.log.warn("The number of user's available sick days must not be null"); |
|
279 |
throw new IllegalArgumentException("sick.day.null.error"); |
|
280 |
} else if (totalSickDayCount < 0) { |
|
281 |
User.log.warn("The number of user's available sick days must not be negative"); |
|
282 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
282 | 283 |
} |
283 | 284 |
|
284 | 285 |
this.totalSickDayCount = totalSickDayCount; |
... | ... | |
295 | 296 |
|
296 | 297 |
/** |
297 | 298 |
* Replaces the number of user's taken sick days with the new value. |
298 |
* If the given number is negative the method throws an exception. |
|
299 |
* If the given number is negative or greater than the number of available sick days or null the method throws an exception.
|
|
299 | 300 |
* |
300 | 301 |
* @param takenSickDayCount the new number of taken sick days |
301 | 302 |
* @throws IllegalArgumentException when the given value is negative |
302 | 303 |
*/ |
303 |
public void setTakenSickDayCount(final int takenSickDayCount) throws IllegalArgumentException {
|
|
304 |
public void setTakenSickDayCount(final Integer takenSickDayCount) throws IllegalArgumentException {
|
|
304 | 305 |
User.log.debug("Setting a new number of user's taken sick days: {}", takenSickDayCount); |
305 | 306 |
|
306 |
if (takenSickDayCount < 0) { |
|
307 |
User.log.warn("The given number number of user's taken sick days must not be negative."); |
|
308 |
throw new IllegalArgumentException("sick.day.count.error"); |
|
307 |
if (takenSickDayCount == null) { |
|
308 |
User.log.warn("The number number of user's taken sick days must not be null"); |
|
309 |
throw new IllegalArgumentException("sick.day.null.error"); |
|
310 |
} else if (takenSickDayCount < 0) { |
|
311 |
User.log.warn("The number number of user's taken sick days must not be negative"); |
|
312 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
313 |
} else if(takenSickDayCount > this.totalSickDayCount){ |
|
314 |
User.log.warn("The number number of user's taken sick days must not greater than his/her available sick days"); |
|
315 |
throw new IllegalArgumentException("taken.sick.day.count.error"); |
|
309 | 316 |
} |
310 | 317 |
|
311 | 318 |
this.takenSickDayCount = takenSickDayCount; |
... | ... | |
322 | 329 |
|
323 | 330 |
/** |
324 | 331 |
* Replaces the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days with the given value. |
332 |
* If the given notification is null the method throws an exception. |
|
325 | 333 |
* |
326 | 334 |
* @param notification the new date and time |
335 |
* @throws IllegalArgumentException when the given notification is null |
|
327 | 336 |
*/ |
328 |
public void setNotification(final LocalDateTime notification) { |
|
337 |
public void setNotification(final LocalDateTime notification) throws IllegalArgumentException {
|
|
329 | 338 |
User.log.debug("Setting a new date and time of sending an email warning: {}", notification); |
339 |
|
|
340 |
if(notification == null) { |
|
341 |
User.log.warn("The given notification must not be null"); |
|
342 |
throw new IllegalArgumentException("notification.null.error"); |
|
343 |
} |
|
344 |
|
|
330 | 345 |
this.notification = notification; |
331 | 346 |
} |
332 | 347 |
|
... | ... | |
369 | 384 |
User.log.debug("Setting a new email address: {}", email); |
370 | 385 |
|
371 | 386 |
if (email.length() > User.EMAIL_ADDRESS_LENGTH) { |
372 |
User.log.warn("The length of the email address exceeded the limit.");
|
|
387 |
User.log.warn("The length of the email address exceeded a limit");
|
|
373 | 388 |
throw new IllegalArgumentException("email.length.error"); |
374 | 389 |
} |
375 | 390 |
|
... | ... | |
415 | 430 |
|
416 | 431 |
/** |
417 | 432 |
* Replaces the user's role with the new provided value. |
433 |
* If the given role is null the method throws an exception. |
|
418 | 434 |
* |
419 | 435 |
* @param role the new role |
436 |
* @throws IllegalArgumentException when the given role is null |
|
420 | 437 |
*/ |
421 |
public void setRole(final UserRole role) { |
|
438 |
public void setRole(final UserRole role) throws IllegalArgumentException {
|
|
422 | 439 |
User.log.debug("Setting a new user's role: {}", role); |
440 |
|
|
441 |
if(role == null) { |
|
442 |
User.log.warn("The given role must not be null"); |
|
443 |
throw new IllegalArgumentException("role.null.error"); |
|
444 |
} |
|
445 |
|
|
423 | 446 |
this.role = role; |
424 | 447 |
} |
425 | 448 |
|
... | ... | |
439 | 462 |
*/ |
440 | 463 |
public void setStatus(final Status status) { |
441 | 464 |
User.log.debug("Setting a new authorization status: {}", status); |
465 |
|
|
466 |
if(status == null) { |
|
467 |
User.log.warn("The given status must not be null"); |
|
468 |
throw new IllegalArgumentException("status.null.error"); |
|
469 |
} |
|
470 |
|
|
442 | 471 |
this.status = status; |
443 | 472 |
} |
444 | 473 |
|
474 |
/** |
|
475 |
* Subtracts a difference of the given starting and the ending time of a vacation |
|
476 |
* from the number of user's available vacations. If some of the given parameters are null |
|
477 |
* or the times are not in order or there is no available vacation left the method throws an exception. |
|
478 |
* |
|
479 |
* @param from the starting time of a vacation |
|
480 |
* @param to the ending time of a vacation |
|
481 |
* @throws IllegalArgumentException when some of the given parameters are null |
|
482 |
* or the times are not in order or there is no available vacation left |
|
483 |
*/ |
|
484 |
public void takeVacation(final LocalTime from, final LocalTime to) throws IllegalArgumentException{ |
|
485 |
User.log.debug("Taking a vacation from {} to {}", from, to); |
|
486 |
|
|
487 |
if(from == null || to == null) { |
|
488 |
User.log.warn("A vacation has to have a starting and an ending time"); |
|
489 |
throw new IllegalArgumentException("time.vacation.error"); |
|
490 |
} else if (from.compareTo(to) >= 0) { |
|
491 |
User.log.warn("A vacation must not start after it ends. from={}, to={}", from, to); |
|
492 |
throw new IllegalArgumentException("time.order.error"); |
|
493 |
} |
|
494 |
|
|
495 |
final float difference = from.until(to, MINUTES) / 60f; |
|
496 |
final float tempVacationCount = this.vacationCount - difference; |
|
497 |
|
|
498 |
if (tempVacationCount < 0) { |
|
499 |
User.log.warn("Cannot take a vacation, not enough available hours"); |
|
500 |
throw new IllegalArgumentException("available.vacation.error"); |
|
501 |
} |
|
502 |
|
|
503 |
this.vacationCount = tempVacationCount; |
|
504 |
} |
|
505 |
|
|
506 |
/** |
|
507 |
* Increases the number of taken sick days by one unless there are not any available sick days left. In that case |
|
508 |
* the method throws and exception. |
|
509 |
* |
|
510 |
* @throws IllegalArgumentException when there is not any available sick days left |
|
511 |
*/ |
|
512 |
public void takeSickDay() throws IllegalArgumentException { |
|
513 |
User.log.trace("Taking a sick day"); |
|
514 |
final int tempTakenSickDayCount = ++this.takenSickDayCount; |
|
515 |
|
|
516 |
if (tempTakenSickDayCount > this.totalSickDayCount) { |
|
517 |
User.log.warn("Cannot take a sick day, not enough available days"); |
|
518 |
throw new IllegalArgumentException("available.sick.day.error"); |
|
519 |
} |
|
520 |
|
|
521 |
this.takenSickDayCount = tempTakenSickDayCount; |
|
522 |
} |
|
523 |
|
|
445 | 524 |
/** |
446 | 525 |
* Gets a string representation of this user. The representation contains the id, first name, last name, |
447 | 526 |
* number of user's remaining hours of an overtime, number of user's sick days available during a year, |
server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java | ||
---|---|---|
23 | 23 |
/** |
24 | 24 |
* The ID of this vacation. |
25 | 25 |
*/ |
26 |
private final int id;
|
|
26 |
private final long id;
|
|
27 | 27 |
|
28 | 28 |
/** |
29 | 29 |
* The date of this vacation. |
... | ... | |
73 | 73 |
* @param creationDate the date and time of the creation of the sick day |
74 | 74 |
* @param status the approval status of the sick day |
75 | 75 |
*/ |
76 |
public VacationDay(final int id, final LocalDate date, final LocalDateTime creationDate, final Status status) {
|
|
77 |
this(id, date, null, null, creationDate, status, VacationType.SICKDAY); |
|
76 |
public VacationDay(final long id, final LocalDate date, final LocalDateTime creationDate, final Status status) {
|
|
77 |
this(id, date, null, null, creationDate, status, VacationType.SICK_DAY);
|
|
78 | 78 |
} |
79 | 79 |
|
80 | 80 |
/** |
... | ... | |
87 | 87 |
* @param creationDate the date and time of the creation of the overtime |
88 | 88 |
* @param status the approval status of the overtime |
89 | 89 |
*/ |
90 |
public VacationDay(final int id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status) {
|
|
90 |
public VacationDay(final long id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status) {
|
|
91 | 91 |
this(id, date, from, to, creationDate, status, VacationType.VACATION); |
92 | 92 |
} |
93 | 93 |
|
94 |
/** |
|
95 |
* Creates a new overtime or sick day with attributes known during insertion. |
|
96 |
* |
|
97 |
* @param date the date of a vacation |
|
98 |
* @param from the starting time of a vacation |
|
99 |
* @param to the ending time of a vacation |
|
100 |
* @param status the approval status of a vacation |
|
101 |
* @param type the type of a vacation |
|
102 |
*/ |
|
103 |
public VacationDay(final LocalDate date, final LocalTime from, final LocalTime to, final Status status, final VacationType type) { |
|
104 |
this(0, date, from, to, null, status, type); |
|
105 |
} |
|
106 |
|
|
94 | 107 |
/** |
95 | 108 |
* Creates a new overtime or sick day with all attributes. |
96 | 109 |
* |
... | ... | |
102 | 115 |
* @param status the approval status of a vacation |
103 | 116 |
* @param type the type of a vacation |
104 | 117 |
*/ |
105 |
private VacationDay(final int id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status, final VacationType type) {
|
|
118 |
public VacationDay(final long id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status, final VacationType type) {
|
|
106 | 119 |
VacationDay.log.trace("Creating a new instance of the class VacationDay."); |
107 | 120 |
VacationDay.log.debug("VacationDay: id={}, date={}, from={}, to={}, creationDate={}, status={}, type={}", id, date, from, to, creationDate, status, type); |
108 | 121 |
|
109 | 122 |
this.id = id; |
110 |
this.date = date; |
|
123 |
this.setDate(date); |
|
124 |
this.setType(type); |
|
111 | 125 |
this.setTime(from, to); |
112 | 126 |
this.creationDate = creationDate; |
113 |
this.status = status; |
|
114 |
this.type = type; |
|
127 |
this.setStatus(status); |
|
115 | 128 |
} |
116 | 129 |
|
117 | 130 |
/** |
... | ... | |
119 | 132 |
* |
120 | 133 |
* @return the ID of this vacation |
121 | 134 |
*/ |
122 |
public int getId() {
|
|
135 |
public long getId() {
|
|
123 | 136 |
return this.id; |
124 | 137 |
} |
125 | 138 |
|
... | ... | |
134 | 147 |
|
135 | 148 |
/** |
136 | 149 |
* Replaces the date of this vacation with the specified date. |
150 |
* If the given date is null the method throws an exception. |
|
137 | 151 |
* |
138 | 152 |
* @param date the new date |
153 |
* @throws IllegalArgumentException when the given date is null |
|
139 | 154 |
*/ |
140 |
public void setDate(final LocalDate date) { |
|
155 |
public void setDate(final LocalDate date) throws IllegalArgumentException {
|
|
141 | 156 |
VacationDay.log.debug("Settings a new value of a date: {}", date); |
157 |
|
|
158 |
if (date == null) { |
|
159 |
VacationDay.log.warn("The given date must not be null."); |
|
160 |
throw new IllegalArgumentException("date.null.error"); |
|
161 |
} |
|
162 |
|
|
142 | 163 |
this.date = date; |
143 | 164 |
} |
144 | 165 |
|
... | ... | |
161 | 182 |
public void setFrom(final LocalTime from) throws IllegalArgumentException { |
162 | 183 |
VacationDay.log.debug("Settings a new value of the starting time of this vacation: {}", from); |
163 | 184 |
|
164 |
if (from != null && this.to != null && from.compareTo(this.to) >= 0) { |
|
165 |
VacationDay.log.warn("The vacation must not start after it ends. from={}, to={}", from, this.to); |
|
185 |
if (from != null && this.type == VacationType.SICK_DAY) { |
|
186 |
VacationDay.log.warn("A sick day must not have a starting or an ending time"); |
|
187 |
throw new IllegalArgumentException("time.sick.day.error"); |
|
188 |
} else if(from == null && this.type == VacationType.VACATION) { |
|
189 |
VacationDay.log.warn("A vacation has to have a starting and an ending time"); |
|
190 |
throw new IllegalArgumentException("time.vacation.error"); |
|
191 |
} else if (from != null && this.to != null && from.compareTo(this.to) >= 0) { |
|
192 |
VacationDay.log.warn("A vacation must not start after it ends. from={}, to={}", from, this.to); |
|
166 | 193 |
throw new IllegalArgumentException("time.order.error"); |
167 | 194 |
} |
168 | 195 |
|
... | ... | |
188 | 215 |
public void setTo(final LocalTime to) throws IllegalArgumentException { |
189 | 216 |
VacationDay.log.debug("Settings a new value of the ending time of this vacation: {}", to); |
190 | 217 |
|
191 |
if (to != null && this.from != null && to.compareTo(this.from) <= 0) { |
|
192 |
VacationDay.log.warn("The vacation must not end after it starts. from={}, to={}", this.from, to); |
|
218 |
if (to != null && this.type == VacationType.SICK_DAY) { |
|
219 |
VacationDay.log.warn("A sick day must not have a starting or an ending time"); |
|
220 |
throw new IllegalArgumentException("time.sick_day.error"); |
|
221 |
} else if(to == null && this.type == VacationType.VACATION) { |
|
222 |
VacationDay.log.warn("A vacation has to have a starting and an ending time"); |
|
223 |
throw new IllegalArgumentException("time.vacation.error"); |
|
224 |
} else if (to != null && this.from != null && to.compareTo(this.from) <= 0) { |
|
225 |
VacationDay.log.warn("A vacation must not end after it starts. from={}, to={}", this.from, to); |
|
193 | 226 |
throw new IllegalArgumentException("time.order.error"); |
194 | 227 |
} |
195 | 228 |
|
... | ... | |
207 | 240 |
public void setTime(final LocalTime from, final LocalTime to) throws IllegalArgumentException { |
208 | 241 |
VacationDay.log.debug("Settings a new value of the starting {} and the ending {} time of this vacation.", from, to); |
209 | 242 |
|
210 |
if (from != null && to != null && from.compareTo(to) >= 0) { |
|
211 |
VacationDay.log.warn("The vacation must not start after it ends. from={}, to={}", from, to); |
|
243 |
if ((from != null || to != null) && this.type == VacationType.SICK_DAY) { |
|
244 |
VacationDay.log.warn("A sick day must not have a starting or an ending time"); |
|
245 |
throw new IllegalArgumentException("time.sick.day_error"); |
|
246 |
} else if((from == null || to == null) && this.type == VacationType.VACATION) { |
|
247 |
VacationDay.log.warn("A vacation has to have a starting and an ending time"); |
|
248 |
throw new IllegalArgumentException("time.vacation.error"); |
|
249 |
} else if (from != null && to != null && from.compareTo(to) >= 0) { |
|
250 |
VacationDay.log.warn("A vacation must not start after it ends. from={}, to={}", from, to); |
|
212 | 251 |
throw new IllegalArgumentException("time.order.error"); |
213 | 252 |
} |
214 | 253 |
|
... | ... | |
236 | 275 |
|
237 | 276 |
/** |
238 | 277 |
* Replaces the approval status of this vacation with the given value. |
278 |
* If the given status is null the method throws an exception. |
|
239 | 279 |
* |
240 | 280 |
* @param status the new approval status |
281 |
* @throws IllegalArgumentException when the given status is null |
|
241 | 282 |
*/ |
242 |
public void setStatus(final Status status) { |
|
283 |
public void setStatus(final Status status) throws IllegalArgumentException {
|
|
243 | 284 |
VacationDay.log.debug("Setting a new approval status: {}", status); |
285 |
|
|
286 |
if (status == null) { |
|
287 |
VacationDay.log.warn("The given status must not be null"); |
|
288 |
throw new IllegalArgumentException("status.null.error"); |
|
289 |
} |
|
290 |
|
|
244 | 291 |
this.status = status; |
245 | 292 |
} |
246 | 293 |
|
... | ... | |
255 | 302 |
|
256 | 303 |
/** |
257 | 304 |
* Replaces the type of this vacation with the handed type. |
258 |
* If the given type is a SICKDAY the method sets the starting and the ending time to null. |
|
305 |
* If the given type is SICK_DAY the method sets the starting and the ending time to null. |
|
306 |
* If the given type is null the method throws an exception. |
|
259 | 307 |
* |
260 | 308 |
* @param type the new type |
309 |
* @throws IllegalArgumentException when the given type is null |
|
261 | 310 |
*/ |
262 |
public void setType(final VacationType type) { |
|
311 |
public void setType(final VacationType type) throws IllegalArgumentException {
|
|
263 | 312 |
VacationDay.log.debug("Setting a new type of this vacation: {}", type); |
313 |
|
|
314 |
if(type == VacationType.SICK_DAY) { |
|
315 |
this.from = null; |
|
316 |
this.to = null; |
|
317 |
} else if (type == null) { |
|
318 |
VacationDay.log.warn("The given type of a vacation must not be null"); |
|
319 |
throw new IllegalArgumentException("type.null.error"); |
|
320 |
} |
|
321 |
|
|
264 | 322 |
this.type = type; |
265 | 323 |
} |
266 | 324 |
|
server/src/main/java/cz/zcu/yamanager/dto/VacationType.java | ||
---|---|---|
7 | 7 |
/** |
8 | 8 |
* The vacation represents a sick day. |
9 | 9 |
*/ |
10 |
SICKDAY, |
|
10 |
SICK_DAY,
|
|
11 | 11 |
|
12 | 12 |
/** |
13 | 13 |
* The vacation represents an overtime. |
server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java | ||
---|---|---|
112 | 112 |
this.updateAuthorization(request.getId(), request.getStatus()); |
113 | 113 |
} |
114 | 114 |
|
115 |
/** |
|
116 |
* Updates the status of an authorization request from the given AuthorizationRequest object. |
|
117 |
* |
|
118 |
* @param request the AuthorizationRequest object with new values of the authorization request |
|
119 |
*/ |
|
120 |
public void updateAuthorization(final AuthorizationRequest request) { |
|
121 |
this.updateAuthorization(request.getId(), request.getStatus()); |
|
122 |
} |
|
123 |
|
|
124 | 115 |
/** |
125 | 116 |
* Gets all vacation requests from a database. Method returns all vacation requests despite |
126 | 117 |
* its authorization status. It returns accepted, pending even rejected vacations. |
... | ... | |
231 | 222 |
public void updateVacationRequest(final BasicRequest request) { |
232 | 223 |
this.updateVacationRequest(request.getId(), request.getStatus()); |
233 | 224 |
} |
234 |
|
|
235 |
/** |
|
236 |
* Updates a status of a vacation request from a VacationRequest object. |
|
237 |
* |
|
238 |
* @param request the VacationRequest object with new values of the vacation request |
|
239 |
*/ |
|
240 |
public void updateVacationRequest(final VacationRequest request) { |
|
241 |
this.updateAuthorization(request.getId(), request.getStatus()); |
|
242 |
} |
|
243 | 225 |
} |
server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.repository; |
2 | 2 |
|
3 |
import cz.zcu.yamanager.domain.User; |
|
3 | 4 |
import cz.zcu.yamanager.dto.*; |
4 | 5 |
import org.slf4j.Logger; |
5 | 6 |
import org.slf4j.LoggerFactory; |
... | ... | |
40 | 41 |
this.jdbc = jdbc; |
41 | 42 |
} |
42 | 43 |
|
44 |
private Map<String, Object> getUserColumns(final long id) { |
|
45 |
final List<SqlParameter> paramList = new ArrayList<>(); |
|
46 |
paramList.add(new SqlParameter("in_id", Types.BIGINT)); |
|
47 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
48 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
49 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
50 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
51 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
52 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
53 |
paramList.add(new SqlOutParameter("out_alert", Types.TIMESTAMP)); |
|
54 |
paramList.add(new SqlOutParameter("out_token", Types.LONGVARCHAR)); |
|
55 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
56 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
57 |
paramList.add(new SqlOutParameter("out_creation_date", Types.TIMESTAMP)); |
|
58 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
59 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
60 |
|
|
61 |
return jdbc.call(con -> { |
|
62 |
final CallableStatement callableStatement = con.prepareCall("{call GetUserId(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); |
|
63 |
callableStatement.setLong(1, id); |
|
64 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
65 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
66 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
67 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
68 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
69 |
callableStatement.registerOutParameter(7, Types.INTEGER); |
|
70 |
callableStatement.registerOutParameter(8, Types.TIMESTAMP); |
|
71 |
callableStatement.registerOutParameter(9, Types.LONGVARCHAR); |
|
72 |
callableStatement.registerOutParameter(10, Types.VARCHAR); |
|
73 |
callableStatement.registerOutParameter(11, Types.LONGVARCHAR); |
|
74 |
callableStatement.registerOutParameter(12, Types.TIMESTAMP); |
|
75 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
76 |
callableStatement.registerOutParameter(14, Types.VARCHAR); |
|
77 |
return callableStatement; |
|
78 |
}, paramList); |
|
79 |
} |
|
80 |
|
|
81 |
private Map<String, Object> getUserColumns(final String token) { |
|
82 |
final List<SqlParameter> paramList = new ArrayList<>(); |
|
83 |
paramList.add(new SqlParameter(Types.LONGVARCHAR)); |
|
84 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
85 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
86 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
87 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
88 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
89 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
90 |
paramList.add(new SqlOutParameter("out_alert", Types.TIMESTAMP)); |
|
91 |
paramList.add(new SqlOutParameter("out_token", Types.LONGVARCHAR)); |
|
92 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
93 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
94 |
paramList.add(new SqlOutParameter("out_creation_date", Types.TIMESTAMP)); |
|
95 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
96 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
97 |
|
|
98 |
return jdbc.call(con -> { |
|
99 |
final CallableStatement callableStatement = con.prepareCall("{call GetUserToken(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); |
|
100 |
callableStatement.setString(1, token); |
|
101 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
102 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
103 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
104 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
105 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
106 |
callableStatement.registerOutParameter(7, Types.INTEGER); |
|
107 |
callableStatement.registerOutParameter(8, Types.TIMESTAMP); |
|
108 |
callableStatement.registerOutParameter(9, Types.LONGVARCHAR); |
|
109 |
callableStatement.registerOutParameter(10, Types.VARCHAR); |
|
110 |
callableStatement.registerOutParameter(11, Types.LONGVARCHAR); |
|
111 |
callableStatement.registerOutParameter(12, Types.TIMESTAMP); |
|
112 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
113 |
callableStatement.registerOutParameter(14, Types.VARCHAR); |
|
114 |
return callableStatement; |
|
115 |
}, paramList); |
|
116 |
} |
|
117 |
|
|
118 |
//---------------------------------- DTO ----------------------------------- |
|
119 |
|
|
43 | 120 |
/** |
44 | 121 |
* Gets basic profile of each user from a database. The basic profile contains default, the most important |
45 | 122 |
* informations which helps identify a user like a name or photo. Every line of output is converted to a BasicProfileUser |
... | ... | |
90 | 167 |
* @return |
91 | 168 |
*/ |
92 | 169 |
public FullUserProfile getFullUser(final long id) { |
93 |
UserRepository.log.trace("Selecting full profiles of a user with a specified id from a database "); |
|
94 |
UserRepository.log.debug("Id: {}", id); |
|
95 |
|
|
96 |
final List<SqlParameter> paramList = new ArrayList<>(); |
|
97 |
paramList.add(new SqlParameter("in_id", Types.BIGINT)); |
|
98 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
99 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
100 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
101 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
102 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
103 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
104 |
paramList.add(new SqlOutParameter("out_alert", Types.TIMESTAMP)); |
|
105 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
106 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
107 |
paramList.add(new SqlOutParameter("out_creation_date", Types.TIMESTAMP)); |
|
108 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
109 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
170 |
UserRepository.log.debug("Selecting full profile of a user with the specified id from a database: {}", id); |
|
110 | 171 |
|
111 |
final Map<String, Object> resultMap = jdbc.call(con -> { |
|
112 |
final CallableStatement callableStatement = con.prepareCall("{call GetUserId(?,?,?,?,?,?,?,?,?,?,?,?,?)}"); |
|
113 |
callableStatement.setLong(1, id); |
|
114 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
115 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
116 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
117 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
118 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
119 |
callableStatement.registerOutParameter(7, Types.INTEGER); |
|
120 |
callableStatement.registerOutParameter(8, Types.TIMESTAMP); |
|
121 |
callableStatement.registerOutParameter(9, Types.VARCHAR); |
|
122 |
callableStatement.registerOutParameter(10, Types.LONGNVARCHAR); |
|
123 |
callableStatement.registerOutParameter(11, Types.TIMESTAMP); |
|
124 |
callableStatement.registerOutParameter(12, Types.VARCHAR); |
|
125 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
126 |
return callableStatement; |
|
127 |
}, paramList); |
|
172 |
final Map<String, Object> resultMap = this.getUserColumns(id); |
|
128 | 173 |
|
129 | 174 |
final FullUserProfile user = new FullUserProfile(); |
130 | 175 |
user.setId(id); |
... | ... | |
134 | 179 |
user.setSickDayCount((Integer) resultMap.get("out_no_sick_days")); |
135 | 180 |
user.setTakenSickDayCount((Integer) resultMap.get("out_taken_sick_days")); |
136 | 181 |
user.setNotification(((Timestamp) resultMap.get("out_alert")).toLocalDateTime()); |
137 |
user.setEmail((String) resultMap.get(("out_email")));
|
|
182 |
user.setEmail((String) resultMap.get("out_email"));
|
|
138 | 183 |
user.setPhoto((String) resultMap.get("out_photo")); |
139 | 184 |
user.setRole(UserRole.getUserRole((String) resultMap.get("out_role"))); |
140 | 185 |
user.setStatus(Status.getStatus((String) resultMap.get("out_status"))); |
... | ... | |
142 | 187 |
|
143 | 188 |
} |
144 | 189 |
|
145 |
public UserRole getUserRole(final long id) { |
|
146 |
return this.jdbc.queryForObject("SELECT user_role FROM end_user WHERE id = ?", new Object[]{id}, (ResultSet rs, int rowNum) -> UserRole.getUserRole(rs.getString("status"))); |
|
147 |
} |
|
148 |
|
|
149 |
public Status getUserStatus(final long id) { |
|
150 |
return this.jdbc.queryForObject("SELECT status FROM end_user WHERE id = ?", new Object[]{id}, (ResultSet rs, int rowNum) -> Status.getStatus(rs.getString("status"))); |
|
151 |
} |
|
152 |
|
|
153 | 190 |
public FullUserProfile getFullUser(final String token) { |
154 |
final List<SqlParameter> paramList = new ArrayList<>(); |
|
155 |
paramList.add(new SqlParameter(Types.LONGNVARCHAR)); |
|
156 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
157 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
158 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
159 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
160 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
161 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
162 |
paramList.add(new SqlOutParameter("out_alert", Types.TIMESTAMP)); |
|
163 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
164 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
165 |
paramList.add(new SqlOutParameter("out_creation_date", Types.TIMESTAMP)); |
|
166 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
167 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
191 |
UserRepository.log.trace("Selecting full profile of a user with the specified token from a database: {}", token); |
|
168 | 192 |
|
169 |
final Map<String, Object> resultMap = jdbc.call(con -> { |
|
170 |
final CallableStatement callableStatement = con.prepareCall("{call GetUserToken(?,?,?,?,?,?,?,?,?,?,?,?,?)}"); |
|
171 |
callableStatement.setString(1, token); |
|
172 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
173 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
174 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
175 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
176 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
177 |
callableStatement.registerOutParameter(7, Types.INTEGER); |
|
178 |
callableStatement.registerOutParameter(8, Types.TIMESTAMP); |
|
179 |
callableStatement.registerOutParameter(9, Types.VARCHAR); |
|
180 |
callableStatement.registerOutParameter(10, Types.LONGNVARCHAR); |
|
181 |
callableStatement.registerOutParameter(11, Types.TIMESTAMP); |
|
182 |
callableStatement.registerOutParameter(12, Types.VARCHAR); |
|
183 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
184 |
return callableStatement; |
|
185 |
}, paramList); |
|
193 |
final Map<String, Object> resultMap = this.getUserColumns(token); |
|
186 | 194 |
|
187 | 195 |
final FullUserProfile user = new FullUserProfile(); |
188 | 196 |
user.setId((Long) resultMap.get("out_id")); |
... | ... | |
199 | 207 |
return user; |
200 | 208 |
} |
201 | 209 |
|
202 |
public UserSettings getUserSettings(final long id) { |
|
203 |
return this.jdbc.queryForObject("SELECT no_vacations, no_sick_days, user_role FROM end_user WHERE id=?", |
|
204 |
new Object[]{id}, (ResultSet rs, int rowNum) -> { |
|
205 |
final UserSettings settings = new UserSettings(); |
|
206 |
settings.setId(id); |
|
207 |
settings.setSickDayCount(rs.getInt("no_sick_day")); |
|
208 |
settings.setVacationCount(rs.getFloat("no_vacations")); |
|
209 |
settings.setRole(UserRole.getUserRole(rs.getString("user_role"))); |
|
210 |
return settings; |
|
211 |
}); |
|
212 |
} |
|
213 |
|
|
214 |
public void decreaseVacationCount(final long id, final float value) { |
|
215 |
this.jdbc.update("UPDATE end_user SET no_vacations = no_vacations - ? WHERE id = ?", value, id); |
|
216 |
} |
|
217 |
|
|
218 |
public void increaseTakenSickdays(final long id) { |
|
219 |
this.jdbc.update("UPDATE end_user SET taken_sick_days = taken_sick_days + 1 WHERE id = ?", id); |
|
220 |
} |
|
221 |
|
|
222 |
public void updateNotification(final UserSettings settings) { |
|
223 |
this.jdbc.update("UPDATE end_user SET alert = ? WHERE id = ?", settings.getNotification(), settings.getId()); |
|
224 |
} |
|
225 |
|
|
226 |
public void updateUserSettings(final UserSettings settings) { |
|
227 |
this.jdbc.update("UPDATE end_user SET no_vacations=?, no_sick_days=?, user_role=? WHERE id = ?", |
|
228 |
settings.getVacationCount(), settings.getSickDayCount(), settings.getRole().name(), settings.getId()); |
|
229 |
} |
|
230 |
|
|
231 | 210 |
public DefaultSettings getLastDefaultSettings() { |
232 | 211 |
return this.jdbc.queryForObject("SELECT * FROM default_settings ORDER BY id DESC LIMIT 1", (ResultSet rs, int rowNum) -> { |
233 | 212 |
final DefaultSettings settings = new DefaultSettings(); |
... | ... | |
237 | 216 |
}); |
238 | 217 |
} |
239 | 218 |
|
240 |
public void insertSettings(final DefaultSettings settings) { |
|
219 |
//---------------------------------- DOMAIN ----------------------------------- |
|
220 |
|
|
221 |
public User getUser(final long id) { |
|
222 |
final Map<String, Object> resultMap = this.getUserColumns(id); |
|
223 |
return new User( |
|
224 |
id, |
|
225 |
(String) resultMap.get("out_first_name"), |
|
226 |
(String) resultMap.get("out_last_name"), |
|
227 |
((Double) resultMap.get("out_no_vacations")).floatValue(), |
|
228 |
(Integer) resultMap.get("out_no_sick_days"), |
|
229 |
(Integer) resultMap.get("out_taken_sick_days"), |
|
230 |
((Timestamp) resultMap.get("out_alert")).toLocalDateTime(), |
|
231 |
(String) resultMap.get("out_token"), |
|
232 |
(String) resultMap.get("out_email"), |
|
233 |
(String) resultMap.get("out_photo"), |
|
234 |
((Timestamp) resultMap.get("out_creation_date")).toLocalDateTime(), |
|
235 |
UserRole.getUserRole((String) resultMap.get("out_role")), |
|
236 |
Status.getStatus((String) resultMap.get("out_status")) |
|
237 |
); |
|
238 |
} |
|
239 |
|
|
240 |
public void updateUser(final cz.zcu.yamanager.domain.User user) { |
|
241 |
this.jdbc.update("UPDATE end_user SET first_name = ?, last_name = ?, no_vacations = ?, no_sick_days = ?, taken_sick_days = ?, alert = ?, token = ?, email = ?, photo = ?, user_role = ?, status = ? WHERE id = ?", |
|
242 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTotalSickDayCount(), user.getTakenSickDayCount(), user.getNotification(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name(), user.getId()); |
|
243 |
} |
|
244 |
|
|
245 |
public void insertUser(final User user) { |
|
246 |
this.jdbc.update("INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES (?,?,?,?,?,?,?,?,?,?,?)", |
|
247 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTotalSickDayCount(), user.getTakenSickDayCount(), user.getNotification(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name()); |
|
248 |
} |
|
249 |
|
|
250 |
public void insertSettings(final cz.zcu.yamanager.domain.DefaultSettings settings) { |
|
241 | 251 |
this.jdbc.update("INSERT INTO default_settings (no_sick_days, alert) VALUES (?, ?)", settings.getSickDayCount(), settings.getNotification()); |
242 | 252 |
} |
243 | 253 |
} |
server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java | ||
---|---|---|
140 | 140 |
}); |
141 | 141 |
} |
142 | 142 |
|
143 |
public void insertVacationDay(final Long userId, final VacationDay day) { |
|
143 |
public cz.zcu.yamanager.domain.VacationDay getVacationDay(final long id) { |
|
144 |
return this.jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type" + |
|
145 |
"FROM vacation_day " + |
|
146 |
"WHERE id = ?", new Object[]{id}, |
|
147 |
(ResultSet rs, int rowNum) -> |
|
148 |
new cz.zcu.yamanager.domain.VacationDay( |
|
149 |
rs.getLong("id"), |
|
150 |
rs.getDate("vacation_date").toLocalDate(), |
|
151 |
rs.getTime("time_from").toLocalTime(), |
|
152 |
rs.getTime("time_to").toLocalTime(), |
|
153 |
rs.getTimestamp("creation_date").toLocalDateTime(), |
|
154 |
Status.getStatus(rs.getString("status")), |
|
155 |
VacationType.getVacationType(rs.getString("v.vacation_type"))) |
|
156 |
); |
|
157 |
} |
|
158 |
|
|
159 |
public void insertVacationDay(final Long userId, final cz.zcu.yamanager.domain.VacationDay day) { |
|
144 | 160 |
this.jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)", |
145 | 161 |
day.getDate(), day.getFrom(), day.getTo(), day.getStatus().name(), day.getType().name(), userId); |
146 | 162 |
} |
147 | 163 |
|
148 |
public void updateVacationDay(final VacationDay item) { |
|
164 |
public void updateVacationDay(final cz.zcu.yamanager.domain.VacationDay item) {
|
|
149 | 165 |
this.jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?", |
150 | 166 |
item.getDate(), item.getFrom(), item.getTo(), item.getStatus().name(), item.getType().name(), item.getId()); |
151 | 167 |
} |
server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java | ||
---|---|---|
12 | 12 |
import org.slf4j.Logger; |
13 | 13 |
import org.slf4j.LoggerFactory; |
14 | 14 |
import org.springframework.beans.factory.annotation.Autowired; |
15 |
import org.springframework.dao.DataAccessException; |
|
15 | 16 |
import org.springframework.http.HttpHeaders; |
16 | 17 |
import org.springframework.http.MediaType; |
17 | 18 |
import org.springframework.http.ResponseEntity; |
... | ... | |
62 | 63 |
} catch (RESTFullException e) { |
63 | 64 |
log.error(e.getMessage()); |
64 | 65 |
return sendError(400, e.getLocalizedMessage(), language); |
66 |
} catch (DataAccessException e) { |
|
67 |
log.error(e.getMessage()); |
|
68 |
return sendError(500, "database.error", language); |
|
65 | 69 |
} catch (Exception e) { |
66 | 70 |
log.error(e.getMessage()); |
67 |
return sendError(401, "rest.exception.generic", language);
|
|
71 |
return sendError(401, e.getMessage(), language);
|
|
68 | 72 |
} |
69 | 73 |
} |
70 | 74 |
|
server/src/main/resources/Message_cs.properties | ||
---|---|---|
1 | 1 |
hello=Ahoj sv\u011Bte |
2 | 2 |
rest.exception.generic=N\u011Bco se stalo :( |
3 |
sick.day.count.error = Po\u010Det sick days nesm\u00ED b\u00FDt z\u00E1porn\u00FD! |
|
4 |
vacation.count.error = Po\u010Det p\u0159es\u010Das\u016F nesm\u00ED b\u00FDt z\u00E1porn\u00FD! |
|
5 |
name.length.error = D\u00E9lka jm\u00E9na nesm\u00ED p\u0159ekro\u010Dit 45 znak\u016F! |
|
6 |
email.length.error = D\u00E9lka emailu nesm\u00ED p\u0159ekro\u010Dit 100 znak\u016F! |
|
7 |
time.order.error = Dovolen\u00E1 nesm\u00ED za\u010D\u00EDnat pozd\u011Bji nebo ve stejn\u00FD \u010Das jako kon\u010D\u00ED! |
|
3 |
negative.sick.day.error = Po\u010Det sick days nesm\u00ED b\u00FDt z\u00E1porn\u00FD. |
|
4 |
negative.vacation.error = Po\u010Det p\u0159es\u010Das\u016F nesm\u00ED b\u00FDt z\u00E1porn\u00FD. |
|
5 |
available.vacation.error = Nen\u00ED mo\u017En\u00E9 vybrat p\u0159es\u010Das. Nem\u00E1te dostate\u010Dn\u00FD po\u010Det nad\u011Blan\u00FDch hodin. |
|
6 |
available.sick.day.error = Nen\u00ED mo\u017En\u00E9 vybrat sick day, ji\u017E V\u00E1m \u017E\u00E1dn\u00E9 nezb\u00FDvaj\u00ED. |
|
7 |
name.length.error = D\u00E9lka jm\u00E9na nesm\u00ED p\u0159ekro\u010Dit 45 znak\u016F. |
|
8 |
email.length.error = D\u00E9lka emailu nesm\u00ED p\u0159ekro\u010Dit 100 znak\u016F. |
|
9 |
time.sick.day.error = Sick day nesm\u00ED m\u00EDt nastaven \u010Das za\u010D\u00E1tku nebo konce. |
|
10 |
time.vacation.error = Dovolen\u00E1 mus\u00ED obsahovat \u010Das za\u010D\u00E1tku a konce. |
|
11 |
time.order.error = Dovolen\u00E1 nesm\u00ED za\u010D\u00EDnat pozd\u011Bji nebo ve stejn\u00FD \u010Das jako kon\u010D\u00ED. |
|
12 |
taken.sick.day.count.error = Nen\u00ED dovoleno vybrat v\u00EDce sick days ne\u017E je p\u0159id\u011Bleno. |
|
13 |
date.null.error = Datum mus\u00ED b\u00FDt zad\u00E1n. |
|
14 |
status.null.error = Status mus\u00ED b\u00FDt zad\u00E1n. |
|
15 |
type.null.error = Typ mus\u00ED b\u00FDt zad\u00E1n. |
|
16 |
sick.day.null.error = Po\u010Det sick days mus\u00ED b\u00FDt zad\u00E1n. |
|
17 |
notification.null.error = Datum upozorn\u011Bn\u00ED mus\u00ED b\u00FDt zad\u00E1n. |
|
18 |
vacation.null.error = Po\u010Det hodin dovolen\u00E9 mus\u00ED b\u00FDt zad\u00E1n. |
|
19 |
role.null.error = Role mus\u00ED b\u00FDt zad\u00E1n. |
|
20 |
database.error = Vyskytl se probl\u00E9m s datab\u00E1z\u00ED. |
server/src/main/resources/Message_en.properties | ||
---|---|---|
1 | 1 |
hello=Hello world |
2 | 2 |
rest.exception.generic=Something happened :( |
3 |
sick.day.count.error = The number of sick days must not be negative! |
|
4 |
vacation.count.error = The number of hours of an overtime must not be negative! |
|
5 |
name.length.error = The length of a name must not exceed 45! |
|
6 |
email.length.error = The length of an email address must not exceed 100! |
|
7 |
time.order.error = The overtime must not start after or at the same time it ends! |
|
3 |
negative.sick.day.error = The number of sick days mustn't be negative. |
|
4 |
negative.vacation.error = The number of a remaining overtime mustn't be negative. |
|
5 |
available.vacation.error = You cannot take a vacation, not enough remaining hours. |
|
6 |
available.sick.day.error = You cannot take a sick day. You don't have any available sick days. |
|
7 |
name.length.error = The length of a name mustn't exceed 45. |
|
8 |
email.length.error = The length of an email address mustn't exceed 100. |
|
9 |
time.sick.day.error = A sick day mustn't have a starting or an ending time. |
|
10 |
time.vacation.error = A vacation has to have a starting and an ending time. |
|
11 |
time.order.error = The overtime mustn't start after or at the same time it ends. |
|
12 |
taken.sick.day.count.error = Not enough available sick days. |
|
13 |
date.null.error = The date has to be filled in. |
|
14 |
status.null.error = The status has to be filled in. |
|
15 |
type.null.error = The type has to be filled in. |
|
16 |
sick.day.null.error = The number of sick days has to be filled in. |
|
17 |
notification.null.error = The date of a notification has to be filled in. |
|
18 |
vacation.null.error = The number of overtime hours has to be filled in. |
|
19 |
role.null.error = The role has to be filled in. |
|
20 |
database.error = There was a problem with the database. |
server/src/test/java/cz/zcu/yamanager/domain/DefaultSettingsTest.java | ||
---|---|---|
61 | 61 |
assertThrows(IllegalArgumentException.class, () -> this.defaultSettings.setSickDayCount(-10)); |
62 | 62 |
} |
63 | 63 |
|
64 |
/** |
|
65 |
* Tests the method {@code setSickDayCount} with null value. |
|
66 |
*/ |
|
67 |
@Test |
|
68 |
void testSetSickDaysCountObjectNull() { |
|
69 |
assertThrows(IllegalArgumentException.class, () -> this.defaultSettings.setSickDayCount(null)); |
|
70 |
} |
|
71 |
|
|
64 | 72 |
/** |
65 | 73 |
* Tests the method {@code toString}. |
66 | 74 |
*/ |
server/src/test/java/cz/zcu/yamanager/domain/UserTest.java | ||
---|---|---|
6 | 6 |
import org.junit.jupiter.api.Test; |
7 | 7 |
|
8 | 8 |
import java.time.LocalDateTime; |
9 |
import java.time.LocalTime; |
|
9 | 10 |
|
10 | 11 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
11 | 12 |
import static org.junit.jupiter.api.Assertions.assertThrows; |
... | ... | |
86 | 87 |
*/ |
87 | 88 |
@Test |
88 | 89 |
void testSetVacationCount() { |
89 |
this.user.setVacationCount(10); |
|
90 |
this.user.setVacationCount(10f);
|
|
90 | 91 |
assertEquals(10, this.user.getVacationCount()); |
91 | 92 |
} |
92 | 93 |
|
... | ... | |
95 | 96 |
*/ |
96 | 97 |
@Test |
97 | 98 |
void testSetVacationCountZero() { |
98 |
this.user.setVacationCount(0); |
|
99 |
this.user.setVacationCount(0f);
|
|
99 | 100 |
assertEquals(0, this.user.getVacationCount()); |
100 | 101 |
} |
101 | 102 |
|
... | ... | |
104 | 105 |
*/ |
105 | 106 |
@Test |
106 | 107 |
void testSetVacationCountNegativeOne() { |
107 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-1)); |
|
108 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-1f));
|
|
108 | 109 |
} |
109 | 110 |
|
110 | 111 |
/** |
... | ... | |
112 | 113 |
*/ |
113 | 114 |
@Test |
114 | 115 |
void testSetVacationCountNegative() { |
115 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-10)); |
|
116 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-10f));
|
|
116 | 117 |
} |
117 | 118 |
|
118 | 119 |
/** |
119 |
* Tests the method {@code decreaseVacationCount} with common values where no problem should occur.
|
|
120 |
* Tests the method {@code setVacationCount} with null value.
|
|
120 | 121 |
*/ |
121 | 122 |
@Test |
122 |
void testDecreaseVacationCount() { |
|
123 |
this.user.setVacationCount(10); |
|
124 |
this.user.decreaseVacationCount(4); |
|
125 |
assertEquals(6, this.user.getVacationCount()); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Tests the method {@code decreaseVacationCount} with result equals to zero. |
|
130 |
*/ |
|
131 |
@Test |
|
132 |
void testDecreaseVacationCountZeroResult() { |
|
133 |
this.user.setVacationCount(10); |
|
134 |
this.user.decreaseVacationCount(10); |
|
135 |
assertEquals(0, this.user.getVacationCount()); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Tests the method {@code decreaseVacationCount} with result equals to -1. |
|
140 |
*/ |
|
141 |
@Test |
|
142 |
void testDecreaseVacationCountNegativeOneResult() { |
|
143 |
this.user.setVacationCount(10); |
|
144 |
assertThrows(IllegalArgumentException.class, () -> this.user.decreaseVacationCount(11)); |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* Tests the method {@code decreaseVacationCount} with result equals to negative number. |
|
149 |
*/ |
|
150 |
@Test |
|
151 |
void testDecreaseVacationCountNegativeResult() { |
|
152 |
this.user.setVacationCount(10); |
|
153 |
assertThrows(IllegalArgumentException.class, () -> this.user.decreaseVacationCount(50)); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Tests the method {@code decreaseVacationCount} with negative input. |
|
158 |
*/ |
|
159 |
@Test |
|
160 |
void testDecreaseVacationCountNegativeInput() { |
|
161 |
this.user.setVacationCount(10); |
|
162 |
this.user.decreaseVacationCount(-10); |
|
163 |
assertEquals(20, this.user.getVacationCount()); |
|
123 |
void testSetVacationCountObjectNull() { |
|
124 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(null)); |
|
164 | 125 |
} |
165 | 126 |
|
166 | 127 |
/** |
... | ... | |
197 | 158 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTotalSickDayCount(-10)); |
198 | 159 |
} |
199 | 160 |
|
161 |
/** |
|
162 |
* Tests the method {@code setTotalSickDayCount} with null value. |
|
163 |
*/ |
|
164 |
@Test |
|
165 |
void testSetTotalSickDayCountObjectNull() { |
|
166 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTotalSickDayCount(null)); |
|
167 |
} |
|
168 |
|
|
200 | 169 |
/** |
201 | 170 |
* Tests the method {@code setTakenSickDayCount} with common values where no problem should occur. |
202 | 171 |
*/ |
203 | 172 |
@Test |
204 | 173 |
void testSetTakenSickDayCount() { |
174 |
this.user.setTotalSickDayCount(50); |
|
205 | 175 |
this.user.setTakenSickDayCount(10); |
206 | 176 |
assertEquals(10, this.user.getTakenSickDayCount()); |
207 | 177 |
} |
... | ... | |
211 | 181 |
*/ |
212 | 182 |
@Test |
213 | 183 |
void testSetTakenSickDayCountZero() { |
184 |
this.user.setTotalSickDayCount(50); |
|
214 | 185 |
this.user.setTakenSickDayCount(0); |
215 | 186 |
assertEquals(0, this.user.getTakenSickDayCount()); |
216 | 187 |
} |
... | ... | |
220 | 191 |
*/ |
221 | 192 |
@Test |
222 | 193 |
void testSetTakenSickDayCountNegativeOne() { |
194 |
this.user.setTotalSickDayCount(10); |
|
223 | 195 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(-1)); |
224 | 196 |
} |
225 | 197 |
|
... | ... | |
228 | 200 |
*/ |
229 | 201 |
@Test |
230 | 202 |
void testSetTakenSickDayCountNegative() { |
203 |
this.user.setTotalSickDayCount(10); |
|
231 | 204 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(-10)); |
232 | 205 |
} |
233 | 206 |
|
207 |
/** |
|
208 |
* Tests the method {@code setTakenSickDayCount} with a value that is greater than total sick days. |
|
209 |
*/ |
|
210 |
@Test |
|
211 |
void testSetTakenSickDayCountOver() { |
|
212 |
this.user.setTotalSickDayCount(10); |
|
213 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(20)); |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Tests the method {@code setTakenSickDayCount} with a value that is equals the total sick days. |
|
218 |
*/ |
|
219 |
@Test |
|
220 |
void testSetTakenSickDayCountSame() { |
|
221 |
this.user.setTotalSickDayCount(10); |
|
222 |
this.user.setTakenSickDayCount(10); |
|
223 |
assertEquals(10, this.user.getTakenSickDayCount()); |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* Tests the method {@code setTakenSickDayCount} with null value. |
|
228 |
*/ |
|
229 |
@Test |
|
230 |
void testSetTakenSickDayCountObjectNull() { |
|
231 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(null)); |
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* Tests the method {@code setNotification} with common values where no problem should occur. |
|
236 |
*/ |
|
237 |
@Test |
|
238 |
void testSetNotification() { |
|
239 |
this.user.setNotification(LocalDateTime.of(2010,5,1,20,0)); |
|
240 |
assertEquals(LocalDateTime.of(2010,5,1,20,0), this.user.getNotification()); |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* Tests the method {@code setNotification} with null value. |
|
245 |
*/ |
|
246 |
@Test |
|
247 |
void testSetNotificationNull() { |
|
248 |
assertThrows(IllegalArgumentException.class, () -> this.user.setNotification(null)); |
|
249 |
} |
|
250 |
|
|
234 | 251 |
/** |
235 | 252 |
* Tests the method {@code setEmail} with common values where no problem should occur. |
236 | 253 |
*/ |
... | ... | |
257 | 274 |
assertThrows(IllegalArgumentException.class, () -> this.user.setEmail("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
258 | 275 |
} |
259 | 276 |
|
277 |
/** |
|
278 |
* Tests the method {@code setRole} with common values where no problem should occur. |
|
279 |
*/ |
|
280 |
@Test |
|
281 |
void testSetRole() { |
|
282 |
this.user.setRole(UserRole.EMPLOYER); |
|
283 |
assertEquals(UserRole.EMPLOYER, this.user.getRole()); |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* Tests the method {@code setRole} with null value. |
|
288 |
*/ |
|
289 |
@Test |
|
290 |
void testSetRoleNull() { |
|
291 |
assertThrows(IllegalArgumentException.class, () -> this.user.setRole(null)); |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* Tests the method {@code setStatus} with common values where no problem should occur. |
|
296 |
*/ |
|
297 |
@Test |
|
298 |
void testSetStatus() { |
|
299 |
this.user.setStatus(Status.ACCEPTED); |
|
300 |
assertEquals(Status.ACCEPTED, this.user.getStatus()); |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Tests the method {@code setStatus} with null value. |
|
305 |
*/ |
|
306 |
@Test |
|
307 |
void testSetStatusNull() { |
|
308 |
assertThrows(IllegalArgumentException.class, () -> this.user.setStatus(null)); |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 |
* Tests the method {@code takeVacation} with common values where no problem should occur. |
|
313 |
*/ |
|
314 |
@Test |
|
315 |
void testTakeVacation() { |
|
316 |
this.user.setVacationCount(10f); |
|
317 |
this.user.takeVacation(LocalTime.of(15,0), LocalTime.of(20, 0)); |
|
318 |
assertEquals(5, this.user.getVacationCount()); |
|
319 |
} |
|
320 |
|
|
321 |
/** |
|
322 |
* Tests the method {@code takeVacation} when there is not enough vacations. |
|
323 |
*/ |
|
324 |
@Test |
|
325 |
void testTakeVacationException() { |
|
326 |
assertThrows(IllegalArgumentException.class, () -> this.user.takeVacation(LocalTime.of(15,0), LocalTime.of(20, 0))); |
|
327 |
} |
|
328 |
|
|
329 |
/** |
Také k dispozici: Unified diff
Handle different or non inputs, unit tests, error messages