-
Notifications
You must be signed in to change notification settings - Fork 0
/
Applicant.java
286 lines (254 loc) · 8.99 KB
/
Applicant.java
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import java.io.*;
import java.util.*;
class Applicant extends User implements Serializable {
private Date last_online;
private String CV;
private ApplicantHistory History;
private ArrayList<File> letters;
private ArrayList<Application> applications;
private Mailbox mailbox;
Applicant(String name1, String password1, ApplicantManager manager, Database d) {
super(name1, password1);
this.CV = "";
this.History = new ApplicantHistory();
this.letters = new ArrayList<>();
this.applications = new ArrayList<>();
this.mailbox = new Mailbox();
manager.addApplicant(this);
d.saveAllApplicants(manager);
}
Applicant(String name1, String password1, Date last_online1, String CV1, ApplicantHistory History1) {
super(name1, password1);
this.CV = CV1;
this.History = History1;
this.letters = new ArrayList<>();
this.applications = new ArrayList<>();
this.mailbox = new Mailbox();
}
/**
* Method triggered when applicant logs in. Notifies user of all closed and filled job postings
*/
void logged_in(JobPostingManager jb) {
ArrayList<JobPosting> jobPostings = jb.getJobPostings();
ArrayList<String> curr = History.getCurrentJobs();
for (String i : curr) {
for (JobPosting j : jobPostings) {
if (j.getTitle().equalsIgnoreCase(i)) {
if (j.getStatus().equalsIgnoreCase("Closed")) {
System.out.println(j.getTitle() + " is closed.");
} else if (j.getStatus().equalsIgnoreCase("Filled")) {
System.out.println(j.getTitle() + " is filled.");
}
}
}
}
}
/**
* Allows applicant to view current applications in the program
*/
void viewCurrentApplications(JobPostingManager jb) {
// print all current applications and their status
int id = 0;
ArrayList<JobPosting> jobPostings = jb.getJobPostings();
ArrayList<String> curr = History.getCurrentJobs();
System.out.println("Current jobs: ");
for (String i : curr) {
for (JobPosting j : jobPostings) {
if (j.getTitle().equalsIgnoreCase(i)) {
id = j.getId();
break;
}
}
System.out.println(i);
JobPosting job = jb.getJobPosting(id);
System.out.println("Status: " + job.getStatus());
}
}
/**
* Apply to a job posting
*/
void apply(JobPostingManager jb) {
// find a job posting and apply
ArrayList<String> curr = this.History.getCurrentJobs();
ArrayList<Integer> current = new ArrayList<>();
int count = 0;
for (String i : curr) {
String[] splited = i.split("\\s+");
for (String j : splited) {
if (count == 1) {
count = 0;
current.add(Integer.parseInt(j));
}
count++;
}
}
System.out.println("Choose from jobs below or enter -1 to go back:");
jb.printPostings();
ArrayList<JobPosting> jobPostings = jb.getJobPostings();
VerifyInput verifyInput = new VerifyInput();
int num = 0;
boolean valid = false;
while (!valid) {
num = verifyInput.getValidNumber();
if (num == -1) {
return;
}
for (JobPosting j : jobPostings) {
if (num == j.getId()) {
valid = true;
}
}
}
if (current.contains(num)) {
System.out.println("Cannot apply twice.");
return;
}
System.out.println("Enter your cover:");
Scanner input = new Scanner(System.in);
String cover = input.nextLine();
System.out.println("Enter your CV:");
this.CV = input.nextLine();
ArrayList<String> extras = new ArrayList<>();
System.out.println("Enter extra documents if there is any: or none to skip");
String str = input.nextLine();
while (!str.equalsIgnoreCase("none")) {
extras.add(str);
System.out.println("Enter extra documents if there is any: or none to skip");
str = input.nextLine();
}
Application application = new Application(this, cover, extras);
applications.add(application);
for (JobPosting i : jobPostings) {
if (i.getId() == num) {
if (i.getStatus().equalsIgnoreCase("Open")) {
this.History.apply(i.getTitle(), i.getId());
i.addApplicant(application);
} else {
System.out.println("Cannot apply.");
}
}
}
}
/**
* Withdraw from a job posting
*/
void withdraw(JobPostingManager jp) {
// withdraw from a particular application.
System.out.println("Enter the id for the job you want to withdraw or -1 to go back:");
ArrayList<String> curr = this.History.getCurrentJobs();
ArrayList<JobPosting> jobPostings = jp.getJobPostings();
if (curr.size() == 0) {
System.out.println("No current applications.");
return;
}
HashMap<String, Integer> jobs = new HashMap<>();
String title = "";
int id = 0;
int count = 0;
VerifyInput verifyInput = new VerifyInput();
for (String i : curr) {
String[] splited = i.split("\\s+");
for (String e : splited) {
if (count == 0) {
title = e;
System.out.println("Job title: " + title);
count++;
} else {
id = Integer.parseInt(e);
System.out.println("Job id: " + id);
count--;
}
}
jobs.put(title, id);
}
Collection<Integer> job_ids = jobs.values();
int remove_id = verifyInput.getValidNumber();
if (remove_id == -1) {
return;
}
while (!(job_ids.contains(remove_id))) {
remove_id = verifyInput.getValidNumber();
}
Application temp = null;
JobPosting jtemp = jobPostings.get(0); // this is to avoid a warning about producing a NullPointerException. The correct job posting WILL be found in this loop
for (JobPosting j : jobPostings) {
if (j.getId() == remove_id) {
ArrayList<Application> ap = j.getCurrentApplications();
jtemp = j;
for (Application a : ap) {
if (a.getApplicant_id() == this.getId()) {
temp = a;
}
}
}
}
this.History.closeApplication(jtemp.getTitle(), jtemp.getId());
this.applications.remove(temp);
jtemp.removeApplicant(this.getId());
}
/**
* View applicant's history
*/
void viewHistory() {
// view the history of the applicant
if (this.History == null) {
System.out.println("No history available.");
} else {
ArrayList<String> past = History.getPastJobs();
ArrayList<String> curr = History.getCurrentJobs();
System.out.println("Past jobs: ");
for (String i : past) {
System.out.println(i);
}
System.out.println("Current jobs: ");
for (String i : curr) {
System.out.println(i);
}
}
}
void addLetter(File file) {
this.letters.add(file);
}
String getCV() {
return this.CV;
}
ApplicantHistory getHistory() {
return this.History;
}
void printReferenceLetters() {
try {
for (File file : this.letters) {
BufferedReader reader = new BufferedReader(new FileReader(file.getName()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
reader.close();
}
} catch (IOException e) {
System.out.println("IO Exception.");
}
}
void mailOption() {
this.mailbox.read();
}
/**
* Use filters to search for job postings
*/
void searchJobPostingByTags(JobPostingManager jmane) {
System.out.println("Type the word you want to search by or cancel to go back:");
Scanner console = new Scanner(System.in);
String word = console.next();
if (word.equalsIgnoreCase("cancel")) {
return;
}
jmane.printFilteredPostings(word);
}
Mailbox getMailbox() {
return this.mailbox;
}
ArrayList<Application> getApplications() {
return this.applications;
}
}