Revize 1a887a3c
Přidáno uživatelem Lukas Cerny před téměř 6 roky(ů)
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
12 | 12 |
import org.springframework.dao.DataAccessException; |
13 | 13 |
import org.springframework.stereotype.Component; |
14 | 14 | |
15 |
import java.sql.SQLException; |
|
16 | 15 |
import java.time.LocalDate; |
17 | 16 |
import java.util.List; |
18 | 17 |
import java.util.Optional; |
... | ... | |
41 | 40 |
@Override |
42 | 41 |
public List<BasicProfileUser> getUsers(Status status) throws RESTFullException { |
43 | 42 |
try { |
44 |
List<BasicProfileUser> users = status == null ? this.userRepository.getAllBasicUsers() : this.userRepository.getAllBasicUsers(status);
|
|
43 |
List<BasicProfileUser> users = userRepository.getAllBasicUsers(status == null ? Status.ACCEPTED : status);
|
|
45 | 44 | |
46 | 45 |
LocalDate today = LocalDate.now(); |
47 | 46 |
LocalDate weekBefore = today.minusDays(ApiManager.WEEK_LENGTH); |
48 | 47 |
LocalDate weekAfter = today.plusDays(ApiManager.WEEK_LENGTH); |
49 | 48 |
for (BasicProfileUser user : users) { |
50 |
user.setCalendar(this.vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter));
|
|
49 |
user.setCalendar(vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter)); |
|
51 | 50 |
} |
52 | 51 | |
53 | 52 |
return users; |
53 | ||
54 | 54 |
} catch (DataAccessException e) { |
55 | 55 |
log.error(e.getMessage()); |
56 | 56 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
60 | 60 |
@Override |
61 | 61 |
public List<VacationRequest> getVacationRequests(Status status) throws RESTFullException { |
62 | 62 |
try { |
63 |
return status == null ? this.requestRepository.getAllVacationRequests() : this.requestRepository.getAllVacationRequests(status);
|
|
63 |
return status == null ? requestRepository.getAllVacationRequests() : requestRepository.getAllVacationRequests(status);
|
|
64 | 64 |
} catch (DataAccessException e) { |
65 | 65 |
log.error(e.getMessage()); |
66 | 66 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
70 | 70 |
@Override |
71 | 71 |
public List<AuthorizationRequest> getAuthorizationRequests(Status status) throws RESTFullException { |
72 | 72 |
try { |
73 |
return status == null ? this.requestRepository.getAllAuthorizations() : this.requestRepository.getAllAuthorizations(status);
|
|
73 |
return status == null ? requestRepository.getAllAuthorizations() : requestRepository.getAllAuthorizations(status);
|
|
74 | 74 |
} catch (DataAccessException e) { |
75 | 75 |
log.error(e.getMessage()); |
76 | 76 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
80 | 80 |
@Override |
81 | 81 |
public FullUserProfile getUserProfile(Long userId) throws RESTFullException { |
82 | 82 |
try { |
83 |
return this.userRepository.getFullUser(userId);
|
|
83 |
return userRepository.getFullUser(userId); |
|
84 | 84 |
} catch (DataAccessException e) { |
85 | 85 |
log.error(e.getMessage()); |
86 | 86 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
90 | 90 |
@Override |
91 | 91 |
public DefaultSettings getDefaultSettings() throws RESTFullException { |
92 | 92 |
try { |
93 |
return this.userRepository.getLastDefaultSettings().orElse(new DefaultSettings());
|
|
93 |
return userRepository.getLastDefaultSettings().orElse(new DefaultSettings()); |
|
94 | 94 |
} catch (DataAccessException e) { |
95 | 95 |
log.error(e.getMessage()); |
96 | 96 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
102 | 102 |
try { |
103 | 103 |
List<VacationDay> vacations; |
104 | 104 |
if (status == null && toDate == null) { |
105 |
vacations = this.vacationRepository.getVacationDays(userId, fromDate);
|
|
105 |
vacations = vacationRepository.getVacationDays(userId, fromDate); |
|
106 | 106 |
} else if (status == null) { |
107 |
vacations = this.vacationRepository.getVacationDays(userId, fromDate, toDate);
|
|
107 |
vacations = vacationRepository.getVacationDays(userId, fromDate, toDate); |
|
108 | 108 |
} else if (toDate != null) { |
109 |
vacations = this.vacationRepository.getVacationDays(userId, fromDate, toDate, status);
|
|
109 |
vacations = vacationRepository.getVacationDays(userId, fromDate, toDate, status); |
|
110 | 110 |
} else { |
111 |
vacations = this.vacationRepository.getVacationDays(userId, fromDate, status);
|
|
111 |
vacations = vacationRepository.getVacationDays(userId, fromDate, status); |
|
112 | 112 |
} |
113 | 113 | |
114 | 114 |
return vacations; |
115 | ||
115 | 116 |
} catch (DataAccessException e) { |
116 | 117 |
log.error(e.getMessage()); |
117 | 118 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
124 | 125 |
cz.zcu.yamanager.domain.DefaultSettings defaultSettings = new cz.zcu.yamanager.domain.DefaultSettings(); |
125 | 126 |
defaultSettings.setSickDayCount(settings.getSickDayCount()); |
126 | 127 |
defaultSettings.setNotification(settings.getNotification()); |
127 |
this.userRepository.insertSettings(defaultSettings);
|
|
128 |
userRepository.insertSettings(defaultSettings); |
|
128 | 129 |
} catch (DataAccessException e) { |
129 | 130 |
log.error(e.getMessage()); |
130 | 131 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
134 | 135 |
@Override |
135 | 136 |
public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
136 | 137 |
try { |
137 |
User user = this.userRepository.getUser(userId);
|
|
138 |
User user = userRepository.getUser(userId); |
|
138 | 139 |
vacationDay.setStatus(user.getRole() == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING); |
139 | 140 | |
140 | 141 |
cz.zcu.yamanager.domain.VacationDay vacation = new cz.zcu.yamanager.domain.VacationDay(); |
... | ... | |
150 | 151 |
user.takeSickDay(); |
151 | 152 |
} |
152 | 153 | |
153 |
this.vacationRepository.insertVacationDay(userId, vacation);
|
|
154 |
this.userRepository.updateUser(user);
|
|
154 |
vacationRepository.insertVacationDay(userId, vacation); |
|
155 |
userRepository.updateUser(user); |
|
155 | 156 |
} catch (DataAccessException e) { |
156 | 157 |
log.error(e.getMessage()); |
157 | 158 |
throw new RESTFullException(e.getMessage(), "database.error"); |
158 | 159 |
} |
159 | 160 |
} |
160 | 161 | |
162 |
private void changeSettingsByEmployee(User user, UserSettings settings, DefaultSettings defaultSettings) { |
|
163 |
if (settings.getNotification() != null && !settings.getNotification().equals(user.getNotification())) { |
|
164 |
user.setNotification(settings.getNotification()); |
|
165 |
} |
|
166 | ||
167 |
if (user.getTotalSickDayCount().equals(defaultSettings.getSickDayCount())) { |
|
168 |
user.setTotalSickDayCount(null); |
|
169 |
} |
|
170 |
} |
|
171 | ||
172 |
private void changeSettingsByEmployer(User user, UserSettings settings, DefaultSettings defaultSettings) { |
|
173 | ||
174 |
if (settings.getRole() != null && !settings.getRole().equals(user.getRole())) { |
|
175 |
user.setRole(settings.getRole()); |
|
176 |
} |
|
177 | ||
178 |
if (settings.getSickDayCount() != null) { |
|
179 |
if (settings.getSickDayCount().equals(defaultSettings.getSickDayCount())) { |
|
180 |
user.setTotalSickDayCount(null); |
|
181 |
} else { |
|
182 |
user.setTotalSickDayCount(settings.getSickDayCount()); |
|
183 |
} |
|
184 |
} else if (user.getTotalSickDayCount().equals(defaultSettings.getSickDayCount())) { |
|
185 |
user.setTotalSickDayCount(null); |
|
186 |
} |
|
187 | ||
188 |
if (settings.getVacationCount() != null) { |
|
189 |
user.setVacationCount(user.getVacationCount() + settings.getVacationCount()); |
|
190 |
} |
|
191 | ||
192 |
if (settings.getNotification() != null && !settings.getNotification().equals(user.getNotification())) { |
|
193 |
user.setNotification(settings.getNotification()); |
|
194 |
} |
|
195 |
} |
|
196 | ||
161 | 197 |
@Override |
162 | 198 |
public void changeSettings(Long userId, UserSettings settings) throws RESTFullException { |
199 | ||
163 | 200 |
try { |
164 |
User user = this.userRepository.getUser(userId); |
|
201 |
UserRole invokedUserPermission = userRepository.getPermission(userId); |
|
202 |
boolean invokedUserIsAdmin = invokedUserPermission.equals(UserRole.EMPLOYER); |
|
203 |
DefaultSettings defaultSettings = getDefaultSettings(); |
|
165 | 204 | |
166 |
if (settings.getRole() == null && settings.getSickDayCount() == null && settings.getVacationCount() == null) { |
|
167 |
user.setNotification(settings.getNotification()); |
|
205 |
User userForChange = userRepository.getUser(settings.getId() == null ? userId : settings.getId()); |
|
206 | ||
207 |
if (invokedUserIsAdmin) { |
|
208 |
changeSettingsByEmployer(userForChange, settings, defaultSettings); |
|
168 | 209 |
} else { |
169 |
user.addVacationCount(settings.getVacationCount()); |
|
170 |
user.setTotalSickDayCount(settings.getSickDayCount()); |
|
171 |
user.setRole(settings.getRole()); |
|
210 |
changeSettingsByEmployee(userForChange, settings, defaultSettings); |
|
172 | 211 |
} |
173 | 212 | |
174 |
this.userRepository.updateUserSettings(user); |
|
213 |
userRepository.updateUserSettings(userForChange); |
|
214 | ||
175 | 215 |
} catch (DataAccessException e) { |
176 | 216 |
log.error(e.getMessage()); |
177 | 217 |
throw new RESTFullException(e.getMessage(), "database.error"); |
... | ... | |
181 | 221 |
@Override |
182 | 222 |
public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
183 | 223 |
try { |
184 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacation = this.vacationRepository.getVacationDay(vacationDay.getId());
|
|
224 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacation = vacationRepository.getVacationDay(vacationDay.getId()); |
|
185 | 225 |
if (vacation.isPresent()) { |
186 | 226 |
vacation.get().setDate(vacationDay.getDate()); |
187 | 227 |
vacation.get().setStatus(vacationDay.getStatus()); |
188 | 228 |
vacation.get().setType(vacationDay.getType()); |
189 | 229 |
vacation.get().setTime(vacationDay.getFrom(), vacationDay.getTo()); |
190 |
this.vacationRepository.updateVacationDay(vacation.get()); |
|
191 |
} else { |
|
192 | ||
230 |
vacationRepository.updateVacationDay(vacation.get()); |
|
193 | 231 |
} |
194 | 232 |
} catch (DataAccessException e) { |
195 | 233 |
log.error(e.getMessage()); |
... | ... | |
200 | 238 |
@Override |
201 | 239 |
public void changeRequest(RequestType type, BasicRequest request) throws RESTFullException { |
202 | 240 |
try { |
203 |
if (RequestType.VACATION == type) { |
|
204 |
Optional<User> user = this.vacationRepository.findUserByVacationID(request.getId()); |
|
205 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacationDay = this.vacationRepository.getVacationDay(request.getId()); |
|
206 |
if (user.isPresent() && request.getStatus() == Status.REJECTED) { |
|
207 |
if (vacationDay.get().getType() == VacationType.SICK_DAY) { |
|
208 |
user.get().addTakenSickDayCount(-1); |
|
209 |
} else { |
|
210 |
user.get().addVacationCount(vacationDay.get().getFrom(), vacationDay.get().getTo()); |
|
241 |
switch (type) { |
|
242 |
case VACATION: { |
|
243 | ||
244 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacationDayOpt = vacationRepository.getVacationDay(request.getId()); |
|
245 | ||
246 |
if (!vacationDayOpt.isPresent()) { |
|
247 |
throw new RESTFullException("", ""); |
|
211 | 248 |
} |
212 |
} |
|
213 | 249 | |
214 |
this.requestRepository.updateVacationRequest(request); |
|
215 |
} else { |
|
216 |
this.requestRepository.updateAuthorization(request); |
|
250 |
cz.zcu.yamanager.domain.VacationDay vacationDay = vacationDayOpt.get(); |
|
251 | ||
252 |
if (request.getStatus().equals(Status.REJECTED)) { |
|
253 |
User user = userRepository.getUser(vacationDay.getUserId()); |
|
254 | ||
255 |
switch (vacationDay.getType()) { |
|
256 |
case VACATION: { |
|
257 |
user.addVacationCount(vacationDay.getFrom(), vacationDay.getTo()); |
|
258 |
userRepository.updateUserTakenVacation(user); |
|
259 |
} break; |
|
260 |
case SICK_DAY: { |
|
261 |
user.addTakenSickDayCount(-1); |
|
262 |
userRepository.updateUserTakenSickDay(user); |
|
263 |
} break; |
|
264 |
} |
|
265 |
} |
|
266 | ||
267 |
requestRepository.updateVacationRequest(vacationDay.getId(), request.getStatus()); |
|
268 | ||
269 |
} break; |
|
270 |
case AUTHORIZATION: { |
|
271 |
requestRepository.updateAuthorization(request); |
|
272 |
} break; |
|
217 | 273 |
} |
218 | 274 |
} catch (DataAccessException e) { |
219 | 275 |
log.error(e.getMessage()); |
220 | 276 |
throw new RESTFullException(e.getMessage(), "database.error"); |
277 |
} catch (IllegalArgumentException e) { |
|
278 |
throw new RESTFullException("Cannot create a domain object.", e.getMessage()); |
|
221 | 279 |
} |
222 | 280 |
} |
223 | 281 | |
224 | 282 |
@Override |
225 | 283 |
public void deleteVacation(Long userId, Long vacationId) throws RESTFullException { |
226 | 284 |
try { |
227 |
User user = this.userRepository.getUser(userId); |
|
228 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacation = this.vacationRepository.getVacationDay(vacationId); |
|
229 |
if (vacation.isPresent()) { |
|
230 |
if (vacation.get().getType() == VacationType.SICK_DAY) { |
|
231 |
user.addTakenSickDayCount(-1); |
|
232 |
} else { |
|
233 |
user.addVacationCount(vacation.get().getFrom(), vacation.get().getTo()); |
|
234 |
} |
|
285 |
User user = userRepository.getUser(userId); |
|
286 |
Optional<cz.zcu.yamanager.domain.VacationDay> vacation = vacationRepository.getVacationDay(vacationId); |
|
287 | ||
288 |
if (!vacation.isPresent()) { |
|
289 |
throw new RESTFullException("", ""); |
|
235 | 290 |
} |
236 | 291 | |
237 |
this.userRepository.updateUser(user); |
|
238 |
this.vacationRepository.deleteVacationDay(vacationId); |
|
292 |
cz.zcu.yamanager.domain.VacationDay vacationDay = vacation.get(); |
|
293 | ||
294 |
if (vacationDay.getDate().isAfter(LocalDate.now())) { |
|
295 |
if (!vacationDay.getStatus().equals(Status.REJECTED)) { |
|
296 |
switch (vacationDay.getType()) { |
|
297 |
case VACATION: { |
|
298 |
user.addVacationCount(vacationDay.getFrom(), vacationDay.getTo()); |
|
299 |
userRepository.updateUserTakenVacation(user); |
|
300 |
} |
|
301 |
break; |
|
302 |
case SICK_DAY: { |
|
303 |
user.addTakenSickDayCount(-1); |
|
304 |
userRepository.updateUserTakenSickDay(user); |
|
305 |
} |
|
306 |
break; |
|
307 |
} |
|
308 |
} |
|
309 |
vacationRepository.deleteVacationDay(vacationDay.getId()); |
|
310 |
} |
|
239 | 311 |
} catch (DataAccessException e) { |
240 | 312 |
log.error(e.getMessage()); |
241 | 313 |
throw new RESTFullException(e.getMessage(), "database.error"); |
server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java | ||
---|---|---|
5 | 5 |
import org.slf4j.Logger; |
6 | 6 |
import org.slf4j.LoggerFactory; |
7 | 7 | |
8 |
import javax.naming.OperationNotSupportedException; |
|
9 | 8 |
import java.time.LocalDate; |
10 | 9 |
import java.time.LocalDateTime; |
11 | 10 |
import java.time.LocalTime; |
... | ... | |
55 | 54 |
*/ |
56 | 55 |
private VacationType type; |
57 | 56 | |
57 |
private Long userId; |
|
58 | ||
58 | 59 |
/** |
59 | 60 |
* Returns the ID of this vacation. |
60 | 61 |
* |
... | ... | |
272 | 273 |
this.type = type; |
273 | 274 |
} |
274 | 275 | |
276 |
public Long getUserId() { |
|
277 |
return userId; |
|
278 |
} |
|
279 | ||
280 |
public void setUserId(Long userId) { |
|
281 |
this.userId = userId; |
|
282 |
} |
|
283 | ||
275 | 284 |
/** |
276 | 285 |
* Gets a string representation of this vacation. The representation consists of its id, date, starting time, ending time, creation date, status and type. |
277 | 286 |
* |
server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java | ||
---|---|---|
9 | 9 |
import org.springframework.jdbc.core.RowMapper; |
10 | 10 |
import org.springframework.jdbc.core.SqlOutParameter; |
11 | 11 |
import org.springframework.jdbc.core.SqlParameter; |
12 |
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|
13 |
import org.springframework.jdbc.support.KeyHolder; |
|
14 | 12 |
import org.springframework.stereotype.Repository; |
15 | 13 | |
16 | 14 |
import java.sql.*; |
... | ... | |
19 | 17 |
import java.util.Map; |
20 | 18 |
import java.util.Optional; |
21 | 19 | |
20 |
import static cz.zcu.yamanager.dto.UserRole.getUserRole; |
|
21 | ||
22 | 22 |
/** |
23 | 23 |
* An instance of the class UserRepository handles queries which selects and updates users and their settings in a database. |
24 | 24 |
*/ |
... | ... | |
196 | 196 |
new Object[]{status.name()}, new BasicProfileUserMapper()); |
197 | 197 |
} |
198 | 198 | |
199 |
public UserRole getPermission(Long id) { |
|
200 |
return jdbc.queryForObject("SELECT user_role FROM end_user WHERE id = ?" ,new Object[]{id}, (rs, rowNum) -> |
|
201 |
getUserRole(rs.getString("user_role")) |
|
202 |
); |
|
203 |
} |
|
204 | ||
199 | 205 |
/** |
200 | 206 |
* |
201 | 207 |
* @param id |
... | ... | |
216 | 222 |
user.setNotification(((Timestamp) resultMap.get("out_alert")).toLocalDateTime()); |
217 | 223 |
user.setEmail((String) resultMap.get("out_email")); |
218 | 224 |
user.setPhoto((String) resultMap.get("out_photo")); |
219 |
user.setRole(UserRole.getUserRole((String) resultMap.get("out_role")));
|
|
225 |
user.setRole(getUserRole((String) resultMap.get("out_role"))); |
|
220 | 226 |
user.setStatus(Status.getStatus((String) resultMap.get("out_status"))); |
221 | 227 |
return user; |
222 | 228 | |
... | ... | |
237 | 243 |
user.setNotification(((Timestamp) resultMap.get("out_alert")).toLocalDateTime()); |
238 | 244 |
user.setEmail((String) resultMap.get(("out_email"))); |
239 | 245 |
user.setPhoto((String) resultMap.get("out_photo")); |
240 |
user.setRole(UserRole.getUserRole((String) resultMap.get("out_role")));
|
|
246 |
user.setRole(getUserRole((String) resultMap.get("out_role"))); |
|
241 | 247 |
user.setStatus(Status.getStatus((String) resultMap.get("out_status"))); |
242 | 248 |
return user; |
243 | 249 |
} |
... | ... | |
262 | 268 |
user.setEmail((String)resultMap.get("out_email")); |
263 | 269 |
user.setPhoto((String)resultMap.get("out_photo")); |
264 | 270 |
user.setCreationDate(((Timestamp)resultMap.get("out_creation_date")).toLocalDateTime()); |
265 |
user.setRole(UserRole.getUserRole((String)resultMap.get("out_role")));
|
|
271 |
user.setRole(getUserRole((String)resultMap.get("out_role"))); |
|
266 | 272 |
user.setStatus(Status.getStatus((String)resultMap.get("out_status"))); |
267 | 273 |
return user; |
268 | 274 |
} |
269 | 275 | |
270 |
public void updateUserSettings(final User user) { |
|
271 |
this.jdbc.update("UPDATE end_user SET no_vacations = ?, no_sick_days = ?, alert = ? WHERE id = ?", |
|
272 |
user.getVacationCount(), user.getTotalSickDayCount(), user.getNotification(), user.getId()); |
|
273 |
} |
|
274 | ||
275 | 276 |
public void updateUser(final User user) { |
276 | 277 |
this.jdbc.update("UPDATE end_user SET first_name = ?, last_name = ?, no_vacations = ?, taken_sick_days = ?, token = ?, email = ?, photo = ?, user_role = ?, status = ? WHERE id = ?", |
277 | 278 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTakenSickDayCount(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name(), user.getId()); |
... | ... | |
285 | 286 |
public void insertSettings(final cz.zcu.yamanager.domain.DefaultSettings settings) { |
286 | 287 |
this.jdbc.update("INSERT INTO default_settings (no_sick_days, alert) VALUES (?, ?)", settings.getSickDayCount(), settings.getNotification()); |
287 | 288 |
} |
289 | ||
290 |
public void updateUserSettings(User user) { |
|
291 |
jdbc.update("UPDATE end_user SET alert = ?, user_role = ?, no_sick_days = ?, no_vacations = ? WHERE id = ?", |
|
292 |
user.getNotification(), user.getRole().name(), user.getTotalSickDayCount(), user.getVacationCount(), user.getId()); |
|
293 |
} |
|
294 | ||
295 |
public void updateUserTakenVacation(User user) { |
|
296 |
jdbc.update("UPDATE end_user SET no_vacations = ? WHERE id = ?", |
|
297 |
user.getVacationCount(), user.getId()); |
|
298 |
} |
|
299 | ||
300 |
public void updateUserTakenSickDay(User user) { |
|
301 |
jdbc.update("UPDATE end_user SET taken_sick_days = ? WHERE id = ?", |
|
302 |
user.getTakenSickDayCount(), user.getId()); |
|
303 |
} |
|
288 | 304 |
} |
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.dto.Status; |
|
5 |
import cz.zcu.yamanager.dto.UserRole; |
|
6 |
import cz.zcu.yamanager.dto.VacationDay; |
|
7 |
import cz.zcu.yamanager.dto.VacationType; |
|
4 |
import cz.zcu.yamanager.dto.*; |
|
8 | 5 | |
9 | 6 |
import org.slf4j.Logger; |
10 | 7 |
import org.slf4j.LoggerFactory; |
... | ... | |
20 | 17 |
import java.util.List; |
21 | 18 |
import java.util.Optional; |
22 | 19 | |
20 |
import static cz.zcu.yamanager.dto.Status.getStatus; |
|
21 |
import static java.util.Optional.ofNullable; |
|
22 | ||
23 | 23 |
@Repository |
24 | 24 |
public class VacationRepository { |
25 | 25 |
/** |
... | ... | |
55 | 55 |
item.setTo(timeTo.toLocalTime()); |
56 | 56 |
} |
57 | 57 | |
58 |
item.setStatus(Status.getStatus(resultSet.getString("v.status")));
|
|
58 |
item.setStatus(getStatus(resultSet.getString("v.status"))); |
|
59 | 59 |
item.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type"))); |
60 | 60 |
return item; |
61 | 61 |
} |
... | ... | |
84 | 84 |
} |
85 | 85 | |
86 | 86 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from) { |
87 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
|
|
87 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
88 | 88 |
"FROM vacation_day v " + |
89 | 89 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
90 | 90 |
"WHERE v.user_id = ? AND v.vacation_date >= ?", |
... | ... | |
92 | 92 |
} |
93 | 93 | |
94 | 94 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final Status status) { |
95 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
|
|
95 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
96 | 96 |
"FROM vacation_day v " + |
97 | 97 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
98 | 98 |
"WHERE v.user_id = ? AND v.vacation_date >= ? AND v.status = ?", |
... | ... | |
100 | 100 |
} |
101 | 101 | |
102 | 102 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to) { |
103 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
|
|
103 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
104 | 104 |
"FROM vacation_day v " + |
105 | 105 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
106 | 106 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ?", |
... | ... | |
109 | 109 |
} |
110 | 110 | |
111 | 111 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status) { |
112 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
|
|
112 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
113 | 113 |
"FROM vacation_day v " + |
114 | 114 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
115 | 115 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ? AND v.status = ?", |
... | ... | |
117 | 117 |
} |
118 | 118 | |
119 | 119 |
public Optional<cz.zcu.yamanager.domain.VacationDay> getVacationDay(final long id) { |
120 |
return Optional.ofNullable(this.jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type " +
|
|
120 |
return ofNullable(jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type, user_id " +
|
|
121 | 121 |
"FROM vacation_day WHERE id = ?", new Object[]{id}, |
122 | 122 |
(ResultSet rs, int rowNum) -> { |
123 | 123 |
cz.zcu.yamanager.domain.VacationDay vacationDay = new cz.zcu.yamanager.domain.VacationDay(); |
... | ... | |
139 | 139 |
} |
140 | 140 | |
141 | 141 |
vacationDay.setCreationDate(rs.getTimestamp("creation_date").toLocalDateTime()); |
142 |
vacationDay.setStatus(Status.getStatus(rs.getString("status")));
|
|
142 |
vacationDay.setStatus(getStatus(rs.getString("status"))); |
|
143 | 143 |
vacationDay.setType(VacationType.getVacationType(rs.getString("vacation_type"))); |
144 |
vacationDay.setUserId(rs.getLong("user_id")); |
|
144 | 145 |
return vacationDay; |
145 | 146 |
})); |
146 | 147 |
} |
147 | 148 | |
148 | 149 |
public void insertVacationDay(final Long userId, final cz.zcu.yamanager.domain.VacationDay day) { |
149 |
this.jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)",
|
|
150 |
jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)", |
|
150 | 151 |
day.getDate(), day.getFrom(), day.getTo(), day.getStatus().name(), day.getType().name(), userId); |
151 | 152 |
} |
152 | 153 | |
153 | 154 |
public void updateVacationDay(final cz.zcu.yamanager.domain.VacationDay item) { |
154 |
this.jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?",
|
|
155 |
jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?", |
|
155 | 156 |
item.getDate(), item.getFrom(), item.getTo(), item.getStatus().name(), item.getType().name(), item.getId()); |
156 | 157 |
} |
157 | 158 | |
158 | 159 |
public void deleteVacationDay(final long id) { |
159 |
this.jdbc.update("DELETE FROM vacation_day WHERE id=?", id);
|
|
160 |
jdbc.update("DELETE FROM vacation_day WHERE id=?", id); |
|
160 | 161 |
} |
161 | 162 | |
162 | 163 |
public Optional<User> findUserByVacationID(final long id) { |
163 |
return Optional.ofNullable(this.jdbc.queryForObject("SELECT u.* FROM vacation_day v INNER JOIN end_user u ON v.user_id = u.id WHERE v.user_id = ?", new Object[]{id}, (ResultSet rs, int rowNum)-> |
|
164 |
return ofNullable(jdbc.queryForObject( |
|
165 |
"SELECT u.id,u.first_name, u.last_name, u.no_vacations," + |
|
166 |
"u.no_sick_days, u.taken_sick_days, u.alert, u.token, u.email," + |
|
167 |
"u.photo, u.creation_date, u.user_role, u.status " + |
|
168 |
"FROM vacation_day v INNER JOIN end_user u ON v.user_id = u.id " + |
|
169 |
"WHERE v.id = ?", new Object[]{id}, (ResultSet rs, int rowNum)-> |
|
164 | 170 |
{ |
165 | 171 |
User user = new User(); |
166 | 172 |
user.setId(rs.getLong("u.id")); |
167 | 173 |
user.setFirstName(rs.getString("u.first_name")); |
168 | 174 |
user.setLastName(rs.getString("u.last_name")); |
169 | 175 |
user.setVacationCount(rs.getFloat("u.no_vacations")); |
170 |
user.setTotalSickDayCount(rs.getInt("u.total_sick_days"));
|
|
176 |
user.setTotalSickDayCount(rs.getInt("u.no_sick_days"));
|
|
171 | 177 |
user.setTakenSickDayCount(rs.getInt("u.taken_sick_days")); |
172 | 178 |
user.setNotification(rs.getTimestamp("u.alert").toLocalDateTime()); |
173 | 179 |
user.setToken(rs.getString("u.token")); |
174 | 180 |
user.setEmail(rs.getString("u.email")); |
175 | 181 |
user.setPhoto(rs.getString("u.photo")); |
176 | 182 |
user.setCreationDate(rs.getTimestamp("u.creation_date").toLocalDateTime()); |
177 |
user.setRole(UserRole.getUserRole(rs.getString("u.role"))); |
|
178 |
user.setStatus(Status.getStatus(rs.getString("u.status")));
|
|
183 |
user.setRole(UserRole.getUserRole(rs.getString("u.user_role")));
|
|
184 |
user.setStatus(getStatus(rs.getString("u.status"))); |
|
179 | 185 |
return user; |
180 | 186 |
})); |
181 | 187 |
} |
server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java | ||
---|---|---|
214 | 214 |
@RequestBody UserSettings settings) |
215 | 215 |
{ |
216 | 216 |
return handle(getLanguage(lang), () -> |
217 |
manager.changeSettings(getUserId(settings.getId()), settings)
|
|
217 |
manager.changeSettings(getUserId("me"), settings)
|
|
218 | 218 |
); |
219 | 219 |
} |
220 | 220 |
Také k dispozici: Unified diff
Fixed: user settings, accepting / rejecting vacation, sick day, users, adding and deleting sick days, etc..