-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployer.java
More file actions
392 lines (362 loc) · 15.1 KB
/
Copy pathEmployer.java
File metadata and controls
392 lines (362 loc) · 15.1 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
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.Random;
import org.json.JSONArray;
import org.json.JSONObject;
public class Employer {
private ArrayList<String> dbInfo;
private ArrayList<String> profileRankings;
private String hashedID;
private String companyName;
private String username;
private String fname;
private String lname;
private java.sql.Date dob;
public Employer() throws ClassNotFoundException, SQLException {
this.hashedID = "123456";
this.companyName = "Testudios";
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);
}
public Employer(String hid) {
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>();
}
public Employer(String hid, String compName, String un, String first, String last,
Calendar dobCal) {
this.hashedID = hid;
this.companyName = compName;
this.username = un;
this.fname = first;
this.lname = last;
Calendar cal = dobCal;
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>();
}
public void createEmployer() 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 EMPLOYER (e_hashedid, e_companyName, e_username, e_fname, e_lname, e_dob) VALUES (?, ?, ?, ?, ?, ?)");
ps.setString(1, this.hashedID);
ps.setString(2, this.companyName);
ps.setString(3, this.username);
ps.setString(4, this.fname);
ps.setString(5, this.lname);
ps.setDate(6, this.dob);
int count = ps.executeUpdate();
System.out.println("Rows Affected By createEmployer() Query = " + count);
con.close();
ps.close();
}
public void uploadJobListing(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 EMPLOYER SET e_jobListingPDF = ? WHERE e_hashedID = ?;");
ps.setBytes(1, pdfData);
ps.setString(2, this.hashedID);
int count = ps.executeUpdate();
System.out.println("Rows Affected By uploadJobListing() Query = " + count);
con.close();
ps.close();
}
public void retrieveJobListing() 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 e_jobListingPDF FROM EMPLOYER WHERE e_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("e_jobListingPDF").getBinaryStream();
byte[] buffer = new byte[(int) rs.getBlob("e_jobListingPDF").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));
this.profileRankings = new ArrayList<String>();
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 EMPLOYER SET 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 = ? WHERE e_hashedid = ?;");
for (int i = 0; i < this.profileRankings.size(); i++) {
ps.setString(i + 1, this.profileRankings.get(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 updateEmployer() 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 EMPLOYER WHERE e_hashedID = ?;");
ps.setString(1, this.hashedID);
ResultSet rs = ps.executeQuery();
ArrayList<String> empInfo = new ArrayList<String>();
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
empInfo.add(rs.getString(i));
}
}
this.hashedID = empInfo.get(0);
this.companyName = empInfo.get(1);
this.username = empInfo.get(2);
this.fname = empInfo.get(3);
this.lname = empInfo.get(4);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date parsed = sdf.parse(empInfo.get(5));
java.sql.Date sql = new java.sql.Date(parsed.getTime());
this.dob = sql;
this.profileRankings = new ArrayList<String>();
for (int i = 8; i < empInfo.size(); i++) {
this.profileRankings.add(empInfo.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 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, 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 viewApplicant(String a_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 a_hashedid, a_username, a_fname, a_lname, a_dob, 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, a_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("a_hashedID", rs.getString(i));
empObject.put("a_username", rs.getString(i + 1));
empObject.put("a_fname", rs.getString(i + 2));
empObject.put("a_lname", rs.getString(i + 3));
empObject.put("a_dob", rs.getString(i + 4));
ranks.add(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));
empObject.put("a_rankings", ranks.toString());
i += 14;
}
}
return empObject;
}
public JSONArray browseApplicants() 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 a_hashedid, a_username, a_fname, a_lname, a_dob, 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_resumePDF 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("a_hashedID", rs.getString(i));
empObject.put("a_username", rs.getString(i + 1));
empObject.put("a_fname", rs.getString(i + 2));
empObject.put("a_lname", rs.getString(i + 3));
empObject.put("a_dob", rs.getString(i + 4));
ranks.add(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));
empObject.put("a_rankings", ranks.toString());
fl.put(empObject);
i += 14;
}
}
return fl;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sb.append("HashedID: " + this.hashedID + "\n" + "Company Name: " + this.companyName + "\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));
return sb.toString();
}
public void setHashedID(String hid) {
this.hashedID = hid;
}
public void setCompanyName(String compName) {
this.companyName = compName;
}
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 ArrayList<String> getDBInfo() {
return this.dbInfo;
}
public ArrayList<String> getProfileRankings() {
return this.profileRankings;
}
public String getHashedID() {
return this.hashedID;
}
public String getCompanyName() {
return this.companyName;
}
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 static void main(String[] args)
throws ClassNotFoundException, IOException, ParseException, SQLException {
Employer emp = new Employer();
emp.updateRankings();
System.out.println(emp.getHashedID() + "\n" + emp.getCompanyName() + "\n" + emp.getUsername()
+ "\n" + emp.getFirstName() + " " + emp.getLastName() + "\n" + emp.getDOB().toString());
System.out
.println(emp.getDBInfo().toString() + "\n" + emp.getProfileRankings().toString() + "\n");
emp = new Employer("Xp2s5v8y/A?D(G+K");
System.out.println("Before: " + emp.hashedID + " " + emp.companyName + " " + emp.username + " "
+ emp.fname + " " + emp.lname + " " + emp.profileRankings);
emp.updateEmployer();
System.out.println(
"After: " + emp.hashedID + " " + emp.companyName + " " + emp.username + " " + emp.fname
+ " " + emp.lname + " " + emp.dob + " " + emp.getProfileRankings().toString() + "\n");
emp.setHashedID("9^-*l#PWxi6}j,w");
emp.setCompanyName("Reddit");
emp.setUsername("CEO");
emp.setFname("Steve");
emp.setLname("Huffman");
Calendar cal = Calendar.getInstance();
cal.set(1983, 10, 12);
emp.setDOB(cal);
String[] rankings = {"20", "21", "22", "23", "24", "25", "26", "27", "28"};
emp.createEmployer();
emp.uploadJobListing("C:/Users/Jeremy/Desktop/reddit.pdf");
emp.updateProfile(rankings);
emp.retrieveJobListing();
System.out.println("\n" + emp.toString() + "\n");
JSONArray test = emp.browseApplicants();
System.out.println("Looping Thru Applicant Result Set Now!");
for (int i = 0; i < test.length(); i++) {
System.out.println(test.get(i).toString());
}
}
}