-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdministrator.java
More file actions
394 lines (364 loc) · 15.3 KB
/
Copy pathAdministrator.java
File metadata and controls
394 lines (364 loc) · 15.3 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
package test394;
import java.io.File;
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.Random;
import org.json.JSONArray;
import org.json.JSONObject;
public class Administrator {
private ArrayList<String> dbInfo;
private String hashedID;
private String username;
private String fname;
private String lname;
private java.sql.Date dob;
public Administrator() throws ClassNotFoundException, SQLException {
this.hashedID = "777";
this.username = "Seal Search Admin";
this.fname = "King";
this.lname = "Seal";
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");
}
public Administrator(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");
}
public Administrator(String hid, String un, String first, String last, Calendar dobCal)
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.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");
}
public void createAdmin() 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 ADMINISTRATOR (admin_hashedid, admin_username, admin_fname, admin_lname, admin_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 createAdmin() Query = " + count);
con.close();
ps.close();
}
public void createApplicant(String a_hid, String a_un, String a_first, String a_last,
Calendar a_dobCal, String city, String state, String phoneNumber, String email)
throws ClassNotFoundException, SQLException {
Applicant newApp =
new Applicant(a_hid, a_un, a_first, a_last, a_dobCal, city, state, phoneNumber, email);
newApp.createApplicant();
}
public void createEmployer(String e_hid, String e_compName, String e_un, String e_first,
String e_last, Calendar e_dobCal) throws ClassNotFoundException, SQLException {
Employer newEmp = new Employer(e_hid, e_compName, e_un, e_first, e_last, e_dobCal);
newEmp.createEmployer();
}
public void retrieveResume(String a_hid)
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, a_hid);
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 retrieveJobListing(String e_hid)
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, e_hid);
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 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;");
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;
}
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 browseEmployers() 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;");
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 deleteApplicant(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("DELETE FROM applicant WHERE a_hashedID = ?;");
ps.setString(1, a_hid);
int count = ps.executeUpdate();
System.out.println("Rows Affected By deleteApplicant() Query = " + count);
con.close();
ps.close();
}
public void deleteEmployer(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("DELETE FROM employer WHERE e_hashedID = ?;");
ps.setString(1, e_hid);
int count = ps.executeUpdate();
System.out.println("Rows Affected By deleteEmployer() Query = " + count);
con.close();
ps.close();
}
@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");
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 ArrayList<String> getDBInfo() {
return this.dbInfo;
}
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 static void main(String[] args)
throws ClassNotFoundException, IOException, ParseException, SQLException {
Administrator admin = new Administrator();
System.out.println(admin.toString());
admin.createAdmin();
Calendar cal = Calendar.getInstance();
admin.createApplicant("aca1234", "Generico", "Bob", "Stevens", cal, "Chicago", "Illinois",
"(123)456-7890", "myEmail@email.com");
System.out.println("\n");
JSONObject test1 = admin.viewApplicant("aca1234");
System.out.println("Printing Applicant JSONObject:");
System.out.println(test1.toString() + "\n");
admin.createEmployer("ace0001", "Overwatch", "Tigole", "Jeff", "Kaplan", cal);
System.out.println("\n");
System.out.println("Printing Employer JSONObject:");
JSONObject test2 = admin.viewEmployer("ace0001");
System.out.println(test2.toString() + "\n");
admin.deleteApplicant("aca1234");
admin.deleteEmployer("ace0001");
}
}