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

Commit

Permalink
update procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 20, 2022
1 parent 7ac203d commit e9e388b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 84 deletions.
2 changes: 1 addition & 1 deletion db/procedures/update_apt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BEGIN
SELECT COUNT(*) into amt
FROM lease
WHERE
prop_id = ? AND apt = ? AND
prop_id = propId AND apt = apt AND
TO_CHAR(ADD_MONTHS(start_date, term_length), 'YYYYMMDD') < TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMMDD');

IF amt <> 0 THEN
Expand Down
10 changes: 0 additions & 10 deletions numa/src/main/java/numa/Exceptions/BadParamException.java

This file was deleted.

1 change: 1 addition & 0 deletions numa/src/main/java/numa/Exceptions/MenuException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public class MenuException extends Exception {
public MenuException() {
super();
}
}
79 changes: 37 additions & 42 deletions numa/src/main/java/numa/NUMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class NUMA {
public static void main (String[] args) throws IOException {
boolean connected = false;

// Re-prompts whenever user is not connected
do {
try (
Reader input = new Reader();
) {
try (
Reader input = new Reader();
) {
// Re-prompts whenever user is not connected
do {
String[] loginInfo = new String[2];
Dotenv dotenv = Dotenv.load();
String DB_URL = dotenv.get("DB_URL");
Expand All @@ -31,77 +31,72 @@ public static void main (String[] args) throws IOException {
loginInfo = getLogin(input);
}

// Try logging in and creating a prepared statement
try (
Connection conn = DriverManager.getConnection(DB_URL, loginInfo[0], loginInfo[1]);
) {
conn.setAutoCommit(false);

connected = true;

while (connected) {
try {
System.out.println();
System.out.println("============================================");
System.out.println("Northside Uncommons Management of Apartments");
System.out.println("============================================");
System.out.println("Enter 'm' to return here and 'q' to quit the program at any time\n");
System.out.println("[1] Resident Portal");
System.out.println("[2] Management Portal");
// System.out.println("[3] Shareholder Disclosures\n");
System.out.println("[2] Management Portal\n");

boolean portalEntered = false;

Boolean portalEntered = false;
while (!portalEntered) {
try {
String portalChoice = input.getMenuLine("Portal #: ");

switch(portalChoice) {
case "1":
new ResidentPortal(conn, input);
portalEntered = true;
break;
case "2":
new ManagementPortal(conn, input);
portalEntered = true;
break;
// case "3":
// new ShareholderPortal(conn, input);
// portalEntered = true;
// break;
default:
System.out.println("Invalid input, please only enter numbers 1 - 3\n");
}
} finally {}

switch (portalChoice) {
case "1":
new ResidentPortal(conn, input);
portalEntered = true;
break;
// case "2":
// new ManagementPortal(conn, input);
// portalEntered = true;
// break;
default:
System.out.println("Invalid input, please only enter numbers 1 - 2\n");
}
}
finally {}
}

System.out.println("Returning to the main menu...\n");
}
catch (MenuException e) {
// Do nothing
}
}
catch (SQLException e) {
System.out.println("SQL Exception: " + e);
System.out.println("Returning to the main menu...\n");
}
}
}
}
catch (SQLException e) {
// Specific exception for bad user/pass combo
if (e.getErrorCode() == 1017) {
System.out.println("Login denied. Please try again");
System.out.println("Login denied. Please try again\n");
} else {
System.out.println("Failed to connect to the database. Please try again at a later time");
}
}
catch (IOException e) {
System.out.println("IOException: " + e);
}
catch (ExitException e) {
System.out.println("Exiting...");
}

} catch (IOException e) {
System.out.println("IOException: " + e);
}
} while (!connected);
} while (!connected);

}
catch (IOException e) {
System.out.println("IO Exception: " + e);
}
catch (ExitException e) {
System.out.println("Exiting...");
}
}

/**
Expand Down
44 changes: 15 additions & 29 deletions numa/src/main/java/numa/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
import java.io.InputStreamReader;
import numa.Exceptions.*;


/**
* Enhanced version of Java's BufferedReader
* Reader with various parsing methods
*/
public class Reader extends BufferedReader {
int MAX_TRIES = 5;

public Reader() {
super(new InputStreamReader(System.in));
}

/** Used for menu input (Navigating between portals and subportals) */
/**
* Used for menu input (Navigating between portals and subportals)
* Allows for immediate quitting and main menu jump
*/
public String getMenuLine(String prompt) throws IOException, ExitException, MenuException {
System.out.print(prompt);
String input = super.readLine().toLowerCase();
System.out.println();
if (input.equals("q") || input.equals("'q'")) {
System.out.println();
throw new ExitException();
}
else if (input.equals("m") || input.equals("'m'")) {
System.out.println();
throw new MenuException();
}
return input;
Expand All @@ -49,39 +51,23 @@ public String getPrompt(String prompt) throws IOException, ExitException {
System.out.print(prompt);
String input = super.readLine();
System.out.println();
if (input.equals("q") || input.equals("'q'")) {
throw new ExitException();
}
return input;
}

/** Used for non-menu inputs that allows validation */
public String getPrompt(String prompt, Validate validation) throws IOException, ExitException {
while (true) {
/** Used for non-menu inputs that allows for input validation */
public String getPrompt(String prompt, Validate validation) throws IOException, ExitException, MenuException {
int i = 0;
while (i++ < MAX_TRIES) {
System.out.print(prompt);
String input = super.readLine();
System.out.println();
if (input.equals("q") || input.equals("'q'")) {
throw new ExitException();
}
Validated res = validation.validate(input);
if (res.errMsg.equals("")) {
return input;
if (res.valid) {
return res.validated;
}
System.out.println(res.errMsg + "\n");
}
}

/** Used for multi-action prompts that allow adding to the database */
public int getAddPrompt(String prompt) throws IOException, ExitException, MenuException {
String input = this.getMenuLine(prompt);
if (input.equals("a") || input.equals("'a'")) {
return 0;
}
try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
throw new NumberFormatException();
System.out.println(res.errMsg);
}
System.out.println("Too many attempts. Returning to the main menu...");
throw new MenuException();
}
}
11 changes: 9 additions & 2 deletions numa/src/main/java/numa/Validated.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
public class Validated {
String validated;
String errMsg;
boolean valid;

public Validated(String validated, String errMsg) {
public Validated(String validated, String errMsg, boolean valid) {
this.validated = validated;
this.errMsg = errMsg;
this.valid = valid;
}
}

interface Validate {
/**
* Validation function format
* Returns true on proper validation and false otherwise
* public boolean validateX();
*/
public Validated validate(String input);
}
}

0 comments on commit e9e388b

Please sign in to comment.