-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeModuleService.java
More file actions
145 lines (123 loc) · 6.02 KB
/
EmployeeModuleService.java
File metadata and controls
145 lines (123 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package TaskManagerProject;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class EmployeeModuleService {
// Databases (In-Memory Data Store)
private List<TimeCard> TimeCardDatabase = new ArrayList<>();
private List<WorkRequest> workRequestsDatabase = new ArrayList<>();
private List<LeaveRequest> leaveRequestsDatabase = new ArrayList<>();
// d) Leave Types List (Configurable Record of Vacation Types)
private List<String> leaveTypes = new ArrayList<>(List.of("ANNUAL", "SICK", "UNPAID", "MATERNITY", "CASUAL"));
private boolean LeaderOrAdmin(Employee employee) {
if (employee == null || employee.getEmployeeRole() == null) {
return false;
}
String role = employee.getEmployeeRole().toUpperCase();
return role.equals("ADMIN") || role.equals("LEADER");
}
// d) Add Leave Types (Restricted to Leaders or Admins)
public void addLeaveType(Employee Requestor, String type) {
if (!LeaderOrAdmin(Requestor)) {
System.out.println("ACCESS DENIED: Only Leaders or Admins can add Leave Types.");
return;
}
if (!leaveTypes.contains(type.toUpperCase())) {
leaveTypes.add(type.toUpperCase());
System.out.println("Leave Type '" + type.toUpperCase() + "' added successfully by " + Requestor.getEmpName());
} else {
System.err.println("ERROR: The Leave Type Already Present!");
}
}
// a) Timecards: Recording Attendance (Check-In)
public void checkIn(Employee employee) {
TimeCard card = new TimeCard(employee);
TimeCardDatabase.add(card);
System.out.println(employee.getEmpName() + " checked in successfully at " + card.getCheckInTime());
}
// a) Timecards: Recording Departure (Check-Out)
public void checkOut(Employee employee) {
TimeCard activeCard = TimeCardDatabase.stream()
.filter(t -> t.getEmployee().getEmpID().equals(employee.getEmpID()) && t.getCheckOutTime() == null)
.findFirst()
.orElse(null);
if (activeCard != null) {
activeCard.setCheckOutTime(LocalDateTime.now());
System.out.println(employee.getEmpName() + " checked out successfully at " + activeCard.getCheckOutTime());
} else {
System.out.println("ERROR: No active Check-In found for " + employee.getEmpName());
}
}
// b) Mission and Permission Requests Creation
public void requestMissionOrPermission(Employee employee, String type, LocalDateTime start, LocalDateTime end, String reason) {
if (!type.equalsIgnoreCase("MISSION") && !type.equalsIgnoreCase("PERMISSION")) {
System.out.println("ERROR: Invalid Request Type. Must be MISSION or PERMISSION.");
return;
}
WorkRequest request = new WorkRequest(employee, type, start, end, reason);
workRequestsDatabase.add(request);
System.out.println(type + " request submitted successfully by " + employee.getEmpName());
}
// e) Leave Request Creation
public void requestLeave(Employee employee, String leaveType, LocalDate start, LocalDate end) {
if (!leaveTypes.contains(leaveType.toUpperCase())) {
System.out.println("ERROR: '" + leaveType + "' is not a recognized Leave Type.");
return;
}
LeaveRequest request = new LeaveRequest(employee, leaveType, start, end);
leaveRequestsDatabase.add(request);
// Printed the unique Leave ID right inside the confirmation message!
System.out.println("Leave request (" + leaveType + ") with ID [" + request.getLeaveId() + "] submitted by " + employee.getEmpName());
}
// c) Page to Approve / Disapprove Mission & Permission Requests
public void reviewWorkRequest(Employee Requestor, UUID requestId, boolean approve) {
if (!LeaderOrAdmin(Requestor)) {
System.out.println("ACCESS DENIED: Only Leaders or Admins can process requests.");
return;
}
WorkRequest req = workRequestsDatabase.stream()
.filter(r -> r.getRequestId().equals(requestId))
.findFirst()
.orElse(null);
if (req != null) {
String targetStatus;
if (approve) {
targetStatus = "APPROVED";
} else {
targetStatus = "DISAPPROVED";
}
req.setStatus(targetStatus);
System.out.println("Work Request " + requestId + " has been " + req.getStatus() + " by " + Requestor.getEmpName());
} else {
System.out.println("ERROR: Request ID not found.");
}
}
// c) Page to Approve / Disapprove Leave Requests
public void reviewLeaveRequest(Employee Requestor, UUID leaveId, boolean approve) {
if (!LeaderOrAdmin(Requestor)) {
System.out.println("ACCESS DENIED: Only Leaders or Admins can process Leave requests.");
return;
}
LeaveRequest req = leaveRequestsDatabase.stream()
.filter(l -> l.getLeaveId().equals(leaveId))
.findFirst()
.orElse(null);
if (req != null) {
String targetStatus;
if (approve) {
targetStatus = "APPROVED";
} else {
targetStatus = "DISAPPROVED";
}
req.setStatus(targetStatus);
System.out.println("Leave Request " + leaveId + " has been " + req.getStatus() + " by " + Requestor.getEmpName());
} else {
System.out.println("ERROR: Leave Request ID not found.");
}
}
// GETTERS REQUIRED BY YOUR MAIN METHOD LOGIC
public List<WorkRequest> getWorkRequestsDatabase() { return workRequestsDatabase; }
public List<LeaveRequest> getLeaveRequestsDatabase() { return leaveRequestsDatabase; }
}