Revize dabc8081
Přidáno uživatelem Dominik Poch před téměř 6 roky(ů)
server/init.sql | ||
---|---|---|
1 |
-- ----------------------------------------------------- |
|
2 |
-- Table role |
|
3 |
-- ----------------------------------------------------- |
|
4 |
DROP TABLE IF EXISTS role; |
|
5 |
CREATE TABLE role ( |
|
6 |
id TINYINT NOT NULL AUTO_INCREMENT, |
|
7 |
name VARCHAR(8) NOT NULL, |
|
8 |
PRIMARY KEY (id) |
|
9 |
); |
|
10 |
|
|
11 |
-- ----------------------------------------------------- |
|
12 |
-- Table approval_status |
|
13 |
-- ----------------------------------------------------- |
|
14 |
DROP TABLE IF EXISTS approval_status; |
|
15 |
CREATE TABLE approval_status ( |
|
16 |
id TINYINT NOT NULL AUTO_INCREMENT, |
|
17 |
name VARCHAR(8) NOT NULL, |
|
18 |
PRIMARY KEY (id) |
|
19 |
); |
|
20 |
|
|
21 |
-- ----------------------------------------------------- |
|
22 |
-- Table vacation_type |
|
23 |
-- ----------------------------------------------------- |
|
24 |
DROP TABLE IF EXISTS vacation_type; |
|
25 |
CREATE TABLE vacation_type ( |
|
26 |
id TINYINT NOT NULL AUTO_INCREMENT, |
|
27 |
name VARCHAR(8) NOT NULL, |
|
28 |
PRIMARY KEY (id) |
|
29 |
); |
|
30 |
|
|
31 | 1 |
-- ----------------------------------------------------- |
32 | 2 |
-- Table end_user |
33 | 3 |
-- ----------------------------------------------------- |
... | ... | |
44 | 14 |
email VARCHAR(100) NOT NULL, |
45 | 15 |
photo TEXT, |
46 | 16 |
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
47 |
role_id TINYINT NOT NULL,
|
|
48 |
status_id TINYINT NOT NULL,
|
|
17 |
user_role VARCHAR(8) NOT NULL,
|
|
18 |
status VARCHAR(8) NOT NULL,
|
|
49 | 19 |
PRIMARY KEY (id), |
50 |
INDEX fk_end_user_role (role_id ASC), |
|
51 |
INDEX fk_end_user_approval_status (status_id ASC), |
|
52 |
CONSTRAINT fk_end_user_role FOREIGN KEY (role_id) |
|
53 |
REFERENCES role (id) |
|
54 |
ON DELETE CASCADE ON UPDATE CASCADE, |
|
55 |
CONSTRAINT fk_end_user_approval_status FOREIGN KEY (status_id) |
|
56 |
REFERENCES approval_status (id) |
|
57 |
ON DELETE NO ACTION ON UPDATE CASCADE, |
|
58 | 20 |
CONSTRAINT check_taken_sick_days CHECK (taken_sick_days >= 0) |
59 | 21 |
); |
60 | 22 |
|
... | ... | |
68 | 30 |
time_from TIME, |
69 | 31 |
time_to TIME, |
70 | 32 |
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
33 |
status VARCHAR(8) NOT NULL, |
|
34 |
vacation_type VARCHAR(8) NOT NULL, |
|
71 | 35 |
user_id BIGINT NOT NULL, |
72 |
status_id TINYINT NOT NULL, |
|
73 |
type_id TINYINT NOT NULL, |
|
74 | 36 |
PRIMARY KEY (id), |
75 |
INDEX fk_vacation_day_approval_status (status_id ASC), |
|
76 | 37 |
INDEX fk_vacation_day_end_user (user_id ASC), |
77 |
INDEX fk_vacation_day_vacation_type (type_id ASC), |
|
78 |
CONSTRAINT fk_vacation_day_approval_status FOREIGN KEY (status_id) |
|
79 |
REFERENCES approval_status (id) |
|
80 |
ON DELETE NO ACTION ON UPDATE CASCADE, |
|
81 | 38 |
CONSTRAINT fk_vacation_day_end_user FOREIGN KEY (user_id) |
82 | 39 |
REFERENCES end_user (id) |
83 | 40 |
ON DELETE CASCADE ON UPDATE CASCADE, |
84 |
CONSTRAINT fk_vacation_day_vacation_type FOREIGN KEY (type_id) |
|
85 |
REFERENCES vacation_type (id) |
|
86 |
ON DELETE CASCADE ON UPDATE CASCADE, |
|
87 | 41 |
CONSTRAINT check_time CHECK (time_from < time_to) |
88 | 42 |
); |
89 | 43 |
|
... | ... | |
121 | 75 |
DECLARE notification DATETIME; |
122 | 76 |
|
123 | 77 |
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1; |
124 |
SELECT u.id, u.first_name, u.last_name, u.no_vacations, IFNULL(u.no_sick_days, sickDaysCount), u.taken_sick_days, IFNULL(u.alert, notification), u.email, u.photo, u.creation_date, r.name, s.name
|
|
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
|
|
125 | 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 |
126 |
FROM end_user u |
|
127 |
INNER JOIN role r ON u.role_id=r.id |
|
128 |
INNER JOIN approval_status s ON u.status_id=s.id |
|
129 |
WHERE u.id=in_id; |
|
80 |
FROM end_user |
|
81 |
WHERE id=in_id; |
|
130 | 82 |
END $$ |
131 | 83 |
|
132 | 84 |
DROP PROCEDURE IF EXISTS GetUserToken $$ |
133 | 85 |
CREATE PROCEDURE GetUserToken( |
134 |
IN p_token TEXT,
|
|
86 |
IN in_token TEXT,
|
|
135 | 87 |
OUT out_id BIGINT, |
136 | 88 |
OUT out_first_name VARCHAR(45), |
137 | 89 |
OUT out_last_name VARCHAR(45), |
... | ... | |
149 | 101 |
DECLARE notification DATETIME; |
150 | 102 |
|
151 | 103 |
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1; |
152 |
SELECT u.id, u.first_name, u.last_name, u.no_vacations, IFNULL(u.no_sick_days, sickDaysCount), u.taken_sick_days, IFNULL(u.alert, notification), u.email, u.photo, u.creation_date, r.name, s.name
|
|
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
|
|
153 | 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 |
154 |
FROM end_user u |
|
155 |
INNER JOIN role r ON u.role_id=r.id |
|
156 |
INNER JOIN approval_status s ON u.status_id=s.id |
|
157 |
WHERE u.token=p_token; |
|
106 |
FROM end_user |
|
107 |
WHERE token=in_token; |
|
158 | 108 |
END $$ |
159 | 109 |
|
160 | 110 |
DELIMITER ; |
161 | 111 |
|
162 |
-- ----------------------------------------------------- |
|
163 |
-- Insert table role |
|
164 |
-- ----------------------------------------------------- |
|
165 |
INSERT INTO role (name) VALUES ('employee'); |
|
166 |
INSERT INTO role (name) VALUES ('employer'); |
|
167 |
|
|
168 |
-- ----------------------------------------------------- |
|
169 |
-- Insert table approval_status |
|
170 |
-- ----------------------------------------------------- |
|
171 |
INSERT INTO approval_status (name) VALUES ('accepted'); |
|
172 |
INSERT INTO approval_status (name) VALUES ('pending'); |
|
173 |
INSERT INTO approval_status (name) VALUES ('rejected'); |
|
174 |
|
|
175 |
-- ----------------------------------------------------- |
|
176 |
-- Insert table vacation_type |
|
177 |
-- ----------------------------------------------------- |
|
178 |
INSERT INTO vacation_type (name) VALUES ('sickday'); |
|
179 |
INSERT INTO vacation_type (name) VALUES ('vacation'); |
|
180 |
|
|
181 | 112 |
-- ----------------------------------------------------- |
182 | 113 |
-- Insert table end_user |
183 | 114 |
-- ----------------------------------------------------- |
184 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, role_id, status_id) VALUES ('admin', 'admin', 0, NULL, 0, NULL, '', '', '', 2, 1); |
|
185 |
INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, role_id, status_id) VALUES ('test', 'test', 0, NULL, 0, NULL, '', '', '', 1, 2); |
|
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'); |
|
186 | 118 |
|
187 | 119 |
-- ----------------------------------------------------- |
188 | 120 |
-- Insert table vacation_day |
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
89 | 89 |
FullUserProfile userProfile = this.userRepository.getFullUser(userId); |
90 | 90 |
System.out.println("Notification: " + userProfile.getNotification()); |
91 | 91 |
System.out.println("Approval: " + userProfile.getStatus()); |
92 |
return userProfile == null ? new FullUserProfile() : userProfile;
|
|
92 |
return userProfile; |
|
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
@Override |
server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
/** |
31 | 31 |
* Creates a new instance of the class RequestRepository which selects and updates requests in a database. |
32 |
* |
|
32 | 33 |
* @param jdbc A connection to the database. |
33 | 34 |
*/ |
34 | 35 |
@Autowired |
35 |
public RequestRepository(JdbcTemplate jdbc) { |
|
36 |
log.trace("Creating a new instance of the class RequestRepository"); |
|
36 |
public RequestRepository(final JdbcTemplate jdbc) {
|
|
37 |
RequestRepository.log.trace("Creating a new instance of the class RequestRepository");
|
|
37 | 38 |
this.jdbc = jdbc; |
38 | 39 |
} |
39 | 40 |
|
40 | 41 |
/** |
41 | 42 |
* Gets all authorization request from a database. |
43 |
* |
|
42 | 44 |
* @return A list of all authorization requests. |
43 | 45 |
*/ |
44 | 46 |
public List<AuthorizationRequest> getAllAuthorizations() { |
45 |
log.trace("Selecting all authorization requests from a database."); |
|
47 |
RequestRepository.log.trace("Selecting all authorization requests from a database.");
|
|
46 | 48 |
|
47 |
return jdbc.query("SELECT u.id, u.first_name, u.last_name, u.creation_date, s.name " + |
|
48 |
"FROM end_user u " + |
|
49 |
"INNER JOIN approval_status s ON u.status_id = s.id", |
|
49 |
return this.jdbc.query("SELECT id, first_name, last_name, creation_date, status FROM end_user", |
|
50 | 50 |
(ResultSet rs, int rowNum) -> { |
51 |
AuthorizationRequest request = new AuthorizationRequest(); |
|
52 |
request.setId(rs.getLong("u.id"));
|
|
53 |
request.setFirstName(rs.getString("u.first_name"));
|
|
54 |
request.setLastName(rs.getString("u.last_name"));
|
|
55 |
request.setStatus(Status.getStatus(rs.getString("s.name")));
|
|
56 |
request.setTimestamp(rs.getTimestamp("u.creation_date").toLocalDateTime());
|
|
51 |
final AuthorizationRequest request = new AuthorizationRequest();
|
|
52 |
request.setId(rs.getLong("id")); |
|
53 |
request.setFirstName(rs.getString("first_name")); |
|
54 |
request.setLastName(rs.getString("last_name")); |
|
55 |
request.setTimestamp(rs.getTimestamp("creation_date").toLocalDateTime());
|
|
56 |
request.setStatus(Status.getStatus(rs.getString("status")));
|
|
57 | 57 |
return request; |
58 | 58 |
}); |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
/** |
62 | 62 |
* Gets all authorization request with the given status from a database. |
63 |
* |
|
63 | 64 |
* @param status The approval status of the requests. |
64 | 65 |
* @return A list of all authorization requests. |
65 | 66 |
*/ |
66 |
public List<AuthorizationRequest> getAllAuthorizations(Status status) { |
|
67 |
log.debug("Selecting all authorization requests from a database with requested status: {}", status); |
|
68 |
|
|
69 |
if(status == null) throw new InvalidParameterException(); |
|
70 |
return jdbc.query("SELECT u.id, u.first_name, u.last_name, u.creation_date, s.name " + |
|
71 |
"FROM end_user u " + |
|
72 |
"INNER JOIN approval_status s ON u.status_id = s.id " + |
|
73 |
"WHERE s.name = ?", |
|
67 |
public List<AuthorizationRequest> getAllAuthorizations(final Status status) { |
|
68 |
RequestRepository.log.debug("Selecting all authorization requests from a database with requested status: {}", status); |
|
69 |
|
|
70 |
if (status == null) throw new InvalidParameterException(); |
|
71 |
return this.jdbc.query("SELECT id, first_name, last_name, creation_date FROM end_user WHERE status = ?", |
|
74 | 72 |
new Object[]{status.name()}, |
75 | 73 |
(ResultSet rs, int rowNum) -> { |
76 |
AuthorizationRequest request = new AuthorizationRequest(); |
|
77 |
request.setId(rs.getLong("u.id"));
|
|
78 |
request.setFirstName(rs.getString("u.first_name"));
|
|
79 |
request.setLastName(rs.getString("u.last_name"));
|
|
80 |
request.setStatus(Status.getStatus(rs.getString("s.name")));
|
|
81 |
request.setTimestamp(rs.getTimestamp("u.creation_date").toLocalDateTime());
|
|
74 |
final AuthorizationRequest request = new AuthorizationRequest();
|
|
75 |
request.setId(rs.getLong("id")); |
|
76 |
request.setFirstName(rs.getString("first_name")); |
|
77 |
request.setLastName(rs.getString("last_name")); |
|
78 |
request.setTimestamp(rs.getTimestamp("creation_date").toLocalDateTime());
|
|
79 |
request.setStatus(status);
|
|
82 | 80 |
return request; |
83 | 81 |
}); |
84 | 82 |
} |
85 | 83 |
|
86 | 84 |
/** |
87 | 85 |
* Updates a status of an authorization request with the given id. |
88 |
* @param id The id of the request. |
|
86 |
* |
|
87 |
* @param id The id of the request. |
|
89 | 88 |
* @param status The new status of the request. |
90 | 89 |
*/ |
91 |
public void updateAuthorization(long id, Status status) {
|
|
92 |
log.debug("Updating authorization request with id {} in a database to {}.", id, status); |
|
90 |
public void updateAuthorization(final long id, final Status status) {
|
|
91 |
RequestRepository.log.debug("Updating authorization request with id {} in a database to {}.", id, status);
|
|
93 | 92 |
|
94 |
jdbc.update("UPDATE end_user EU, approval_status APS SET EU.status_id=APS.id WHERE EU.id=? AND APS.name=?", id, status.name());
|
|
93 |
this.jdbc.update("UPDATE end_user SET status=? WHERE id=?", status.name(), id);
|
|
95 | 94 |
} |
96 | 95 |
|
97 | 96 |
/** |
98 | 97 |
* Updates a status of an authorization request from a BasicRequest object. |
98 |
* |
|
99 | 99 |
* @param request The BasicRequest object with new values of the vacation request. |
100 | 100 |
*/ |
101 |
public void updateAuthorization(BasicRequest request) { |
|
102 |
this.updateAuthorization(request.getId(), request.getStatus());
|
|
101 |
public void updateAuthorization(final BasicRequest request) {
|
|
102 |
updateAuthorization(request.getId(), request.getStatus()); |
|
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
/** |
106 | 106 |
* Updates a status of an authorization request from an AuthorizationRequest object. |
107 |
* |
|
107 | 108 |
* @param request The AuthorizationRequest object with new values of the authorization request. |
108 | 109 |
*/ |
109 |
public void updateAuthorization(AuthorizationRequest request) { |
|
110 |
this.updateAuthorization(request.getId(), request.getStatus());
|
|
110 |
public void updateAuthorization(final AuthorizationRequest request) {
|
|
111 |
updateAuthorization(request.getId(), request.getStatus()); |
|
111 | 112 |
} |
112 | 113 |
|
113 | 114 |
/** |
114 | 115 |
* Gets all vacation request from a database. |
116 |
* |
|
115 | 117 |
* @return A list of all vacation requests. |
116 | 118 |
*/ |
117 | 119 |
public List<VacationRequest> getAllVacationRequests() { |
118 |
log.trace("Selecting all vacation requests from a database."); |
|
120 |
RequestRepository.log.trace("Selecting all vacation requests from a database.");
|
|
119 | 121 |
|
120 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.creation_date, t.name, s.name, u.first_name, u.last_name " + |
|
121 |
"FROM vacation_day v " + |
|
122 |
"INNER JOIN vacation_type t on v.type_id = t.id " + |
|
123 |
"INNER JOIN approval_status s ON v.status_id = s.id " + |
|
124 |
"INNER JOIN end_user u ON v.user_id = u.id", |
|
122 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.creation_date, v.vacation_type, v.status, u.first_name, u.last_name " + |
|
123 |
"FROM vacation_day v " + |
|
124 |
"INNER JOIN end_user u ON v.user_id = u.id", |
|
125 | 125 |
(ResultSet rs, int rowNum) -> { |
126 |
VacationRequest request = new VacationRequest(); |
|
126 |
final VacationRequest request = new VacationRequest();
|
|
127 | 127 |
request.setId(rs.getLong("v.id")); |
128 | 128 |
request.setFirstName(rs.getString("u.first_name")); |
129 | 129 |
request.setLastName(rs.getString("u.last_name")); |
130 | 130 |
request.setDate(rs.getDate("v.vacation_date").toLocalDate()); |
131 |
Time timeFrom = rs.getTime("v.time_from"); |
|
132 |
if(timeFrom != null) { |
|
131 |
final Time timeFrom = rs.getTime("v.time_from");
|
|
132 |
if (timeFrom != null) {
|
|
133 | 133 |
request.setFrom(timeFrom.toLocalTime()); |
134 | 134 |
} |
135 | 135 |
|
136 |
Time timeTo = rs.getTime("v.time_to"); |
|
137 |
if(timeTo != null) { |
|
136 |
final Time timeTo = rs.getTime("v.time_to");
|
|
137 |
if (timeTo != null) {
|
|
138 | 138 |
request.setTo(timeTo.toLocalTime()); |
139 | 139 |
} |
140 |
|
|
140 | 141 |
request.setTimestamp(rs.getTimestamp("v.creation_date").toLocalDateTime()); |
141 |
request.setType(VacationType.getVacationType(rs.getString("t.name")));
|
|
142 |
request.setStatus(Status.getStatus(rs.getString("s.name")));
|
|
142 |
request.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
|
|
143 |
request.setStatus(Status.getStatus(rs.getString("v.status")));
|
|
143 | 144 |
return request; |
144 | 145 |
}); |
145 | 146 |
} |
146 | 147 |
|
147 | 148 |
/** |
148 | 149 |
* Gets all vacation request with the given status from a database. |
150 |
* |
|
149 | 151 |
* @param status The approval status of the requests. |
150 | 152 |
* @return A list of all vacation requests. |
151 | 153 |
*/ |
152 |
public List<VacationRequest> getAllVacationRequests(Status status) { |
|
153 |
log.debug("Selecting all vacation requests from a database with requested status: {}", status); |
|
154 |
|
|
155 |
if(status == null) throw new InvalidParameterException(); |
|
156 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.creation_date, t.name, s.name, u.first_name, u.last_name " + |
|
157 |
"FROM vacation_day v " + |
|
158 |
"INNER JOIN vacation_type t on v.type_id = t.id " + |
|
159 |
"INNER JOIN approval_status s ON v.status_id = s.id " + |
|
160 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
|
161 |
"WHERE s.name=?", |
|
154 |
public List<VacationRequest> getAllVacationRequests(final Status status) { |
|
155 |
RequestRepository.log.debug("Selecting all vacation requests from a database with requested status: {}", status); |
|
156 |
|
|
157 |
if (status == null) throw new InvalidParameterException(); |
|
158 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.creation_date, v.vacation_type, v.status, u.first_name, u.last_name " + |
|
159 |
"FROM vacation_day v " + |
|
160 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
|
161 |
"WHERE v.status=?", |
|
162 | 162 |
new Object[]{status.name()}, |
163 | 163 |
(ResultSet rs, int rowNum) -> { |
164 |
VacationRequest request = new VacationRequest(); |
|
164 |
final VacationRequest request = new VacationRequest();
|
|
165 | 165 |
request.setId(rs.getLong("v.id")); |
166 | 166 |
request.setFirstName(rs.getString("u.first_name")); |
167 | 167 |
request.setLastName(rs.getString("u.last_name")); |
168 | 168 |
request.setDate(rs.getDate("v.vacation_date").toLocalDate()); |
169 |
Time timeFrom = rs.getTime("v.time_from"); |
|
170 |
if(timeFrom != null) { |
|
169 |
final Time timeFrom = rs.getTime("v.time_from");
|
|
170 |
if (timeFrom != null) {
|
|
171 | 171 |
request.setFrom(timeFrom.toLocalTime()); |
172 | 172 |
} |
173 | 173 |
|
174 |
Time timeTo = rs.getTime("v.time_to"); |
|
175 |
if(timeTo != null) { |
|
174 |
final Time timeTo = rs.getTime("v.time_to");
|
|
175 |
if (timeTo != null) {
|
|
176 | 176 |
request.setTo(timeTo.toLocalTime()); |
177 | 177 |
} |
178 | 178 |
|
179 | 179 |
request.setTimestamp(rs.getTimestamp("v.creation_date").toLocalDateTime()); |
180 |
request.setType(VacationType.getVacationType(rs.getString("t.name")));
|
|
181 |
request.setStatus(Status.getStatus(rs.getString("s.name")));
|
|
180 |
request.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
|
|
181 |
request.setStatus(status);
|
|
182 | 182 |
return request; |
183 | 183 |
}); |
184 | 184 |
} |
185 | 185 |
|
186 | 186 |
/** |
187 | 187 |
* Updates a status of a vacation request with the given id. |
188 |
* @param id The id of the request. |
|
188 |
* |
|
189 |
* @param id The id of the request. |
|
189 | 190 |
* @param status The new status of the request. |
190 | 191 |
*/ |
191 |
public void updateVacationRequest(long id, Status status) {
|
|
192 |
log.debug("Updating vacation request with id {} in a database to {}.", id, status); |
|
192 |
public void updateVacationRequest(final long id, final Status status) {
|
|
193 |
RequestRepository.log.debug("Updating vacation request with id {} in a database to {}.", id, status);
|
|
193 | 194 |
|
194 |
jdbc.update("UPDATE vacation_day VD, approval_status APS SET VD.status_id=APS.id WHERE VD.id=? AND APS.name=?", id, status.name());
|
|
195 |
this.jdbc.update("UPDATE vacation_day SET status=? WHERE id=?", status.name(), id);
|
|
195 | 196 |
} |
196 | 197 |
|
197 | 198 |
/** |
198 | 199 |
* Updates a status of a vacation request from a BasicRequest object. |
200 |
* |
|
199 | 201 |
* @param request The BasicRequest object with new values of the vacation request. |
200 | 202 |
*/ |
201 |
public void updateVacationRequest(BasicRequest request) { |
|
202 |
this.updateVacationRequest(request.getId(), request.getStatus());
|
|
203 |
public void updateVacationRequest(final BasicRequest request) {
|
|
204 |
updateVacationRequest(request.getId(), request.getStatus()); |
|
203 | 205 |
} |
204 | 206 |
|
205 | 207 |
/** |
206 | 208 |
* Updates a status of a vacation request from a VacationRequest object. |
209 |
* |
|
207 | 210 |
* @param request The VacationRequest object with new values of the vacation request. |
208 | 211 |
*/ |
209 |
public void updateVacationRequest(VacationRequest request) { |
|
210 |
this.updateAuthorization(request.getId(), request.getStatus());
|
|
212 |
public void updateVacationRequest(final VacationRequest request) {
|
|
213 |
updateAuthorization(request.getId(), request.getStatus()); |
|
211 | 214 |
} |
212 | 215 |
} |
server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java | ||
---|---|---|
7 | 7 |
import org.springframework.jdbc.core.JdbcTemplate; |
8 | 8 |
import org.springframework.jdbc.core.SqlOutParameter; |
9 | 9 |
import org.springframework.jdbc.core.SqlParameter; |
10 |
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
|
11 |
import org.springframework.jdbc.core.simple.SimpleJdbcCall; |
|
12 | 10 |
import org.springframework.stereotype.Repository; |
13 | 11 |
|
14 | 12 |
import java.sql.*; |
... | ... | |
30 | 28 |
|
31 | 29 |
/** |
32 | 30 |
* Creates a new instance of the class UserRepository which selects and updates users in a database. |
31 |
* |
|
33 | 32 |
* @param jdbc A connection to the database. |
34 | 33 |
*/ |
35 | 34 |
@Autowired |
... | ... | |
50 | 49 |
} |
51 | 50 |
|
52 | 51 |
public List<BasicProfileUser> getAllBasicUsers(Status status) { |
53 |
if(status == null) throw new IllegalArgumentException(); |
|
54 |
|
|
55 |
return jdbc.query("SELECT u.id, u.first_name, u.last_name, u.photo" + |
|
56 |
"FROM end_user u " + |
|
57 |
"INNER JOIN approval_status s ON u.status_id = s.id " + |
|
58 |
"WHERE s.name = ?", |
|
52 |
return jdbc.query("SELECT id, first_name, last_name, photo FROM end_user WHERE status = ?", |
|
59 | 53 |
new Object[]{status.name()}, (ResultSet rs, int rowNum) -> { |
60 |
BasicProfileUser user = new BasicProfileUser(); |
|
61 |
user.setId(rs.getLong("u.id"));
|
|
62 |
user.setFirstName(rs.getString("u.first_name"));
|
|
63 |
user.setLastName(rs.getString("u.last_name"));
|
|
64 |
user.setPhoto(rs.getString("u.photo"));
|
|
65 |
return user; |
|
66 |
}); |
|
54 |
BasicProfileUser user = new BasicProfileUser();
|
|
55 |
user.setId(rs.getLong("id"));
|
|
56 |
user.setFirstName(rs.getString("first_name"));
|
|
57 |
user.setLastName(rs.getString("last_name"));
|
|
58 |
user.setPhoto(rs.getString("photo"));
|
|
59 |
return user;
|
|
60 |
});
|
|
67 | 61 |
} |
68 | 62 |
|
69 | 63 |
public FullUserProfile getFullUser(long id) { |
... | ... | |
101 | 95 |
}, paramList); |
102 | 96 |
|
103 | 97 |
FullUserProfile user = new FullUserProfile(); |
104 |
user.setId((Long)resultMap.get("out_id")); |
|
105 |
user.setFirstName((String)resultMap.get("out_first_name")); |
|
106 |
user.setLastName((String)resultMap.get("out_last_name")); |
|
107 |
user.setVacationCount(((Double)resultMap.get("out_no_vacations")).floatValue()); |
|
108 |
user.setSickdayCount((Integer)resultMap.get("out_no_sick_days")); |
|
109 |
user.setTakenSickdayCount((Integer)resultMap.get("out_taken_sick_days")); |
|
110 |
user.setNotification(((Timestamp)resultMap.get("out_alert")).toLocalDateTime()); |
|
111 |
user.setEmail((String)resultMap.get(("out_email"))); |
|
112 |
user.setPhoto((String)resultMap.get("out_photo")); |
|
113 |
user.setRole(UserRole.getUserRole((String)resultMap.get("out_role"))); |
|
114 |
user.setStatus(Status.getStatus((String)resultMap.get("out_status"))); |
|
98 |
user.setId(id); |
|
99 |
user.setFirstName((String) resultMap.get("out_first_name")); |
|
100 |
user.setLastName((String) resultMap.get("out_last_name")); |
|
101 |
user.setVacationCount(((Double) resultMap.get("out_no_vacations")).floatValue()); |
|
102 |
user.setSickdayCount((Integer) resultMap.get("out_no_sick_days")); |
|
103 |
user.setTakenSickdayCount((Integer) resultMap.get("out_taken_sick_days")); |
|
104 |
|
|
105 |
final Timestamp alertTimestamp = (Timestamp) resultMap.get(("out_alert")); |
|
106 |
if (alertTimestamp != null) { |
|
107 |
user.setNotification(alertTimestamp.toLocalDateTime()); |
|
108 |
} |
|
109 |
|
|
110 |
user.setEmail((String) resultMap.get(("out_email"))); |
|
111 |
user.setPhoto((String) resultMap.get("out_photo")); |
|
112 |
user.setRole(UserRole.getUserRole((String) resultMap.get("out_role"))); |
|
113 |
user.setStatus(Status.getStatus((String) resultMap.get("out_status"))); |
|
115 | 114 |
return user; |
116 | 115 |
|
117 | 116 |
} |
... | ... | |
151 | 150 |
}, paramList); |
152 | 151 |
|
153 | 152 |
FullUserProfile user = new FullUserProfile(); |
154 |
user.setId((Long)resultMap.get("out_id")); |
|
155 |
user.setFirstName((String)resultMap.get("out_first_name")); |
|
156 |
user.setLastName((String)resultMap.get("out_last_name")); |
|
157 |
user.setVacationCount(((Double)resultMap.get("out_no_vacations")).floatValue()); |
|
158 |
user.setSickdayCount((Integer)resultMap.get("out_no_sick_days")); |
|
159 |
user.setTakenSickdayCount((Integer)resultMap.get("out_taken_sick_days")); |
|
160 |
user.setNotification(((Timestamp)resultMap.get("out_alert")).toLocalDateTime()); |
|
161 |
user.setEmail((String)resultMap.get(("out_email"))); |
|
162 |
user.setPhoto((String)resultMap.get("out_photo")); |
|
163 |
user.setRole(UserRole.getUserRole((String)resultMap.get("out_role"))); |
|
164 |
user.setStatus(Status.getStatus((String)resultMap.get("out_status"))); |
|
153 |
user.setId((Long) resultMap.get("out_id")); |
|
154 |
user.setFirstName((String) resultMap.get("out_first_name")); |
|
155 |
user.setLastName((String) resultMap.get("out_last_name")); |
|
156 |
user.setVacationCount(((Double) resultMap.get("out_no_vacations")).floatValue()); |
|
157 |
user.setSickdayCount((Integer) resultMap.get("out_no_sick_days")); |
|
158 |
user.setTakenSickdayCount((Integer) resultMap.get("out_taken_sick_days")); |
|
159 |
|
|
160 |
final Timestamp alertTimestamp = (Timestamp) resultMap.get(("out_alert")); |
|
161 |
if (alertTimestamp != null) { |
|
162 |
user.setNotification(alertTimestamp.toLocalDateTime()); |
|
163 |
} |
|
164 |
|
|
165 |
user.setEmail((String) resultMap.get(("out_email"))); |
|
166 |
user.setPhoto((String) resultMap.get("out_photo")); |
|
167 |
user.setRole(UserRole.getUserRole((String) resultMap.get("out_role"))); |
|
168 |
user.setStatus(Status.getStatus((String) resultMap.get("out_status"))); |
|
165 | 169 |
return user; |
166 | 170 |
} |
167 | 171 |
|
168 | 172 |
public UserSettings getUserSettings(long id) { |
169 |
return jdbc.queryForObject("SELECT no_vacations, no_sick_days, role_id FROM end_user WHERE = id=?",
|
|
170 |
new Object[]{id}, (ResultSet rs, int rowNum)->{
|
|
171 |
UserSettings settings = new UserSettings(); |
|
172 |
settings.setId(id); |
|
173 |
settings.setSickdayCount(rs.getInt("no_sick_day")); |
|
174 |
settings.setVacationCount(rs.getFloat("no_vacations")); |
|
175 |
settings.setRole(UserRole.values()[rs.getByte("role_id")]);
|
|
176 |
return settings; |
|
177 |
}); |
|
173 |
return jdbc.queryForObject("SELECT no_vacations, no_sick_days, user_role FROM end_user WHERE = id=?",
|
|
174 |
new Object[]{id}, (ResultSet rs, int rowNum) -> {
|
|
175 |
UserSettings settings = new UserSettings();
|
|
176 |
settings.setId(id);
|
|
177 |
settings.setSickdayCount(rs.getInt("no_sick_day"));
|
|
178 |
settings.setVacationCount(rs.getFloat("no_vacations"));
|
|
179 |
settings.setRole(UserRole.getUserRole(rs.getString("user_role")));
|
|
180 |
return settings;
|
|
181 |
});
|
|
178 | 182 |
} |
179 | 183 |
|
180 | 184 |
public void updateNotification(UserSettings settings) { |
... | ... | |
182 | 186 |
} |
183 | 187 |
|
184 | 188 |
public void updateUserSettings(UserSettings settings) { |
185 |
jdbc.update("UPDATE end_user u, role r SET u.no_vacations=?, u.no_sick_days=?, u.role_id=r.id WHERE u.id = ? AND r.name=?",
|
|
186 |
settings.getVacationCount(), settings.getSickdayCount(), settings.getId(), settings.getRole().name());
|
|
189 |
jdbc.update("UPDATE end_user SET no_vacations=?, no_sick_days=?, user_role=? WHERE id = ?",
|
|
190 |
settings.getVacationCount(), settings.getSickdayCount(), settings.getRole().name(), settings.getId());
|
|
187 | 191 |
} |
188 | 192 |
|
189 | 193 |
public DefaultSettings getLastDefaultSettings() { |
server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
/** |
31 | 31 |
* Creates a new instance of the class VacationRepository which selects and updates users in a database. |
32 |
* |
|
32 | 33 |
* @param jdbc A connection to the database. |
33 | 34 |
*/ |
34 | 35 |
@Autowired |
35 |
public VacationRepository(JdbcTemplate jdbc) { |
|
36 |
log.trace("Creating a new instance of the class VacationRepository"); |
|
36 |
public VacationRepository(final JdbcTemplate jdbc) {
|
|
37 |
VacationRepository.log.trace("Creating a new instance of the class VacationRepository");
|
|
37 | 38 |
this.jdbc = jdbc; |
38 | 39 |
} |
39 | 40 |
|
40 |
public List<VacationDay> getVacationDays(String token, LocalDate from) { |
|
41 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
42 |
"FROM vacation_day VD " + |
|
43 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
44 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
45 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
46 |
"WHERE EU.token = ? AND VD.vacation_date >= ?", |
|
47 |
new Object[]{token, from}, (ResultSet rs, int rowNum) -> { |
|
48 |
VacationDay item = new VacationDay(); |
|
49 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
50 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
51 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
52 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
53 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
54 |
return item; |
|
55 |
}); |
|
56 |
} |
|
57 |
|
|
58 |
public List<VacationDay> getVacationDays(String token, LocalDate from, LocalDate to) { |
|
59 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
60 |
"FROM vacation_day VD " + |
|
61 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
62 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
63 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
64 |
"WHERE EU.token = ? AND VD.vacation_date >= ? AND VD.vacation_date <= ?", |
|
65 |
new Object[]{token, from, to}, (ResultSet rs, int rowNum) -> { |
|
66 |
VacationDay item = new VacationDay(); |
|
67 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
68 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
69 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
70 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
71 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
72 |
return item; |
|
73 |
}); |
|
74 |
} |
|
75 |
|
|
76 |
public List<VacationDay> getVacationDays(long userId, LocalDate from) { |
|
77 |
return jdbc.query("SELECT v.vacation_date, v.time_from, v.time_to, t.name, s.name " + |
|
41 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from) { |
|
42 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
78 | 43 |
"FROM vacation_day v " + |
79 | 44 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
80 |
"INNER JOIN vacation_type t ON v.type_id = t.id " + |
|
81 |
"INNER JOIN approval_status s ON v.status_id = s.id " + |
|
82 | 45 |
"WHERE v.user_id = ? AND v.vacation_date >= ?", |
83 | 46 |
new Object[]{userId, from}, (ResultSet rs, int rowNum) -> { |
84 |
VacationDay item = new VacationDay(); |
|
47 |
final VacationDay item = new VacationDay(); |
|
48 |
item.setId(rs.getLong("v.id")); |
|
85 | 49 |
item.setDate(rs.getDate("v.vacation_date").toLocalDate()); |
86 |
Time timeFrom = rs.getTime("v.time_from"); |
|
87 |
if(timeFrom != null) { |
|
50 |
final Time timeFrom = rs.getTime("v.time_from");
|
|
51 |
if (timeFrom != null) {
|
|
88 | 52 |
item.setFrom(timeFrom.toLocalTime()); |
89 | 53 |
} |
90 | 54 |
|
91 |
Time timeTo = rs.getTime("v.time_to"); |
|
92 |
if(timeTo != null) { |
|
55 |
final Time timeTo = rs.getTime("v.time_to");
|
|
56 |
if (timeTo != null) {
|
|
93 | 57 |
item.setTo(timeTo.toLocalTime()); |
94 | 58 |
} |
95 |
item.setType(VacationType.getVacationType(rs.getString("t.name"))); |
|
96 |
item.setStatus(Status.getStatus(rs.getString("s.name"))); |
|
59 |
|
|
60 |
item.setStatus(Status.getStatus(rs.getString("v.status"))); |
|
61 |
item.setType(VacationType.getVacationType(rs.getString("v.vacation_type"))); |
|
97 | 62 |
return item; |
98 | 63 |
}); |
99 | 64 |
} |
100 | 65 |
|
101 |
public List<VacationDay> getVacationDays(long userId, LocalDate from, Status status) { |
|
102 |
if(status == null) throw new IllegalArgumentException(); |
|
103 |
|
|
104 |
return jdbc.query("SELECT v.vacation_date, v.time_from, v.time_to, t.name, s.name " + |
|
66 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final Status status) { |
|
67 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
105 | 68 |
"FROM vacation_day v " + |
106 | 69 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
107 |
"INNER JOIN vacation_type t ON v.type_id = t.id " + |
|
108 |
"INNER JOIN approval_status s ON v.status_id = s.id " + |
|
109 |
"WHERE v.user_id = ? AND v.vacation_date >= ? AND s.name = ?", |
|
70 |
"WHERE v.user_id = ? AND v.vacation_date >= ? AND v.status = ?", |
|
110 | 71 |
new Object[]{userId, from, status.name()}, (ResultSet rs, int rowNum) -> { |
111 |
VacationDay item = new VacationDay(); |
|
72 |
final VacationDay item = new VacationDay(); |
|
73 |
item.setId(rs.getLong("v.id")); |
|
112 | 74 |
item.setDate(rs.getDate("v.vacation_date").toLocalDate()); |
113 |
Time timeFrom = rs.getTime("v.time_from"); |
|
114 |
if(timeFrom != null) { |
|
75 |
final Time timeFrom = rs.getTime("v.time_from");
|
|
76 |
if (timeFrom != null) {
|
|
115 | 77 |
item.setFrom(timeFrom.toLocalTime()); |
116 | 78 |
} |
117 | 79 |
|
118 |
Time timeTo = rs.getTime("v.time_to"); |
|
119 |
if(timeTo != null) { |
|
80 |
final Time timeTo = rs.getTime("v.time_to");
|
|
81 |
if (timeTo != null) {
|
|
120 | 82 |
item.setTo(timeTo.toLocalTime()); |
121 | 83 |
} |
122 |
item.setType(VacationType.getVacationType(rs.getString("t.name"))); |
|
123 |
item.setStatus(Status.getStatus(rs.getString("s.name"))); |
|
84 |
|
|
85 |
item.setStatus(Status.getStatus(rs.getString("v.status"))); |
|
86 |
item.setType(VacationType.getVacationType(rs.getString("v.vacation_type"))); |
|
124 | 87 |
return item; |
125 | 88 |
}); |
126 | 89 |
} |
127 | 90 |
|
128 |
public List<VacationDay> getVacationDays(long userId, LocalDate from, LocalDate to) {
|
|
129 |
return jdbc.query("SELECT v.vacation_date, v.time_from, v.time_to, t.name, s.name " +
|
|
91 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to) {
|
|
92 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
|
|
130 | 93 |
"FROM vacation_day v " + |
131 | 94 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
132 |
"INNER JOIN vacation_type t ON v.type_id = t.id " + |
|
133 |
"INNER JOIN approval_status s ON v.status_id = s.id " + |
|
134 | 95 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ?", |
135 | 96 |
new Object[]{userId, from, to}, (ResultSet rs, int rowNum) -> { |
136 |
VacationDay item = new VacationDay(); |
|
97 |
final VacationDay item = new VacationDay(); |
|
98 |
item.setId(rs.getLong("v.id")); |
|
137 | 99 |
item.setDate(rs.getDate("v.vacation_date").toLocalDate()); |
138 |
Time timeFrom = rs.getTime("v.time_from"); |
|
139 |
if(timeFrom != null) { |
|
100 |
final Time timeFrom = rs.getTime("v.time_from");
|
|
101 |
if (timeFrom != null) {
|
|
140 | 102 |
item.setFrom(timeFrom.toLocalTime()); |
141 | 103 |
} |
142 | 104 |
|
143 |
Time timeTo = rs.getTime("v.time_to"); |
|
144 |
if(timeTo != null) { |
|
105 |
final Time timeTo = rs.getTime("v.time_to");
|
|
106 |
if (timeTo != null) {
|
|
145 | 107 |
item.setTo(timeTo.toLocalTime()); |
146 | 108 |
} |
147 |
item.setType(VacationType.getVacationType(rs.getString("t.name"))); |
|
148 |
item.setStatus(Status.getStatus(rs.getString("s.name"))); |
|
109 |
|
|
110 |
item.setStatus(Status.getStatus(rs.getString("v.status"))); |
|
111 |
item.setType(VacationType.getVacationType(rs.getString("v.vacation_type"))); |
|
149 | 112 |
return item; |
150 | 113 |
}); |
151 | 114 |
|
152 | 115 |
} |
153 | 116 |
|
154 |
public List<VacationDay> getVacationDays(long userId, LocalDate from, LocalDate to, Status status) { |
|
155 |
if(status == null) throw new IllegalArgumentException(); |
|
156 |
|
|
157 |
return jdbc.query("SELECT v.vacation_date, v.time_from, v.time_to, t.name, s.name " + |
|
117 |
public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status) { |
|
118 |
return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
158 | 119 |
"FROM vacation_day v " + |
159 | 120 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
160 |
"INNER JOIN vacation_type t ON v.type_id = t.id " + |
|
161 |
"INNER JOIN approval_status s ON v.status_id = s.id " + |
|
162 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ? AND s.name = ?", |
|
121 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ? AND v.status = ?", |
|
163 | 122 |
new Object[]{userId, from, to, status.name()}, (ResultSet rs, int rowNum) -> { |
164 |
VacationDay item = new VacationDay(); |
|
123 |
final VacationDay item = new VacationDay(); |
|
124 |
item.setId(rs.getLong("v.id")); |
|
165 | 125 |
item.setDate(rs.getDate("v.vacation_date").toLocalDate()); |
166 | 126 |
|
167 |
Time timeFrom = rs.getTime("v.time_from"); |
|
168 |
if(timeFrom != null) { |
|
127 |
final Time timeFrom = rs.getTime("v.time_from");
|
|
128 |
if (timeFrom != null) {
|
|
169 | 129 |
item.setFrom(timeFrom.toLocalTime()); |
170 | 130 |
} |
171 | 131 |
|
172 |
Time timeTo = rs.getTime("v.time_to"); |
|
173 |
if(timeTo != null) { |
|
132 |
final Time timeTo = rs.getTime("v.time_to");
|
|
133 |
if (timeTo != null) {
|
|
174 | 134 |
item.setTo(timeTo.toLocalTime()); |
175 | 135 |
} |
176 | 136 |
|
177 |
item.setType(VacationType.getVacationType(rs.getString("t.name"))); |
|
178 | 137 |
item.setStatus(Status.getStatus(rs.getString("s.name"))); |
138 |
item.setType(VacationType.getVacationType(rs.getString("t.name"))); |
|
179 | 139 |
return item; |
180 | 140 |
}); |
181 | 141 |
} |
182 | 142 |
|
183 |
public void insertVacationDay(Long userId, VacationDay day) {
|
|
184 |
jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, user_id, status_id, type_id) VALUES (?,?,?,?,?,?)",
|
|
185 |
day.getDate(), day.getFrom(), day.getTo(), userId, 2, day.getType().ordinal() + 1);
|
|
143 |
public void insertVacationDay(final Long userId, final VacationDay day) {
|
|
144 |
this.jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)",
|
|
145 |
day.getDate(), day.getFrom(), day.getTo(), "pending", day.getType().name(), userId);
|
|
186 | 146 |
} |
187 | 147 |
|
188 |
public void updateVacationDay(VacationDay item) { |
|
189 |
jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status_id=?, type_id=? WHERE id=?",
|
|
190 |
item.getDate(), item.getFrom(), item.getTo(), item.getStatus().ordinal() + 1, item.getType().ordinal() + 1, item.getId());
|
|
148 |
public void updateVacationDay(final VacationDay item) {
|
|
149 |
this.jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?",
|
|
150 |
item.getDate(), item.getFrom(), item.getTo(), item.getStatus().name(), item.getType().name(), item.getId());
|
|
191 | 151 |
} |
192 | 152 |
|
193 |
public void deleteVacationDay(long id) { |
|
194 |
jdbc.update("DELETE FROM vacation_day WHERE id=?", id); |
|
153 |
public void deleteVacationDay(final long id) {
|
|
154 |
this.jdbc.update("DELETE FROM vacation_day WHERE id=?", id);
|
|
195 | 155 |
} |
196 | 156 |
} |
Také k dispozici: Unified diff
Deletion of enums from the database