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

Commit

Permalink
restructure directory
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 3, 2022
1 parent e523918 commit d5cd9e2
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 209 deletions.
21 changes: 13 additions & 8 deletions db/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ CREATE TABLE pet (
PRIMARY KEY(id)
);

CREATE TABLE admin (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
username VARCHAR2(20) NOT NULL,
password VARCHAR2(255) NOT NULL
);


-- -------------------
-- Payment Types
-- -------------------
-- Can be debit or credit, from the point of view of NUMA, it doesn't matter
-- Can be debit or credit, from the point of view of NUMA, it doesn't matter (Debit will have PIN)
CREATE TABLE pay_card (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
person_id NUMBER NOT NULL,
card_num CHAR(19) NOT NULL UNIQUE,
card_num CHAR(19) NOT NULL,
exp_date DATE NOT NULL,
cvv CHAR(3) NOT NULL
CHECK (REGEXP_LIKE(cvv, '\d{3}')),
Expand All @@ -52,16 +57,14 @@ CREATE TABLE pay_card (

CREATE TABLE venmo (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
person_id NUMBER NOT NULL,
handle VARCHAR2(255) NOT NULL UNIQUE
handle VARCHAR2(255) NOT NULL
CHECK (handle LIKE '@%'),
PRIMARY KEY(id)
);

CREATE TABLE ach (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
person_id NUMBER NOT NULL,
acct_num CHAR(17) NOT NULL UNIQUE
acct_num CHAR(17) NOT NULL
CHECK (REGEXP_LIKE(acct_num, '\d{17}')),
routing_num CHAR(9) NOT NULL
CHECK (REGEXP_LIKE(routing_num, '\d{9}')),
Expand All @@ -73,11 +76,13 @@ CREATE TABLE ach (
-- Adding a specific payment method (Card, Venmo or ACH) should trigger a row add to this table automatically
-- Only one of the [payment]_id methods should be filled, rest should be NULL
CREATE TABLE payment_method (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
person_id NUMBER NOT NULL,
pay_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
card_id NUMBER DEFAULT NULL,
venmo_id NUMBER DEFAULT NULL,
ach_id NUMBER DEFAULT NULL,
PRIMARY KEY(id),
FOREIGN KEY(person_id) REFERENCES person(id) ON DELETE CASCADE,
FOREIGN KEY(card_id) REFERENCES pay_card(id) ON DELETE CASCADE,
FOREIGN KEY(venmo_id) REFERENCES venmo(id) ON DELETE CASCADE,
FOREIGN KEY(ach_id) REFERENCES ach(id) ON DELETE CASCADE
Expand Down
4 changes: 3 additions & 1 deletion numa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ repositories {
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc8', version: '21.5.0.0'
implementation 'io.github.cdimascio:dotenv-java:2.2.3'
// https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc8', version: '21.5.0.0'

}

testing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package numa;
package numa.Exceptions;

/**
* Custom exception for handling erroneous user-inputted parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package numa;
package numa.Exceptions;

/**
* Custom exception for early exiting of the program
Expand Down
6 changes: 6 additions & 0 deletions numa/src/main/java/numa/Exceptions/MenuException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package numa.Exceptions;

public class MenuException extends Exception {
public MenuException() {
}
}
102 changes: 44 additions & 58 deletions numa/src/main/java/numa/NUMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import io.github.cdimascio.dotenv.Dotenv;
import numa.Portals.*;
import numa.Exceptions.*;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
public class NUMA {
final static boolean DEV = true;
Expand All @@ -20,94 +25,75 @@ public static void main (String[] args) throws IOException {

// Re-prompts whenever user is not connected
do {
try {
try (
Reader input = new Reader();
) {
String[] loginInfo = new String[2];
String DB_URL = "";
Dotenv dotenv = Dotenv.load();
String DB_URL = dotenv.get("DB_URL");
if (DEV) {
Dotenv dotenv = Dotenv.load();
String USER = dotenv.get("USERNAME");
String PASS = dotenv.get("PASSWORD");
DB_URL = dotenv.get("DB_URL");
loginInfo[0] = USER;
loginInfo[1] = PASS;
} else {
System.out.print("Enter Oracle DB URL: ");
DB_URL = input.readLine();
loginInfo = getLogin(input);
}

// Try logging in and creating a prepared statement
try (
Connection conn = DriverManager.getConnection(DB_URL, loginInfo[0], loginInfo[1]);
PreparedStatement query = conn.prepareStatement("select capacity, count(id) as count from takes natural join (select * from section natural join classroom) where year=? and semester=? and course_id=? and sec_id=? group by capacity");
Statement getYearOpts = conn.createStatement();
) {
Connection conn = DriverManager.getConnection(DB_URL, loginInfo[0], loginInfo[1]);
) {
connected = true;
System.out.println("Connected\n");

// Fetch all valid year options so it's cached (Year list is small enough)
ResultSet yearOptsRes = getYearOpts.executeQuery("select distinct year from section");
List<String> yearOpts = new ArrayList<String>();
while (yearOptsRes.next()) {
yearOpts.add(yearOptsRes.getString(1));
}
yearOptsRes.close();

// Verify and get parameters of the query from the user
Parameters params = new Parameters();

// Will refetch parameters if user inputs bad parameters instead of exiting
while (true) {
try {
params.getParams(conn, input, yearOpts);
break;
} catch (BadParamException e) {
System.out.println(e.getMessage());
}
}

input.close(); // Close Reader object (No more input is needed)

query.setInt(1, params.year);
query.setString(2, params.sem);
query.setInt(3, params.courseId);
query.setInt(4, params.secId);
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");

// Should only have one occurrence
ResultSet res = query.executeQuery();
int[] capacityCount = new int[2];
// capacityCount[0] = Capacity of classroom
// capacityCount[1] = Enrollment of section
while (res.next()) {
capacityCount[0] = res.getInt(1);
capacityCount[1] = res.getInt(2);
}
res.close();

System.out.printf("Capacity is %d | Enrollment is %d\n", capacityCount[0], capacityCount[1]);
System.out.print("Portal #: ");
try {
String portalChoice = input.getMenuLine();
System.out.println();

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

int difference = capacityCount[0] - capacityCount[1];
if (difference == 0) {
System.out.printf("There are no open seats\n");
} else if (difference > 0) {
System.out.printf("There are %d open seat(s)\n", difference);
} else {
System.out.printf("There are %d students without seats\n", Math.abs(difference));
}
catch (MenuException e) {
// Do nothing
}
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(e);
System.out.println("Login denied. Please try again\n");
} else {
System.out.println("SQLException: " + e);
}
}
catch (IOException e) {
System.out.println("IOException: " + e);
} catch (ExitException e) {
}
catch (ExitException e) {
System.out.println("\nExiting...");
}

Expand Down
Loading

0 comments on commit d5cd9e2

Please sign in to comment.