-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicant.java
More file actions
502 lines (462 loc) · 19 KB
/
Copy pathApplicant.java
File metadata and controls
502 lines (462 loc) · 19 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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
package test394;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.json.JSONArray;
import org.json.JSONObject;
public class Applicant {
private ArrayList<String> dbInfo;
private ArrayList<String> profileRankings;
private Map<String, Employer> followedEmps;
private String hashedID;
private String username;
private String fname;
private String lname;
private java.sql.Date dob;
private String city;
private String state;
private String phoneNumber;
private String email;
public Applicant() throws ClassNotFoundException, SQLException {
this.hashedID = "123456";
this.username = "Test";
this.fname = "John";
this.lname = "Doe";
Calendar cal = Calendar.getInstance();
this.dob = new java.sql.Date(cal.getTimeInMillis());
this.dbInfo = new ArrayList<String>();
this.dbInfo.add("com.mysql.cj.jdbc.Driver");
this.dbInfo.add(
"jdbc:mysql://thesealsearchserver.mysql.database.azure.com:3306/sealdb?useSSL=true&requireSSL=false");
this.dbInfo.add("KingSeal@thesealsearchserver");
this.dbInfo.add("Password1");
this.profileRankings = new ArrayList<String>();
String[] tempRankings = {"1", "1", "1", "1", "1", "1", "1", "1", "1"};
updateProfile(tempRankings);
this.followedEmps = new HashMap<>();
this.city = "Chicago";
this.state = "Illinois";
this.phoneNumber = "(123)456-7890";
this.email = "myEmail@email.com";
}
public Applicant(String hid) throws ClassNotFoundException, SQLException {
this.hashedID = hid;
this.dbInfo = new ArrayList<String>();
this.dbInfo.add("com.mysql.cj.jdbc.Driver");
this.dbInfo.add(
"jdbc:mysql://thesealsearchserver.mysql.database.azure.com:3306/sealdb?useSSL=true&requireSSL=false");
this.dbInfo.add("KingSeal@thesealsearchserver");
this.dbInfo.add("Password1");
this.profileRankings = new ArrayList<String>();
this.followedEmps = new HashMap<>();
this.city = "Chicago";
this.state = "Illinois";
this.phoneNumber = "(123)456-7890";
this.email = "myEmail@email.com";
}
public Applicant(String hid, String un, String first, String last, Calendar dobCal, String a_city,
String a_state, String a_number, String a_email) throws ClassNotFoundException, SQLException {
this.hashedID = hid;
this.username = un;
this.fname = first;
this.lname = last;
Calendar cal = dobCal;
this.dob = new java.sql.Date(cal.getTimeInMillis());
this.city = a_city;
this.state = a_state;
this.phoneNumber = a_number;
this.email = a_email;
this.dbInfo = new ArrayList<String>();
this.dbInfo.add("com.mysql.cj.jdbc.Driver");
this.dbInfo.add(
"jdbc:mysql://thesealsearchserver.mysql.database.azure.com:3306/sealdb?useSSL=true&requireSSL=false");
this.dbInfo.add("KingSeal@thesealsearchserver");
this.dbInfo.add("Password1");
this.profileRankings = new ArrayList<String>();
this.followedEmps = new HashMap<>();
}
public void createApplicant() throws ClassNotFoundException, SQLException {
Class.forName(dbInfo.get(0));
Connection con = DriverManager.getConnection(dbInfo.get(1), dbInfo.get(2), dbInfo.get(3));
PreparedStatement ps = con.prepareStatement(
"INSERT INTO APPLICANT (a_hashedid, a_username, a_fname, a_lname, a_dob) VALUES (?, ?, ?, ?, ?)");
ps.setString(1, this.hashedID);
ps.setString(2, this.username);
ps.setString(3, this.fname);
ps.setString(4, this.lname);
ps.setDate(5, this.dob);
int count = ps.executeUpdate();
System.out.println("Rows Affected By createApplicant() Query = " + count);
con.close();
ps.close();
}
public void uploadResume(String filepath)
throws ClassNotFoundException, IOException, SQLException {
Class.forName(dbInfo.get(0));
String fp = filepath;
File pdfFile = new File(fp);
byte[] pdfData = new byte[(int) pdfFile.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(pdfFile));
dis.readFully(pdfData);
dis.close();
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps =
con.prepareStatement("UPDATE APPLICANT SET a_resumePDF = ? WHERE a_hashedID = ?;");
ps.setBytes(1, pdfData);
ps.setString(2, this.hashedID);
int count = ps.executeUpdate();
System.out.println("Rows Affected By uploadResume() Query = " + count);
con.close();
ps.close();
}
public void uploadProfPic(String filepath)
throws ClassNotFoundException, IOException, SQLException {
Class.forName(dbInfo.get(0));
String fp = filepath;
File pdfFile = new File(fp);
byte[] pdfData = new byte[(int) pdfFile.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(pdfFile));
dis.readFully(pdfData);
dis.close();
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps =
con.prepareStatement("UPDATE APPLICANT SET a_profilePicture = ? WHERE a_hashedID = ?;");
ps.setBytes(1, pdfData);
ps.setString(2, this.hashedID);
int count = ps.executeUpdate();
System.out.println("Rows Affected By uploadResume() Query = " + count);
con.close();
ps.close();
}
public void retrieveResume() throws ClassNotFoundException, IOException, SQLException {
Class.forName(dbInfo.get(0));
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps =
con.prepareStatement("SELECT a_resumePDF FROM APPLICANT WHERE a_hashedID = ?;");
ps.setString(1, this.hashedID);
ResultSet rs = ps.executeQuery();
Random random = new Random();
String ext = ".pdf";
String name = String.format("%s%s", System.currentTimeMillis(), random.nextInt(100000) + ext);
File file = new File(name);
FileOutputStream output = new FileOutputStream(file);
System.out.println("Writing to file...");
while (rs.next()) {
InputStream input = rs.getBlob("a_resumePDF").getBinaryStream();
byte[] buffer = new byte[(int) rs.getBlob("a_resumePDF").length()];
while (input.read(buffer) > 0) {
output.write(buffer);
}
}
System.out.println("File Saved Here: " + file.getAbsolutePath());
output.close();
ps.close();
con.close();
}
public void updateProfile(String[] rankings) throws ClassNotFoundException, SQLException {
Class.forName(dbInfo.get(0));
for (int i = 0; i < rankings.length; i++) {
this.profileRankings.add(rankings[i]);
}
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps = con.prepareStatement(
"UPDATE APPLICANT SET a_tech_yearsofexp = ?, a_tech_problemsolving = ?, a_tech_degree = ?, a_busi_jobtype = ?, a_busi_growthopp = ?, a_busi_companysize = ?, a_cult_consistency = ?, a_cult_communication = ?, a_cult_leadership = ? WHERE a_hashedid = ?;");
for (int i = 0; i < rankings.length; i++) {
ps.setString(i + 1, rankings[i]);
}
ps.setString(10, this.hashedID);
int count = ps.executeUpdate();
System.out.println("Rows Affected By updateProfile() Query = " + count);
con.close();
ps.close();
}
public void updateApplicant() throws ClassNotFoundException, ParseException, SQLException {
Class.forName(dbInfo.get(0));
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps = con.prepareStatement("SELECT * FROM APPLICANT WHERE a_hashedID = ?;");
ps.setString(1, this.hashedID);
ResultSet rs = ps.executeQuery();
ArrayList<String> appInfo = new ArrayList<String>();
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
appInfo.add(rs.getString(i));
}
}
this.hashedID = appInfo.get(0);
this.username = appInfo.get(1);
this.fname = appInfo.get(2);
this.lname = appInfo.get(3);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date parsed = sdf.parse(appInfo.get(4));
java.sql.Date sql = new java.sql.Date(parsed.getTime());
this.dob = sql;
this.profileRankings = new ArrayList<String>();
for (int i = 7; i < appInfo.size() - 1; i++) {
this.profileRankings.add(appInfo.get(i));
}
}
public void updateRankings() throws ClassNotFoundException, SQLException {
Class.forName(dbInfo.get(0));
this.profileRankings = new ArrayList<String>();
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps = con.prepareStatement(
"SELECT a_tech_yearsofexp, a_tech_problemsolving, a_tech_degree, a_busi_jobtype, a_busi_growthopp, a_busi_companysize, a_cult_consistency, a_cult_communication, a_cult_leadership FROM APPLICANT WHERE a_hashedid = ?;");
ps.setString(1, this.hashedID);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
this.profileRankings.add(rs.getString(i));
}
}
System.out.println("Retrieved Rankings: " + this.profileRankings.toString());
con.close();
ps.close();
rs.close();
}
public JSONObject viewEmployer(String e_hid) throws ClassNotFoundException, SQLException {
Class.forName(dbInfo.get(0));
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps = con.prepareStatement(
"SELECT e_hashedID, e_companyName, e_username, e_fname, e_lname, e_dob, e_tech_yearsofexp, e_tech_problemsolving, e_tech_degree, e_busi_jobtype, e_busi_growthopp, e_busi_companysize, e_cult_consistency, e_cult_communication, e_cult_leadership FROM EMPLOYER WHERE e_hashedID = ?;");
ps.setString(1, e_hid);
ResultSet rs = ps.executeQuery();
JSONObject empObject = null;
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
empObject = new JSONObject();
ArrayList<String> ranks = new ArrayList<String>();
empObject.put("e_hashedID", rs.getString(i));
empObject.put("e_companyName", rs.getString(i + 1));
empObject.put("e_username", rs.getString(i + 2));
empObject.put("e_fname", rs.getString(i + 3));
empObject.put("e_lname", rs.getString(i + 4));
empObject.put("e_dob", rs.getString(i + 5));
ranks.add(rs.getString(i + 6));
ranks.add(rs.getString(i + 7));
ranks.add(rs.getString(i + 8));
ranks.add(rs.getString(i + 9));
ranks.add(rs.getString(i + 10));
ranks.add(rs.getString(i + 11));
ranks.add(rs.getString(i + 12));
ranks.add(rs.getString(i + 13));
ranks.add(rs.getString(i + 14));
empObject.put("e_rankings", ranks.toString());
i += 15;
}
}
return empObject;
}
public JSONArray browseJobs() throws ClassNotFoundException, SQLException {
Class.forName(dbInfo.get(0));
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
PreparedStatement ps = con.prepareStatement(
"SELECT e_hashedID, e_companyName, e_username, e_fname, e_lname, e_dob, e_tech_yearsofexp, e_tech_problemsolving, e_tech_degree, e_busi_jobtype, e_busi_growthopp, e_busi_companysize, e_cult_consistency, e_cult_communication, e_cult_leadership FROM EMPLOYER WHERE e_jobListingPDF IS NOT NULL;");
ResultSet rs = ps.executeQuery();
JSONArray fl = new JSONArray();
JSONObject empObject;
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
empObject = new JSONObject();
ArrayList<String> ranks = new ArrayList<String>();
empObject.put("e_hashedID", rs.getString(i));
empObject.put("e_companyName", rs.getString(i + 1));
empObject.put("e_username", rs.getString(i + 2));
empObject.put("e_fname", rs.getString(i + 3));
empObject.put("e_lname", rs.getString(i + 4));
empObject.put("e_dob", rs.getString(i + 5));
ranks.add(rs.getString(i + 6));
ranks.add(rs.getString(i + 7));
ranks.add(rs.getString(i + 8));
ranks.add(rs.getString(i + 9));
ranks.add(rs.getString(i + 10));
ranks.add(rs.getString(i + 11));
ranks.add(rs.getString(i + 12));
ranks.add(rs.getString(i + 13));
ranks.add(rs.getString(i + 14));
empObject.put("e_rankings", ranks.toString());
fl.put(empObject);
i += 15;
}
}
return fl;
}
public void followEmployer(String e_hid)
throws ClassNotFoundException, ParseException, SQLException {
Employer emp = new Employer(e_hid);
emp.updateEmployer();
followedEmps.put(emp.getHashedID(), emp);
}
public void updateFollowedList() throws ClassNotFoundException, SQLException {
Class.forName(dbInfo.get(0));
Connection con =
DriverManager.getConnection(this.dbInfo.get(1), this.dbInfo.get(2), this.dbInfo.get(3));
JSONArray fl = new JSONArray();
JSONObject empObject;
PreparedStatement ps =
con.prepareStatement("UPDATE APPLICANT SET a_followedEmployers = ? WHERE a_hashedID = ?;");
for (Employer value : this.followedEmps.values()) {
empObject = new JSONObject();
empObject.put("HID", value.getHashedID());
empObject.put("CompanyName", value.getCompanyName());
empObject.put("Username", value.getUsername());
empObject.put("FirstName", value.getFirstName());
empObject.put("LastName", value.getLastName());
empObject.put("DOB", value.getDOB());
empObject.put("Rankings", value.getProfileRankings().toString());
fl.put(empObject);
}
ps.setString(1, fl.toString());
ps.setString(2, this.hashedID);
int count = ps.executeUpdate();
System.out.println("Rows Affected By updateFollowedList() Query = " + count);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sb.append("HashedID: " + this.hashedID + "\n" + "Username: " + this.username + "\n"
+ "First Name: " + this.fname + "\n" + "Last Name: " + this.lname + "\n" + "DOB: "
+ sdf.format(this.dob) + "\n");
sb.append("Years Of Experience: " + this.profileRankings.get(0) + "\n" + "Problem Solving: "
+ this.profileRankings.get(1) + "\n" + "Degree: " + this.profileRankings.get(2) + "\n");
sb.append("Job Type: " + this.profileRankings.get(3) + "\n" + "Growth Opportunity: "
+ this.profileRankings.get(4) + "\n" + "Company Size: " + this.profileRankings.get(5)
+ "\n");
sb.append("Consistency: " + this.profileRankings.get(6) + "\n" + "Communication: "
+ this.profileRankings.get(7) + "\n" + "Leadership: " + this.profileRankings.get(8) + "\n");
sb.append("Followed Employers: " + this.followedEmps.toString());
return sb.toString();
}
public void setHashedID(String hid) {
this.hashedID = hid;
}
public void setUsername(String un) {
this.username = un;
}
public void setFname(String first) {
this.fname = first;
}
public void setLname(String last) {
this.lname = last;
}
public void setDOB(Calendar cal) {
this.dob = new java.sql.Date(cal.getTimeInMillis());
}
public void setCity(String city) {
this.city = city;
}
public void setState(String state) {
this.state = state;
}
public void setPhoneNumber(String number) {
this.phoneNumber = number;
}
public void setEmail(String email) {
this.email = email;
}
public ArrayList<String> getDBInfo() {
return this.dbInfo;
}
public ArrayList<String> getProfileRankings() {
return this.profileRankings;
}
public Map<String, Employer> getFollowedEmps() {
return this.followedEmps;
}
public String getHashedID() {
return this.hashedID;
}
public String getUsername() {
return this.username;
}
public String getFirstName() {
return this.fname;
}
public String getLastName() {
return this.lname;
}
public java.sql.Date getDOB() {
return this.dob;
}
public String getCity() {
return this.city;
}
public String getState() {
return this.state;
}
public String getPhoneNumber() {
return this.phoneNumber;
}
public String getEmail() {
return this.email;
}
public static void main(String[] args)
throws ClassNotFoundException, IOException, ParseException, SQLException {
Applicant appDefault = new Applicant();
appDefault.updateRankings();
System.out.println(appDefault.getHashedID() + "\n" + appDefault.getUsername() + "\n"
+ appDefault.getFirstName() + " " + appDefault.getLastName() + "\n"
+ appDefault.getDOB().toString());
System.out.println(
appDefault.getDBInfo().toString() + "\n" + appDefault.getProfileRankings().toString() + "\n"
+ appDefault.getFollowedEmps().toString() + "\n");
Applicant appExists = new Applicant("2129704133");
System.out.println("Before: " + appExists.hashedID + " " + appExists.username + " "
+ appExists.fname + " " + appExists.lname + " " + " " + appExists.dob + " "
+ appExists.profileRankings + " " + appExists.followedEmps);
appExists.updateApplicant();
System.out.println("After: " + appExists.hashedID + " " + appExists.username + " "
+ appExists.fname + " " + appExists.lname + " " + appExists.dob + " "
+ appExists.profileRankings.toString() + " " + appExists.followedEmps + "\n");
Applicant appSetTest = new Applicant();
appSetTest.setHashedID("987654320");
appSetTest.setUsername("Captain America");
appSetTest.setFname("Steve");
appSetTest.setLname("Rogers");
Calendar cal = Calendar.getInstance();
cal.set(1918, 06, 04);
appSetTest.setDOB(cal);
String[] rankings2 = {"100", "101", "102", "103", "104", "105", "106", "107", "108"};
appSetTest.createApplicant();
appSetTest.uploadResume("C:/Users/Jeremy/Desktop/captain.pdf");
appSetTest.uploadProfPic("C:/Users/Jeremy/Desktop/captain.pdf");
appSetTest.updateProfile(rankings2);
appSetTest.retrieveResume();
System.out.println("\n" + appSetTest.toString() + "\n");
JSONArray test = appSetTest.browseJobs();
for (int i = 0; i < test.length(); i++) {
System.out.println(test.get(i).toString());
}
System.out.println("\n");
appSetTest.followEmployer("9^-*l#PWxi6}j,w");
appSetTest.followEmployer("Xp2s5v8y/A?D(G+K");
appSetTest.followEmployer("123456");
appSetTest.updateFollowedList();
System.out.println("\n");
System.out.println(appSetTest.toString());
}
}