Revize d83c5707
Přidáno uživatelem Pavel Fidransky před více než 4 roky(ů)
server/src/main/java/org/danekja/ymanager/business/ApiManager.java | ||
---|---|---|
4 | 4 |
import org.danekja.ymanager.business.auth.anot.IsEmployer; |
5 | 5 |
import org.danekja.ymanager.business.auth.anot.IsOwner; |
6 | 6 |
import org.danekja.ymanager.business.auth.anot.IsSignedIn; |
7 |
import org.danekja.ymanager.domain.DefaultSettings; |
|
8 | 7 |
import org.danekja.ymanager.domain.*; |
9 |
import org.danekja.ymanager.dto.*; |
|
8 |
import org.danekja.ymanager.dto.BasicRequestDTO; |
|
9 |
import org.danekja.ymanager.dto.UserSettingsDTO; |
|
10 |
import org.danekja.ymanager.dto.VacationDayDTO; |
|
10 | 11 |
import org.danekja.ymanager.repository.RequestRepository; |
11 | 12 |
import org.danekja.ymanager.repository.SettingsRepository; |
12 | 13 |
import org.danekja.ymanager.repository.UserRepository; |
... | ... | |
49 | 50 |
|
50 | 51 |
@Override |
51 | 52 |
@IsEmployer |
52 |
public List<VacationRequestDTO> getVacationRequests(Status status) {
|
|
53 |
public List<VacationRequest> getVacationRequests(Status status) { |
|
53 | 54 |
if (status == null) { |
54 | 55 |
return requestRepository.getAllVacationRequests(); |
55 | 56 |
} else { |
... | ... | |
59 | 60 |
|
60 | 61 |
@Override |
61 | 62 |
@IsEmployer |
62 |
public List<AuthorizationRequestDTO> getAuthorizationRequests(Status status) {
|
|
63 |
public List<AuthorizationRequest> getAuthorizationRequests(Status status) { |
|
63 | 64 |
if (status == null) { |
64 | 65 |
return requestRepository.getAllAuthorizations(); |
65 | 66 |
} else { |
... | ... | |
75 | 76 |
|
76 | 77 |
@Override |
77 | 78 |
@IsOwner |
78 |
public List<VacationDayDTO> getUserCalendar(long userId, LocalDate fromDate, LocalDate toDate, Status status) {
|
|
79 |
List<VacationDayDTO> vacations;
|
|
79 |
public List<Vacation> getUserCalendar(long userId, LocalDate fromDate, LocalDate toDate, Status status) { |
|
80 |
List<Vacation> vacations; |
|
80 | 81 |
if (status == null && toDate == null) { |
81 | 82 |
vacations = vacationRepository.getVacationDays(userId, fromDate); |
82 | 83 |
} else if (status == null) { |
server/src/main/java/org/danekja/ymanager/business/Manager.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.business; |
2 | 2 |
|
3 |
import org.danekja.ymanager.domain.DefaultSettings;
|
|
4 |
import org.danekja.ymanager.domain.RequestType;
|
|
5 |
import org.danekja.ymanager.domain.Status;
|
|
6 |
import org.danekja.ymanager.dto.*;
|
|
3 |
import org.danekja.ymanager.domain.*;
|
|
4 |
import org.danekja.ymanager.dto.BasicRequestDTO;
|
|
5 |
import org.danekja.ymanager.dto.UserSettingsDTO;
|
|
6 |
import org.danekja.ymanager.dto.VacationDayDTO;
|
|
7 | 7 |
|
8 | 8 |
import java.time.LocalDate; |
9 | 9 |
import java.util.List; |
... | ... | |
11 | 11 |
public interface Manager { |
12 | 12 |
|
13 | 13 |
|
14 |
List<VacationRequestDTO> getVacationRequests(Status status);
|
|
14 |
List<VacationRequest> getVacationRequests(Status status); |
|
15 | 15 |
|
16 |
List<AuthorizationRequestDTO> getAuthorizationRequests(Status status);
|
|
16 |
List<AuthorizationRequest> getAuthorizationRequests(Status status); |
|
17 | 17 |
|
18 | 18 |
DefaultSettings getDefaultSettings(); |
19 | 19 |
|
20 |
List<VacationDayDTO> getUserCalendar(long userId, LocalDate fromDate, LocalDate toDate, Status status);
|
|
20 |
List<Vacation> getUserCalendar(long userId, LocalDate fromDate, LocalDate toDate, Status status); |
|
21 | 21 |
|
22 | 22 |
void createSettings(DefaultSettings settings); |
23 | 23 |
|
server/src/main/java/org/danekja/ymanager/business/UserManager.java | ||
---|---|---|
3 | 3 |
import org.danekja.ymanager.domain.GoogleUser; |
4 | 4 |
import org.danekja.ymanager.domain.Status; |
5 | 5 |
import org.danekja.ymanager.domain.User; |
6 |
import org.danekja.ymanager.dto.BasicProfileUserDTO; |
|
7 | 6 |
import org.springframework.security.oauth2.core.oidc.OidcIdToken; |
8 | 7 |
|
9 | 8 |
import java.util.List; |
... | ... | |
15 | 14 |
|
16 | 15 |
/** |
17 | 16 |
* List all users with given status. |
18 |
* <p> |
|
19 |
* TODO: refactor to return domain class instead of DTO as part of #32 |
|
20 | 17 |
* |
21 | 18 |
* @param status status filter value |
22 | 19 |
* @return list of users or empty list if none found |
23 | 20 |
*/ |
24 |
List<BasicProfileUserDTO> getUsers(Status status);
|
|
21 |
List<? extends User> getUsers(Status status);
|
|
25 | 22 |
|
26 | 23 |
/** |
27 | 24 |
* Gets user by id (PK) |
server/src/main/java/org/danekja/ymanager/business/impl/DefaultUserManager.java | ||
---|---|---|
4 | 4 |
import org.danekja.ymanager.business.auth.anot.IsEmployer; |
5 | 5 |
import org.danekja.ymanager.business.auth.anot.IsOwner; |
6 | 6 |
import org.danekja.ymanager.domain.*; |
7 |
import org.danekja.ymanager.dto.BasicProfileUserDTO; |
|
8 | 7 |
import org.danekja.ymanager.repository.SettingsRepository; |
9 | 8 |
import org.danekja.ymanager.repository.UserRepository; |
10 | 9 |
import org.danekja.ymanager.repository.VacationRepository; |
... | ... | |
16 | 15 |
import org.springframework.security.oauth2.core.oidc.OidcIdToken; |
17 | 16 |
import org.springframework.stereotype.Service; |
18 | 17 |
|
19 |
import java.time.LocalDate; |
|
20 | 18 |
import java.util.List; |
21 | 19 |
|
22 | 20 |
/** |
... | ... | |
60 | 58 |
|
61 | 59 |
@Override |
62 | 60 |
@IsEmployer |
63 |
public List<BasicProfileUserDTO> getUsers(Status status) { |
|
64 |
List<BasicProfileUserDTO> users = userRepository.getAllBasicUsers(status == null ? Status.ACCEPTED : status); |
|
65 |
|
|
66 |
LocalDate today = LocalDate.now(); |
|
67 |
LocalDate weekBefore = today.minusWeeks(1); |
|
68 |
LocalDate weekAfter = today.plusWeeks(1); |
|
69 |
for (BasicProfileUserDTO user : users) { |
|
70 |
user.setCalendar(vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter)); |
|
61 |
public List<? extends User> getUsers(Status status) { |
|
62 |
if (status == null) { |
|
63 |
return userRepository.getUsers(Status.ACCEPTED); |
|
64 |
} else { |
|
65 |
return userRepository.getUsers(status); |
|
71 | 66 |
} |
72 |
|
|
73 |
return users; |
|
74 | 67 |
} |
75 | 68 |
|
76 | 69 |
@Override |
server/src/main/java/org/danekja/ymanager/domain/AuthorizationRequest.java | ||
---|---|---|
1 |
package org.danekja.ymanager.domain; |
|
2 |
|
|
3 |
import java.time.LocalDateTime; |
|
4 |
|
|
5 |
/** |
|
6 |
* User authorization request. |
|
7 |
*/ |
|
8 |
public class AuthorizationRequest { |
|
9 |
|
|
10 |
/** |
|
11 |
* The user's ID. |
|
12 |
*/ |
|
13 |
private Long id; |
|
14 |
/** |
|
15 |
* The user's first name. |
|
16 |
*/ |
|
17 |
private String firstName; |
|
18 |
|
|
19 |
/** |
|
20 |
* The user's last name. |
|
21 |
*/ |
|
22 |
private String lastName; |
|
23 |
|
|
24 |
/** |
|
25 |
* The date and time of a creation of this authorization request. |
|
26 |
*/ |
|
27 |
private LocalDateTime creationDate; |
|
28 |
|
|
29 |
/** |
|
30 |
* The approval status of this authorization request. |
|
31 |
*/ |
|
32 |
private Status status; |
|
33 |
|
|
34 |
public Long getId() { |
|
35 |
return id; |
|
36 |
} |
|
37 |
|
|
38 |
public void setId(Long id) { |
|
39 |
this.id = id; |
|
40 |
} |
|
41 |
|
|
42 |
public String getFirstName() { |
|
43 |
return firstName; |
|
44 |
} |
|
45 |
|
|
46 |
public void setFirstName(String firstName) { |
|
47 |
this.firstName = firstName; |
|
48 |
} |
|
49 |
|
|
50 |
public String getLastName() { |
|
51 |
return lastName; |
|
52 |
} |
|
53 |
|
|
54 |
public void setLastName(String lastName) { |
|
55 |
this.lastName = lastName; |
|
56 |
} |
|
57 |
|
|
58 |
public LocalDateTime getCreationDate() { |
|
59 |
return creationDate; |
|
60 |
} |
|
61 |
|
|
62 |
public void setCreationDate(LocalDateTime creationDate) { |
|
63 |
this.creationDate = creationDate; |
|
64 |
} |
|
65 |
|
|
66 |
public Status getStatus() { |
|
67 |
return status; |
|
68 |
} |
|
69 |
|
|
70 |
public void setStatus(Status status) { |
|
71 |
this.status = status; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public String toString() { |
|
76 |
return "AuthorizationRequest{" + |
|
77 |
"id=" + id + |
|
78 |
", firstName='" + firstName + '\'' + |
|
79 |
", lastName='" + lastName + '\'' + |
|
80 |
", creationDate=" + creationDate + |
|
81 |
", status=" + status + |
|
82 |
'}'; |
|
83 |
} |
|
84 |
} |
server/src/main/java/org/danekja/ymanager/domain/VacationRequest.java | ||
---|---|---|
1 |
package org.danekja.ymanager.domain; |
|
2 |
|
|
3 |
/** |
|
4 |
* Vacation request domain. |
|
5 |
*/ |
|
6 |
public class VacationRequest extends Vacation { |
|
7 |
|
|
8 |
/** |
|
9 |
* The user's first name. |
|
10 |
*/ |
|
11 |
private String firstName; |
|
12 |
|
|
13 |
/** |
|
14 |
* The user's last name. |
|
15 |
*/ |
|
16 |
private String lastName; |
|
17 |
|
|
18 |
public String getFirstName() { |
|
19 |
return firstName; |
|
20 |
} |
|
21 |
|
|
22 |
public void setFirstName(String firstName) { |
|
23 |
this.firstName = firstName; |
|
24 |
} |
|
25 |
|
|
26 |
public String getLastName() { |
|
27 |
return lastName; |
|
28 |
} |
|
29 |
|
|
30 |
public void setLastName(String lastName) { |
|
31 |
this.lastName = lastName; |
|
32 |
} |
|
33 |
} |
server/src/main/java/org/danekja/ymanager/dto/AuthorizationRequestDTO.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.dto; |
2 | 2 |
|
3 |
import org.danekja.ymanager.domain.AuthorizationRequest; |
|
3 | 4 |
import org.danekja.ymanager.domain.Status; |
4 | 5 |
|
5 | 6 |
import java.time.LocalDateTime; |
... | ... | |
35 | 36 |
*/ |
36 | 37 |
private LocalDateTime timestamp; |
37 | 38 |
|
39 |
public AuthorizationRequestDTO() { |
|
40 |
} |
|
41 |
|
|
42 |
public AuthorizationRequestDTO(AuthorizationRequest authorizationRequest) { |
|
43 |
this.id = authorizationRequest.getId(); |
|
44 |
this.firstName = authorizationRequest.getFirstName(); |
|
45 |
this.lastName = authorizationRequest.getLastName(); |
|
46 |
this.status = authorizationRequest.getStatus(); |
|
47 |
this.timestamp = authorizationRequest.getCreationDate(); |
|
48 |
} |
|
49 |
|
|
38 | 50 |
/** |
39 | 51 |
* Returns the user's ID. |
40 | 52 |
* |
server/src/main/java/org/danekja/ymanager/dto/BasicProfileUserDTO.java | ||
---|---|---|
1 |
package org.danekja.ymanager.dto; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
/** |
|
6 |
* An instance of the messenger class {@code BasicProfileUser} represents a basic profile of a user in a database. |
|
7 |
* The basic profile contains default, the most important informations which helps identify a user like a name or photo. |
|
8 |
* This class is used to communicate with a frontend. |
|
9 |
*/ |
|
10 |
public class BasicProfileUserDTO { |
|
11 |
/** |
|
12 |
* The user's ID. |
|
13 |
*/ |
|
14 |
private Long id; |
|
15 |
|
|
16 |
/** |
|
17 |
* The user's first name. |
|
18 |
*/ |
|
19 |
private String firstName; |
|
20 |
|
|
21 |
/** |
|
22 |
* The user's last name. |
|
23 |
*/ |
|
24 |
private String lastName; |
|
25 |
|
|
26 |
/** |
|
27 |
* The URL of a user's photo. |
|
28 |
*/ |
|
29 |
private String photo; |
|
30 |
|
|
31 |
/** |
|
32 |
* The list of user's vacations. |
|
33 |
*/ |
|
34 |
private List<VacationDayDTO> calendar; |
|
35 |
|
|
36 |
/** |
|
37 |
* Returns the user's ID. |
|
38 |
* |
|
39 |
* @return the user's ID |
|
40 |
*/ |
|
41 |
public Long getId() { |
|
42 |
return this.id; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Replaces the user's ID with the specified value. |
|
47 |
* |
|
48 |
* @param id the new user's ID |
|
49 |
*/ |
|
50 |
public void setId(final Long id) { |
|
51 |
this.id = id; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Returns the user's first name. |
|
56 |
* |
|
57 |
* @return the user's first name |
|
58 |
*/ |
|
59 |
public String getFirstName() { |
|
60 |
return this.firstName; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Replaces the user's first name with the new specified value. |
|
65 |
* |
|
66 |
* @param firstName the new first name |
|
67 |
*/ |
|
68 |
public void setFirstName(final String firstName) { |
|
69 |
this.firstName = firstName; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Returns the user's last name. |
|
74 |
* |
|
75 |
* @return the user's last name |
|
76 |
*/ |
|
77 |
public String getLastName() { |
|
78 |
return this.lastName; |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Replaces the user's last name with the given one. |
|
83 |
* |
|
84 |
* @param lastName the new last name |
|
85 |
*/ |
|
86 |
public void setLastName(final String lastName) { |
|
87 |
this.lastName = lastName; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Returns the URL of a user's photo. |
|
92 |
* |
|
93 |
* @return the URL of the user's photo |
|
94 |
*/ |
|
95 |
public String getPhoto() { |
|
96 |
return this.photo; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Replaces the URL of a user's photo with the given link. |
|
101 |
* |
|
102 |
* @param photo the new URL of the user's photo |
|
103 |
*/ |
|
104 |
public void setPhoto(final String photo) { |
|
105 |
this.photo = photo; |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Returns the list of user's vacations. |
|
110 |
* |
|
111 |
* @return the list of user's vacations |
|
112 |
*/ |
|
113 |
public List<VacationDayDTO> getCalendar() { |
|
114 |
return this.calendar; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Replaces the list of user's vacations with the given list. |
|
119 |
* |
|
120 |
* @param calendar the new list of vacations |
|
121 |
*/ |
|
122 |
public void setCalendar(final List<VacationDayDTO> calendar) { |
|
123 |
this.calendar = calendar; |
|
124 |
} |
|
125 |
} |
server/src/main/java/org/danekja/ymanager/dto/VacationDayDTO.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.dto; |
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.Status; |
4 |
import org.danekja.ymanager.domain.Vacation; |
|
4 | 5 |
import org.danekja.ymanager.domain.VacationType; |
5 | 6 |
|
6 | 7 |
import java.time.LocalDate; |
... | ... | |
41 | 42 |
*/ |
42 | 43 |
private Status status; |
43 | 44 |
|
45 |
public VacationDayDTO() { |
|
46 |
} |
|
47 |
|
|
48 |
public VacationDayDTO(Vacation vacation) { |
|
49 |
this.id = vacation.getId(); |
|
50 |
this.date = vacation.getDate(); |
|
51 |
this.from = vacation.getFrom(); |
|
52 |
this.to = vacation.getTo(); |
|
53 |
this.type = vacation.getType(); |
|
54 |
this.status = vacation.getStatus(); |
|
55 |
} |
|
56 |
|
|
44 | 57 |
/** |
45 | 58 |
* Returns the ID of this vacation. |
46 | 59 |
* |
server/src/main/java/org/danekja/ymanager/dto/VacationRequestDTO.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.Status; |
4 | 4 |
import org.danekja.ymanager.domain.VacationType; |
5 |
import org.danekja.ymanager.domain.VacationRequest; |
|
5 | 6 |
|
6 | 7 |
import java.time.LocalDate; |
7 | 8 |
import java.time.LocalDateTime; |
... | ... | |
58 | 59 |
*/ |
59 | 60 |
private LocalDateTime timestamp; |
60 | 61 |
|
62 |
public VacationRequestDTO() { |
|
63 |
} |
|
64 |
|
|
65 |
public VacationRequestDTO(VacationRequest vacation) { |
|
66 |
this.id = vacation.getId(); |
|
67 |
this.firstName = vacation.getFirstName(); |
|
68 |
this.lastName = vacation.getLastName(); |
|
69 |
this.date = vacation.getDate(); |
|
70 |
this.from = vacation.getFrom(); |
|
71 |
this.to = vacation.getTo(); |
|
72 |
this.type = vacation.getType(); |
|
73 |
this.status = vacation.getStatus(); |
|
74 |
this.timestamp = vacation.getCreationDate(); |
|
75 |
} |
|
76 |
|
|
61 | 77 |
/** |
62 | 78 |
* Returns the ID of this vacation request. |
63 | 79 |
* |
server/src/main/java/org/danekja/ymanager/repository/RequestRepository.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.repository; |
2 | 2 |
|
3 |
import org.danekja.ymanager.domain.AuthorizationRequest; |
|
3 | 4 |
import org.danekja.ymanager.domain.Status; |
5 |
import org.danekja.ymanager.domain.VacationRequest; |
|
4 | 6 |
import org.danekja.ymanager.dto.AuthorizationRequestDTO; |
5 | 7 |
import org.danekja.ymanager.dto.BasicRequestDTO; |
6 |
import org.danekja.ymanager.dto.VacationRequestDTO; |
|
7 | 8 |
|
8 | 9 |
import java.util.List; |
9 | 10 |
|
... | ... | |
24 | 25 |
* |
25 | 26 |
* @return the list of all authorization requests |
26 | 27 |
*/ |
27 |
List<AuthorizationRequestDTO> getAllAuthorizations();
|
|
28 |
List<AuthorizationRequest> getAllAuthorizations(); |
|
28 | 29 |
|
29 | 30 |
/** |
30 | 31 |
* Gets all authorization request with the given authorization status from a database. |
... | ... | |
35 | 36 |
* @param status the approval status of the requests |
36 | 37 |
* @return the list of all authorization requests with the given status |
37 | 38 |
*/ |
38 |
List<AuthorizationRequestDTO> getAllAuthorizations(final Status status);
|
|
39 |
List<AuthorizationRequest> getAllAuthorizations(final Status status); |
|
39 | 40 |
|
40 | 41 |
/** |
41 | 42 |
* Updates the status of an authorization request with the given id. |
... | ... | |
60 | 61 |
* |
61 | 62 |
* @return the list of all vacation requests |
62 | 63 |
*/ |
63 |
List<VacationRequestDTO> getAllVacationRequests();
|
|
64 |
List<VacationRequest> getAllVacationRequests(); |
|
64 | 65 |
|
65 | 66 |
/** |
66 | 67 |
* Gets all vacation requests with the given approval status from a database. |
... | ... | |
70 | 71 |
* @param status the approval status of the requests |
71 | 72 |
* @return the list of all vacation requests with the given status |
72 | 73 |
*/ |
73 |
List<VacationRequestDTO> getAllVacationRequests(final Status status);
|
|
74 |
List<VacationRequest> getAllVacationRequests(final Status status); |
|
74 | 75 |
|
75 | 76 |
/** |
76 | 77 |
* Updates a status of a vacation request with the given id. |
server/src/main/java/org/danekja/ymanager/repository/UserRepository.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.repository; |
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.*; |
4 |
import org.danekja.ymanager.dto.BasicProfileUserDTO; |
|
5 |
import org.danekja.ymanager.dto.FullUserProfileDTO; |
|
6 | 4 |
|
7 | 5 |
import java.util.List; |
8 | 6 |
|
... | ... | |
11 | 9 |
*/ |
12 | 10 |
public interface UserRepository { |
13 | 11 |
/** |
14 |
* Gets basic profile of each user from a database. The basic profile contains default, the most important |
|
15 |
* informations which helps identify a user like a name or photo. Every line of output is converted to a BasicProfileUser |
|
16 |
* object filled with data from the database. If there aren't any users in the database, the method returns an empty list. |
|
17 |
* |
|
18 |
* @return A list of all basic profiles. |
|
19 |
*/ |
|
20 |
List<BasicProfileUserDTO> getAllBasicUsers(); |
|
21 |
|
|
22 |
/** |
|
23 |
* Gets basic profile of each user with the given authorization status from a database. The basic profile contains |
|
24 |
* default, the most important informations which helps identify a user like a name or a photo. |
|
25 |
* Every line of output is converted to a BasicProfileUser object filled with data from the database. |
|
26 |
* If there aren't any users with the given authorization status in the database, the method returns an empty list. |
|
12 |
* Gets users with the given authorization status from a database. If there aren't any users with |
|
13 |
* the given authorization status in the database, the method returns an empty list. |
|
27 | 14 |
* |
28 | 15 |
* @param status The authentication status. |
29 |
* @return A list of all basic profiles with the given status. |
|
30 |
*/ |
|
31 |
List<BasicProfileUserDTO> getAllBasicUsers(final Status status); |
|
32 |
|
|
33 |
UserRole getPermission(Long id); |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @param id |
|
38 |
* @return |
|
16 |
* @return A list of all users with the given status. |
|
39 | 17 |
*/ |
40 |
FullUserProfileDTO getFullUser(final long id);
|
|
18 |
List<RegisteredUser> getUsers(final Status status);
|
|
41 | 19 |
|
42 | 20 |
/** |
43 | 21 |
* Gets user from database based on its email |
server/src/main/java/org/danekja/ymanager/repository/VacationRepository.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.Status; |
4 | 4 |
import org.danekja.ymanager.domain.Vacation; |
5 |
import org.danekja.ymanager.dto.VacationDayDTO; |
|
6 | 5 |
|
7 | 6 |
import java.time.LocalDate; |
8 | 7 |
import java.util.List; |
... | ... | |
10 | 9 |
|
11 | 10 |
public interface VacationRepository { |
12 | 11 |
|
13 |
List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from);
|
|
12 |
List<Vacation> getVacationDays(final long userId, final LocalDate from); |
|
14 | 13 |
|
15 |
List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from, final Status status);
|
|
14 |
List<Vacation> getVacationDays(final long userId, final LocalDate from, final Status status); |
|
16 | 15 |
|
17 |
List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from, final LocalDate to);
|
|
16 |
List<Vacation> getVacationDays(final long userId, final LocalDate from, final LocalDate to); |
|
18 | 17 |
|
19 |
List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status);
|
|
18 |
List<Vacation> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status); |
|
20 | 19 |
|
21 | 20 |
Optional<Vacation> getVacationDay(final long id); |
22 | 21 |
|
server/src/main/java/org/danekja/ymanager/repository/jdbc/JdbcRequestRepository.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.repository.jdbc; |
2 | 2 |
|
3 |
import org.danekja.ymanager.domain.AuthorizationRequest; |
|
3 | 4 |
import org.danekja.ymanager.domain.Status; |
5 |
import org.danekja.ymanager.domain.VacationRequest; |
|
4 | 6 |
import org.danekja.ymanager.dto.AuthorizationRequestDTO; |
5 | 7 |
import org.danekja.ymanager.dto.BasicRequestDTO; |
6 |
import org.danekja.ymanager.dto.VacationRequestDTO; |
|
7 | 8 |
import org.danekja.ymanager.repository.RequestRepository; |
8 | 9 |
import org.danekja.ymanager.repository.jdbc.mappers.AuthorizationRequestMapper; |
9 | 10 |
import org.danekja.ymanager.repository.jdbc.mappers.VacationRequestMapper; |
... | ... | |
23 | 24 |
*/ |
24 | 25 |
private static final Logger log = LoggerFactory.getLogger(JdbcRequestRepository.class); |
25 | 26 |
|
26 |
private static final VacationRequestMapper VACATION_REQUEST_MAPPER = new VacationRequestMapper();
|
|
27 |
private static final VacationRequestMapper VACATION_WITH_USER_MAPPER = new VacationRequestMapper();
|
|
27 | 28 |
private static final AuthorizationRequestMapper AUTHORIZATION_REQUEST_MAPPER = new AuthorizationRequestMapper(); |
28 | 29 |
|
29 | 30 |
/** |
... | ... | |
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
@Override |
47 |
public List<AuthorizationRequestDTO> getAllAuthorizations() {
|
|
48 |
public List<AuthorizationRequest> getAllAuthorizations() { |
|
48 | 49 |
JdbcRequestRepository.log.trace("Selecting all authorization requests from a database."); |
49 | 50 |
|
50 | 51 |
return this.jdbc.query("SELECT id, first_name, last_name, creation_date, status FROM end_user", AUTHORIZATION_REQUEST_MAPPER); |
51 | 52 |
} |
52 | 53 |
|
53 | 54 |
@Override |
54 |
public List<AuthorizationRequestDTO> getAllAuthorizations(final Status status) {
|
|
55 |
public List<AuthorizationRequest> getAllAuthorizations(final Status status) { |
|
55 | 56 |
JdbcRequestRepository.log.trace("Selecting all authorization requests from a database with requested status."); |
56 | 57 |
JdbcRequestRepository.log.debug("Status: {}", status); |
57 | 58 |
|
... | ... | |
72 | 73 |
} |
73 | 74 |
|
74 | 75 |
@Override |
75 |
public List<VacationRequestDTO> getAllVacationRequests() {
|
|
76 |
public List<VacationRequest> getAllVacationRequests() { |
|
76 | 77 |
JdbcRequestRepository.log.trace("Selecting all vacation requests from a database."); |
77 | 78 |
|
78 | 79 |
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 " + |
79 | 80 |
"FROM vacation_day v " + |
80 |
"INNER JOIN end_user u ON v.user_id = u.id", VACATION_REQUEST_MAPPER);
|
|
81 |
"INNER JOIN end_user u ON v.user_id = u.id", VACATION_WITH_USER_MAPPER);
|
|
81 | 82 |
} |
82 | 83 |
|
83 | 84 |
@Override |
84 |
public List<VacationRequestDTO> getAllVacationRequests(final Status status) {
|
|
85 |
public List<VacationRequest> getAllVacationRequests(final Status status) { |
|
85 | 86 |
JdbcRequestRepository.log.trace("Selecting all vacation requests from a database with requested status."); |
86 | 87 |
JdbcRequestRepository.log.debug("Status: {}", status); |
87 | 88 |
|
88 | 89 |
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 " + |
89 | 90 |
"FROM vacation_day v " + |
90 | 91 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
91 |
"WHERE v.status=?", VACATION_REQUEST_MAPPER, status.name());
|
|
92 |
"WHERE v.status=?", VACATION_WITH_USER_MAPPER, status.name());
|
|
92 | 93 |
} |
93 | 94 |
|
94 | 95 |
@Override |
server/src/main/java/org/danekja/ymanager/repository/jdbc/JdbcUserRepository.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.repository.jdbc; |
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.*; |
4 |
import org.danekja.ymanager.dto.BasicProfileUserDTO; |
|
5 |
import org.danekja.ymanager.dto.FullUserProfileDTO; |
|
6 | 4 |
import org.danekja.ymanager.repository.UserRepository; |
7 |
import org.danekja.ymanager.repository.jdbc.mappers.BasicProfileUserMapper; |
|
8 | 5 |
import org.danekja.ymanager.repository.jdbc.mappers.UserDataRowMapper; |
9 | 6 |
import org.danekja.ymanager.repository.jdbc.mappers.UserRowMapper; |
10 | 7 |
import org.slf4j.Logger; |
11 | 8 |
import org.slf4j.LoggerFactory; |
12 | 9 |
import org.springframework.beans.factory.annotation.Autowired; |
13 |
import org.springframework.jdbc.core.*; |
|
10 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
11 |
import org.springframework.jdbc.core.PreparedStatementCreator; |
|
12 |
import org.springframework.jdbc.core.PreparedStatementCreatorFactory; |
|
13 |
import org.springframework.jdbc.core.RowMapper; |
|
14 | 14 |
import org.springframework.jdbc.support.GeneratedKeyHolder; |
15 | 15 |
import org.springframework.stereotype.Repository; |
16 | 16 |
|
17 |
import java.sql.CallableStatement; |
|
18 |
import java.sql.Timestamp; |
|
19 | 17 |
import java.sql.Types; |
20 |
import java.util.ArrayList; |
|
21 | 18 |
import java.util.List; |
22 |
import java.util.Map; |
|
23 | 19 |
import java.util.Objects; |
24 | 20 |
|
25 |
import static org.danekja.ymanager.domain.UserRole.getUserRole; |
|
26 |
|
|
27 | 21 |
@Repository |
28 | 22 |
public class JdbcUserRepository implements UserRepository { |
29 | 23 |
|
30 |
private static final RowMapper<BasicProfileUserDTO> BASIC_PROFILE_USER_MAPPER = new BasicProfileUserMapper(); |
|
31 | 24 |
private static final RowMapper<UserData> USER_DATA_MAPPER = new UserDataRowMapper(); |
32 | 25 |
private static final RowMapper<RegisteredUser> USER_MAPPER = new UserRowMapper(USER_DATA_MAPPER); |
33 | 26 |
|
... | ... | |
52 | 45 |
this.jdbc = jdbc; |
53 | 46 |
} |
54 | 47 |
|
55 |
private Map<String, Object> getUserColumns(final long id) { |
|
56 |
final List<SqlParameter> paramList = new ArrayList<>(); |
|
57 |
paramList.add(new SqlParameter("in_id", 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_sick_days", Types.INTEGER)); |
|
64 |
paramList.add(new SqlOutParameter("out_alert", Types.TIMESTAMP)); |
|
65 |
paramList.add(new SqlOutParameter("out_token", Types.LONGVARCHAR)); |
|
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.TIMESTAMP)); |
|
69 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
70 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
71 |
|
|
72 |
return jdbc.call(con -> { |
|
73 |
final 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.INTEGER); |
|
81 |
callableStatement.registerOutParameter(8, Types.TIMESTAMP); |
|
82 |
callableStatement.registerOutParameter(9, Types.LONGVARCHAR); |
|
83 |
callableStatement.registerOutParameter(10, Types.VARCHAR); |
|
84 |
callableStatement.registerOutParameter(11, Types.LONGVARCHAR); |
|
85 |
callableStatement.registerOutParameter(12, Types.TIMESTAMP); |
|
86 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
87 |
callableStatement.registerOutParameter(14, Types.VARCHAR); |
|
88 |
return callableStatement; |
|
89 |
}, paramList); |
|
90 |
} |
|
91 |
|
|
92 |
//---------------------------------- DTO ----------------------------------- |
|
93 |
|
|
94 | 48 |
@Override |
95 |
public List<BasicProfileUserDTO> getAllBasicUsers() { |
|
96 |
JdbcUserRepository.log.trace("Selecting basic profiles of all users from a database."); |
|
97 |
|
|
98 |
return this.jdbc.query("SELECT id, first_name, last_name, photo FROM end_user", BASIC_PROFILE_USER_MAPPER); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public List<BasicProfileUserDTO> getAllBasicUsers(final Status status) { |
|
103 |
JdbcUserRepository.log.trace("Selecting basic profiles of all users with a required status from a database."); |
|
104 |
JdbcUserRepository.log.debug("Status: {}", status); |
|
105 |
|
|
106 |
return this.jdbc.query("SELECT id, first_name, last_name, photo FROM end_user WHERE status = ?", |
|
107 |
BASIC_PROFILE_USER_MAPPER, status.name()); |
|
49 |
public List<RegisteredUser> getUsers(final Status status) { |
|
50 |
return this.jdbc.query("SELECT * FROM end_user WHERE status = ?", USER_MAPPER, status.name()); |
|
108 | 51 |
} |
109 | 52 |
|
110 |
@Override |
|
111 |
public UserRole getPermission(Long id) { |
|
112 |
return jdbc.queryForObject("SELECT user_role FROM end_user WHERE id = ?" ,new Object[]{id}, (rs, rowNum) -> |
|
113 |
getUserRole(rs.getString("user_role")) |
|
114 |
); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public FullUserProfileDTO getFullUser(final long id) { |
|
119 |
JdbcUserRepository.log.debug("Selecting full profile of a user with the specified id from a database: {}", id); |
|
120 |
|
|
121 |
final Map<String, Object> resultMap = this.getUserColumns(id); |
|
122 |
|
|
123 |
final FullUserProfileDTO user = new FullUserProfileDTO(); |
|
124 |
user.setId(id); |
|
125 |
user.setFirstName((String) resultMap.get("out_first_name")); |
|
126 |
user.setLastName((String) resultMap.get("out_last_name")); |
|
127 |
user.setVacationCount(((Double) resultMap.get("out_no_vacations")).floatValue()); |
|
128 |
user.setSickDayCount((Integer) resultMap.get("out_no_sick_days")); |
|
129 |
user.setTakenSickDayCount((Integer) resultMap.get("out_taken_sick_days")); |
|
130 |
user.setNotification(((Timestamp) resultMap.get("out_alert")).toLocalDateTime()); |
|
131 |
user.setEmail((String) resultMap.get("out_email")); |
|
132 |
user.setPhoto((String) resultMap.get("out_photo")); |
|
133 |
user.setRole(getUserRole((String) resultMap.get("out_role"))); |
|
134 |
user.setStatus(Status.valueOf((String) resultMap.get("out_status"))); |
|
135 |
return user; |
|
136 |
|
|
137 |
} |
|
138 |
|
|
139 |
//---------------------------------- DOMAIN ----------------------------------- |
|
140 |
|
|
141 | 53 |
@Override |
142 | 54 |
public RegisteredUser getUser(final String email) { |
143 | 55 |
return this.jdbc.queryForObject("SELECT * FROM end_user WHERE email = ?", USER_MAPPER, email); |
server/src/main/java/org/danekja/ymanager/repository/jdbc/JdbcVacationRepository.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.Status; |
4 | 4 |
import org.danekja.ymanager.domain.Vacation; |
5 |
import org.danekja.ymanager.domain.VacationType; |
|
6 |
import org.danekja.ymanager.dto.VacationDayDTO; |
|
7 | 5 |
import org.danekja.ymanager.repository.VacationRepository; |
8 |
import org.danekja.ymanager.repository.jdbc.mappers.VacationDayMapper; |
|
9 | 6 |
import org.danekja.ymanager.repository.jdbc.mappers.VacationMapper; |
10 | 7 |
import org.slf4j.Logger; |
11 | 8 |
import org.slf4j.LoggerFactory; |
... | ... | |
14 | 11 |
import org.springframework.jdbc.core.RowMapper; |
15 | 12 |
import org.springframework.stereotype.Repository; |
16 | 13 |
|
17 |
import java.sql.ResultSet; |
|
18 |
import java.sql.Time; |
|
19 | 14 |
import java.time.LocalDate; |
20 | 15 |
import java.util.List; |
21 | 16 |
import java.util.Optional; |
... | ... | |
26 | 21 |
public class JdbcVacationRepository implements VacationRepository { |
27 | 22 |
|
28 | 23 |
private static final RowMapper<Vacation> VACATION_MAPPER = new VacationMapper(); |
29 |
private static final RowMapper<VacationDayDTO> VACATION_DAY_MAPPER = new VacationDayMapper(); |
|
30 | 24 |
|
31 | 25 |
/** |
32 | 26 |
* The logger. |
... | ... | |
51 | 45 |
} |
52 | 46 |
|
53 | 47 |
@Override |
54 |
public List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from) { |
|
55 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
56 |
"FROM vacation_day v " + |
|
57 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
|
58 |
"WHERE v.user_id = ? AND v.vacation_date >= ?", |
|
59 |
VACATION_DAY_MAPPER, userId, from); |
|
48 |
public List<Vacation> getVacationDays(final long userId, final LocalDate from) { |
|
49 |
return jdbc.query("SELECT * FROM vacation_day WHERE user_id = ? AND vacation_date >= ?", VACATION_MAPPER, userId, from); |
|
60 | 50 |
} |
61 | 51 |
|
62 | 52 |
@Override |
63 |
public List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from, final Status status) { |
|
64 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
65 |
"FROM vacation_day v " + |
|
66 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
|
67 |
"WHERE v.user_id = ? AND v.vacation_date >= ? AND v.status = ?", |
|
68 |
VACATION_DAY_MAPPER, userId, from, status.name()); |
|
53 |
public List<Vacation> getVacationDays(final long userId, final LocalDate from, final Status status) { |
|
54 |
return jdbc.query("SELECT * FROM vacation_day WHERE user_id = ? AND vacation_date >= ? AND status = ?", VACATION_MAPPER, userId, from, status.name()); |
|
69 | 55 |
} |
70 | 56 |
|
71 | 57 |
@Override |
72 |
public List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from, final LocalDate to) { |
|
73 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
74 |
"FROM vacation_day v " + |
|
75 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
|
76 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ?", |
|
77 |
VACATION_DAY_MAPPER, userId, from, to); |
|
78 |
|
|
58 |
public List<Vacation> getVacationDays(final long userId, final LocalDate from, final LocalDate to) { |
|
59 |
return jdbc.query("SELECT * FROM vacation_day WHERE user_id=? AND vacation_date >= ? AND vacation_date <= ?", VACATION_MAPPER, userId, from, to); |
|
79 | 60 |
} |
80 | 61 |
|
81 | 62 |
@Override |
82 |
public List<VacationDayDTO> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status) { |
|
83 |
return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " + |
|
84 |
"FROM vacation_day v " + |
|
85 |
"INNER JOIN end_user u ON v.user_id = u.id " + |
|
86 |
"WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ? AND v.status = ?", |
|
87 |
VACATION_DAY_MAPPER, userId, from, to, status.name()); |
|
63 |
public List<Vacation> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status) { |
|
64 |
return jdbc.query("SELECT * FROM vacation_day WHERE user_id=? AND vacation_date >= ? AND vacation_date <= ? AND status = ?", VACATION_MAPPER, userId, from, to, status.name()); |
|
88 | 65 |
} |
89 | 66 |
|
90 | 67 |
@Override |
server/src/main/java/org/danekja/ymanager/repository/jdbc/mappers/AuthorizationRequestMapper.java | ||
---|---|---|
1 | 1 |
package org.danekja.ymanager.repository.jdbc.mappers; |
2 | 2 |
|
3 |
import org.danekja.ymanager.domain.AuthorizationRequest; |
|
3 | 4 |
import org.danekja.ymanager.domain.Status; |
4 | 5 |
import org.danekja.ymanager.dto.AuthorizationRequestDTO; |
5 | 6 |
import org.springframework.jdbc.core.RowMapper; |
... | ... | |
10 | 11 |
/** |
11 | 12 |
* The mapper maps a row from a result of a query to an AuthorizationRequest. |
12 | 13 |
*/ |
13 |
public class AuthorizationRequestMapper implements RowMapper<AuthorizationRequestDTO> {
|
|
14 |
public class AuthorizationRequestMapper implements RowMapper<AuthorizationRequest> { |
|
14 | 15 |
|
15 | 16 |
/** |
16 | 17 |
* Maps a row from a result of a query to an AuthorizationRequest. |
... | ... | |
20 | 21 |
* @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set |
21 | 22 |
*/ |
22 | 23 |
@Override |
23 |
public AuthorizationRequestDTO mapRow(ResultSet resultSet, int i) throws SQLException {
|
|
24 |
final AuthorizationRequestDTO request = new AuthorizationRequestDTO();
|
|
24 |
public AuthorizationRequest mapRow(ResultSet resultSet, int i) throws SQLException { |
|
25 |
final AuthorizationRequest request = new AuthorizationRequest();
|
|
25 | 26 |
request.setId(resultSet.getLong("id")); |
26 | 27 |
request.setFirstName(resultSet.getString("first_name")); |
27 | 28 |
request.setLastName(resultSet.getString("last_name")); |
28 |
request.setTimestamp(resultSet.getTimestamp("creation_date").toLocalDateTime());
|
|
29 |
request.setCreationDate(resultSet.getTimestamp("creation_date").toLocalDateTime());
|
|
29 | 30 |
request.setStatus(Status.valueOf(resultSet.getString("status"))); |
30 | 31 |
return request; |
31 | 32 |
} |
server/src/main/java/org/danekja/ymanager/repository/jdbc/mappers/BasicProfileUserMapper.java | ||
---|---|---|
1 |
package org.danekja.ymanager.repository.jdbc.mappers; |
|
2 |
|
|
3 |
import org.danekja.ymanager.dto.BasicProfileUserDTO; |
|
4 |
import org.springframework.jdbc.core.RowMapper; |
|
5 |
|
|
6 |
import java.sql.ResultSet; |
|
7 |
import java.sql.SQLException; |
|
8 |
|
|
9 |
/** |
|
10 |
* The mapper maps a row from a result of a query to an BasicProfileUser. |
|
11 |
*/ |
|
12 |
public class BasicProfileUserMapper implements RowMapper<BasicProfileUserDTO> { |
|
13 |
|
|
14 |
/** |
|
15 |
* Maps a row from a result of a query to an BasicProfileUser. |
|
16 |
* @param resultSet the row from the result |
|
17 |
* @param i the index of the row |
|
18 |
* @return the BasicProfileUser object |
|
19 |
* @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set |
|
20 |
*/ |
|
21 |
@Override |
|
22 |
public BasicProfileUserDTO mapRow(ResultSet resultSet, int i) throws SQLException { |
|
23 |
final BasicProfileUserDTO user = new BasicProfileUserDTO(); |
|
24 |
user.setId(resultSet.getLong("id")); |
|
25 |
user.setFirstName(resultSet.getString("first_name")); |
|
26 |
user.setLastName(resultSet.getString("last_name")); |
|
27 |
user.setPhoto(resultSet.getString("photo")); |
|
28 |
return user; |
|
29 |
} |
|
30 |
} |
server/src/main/java/org/danekja/ymanager/repository/jdbc/mappers/VacationDayMapper.java | ||
---|---|---|
1 |
package org.danekja.ymanager.repository.jdbc.mappers; |
|
2 |
|
|
3 |
import org.danekja.ymanager.domain.Status; |
|
4 |
import org.danekja.ymanager.domain.VacationType; |
|
5 |
import org.danekja.ymanager.dto.VacationDayDTO; |
|
6 |
import org.springframework.jdbc.core.RowMapper; |
|
7 |
|
|
8 |
import java.sql.ResultSet; |
|
9 |
import java.sql.SQLException; |
|
10 |
import java.sql.Time; |
|
11 |
|
|
12 |
/** |
|
13 |
* The mapper maps a row from a result of a query to an Vacation. |
|
14 |
*/ |
|
15 |
public class VacationDayMapper implements RowMapper<VacationDayDTO> { |
|
16 |
|
|
17 |
/** |
|
18 |
* Maps a row from a result of a query to an Vacation. |
|
19 |
* @param resultSet the row from the result |
|
20 |
* @param i the index of the row |
|
21 |
* @return the Vacation object |
|
22 |
* @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set |
|
23 |
*/ |
|
24 |
@Override |
|
25 |
public VacationDayDTO mapRow(ResultSet resultSet, int i) throws SQLException { |
|
26 |
final VacationDayDTO item = new VacationDayDTO(); |
|
27 |
item.setId(resultSet.getLong("v.id")); |
|
28 |
item.setDate(resultSet.getDate("v.vacation_date").toLocalDate()); |
|
29 |
|
|
30 |
/* |
|
31 |
When a result contains a sick day it doesn't have specified a start and end time because |
|
32 |
it can be taken only as a whole day. In this case the v.time_from and v.time_to are null. |
|
33 |
Which must be handled. |
|
34 |
*/ |
|
35 |
final Time timeFrom = resultSet.getTime("v.time_from"); |
|
36 |
if (timeFrom != null) { |
|
37 |
item.setFrom(timeFrom.toLocalTime()); |
|
38 |
} |
|
39 |
|
|
40 |
final Time timeTo = resultSet.getTime("v.time_to"); |
|
41 |
if (timeTo != null) { |
|
42 |
item.setTo(timeTo.toLocalTime()); |
|
43 |
} |
|
44 |
|
|
45 |
item.setStatus(Status.valueOf(resultSet.getString("v.status"))); |
|
46 |
item.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type"))); |
|
47 |
return item; |
|
48 |
} |
|
49 |
} |
server/src/main/java/org/danekja/ymanager/repository/jdbc/mappers/VacationRequestMapper.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.Status; |
4 | 4 |
import org.danekja.ymanager.domain.VacationType; |
5 |
import org.danekja.ymanager.dto.VacationRequestDTO;
|
|
5 |
import org.danekja.ymanager.domain.VacationRequest;
|
|
6 | 6 |
import org.springframework.jdbc.core.RowMapper; |
7 | 7 |
|
8 | 8 |
import java.sql.ResultSet; |
... | ... | |
12 | 12 |
/** |
13 | 13 |
* The mapper maps each row from a result of a query to a VacationRequest. |
14 | 14 |
*/ |
15 |
public class VacationRequestMapper implements RowMapper<VacationRequestDTO> {
|
|
15 |
public class VacationRequestMapper implements RowMapper<VacationRequest> { |
|
16 | 16 |
|
17 | 17 |
/** |
18 | 18 |
* Maps a row from a result of a query to an VacationRequest. |
... | ... | |
22 | 22 |
* @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set |
23 | 23 |
*/ |
24 | 24 |
@Override |
25 |
public VacationRequestDTO mapRow(ResultSet resultSet, int i) throws SQLException {
|
|
26 |
final VacationRequestDTO request = new VacationRequestDTO();
|
|
25 |
public VacationRequest mapRow(ResultSet resultSet, int i) throws SQLException { |
|
26 |
final VacationRequest request = new VacationRequest();
|
|
27 | 27 |
request.setId(resultSet.getLong("v.id")); |
28 | 28 |
request.setFirstName(resultSet.getString("u.first_name")); |
29 | 29 |
request.setLastName(resultSet.getString("u.last_name")); |
... | ... | |
44 | 44 |
request.setTo(timeTo.toLocalTime()); |
45 | 45 |
} |
46 | 46 |
|
47 |
request.setTimestamp(resultSet.getTimestamp("v.creation_date").toLocalDateTime());
|
|
47 |
request.setCreationDate(resultSet.getTimestamp("v.creation_date").toLocalDateTime());
|
|
48 | 48 |
request.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type"))); |
49 | 49 |
request.setStatus(Status.valueOf(resultSet.getString("v.status"))); |
50 | 50 |
return request; |
server/src/main/java/org/danekja/ymanager/ws/rest/ApiController.java | ||
---|---|---|
3 | 3 |
import org.danekja.ymanager.business.FileExportResult; |
4 | 4 |
import org.danekja.ymanager.business.FileService; |
5 | 5 |
import org.danekja.ymanager.business.Manager; |
6 |
import org.danekja.ymanager.domain.RequestType; |
|
7 |
import org.danekja.ymanager.domain.Status; |
|
8 |
import org.danekja.ymanager.domain.User; |
|
6 |
import org.danekja.ymanager.domain.*; |
|
9 | 7 |
import org.danekja.ymanager.dto.*; |
10 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 9 |
import org.springframework.http.HttpHeaders; |
... | ... | |
17 | 15 |
import java.time.LocalDate; |
18 | 16 |
import java.time.format.DateTimeFormatter; |
19 | 17 |
import java.util.List; |
18 |
import java.util.stream.Collectors; |
|
20 | 19 |
|
21 | 20 |
@RestController |
22 | 21 |
public class ApiController { |
... | ... | |
35 | 34 |
|
36 | 35 |
@GetMapping("/users/requests/vacation") |
37 | 36 |
public List<VacationRequestDTO> usersRequestsVacation(@RequestParam(value = "status", required = false) Status status) { |
38 |
return manager.getVacationRequests(status); |
|
37 |
List<VacationRequest> requests = manager.getVacationRequests(status); |
|
38 |
|
|
39 |
return requests.stream() |
|
40 |
.map(VacationRequestDTO::new) |
|
41 |
.collect(Collectors.toList()); |
|
39 | 42 |
} |
40 | 43 |
|
41 | 44 |
@GetMapping("/users/requests/authorization") |
42 | 45 |
public List<AuthorizationRequestDTO> userRequestsAuthorization(@RequestParam(value = "status", required = false) Status status) { |
43 |
return manager.getAuthorizationRequests(status); |
|
46 |
List<AuthorizationRequest> requests = manager.getAuthorizationRequests(status); |
|
47 |
|
|
48 |
return requests.stream() |
|
49 |
.map(AuthorizationRequestDTO::new) |
|
50 |
.collect(Collectors.toList()); |
|
44 | 51 |
} |
45 | 52 |
|
46 | 53 |
@GetMapping("/user/{id}/calendar") |
... | ... | |
48 | 55 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); |
49 | 56 |
LocalDate fromDate = LocalDate.parse(from, formatter); |
50 | 57 |
LocalDate toDate = to != null ? LocalDate.parse(to, formatter) : null; |
51 |
return manager.getUserCalendar(id, fromDate, toDate, status); |
|
58 |
List<Vacation> vacations = manager.getUserCalendar(id, fromDate, toDate, status); |
|
59 |
|
|
60 |
return vacations.stream() |
|
61 |
.map(VacationDayDTO::new) |
|
62 |
.collect(Collectors.toList()); |
|
52 | 63 |
} |
53 | 64 |
|
54 | 65 |
@GetMapping("/settings") |
server/src/main/java/org/danekja/ymanager/ws/rest/UserController.java | ||
---|---|---|
3 | 3 |
import org.danekja.ymanager.business.UserManager; |
4 | 4 |
import org.danekja.ymanager.domain.Status; |
5 | 5 |
import org.danekja.ymanager.domain.User; |
6 |
import org.danekja.ymanager.dto.BasicProfileUserDTO; |
|
7 | 6 |
import org.danekja.ymanager.dto.FullUserProfileDTO; |
8 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 8 |
import org.springframework.security.authentication.AnonymousAuthenticationToken; |
... | ... | |
11 | 10 |
import org.springframework.web.bind.annotation.*; |
12 | 11 |
|
13 | 12 |
import java.util.List; |
13 |
import java.util.stream.Collectors; |
|
14 | 14 |
|
15 | 15 |
/** |
16 | 16 |
* Controller for Users collection of WS API. |
... | ... | |
27 | 27 |
} |
28 | 28 |
|
29 | 29 |
@GetMapping |
30 |
public List<BasicProfileUserDTO> users(@RequestParam(value = "status", required = false) Status status) { |
|
31 |
return userManager.getUsers(status); |
|
30 |
public List<FullUserProfileDTO> getUsers(@RequestParam(value = "status", required = false) Status status) { |
|
31 |
List<? extends User> users = userManager.getUsers(status); |
|
32 |
|
|
33 |
return users.stream() |
|
34 |
.map(FullUserProfileDTO::new) |
|
35 |
.collect(Collectors.toList()); |
|
32 | 36 |
} |
33 | 37 |
|
34 | 38 |
|
Také k dispozici: Unified diff
re #32 use domain classes in repositories