-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJobPosting.java
315 lines (281 loc) · 9.71 KB
/
JobPosting.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import java.io.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class JobPosting implements Serializable {
private int id;
private ArrayList<Application> applications;
private InterviewFormat interviewFormat;
private String title;
private Date dateCreated;
private Date closingDate;
private String status;
private Boolean shouldManuallyFill;
private ArrayList<String> tags;
private Integer hired_applicant;
public JobPosting(String title, Date closingDate, String unfiltered_order, ArrayList<String> new_tags) {
this.applications = new ArrayList<>();
this.title = title;
this.closingDate = closingDate;
this.dateCreated = new Date();
this.status = "Open";
this.shouldManuallyFill = false;
this.interviewFormat = new InterviewFormat(unfiltered_order);
ArrayList<String> temp = new ArrayList<>();
for (String s : new_tags) {
temp.add(s.toLowerCase());
}
this.tags = temp;
this.hired_applicant = -1; // -1 means no one is hired yet
try {
File file = new File("JobID.txt");
if (!file.exists()) {
file.createNewFile();
BufferedWriter output = new BufferedWriter(new FileWriter(file, false));
output.write("0");
output.close();
}
BufferedReader reader = new BufferedReader(new FileReader(file));
this.id = Integer.parseInt(reader.readLine());
reader.close();
BufferedWriter writer = new BufferedWriter(new FileWriter(file, false));
writer.write(String.valueOf(this.id + 1));
writer.close();
} catch (IOException e) {
System.out.println("IO exception.");
}
}
// ------------------GETTERS---------------------
int getId() {
return this.id;
}
String getTitle() {
return this.title;
}
String getStatus() {
return this.status;
}
Date getDateCreated() {
return this.dateCreated;
}
Date getClosingDate() {
return this.closingDate;
}
Boolean getShouldManuallyFill() {
return this.shouldManuallyFill;
}
ArrayList<Application> getCurrentApplications() {
return this.applications;
}
Integer getHired_applicant() {
return this.hired_applicant;
}
// ------------------PUBLIC methods--------------
/**
* Called at the start of the program as well as whenever an application is accepted or rejected
* Checks if a) there is only one candidate remaining (hires them in this case)
* b) all rounds have been completed (makes hrcoordinator of company choose the best candidate)
* c) current round is completed (goes to next round)
*/
void updateJobPosting(ApplicantManager manager) {
if (!this.status.equals("Filled")) {
this.closePosting();
Application application = this.getLastCandidateLeft();
if (application != null) {
this.hire(manager, application);
} else if (this.allRoundsCompleted()) {
this.shouldManuallyFill = true;
} else if (this.roundCompleted()) {
this.nextRound(manager);
}
}
}
/**
* Add a tag to this JobPosting's list of tags
*/
void addTag(String tag) {
this.tags.add(tag);
}
/**
* `* Add an Applicant (its info) to this JobPosting's list of applicants (both lists)
*/
void addApplicant(Application application) {
this.applications.add(application);
}
/**
* Remove an Applicant (and its info) from this JobPosting object entirely (as if they never applied)
*
* @param id Applicant's Id
*/
void removeApplicant(Integer id) {
Application application1 = null;
for (Application application : this.applications) {
if (application.getApplicant_id() == id) {
application1 = application;
}
}
this.applications.remove(application1);
}
/**
* Check if this job posting is open.
*
* @return true if it is open
*/
boolean isOpen() {
return this.getStatus().equals("Open");
}
boolean isFilled() {
return this.status.equals("Filled");
}
/**
* Print out this posting's title, date posted and date closes, list of requirements (CV + CL), and status
*/
public String toString() {
return "---------------------------------------------"
+ "\nJobPosting id: " + this.id + "\nJob title: " + this.title + "\nJob posted: " + this.dateCreated.toString()
+ "\nApplications closed: " + this.closingDate.toString() + "\nRequirements: CV and CL" + this.interviewFormat.printSummary() + "\nStatus: "
+ this.status + "\nTags: " + this.printTags();
}
/**
* @param id applicant's id
* @return application of this applicant
*/
Application getApplicant(int id) {
for (Application application : this.applications) {
if (application.getApplicant_id() == id) {
return application;
}
}
return null;
}
/**
* @param filter represents the filter (can be lower of uppercase)
* @return true if the job posting passes the filter
*/
boolean passesFilter(String filter) {
String lc_filter = filter.toLowerCase();
if (lc_filter.equals("deadline")) {
return this.isOpen();
}
return this.tags.contains(lc_filter);
}
void manuallyFill(ApplicantManager manager) {
this.readAllApplications(manager);
System.out.println("Please select one of these applications (enter their applicant id)");
VerifyInput verifyInput = new VerifyInput();
int id = verifyInput.getValidNumber();
for (Application application1 : this.applications) {
if (application1.getApplicant_id() == id) {
System.out.println("Hiring " + manager.getApplicant(id).getName());
this.hire(manager, application1);
return;
}
}
System.out.println("Applicant does not exist or did not apply to this job posting. Please try again.");
this.manuallyFill(manager);
}
void readAllApplications(ApplicantManager manager) {
for (Application application1 : this.applications) {
application1.read(manager);
}
}
//------------------PRIVATE METHODS-----------------------
/**
* @return an application object if there is only one candidate remaining and all others are rejected
* return null otherwise
*/
private Application getLastCandidateLeft() {
Application lastCandidate = null;
int accepted = 0;
for (Application application : this.applications) {
if (application.getStatus().equals("Accepted into next round")) {
accepted++;
lastCandidate = application;
} else if (application.getStatus().equals("Pending")) {
return null;
}
}
if (accepted > 1) {
return null;
}
return lastCandidate;
}
/**
* Hires applicant who submitted application
*/
private void hire(ApplicantManager manager, Application application) {
application.accepted(manager, this);
for (Application application1 : this.applications) {
if (application1.getId() != application.getId()) {
application1.rejected(manager, this);
}
}
this.status = "Filled";
this.deleteApplicantInfo();
this.hired_applicant = application.getApplicant_id();
}
/**
* @return true only if all rounds are completed
*/
private boolean allRoundsCompleted() {
return this.interviewFormat.atLastRound() && this.roundCompleted();
}
/**
* @return true only if the current round is completed
* a round is completed when all applications have been reviewed
*/
private boolean roundCompleted() {
for (Application application : this.applications) {
if (application.getStatus().equals("Pending")) {
return false;
}
}
return true;
}
/**
* Commences next round
*/
private void nextRound(ApplicantManager manager) {
this.interviewFormat.nextRound();
Application application1 = null;
for (Application application : this.applications) {
if (application.getStatus().equals("Rejected")) {
application1 = application;
} else {
application.nextRound(manager, this);
}
}
this.applications.remove(application1);
}
/**
* Closed when no new applications is allowed
* Compare today's date (new Date) with closing date
* Make the status = "Closed"
*/
private void closePosting() {
Date currentDate = new Date();
if (currentDate.compareTo(this.closingDate) >= 0) {
this.status = "Closed";
this.deleteApplicantInfo();
}
}
/**
* Delete the documents saved in this JobPosting
*/
private void deleteApplicantInfo() {
for (Application application : this.applications) {
application.clearInfo();
}
}
private String printTags() {
String result = "";
for (String tag : this.tags) {
result += tag;
result += ", ";
}
return result;
}
}