Revize 79e44ca9
Přidáno uživatelem Dominik Poch před téměř 6 roky(ů)
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
12 | 12 |
import org.springframework.jdbc.core.JdbcTemplate; |
13 | 13 |
import org.springframework.stereotype.Component; |
14 | 14 |
|
15 |
import java.time.Duration; |
|
15 | 16 |
import java.time.LocalDate; |
17 |
import java.time.temporal.TemporalUnit; |
|
16 | 18 |
import java.util.Collections; |
17 | 19 |
import java.util.List; |
18 | 20 |
|
21 |
import static java.time.temporal.ChronoUnit.MINUTES; |
|
22 |
|
|
19 | 23 |
@Component |
20 | 24 |
public class ApiManager implements Manager { |
21 | 25 |
|
... | ... | |
46 | 50 |
users = this.userRepository.getAllBasicUsers(status); |
47 | 51 |
} |
48 | 52 |
|
49 |
if(users == null) { |
|
50 |
return Collections.emptyList(); |
|
51 |
} else { |
|
52 |
LocalDate today = LocalDate.now(); |
|
53 |
LocalDate weekBefore = today.minusDays(ApiManager.DAYS_IN_WEEK); |
|
54 |
LocalDate weekAfter = today.plusDays(ApiManager.DAYS_IN_WEEK); |
|
55 |
for (BasicProfileUser user : users) { |
|
56 |
user.setCalendar(this.vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter)); |
|
57 |
} |
|
58 |
|
|
59 |
return users; |
|
53 |
LocalDate today = LocalDate.now(); |
|
54 |
LocalDate weekBefore = today.minusDays(ApiManager.DAYS_IN_WEEK); |
|
55 |
LocalDate weekAfter = today.plusDays(ApiManager.DAYS_IN_WEEK); |
|
56 |
for (BasicProfileUser user : users) { |
|
57 |
user.setCalendar(this.vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter)); |
|
60 | 58 |
} |
59 |
|
|
60 |
return users; |
|
61 |
|
|
61 | 62 |
} |
62 | 63 |
|
63 | 64 |
@Override |
... | ... | |
69 | 70 |
requests = this.requestRepository.getAllVacationRequests(status); |
70 | 71 |
} |
71 | 72 |
|
72 |
return requests == null ? Collections.emptyList() : requests;
|
|
73 |
return requests; |
|
73 | 74 |
} |
74 | 75 |
|
75 | 76 |
@Override |
... | ... | |
81 | 82 |
requests = this.requestRepository.getAllAuthorizations(status); |
82 | 83 |
} |
83 | 84 |
|
84 |
return requests == null ? Collections.emptyList() : requests;
|
|
85 |
return requests; |
|
85 | 86 |
} |
86 | 87 |
|
87 | 88 |
@Override |
88 | 89 |
public FullUserProfile getUserProfile(Long userId) throws RESTFullException { |
89 |
FullUserProfile userProfile = this.userRepository.getFullUser(userId); |
|
90 |
System.out.println("Notification: " + userProfile.getNotification()); |
|
91 |
System.out.println("Approval: " + userProfile.getStatus()); |
|
92 |
return userProfile; |
|
90 |
return this.userRepository.getFullUser(userId); |
|
93 | 91 |
} |
94 | 92 |
|
95 | 93 |
@Override |
... | ... | |
111 | 109 |
vacations = this.vacationRepository.getVacationDays(userId, fromDate, status); |
112 | 110 |
} |
113 | 111 |
|
114 |
return vacations == null ? Collections.emptyList() : vacations;
|
|
112 |
return vacations; |
|
115 | 113 |
} |
116 | 114 |
|
117 | 115 |
@Override |
... | ... | |
121 | 119 |
|
122 | 120 |
@Override |
123 | 121 |
public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException { |
122 |
UserRole role = this.userRepository.getUserRole(userId); |
|
123 |
vacationDay.setStatus(role == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING); |
|
124 |
|
|
125 |
if(vacationDay.getType() == VacationType.VACATION) { |
|
126 |
this.userRepository.decreaseVacationCount(userId, vacationDay.getFrom().until(vacationDay.getTo(), MINUTES) / 60f); |
|
127 |
} else { |
|
128 |
this.userRepository.increaseTakenSickdays(userId); |
|
129 |
} |
|
130 |
|
|
124 | 131 |
this.vacationRepository.insertVacationDay(userId, vacationDay); |
125 | 132 |
} |
126 | 133 |
|
127 | 134 |
@Override |
128 | 135 |
public void changeSettings(Long userId, UserSettings settings) throws RESTFullException { |
129 | 136 |
settings.setId(userId); |
130 |
if(settings.getRole() == null && settings.getSickdayCount() == null && settings.getVacationCount() == null) {
|
|
137 |
if(settings.getRole() == null && settings.getSickDayCount() == null && settings.getVacationCount() == null) {
|
|
131 | 138 |
this.userRepository.updateNotification(settings); |
132 | 139 |
} else { |
133 | 140 |
this.userRepository.updateUserSettings(settings); |
server/src/main/java/cz/zcu/yamanager/business/mock/ManagerMock.java | ||
---|---|---|
109 | 109 |
if (userSettings.containsKey(id)) { |
110 | 110 |
UserSettings settings = userSettings.get(id); |
111 | 111 |
user.setVacationCount(settings.getVacationCount()); |
112 |
user.setSickdayCount(settings.getSickdayCount());
|
|
112 |
user.setSickDayCount(settings.getSickDayCount());
|
|
113 | 113 |
user.setRole(settings.getRole()); |
114 | 114 |
} else { |
115 | 115 |
user.setVacationCount(8.5F); |
116 |
user.setSickdayCount(3);
|
|
116 |
user.setSickDayCount(3);
|
|
117 | 117 |
user.setRole(UserRole.EMPLOYER); |
118 | 118 |
} |
119 | 119 |
|
... | ... | |
125 | 125 |
private DefaultSettings createDefaultSettings() { |
126 | 126 |
DefaultSettings settings = new DefaultSettings(); |
127 | 127 |
|
128 |
settings.setSickdayCount(3);
|
|
128 |
settings.setSickDayCount(3);
|
|
129 | 129 |
settings.setNotification(LocalDateTime.now()); |
130 | 130 |
|
131 | 131 |
return settings; |
server/src/main/java/cz/zcu/yamanager/domain/DefaultSettings.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.domain; |
2 | 2 |
|
3 |
import java.time.LocalDate; |
|
3 |
import org.slf4j.Logger; |
|
4 |
import org.slf4j.LoggerFactory; |
|
5 |
|
|
6 |
import java.time.LocalDateTime; |
|
4 | 7 |
|
5 | 8 |
/** |
6 |
* A domain class {@code DefaultSettings} represents a single record in the Default_settings table of a database. |
|
7 |
* It contains default settings of the application. |
|
9 |
* The domain class {@code DefaultSettings} represents a single record in the 'default_settings' table of a database. |
|
10 |
* It contains default settings of users' informations that are known to the application. Informations consist of a number of |
|
11 |
* available sick days, date and time of an email notification. Default settings are mainly used when the user is added to |
|
12 |
* the application which means he/she can't have his/her own values. |
|
8 | 13 |
*/ |
9 | 14 |
public class DefaultSettings { |
10 |
|
|
11 | 15 |
/** |
12 |
* ID of the default settings.
|
|
16 |
* The logger.
|
|
13 | 17 |
*/ |
14 |
private final int id;
|
|
18 |
private static final Logger log = LoggerFactory.getLogger(DefaultSettings.class);
|
|
15 | 19 |
|
16 | 20 |
/** |
17 |
* Default remaining vacation hours.
|
|
21 |
* The ID of default settings.
|
|
18 | 22 |
*/ |
19 |
private int noVacations;
|
|
23 |
private final long id;
|
|
20 | 24 |
|
21 | 25 |
/** |
22 |
* Default remaining sick days.
|
|
26 |
* The default number of available sick days.
|
|
23 | 27 |
*/ |
24 |
private int noSickDays;
|
|
28 |
private int sickDayCount;
|
|
25 | 29 |
|
26 | 30 |
/** |
27 |
* Default date of an email warning about an incoming reset of the vacation hours and sick days.
|
|
31 |
* The default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days.
|
|
28 | 32 |
*/ |
29 |
private LocalDate alertDate;
|
|
33 |
private LocalDateTime notification;
|
|
30 | 34 |
|
31 | 35 |
/** |
32 |
* Creates a new instance of the class {@code DefaultSettings}. |
|
33 |
* @param id ID of the default settings. |
|
34 |
* @param noVacations Default remaining vacation hours. |
|
35 |
* @param noSickDays Default remaining sick days. |
|
36 |
* @param alertDate Default date of an email warning about an incoming reset of the vacation hours and sick days. |
|
36 |
* Creates an empty default settings for testing purposes only. |
|
37 |
* It just sets id to zero. |
|
37 | 38 |
*/ |
38 |
public DefaultSettings(int id, int noVacations, int noSickDays, LocalDate alertDate) { |
|
39 |
this.id = id; |
|
40 |
this.noVacations = noVacations; |
|
41 |
this.noSickDays = noSickDays; |
|
42 |
this.alertDate = alertDate; |
|
39 |
public DefaultSettings() { |
|
40 |
DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings."); |
|
41 |
this.id = 0; |
|
43 | 42 |
} |
44 | 43 |
|
45 | 44 |
/** |
46 |
* Gets an ID of the default settings. |
|
47 |
* @return The ID of the default settings. |
|
45 |
* Creates a new default settings with the specified id, number of available sick days, date and time of a notification. |
|
46 |
* |
|
47 |
* @param id the ID of default settings |
|
48 |
* @param sickDayCount the default number of available sick days |
|
49 |
* @param notification the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
|
50 |
* @throws IllegalArgumentException when the given sickDayCount value is negative |
|
48 | 51 |
*/ |
49 |
public int getId() {
|
|
50 |
return id;
|
|
51 |
}
|
|
52 |
public DefaultSettings(final long id, final int sickDayCount, final LocalDateTime notification) throws IllegalArgumentException {
|
|
53 |
DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings.");
|
|
54 |
DefaultSettings.log.debug("DefaultSettings: id={},\nsickDayCount={},\nnotification={}", id, sickDayCount, notification);
|
|
52 | 55 |
|
53 |
/** |
|
54 |
* Gets a default remaining vacation hours. |
|
55 |
* @return The default remaining vacation hours. |
|
56 |
*/ |
|
57 |
public int getNoVacations() { |
|
58 |
return noVacations; |
|
56 |
this.id = id; |
|
57 |
this.setSickDayCount(sickDayCount); |
|
58 |
this.notification = notification; |
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
/** |
62 |
* Sets a new default remaining vacation hours. |
|
63 |
* @param noVacations The new default remaining vacation hours. |
|
62 |
* Returns the ID of this default settings. |
|
63 |
* |
|
64 |
* @return the ID of this default settings |
|
64 | 65 |
*/ |
65 |
public void setNoVacations(int noVacations) {
|
|
66 |
this.noVacations = noVacations;
|
|
66 |
public long getId() {
|
|
67 |
return this.id;
|
|
67 | 68 |
} |
68 | 69 |
|
69 | 70 |
/** |
70 |
* Gets a default remaining sick days. |
|
71 |
* @return The default remaining sick days. |
|
71 |
* Returns the default number of available sick days in this default settings. |
|
72 |
* |
|
73 |
* @return the default number of available sick days |
|
72 | 74 |
*/ |
73 |
public int getNoSickDays() {
|
|
74 |
return noSickDays;
|
|
75 |
public int getSickDayCount() {
|
|
76 |
return this.sickDayCount;
|
|
75 | 77 |
} |
76 | 78 |
|
77 | 79 |
/** |
78 |
* Sets a new default remaining sick days. |
|
79 |
* @param noSickDays The new default remaining sick days. |
|
80 |
* Replaces the default number of available sick days in this default settings with the given one. |
|
81 |
* If the given number is negative the method throws an exception. |
|
82 |
* |
|
83 |
* @param sickDayCount the new default number of available sick days |
|
84 |
* @throws IllegalArgumentException when the given value is negative |
|
80 | 85 |
*/ |
81 |
public void setNoSickDays(int noSickDays) { |
|
82 |
this.noSickDays = noSickDays; |
|
86 |
public void setSickDayCount(final int sickDayCount) throws IllegalArgumentException { |
|
87 |
DefaultSettings.log.debug("Setting a new number of available sick days: {}.", sickDayCount); |
|
88 |
|
|
89 |
if (sickDayCount < 0) { |
|
90 |
DefaultSettings.log.warn("The number of available sick days was negative."); |
|
91 |
throw new IllegalArgumentException("sick.day.count.error"); |
|
92 |
} |
|
93 |
|
|
94 |
this.sickDayCount = sickDayCount; |
|
83 | 95 |
} |
84 | 96 |
|
85 | 97 |
/** |
86 |
* Gets a default date of an email warning about an incoming reset of the vacation hours and sick days. |
|
87 |
* @return The default date of an email warning about an incoming reset of the vacation hours and sick days. |
|
98 |
* Returns the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days. |
|
99 |
* |
|
100 |
* @return the default date and time |
|
88 | 101 |
*/ |
89 |
public LocalDate getAlertDate() {
|
|
90 |
return alertDate;
|
|
102 |
public LocalDateTime getNotification() {
|
|
103 |
return this.notification;
|
|
91 | 104 |
} |
92 | 105 |
|
93 | 106 |
/** |
94 |
* Sets a new default date of an email warning about an incoming reset of the vacation hours and sick days. |
|
95 |
* @param alertDate The new default date of an email warning about an incoming reset of the vacation hours and sick days. |
|
107 |
* Replaces the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days with the specified one. |
|
108 |
* |
|
109 |
* @param notification the new default date and time |
|
96 | 110 |
*/ |
97 |
public void setAlertDate(LocalDate alertDate) { |
|
98 |
this.alertDate = alertDate; |
|
111 |
public void setNotification(final LocalDateTime notification) { |
|
112 |
DefaultSettings.log.debug("Setting a new default date and time of sending an email warning: {}.", notification); |
|
113 |
this.notification = notification; |
|
99 | 114 |
} |
100 | 115 |
|
101 | 116 |
/** |
102 |
* Gets a string representation of the class {@code DefaultSettings}. |
|
103 |
* @return The string representation of the class. |
|
117 |
* Returns a string representation of this default settings. The representation consists of the id, number of sick days and notification of the default settings. |
|
118 |
* |
|
119 |
* @return the string representation of this default settings |
|
104 | 120 |
*/ |
105 | 121 |
@Override |
106 | 122 |
public String toString() { |
107 | 123 |
return "DefaultSettings{" + |
108 |
"id=" + id + |
|
109 |
", noVacations=" + noVacations + |
|
110 |
", noSickDays=" + noSickDays + |
|
111 |
", alertDate=" + alertDate + |
|
124 |
"id=" + this.id + |
|
125 |
", sickDayCount=" + this.sickDayCount + |
|
126 |
", notification=" + this.notification + |
|
112 | 127 |
'}'; |
113 | 128 |
} |
114 | 129 |
} |
server/src/main/java/cz/zcu/yamanager/domain/Right.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
/** |
|
4 |
* A domain class {@code Right} represents a single record in the Right table of a database. |
|
5 |
* It holds informations about a user's right, which says what can a user do in the application. |
|
6 |
* Rights are grouped to roles ({@code Role}). |
|
7 |
*/ |
|
8 |
public class Right { |
|
9 |
|
|
10 |
/** |
|
11 |
* ID of the right. |
|
12 |
*/ |
|
13 |
private final int id; |
|
14 |
|
|
15 |
/** |
|
16 |
* Name of the right. |
|
17 |
*/ |
|
18 |
private String name; |
|
19 |
|
|
20 |
/** |
|
21 |
* Description of the right. |
|
22 |
*/ |
|
23 |
private String description; |
|
24 |
|
|
25 |
/** |
|
26 |
* Creates a new instance of the class {@code Right}. |
|
27 |
* @param id ID of the right. |
|
28 |
* @param name Name of the right. |
|
29 |
* @param description Description of the right. |
|
30 |
*/ |
|
31 |
public Right(int id, String name, String description) { |
|
32 |
this.id = id; |
|
33 |
this.name = name; |
|
34 |
this.description = description; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets an ID of the right. |
|
39 |
* @return The ID of the right. |
|
40 |
*/ |
|
41 |
public int getId() { |
|
42 |
return this.id; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Gets a name of the right. |
|
47 |
* @return The name of the right. |
|
48 |
*/ |
|
49 |
public String getName() { |
|
50 |
return this.name; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Sets a new name. |
|
55 |
* @param name The new name. |
|
56 |
*/ |
|
57 |
public void setName(String name) { |
|
58 |
this.name = name; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Gets a description of the right. |
|
63 |
* @return The description of the right. |
|
64 |
*/ |
|
65 |
public String getDescription() { |
|
66 |
return this.description; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Sets a new description. |
|
71 |
* @param description The new description. |
|
72 |
*/ |
|
73 |
public void setDescription(String description) { |
|
74 |
this.description = description; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Gets a string representation of the class {@code Right}. |
|
79 |
* @return The string representation of the class. |
|
80 |
*/ |
|
81 |
@Override |
|
82 |
public String toString() { |
|
83 |
return "Right{" + |
|
84 |
"id=" + this.id + |
|
85 |
", name='" + this.name + '\'' + |
|
86 |
", description='" + this.description + '\'' + |
|
87 |
'}'; |
|
88 |
} |
|
89 |
} |
server/src/main/java/cz/zcu/yamanager/domain/Role.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
/** |
|
7 |
* A domain class {@code Role} represents a single record in the Role table of a database. |
|
8 |
* Role groups user's rights to a bigger wholes. |
|
9 |
*/ |
|
10 |
public class Role { |
|
11 |
|
|
12 |
/** |
|
13 |
* ID of the role. |
|
14 |
*/ |
|
15 |
private final int id; |
|
16 |
|
|
17 |
/** |
|
18 |
* Name of the role. |
|
19 |
*/ |
|
20 |
private String name; |
|
21 |
|
|
22 |
/** |
|
23 |
* List of rights of the role. |
|
24 |
*/ |
|
25 |
private List<Right> rightList; |
|
26 |
|
|
27 |
/** |
|
28 |
* Creates a new instance of the class {@code Role}. |
|
29 |
* @param id ID of the role. |
|
30 |
* @param name Name of the role. |
|
31 |
* @param rightList List of rights of the role. |
|
32 |
*/ |
|
33 |
public Role(int id, String name, List<Right> rightList) { |
|
34 |
this.id = id; |
|
35 |
this.name = name; |
|
36 |
this.rightList = rightList; |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* Gets an ID of the role. |
|
41 |
* @return The ID of the right. |
|
42 |
*/ |
|
43 |
public int getId() { |
|
44 |
return this.id; |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Gets a name of the role. |
|
49 |
* @return The name of the role. |
|
50 |
*/ |
|
51 |
public String getName() { |
|
52 |
return this.name; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Sets a new name. |
|
57 |
* @param name The new name. |
|
58 |
*/ |
|
59 |
public void setName(String name) { |
|
60 |
this.name = name; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Returns a copy of a list of rights. |
|
65 |
* @return The copy of the list of rights. |
|
66 |
*/ |
|
67 |
public List<Right> getRightList() { |
|
68 |
return new ArrayList<>(this.rightList); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Sets a copy of the given list of rights. |
|
73 |
* @param rightList The given list of rights. |
|
74 |
*/ |
|
75 |
public void setRightList(List<Right> rightList) { |
|
76 |
this.rightList = new ArrayList<>(rightList); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Gets a string representation of the class {@code Role}. |
|
81 |
* @return The string representation of the class. |
|
82 |
*/ |
|
83 |
@Override |
|
84 |
public String toString() { |
|
85 |
return "Role{" + |
|
86 |
"id=" + id + |
|
87 |
", name='" + name + '\'' + |
|
88 |
", rightList=" + rightList + |
|
89 |
'}'; |
|
90 |
} |
|
91 |
} |
server/src/main/java/cz/zcu/yamanager/domain/SickDay.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
import java.time.LocalDate; |
|
4 |
|
|
5 |
/** |
|
6 |
* A domain class {@code SickDay} represents a single record in the Sick_days table of a database. |
|
7 |
* Class holds informations of a sick day taken by a user. |
|
8 |
*/ |
|
9 |
public class SickDay { |
|
10 |
|
|
11 |
/** |
|
12 |
* ID of the sick day. |
|
13 |
*/ |
|
14 |
private final int id; |
|
15 |
|
|
16 |
/** |
|
17 |
* Date of the sick day. |
|
18 |
*/ |
|
19 |
private LocalDate date; |
|
20 |
|
|
21 |
/** |
|
22 |
* Approval status of the sick day. |
|
23 |
*/ |
|
24 |
private Status status; |
|
25 |
|
|
26 |
/** |
|
27 |
* Creates a new instance of the class {@code SickDay}. |
|
28 |
* @param id ID of the sick day. |
|
29 |
* @param date Date of the sick day. |
|
30 |
* @param status Approval status of the sick day. |
|
31 |
*/ |
|
32 |
public SickDay(int id, LocalDate date, Status status) { |
|
33 |
this.id = id; |
|
34 |
this.date = date; |
|
35 |
this.status = status; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Gets an ID of the sick day. |
|
40 |
* @return The ID of the sick day. |
|
41 |
*/ |
|
42 |
public int getId() { |
|
43 |
return id; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Gets a date of the sick day. |
|
48 |
* @return The date of the sick day. |
|
49 |
*/ |
|
50 |
public LocalDate getDate() { |
|
51 |
return date; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Sets a new date. |
|
56 |
* @param date The new date. |
|
57 |
*/ |
|
58 |
public void setDate(LocalDate date) { |
|
59 |
this.date = date; |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Gets an approval status of the sick day. |
|
64 |
* @return The approval status of the sick day. |
|
65 |
*/ |
|
66 |
public Status getStatus() { |
|
67 |
return status; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Sets a new approval status. |
|
72 |
* @param status The new approval status. |
|
73 |
*/ |
|
74 |
public void setStatus(Status status) { |
|
75 |
this.status = status; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Gets a string representation of the class {@code SickDay}. |
|
80 |
* @return The string representation of the class. |
|
81 |
*/ |
|
82 |
@Override |
|
83 |
public String toString() { |
|
84 |
return "SickDay{" + |
|
85 |
"id=" + id + |
|
86 |
", date=" + date + |
|
87 |
", status=" + status + |
|
88 |
'}'; |
|
89 |
} |
|
90 |
} |
server/src/main/java/cz/zcu/yamanager/domain/Status.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
/** |
|
4 |
* A domain class {@code Status} represents a single record in the Approval_status table of a database. |
|
5 |
* Approval status indicates state of user's authorization or vacation/sick days confirmation. |
|
6 |
*/ |
|
7 |
public class Status { |
|
8 |
|
|
9 |
/** |
|
10 |
* ID of the status. |
|
11 |
*/ |
|
12 |
private final int id; |
|
13 |
|
|
14 |
/** |
|
15 |
* Name of the status. |
|
16 |
*/ |
|
17 |
private String name; |
|
18 |
|
|
19 |
/** |
|
20 |
* Creates a new instance of the class {@code Status}. |
|
21 |
* @param id ID of the status. |
|
22 |
* @param name Name of the status. |
|
23 |
*/ |
|
24 |
public Status(int id, String name) { |
|
25 |
this.id = id; |
|
26 |
this.name = name; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* Gets an ID of the status. |
|
31 |
* @return The ID of the status. |
|
32 |
*/ |
|
33 |
public int getId() { |
|
34 |
return id; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets a name of the status. |
|
39 |
* @return The name of the status. |
|
40 |
*/ |
|
41 |
public String getName() { |
|
42 |
return name; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Sets a new name. |
|
47 |
* @param name The new name. |
|
48 |
*/ |
|
49 |
public void setName(String name) { |
|
50 |
this.name = name; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Gets a string representation of the class {@code Status}. |
|
55 |
* @return The string representation of the class. |
|
56 |
*/ |
|
57 |
@Override |
|
58 |
public String toString() { |
|
59 |
return "Status{" + |
|
60 |
"id=" + id + |
|
61 |
", name='" + name + '\'' + |
|
62 |
'}'; |
|
63 |
} |
|
64 |
} |
server/src/main/java/cz/zcu/yamanager/domain/Test.java | ||
---|---|---|
1 |
package cz.zcu.yamanager.domain; |
|
2 |
|
|
3 |
public class Test { |
|
4 |
|
|
5 |
private final long id; |
|
6 |
private final String message; |
|
7 |
|
|
8 |
public Test(long id, String message) { |
|
9 |
this.id = id; |
|
10 |
this.message = message; |
|
11 |
} |
|
12 |
|
|
13 |
public long getId() { |
|
14 |
return id; |
|
15 |
} |
|
16 |
|
|
17 |
public String getMessage() { |
|
18 |
return message; |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public String toString() { |
|
23 |
return String.format("Test[id=%d, message='%s']", id, message); |
|
24 |
} |
|
25 |
} |
server/src/main/java/cz/zcu/yamanager/domain/User.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.domain; |
2 | 2 |
|
3 |
import java.time.LocalDate; |
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.UserRole; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
|
|
8 |
import java.time.LocalDateTime; |
|
4 | 9 |
|
5 | 10 |
/** |
6 |
* A domain class {@code User} represents a single record in the User table of a database.
|
|
7 |
* User hold all informations about a user which logged to the application.
|
|
11 |
* The domain class {@code User} represents a single record in the 'end_user' table of a database.
|
|
12 |
* User holds all informations about a user which is logged to the application.
|
|
8 | 13 |
*/ |
9 | 14 |
public class User { |
15 |
/** |
|
16 |
* The maximal length of a name. |
|
17 |
*/ |
|
18 |
private static final int NAME_LENGTH = 45; |
|
19 |
|
|
20 |
/** |
|
21 |
* The maximal length of an email address. |
|
22 |
*/ |
|
23 |
private static final int EMAIL_ADDRESS_LENGTH = 100; |
|
10 | 24 |
|
11 | 25 |
/** |
12 |
* User's ID.
|
|
26 |
* The logger.
|
|
13 | 27 |
*/ |
14 |
private final int id;
|
|
28 |
private static final Logger log = LoggerFactory.getLogger(User.class);
|
|
15 | 29 |
|
16 | 30 |
/** |
17 |
* User's first name. |
|
31 |
* The user's ID. |
|
32 |
*/ |
|
33 |
private final long id; |
|
34 |
|
|
35 |
/** |
|
36 |
* The user's first name. |
|
18 | 37 |
*/ |
19 | 38 |
private String firstName; |
20 | 39 |
|
21 | 40 |
/** |
22 |
* User's last name.
|
|
41 |
* The user's last name.
|
|
23 | 42 |
*/ |
24 | 43 |
private String lastName; |
25 | 44 |
|
26 | 45 |
/** |
27 |
* User's remaining vacation hours. |
|
46 |
* The number of user's remaining hours of an overtime. |
|
47 |
*/ |
|
48 |
private float vacationCount; |
|
49 |
|
|
50 |
/** |
|
51 |
* The number of user's sick days available during a year. |
|
28 | 52 |
*/ |
29 |
private int noVacations;
|
|
53 |
private int totalSickDayCount;
|
|
30 | 54 |
|
31 | 55 |
/** |
32 |
* User's remaining sick days.
|
|
56 |
* The number of user's taken sick days.
|
|
33 | 57 |
*/ |
34 |
private int noSickDays;
|
|
58 |
private int takenSickDayCount;
|
|
35 | 59 |
|
36 | 60 |
/** |
37 |
* Date of an email warning about an incoming reset of the vacation hours and sick days.
|
|
61 |
* The date and time of sending an email warning about an incoming reset of remaining overtimes and sick days.
|
|
38 | 62 |
*/ |
39 |
private LocalDate alertDate;
|
|
63 |
private LocalDateTime notification;
|
|
40 | 64 |
|
41 | 65 |
/** |
42 |
* Token for the Google oAuth. |
|
66 |
* The token for the Google oAuth.
|
|
43 | 67 |
*/ |
44 | 68 |
private String token; |
45 | 69 |
|
46 | 70 |
/** |
47 |
* User's email address.
|
|
71 |
* The user's email address.
|
|
48 | 72 |
*/ |
49 | 73 |
private String email; |
50 | 74 |
|
51 | 75 |
/** |
52 |
* URL of a user's photo. |
|
76 |
* The URL of a user's photo.
|
|
53 | 77 |
*/ |
54 | 78 |
private String photo; |
55 | 79 |
|
56 | 80 |
/** |
57 |
* User's role. |
|
81 |
* The date and time of a user's creation. |
|
82 |
*/ |
|
83 |
private final LocalDateTime creationDate; |
|
84 |
|
|
85 |
/** |
|
86 |
* The user's role. |
|
58 | 87 |
*/ |
59 |
private Role role; |
|
88 |
private UserRole role;
|
|
60 | 89 |
|
61 | 90 |
/** |
62 |
* User's approval status.
|
|
91 |
* The user's authorization status.
|
|
63 | 92 |
*/ |
64 | 93 |
private Status status; |
65 | 94 |
|
66 | 95 |
/** |
67 |
* Creates a new instance of the class {@code User}. |
|
68 |
* @param id User's ID. |
|
69 |
* @param firstName User's first name. |
|
70 |
* @param lastName User's last name. |
|
71 |
* @param noVacations User's remaining vacation hours. |
|
72 |
* @param noSickDays User's remaining sick days. |
|
73 |
* @param alertDate Date of email warning about an incoming reset of the vacation hours and sick days. |
|
74 |
* @param token Token for the Google oAuth. |
|
75 |
* @param email User's email address. |
|
76 |
* @param photo URL of a user's photo. |
|
77 |
* @param role User's role. |
|
78 |
* @param status User's approval status. |
|
79 |
*/ |
|
80 |
public User(int id, String firstName, String lastName, int noVacations, int noSickDays, LocalDate alertDate, String token, String email, String photo, Role role, Status status) { |
|
96 |
* Creates an empty user for testing purposes only. |
|
97 |
* It just sets id to zero and creation date to now. |
|
98 |
*/ |
|
99 |
public User() { |
|
100 |
User.log.trace("Creating a new instance of the class User."); |
|
101 |
this.id = 0; |
|
102 |
this.creationDate = LocalDateTime.now(); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Creates a new user and sets all its attributes. |
|
107 |
* |
|
108 |
* @param id the user's ID |
|
109 |
* @param firstName the user's first name |
|
110 |
* @param lastName the user's last name. |
|
111 |
* @param vacationCount the number of user's remaining hours of an overtime |
|
112 |
* @param totalSickDayCount the number of user's sick days available during a year |
|
113 |
* @param takenSickDayCount the number of user's taken sick days |
|
114 |
* @param notification the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
|
115 |
* @param token the token for the Google oAuth |
|
116 |
* @param email the user's email address |
|
117 |
* @param photo the URL of a user's photo |
|
118 |
* @param creationDate the date and time of a user's creation |
|
119 |
* @param role the user's role |
|
120 |
* @param status the user's authorization status |
|
121 |
* @throws IllegalArgumentException when the vacationCount, totalSickDayCount or takenSickDayCount are negative or first name, last name or email exceed the maximal permitted number of characters |
|
122 |
*/ |
|
123 |
public User(final long id, final String firstName, final String lastName, final float vacationCount, final int totalSickDayCount, final int takenSickDayCount, final LocalDateTime notification, final String token, final String email, final String photo, final LocalDateTime creationDate, final UserRole role, final Status status) throws IllegalArgumentException { |
|
124 |
User.log.trace("Creating a new instance of the class User."); |
|
125 |
User.log.debug("User: id={},\nfirstName={},\nlastName={},\nvacationCount={},\ntotalSickDayCount={},\ntakenSickDayCount={},\nnotification={},\ntoken={},\nemail={},\nphoto={},\ncreationDate={},\nrole={},\nstatus={}", id, firstName, lastName, vacationCount, totalSickDayCount, takenSickDayCount, notification, token, email, photo, creationDate, role, status); |
|
126 |
|
|
81 | 127 |
this.id = id; |
82 |
this.firstName = firstName; |
|
83 |
this.lastName = lastName; |
|
84 |
this.noVacations = noVacations; |
|
85 |
this.noSickDays = noSickDays; |
|
86 |
this.alertDate = alertDate; |
|
128 |
this.setFirstName(firstName); |
|
129 |
this.setLastName(lastName); |
|
130 |
this.setVacationCount(vacationCount); |
|
131 |
this.setTotalSickDayCount(totalSickDayCount); |
|
132 |
this.setTakenSickDayCount(takenSickDayCount); |
|
133 |
this.notification = notification; |
|
87 | 134 |
this.token = token; |
88 |
this.email = email;
|
|
135 |
this.setEmail(email);
|
|
89 | 136 |
this.photo = photo; |
137 |
this.creationDate = creationDate; |
|
90 | 138 |
this.role = role; |
91 | 139 |
this.status = status; |
92 | 140 |
} |
93 | 141 |
|
94 | 142 |
/** |
95 |
* Gets a user's ID. |
|
96 |
* @return The user's ID. |
|
143 |
* Returns the user's ID. |
|
144 |
* |
|
145 |
* @return the user's ID |
|
97 | 146 |
*/ |
98 |
public int getId() {
|
|
99 |
return id; |
|
147 |
public long getId() {
|
|
148 |
return this.id;
|
|
100 | 149 |
} |
101 | 150 |
|
102 | 151 |
/** |
103 |
* Gets a user's first name. |
|
104 |
* @return The user's first name. |
|
152 |
* Returns the user's first name. |
|
153 |
* |
|
154 |
* @return the user's first name |
|
105 | 155 |
*/ |
106 | 156 |
public String getFirstName() { |
107 |
return firstName; |
|
157 |
return this.firstName;
|
|
108 | 158 |
} |
109 | 159 |
|
110 | 160 |
/** |
111 |
* Sets a new first name. |
|
112 |
* @param firstName The new first name. |
|
161 |
* Replaces the user's first name with the new specified value. |
|
162 |
* If the given name is longer than the maximal allowed number of characters the method throws an exception. |
|
163 |
* |
|
164 |
* @param firstName the new first name |
|
165 |
* @throws IllegalArgumentException when the given name is longer than the maximal allowed number of characters |
|
113 | 166 |
*/ |
114 |
public void setFirstName(String firstName) { |
|
167 |
public void setFirstName(final String firstName) throws IllegalArgumentException { |
|
168 |
User.log.debug("Setting a new first name: {}", firstName); |
|
169 |
|
|
170 |
if (firstName.length() > User.NAME_LENGTH) { |
|
171 |
User.log.warn("The length of the given first name exceeded the limit."); |
|
172 |
throw new IllegalArgumentException("name.length.error"); |
|
173 |
} |
|
174 |
|
|
115 | 175 |
this.firstName = firstName; |
116 | 176 |
} |
117 | 177 |
|
118 | 178 |
/** |
119 |
* Gets a user's last name. |
|
120 |
* @return The user's last name. |
|
179 |
* Returns the user's last name. |
|
180 |
* |
|
181 |
* @return the user's last name |
|
121 | 182 |
*/ |
122 | 183 |
public String getLastName() { |
123 |
return lastName; |
|
184 |
return this.lastName;
|
|
124 | 185 |
} |
125 | 186 |
|
126 | 187 |
/** |
127 |
* Sets a new last name. |
|
128 |
* @param lastName The new last name. |
|
188 |
* Replaces the user's last name with the given one. |
|
189 |
* If the given name is longer than the maximal allowed number of characters the method throws an exception. |
|
190 |
* |
|
191 |
* @param lastName the new last name |
|
192 |
* @throws IllegalArgumentException when the given name is longer than the maximal allowed number of characters |
|
129 | 193 |
*/ |
130 |
public void setLastName(String lastName) { |
|
194 |
public void setLastName(final String lastName) throws IllegalArgumentException { |
|
195 |
User.log.debug("Setting a new last name: {}", lastName); |
|
196 |
|
|
197 |
if (lastName.length() > User.NAME_LENGTH) { |
|
198 |
User.log.warn("The length of the given last name exceeded the limit."); |
|
199 |
throw new IllegalArgumentException("name.length.error"); |
|
200 |
} |
|
201 |
|
|
131 | 202 |
this.lastName = lastName; |
132 | 203 |
} |
133 | 204 |
|
134 | 205 |
/** |
135 |
* Gets a user's remaining vacation hours. |
|
136 |
* @return The user's remaining vacation hours. |
|
206 |
* Returns the number of user's remaining hours of an overtime. |
|
207 |
* |
|
208 |
* @return the number of user's remaining hours of the overtime |
|
137 | 209 |
*/ |
138 |
public int getNoVacations() {
|
|
139 |
return noVacations;
|
|
210 |
public float getVacationCount() {
|
|
211 |
return this.vacationCount;
|
|
140 | 212 |
} |
141 | 213 |
|
142 | 214 |
/** |
143 |
* Sets a new number of remaining vacation hours. |
|
144 |
* If the given value is negative the number of vacation hours is set to zero. |
|
145 |
* @param noVacations The new number of remaining vacation hours. |
|
215 |
* Replaces the number of user's remaining hours of an overtime with the specified value. |
|
216 |
* If the given number is negative the method throws an exception. |
|
217 |
* |
|
218 |
* @param vacationCount the new number of remaining hours of the overtime. |
|
219 |
* @throws IllegalArgumentException when the given value is negative |
|
146 | 220 |
*/ |
147 |
public void setNoVacations(int noVacations) { |
|
148 |
this.noVacations = noVacations < 0 ? 0 : noVacations; |
|
221 |
public void setVacationCount(final float vacationCount) throws IllegalArgumentException { |
|
222 |
User.log.debug("Setting a new number of remaining overtime: {}", vacationCount); |
|
223 |
|
|
224 |
if (vacationCount < 0) { |
|
225 |
User.log.warn("The given number of remaining overtime must not be negative."); |
|
226 |
throw new IllegalArgumentException("vacation.count.error"); |
|
227 |
} |
|
228 |
|
|
229 |
this.vacationCount = vacationCount; |
|
149 | 230 |
} |
150 | 231 |
|
151 | 232 |
/** |
152 |
* Gets a user's remaining sick days. |
|
153 |
* @return The user's remaining sick days. |
|
233 |
* Increases the number of user's remaining hours of an overtime by the given amount. |
|
234 |
* |
|
235 |
* @param amount the amount of hours |
|
154 | 236 |
*/ |
155 |
public int getNoSickDays() { |
|
156 |
return noSickDays; |
|
237 |
public void increaseVacationCount(final float amount) { |
|
238 |
User.log.debug("Increasing the number of remaining overtime by {}", amount); |
|
239 |
this.vacationCount += amount; |
|
157 | 240 |
} |
158 | 241 |
|
159 | 242 |
/** |
160 |
* Sets a new number of remaining sick days. |
|
161 |
* If the given value is negative the number of sick days is set to zero. |
|
162 |
* @param noSickDays The new number of remaining sick days. |
|
243 |
* Decreases the number of user's remaining hours of an overtime by the given amount. |
|
244 |
* If the new number of remaining hours is below zero the method throws an exception. |
|
245 |
* |
|
246 |
* @param amount the amount of hours |
|
247 |
* @throws IllegalArgumentException when the result of the subtraction is negative |
|
163 | 248 |
*/ |
164 |
public void setNoSickDays(int noSickDays) { |
|
165 |
this.noSickDays = noSickDays < 0 ? 0 : noSickDays; |
|
249 |
public void decreaseVacationCount(final float amount) throws IllegalArgumentException { |
|
250 |
User.log.debug("Decreasing the number of remaining overtime by {}", amount); |
|
251 |
|
|
252 |
if (this.vacationCount - amount < 0) { |
|
253 |
User.log.warn("The result of the decrease must not be negative."); |
|
254 |
throw new IllegalArgumentException("vacation.count.error"); |
|
255 |
} |
|
256 |
|
|
257 |
this.vacationCount -= amount; |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Returns the number of user's sick days available during a year. |
|
262 |
* |
|
263 |
* @return the number of user's sick days available during the year |
|
264 |
*/ |
|
265 |
public int getTotalSickDayCount() { |
|
266 |
return this.totalSickDayCount; |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* Replaces the number of user's sick days available during a year with the new value. |
|
271 |
* If the given number is negative the method throws an exception. |
|
272 |
* |
|
273 |
* @param totalSickDayCount the new number of sick days available during the year |
|
274 |
* @throws IllegalArgumentException when the given value is negative |
|
275 |
*/ |
|
276 |
public void setTotalSickDayCount(final int totalSickDayCount) throws IllegalArgumentException { |
|
277 |
User.log.debug("Setting a new number of user's sick days available during a year: {}", totalSickDayCount); |
|
278 |
|
|
279 |
if (totalSickDayCount < 0) { |
|
280 |
User.log.warn("The given number of user's sick days available during a year must not be negative."); |
|
281 |
throw new IllegalArgumentException("sick.day.count.error"); |
|
282 |
} |
|
283 |
|
|
284 |
this.totalSickDayCount = totalSickDayCount; |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* Returns the number of user's taken sick days. |
|
289 |
* |
|
290 |
* @return the number of user's taken sick days |
|
291 |
*/ |
|
292 |
public int getTakenSickDayCount() { |
|
293 |
return this.takenSickDayCount; |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* Replaces the number of user's taken sick days with the new value. |
|
298 |
* If the given number is negative the method throws an exception. |
|
299 |
* |
|
300 |
* @param takenSickDayCount the new number of taken sick days |
|
301 |
* @throws IllegalArgumentException when the given value is negative |
|
302 |
*/ |
|
303 |
public void setTakenSickDayCount(final int takenSickDayCount) throws IllegalArgumentException { |
|
304 |
User.log.debug("Setting a new number of user's taken sick days: {}", takenSickDayCount); |
|
305 |
|
|
306 |
if (takenSickDayCount < 0) { |
|
307 |
User.log.warn("The given number number of user's taken sick days must not be negative."); |
|
308 |
throw new IllegalArgumentException("sick.day.count.error"); |
|
309 |
} |
|
310 |
|
|
311 |
this.takenSickDayCount = takenSickDayCount; |
|
166 | 312 |
} |
167 | 313 |
|
168 | 314 |
/** |
169 |
* Gets a date of an email warning about an incoming reset of the vacation hours and sick days. |
|
170 |
* @return The date of the email warning about the incoming reset of the vacation hours and sick days. |
|
315 |
* Returns the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days. |
|
316 |
* |
|
317 |
* @return the date and time |
|
171 | 318 |
*/ |
172 |
public LocalDate getAlertDate() {
|
|
173 |
return alertDate;
|
|
319 |
public LocalDateTime getNotification() {
|
|
320 |
return this.notification;
|
|
174 | 321 |
} |
175 | 322 |
|
176 | 323 |
/** |
177 |
* Sets a new date of an email warning about an incoming reset of the vacation hours and sick days. |
|
178 |
* @param alertDate The new date of the email warning about the incoming reset of the vacation hours and sick days. |
|
324 |
* Replaces the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days with the given value. |
|
325 |
* |
|
326 |
* @param notification the new date and time |
|
179 | 327 |
*/ |
180 |
public void setAlertDate(LocalDate alertDate) { |
|
181 |
this.alertDate = alertDate; |
|
328 |
public void setNotification(final LocalDateTime notification) { |
|
329 |
User.log.debug("Setting a new date and time of sending an email warning: {}", notification); |
|
330 |
this.notification = notification; |
|
182 | 331 |
} |
183 | 332 |
|
184 | 333 |
/** |
185 |
* Gets a user's token for the Google oAuth. |
|
186 |
* @return The user's token for the Google oAuth. |
|
334 |
* Returns the user's token for the Google oAuth. |
|
335 |
* |
|
336 |
* @return the user's token for the Google oAuth |
|
187 | 337 |
*/ |
188 | 338 |
public String getToken() { |
189 |
return token; |
|
339 |
return this.token;
|
|
190 | 340 |
} |
191 | 341 |
|
192 | 342 |
/** |
193 |
* Sets a new token for the Google oAuth. |
|
194 |
* @param token The new token for the Google oAuth. |
|
343 |
* Replaces the user's token for the Google oAuth with the specified string. |
|
344 |
* |
|
345 |
* @param token the new token for the Google oAuth |
|
195 | 346 |
*/ |
196 |
public void setToken(String token) { |
|
347 |
public void setToken(final String token) { |
|
348 |
User.log.debug("Setting a new token: {}", token); |
|
197 | 349 |
this.token = token; |
198 | 350 |
} |
199 | 351 |
|
200 | 352 |
/** |
201 |
* Gets a user's email address. |
|
202 |
* @return The user's email address. |
|
353 |
* Returns the user's email address. |
|
354 |
* |
|
355 |
* @return the user's email address |
|
203 | 356 |
*/ |
204 | 357 |
public String getEmail() { |
205 |
return email; |
|
358 |
return this.email;
|
|
206 | 359 |
} |
207 | 360 |
|
208 | 361 |
/** |
209 |
* Sets a new email address. |
|
210 |
* @param email The new email address. |
|
362 |
* Replaces the user's email address with the new given value. |
|
363 |
* If the given email is longer than the maximal allowed number of characters the method throws an exception. |
|
364 |
* |
|
365 |
* @param email the new email address |
|
366 |
* @throws IllegalArgumentException when the given email is longer than the maximal allowed number of characters |
|
211 | 367 |
*/ |
212 |
public void setEmail(String email) { |
|
368 |
public void setEmail(final String email) throws IllegalArgumentException { |
|
369 |
User.log.debug("Setting a new email address: {}", email); |
|
370 |
|
|
371 |
if (email.length() > User.EMAIL_ADDRESS_LENGTH) { |
|
372 |
User.log.warn("The length of the email address exceeded the limit."); |
|
373 |
throw new IllegalArgumentException("email.length.error"); |
|
374 |
} |
|
375 |
|
|
213 | 376 |
this.email = email; |
214 | 377 |
} |
215 | 378 |
|
216 | 379 |
/** |
217 |
* Gets a URL of a user's photo. |
|
218 |
* @return The URL of the user's photo. |
|
380 |
* Returns the URL of a user's photo. |
|
381 |
* |
|
382 |
* @return the URL of the user's photo |
|
219 | 383 |
*/ |
220 | 384 |
public String getPhoto() { |
221 |
return photo; |
|
385 |
return this.photo;
|
|
222 | 386 |
} |
223 | 387 |
|
224 | 388 |
/** |
225 |
* Sets a new URL of a user's photo. |
|
226 |
* @param photo The new URL of a user's photo. |
|
389 |
* Replaces the URL of a user's photo with the given link. |
|
390 |
* |
|
391 |
* @param photo the new URL of the user's photo |
|
227 | 392 |
*/ |
228 |
public void setPhoto(String photo) { |
|
393 |
public void setPhoto(final String photo) { |
|
394 |
User.log.debug("Setting a new url of a photo: {}", photo); |
|
229 | 395 |
this.photo = photo; |
230 | 396 |
} |
231 | 397 |
|
232 | 398 |
/** |
233 |
* Gets a user's role. |
|
234 |
* @return The user's role. |
|
399 |
* Returns the date and time of a user's creation. |
|
400 |
* |
|
401 |
* @return the date and time of the user's creation |
|
402 |
*/ |
|
403 |
public LocalDateTime getCreationDate() { |
|
404 |
return this.creationDate; |
|
405 |
} |
|
406 |
|
|
407 |
/** |
|
408 |
* Returns the user's role. |
|
409 |
* |
|
410 |
* @return the user's role |
|
235 | 411 |
*/ |
236 |
public Role getRole() { |
|
237 |
return role; |
|
412 |
public UserRole getRole() {
|
|
413 |
return this.role;
|
|
238 | 414 |
} |
239 | 415 |
|
240 | 416 |
/** |
241 |
* Sets a new role. |
|
242 |
* @param role The new role. |
|
417 |
* Replaces the user's role with the new provided value. |
|
418 |
* |
|
419 |
* @param role the new role |
|
243 | 420 |
*/ |
244 |
public void setRole(Role role) { |
|
421 |
public void setRole(final UserRole role) { |
|
422 |
User.log.debug("Setting a new user's role: {}", role); |
|
245 | 423 |
this.role = role; |
246 | 424 |
} |
247 | 425 |
|
248 | 426 |
/** |
249 |
* Gets a user's approval status. |
|
250 |
* @return The user's approval status. |
|
427 |
* Returns the user's authorization status. |
|
428 |
* |
|
429 |
* @return the user's authorization status |
|
251 | 430 |
*/ |
252 | 431 |
public Status getStatus() { |
253 |
return status; |
|
432 |
return this.status;
|
|
254 | 433 |
} |
255 | 434 |
|
256 | 435 |
/** |
257 |
* Sets a new approval status. |
|
258 |
* @param status The new approval status. |
|
436 |
* Replaces the authorization status with the handed value. |
|
437 |
* |
|
438 |
* @param status the new authorization status |
|
259 | 439 |
*/ |
260 |
public void setStatus(Status status) { |
|
440 |
public void setStatus(final Status status) { |
|
441 |
User.log.debug("Setting a new authorization status: {}", status); |
|
261 | 442 |
this.status = status; |
262 | 443 |
} |
263 | 444 |
|
264 | 445 |
/** |
265 |
* Gets a string representation of the class {@code User}. |
|
266 |
* @return The string representation of the class. |
|
446 |
* Gets a string representation of this user. The representation contains the id, first name, last name, |
|
447 |
* number of user's remaining hours of an overtime, number of user's sick days available during a year, |
|
448 |
* number of user's taken sick days, date and time of sending an email warning about an incoming reset of |
|
449 |
* remaining overtimes and sick days, token for the Google oAuth, email address, URL of a photo, role and |
|
450 |
* authorization status. |
|
451 |
* |
|
452 |
* @return the string representation of this user |
|
267 | 453 |
*/ |
268 | 454 |
@Override |
269 | 455 |
public String toString() { |
270 | 456 |
return "User{" + |
271 |
"id=" + id + |
|
272 |
", firstName='" + firstName + '\'' + |
|
273 |
", lastName='" + lastName + '\'' + |
|
274 |
", noVacations=" + noVacations + |
|
275 |
", noSickDays=" + noSickDays + |
|
276 |
", alertDate=" + alertDate + |
|
277 |
", token='" + token + '\'' + |
|
278 |
", email='" + email + '\'' + |
|
279 |
", photo='" + photo + '\'' + |
|
280 |
", role=" + role + |
|
281 |
", status=" + status + |
|
457 |
"id=" + this.id + |
|
458 |
", firstName='" + this.firstName + '\'' + |
|
459 |
", lastName='" + this.lastName + '\'' + |
|
460 |
", vacationCount=" + this.vacationCount + |
|
461 |
", totalSickDayCount=" + this.totalSickDayCount + |
|
462 |
", takenSickDayCount=" + this.takenSickDayCount + |
|
463 |
", notification=" + this.notification + |
|
464 |
", token='" + this.token + '\'' + |
|
465 |
", email='" + this.email + '\'' + |
|
466 |
", photo='" + this.photo + '\'' + |
|
467 |
", creationDate=" + this.creationDate + |
|
468 |
", role=" + this.role + |
|
469 |
", status=" + this.status + |
|
282 | 470 |
'}'; |
283 | 471 |
} |
284 | 472 |
} |
server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java | ||
---|---|---|
1 | 1 |
package cz.zcu.yamanager.domain; |
2 | 2 |
|
3 |
import cz.zcu.yamanager.dto.Status; |
|
4 |
import cz.zcu.yamanager.dto.VacationType; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
|
|
8 |
import javax.naming.OperationNotSupportedException; |
|
3 | 9 |
import java.time.LocalDate; |
10 |
import java.time.LocalDateTime; |
|
4 | 11 |
import java.time.LocalTime; |
5 | 12 |
|
6 | 13 |
/** |
7 |
* A domain class {@code VacationDay} represents a single record in the Vacation_day table of a database.
|
|
8 |
* Class holds informations of a vacation day taken by a user.
|
|
14 |
* The domain class {@code VacationDay} represents a single record in the 'vacation_day' table of a database.
|
|
15 |
* Class holds informations of an overtime or a sick day taken by a user.
|
|
9 | 16 |
*/ |
10 | 17 |
public class VacationDay { |
18 |
/** |
|
19 |
* The logger. |
|
20 |
*/ |
|
21 |
private static final Logger log = LoggerFactory.getLogger(VacationDay.class); |
|
11 | 22 |
|
12 | 23 |
/** |
13 |
* ID of the vacation day.
|
|
24 |
* The ID of this vacation.
|
|
14 | 25 |
*/ |
15 | 26 |
private final int id; |
16 | 27 |
|
17 | 28 |
/** |
18 |
* Date of the vacation day.
|
|
29 |
* The date of this vacation.
|
|
19 | 30 |
*/ |
20 | 31 |
private LocalDate date; |
21 | 32 |
|
22 | 33 |
/** |
23 |
* Starting time of a vacation.
|
|
34 |
* The starting time of this vacation.
|
|
24 | 35 |
*/ |
25 | 36 |
private LocalTime from; |
26 | 37 |
|
27 | 38 |
/** |
28 |
* Ending time of a vacation.
|
|
39 |
* The ending time of this vacation.
|
|
29 | 40 |
*/ |
30 | 41 |
private LocalTime to; |
31 | 42 |
|
32 | 43 |
/** |
33 |
* Approval status of the vacation day. |
|
44 |
* The date and time of a creation of this vacation. |
|
45 |
*/ |
|
46 |
private final LocalDateTime creationDate; |
|
47 |
|
|
48 |
/** |
|
49 |
* The approval status of this vacation. |
|
34 | 50 |
*/ |
35 | 51 |
private Status status; |
36 | 52 |
|
37 | 53 |
/** |
38 |
* Creates a new instance of the class {@code VacationDay}. |
|
39 |
* @param id ID of the vacation day. |
|
40 |
* @param date Date of the vacation day. |
|
41 |
* @param from Starting time of a vacation. |
|
42 |
* @param to Ending time of a vacation. |
|
43 |
* @param status Approval status of the vacation day. |
|
54 |
* The type of this vacation. |
|
55 |
*/ |
|
56 |
private VacationType type; |
|
57 |
|
|
58 |
/** |
|
59 |
* Creates an empty vacation for testing purposes only. |
|
60 |
* It just sets id to zero and creation date to nowte. |
|
44 | 61 |
*/ |
45 |
public VacationDay(int id, LocalDate date, LocalTime from, LocalTime to, Status status) { |
|
62 |
public VacationDay() { |
|
63 |
VacationDay.log.trace("Creating a new instance of the class VacationDay."); |
|
64 |
this.id = 0; |
|
65 |
this.creationDate = LocalDateTime.now(); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Creates a new sick day with the specified id, date, date when a sick day request was created and its approval status. |
|
70 |
* |
|
71 |
* @param id the ID of the sick day |
|
72 |
* @param date the date of the sick day |
|
73 |
* @param creationDate the date and time of the creation of the sick day |
|
74 |
* @param status the approval status of the sick day |
|
75 |
*/ |
|
76 |
public VacationDay(final int id, final LocalDate date, final LocalDateTime creationDate, final Status status) { |
|
77 |
this(id, date, null, null, creationDate, status, VacationType.SICKDAY); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Creates a new overtime with the specified id, date, starting time, ending time, date when an overtime request was created and its approval status. |
|
82 |
* |
|
83 |
* @param id the ID of the overtime |
|
84 |
* @param date the date of the overtime |
|
85 |
* @param from the starting time of the overtime |
|
86 |
* @param to the ending time of the overtime |
|
87 |
* @param creationDate the date and time of the creation of the overtime |
|
88 |
* @param status the approval status of the overtime |
|
89 |
*/ |
|
90 |
public VacationDay(final int id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status) { |
|
91 |
this(id, date, from, to, creationDate, status, VacationType.VACATION); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Creates a new overtime or sick day with all attributes. |
|
96 |
* |
|
97 |
* @param id the ID of a vacation |
|
98 |
* @param date the date of a vacation |
|
99 |
* @param from the starting time of a vacation |
|
100 |
* @param to the ending time of a vacation |
|
101 |
* @param creationDate the date and time of a creation of a vacation |
|
102 |
* @param status the approval status of a vacation |
|
103 |
* @param type the type of a vacation |
|
104 |
*/ |
|
105 |
private VacationDay(final int id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status, final VacationType type) { |
|
106 |
VacationDay.log.trace("Creating a new instance of the class VacationDay."); |
|
107 |
VacationDay.log.debug("VacationDay: id={},\ndate={},\nfrom={},\nto={},\ncreationDate={},\nstatus={},\ntype={}", id, date, from, to, creationDate, status, type); |
|
108 |
|
|
46 | 109 |
this.id = id; |
47 | 110 |
this.date = date; |
48 |
this.from = from;
|
|
49 |
this.to = to;
|
|
111 |
this.setTime(from, to);
|
|
112 |
this.creationDate = creationDate;
|
|
50 | 113 |
this.status = status; |
114 |
this.type = type; |
|
51 | 115 |
} |
52 | 116 |
|
53 | 117 |
/** |
54 |
* Gets an ID of the vacation day. |
|
55 |
* @return The ID of the vacation day. |
|
118 |
* Returns the ID of this vacation. |
|
119 |
* |
|
120 |
* @return the ID of this vacation |
|
56 | 121 |
*/ |
57 | 122 |
public int getId() { |
58 |
return id; |
|
123 |
return this.id;
|
|
59 | 124 |
} |
60 | 125 |
|
61 | 126 |
/** |
62 |
* Gets a date of the vacation day. |
|
63 |
* @return The date of the vacation day. |
|
127 |
* Returns the date of this vacation. |
|
128 |
* |
|
129 |
* @return the date of this vacation |
|
64 | 130 |
*/ |
65 | 131 |
public LocalDate getDate() { |
66 |
return date; |
|
132 |
return this.date;
|
|
67 | 133 |
} |
68 | 134 |
|
69 | 135 |
/** |
70 |
* Sets a new date. |
|
71 |
* @param date The new date. |
|
136 |
* Replaces the date of this vacation with the specified date. |
|
137 |
* |
|
138 |
* @param date the new date |
|
72 | 139 |
*/ |
73 |
public void setDate(LocalDate date) { |
|
140 |
public void setDate(final LocalDate date) { |
|
141 |
VacationDay.log.debug("Settings a new value of a date: {}", date); |
|
74 | 142 |
this.date = date; |
75 | 143 |
} |
76 | 144 |
|
Také k dispozici: Unified diff
Documentation domain and dto, unit test domain, error input domain