Revize ebc739a0
Přidáno uživatelem Lukas Cerny před téměř 6 roky(ů)
server/pom.xml | ||
---|---|---|
23 | 23 |
<artifactId>spring-boot-starter-web</artifactId> |
24 | 24 |
</dependency> |
25 | 25 |
|
26 |
<dependency> |
|
27 |
<groupId>org.apache.commons</groupId> |
|
28 |
<artifactId>commons-lang3</artifactId> |
|
29 |
<version>3.9</version> |
|
30 |
</dependency> |
|
31 |
|
|
32 |
|
|
26 | 33 |
<!-- DATABASE --> |
27 | 34 |
<dependency> |
28 | 35 |
<groupId>org.springframework.boot</groupId> |
server/src/main/java/cz/zcu/yamanager/dto/AuthorizationRequest.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
public class AuthorizationRequest { |
6 | 6 |
|
7 |
class User { |
|
8 |
public UserName name; |
|
9 |
} |
|
10 |
|
|
11 |
private long id; |
|
12 |
private User user; |
|
13 |
private LocalDateTime date; |
|
7 |
private Long id; |
|
8 |
private String firstName; |
|
9 |
private String lastName; |
|
10 |
private Status status; |
|
11 |
private LocalDateTime timestamp; |
|
14 | 12 |
|
15 |
public long getId() {
|
|
13 |
public Long getId() {
|
|
16 | 14 |
return id; |
17 | 15 |
} |
18 | 16 |
|
19 |
public void setId(long id) {
|
|
17 |
public void setId(Long id) {
|
|
20 | 18 |
this.id = id; |
21 | 19 |
} |
22 | 20 |
|
23 |
public User getUser() { |
|
24 |
return user; |
|
21 |
public String getFirstName() { |
|
22 |
return firstName; |
|
23 |
} |
|
24 |
|
|
25 |
public void setFirstName(String firstName) { |
|
26 |
this.firstName = firstName; |
|
27 |
} |
|
28 |
|
|
29 |
public String getLastName() { |
|
30 |
return lastName; |
|
31 |
} |
|
32 |
|
|
33 |
public void setLastName(String lastName) { |
|
34 |
this.lastName = lastName; |
|
25 | 35 |
} |
26 | 36 |
|
27 |
public void setUserName(UserName name) { |
|
28 |
this.user = new User(); |
|
29 |
this.user.name = name; |
|
37 |
public Status getStatus() { |
|
38 |
return status; |
|
30 | 39 |
} |
31 | 40 |
|
32 |
public void setUserName(String firstName, String lastName) { |
|
33 |
UserName name = new UserName(); |
|
34 |
name.setFirst(firstName); |
|
35 |
name.setLast(lastName); |
|
36 |
this.setUserName(name); |
|
41 |
public void setStatus(Status status) { |
|
42 |
this.status = status; |
|
37 | 43 |
} |
38 | 44 |
|
39 |
public LocalDateTime getDate() {
|
|
40 |
return date;
|
|
45 |
public LocalDateTime getTimestamp() {
|
|
46 |
return timestamp;
|
|
41 | 47 |
} |
42 | 48 |
|
43 |
public void setDate(LocalDateTime date) {
|
|
44 |
this.date = date;
|
|
49 |
public void setTimestamp(LocalDateTime timestamp) {
|
|
50 |
this.timestamp = timestamp;
|
|
45 | 51 |
} |
46 | 52 |
} |
server/src/main/java/cz/zcu/yamanager/dto/BasicProfileUser.java | ||
---|---|---|
3 | 3 |
import java.util.List; |
4 | 4 |
|
5 | 5 |
public class BasicProfileUser { |
6 |
private long id; |
|
7 |
private UserName name; |
|
6 |
private Long id; |
|
7 |
private String firstName; |
|
8 |
private String lastName; |
|
8 | 9 |
private String photo; |
9 |
private List<CalendarItem> calendar;
|
|
10 |
private List<VacationDay> calendar;
|
|
10 | 11 |
|
11 |
public long getId() {
|
|
12 |
public Long getId() {
|
|
12 | 13 |
return id; |
13 | 14 |
} |
14 | 15 |
|
15 |
public void setId(long id) {
|
|
16 |
public void setId(Long id) {
|
|
16 | 17 |
this.id = id; |
17 | 18 |
} |
18 | 19 |
|
19 |
public UserName getName() {
|
|
20 |
return name;
|
|
20 |
public String getFirstName() {
|
|
21 |
return firstName;
|
|
21 | 22 |
} |
22 | 23 |
|
23 |
public void setName(UserName name) {
|
|
24 |
this.name = name;
|
|
24 |
public void setFirstName(String firstName) {
|
|
25 |
this.firstName = firstName;
|
|
25 | 26 |
} |
26 | 27 |
|
27 |
public void setName(String firstName, String lastName) { |
|
28 |
UserName name = new UserName(); |
|
29 |
name.setFirst(firstName); |
|
30 |
name.setLast(lastName); |
|
31 |
this.setName(name); |
|
28 |
public String getLastName() { |
|
29 |
return lastName; |
|
30 |
} |
|
31 |
|
|
32 |
public void setLastName(String lastName) { |
|
33 |
this.lastName = lastName; |
|
32 | 34 |
} |
33 | 35 |
|
34 | 36 |
public String getPhoto() { |
... | ... | |
39 | 41 |
this.photo = photo; |
40 | 42 |
} |
41 | 43 |
|
42 |
public List<CalendarItem> getCalendar() {
|
|
44 |
public List<VacationDay> getCalendar() {
|
|
43 | 45 |
return calendar; |
44 | 46 |
} |
45 | 47 |
|
46 |
public void setCalendar(List<CalendarItem> calendar) {
|
|
48 |
public void setCalendar(List<VacationDay> calendar) {
|
|
47 | 49 |
this.calendar = calendar; |
48 | 50 |
} |
49 | 51 |
} |
server/src/main/java/cz/zcu/yamanager/dto/BasicRequest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
public class BasicRequest { |
4 | 4 |
|
5 |
private long id; |
|
6 |
private RequestType type; |
|
7 |
private RequestStatus status; |
|
5 |
private Long id; |
|
6 |
private Status status; |
|
8 | 7 |
|
9 |
public long getId() {
|
|
8 |
public Long getId() {
|
|
10 | 9 |
return id; |
11 | 10 |
} |
12 | 11 |
|
13 |
public void setId(long id) {
|
|
12 |
public void setId(Long id) {
|
|
14 | 13 |
this.id = id; |
15 | 14 |
} |
16 | 15 |
|
17 |
public RequestType getType() { |
|
18 |
return type; |
|
19 |
} |
|
20 |
|
|
21 |
public void setType(RequestType type) { |
|
22 |
this.type = type; |
|
23 |
} |
|
24 |
|
|
25 |
public RequestStatus getStatus() { |
|
16 |
public Status getStatus() { |
|
26 | 17 |
return status; |
27 | 18 |
} |
28 | 19 |
|
29 |
public void setStatus(RequestStatus status) {
|
|
20 |
public void setStatus(Status status) { |
|
30 | 21 |
this.status = status; |
31 | 22 |
} |
32 | 23 |
} |
server/src/main/java/cz/zcu/yamanager/dto/CalendarItem.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
import java.time.LocalDate; |
|
4 |
import java.time.LocalTime; |
|
5 |
|
|
6 |
public class CalendarItem { |
|
7 |
|
|
8 |
private LocalDate date; |
|
9 |
private LocalTime from; |
|
10 |
private LocalTime to; |
|
11 |
private VacationType type; |
|
12 |
private RequestStatus status; |
|
13 |
|
|
14 |
public LocalDate getDate() { |
|
15 |
return date; |
|
16 |
} |
|
17 |
|
|
18 |
public void setDate(LocalDate date) { |
|
19 |
this.date = date; |
|
20 |
} |
|
21 |
|
|
22 |
public LocalTime getFrom() { |
|
23 |
return from; |
|
24 |
} |
|
25 |
|
|
26 |
public void setFrom(LocalTime from) { |
|
27 |
this.from = from; |
|
28 |
} |
|
29 |
|
|
30 |
public LocalTime getTo() { |
|
31 |
return to; |
|
32 |
} |
|
33 |
|
|
34 |
public void setTo(LocalTime to) { |
|
35 |
this.to = to; |
|
36 |
} |
|
37 |
|
|
38 |
public VacationType getType() { |
|
39 |
return type; |
|
40 |
} |
|
41 |
|
|
42 |
public void setType(VacationType type) { |
|
43 |
this.type = type; |
|
44 |
} |
|
45 |
|
|
46 |
public RequestStatus getStatus() { |
|
47 |
return status; |
|
48 |
} |
|
49 |
|
|
50 |
public void setStatus(RequestStatus status) { |
|
51 |
this.status = status; |
|
52 |
} |
|
53 |
} |
server/src/main/java/cz/zcu/yamanager/dto/CalendarViewType.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public enum CalendarViewType { |
|
4 |
MONTH,WEEK |
|
5 |
} |
server/src/main/java/cz/zcu/yamanager/dto/DefaultSettings.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
public class DefaultSettings { |
6 | 6 |
|
7 |
private VacationInfo sickDay;
|
|
7 |
private Integer sickdayCount;
|
|
8 | 8 |
private LocalDateTime notification; |
9 | 9 |
|
10 |
public VacationInfo getSickDay() {
|
|
11 |
return sickDay;
|
|
10 |
public Integer getSickdayCount() {
|
|
11 |
return sickdayCount;
|
|
12 | 12 |
} |
13 | 13 |
|
14 |
public void setSickDay(VacationInfo sickDay) { |
|
15 |
this.sickDay = sickDay; |
|
16 |
} |
|
17 |
|
|
18 |
public void setSickDay(short count, VacationUnit unit) { |
|
19 |
VacationInfo info = new VacationInfo(); |
|
20 |
info.setValue(count); |
|
21 |
info.setUnit(unit); |
|
22 |
this.setSickDay(info); |
|
14 |
public void setSickdayCount(Integer sickdayCount) { |
|
15 |
this.sickdayCount = sickdayCount; |
|
23 | 16 |
} |
24 | 17 |
|
25 | 18 |
public LocalDateTime getNotification() { |
... | ... | |
30 | 23 |
this.notification = notification; |
31 | 24 |
} |
32 | 25 |
} |
26 |
|
server/src/main/java/cz/zcu/yamanager/dto/FullUserProfile.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
public class FullUserProfile { |
7 | 7 |
|
8 |
class Settings { |
|
9 |
public LocalDateTime notification; |
|
10 |
} |
|
11 |
|
|
12 |
private long id; |
|
13 |
private UserName name; |
|
8 |
private Long id; |
|
9 |
private String firstName; |
|
10 |
private String lastName; |
|
14 | 11 |
private String photo; |
15 |
private Settings settings; |
|
16 |
private VacationInfo vacation; |
|
17 |
private VacationInfo sickDay; |
|
18 |
private UserStatus status; |
|
12 |
private Float vacationCount; |
|
13 |
private Integer sickdayCount; |
|
14 |
private Status status; |
|
19 | 15 |
private UserRole role; |
16 |
private LocalDateTime notification; |
|
20 | 17 |
|
21 |
public long getId() {
|
|
18 |
public Long getId() {
|
|
22 | 19 |
return id; |
23 | 20 |
} |
24 | 21 |
|
25 |
public void setId(long id) {
|
|
22 |
public void setId(Long id) {
|
|
26 | 23 |
this.id = id; |
27 | 24 |
} |
28 | 25 |
|
29 |
public UserName getName() {
|
|
30 |
return name;
|
|
26 |
public String getFirstName() {
|
|
27 |
return firstName;
|
|
31 | 28 |
} |
32 | 29 |
|
33 |
public void setName(UserName name) {
|
|
34 |
this.name = name;
|
|
30 |
public void setFirstName(String firstName) {
|
|
31 |
this.firstName = firstName;
|
|
35 | 32 |
} |
36 | 33 |
|
37 |
public void setName(String firstName, String lastName) { |
|
38 |
UserName name = new UserName(); |
|
39 |
name.setFirst(firstName); |
|
40 |
name.setLast(lastName); |
|
41 |
this.setName(name); |
|
34 |
public String getLastName() { |
|
35 |
return lastName; |
|
36 |
} |
|
37 |
|
|
38 |
public void setLastName(String lastName) { |
|
39 |
this.lastName = lastName; |
|
42 | 40 |
} |
43 | 41 |
|
44 | 42 |
public String getPhoto() { |
... | ... | |
49 | 47 |
this.photo = photo; |
50 | 48 |
} |
51 | 49 |
|
52 |
public Settings getSettings() { |
|
53 |
return settings; |
|
54 |
} |
|
55 |
|
|
56 |
public void setNotification(LocalDateTime notification) { |
|
57 |
this.settings = new Settings(); |
|
58 |
this.settings.notification = notification; |
|
59 |
} |
|
60 |
|
|
61 |
public VacationInfo getVacation() { |
|
62 |
return vacation; |
|
50 |
public Float getVacationCount() { |
|
51 |
return vacationCount; |
|
63 | 52 |
} |
64 | 53 |
|
65 |
public void setVacation(VacationInfo vacation) {
|
|
66 |
this.vacation = vacation;
|
|
54 |
public void setVacationCount(Float vacationCount) {
|
|
55 |
this.vacationCount = vacationCount;
|
|
67 | 56 |
} |
68 | 57 |
|
69 |
public void setVacation(float count, VacationUnit unit) { |
|
70 |
VacationInfo info = new VacationInfo(); |
|
71 |
info.setValue(count); |
|
72 |
info.setUnit(unit); |
|
73 |
this.setVacation(info); |
|
58 |
public Integer getSickdayCount() { |
|
59 |
return sickdayCount; |
|
74 | 60 |
} |
75 | 61 |
|
76 |
public VacationInfo getSickDay() {
|
|
77 |
return sickDay;
|
|
62 |
public void setSickdayCount(Integer sickdayCount) {
|
|
63 |
this.sickdayCount = sickdayCount;
|
|
78 | 64 |
} |
79 | 65 |
|
80 |
public void setSickDay(VacationInfo sickDay) { |
|
81 |
this.sickDay = sickDay; |
|
82 |
} |
|
83 |
|
|
84 |
public void setSickDay(short count, VacationUnit unit) { |
|
85 |
VacationInfo info = new VacationInfo(); |
|
86 |
info.setValue(count); |
|
87 |
info.setUnit(unit); |
|
88 |
this.setSickDay(info); |
|
89 |
} |
|
90 |
|
|
91 |
public UserStatus getStatus() { |
|
66 |
public Status getStatus() { |
|
92 | 67 |
return status; |
93 | 68 |
} |
94 | 69 |
|
95 |
public void setStatus(UserStatus status) {
|
|
70 |
public void setStatus(Status status) { |
|
96 | 71 |
this.status = status; |
97 | 72 |
} |
98 | 73 |
|
... | ... | |
103 | 78 |
public void setRole(UserRole role) { |
104 | 79 |
this.role = role; |
105 | 80 |
} |
81 |
|
|
82 |
public LocalDateTime getNotification() { |
|
83 |
return notification; |
|
84 |
} |
|
85 |
|
|
86 |
public void setNotification(LocalDateTime notification) { |
|
87 |
this.notification = notification; |
|
88 |
} |
|
106 | 89 |
} |
server/src/main/java/cz/zcu/yamanager/dto/RequestStatus.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public enum RequestStatus { |
|
4 |
ACCEPTED, PENDING, REJECTED |
|
5 |
} |
server/src/main/java/cz/zcu/yamanager/dto/RequestType.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.dto; |
2 | 2 |
|
3 | 3 |
public enum RequestType { |
4 |
VACATION, SICK_DAY, AUTHORIZATION |
|
4 |
VACATION, AUTHORIZATION; |
|
5 |
|
|
6 |
public static RequestType getType(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/dto/Status.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public enum Status { |
|
4 |
ACCEPTED, PENDING, REJECTED |
|
5 |
|
|
6 |
; |
|
7 |
public static Status getStatus(String status) { |
|
8 |
if (status == null || status.isEmpty()) return null; |
|
9 |
try { |
|
10 |
return valueOf(status.toUpperCase()); |
|
11 |
} catch (IllegalArgumentException e) { |
|
12 |
return null; |
|
13 |
} |
|
14 |
} |
|
15 |
} |
server/src/main/java/cz/zcu/yamanager/dto/UserName.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public class UserName { |
|
4 |
private String first; |
|
5 |
private String last; |
|
6 |
|
|
7 |
public String getFirst() { |
|
8 |
return first; |
|
9 |
} |
|
10 |
|
|
11 |
public void setFirst(String first) { |
|
12 |
this.first = first; |
|
13 |
} |
|
14 |
|
|
15 |
public String getLast() { |
|
16 |
return last; |
|
17 |
} |
|
18 |
|
|
19 |
public void setLast(String last) { |
|
20 |
this.last = last; |
|
21 |
} |
|
22 |
} |
server/src/main/java/cz/zcu/yamanager/dto/UserRequest.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class UserRequest { |
|
6 |
|
|
7 |
private List<VacationRequest> vacation; |
|
8 |
private List<AuthorizationRequest> authorization; |
|
9 |
|
|
10 |
public List<VacationRequest> getVacation() { |
|
11 |
return vacation; |
|
12 |
} |
|
13 |
|
|
14 |
public void setVacation(List<VacationRequest> vacation) { |
|
15 |
this.vacation = vacation; |
|
16 |
} |
|
17 |
|
|
18 |
public List<AuthorizationRequest> getAuthorization() { |
|
19 |
return authorization; |
|
20 |
} |
|
21 |
|
|
22 |
public void setAuthorization(List<AuthorizationRequest> authorization) { |
|
23 |
this.authorization = authorization; |
|
24 |
} |
|
25 |
} |
server/src/main/java/cz/zcu/yamanager/dto/UserSettings.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
public class UserSettings { |
4 | 4 |
|
5 |
private Long id; |
|
6 |
private Float vacationCount; |
|
7 |
private Integer sickdayCount; |
|
5 | 8 |
private UserRole role; |
6 |
private VacationInfo vacation; |
|
7 |
private VacationInfo sickDay; |
|
8 | 9 |
|
9 |
public UserRole getRole() {
|
|
10 |
return role;
|
|
10 |
public Long getId() {
|
|
11 |
return id;
|
|
11 | 12 |
} |
12 | 13 |
|
13 |
public void setRole(UserRole role) { |
|
14 |
this.role = role; |
|
14 |
public void setId(Long id) { |
|
15 |
this.id = id; |
|
16 |
} |
|
17 |
|
|
18 |
public Float getVacationCount() { |
|
19 |
return vacationCount; |
|
15 | 20 |
} |
16 | 21 |
|
17 |
public VacationInfo getVacation() {
|
|
18 |
return vacation;
|
|
22 |
public void setVacationCount(Float vacationCount) {
|
|
23 |
this.vacationCount = vacationCount;
|
|
19 | 24 |
} |
20 | 25 |
|
21 |
public void setVacation(VacationInfo vacation) {
|
|
22 |
this.vacation = vacation;
|
|
26 |
public Integer getSickdayCount() {
|
|
27 |
return sickdayCount;
|
|
23 | 28 |
} |
24 | 29 |
|
25 |
public VacationInfo getSickDay() {
|
|
26 |
return sickDay;
|
|
30 |
public void setSickdayCount(Integer sickdayCount) {
|
|
31 |
this.sickdayCount = sickdayCount;
|
|
27 | 32 |
} |
28 | 33 |
|
29 |
public void setSickDay(VacationInfo sickDay) { |
|
30 |
this.sickDay = sickDay; |
|
34 |
public UserRole getRole() { |
|
35 |
return role; |
|
36 |
} |
|
37 |
|
|
38 |
public void setRole(UserRole role) { |
|
39 |
this.role = role; |
|
31 | 40 |
} |
32 | 41 |
} |
server/src/main/java/cz/zcu/yamanager/dto/UserStatus.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public enum UserStatus { |
|
4 |
AUTHORIZED, PENDING, REJECTED |
|
5 |
} |
server/src/main/java/cz/zcu/yamanager/dto/VacationDay.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
import java.time.LocalDate; |
|
4 |
import java.time.LocalTime; |
|
5 |
|
|
6 |
public class VacationDay { |
|
7 |
|
|
8 |
private Long id; |
|
9 |
private LocalDate date; |
|
10 |
private LocalTime from; |
|
11 |
private LocalTime to; |
|
12 |
private VacationType type; |
|
13 |
private Status status; |
|
14 |
|
|
15 |
public Long getId() { |
|
16 |
return id; |
|
17 |
} |
|
18 |
|
|
19 |
public void setId(Long id) { |
|
20 |
this.id = id; |
|
21 |
} |
|
22 |
|
|
23 |
public LocalDate getDate() { |
|
24 |
return date; |
|
25 |
} |
|
26 |
|
|
27 |
public void setDate(LocalDate date) { |
|
28 |
this.date = date; |
|
29 |
} |
|
30 |
|
|
31 |
public LocalTime getFrom() { |
|
32 |
return from; |
|
33 |
} |
|
34 |
|
|
35 |
public void setFrom(LocalTime from) { |
|
36 |
this.from = from; |
|
37 |
} |
|
38 |
|
|
39 |
public LocalTime getTo() { |
|
40 |
return to; |
|
41 |
} |
|
42 |
|
|
43 |
public void setTo(LocalTime to) { |
|
44 |
this.to = to; |
|
45 |
} |
|
46 |
|
|
47 |
public VacationType getType() { |
|
48 |
return type; |
|
49 |
} |
|
50 |
|
|
51 |
public void setType(VacationType type) { |
|
52 |
this.type = type; |
|
53 |
} |
|
54 |
|
|
55 |
public Status getStatus() { |
|
56 |
return status; |
|
57 |
} |
|
58 |
|
|
59 |
public void setStatus(Status status) { |
|
60 |
this.status = status; |
|
61 |
} |
|
62 |
} |
server/src/main/java/cz/zcu/yamanager/dto/VacationInfo.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public class VacationInfo { |
|
4 |
private float value; |
|
5 |
private VacationUnit unit; |
|
6 |
|
|
7 |
public float getValue() { |
|
8 |
return value; |
|
9 |
} |
|
10 |
|
|
11 |
public void setValue(float value) { |
|
12 |
this.value = value; |
|
13 |
} |
|
14 |
|
|
15 |
public VacationUnit getUnit() { |
|
16 |
return unit; |
|
17 |
} |
|
18 |
|
|
19 |
public void setUnit(VacationUnit unit) { |
|
20 |
this.unit = unit; |
|
21 |
} |
|
22 |
} |
server/src/main/java/cz/zcu/yamanager/dto/VacationRequest.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.dto; |
2 | 2 |
|
3 | 3 |
import java.time.LocalDate; |
4 |
import java.time.LocalDateTime; |
|
4 | 5 |
import java.time.LocalTime; |
5 | 6 |
|
6 | 7 |
public class VacationRequest { |
7 | 8 |
|
8 |
class User { |
|
9 |
public UserName name; |
|
10 |
} |
|
11 |
|
|
12 |
private long id; |
|
13 |
private User user; |
|
9 |
private Long id; |
|
10 |
private String firstName; |
|
11 |
private String lastName; |
|
14 | 12 |
private LocalDate date; |
15 | 13 |
private LocalTime from; |
16 | 14 |
private LocalTime to; |
17 | 15 |
private VacationType type; |
18 |
private RequestStatus status; |
|
16 |
private Status status; |
|
17 |
private LocalDateTime timestamp; |
|
19 | 18 |
|
20 |
public long getId() {
|
|
19 |
public Long getId() {
|
|
21 | 20 |
return id; |
22 | 21 |
} |
23 | 22 |
|
24 |
public void setId(long id) {
|
|
23 |
public void setId(Long id) {
|
|
25 | 24 |
this.id = id; |
26 | 25 |
} |
27 | 26 |
|
28 |
public User getUser() { |
|
29 |
return user; |
|
27 |
public String getFirstName() { |
|
28 |
return firstName; |
|
29 |
} |
|
30 |
|
|
31 |
public void setFirstName(String firstName) { |
|
32 |
this.firstName = firstName; |
|
33 |
} |
|
34 |
|
|
35 |
public String getLastName() { |
|
36 |
return lastName; |
|
30 | 37 |
} |
31 | 38 |
|
32 |
public void setUserName(UserName name) { |
|
33 |
this.user = new User(); |
|
34 |
this.user.name = name; |
|
39 |
public void setLastName(String lastName) { |
|
40 |
this.lastName = lastName; |
|
35 | 41 |
} |
36 | 42 |
|
37 | 43 |
public LocalDate getDate() { |
... | ... | |
66 | 72 |
this.type = type; |
67 | 73 |
} |
68 | 74 |
|
69 |
public RequestStatus getStatus() {
|
|
75 |
public Status getStatus() { |
|
70 | 76 |
return status; |
71 | 77 |
} |
72 | 78 |
|
73 |
public void setStatus(RequestStatus status) {
|
|
79 |
public void setStatus(Status status) { |
|
74 | 80 |
this.status = status; |
75 | 81 |
} |
82 |
|
|
83 |
public LocalDateTime getTimestamp() { |
|
84 |
return timestamp; |
|
85 |
} |
|
86 |
|
|
87 |
public void setTimestamp(LocalDateTime timestamp) { |
|
88 |
this.timestamp = timestamp; |
|
89 |
} |
|
76 | 90 |
} |
server/src/main/java/cz/zcu/yamanager/dto/VacationUnit.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.dto; |
|
2 |
|
|
3 |
public enum VacationUnit { |
|
4 |
DAY, HOUR |
|
5 |
} |
server/src/main/java/cz/zcu/yamanager/manager/Manager.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.manager; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.*; |
|
4 |
import cz.zcu.yamanager.ws.rest.RESTFullException; |
|
5 |
|
|
6 |
import java.time.LocalDate; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
public interface Manager { |
|
10 |
|
|
11 |
List<BasicProfileUser> getUsers(Status status) throws RESTFullException; |
|
12 |
|
|
13 |
List<VacationRequest> getVacationRequests(Status status) throws RESTFullException; |
|
14 |
|
|
15 |
List<AuthorizationRequest> getAuthorizationRequests(Status status) throws RESTFullException; |
|
16 |
|
|
17 |
FullUserProfile getUserProfile(Long userId) throws RESTFullException; |
|
18 |
|
|
19 |
DefaultSettings getDefaultSettings() throws RESTFullException; |
|
20 |
|
|
21 |
List<VacationDay> getUserCalendar(Long userId, LocalDate fromDate, LocalDate toDate, Status status) throws RESTFullException; |
|
22 |
|
|
23 |
void createSettings(DefaultSettings settings) throws RESTFullException; |
|
24 |
|
|
25 |
void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException; |
|
26 |
|
|
27 |
void changeSettings(Long userId, UserSettings settings) throws RESTFullException; |
|
28 |
|
|
29 |
void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException; |
|
30 |
|
|
31 |
void changeRequest(RequestType type, BasicRequest request) throws RESTFullException; |
|
32 |
|
|
33 |
void deleteVacation(Long userId, Long vacationId) throws RESTFullException; |
|
34 |
} |
server/src/main/java/cz/zcu/yamanager/manager/mock/ManagerMock.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.manager.mock; |
|
2 |
|
|
3 |
import cz.zcu.yamanager.dto.*; |
|
4 |
import cz.zcu.yamanager.manager.Manager; |
|
5 |
import cz.zcu.yamanager.ws.rest.RESTFullException; |
|
6 |
import org.springframework.stereotype.Component; |
|
7 |
|
|
8 |
import java.time.LocalDate; |
|
9 |
import java.time.LocalDateTime; |
|
10 |
import java.time.LocalTime; |
|
11 |
import java.time.Period; |
|
12 |
import java.util.*; |
|
13 |
import java.util.function.Predicate; |
|
14 |
import java.util.stream.Collectors; |
|
15 |
|
|
16 |
import static java.util.Arrays.asList; |
|
17 |
|
|
18 |
@Component |
|
19 |
public class ManagerMock implements Manager { |
|
20 |
|
|
21 |
private List<DefaultSettings> settings = new LinkedList<>(); |
|
22 |
|
|
23 |
private Map<Long, List<VacationDay>> vacations = new HashMap<>(); |
|
24 |
|
|
25 |
private Map<Long, UserSettings> userSettings = new HashMap<>(); |
|
26 |
|
|
27 |
private BasicProfileUser createBasicProfileUser(long id, Status status) { |
|
28 |
BasicProfileUser user = new BasicProfileUser(); |
|
29 |
|
|
30 |
user.setId(id); |
|
31 |
user.setFirstName("Tomas"); |
|
32 |
user.setLastName(status == null ? "unknown" : status.name().toLowerCase()); |
|
33 |
user.setPhoto("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg"); |
|
34 |
user.setCalendar(asList( |
|
35 |
createVacationDay(1L, LocalDate.now(), VacationType.VACATION, Status.ACCEPTED), |
|
36 |
createVacationDay(2L, LocalDate.now().plusDays(1), VacationType.VACATION, Status.ACCEPTED)) |
|
37 |
); |
|
38 |
|
|
39 |
return user; |
|
40 |
} |
|
41 |
|
|
42 |
private VacationDay createVacationDay(long id, LocalDate date, VacationType vacationType, Status status) { |
|
43 |
VacationDay vacationDay = new VacationDay(); |
|
44 |
|
|
45 |
vacationDay.setId(id); |
|
46 |
vacationDay.setType(vacationType); |
|
47 |
vacationDay.setDate(date); |
|
48 |
vacationDay.setStatus(status); |
|
49 |
|
|
50 |
switch (vacationType) { |
|
51 |
case SICKDAY: { |
|
52 |
vacationDay.setFrom(null); |
|
53 |
vacationDay.setTo(null); |
|
54 |
} break; |
|
55 |
case VACATION: { |
|
56 |
vacationDay.setFrom(LocalTime.of(9, 00)); |
|
57 |
vacationDay.setTo(LocalTime.of(13, 00)); |
|
58 |
} break; |
|
59 |
} |
|
60 |
|
|
61 |
return vacationDay; |
|
62 |
} |
|
63 |
|
|
64 |
private VacationRequest createVacationRequest(long id, VacationType vacationType, Status status) { |
|
65 |
VacationRequest request = new VacationRequest(); |
|
66 |
|
|
67 |
request.setId(id); |
|
68 |
request.setFirstName("Tomas"); |
|
69 |
request.setLastName("Novak"); |
|
70 |
request.setDate(LocalDate.now()); |
|
71 |
request.setType(vacationType); |
|
72 |
request.setStatus(status); |
|
73 |
request.setTimestamp(LocalDateTime.now()); |
|
74 |
|
|
75 |
switch (vacationType) { |
|
76 |
case SICKDAY: { |
|
77 |
request.setFrom(null); |
|
78 |
request.setTo(null); |
|
79 |
} break; |
|
80 |
case VACATION: { |
|
81 |
request.setFrom(LocalTime.of(9, 30)); |
|
82 |
request.setTo(LocalTime.of(18, 30)); |
|
83 |
} break; |
|
84 |
} |
|
85 |
|
|
86 |
return request; |
|
87 |
} |
|
88 |
|
|
89 |
private AuthorizationRequest createAuthorizationRequest(long id, Status status) { |
|
90 |
AuthorizationRequest request = new AuthorizationRequest(); |
|
91 |
|
|
92 |
request.setId(id); |
|
93 |
request.setFirstName("Tomas"); |
|
94 |
request.setLastName("Novak"); |
|
95 |
request.setStatus(status); |
|
96 |
request.setTimestamp(LocalDateTime.now()); |
|
97 |
|
|
98 |
return request; |
|
99 |
} |
|
100 |
|
|
101 |
private FullUserProfile createFullUserProfile(Long id) { |
|
102 |
FullUserProfile user = new FullUserProfile(); |
|
103 |
|
|
104 |
user.setId(id); |
|
105 |
user.setFirstName("Tomas"); |
|
106 |
user.setLastName("Novak"); |
|
107 |
user.setPhoto("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg"); |
|
108 |
user.setStatus(Status.ACCEPTED); |
|
109 |
|
|
110 |
if (userSettings.containsKey(id)) { |
|
111 |
UserSettings settings = userSettings.get(id); |
|
112 |
user.setVacationCount(settings.getVacationCount()); |
|
113 |
user.setSickdayCount(settings.getSickdayCount()); |
|
114 |
user.setRole(settings.getRole()); |
|
115 |
} else { |
|
116 |
user.setVacationCount(8.5F); |
|
117 |
user.setSickdayCount(3); |
|
118 |
user.setRole(UserRole.EMPLOYER); |
|
119 |
} |
|
120 |
|
|
121 |
user.setNotification(LocalDateTime.of(2000, 12, 1, 9, 0)); |
|
122 |
|
|
123 |
return user; |
|
124 |
} |
|
125 |
|
|
126 |
private DefaultSettings createDefaultSettings() { |
|
127 |
DefaultSettings settings = new DefaultSettings(); |
|
128 |
|
|
129 |
settings.setSickdayCount(3); |
|
130 |
settings.setNotification(LocalDateTime.now()); |
|
131 |
|
|
132 |
return settings; |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public List<BasicProfileUser> getUsers(Status status) throws RESTFullException { |
|
137 |
int count = 5; |
|
138 |
List<BasicProfileUser> users = new ArrayList<>(count); |
|
139 |
for (int i = 1; i <= count; i++) { |
|
140 |
users.add(createBasicProfileUser(i, status)); |
|
141 |
} |
|
142 |
return users; |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public List<VacationRequest> getVacationRequests(Status status) throws RESTFullException { |
|
147 |
int count = 5; |
|
148 |
List<VacationRequest> requests = new ArrayList<>(count); |
|
149 |
int length = VacationType.values().length; |
|
150 |
for (int i = 1; i <= count; i++) { |
|
151 |
requests.add(createVacationRequest(i, VacationType.values()[i % length], status)); |
|
152 |
} |
|
153 |
return requests; |
|
154 |
} |
|
155 |
|
|
156 |
@Override |
|
157 |
public List<AuthorizationRequest> getAuthorizationRequests(Status status) { |
|
158 |
int count = 5; |
|
159 |
List<AuthorizationRequest> requests = new ArrayList<>(count); |
|
160 |
for (int i = 1; i <= count; i++) { |
|
161 |
requests.add(createAuthorizationRequest(i, status)); |
|
162 |
} |
|
163 |
return requests; |
|
164 |
} |
|
165 |
|
|
166 |
@Override |
|
167 |
public FullUserProfile getUserProfile(Long userId) { |
|
168 |
return createFullUserProfile(userId); |
|
169 |
} |
|
170 |
|
|
171 |
@Override |
|
172 |
public DefaultSettings getDefaultSettings() { |
|
173 |
return settings.isEmpty() ? createDefaultSettings() : settings.get(settings.size()-1); |
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
public List<VacationDay> getUserCalendar(Long userId, LocalDate fromDate, LocalDate toDate, Status status) { |
|
178 |
if (vacations.containsKey(userId)) { |
|
179 |
List<VacationDay> vacationDays = vacations.get(userId); |
|
180 |
Predicate<VacationDay> predicate = (day) -> day.getDate().isAfter(fromDate); |
|
181 |
predicate = predicate.or((day) -> day.getDate().isEqual(fromDate)); |
|
182 |
if (toDate != null) { |
|
183 |
predicate = predicate.and((day) -> day.getDate().isBefore(toDate)).or((day) -> day.getDate().isEqual(toDate)); |
|
184 |
} |
|
185 |
return vacationDays.stream().filter(predicate).collect(Collectors.toList()); |
|
186 |
|
|
187 |
} else { |
|
188 |
int daysDifference = toDate == null ? 5 : Period.between(fromDate, toDate).getDays(); |
|
189 |
List<VacationDay> days = new ArrayList<>(daysDifference); |
|
190 |
for (int i = 0; i < daysDifference; i++) { |
|
191 |
days.add(createVacationDay(i + 1, fromDate.plusDays(i), VacationType.values()[i % 2], status)); |
|
192 |
} |
|
193 |
return days; |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public void createSettings(DefaultSettings sett) { |
|
199 |
settings.add(sett); |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public void createVacation(Long userId, VacationDay vacationDay) { |
|
204 |
if (!vacations.containsKey(userId)) { |
|
205 |
vacations.put(userId, new ArrayList<>()); |
|
206 |
} |
|
207 |
|
|
208 |
List<VacationDay> days = vacations.get(userId); |
|
209 |
days.add(vacationDay); |
|
210 |
vacationDay.setId((long)days.size()); |
|
211 |
} |
|
212 |
|
|
213 |
@Override |
|
214 |
public void changeSettings(Long userId, UserSettings settings) { |
|
215 |
userSettings.put(userId, settings); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
|
220 |
if (vacationDay.getId() == null) { |
|
221 |
throw new RESTFullException("Vacation does not contain ID.", "rest.exception.generic"); |
|
222 |
} |
|
223 |
|
|
224 |
if (!vacations.containsKey(userId)) { |
|
225 |
throw new RESTFullException("User does not exist.", "rest.exception.generic"); |
|
226 |
} |
|
227 |
|
|
228 |
List<VacationDay> vacs = vacations.get(userId); |
|
229 |
boolean founded = false; |
|
230 |
for (int i = 0; i < vacs.size(); i++) { |
|
231 |
if (vacs.get(i).getId() == vacationDay.getId()) { |
|
232 |
VacationDay day = vacs.get(i); |
|
233 |
day.setStatus(vacationDay.getStatus()); |
|
234 |
day.setFrom(vacationDay.getFrom()); |
|
235 |
day.setTo(vacationDay.getTo()); |
|
236 |
day.setDate(vacationDay.getDate()); |
|
237 |
day.setType(vacationDay.getType()); |
|
238 |
founded = true; |
|
239 |
break; |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
if (!founded) { |
|
244 |
throw new RESTFullException("Vacation does not exist.", "rest.exception.generic"); |
|
245 |
} |
|
246 |
} |
|
247 |
|
|
248 |
@Override |
|
249 |
public void changeRequest(RequestType type, BasicRequest request) throws RESTFullException { |
|
250 |
|
|
251 |
if (request.getId() == null) { |
|
252 |
throw new RESTFullException("ID of request can not be empty.", "rest.exception.generic"); |
|
253 |
} |
|
254 |
|
|
255 |
switch (type) { |
|
256 |
case VACATION: { |
|
257 |
boolean found = false; |
|
258 |
for (List<VacationDay> value : vacations.values()) { |
|
259 |
for (VacationDay day : value) { |
|
260 |
if (day.getId() == request.getId()) { |
|
261 |
found = true; |
|
262 |
day.setStatus(request.getStatus()); |
|
263 |
break; |
|
264 |
} |
|
265 |
} |
|
266 |
if (found) break; |
|
267 |
} |
|
268 |
if (!found) { |
|
269 |
throw new RESTFullException("Vacation does not exist.", "rest.exception.generic"); |
|
270 |
} |
|
271 |
} break; |
|
272 |
case AUTHORIZATION: { |
|
273 |
throw new RESTFullException("User does not exist.", "rest.exception.generic"); |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public void deleteVacation(Long userId, Long vacationId) throws RESTFullException{ |
|
280 |
if (!vacations.containsKey(userId)) { |
|
281 |
throw new RESTFullException("User does not exist.", "rest.exception.generic"); |
|
282 |
} |
|
283 |
|
|
284 |
List<VacationDay> vacs = vacations.get(userId); |
|
285 |
if (!vacs.removeIf(day -> day.getId() == vacationId)) { |
|
286 |
throw new RESTFullException("Vacation does not exist for the user.", "rest.exception.generic"); |
|
287 |
} |
|
288 |
} |
|
289 |
} |
server/src/main/java/cz/zcu/yamanager/repository/TestRepository.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.repository; |
2 | 2 |
|
3 |
import cz.zcu.yamanager.dto.*; |
|
4 | 3 |
import org.slf4j.Logger; |
5 | 4 |
import org.slf4j.LoggerFactory; |
6 | 5 |
import org.springframework.beans.factory.annotation.Autowired; |
7 | 6 |
import org.springframework.jdbc.core.JdbcTemplate; |
8 | 7 |
import org.springframework.stereotype.Repository; |
9 | 8 |
|
10 |
import java.sql.ResultSet; |
|
11 |
import java.time.LocalDate; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 | 9 |
@Repository |
15 | 10 |
public class TestRepository { |
16 | 11 |
|
... | ... | |
23 | 18 |
this.jdbc = jdbc; |
24 | 19 |
} |
25 | 20 |
|
21 |
/* |
|
26 | 22 |
public List<AuthorizationRequest> getAllUserRequests() { |
27 | 23 |
return jdbc.query("SELECT id, first_name, last_name FROM end_user", (ResultSet rs, int rowNum) -> { |
28 | 24 |
AuthorizationRequest request = new AuthorizationRequest(); |
... | ... | |
55 | 51 |
} |
56 | 52 |
} |
57 | 53 |
|
58 |
public List<CalendarItem> getCalendarItems(long userId, LocalDate from, LocalDate to) {
|
|
54 |
public List<VacationDay> getCalendarItems(long userId, LocalDate from, LocalDate to) {
|
|
59 | 55 |
return jdbc.query("SELECT vacation_date, time_from, time_to, type_id, status_id FROM vacation_day WHERE user_id=? AND vacation_date >= ? AND vacation_date <= ?", |
60 | 56 |
new Object[]{userId, from, to}, (ResultSet rs, int rowNum) -> { |
61 |
CalendarItem item = new CalendarItem();
|
|
57 |
VacationDay item = new VacationDay();
|
|
62 | 58 |
item.setDate(rs.getDate("day.vacation_date").toLocalDate()); |
63 | 59 |
item.setFrom(rs.getTime("day.time_from").toLocalTime()); |
64 | 60 |
item.setTo(rs.getTime("day.time_to").toLocalTime()); |
... | ... | |
68 | 64 |
}); |
69 | 65 |
} |
70 | 66 |
|
71 |
/*public void insertCalendarItem(CalendarItem item) {
|
|
67 |
public void insertCalendarItem(VacationDay item) {
|
|
72 | 68 |
jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, user_id, status_id, type_id) VALUES (?,?,?,?,?,?)", |
73 | 69 |
item.getDate(), item.getFrom(), item.getTo(), item.getUserId(), item.getStatus().ordinal(), item.getType().ordinal()); |
74 | 70 |
} |
75 | 71 |
|
76 |
public void updateCalendarItem(CalendarItem item) {
|
|
72 |
public void updateCalendarItem(VacationDay item) {
|
|
77 | 73 |
jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, user_id=?, status_id=?, type_id=? WHERE id=?", |
78 | 74 |
item.getDate(), item.getFrom(), item.getTo(), item.getUserId(), item.getStatus().ordinal(), item.getType().ordinal(), item.getId()); |
79 |
}*/
|
|
75 |
} |
|
80 | 76 |
|
81 | 77 |
public DefaultSettings getLastSettings() { |
82 | 78 |
return jdbc.queryForObject("SELECT * FROM default_settings ORDER BY id DESC LIMIT 1", (ResultSet rs, int rowNum) -> { |
... | ... | |
112 | 108 |
user.setNotification(rs.getTimestamp("alert").toLocalDateTime()); |
113 | 109 |
user.setPhoto(rs.getString("photo")); |
114 | 110 |
user.setRole(UserRole.values()[rs.getByte("role_id")]); |
115 |
user.setStatus(UserStatus.values()[rs.getByte("status_id")]);
|
|
111 |
user.setStatus(Status.values()[rs.getByte("status_id")]); |
|
116 | 112 |
return user; |
117 | 113 |
}); |
118 | 114 |
} |
... | ... | |
128 | 124 |
user.setNotification(rs.getTimestamp("alert").toLocalDateTime()); |
129 | 125 |
user.setPhoto(rs.getString("photo")); |
130 | 126 |
user.setRole(UserRole.values()[rs.getByte("role_id")]); |
131 |
user.setStatus(UserStatus.values()[rs.getByte("status_id")]);
|
|
127 |
user.setStatus(Status.values()[rs.getByte("status_id")]); |
|
132 | 128 |
return user; |
133 | 129 |
}); |
134 | 130 |
} |
131 |
*/ |
|
135 | 132 |
} |
server/src/main/java/cz/zcu/yamanager/util/localization/Language.java | ||
---|---|---|
17 | 17 |
return locale; |
18 | 18 |
} |
19 | 19 |
|
20 |
public static Language get(String lang) { |
|
21 |
return valueOf(lang.toUpperCase()); |
|
20 |
public static Language getLanguageOrDefault(String lang, Language defaultLang) { |
|
21 |
try { |
|
22 |
return lang != null ? valueOf(lang.toUpperCase()) : defaultLang; |
|
23 |
} catch (IllegalArgumentException | NullPointerException e) { |
|
24 |
return defaultLang; |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 |
public static Language getLanguage(String lang) { |
|
29 |
return getLanguageOrDefault(lang, EN); |
|
22 | 30 |
} |
23 | 31 |
} |
server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.ws.rest; |
2 | 2 |
|
3 |
import cz.zcu.yamanager.dto.*; |
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
4 |
import cz.zcu.yamanager.dto.BasicRequest; |
|
5 |
import cz.zcu.yamanager.dto.DefaultSettings; |
|
6 |
import cz.zcu.yamanager.dto.UserSettings; |
|
7 |
import cz.zcu.yamanager.dto.VacationDay; |
|
8 |
import cz.zcu.yamanager.manager.Manager; |
|
9 |
import cz.zcu.yamanager.util.localization.Language; |
|
10 |
import cz.zcu.yamanager.util.localization.Message; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.slf4j.Logger; |
|
13 |
import org.slf4j.LoggerFactory; |
|
14 |
import org.springframework.beans.factory.annotation.Autowired; |
|
15 |
import org.springframework.http.MediaType; |
|
4 | 16 |
import org.springframework.http.ResponseEntity; |
5 | 17 |
import org.springframework.web.bind.annotation.*; |
6 | 18 |
|
7 | 19 |
import java.time.LocalDate; |
8 |
import java.time.LocalDateTime; |
|
9 |
import java.time.LocalTime; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.List; |
|
20 |
import java.time.format.DateTimeFormatter; |
|
21 |
import java.util.HashMap; |
|
12 | 22 |
|
23 |
import static cz.zcu.yamanager.dto.RequestType.getType; |
|
24 |
import static cz.zcu.yamanager.dto.Status.getStatus; |
|
25 |
import static cz.zcu.yamanager.util.localization.Language.getLanguage; |
|
13 | 26 |
import static org.springframework.http.HttpStatus.OK; |
14 | 27 |
import static org.springframework.http.ResponseEntity.ok; |
15 |
import static org.springframework.web.bind.annotation.RequestMethod.GET; |
|
16 |
import static org.springframework.web.bind.annotation.RequestMethod.POST; |
|
28 |
import static org.springframework.web.bind.annotation.RequestMethod.*; |
|
17 | 29 |
|
18 | 30 |
@RestController |
19 | 31 |
public class ApiController { |
20 | 32 |
|
21 |
// *********************** POST **************************** |
|
22 |
|
|
23 |
@RequestMapping(value = "/users", method=GET) |
|
24 |
public List<BasicProfileUser> users(@RequestParam("status") String status) { |
|
25 |
UserStatus userStatus = UserStatus.valueOf(status); |
|
26 |
|
|
27 |
List<BasicProfileUser> users = new ArrayList<>(); |
|
28 |
|
|
29 |
BasicProfileUser user = new BasicProfileUser(); |
|
30 |
user.setId(1); |
|
31 |
UserName userName = new UserName(); |
|
32 |
userName.setFirst("Tomas"); |
|
33 |
userName.setLast("Novak"); |
|
34 |
user.setName(userName); |
|
35 |
user.setPhoto("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg"); |
|
36 |
|
|
37 |
List<CalendarItem> calendarItems = new ArrayList<>(); |
|
33 |
private static final Logger log = LoggerFactory.getLogger(ApiController.class); |
|
38 | 34 |
|
39 |
CalendarItem calendarItem = new CalendarItem(); |
|
40 |
calendarItem.setType(VacationType.SICKDAY); |
|
41 |
calendarItem.setStatus(RequestStatus.ACCEPTED); |
|
42 |
calendarItem.setDate(LocalDate.now()); |
|
43 |
calendarItem.setFrom(LocalTime.now()); |
|
44 |
calendarItem.setTo(LocalTime.now()); |
|
45 |
calendarItems.add(calendarItem); |
|
46 |
user.setCalendar(calendarItems); |
|
35 |
private final Manager manager; |
|
47 | 36 |
|
48 |
users.add(user);
|
|
49 |
|
|
50 |
return users;
|
|
37 |
@Autowired
|
|
38 |
public ApiController(Manager manager) { |
|
39 |
this.manager = manager;
|
|
51 | 40 |
} |
52 | 41 |
|
53 |
@RequestMapping(value = "/user/{id}/profile", method=GET) |
|
54 |
public FullUserProfile userProfile(@PathVariable("id") String id) { |
|
55 |
long userId = Long.valueOf(id); |
|
56 |
FullUserProfile user = new FullUserProfile(); |
|
57 |
|
|
58 |
user.setId(userId); |
|
59 |
UserName userName = new UserName(); |
|
60 |
userName.setFirst("Tomas"); |
|
61 |
userName.setLast("Novak"); |
|
62 |
user.setName(userName); |
|
63 |
user.setPhoto("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg"); |
|
64 |
user.setRole(UserRole.EMPLOYEE); |
|
65 |
user.setNotification(LocalDateTime.of(2010, 5, 4, 16, 10)); |
|
66 |
user.setStatus(UserStatus.AUTHORIZED); |
|
67 |
VacationInfo sickday = new VacationInfo(); |
|
68 |
sickday.setValue(3); |
|
69 |
sickday.setUnit(VacationUnit.DAY); |
|
70 |
user.setSickDay(sickday); |
|
71 |
VacationInfo vacation = new VacationInfo(); |
|
72 |
vacation.setValue(15); |
|
73 |
vacation.setUnit(VacationUnit.HOUR); |
|
74 |
user.setVacation(vacation); |
|
75 |
return user; |
|
42 |
private ResponseEntity sendError(Integer errorCode, String messageKey, Language language) { |
|
43 |
String localizedMessage = Message.getString(language, messageKey); |
|
44 |
String msg = String.format("{\"error\": %s,\"message\": \"%s\"}", errorCode, localizedMessage); |
|
45 |
return ResponseEntity.status(errorCode).contentType(MediaType.APPLICATION_JSON).body(msg); |
|
76 | 46 |
} |
77 | 47 |
|
78 |
@RequestMapping(value = "/users/requests", method=GET) |
|
79 |
public UserRequest userRequests(@RequestParam(value = "type", required = false) String type) { |
|
80 |
RequestType requestType = RequestType.valueOf(type); |
|
81 |
|
|
82 |
UserName userName = new UserName(); |
|
83 |
userName.setFirst("Tomas"); |
|
84 |
userName.setLast("Novak"); |
|
85 |
|
|
86 |
UserRequest request = new UserRequest(); |
|
87 |
|
|
88 |
List<AuthorizationRequest> authorization = new ArrayList<>(); |
|
89 |
AuthorizationRequest authRequest = new AuthorizationRequest(); |
|
90 |
authRequest.setId(1); |
|
91 |
authRequest.setUserName(userName); |
|
92 |
authRequest.setDate(LocalDateTime.now()); |
|
93 |
|
|
94 |
authorization.add(authRequest); |
|
95 |
request.setAuthorization(authorization); |
|
96 |
|
|
97 |
List<VacationRequest> vacation = new ArrayList<>(); |
|
98 |
VacationRequest vacRequest = new VacationRequest(); |
|
99 |
vacRequest.setId(1); |
|
100 |
vacRequest.setUserName(userName); |
|
101 |
vacRequest.setStatus(RequestStatus.PENDING); |
|
102 |
vacRequest.setType(VacationType.SICKDAY); |
|
103 |
vacRequest.setDate(LocalDate.now()); |
|
104 |
vacRequest.setFrom(LocalTime.of(9, 30)); |
|
105 |
vacRequest.setTo(LocalTime.of(18, 30)); |
|
106 |
|
|
107 |
vacation.add(vacRequest); |
|
108 |
request.setVacation(vacation); |
|
48 |
private <T> ResponseEntity handle(Language language, RESTGetHandler<T> handler) { |
|
49 |
try { |
|
50 |
return ok(handler.get()); |
|
51 |
} catch (RESTFullException e) { |
|
52 |
log.error(e.getMessage()); |
|
53 |
return sendError(400, e.getLocalizedMessage(), language); |
|
54 |
} catch (Exception e) { |
|
55 |
log.error(e.getMessage()); |
|
56 |
return sendError(401, "rest.exception.generic", language); |
|
57 |
} |
|
58 |
} |
|
109 | 59 |
|
110 |
return request; |
|
60 |
private <T> ResponseEntity handle(Language language, RESTInvokeHandler<T> handler) { |
|
61 |
try { |
|
62 |
handler.invoke(); |
|
63 |
return ok(OK); |
|
64 |
} catch (RESTFullException e) { |
|
65 |
log.error(e.getMessage()); |
|
66 |
return sendError(400, e.getLocalizedMessage(), language); |
|
67 |
} catch (Exception e) { |
|
68 |
log.error(e.getMessage()); |
|
69 |
return sendError(401, "rest.exception.generic", language); |
|
70 |
} |
|
111 | 71 |
} |
112 | 72 |
|
73 |
private Long getUserId(String id) { |
|
74 |
// TODO verify permission |
|
75 |
if (id.toLowerCase().equals("me")) { |
|
76 |
return 1L; |
|
77 |
} else if (StringUtils.isNumeric(id)) { |
|
78 |
return Long.valueOf(id); |
|
79 |
} else { |
|
80 |
throw new IllegalArgumentException("User not found."); |
|
81 |
} |
|
82 |
} |
|
113 | 83 |
|
114 |
@RequestMapping(value = "/user/calendar", method=GET) |
|
115 |
public List<CalendarItem> personalCalendarView(@RequestParam("viewType") String viewType, @RequestParam("value") String value) { |
|
116 |
CalendarViewType calendarViewType = CalendarViewType.valueOf(viewType); |
|
117 |
int numberOfView = Integer.valueOf(value); |
|
84 |
// *********************** GET **************************** |
|
118 | 85 |
|
119 |
List<CalendarItem> calendarItems = new ArrayList<>(); |
|
86 |
@RequestMapping(value = "/users", method=GET) |
|
87 |
public ResponseEntity users( |
|
88 |
@RequestParam(value = "lang", required = false) String lang, |
|
89 |
@RequestParam(value = "status", required = false) String status) |
|
90 |
{ |
|
91 |
return handle(getLanguage(lang), () -> |
|
92 |
manager.getUsers(getStatus(status)) |
|
93 |
); |
|
94 |
} |
|
120 | 95 |
|
121 |
CalendarItem view = new CalendarItem(); |
|
122 |
view.setStatus(RequestStatus.PENDING); |
|
123 |
view.setType(VacationType.SICKDAY); |
|
124 |
view.setDate(LocalDate.now()); |
|
125 |
view.setFrom(LocalTime.of(9, 30)); |
|
126 |
view.setTo(LocalTime.of(18, 30)); |
|
96 |
@RequestMapping(value = "/users/requests/vacation", method=GET) |
|
97 |
public ResponseEntity usersRequestsVacation( |
|
98 |
@RequestParam(value = "lang", required = false) String lang, |
|
99 |
@RequestParam(value = "status", required = false) String status) |
|
100 |
{ |
|
101 |
return handle(getLanguage(lang), () -> |
|
102 |
manager.getVacationRequests(getStatus(status)) |
|
103 |
); |
|
104 |
} |
|
127 | 105 |
|
128 |
calendarItems.add(view); |
|
106 |
@RequestMapping(value = "/users/requests/authorization", method=GET) |
|
107 |
public ResponseEntity userRequestsAuthorization( |
|
108 |
@RequestParam(value = "lang", required = false) String lang, |
|
109 |
@RequestParam(value = "status", required = false) String status) |
|
110 |
{ |
|
111 |
return handle(getLanguage(lang), () -> |
|
112 |
manager.getAuthorizationRequests(getStatus(status)) |
|
113 |
); |
|
114 |
} |
|
129 | 115 |
|
130 |
return calendarItems; |
|
116 |
@RequestMapping(value = "/user/{id}/profile", method=GET) |
|
117 |
public ResponseEntity userProfile( |
|
118 |
@PathVariable("id") String id, |
|
119 |
@RequestParam(value = "lang", required = false) String lang) |
|
120 |
{ |
|
121 |
return handle(getLanguage(lang), () -> |
|
122 |
manager.getUserProfile(getUserId(id)) |
|
123 |
); |
|
131 | 124 |
} |
132 | 125 |
|
133 | 126 |
@RequestMapping(value = "/user/{id}/calendar", method=GET) |
134 |
public List<CalendarItem> userCalendarView(@PathVariable("id") String id, @RequestParam("viewType") String viewType, @RequestParam("value") String value) { |
Také k dispozici: Unified diff
Re #7477 Edited endpoints and created mock manager for data