Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
rearrange higher level functions
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 27, 2022
1 parent dbe38bf commit 8b99c1f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 39 deletions.
Binary file modified ER Diagram.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion db/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CREATE TABLE renter_info (
person_id NUMBER,
ssn CHAR(11) UNIQUE
CHECK (REGEXP_LIKE(ssn, '\d{3}-\d{2}-\d{4}')),
preferred_payment NUMBER NOT NULL,
preferred_payment NUMBER,
PRIMARY KEY(person_id),
FOREIGN KEY(person_id) REFERENCES person(id) ON DELETE CASCADE,
FOREIGN KEY(preferred_payment) REFERENCES payment_method(id)
Expand Down
93 changes: 55 additions & 38 deletions numa/src/main/java/numa/Portals/ManagementPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,35 +238,19 @@ private void lease() throws IOException, ExitException, SQLException, MenuExcept

// If a new person needs to be registered in the database
if (person.id == -1) {
String last = input.getPrompt("Last Name: ");
last = last.substring(0, 1) + last.substring(1);
int age = input.getMenuInt("Age: ");
String phone_number = input.getPrompt("Phone Number (###-###-####): ");
String email = input.getPrompt("Email: ");
int credit_score = input.getMenuInt("Credit Score: ");

person = new Person(-1, first, last, null, age, phone_number, email, credit_score);
person = addPerson(first);
}
person.ssn = input.getPrompt("Social Security Number (###-##-####): ");

if (person.id == -1) {
try (
PreparedStatement addPerson = conn.prepareStatement(
"insert into person(first_name, last_name, age, phone_number, email, credit_score) values(?, ?, ?, ?, ?, ?)"
);
Statement getResId = conn.createStatement();
) {
addPerson.setString(1, person.first_name);
addPerson.setString(2, person.last_name);
addPerson.setInt(3, person.age);
addPerson.setString(4, person.phone_num);
addPerson.setString(5, person.email);
addPerson.setInt(6, person.credit_score);

addPerson.executeUpdate();
ResultSet res = getResId.executeQuery("select max(id) as id from person");
if (res.next()) person.id = res.getInt("id");
}

String ssn = input.getPrompt("Social Security Number (###-##-####): ");
try (
PreparedStatement addRenterInfo = conn.prepareStatement("insert into renter_info values(?, ?, ?)");
) {
addRenterInfo.setInt(1, person.id);
addRenterInfo.setString(2, ssn);
addRenterInfo.setNull(3, Types.NULL);

addRenterInfo.execute();
conn.commit();
}

System.out.println("Lease Info: ");
Expand All @@ -275,23 +259,18 @@ private void lease() throws IOException, ExitException, SQLException, MenuExcept
int term_length = input.getMenuInt("Term Length: ");

try (
CallableStatement add = this.conn.prepareCall("{call sign_lease(?, ?, ?, ?, ?, ?, ?)}");
CallableStatement add = this.conn.prepareCall("{call sign_lease(?, ?, ?, ?, ?)}");
) {
add.setInt(1, person.id);
add.setInt(2, propId);
add.setString(3, apt);
add.setInt(4, term_length);
add.registerOutParameter(5, Types.INTEGER);
add.registerOutParameter(6, Types.INTEGER);
add.registerOutParameter(7, Types.INTEGER);


add.execute();
System.out.println("executed");
conn.commit();
int ret = add.getInt(5);
int amt = add.getInt(6);
int valid = add.getInt(7);
System.out.format("Ret: %d\nAmt: %d\nValid: %d\n", ret, amt, valid);

if (ret == -2) {
System.out.format("Apt %s does not exist\n", apt);
Expand All @@ -302,12 +281,50 @@ private void lease() throws IOException, ExitException, SQLException, MenuExcept
}
}

conn.commit();
System.out.format("Lease for Apt %s successfully signed to %s %s\n", apt, person.first_name, person.last_name);
System.out.println("Please inform the tenant to setup payment details EOD in the Resident Portal");
}

private void visits() {

private void visits() throws IOException, SQLException, ExitException, MenuException, TooManyTriesException {
System.out.println("New Visit Registration");
System.out.println();
String first = input.getPrompt("First Name: ");
first = first.substring(0, 1) + first.substring(1);
Person person = checkPersonExists(first);

if (person.id == -1) {
person = addPerson(first);
}
}

private Person addPerson(String firstName) throws SQLException, IOException, MenuException, ExitException, TooManyTriesException {
try (
PreparedStatement addPerson = conn.prepareStatement(
"insert into person(first_name, last_name, age, phone_number, email, credit_score) values(?, ?, ?, ?, ?, ?)"
);
Statement getResId = conn.createStatement();
) {
String last = input.getPrompt("Last Name: ");
last = last.substring(0, 1) + last.substring(1);
int age = input.getMenuInt("Age: ");
String phone_number = input.getPrompt("Phone Number (###-###-####): ");
String email = input.getPrompt("Email: ");
int credit_score = input.getMenuInt("Credit Score: ");
Person person = new Person(-1, firstName, last, null, age, phone_number, email, credit_score);

addPerson.setString(1, firstName);
addPerson.setString(2, last);
addPerson.setInt(3, age);
addPerson.setString(4, phone_number);
addPerson.setString(5, email);
addPerson.setInt(6, credit_score);

addPerson.execute();
conn.commit();
ResultSet res = getResId.executeQuery("select max(id) as id from person");
if (res.next()) person.id = res.getInt("id");
return person;
}
}

private void changePIN() throws IOException, ExitException, MenuException, SQLException, TooManyTriesException {
Expand Down

0 comments on commit 8b99c1f

Please sign in to comment.