-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskService.java
More file actions
114 lines (97 loc) · 5.01 KB
/
TaskService.java
File metadata and controls
114 lines (97 loc) · 5.01 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
package TaskManagerProject;
import java.util.*;
//SpringBoot
//Task Module (C), (e), (d)
//e)The leader can manage the tasks (create, show all, evaluation,
// reassign task, change any filed in the task).
public class TaskService
{
//Implements logic where Leaders/Admins see all tasks (`GlobalTask`), while regular employees only see tasks assigned to their specific `UUID`.
private List <Task> GlobalTask = new ArrayList<>();
private List <TaskLog> TaskLog = new ArrayList<>();
//Task Module(e)Task Creation, // WE ADDED TASK REQUESTOR HERE:
public Task CreateTask(Employee Requestor, String TaskTitle, String Taskdescription, Employee TaskAssignedEmp,
Project TaskProject, String priority, int estimationHours, String CreatorName) {
//Added: Employee Requestor to check if the requestor is only an Admin or a leader to assign the task
if (LeaderOrAdmin(Requestor)) {
//Requester is already an instance of Employee, we can add a name of the requestor: Requestor.getEmpName()
Task newTask = new Task(TaskTitle, Taskdescription, TaskAssignedEmp, TaskProject, priority, estimationHours, Requestor.getEmpName());
//Add to global database
GlobalTask.add(newTask);
System.out.println("SUCCESS: Task '" + TaskTitle + "' created and assigned to " + TaskAssignedEmp.getEmpName());
return newTask;
} else {
System.err.println("ACCESS DENIED: Only Leaders or Admins can create tasks.");
}
return null;
}
//Permission Checking Emp Role, if Leader or Admin: he/ SHe can add task to an employee
boolean LeaderOrAdmin(Employee Emp) {
String EmpRole = Emp.getEmployeeRole();
return EmpRole.equals("LEADER") || EmpRole.equals("ADMIN"); //will return true or false
}
//Task Module(e) Calendar show all employees tasks and phases. /Every Employee Can See his/her Tasks
public List<Task> getTasksForEmployee(Employee emp)
{
//checking again if the emp who wants to see tasks is admin/leader(Can View All Tasks, displaying GlobalTask to him)
//or Regular tasks(Can view only his / her tasks - Else statement)
if(LeaderOrAdmin(emp))
{
return GlobalTask; //return the entire database
}
else
{
//filtering the Employee task using Stream
return GlobalTask.stream().filter(Task->Task.getTaskAssignedEmp().getEmpID().equals(emp.getEmpID()))
.toList();
}
}
//Reassign the task
public void Reassigntask(Employee Requestor, Task task, Employee newAssignee)
{
if(LeaderOrAdmin(Requestor))
{
task.setTaskAssignedEmp(newAssignee); //setter for re-assigning the task
System.out.println("SUCCESS: Task reassigned to " + newAssignee.getEmpName());
} else {
System.err.println("DENIED: Only Leaders/Admins can reassign tasks.");
}
}
// Evaluation Changing tha phase to "EVALUATION", "TEST", or "DONE"
public void evaluateTask(Employee requester, Task task, String evaluationPhase) {
if (LeaderOrAdmin(requester)) {
// Changing tha phase to "EVALUATION", "TEST", or "DONE", we're entering the string of evaluation
task.setTaskPhase(evaluationPhase.toUpperCase());
System.out.println("SUCCESS: Task phase updated to " + evaluationPhase);
} else {
System.err.println("DENIED: Only Leaders can evaluate tasks.");
}
}
//Changing Any Field in the Task by the "ADMIN/LEADER" ONLY
public void ChangeTaskFields(Task task, Employee Requestor, String newTaskTitle, String newTaskdescription,
Project TaskProject, String newPriority, int newEstimationHours, String newCreatorName, String newPhase)
{
if(LeaderOrAdmin(Requestor))
{
task.setTaskPhase(newPhase.toUpperCase());
task.setTaskTitle(newTaskTitle);
task.setEstimationHours(newEstimationHours);
task.setPriority(newPriority);
task.setTaskdescription(newTaskdescription);
System.out.println("SUCCESS: Task [" + task.getTaskCode() + "] has been modified by Leader: " + Requestor.getEmpName());
} else {
System.err.println("PERMISSION DENIED: You are not authorized to edit task fields.");
}
}
public List<Task> getGlobalTasks() {
return this.GlobalTask;
}
public List<TaskLog> getTaskLogs() {
return this.TaskLog;
}
}
//NOTE
//The Difference:
//findFirst().orElse(null): This tells Java: "Search the list, and the moment you find one task that matches this employee, stop searching and give me just that one (or nothing)."
//
//.toList() (or .collect): This tells Java: "Search the entire list and give me every single task that belongs to this employee."