-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOfficerController.java
More file actions
149 lines (133 loc) · 6.07 KB
/
Copy pathOfficerController.java
File metadata and controls
149 lines (133 loc) · 6.07 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
package assignment2002;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import assignment2002.application.Application;
import assignment2002.application.ApplicationService;
import assignment2002.user.Officer;
import assignment2002.user.UserService;
import assignment2002.utils.Authenticator;
import assignment2002.utils.InputUtil;
import assignment2002.utils.ProjectPrinter;
import assignment2002.utils.Status.REGISTRATION;
public class OfficerController {
private Officer officer;
public OfficerController(Officer officer) {
this.officer = officer;
}
public void showMenu() {
Scanner sc = new Scanner(System.in);
boolean run = true;
do {
System.out.println("==== ROLE MENU ===="
+ "\n1: Applicant menu"
+ "\n2: Officer menu"
+ "\n3: Change password"
+ "\n4: Logout");
int choice = InputUtil.getValidatedIntRange(sc, "Choice: ", 1, 4);
switch (choice) {
case 1 -> {
ApplicantController aController = new ApplicantController(officer);
aController.showMenu();
}
case 2 -> exclusiveOfficerMenu();
case 3 -> UserService.resetPasswordPrompt(officer);
case 4 -> run = false;
default -> System.out.println("Invalid input. Try again.");
}
} while (run);
System.out.println("You have logged out.");
}
private void exclusiveOfficerMenu() {
Scanner sc = new Scanner(System.in);
boolean run = true;
do {
System.out.println("==== OFFICER MENU ===="
+ "\n1: Register to join a project team"
+ "\n2: View status of projects as officer"
+ "\n3: View registered projects"
+ "\n4. View enquiries"
+ "\n5. View/update applicant's detail"
+ "\n6. Generate receipts for booked flats"
+ "\n7. Back");
int choice = InputUtil.getValidatedIntRange(sc, "Choice: ", 1, 7);
switch (choice) {
case 1 -> {
List<BTOProperty> proj = OfficerService.getAvailableProjectsToRegister(officer);
if (proj.size() == 0) {
System.out.println("Sorry, there are no projects that you can register!");
} else {
System.out.println("There are " + proj.size() + " you can choose to register!\n");
for (BTOProperty p : proj) {
System.out.println(p.getProjectName());
}
if (!OfficerService.registerProject(officer, InputUtil.getNonEmptyString(sc, "\nPlease type the project name you want to register in: "))) {
System.out.println("Unable to register for specified project");
} else {
System.out.println("Registeration has been successful. Please wait for the relevant manager for it's updated status!");
}
}
}
case 2 -> {
Map<String, REGISTRATION> temp = OfficerService.getAllProjectStatus(officer);
if (temp.size() > 0) {
System.out.println("Listing " + temp.size() + " project status:");
temp.forEach((k, v) -> System.out.println(k + " : " + v.toString()));
} else {
System.out.println("You have not registered for any projects!");
}
}
case 3 -> ProjectPrinter.viewProjects(officer.getRegisteredProjects());
case 4 -> OfficerService.viewAndReplyEnquiries(officer);
case 5 -> {
List<Application> apps = officer.getAllSuccessfulApplications();
if (apps.size() <= 0) {
System.out.println("No applications at the moment!");
continue;
}
System.out.println("Here are all successful applications:");
for (Application app1 : apps) {
ApplicationService.generateReceipt(app1);
}
String nric = "";
do {
nric = InputUtil.getNonEmptyString(sc, "Please enter applicant's NRIC to update applicant's detail (invalid input to exit):");
if (Authenticator.isValidNRIC(nric)) {
Application app = null;
for (Application app2 : apps) {
if (app2.getApplicant().getNRIC().equalsIgnoreCase(nric)) {
app = app2;
}
}
if (app == null) {
System.out.println("Unable to find application with this NRIC");
continue;
}
String roomType = InputUtil.getNonEmptyString(sc, "Please confirm applicant's room type (2-Room / 3-Room): ");
if (!roomType.equals("2-Room") && !roomType.equals("3-Room")) {
System.out.println("Invalid input! Please try again!");
continue;
}
OfficerService.updateBTOApplication(officer, app, roomType);
} else {
System.out.println("Not valid NRIC! Please try again...");
}
} while (nric.equals("0"));
}
case 6 -> {
String projectName = InputUtil.getNonEmptyString(sc, "Enter the project name: ");
String applicantNric = InputUtil.getNonEmptyString(sc, "Enter the applicant's NRIC: ");
Application app = OfficerService.getBookedApplicationByApplicantNRIC(officer, projectName, applicantNric);
if (app == null) {
System.out.println("Unable to retrieve application by details you have entered!");
continue;
}
OfficerService.generateReceiptOfApplication(officer, app);
}
case 7 -> run = false;
default -> System.out.println("Invalid input. Try again.");
}
} while (run);
System.out.println("You have logged out.");
}
}