-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainEngine.java
More file actions
166 lines (132 loc) · 8.2 KB
/
mainEngine.java
File metadata and controls
166 lines (132 loc) · 8.2 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package TaskManagerProject;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
public class mainEngine {
public static void main(String[] args) {
// =========================================================================
// 1. SETUP SERVICES
// =========================================================================
AdminControlService adminService = new AdminControlService();
TaskService taskService = new TaskService();
EmployeeModuleService EmpService = new EmployeeModuleService();
// =========================================================================
// 2. INITIALIZE EMPLOYEES & ROLES
// =========================================================================
Employee admin = adminService.CreateEmployee("Fatma", "Fatma@company.com", "123","ADMIN");
Employee leader = adminService.CreateEmployee("Omar", "omar@company.com", "456", "LEADER"); // Added to fix your configuration tests!
Employee dev = adminService.CreateEmployee("Sara", "sara@company.com", "567", "DEVELOPER");
Employee dev2 = adminService.CreateEmployee("Mohamed", "Mohamed@company.com", "124", "DEVELOPER");
// =========================================================================
// 3. Project Creation
// =========================================================================
adminService.CreateProject("AI Integration", "Google");
Project project = adminService.ProjDataBase.get(0);
// =========================================================================
// 4. TESTING THE LOGIN (Attendance & Departure)
// =========================================================================
System.out.println("\n--- Testing Login ---");
adminService.Login("Fatma@company.com", "123");
adminService.Login("sara@company.com", "567");
//Mohamed Entered invalid password
adminService.Login("Mohamed@company.com", "128");
// =========================================================================
// 5. TASK CREATION
// =========================================================================
System.out.println("\n--- Testing Task Creation ---");
Task t1 = taskService.CreateTask(admin, "Build API", "Develop the login endpoint", dev, project, "HIGH", 10, "Fatma");
// =========================================================================
// 6. Test Security
// =========================================================================
System.out.println("\n--- Testing Security ---");
// Only Admin can re-assing task or leaders - Dev are not allowed-Failure
taskService.Reassigntask(dev, t1, admin);
//admin will assign task1 to dev2 - Success
taskService.Reassigntask(admin, t1, dev2);
// =========================================================================
// 7. Test Visibility (Employees(Admin and DEVs))
// =========================================================================
// Sara should only see her 1 task
System.out.println("\n--- Testing Employee View ---");
//Employee who's not an admin or leader: must see his/her own tasks
List<Task> sarasTasks = taskService.getTasksForEmployee(dev);
List<Task> MohamedTasks = taskService.getTasksForEmployee(dev2);
List<Task> FatmaTasks = taskService.getTasksForEmployee(admin);
System.out.println("Sara sees " + sarasTasks.size() + " tasks.");
System.out.println("Mohamed sees " + MohamedTasks.size() + " tasks.");
//Tasks that the admin sees(all tasks)
System.out.println("Fatma (The Admin) sees " + FatmaTasks.size() + " tasks.");
// =========================================================================
// 8. Testing Evaluation
// =========================================================================
System.out.println("\n--- Testing Evaluation ---");
taskService.evaluateTask(admin, t1, "IN PROGRESS");
// =========================================================================
// 9. TESTING TIMECARDS (Attendance & Departure)
// =========================================================================
System.out.println("\n--- Testing Timecards ---");
// Sara arrives at work
EmpService.checkIn(dev);
// Sara leaves work
EmpService.checkOut(dev);
// =========================================================================
// 10. TESTING LEAVE TYPES CONFIGURATION (Authorization Test)
// =========================================================================
System.out.println("\n--- Testing Leave Type Configurations ---");
// Failure: Developer tries to add a custom vacation type
EmpService.addLeaveType(dev, "CONFERENCE_LEAVE");
// Success: Leader adds a custom vacation type
EmpService.addLeaveType(leader, "CONFERENCE_LEAVE");
// =========================================================================
// 11. TESTING WORK REQUESTS (Missions & Permissions)
// =========================================================================
System.out.println("\n--- Testing Work Requests (Missions/Permissions) ---");
// Sara requests a 2-hour dentist permission
EmpService.requestMissionOrPermission(
dev,
"PERMISSION",
LocalDateTime.now(),
LocalDateTime.now().plusHours(2),
"Dentist Appointment"
);
// Fetch the generated request from our in-memory storage to review it
WorkRequest pendingWorkReq = EmpService.getWorkRequestsDatabase().get(0);
System.out.println("\n--- Testing Work Request Approvals ---");
// Security Failure: Dev attempts to self-approve
EmpService.reviewWorkRequest(dev, pendingWorkReq.getRequestId(), true);
// Success: Admin approves the request
EmpService.reviewWorkRequest(admin, pendingWorkReq.getRequestId(), true);
// =========================================================================
// 12. TESTING VACATION LEAVE REQUESTS
// =========================================================================
System.out.println("\n--- Testing Vacation Leave Requests ---");
// Sara applies for an Annual Leave vacation next week
EmpService.requestLeave(
dev,
"ANNUAL",
LocalDate.now().plusDays(7),
LocalDate.now().plusDays(12)
);
// Fetch the generated vacation request to review it
LeaveRequest pendingLeaveReq = EmpService.getLeaveRequestsDatabase().get(0);
System.out.println("\n--- Testing Leave Request Approvals ---");
// Success: Leader disapproves the request
EmpService.reviewLeaveRequest(leader, pendingLeaveReq.getLeaveId(), false);
// ==========================================
// ** ENTERPRISE REPORTS
// ==========================================
System.out.println("\n--- GENERATING SYSTEM REPORTS ---");
// Report 1: Simple Task Status Count
long totalTasks = taskService.getGlobalTasks().size();
long pendingTasks = taskService.getGlobalTasks().stream().filter(t -> t.getTaskPhase().equals("PENDING")).count();
System.out.println("1. TASK STATUS REPORT:");
System.out.println(" Total Tasks in System: " + totalTasks);
System.out.println(" Tasks Pending Work: " + pendingTasks);
// Report 2: Time Tracking
System.out.println("\n2. TIME TRACKING LOG AUDIT:");
for (TaskLog log : taskService.getTaskLogs()) {
double hours = log.getMinutesSpent() / 60.0;
System.out.println(" " + log.getEmployee().getEmpName() + " worked " + hours + " hours on: " + log.getTask().getTaskTitle());
}
}
}