Revize 6e79da77
Přidáno uživatelem Dominik Poch před téměř 6 roky(ů)
server/init.sql | ||
---|---|---|
37 | 37 |
first_name VARCHAR(45) NOT NULL, |
38 | 38 |
last_name VARCHAR(45) NOT NULL, |
39 | 39 |
no_vacations FLOAT, |
40 |
no_sick_days SMALLINT, |
|
40 |
no_sick_days INT, |
|
41 |
taken_vacations FLOAT NOT NULL, |
|
42 |
taken_sick_days INT NOT NULL, |
|
41 | 43 |
alert DATETIME, |
42 | 44 |
token TEXT NOT NULL, |
43 |
email VARCHAR(45) NOT NULL,
|
|
45 |
email VARCHAR(100) NOT NULL,
|
|
44 | 46 |
photo TEXT, |
45 | 47 |
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
46 | 48 |
role_id TINYINT NOT NULL, |
... | ... | |
54 | 56 |
CONSTRAINT fk_end_user_approval_status FOREIGN KEY (status_id) |
55 | 57 |
REFERENCES approval_status (id) |
56 | 58 |
ON DELETE NO ACTION ON UPDATE CASCADE, |
57 |
CONSTRAINT check_no_vacation CHECK (no_vacations >= 0), |
|
58 |
CONSTRAINT check_no_sick_days CHECK (no_sick_days >= 0), |
|
59 |
CONSTRAINT check_email CHECK (email = '%_@__%.__%') |
|
59 |
CONSTRAINT check_taken_vacation CHECK (taken_vacations >= 0), |
|
60 |
CONSTRAINT check_taken_sick_days CHECK (taken_sick_days >= 0) |
|
60 | 61 |
); |
61 | 62 |
|
62 | 63 |
-- ----------------------------------------------------- |
... | ... | |
75 | 76 |
PRIMARY KEY (id), |
76 | 77 |
INDEX fk_vacation_day_approval_status (status_id ASC), |
77 | 78 |
INDEX fk_vacation_day_end_user (user_id ASC), |
79 |
INDEX fk_vacation_day_vacation_type (type_id ASC), |
|
78 | 80 |
CONSTRAINT fk_vacation_day_approval_status FOREIGN KEY (status_id) |
79 | 81 |
REFERENCES approval_status (id) |
80 | 82 |
ON DELETE NO ACTION ON UPDATE CASCADE, |
81 | 83 |
CONSTRAINT fk_vacation_day_end_user FOREIGN KEY (user_id) |
82 | 84 |
REFERENCES end_user (id) |
83 | 85 |
ON DELETE CASCADE ON UPDATE CASCADE, |
86 |
CONSTRAINT fk_vacation_day_vacation_type FOREIGN KEY (type_id) |
|
87 |
REFERENCES vacation_type (id) |
|
88 |
ON DELETE CASCADE ON UPDATE CASCADE, |
|
84 | 89 |
CONSTRAINT check_time CHECK (time_from < time_to) |
85 | 90 |
); |
86 | 91 |
|
... | ... | |
90 | 95 |
DROP TABLE IF EXISTS default_settings; |
91 | 96 |
CREATE TABLE default_settings ( |
92 | 97 |
id BIGINT NOT NULL AUTO_INCREMENT, |
93 |
no_sick_days SMALLINT NOT NULL,
|
|
98 |
no_sick_days INT NOT NULL, |
|
94 | 99 |
alert DATETIME NOT NULL, |
95 | 100 |
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
96 | 101 |
PRIMARY KEY (id), |
97 | 102 |
CONSTRAINT check_no_sick_days CHECK (no_sick_days >= 0) |
98 | 103 |
); |
99 | 104 |
|
105 |
DELIMITER $$ |
|
106 |
DROP PROCEDURE IF EXISTS GetUserId $$ |
|
107 |
CREATE PROCEDURE GetUserId( |
|
108 |
IN in_id BIGINT, |
|
109 |
OUT out_id BIGINT, |
|
110 |
OUT out_first_name VARCHAR(45), |
|
111 |
OUT out_last_name VARCHAR(45), |
|
112 |
OUT out_no_vacations FLOAT, |
|
113 |
OUT out_no_sick_days INT, |
|
114 |
OUT out_taken_vacations FLOAT, |
|
115 |
OUT out_taken_sick_days INT, |
|
116 |
OUT out_alert DATETIME, |
|
117 |
OUT out_email VARCHAR(100), |
|
118 |
OUT out_photo TEXT, |
|
119 |
OUT out_creation_date DATETIME, |
|
120 |
OUT out_role VARCHAR(8), |
|
121 |
OUT out_status VARCHAR(8)) |
|
122 |
BEGIN |
|
123 |
DECLARE sickDaysCount INT; |
|
124 |
DECLARE notification DATETIME; |
|
125 |
|
|
126 |
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1; |
|
127 |
SELECT EU.id, EU.first_name, EU.last_name, EU.no_vacation, IFNULL(EU.no_sick_days, sickDaysCount), EU.taken_vacations, EU.taken_sick_days, IFNULL(EU.alert, notification), EU.email, EU.photo, EU.creation_date, R.name, APS.name |
|
128 |
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_vacations, out_taken_sick_days, out_alert, out_email, out_photo, out_creation_date, out_role, out_status |
|
129 |
FROM end_user EU |
|
130 |
INNER JOIN role R ON EU.role_id=R.id |
|
131 |
INNER JOIN approval_status APS ON EU.status_id=APS.id |
|
132 |
WHERE EU.id=in_id; |
|
133 |
END $$ |
|
134 |
|
|
135 |
DROP PROCEDURE IF EXISTS GetUserToken $$ |
|
136 |
CREATE PROCEDURE GetUserToken( |
|
137 |
IN p_token TEXT, |
|
138 |
OUT out_id BIGINT, |
|
139 |
OUT out_first_name VARCHAR(45), |
|
140 |
OUT out_last_name VARCHAR(45), |
|
141 |
OUT out_no_vacations FLOAT, |
|
142 |
OUT out_no_sick_days INT, |
|
143 |
OUT out_taken_vacations FLOAT, |
|
144 |
OUT out_taken_sick_days INT, |
|
145 |
OUT out_alert DATETIME, |
|
146 |
OUT out_email VARCHAR(100), |
|
147 |
OUT out_photo TEXT, |
|
148 |
OUT out_creation_date DATETIME, |
|
149 |
OUT out_role VARCHAR(8), |
|
150 |
OUT out_status VARCHAR(8)) |
|
151 |
BEGIN |
|
152 |
DECLARE sickDaysCount INT; |
|
153 |
DECLARE notification DATETIME; |
|
154 |
|
|
155 |
SELECT no_sick_days, alert INTO sickDaysCount, notification FROM default_settings ORDER BY id DESC LIMIT 1; |
|
156 |
SELECT EU.id, EU.first_name, EU.last_name, EU.no_vacation, IFNULL(EU.no_sick_days, sickDaysCount), EU.taken_vacations, EU.taken_sick_days, IFNULL(EU.alert, notification), EU.email, EU.photo, EU.creation_date, R.name, APS.name |
|
157 |
INTO out_id, out_first_name, out_last_name, out_no_vacations, out_no_sick_days, out_taken_vacations, out_taken_sick_days, out_alert, out_email, out_photo, out_creation_date, out_role, out_status |
|
158 |
FROM end_user EU |
|
159 |
INNER JOIN role R ON EU.role_id=R.id |
|
160 |
INNER JOIN approval_status APS ON EU.status_id=APS.id |
|
161 |
WHERE EU.token=p_token; |
|
162 |
END $$ |
|
163 |
|
|
164 |
DELIMITER ; |
|
165 |
|
|
100 | 166 |
-- ----------------------------------------------------- |
101 | 167 |
-- Insert table role |
102 | 168 |
-- ----------------------------------------------------- |
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.business; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.*; |
|
4 |
import cz.zcu.yamanager.repository.RequestRepository; |
|
5 |
import cz.zcu.yamanager.repository.UserRepository; |
|
6 |
import cz.zcu.yamanager.repository.VacationRepository; |
|
7 |
import cz.zcu.yamanager.ws.rest.RESTFullException; |
|
8 |
import org.apache.tomcat.jni.Local; |
|
9 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
10 |
|
|
11 |
import java.time.LocalDate; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
public class ApiManager implements Manager { |
|
15 |
|
|
16 |
private static final int DAYS_IN_WEEK = 7; |
|
17 |
|
|
18 |
private RequestRepository requestRepository; |
|
19 |
private UserRepository userRepository; |
|
20 |
private VacationRepository vacationRepository; |
|
21 |
|
|
22 |
public ApiManager(JdbcTemplate jdbc) { |
|
23 |
this.requestRepository = new RequestRepository(jdbc); |
|
24 |
this.userRepository = new UserRepository(jdbc); |
|
25 |
this.vacationRepository = new VacationRepository(jdbc); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public List<BasicProfileUser> getUsers(Status status) throws RESTFullException { |
|
30 |
List<BasicProfileUser> users = this.userRepository.getAllBasicUsers(); |
|
31 |
LocalDate today = LocalDate.now(); |
|
32 |
LocalDate weekBefore = today.minusDays(ApiManager.DAYS_IN_WEEK); |
|
33 |
LocalDate weekAfter = today.plusDays(ApiManager.DAYS_IN_WEEK); |
|
34 |
for (BasicProfileUser user : users) { |
|
35 |
user.setCalendar(this.vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter)); |
|
36 |
} |
|
37 |
|
|
38 |
return users; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public List<VacationRequest> getVacationRequests(Status status) throws RESTFullException { |
|
43 |
return this.requestRepository.getAllVacationRequests(status); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public List<AuthorizationRequest> getAuthorizationRequests(Status status) throws RESTFullException { |
|
48 |
return this.requestRepository.getAllAuthorizations(status); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public FullUserProfile getUserProfile(Long userId) throws RESTFullException { |
|
53 |
return this.userRepository.getFullUser(userId); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public DefaultSettings getDefaultSettings() throws RESTFullException { |
|
58 |
return this.userRepository.getLastDefaultSettings(); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public List<VacationDay> getUserCalendar(Long userId, LocalDate fromDate, LocalDate toDate, Status status) throws RESTFullException { |
|
63 |
return this.vacationRepository.getVacationDays(userId, fromDate, toDate, status); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public void createSettings(DefaultSettings settings) throws RESTFullException { |
|
68 |
this.userRepository.insertSettings(settings); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
|
73 |
//this.vacationRepository. |
|
74 |
// TODO |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public void changeSettings(Long userId, UserSettings settings) throws RESTFullException { |
|
79 |
this.userRepository.updateUserSettings(settings); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
|
84 |
this.vacationRepository.updateVacationDay(vacationDay); |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void changeRequest(RequestType type, BasicRequest request) throws RESTFullException { |
|
89 |
if(RequestType.VACATION == type) { |
|
90 |
this.requestRepository.updateVacationRequest(request); |
|
91 |
} else { |
|
92 |
this.requestRepository.updateAuthorization(request); |
|
93 |
} |
|
94 |
|
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public void deleteVacation(Long userId, Long vacationId) throws RESTFullException { |
|
99 |
this.vacationRepository.deleteVacationDay(vacationId); |
|
100 |
} |
|
101 |
} |
server/src/main/java/cz/zcu/yamanager/dto/FullUserProfile.java | ||
---|---|---|
11 | 11 |
private String photo; |
12 | 12 |
private Float vacationCount; |
13 | 13 |
private Integer sickdayCount; |
14 |
private Float takenVacationCount; |
|
15 |
private Integer takenSickdayCount; |
|
14 | 16 |
private Status status; |
15 | 17 |
private UserRole role; |
16 | 18 |
private LocalDateTime notification; |
19 |
private String email; |
|
20 |
|
|
21 |
public String getEmail() { |
|
22 |
return email; |
|
23 |
} |
|
24 |
|
|
25 |
public void setEmail(String email) { |
|
26 |
this.email = email; |
|
27 |
} |
|
17 | 28 |
|
18 | 29 |
public Long getId() { |
19 | 30 |
return id; |
... | ... | |
27 | 38 |
return firstName; |
28 | 39 |
} |
29 | 40 |
|
41 |
public Float getTakenVacationCount() { |
|
42 |
return takenVacationCount; |
|
43 |
} |
|
44 |
|
|
45 |
public void setTakenVacationCount(Float takenVacationCount) { |
|
46 |
this.takenVacationCount = takenVacationCount; |
|
47 |
} |
|
48 |
|
|
49 |
public Integer getTakenSickdayCount() { |
|
50 |
return takenSickdayCount; |
|
51 |
} |
|
52 |
|
|
53 |
public void setTakenSickdayCount(Integer takenSickdayCount) { |
|
54 |
this.takenSickdayCount = takenSickdayCount; |
|
55 |
} |
|
56 |
|
|
30 | 57 |
public void setFirstName(String firstName) { |
31 | 58 |
this.firstName = firstName; |
32 | 59 |
} |
server/src/main/java/cz/zcu/yamanager/dto/Status.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.dto; |
2 | 2 |
|
3 | 3 |
public enum Status { |
4 |
ACCEPTED, PENDING, REJECTED |
|
4 |
ACCEPTED, PENDING, REJECTED;
|
|
5 | 5 |
|
6 |
; |
|
7 | 6 |
public static Status getStatus(String status) { |
8 | 7 |
if (status == null || status.isEmpty()) return null; |
9 | 8 |
try { |
server/src/main/java/cz/zcu/yamanager/dto/UserRole.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.dto; |
2 | 2 |
|
3 | 3 |
public enum UserRole { |
4 |
EMPLOYEE, EMPLOYER |
|
4 |
EMPLOYEE, EMPLOYER; |
|
5 |
|
|
6 |
public static UserRole getUserRole(String role) { |
|
7 |
if (role == null || role.isEmpty()) return null; |
|
8 |
try { |
|
9 |
return valueOf(role.toUpperCase()); |
|
10 |
} catch (IllegalArgumentException e) { |
|
11 |
return null; |
|
12 |
} |
|
13 |
} |
|
5 | 14 |
} |
server/src/main/java/cz/zcu/yamanager/dto/VacationType.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.dto; |
2 | 2 |
|
3 | 3 |
public enum VacationType { |
4 |
VACATION, SICKDAY |
|
4 |
VACATION, SICKDAY; |
|
5 |
|
|
6 |
public static VacationType getVacationType(String type) { |
|
7 |
if (type == null || type.isEmpty()) return null; |
|
8 |
try { |
|
9 |
return valueOf(type.toUpperCase()); |
|
10 |
} catch (IllegalArgumentException e) { |
|
11 |
return null; |
|
12 |
} |
|
13 |
} |
|
5 | 14 |
} |
server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.repository; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.*; |
|
4 |
import org.slf4j.Logger; |
|
5 |
import org.slf4j.LoggerFactory; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
8 |
import org.springframework.stereotype.Repository; |
|
9 |
|
|
10 |
import java.sql.ResultSet; |
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
/** |
|
14 |
* An instance of the class RequestRepository handles queries which selects and updates requests in a database. |
|
15 |
*/ |
|
16 |
@Repository |
|
17 |
public class RequestRepository { |
|
18 |
/** |
|
19 |
* The logger. |
|
20 |
*/ |
|
21 |
private static final Logger log = LoggerFactory.getLogger(RequestRepository.class); |
|
22 |
|
|
23 |
/** |
|
24 |
* The connection to a database. |
|
25 |
*/ |
|
26 |
private final JdbcTemplate jdbc; |
|
27 |
|
|
28 |
/** |
|
29 |
* Creates a new instance of the class RequestRepository which selects and updates requests in a database. |
|
30 |
* @param jdbc A connection to the database. |
|
31 |
*/ |
|
32 |
@Autowired |
|
33 |
public RequestRepository(JdbcTemplate jdbc) { |
|
34 |
log.trace("Creating a new instance of the class RequestRepository"); |
|
35 |
this.jdbc = jdbc; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Gets all authorization request from a database. |
|
40 |
* @return A list of all authorization requests. |
|
41 |
*/ |
|
42 |
public List<AuthorizationRequest> getAllAuthorizations() { |
|
43 |
log.trace("Selecting all authorization requests from a database."); |
|
44 |
|
|
45 |
return jdbc.query("SELECT EU.id, EU.first_name, EU.last_name, EU.creation_date, APS.name " + |
|
46 |
"FROM end_user EU " + |
|
47 |
"INNER JOIN approval_status APS ON EU.status_id = APS.id", |
|
48 |
(ResultSet rs, int rowNum) -> { |
|
49 |
AuthorizationRequest request = new AuthorizationRequest(); |
|
50 |
request.setId(rs.getLong("EU.id")); |
|
51 |
request.setFirstName(rs.getString("EU.first_name")); |
|
52 |
request.setLastName(rs.getString("EU.last_name")); |
|
53 |
request.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
54 |
request.setTimestamp(rs.getTimestamp("EU.creation_date").toLocalDateTime()); |
|
55 |
return request; |
|
56 |
}); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Gets all authorization request with the given status from a database. |
|
61 |
* @param status The approval status of the requests. |
|
62 |
* @return A list of all authorization requests. |
|
63 |
*/ |
|
64 |
public List<AuthorizationRequest> getAllAuthorizations(Status status) { |
|
65 |
log.debug("Selecting all authorization requests from a database with requested status: {}", status); |
|
66 |
|
|
67 |
return jdbc.query("SELECT EU.id, EU.first_name, EU.last_name, EU.creation_date " + |
|
68 |
"FROM end_user EU " + |
|
69 |
"INNER JOIN approval_status APS ON EU.status_id = APS.id " + |
|
70 |
"WHERE APS.name=?", |
|
71 |
new Object[]{status.name()}, |
|
72 |
(ResultSet rs, int rowNum) -> { |
|
73 |
AuthorizationRequest request = new AuthorizationRequest(); |
|
74 |
request.setId(rs.getLong("EU.id")); |
|
75 |
request.setFirstName(rs.getString("EU.first_name")); |
|
76 |
request.setLastName(rs.getString("EU.last_name")); |
|
77 |
request.setStatus(status); |
|
78 |
request.setTimestamp(rs.getTimestamp("EU.creation_date").toLocalDateTime()); |
|
79 |
return request; |
|
80 |
}); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Updates a status of an authorization request with the given id. |
|
85 |
* @param id The id of the request. |
|
86 |
* @param status The new status of the request. |
|
87 |
*/ |
|
88 |
public void updateAuthorization(long id, Status status) { |
|
89 |
log.debug("Updating authorization request with id {} in a database to {}.", id, status); |
|
90 |
|
|
91 |
jdbc.update("UPDATE end_user EU, approval_status APS SET EU.status_id=APS.id WHERE EU.id=? AND APS.name=?", id, status.name()); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Updates a status of an authorization request from a BasicRequest object. |
|
96 |
* @param request The BasicRequest object with new values of the vacation request. |
|
97 |
*/ |
|
98 |
public void updateAuthorization(BasicRequest request) { |
|
99 |
this.updateAuthorization(request.getId(), request.getStatus()); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Updates a status of an authorization request from an AuthorizationRequest object. |
|
104 |
* @param request The AuthorizationRequest object with new values of the authorization request. |
|
105 |
*/ |
|
106 |
public void updateAuthorization(AuthorizationRequest request) { |
|
107 |
this.updateAuthorization(request.getId(), request.getStatus()); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Gets all vacation request from a database. |
|
112 |
* @return A list of all vacation requests. |
|
113 |
*/ |
|
114 |
public List<VacationRequest> getAllVacationRequests() { |
|
115 |
log.trace("Selecting all vacation requests from a database."); |
|
116 |
|
|
117 |
return jdbc.query("SELECT VD.id, VD.vacation_date, VD.time_from, VD.time_to, VD.creation_date, VT.name, APS.name, EU.first_name, EU.last_name " + |
|
118 |
"FROM vacation_day VD " + |
|
119 |
"INNER JOIN vacation_type VT on VD.type_id=VT.id " + |
|
120 |
"INNER JOIN approval_status APS ON VD.status_id=APS.id" + |
|
121 |
"INNER JOIN end_user EU ON VD.user_id=EU.id", |
|
122 |
(ResultSet rs, int rowNum) -> { |
|
123 |
VacationRequest request = new VacationRequest(); |
|
124 |
request.setId(rs.getLong("VD.id")); |
|
125 |
request.setFirstName(rs.getString("EU.first_name")); |
|
126 |
request.setLastName(rs.getString("EU.last_name")); |
|
127 |
request.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
128 |
request.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
129 |
request.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
130 |
request.setType(VacationType.getVacationType("VT.name")); |
|
131 |
request.setStatus(Status.getStatus("APS.name")); |
|
132 |
return request; |
|
133 |
}); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Gets all vacation request with the given status from a database. |
|
138 |
* @param status The approval status of the requests. |
|
139 |
* @return A list of all vacation requests. |
|
140 |
*/ |
|
141 |
public List<VacationRequest> getAllVacationRequests(Status status) { |
|
142 |
log.debug("Selecting all vacation requests from a database with requested status: {}", status); |
|
143 |
|
|
144 |
return jdbc.query("SELECT VD.id, VD.vacation_date, VD.time_from, VD.time_to, VD.creation_date, VT.name, APS.name, EU.first_name, EU.last_name " + |
|
145 |
"FROM vacation_day VD " + |
|
146 |
"INNER JOIN vacation_type VT on VD.type_id=VT.id " + |
|
147 |
"INNER JOIN approval_status APS ON VD.status_id=APS.id" + |
|
148 |
"INNER JOIN end_user EU ON VD.user_id=EU.id" + |
|
149 |
"WHERE APS.name=?", |
|
150 |
new Object[]{status.name()}, |
|
151 |
(ResultSet rs, int rowNum) -> { |
|
152 |
VacationRequest request = new VacationRequest(); |
|
153 |
request.setId(rs.getLong("VD.id")); |
|
154 |
request.setFirstName(rs.getString("EU.first_name")); |
|
155 |
request.setLastName(rs.getString("EU.last_name")); |
|
156 |
request.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
157 |
request.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
158 |
request.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
159 |
request.setType(VacationType.getVacationType("VT.name")); |
|
160 |
request.setStatus(status); |
|
161 |
return request; |
|
162 |
}); |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Updates a status of a vacation request with the given id. |
|
167 |
* @param id The id of the request. |
|
168 |
* @param status The new status of the request. |
|
169 |
*/ |
|
170 |
public void updateVacationRequest(long id, Status status) { |
|
171 |
log.debug("Updating vacation request with id {} in a database to {}.", id, status); |
|
172 |
|
|
173 |
jdbc.update("UPDATE vacation_day VD, approval_status APS SET VD.status_id=APS.id WHERE VD.id=? AND APS.name=?", id, status.name()); |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Updates a status of a vacation request from a BasicRequest object. |
|
178 |
* @param request The BasicRequest object with new values of the vacation request. |
|
179 |
*/ |
|
180 |
public void updateVacationRequest(BasicRequest request) { |
|
181 |
this.updateVacationRequest(request.getId(), request.getStatus()); |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Updates a status of a vacation request from a VacationRequest object. |
|
186 |
* @param request The VacationRequest object with new values of the vacation request. |
|
187 |
*/ |
|
188 |
public void updateVacationRequest(VacationRequest request) { |
|
189 |
this.updateAuthorization(request.getId(), request.getStatus()); |
|
190 |
} |
|
191 |
} |
server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.repository; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.*; |
|
4 |
import org.slf4j.Logger; |
|
5 |
import org.slf4j.LoggerFactory; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
8 |
import org.springframework.jdbc.core.SqlOutParameter; |
|
9 |
import org.springframework.jdbc.core.SqlParameter; |
|
10 |
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
|
11 |
import org.springframework.jdbc.core.simple.SimpleJdbcCall; |
|
12 |
import org.springframework.stereotype.Repository; |
|
13 |
|
|
14 |
import java.sql.CallableStatement; |
|
15 |
import java.sql.ResultSet; |
|
16 |
import java.sql.Timestamp; |
|
17 |
import java.sql.Types; |
|
18 |
import java.util.ArrayList; |
|
19 |
import java.util.List; |
|
20 |
import java.util.Map; |
|
21 |
|
|
22 |
@Repository |
|
23 |
public class UserRepository { |
|
24 |
/** |
|
25 |
* The logger. |
|
26 |
*/ |
|
27 |
private static final Logger log = LoggerFactory.getLogger(UserRepository.class); |
|
28 |
|
|
29 |
/** |
|
30 |
* The connection to a database. |
|
31 |
*/ |
|
32 |
private final JdbcTemplate jdbc; |
|
33 |
|
|
34 |
/** |
|
35 |
* Creates a new instance of the class UserRepository which selects and updates users in a database. |
|
36 |
* @param jdbc A connection to the database. |
|
37 |
*/ |
|
38 |
@Autowired |
|
39 |
public UserRepository(JdbcTemplate jdbc) { |
|
40 |
log.trace("Creating a new instance of the class UserRepository"); |
|
41 |
this.jdbc = jdbc; |
|
42 |
} |
|
43 |
|
|
44 |
public List<BasicProfileUser> getAllBasicUsers() { |
|
45 |
return jdbc.query("SELECT id, first_name, last_name, photo FROM end_user", (ResultSet rs, int rowNum) -> { |
|
46 |
BasicProfileUser user = new BasicProfileUser(); |
|
47 |
user.setId(rs.getLong("id")); |
|
48 |
user.setFirstName(rs.getString("first_name")); |
|
49 |
user.setLastName(rs.getString("last_name")); |
|
50 |
user.setPhoto(rs.getString("photo")); |
|
51 |
return user; |
|
52 |
}); |
|
53 |
} |
|
54 |
|
|
55 |
public FullUserProfile getFullUser(long id) { |
|
56 |
List<SqlParameter> paramList = new ArrayList<>(); |
|
57 |
paramList.add(new SqlParameter(Types.BIGINT)); |
|
58 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
59 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
60 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
61 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
62 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
63 |
paramList.add(new SqlOutParameter("out_taken_vacations", Types.FLOAT)); |
|
64 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
65 |
paramList.add(new SqlOutParameter("out_alert", Types.DATE)); |
|
66 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
67 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
68 |
paramList.add(new SqlOutParameter("out_creation_date", Types.DATE)); |
|
69 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
70 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
71 |
|
|
72 |
Map<String, Object> resultMap = this.jdbc.call(con -> { |
|
73 |
CallableStatement callableStatement = con.prepareCall("{call GetUserId(?)}"); |
|
74 |
callableStatement.setLong(1, id); |
|
75 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
76 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
77 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
78 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
79 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
80 |
callableStatement.registerOutParameter(7, Types.FLOAT); |
|
81 |
callableStatement.registerOutParameter(8, Types.INTEGER); |
|
82 |
callableStatement.registerOutParameter(9, Types.DATE); |
|
83 |
callableStatement.registerOutParameter(10, Types.VARCHAR); |
|
84 |
callableStatement.registerOutParameter(11, Types.LONGNVARCHAR); |
|
85 |
callableStatement.registerOutParameter(12, Types.DATE); |
|
86 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
87 |
callableStatement.registerOutParameter(14, Types.VARCHAR); |
|
88 |
return callableStatement; |
|
89 |
}, paramList); |
|
90 |
|
|
91 |
FullUserProfile user = new FullUserProfile(); |
|
92 |
user.setId((long)resultMap.get("out_id")); |
|
93 |
user.setFirstName((String)resultMap.get("out_first_name")); |
|
94 |
user.setLastName((String)resultMap.get("out_last_name")); |
|
95 |
user.setVacationCount((float)resultMap.get("out_no_vacations")); |
|
96 |
user.setSickdayCount((int)resultMap.get("out_no_sick_days")); |
|
97 |
user.setTakenVacationCount((float)resultMap.get("out_taken_vacations")); |
|
98 |
user.setTakenSickdayCount((int)resultMap.get("out_taken_sick_days")); |
|
99 |
user.setNotification(((Timestamp)resultMap.get("out_alert")).toLocalDateTime()); |
|
100 |
user.setEmail((String)resultMap.get(("out_email"))); |
|
101 |
user.setPhoto((String)resultMap.get("out_photo")); |
|
102 |
user.setRole(UserRole.getUserRole((String)resultMap.get("out_role_id"))); |
|
103 |
user.setStatus(Status.getStatus((String)resultMap.get("out_status_id"))); |
|
104 |
return user; |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
public FullUserProfile getFullUser(String token) { |
|
109 |
List<SqlParameter> paramList = new ArrayList<>(); |
|
110 |
paramList.add(new SqlParameter(Types.LONGNVARCHAR)); |
|
111 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
112 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
113 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
114 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
115 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
116 |
paramList.add(new SqlOutParameter("out_taken_vacations", Types.FLOAT)); |
|
117 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
118 |
paramList.add(new SqlOutParameter("out_alert", Types.DATE)); |
|
119 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
120 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
121 |
paramList.add(new SqlOutParameter("out_creation_date", Types.DATE)); |
|
122 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
123 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
124 |
|
|
125 |
Map<String, Object> resultMap = this.jdbc.call(con -> { |
|
126 |
CallableStatement callableStatement = con.prepareCall("{call GetUserToken(?)}"); |
|
127 |
callableStatement.setString(1, token); |
|
128 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
129 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
130 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
131 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
132 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
133 |
callableStatement.registerOutParameter(7, Types.FLOAT); |
|
134 |
callableStatement.registerOutParameter(8, Types.INTEGER); |
|
135 |
callableStatement.registerOutParameter(9, Types.DATE); |
|
136 |
callableStatement.registerOutParameter(10, Types.VARCHAR); |
|
137 |
callableStatement.registerOutParameter(11, Types.LONGNVARCHAR); |
|
138 |
callableStatement.registerOutParameter(12, Types.DATE); |
|
139 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
140 |
callableStatement.registerOutParameter(14, Types.VARCHAR); |
|
141 |
return callableStatement; |
|
142 |
}, paramList); |
|
143 |
|
|
144 |
FullUserProfile user = new FullUserProfile(); |
|
145 |
user.setId((long)resultMap.get("out_id")); |
|
146 |
user.setFirstName((String)resultMap.get("out_first_name")); |
|
147 |
user.setLastName((String)resultMap.get("out_last_name")); |
|
148 |
user.setVacationCount((float)resultMap.get("out_no_vacations")); |
|
149 |
user.setSickdayCount((int)resultMap.get("out_no_sick_days")); |
|
150 |
user.setTakenVacationCount((float)resultMap.get("out_taken_vacations")); |
|
151 |
user.setTakenSickdayCount((int)resultMap.get("out_taken_sick_days")); |
|
152 |
user.setNotification(((Timestamp)resultMap.get("out_alert")).toLocalDateTime()); |
|
153 |
user.setEmail((String)resultMap.get(("out_email"))); |
|
154 |
user.setPhoto((String)resultMap.get("out_photo")); |
|
155 |
user.setRole(UserRole.getUserRole((String)resultMap.get("out_role_id"))); |
|
156 |
user.setStatus(Status.getStatus((String)resultMap.get("out_status_id"))); |
|
157 |
return user; |
|
158 |
} |
|
159 |
|
|
160 |
public UserSettings getUserSettings(long id) { |
|
161 |
return jdbc.queryForObject("SELECT no_vacations, no_sick_days, role_id FROM end_user WHERE = id=?", |
|
162 |
new Object[]{id}, (ResultSet rs, int rowNum)->{ |
|
163 |
UserSettings settings = new UserSettings(); |
|
164 |
settings.setId(id); |
|
165 |
settings.setSickdayCount(rs.getInt("no_sick_day")); |
|
166 |
settings.setVacationCount(rs.getFloat("no_vacations")); |
|
167 |
settings.setRole(UserRole.values()[rs.getByte("role_id")]); |
|
168 |
return settings; |
|
169 |
}); |
|
170 |
} |
|
171 |
|
|
172 |
public void updateUserSettings(UserSettings settings) { |
|
173 |
jdbc.update("UPDATE end_user EU, role R SET EU.no_vacations=?, EU.no_sick_days=?, EU.role_id=R.id WHERE EU.id = ? AND R.name=?", |
|
174 |
settings.getVacationCount(), settings.getSickdayCount(), settings.getId(), settings.getRole().name()); |
|
175 |
} |
|
176 |
|
|
177 |
public DefaultSettings getLastDefaultSettings() { |
|
178 |
return jdbc.queryForObject("SELECT * FROM default_settings ORDER BY id DESC LIMIT 1", (ResultSet rs, int rowNum) -> { |
|
179 |
DefaultSettings settings = new DefaultSettings(); |
|
180 |
settings.setSickdayCount(rs.getInt("no_sick_days")); |
|
181 |
settings.setNotification(rs.getTimestamp("alert").toLocalDateTime()); |
|
182 |
return settings; |
|
183 |
}); |
|
184 |
} |
|
185 |
|
|
186 |
public void insertSettings(DefaultSettings settings) { |
|
187 |
jdbc.update("INSERT INTO default_settings (no_sick_days, alert) VALUES (?, ?)", settings.getSickdayCount(), settings.getNotification()); |
|
188 |
} |
|
189 |
} |
server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.repository; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.VacationDay; |
|
5 |
import cz.zcu.yamanager.dto.VacationType; |
|
6 |
|
|
7 |
import org.slf4j.Logger; |
|
8 |
import org.slf4j.LoggerFactory; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
11 |
import org.springframework.stereotype.Repository; |
|
12 |
|
|
13 |
import java.sql.ResultSet; |
|
14 |
import java.time.LocalDate; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
@Repository |
|
18 |
public class VacationRepository { |
|
19 |
/** |
|
20 |
* The logger. |
|
21 |
*/ |
|
22 |
private static final Logger log = LoggerFactory.getLogger(VacationRepository.class); |
|
23 |
|
|
24 |
/** |
|
25 |
* The connection to a database. |
|
26 |
*/ |
|
27 |
private final JdbcTemplate jdbc; |
|
28 |
|
|
29 |
/** |
|
30 |
* Creates a new instance of the class VacationRepository which selects and updates users in a database. |
|
31 |
* @param jdbc A connection to the database. |
|
32 |
*/ |
|
33 |
@Autowired |
|
34 |
public VacationRepository(JdbcTemplate jdbc) { |
|
35 |
log.trace("Creating a new instance of the class VacationRepository"); |
|
36 |
this.jdbc = jdbc; |
|
37 |
} |
|
38 |
|
|
39 |
public List<VacationDay> getVacationDays(String token, LocalDate from) { |
|
40 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
41 |
"FROM vacation_day VD " + |
|
42 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
43 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
44 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
45 |
"WHERE EU.token = ? AND VD.vacation_date >= ?", |
|
46 |
new Object[]{token, from}, (ResultSet rs, int rowNum) -> { |
|
47 |
VacationDay item = new VacationDay(); |
|
48 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
49 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
50 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
51 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
52 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
53 |
return item; |
|
54 |
}); |
|
55 |
} |
|
56 |
|
|
57 |
public List<VacationDay> getVacationDays(String token, LocalDate from, LocalDate to) { |
|
58 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
59 |
"FROM vacation_day VD " + |
|
60 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
61 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
62 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
63 |
"WHERE EU.token = ? AND VD.vacation_date >= ? AND VD.vacation_date <= ?", |
|
64 |
new Object[]{token, from, to}, (ResultSet rs, int rowNum) -> { |
|
65 |
VacationDay item = new VacationDay(); |
|
66 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
67 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
68 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
69 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
70 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
71 |
return item; |
|
72 |
}); |
|
73 |
} |
|
74 |
|
|
75 |
public List<VacationDay> getVacationDays(long userId, LocalDate from) { |
|
76 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
77 |
"FROM vacation_day VD " + |
|
78 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
79 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
80 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
81 |
"WHERE VD.user_id = ? AND VD.vacation_date >= ?", |
|
82 |
new Object[]{userId, from}, (ResultSet rs, int rowNum) -> { |
|
83 |
VacationDay item = new VacationDay(); |
|
84 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
85 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
86 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
87 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
88 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
89 |
return item; |
|
90 |
}); |
|
91 |
} |
|
92 |
|
|
93 |
public List<VacationDay> getVacationDays(long userId, LocalDate from, LocalDate to) { |
|
94 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
95 |
"FROM vacation_day VD " + |
|
96 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
97 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
98 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
99 |
"WHERE VD.user_id=? AND VD.vacation_date >= ? AND VD.vacation_date <= ?", |
|
100 |
new Object[]{userId, from, to}, (ResultSet rs, int rowNum) -> { |
|
101 |
VacationDay item = new VacationDay(); |
|
102 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
103 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
104 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
105 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
106 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
107 |
return item; |
|
108 |
}); |
|
109 |
} |
|
110 |
|
|
111 |
public List<VacationDay> getVacationDays(long userId, LocalDate from, LocalDate to, Status status) { |
|
112 |
return jdbc.query("SELECT VD.vacation_date, VD.time_from, VD.time_to, VT.name, APS.name " + |
|
113 |
"FROM vacation_day VD " + |
|
114 |
"INNER JOIN end_user EU ON VD.user_id = EU.id " + |
|
115 |
"INNER JOIN vacation_type VT ON VD.type_id = VT.id " + |
|
116 |
"INNER JOIN approval_status APS ON VD.status_id = APS.id " + |
|
117 |
"WHERE VD.user_id=? AND VD.vacation_date >= ? AND VD.vacation_date <= ? AND APS.name = ?", |
|
118 |
new Object[]{userId, from, to, status.name()}, (ResultSet rs, int rowNum) -> { |
|
119 |
VacationDay item = new VacationDay(); |
|
120 |
item.setDate(rs.getDate("VD.vacation_date").toLocalDate()); |
|
121 |
item.setFrom(rs.getTime("VD.time_from").toLocalTime()); |
|
122 |
item.setTo(rs.getTime("VD.time_to").toLocalTime()); |
|
123 |
item.setType(VacationType.getVacationType(rs.getString("VT.name"))); |
|
124 |
item.setStatus(Status.getStatus(rs.getString("APS.name"))); |
|
125 |
return item; |
|
126 |
}); |
|
127 |
} |
|
128 |
|
|
129 |
public void insertVacationDay(String token, VacationDay day) { |
|
130 |
jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status_id, type_id) VALUES (?,?,?,?,?)", |
|
131 |
day.getDate(), day.getFrom(), day.getTo(), day.getStatus().ordinal(), day.getType().ordinal()); |
|
132 |
} |
|
133 |
|
|
134 |
public void updateVacationDay(VacationDay item) { |
|
135 |
jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status_id=?, type_id=? WHERE id=?", |
|
136 |
item.getDate(), item.getFrom(), item.getTo(), item.getStatus().ordinal(), item.getType().ordinal(), item.getId()); |
|
137 |
} |
|
138 |
|
|
139 |
public void deleteVacationDay(long id) { |
|
140 |
jdbc.update("DELETE FROM vacation_day WHERE id=?", id); |
|
141 |
} |
|
142 |
} |
Také k dispozici: Unified diff
Re #7526 Database queries