-
Notifications
You must be signed in to change notification settings - Fork 59
Vglevel #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vglevel #16
Changes from all commits
646d156
66b030d
6477a62
fbbfc41
16d6c42
3f354f6
d446fb7
c6038c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.example; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.sql.Connection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.sql.DriverManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.sql.SQLException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.repo.AccountRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.repo.DTO.AccountDTO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.repo.DTO.MissionDTO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.repo.MoonMissionRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.sql.DataSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.sql.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Optional; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Scanner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.regex.Pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class Main { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final Scanner scanner = new Scanner(System.in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void main(String[] args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isDevMode(args)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DevDatabaseInitializer.start(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -26,13 +36,328 @@ public void run() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "as system properties (-Dkey=value) or environment variables."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try (Connection connection = DriverManager.getConnection(jdbcUrl, dbUser, dbPass)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (SQLException e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RuntimeException(e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DataSource ds = new SimpleDriverManagerDataSource( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.getProperty("APP_JDBC_URL"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.getProperty("APP_DB_USER"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.getProperty("APP_DB_PASS") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AccountRepository ac = new AccountRepository(ds); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MoonMissionRepository mmc = new MoonMissionRepository(ds); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean authorized = login(ac); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!authorized) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Invalid username or password"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("press 0 to exit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String exit = scanner.nextLine().trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(exit.equals("0")){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int option = promptMenu(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (option) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 1 -> listMissions(mmc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 2 -> getMission(mmc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 3 -> missionsCountYear(mmc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 4 -> createAccount(ac); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 5 -> updatePassword(ac); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 6 -> deleteAccount(ac); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 0 -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default -> System.out.println("Invalid choice.\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Prompts username and password, checks if the combination is present in accounts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return <code>true</code> if the name/password combo exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * <code>false</code> if either name/password isn't present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private boolean login(AccountRepository ac) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Username: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String unm = scanner.nextLine(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Password: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String pw = scanner.nextLine(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ac.matchCredentials(unm, pw); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Prompts the menu options and returns a user input integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return integer >= 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidInt(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private int promptMenu(){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.print("\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "1) List moon missions (prints spacecraft names from `moon_mission`).\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "2) Get a moon mission by mission_id (prints details for that mission).\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "3) Count missions for a given year (prompts: year; prints the number of missions launched that year).\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "4) Create an account (prompts: first name, last name, ssn, password; prints confirmation).\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "5) Update an account password (prompts: user_id, new password; prints confirmation).\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "6) Delete an account (prompts: user_id; prints confirmation).\n" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "0) Exit.\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return getValidInt("Enter Choice: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Lists all spacecraft from the moon_mission table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void listMissions(MoonMissionRepository mmc){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<MissionDTO> missions = mmc.getAllMissions(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for(MissionDTO mission : missions){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println(mission.spacecraft()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Prompts for a mission ID and prints its data is available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidInt(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void getMission(MoonMissionRepository mmc){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int id = getValidInt("Mission Id: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<MissionDTO> mission = mmc.getMissionById(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(mission.isPresent()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MissionDTO m = mission.get(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\nSpacecraft: " + m.spacecraft() + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\nLaunch date: " + m.launchDate() + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\nCarrier rocket: " + m.carrierRocket() + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\nOperator: " + m.operator() + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\nMission type: " + m.missionType() + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "\nOutcome: " + m.outcome()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nMission not found."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Prompts for a year and prints how many rows in moon_mission was launched then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidInt(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void missionsCountYear(MoonMissionRepository mmc){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int year = getValidInt("Mission Year: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nMissions in " + year + ": " + mmc.missionCount(year)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Gives a flow for creating a new account, asking for First and Last name, SSN and password | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * default accountname is assigned if available and promted for if not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidName(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidSSN(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidPassword(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void createAccount(AccountRepository ac) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String fn = getValidName("First Name: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String ln = getValidName("Last Name: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String ssn = getValidSSN("SSN: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String pw = getValidPassword("Password: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String accName; //Default accountname is first three letters of first and last name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(fn.length() <= 3 && ln.length() <=3){ //if both first and last name are 3 or fewer letters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accName = fn + ln;} //accountname is both full combined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (fn.length() <= 3){ //if only first name is 3 or fewer letters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accName = fn + ln.substring(0, 2); //accountname is full first name and first 3 from last name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if(ln.length() <= 3){ //if only last name is 3 or fewer letters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accName = fn.substring(0, 2) + ln; //accountname is first 3 from first name and full last name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else{ //if both are longer than 3 accountname follows default pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accName = fn.substring(0, 2) + ln.substring(0, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+182
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Account name generation uses wrong substring length. Comments say "first 3 letters" but - if(fn.length() <= 3 && ln.length() <=3){ //if both first and last name are 3 or fewer letters
+ if(fn.length() <= 3 && ln.length() <= 3){ //if both first and last name are 3 or fewer letters
accName = fn + ln;} //accountname is both full combined
else if (fn.length() <= 3){ //if only first name is 3 or fewer letters
- accName = fn + ln.substring(0, 2); //accountname is full first name and first 3 from last name
+ accName = fn + ln.substring(0, 3); //accountname is full first name and first 3 from last name
}
else if(ln.length() <= 3){ //if only last name is 3 or fewer letters
- accName = fn.substring(0, 2) + ln; //accountname is first 3 from first name and full last name
+ accName = fn.substring(0, 3) + ln; //accountname is first 3 from first name and full last name
}
else{ //if both are longer than 3 accountname follows default pattern
- accName = fn.substring(0, 2) + ln.substring(0, 2);
+ accName = fn.substring(0, 3) + ln.substring(0, 3);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //Check if the accountname exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<AccountDTO> nameCheck; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nameCheck = ac.getAccountByName(accName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(nameCheck.isEmpty()){ //if accountname is available continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accName = getValidName("Account Name: "); //if not prompt for a new accountname and check again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //todo add help method for accountname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //Create and add account | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AccountDTO newAccount = new AccountDTO(0, accName, pw, fn, ln, ssn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ac.createAccount(newAccount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(ac.accountExists(accName)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nAccount created"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nAccount creation failed."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Updates password after prompting for an ID and new password | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidInt(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidPassword(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void updatePassword (AccountRepository ac) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int id = getValidInt("User id: "); //todo add check if account is present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(ac.accountExists(id)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String newPassword = getValidPassword("New password: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ac.updatePassword(id, newPassword); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(ac.matchCredentials(ac.getAccountByID(id).get().name(), newPassword)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Password updated"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Password update failed."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Account not found."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Deletes account after prompting for an ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see #getValidInt(String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void deleteAccount(AccountRepository ac) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int id = getValidInt("User id: "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(ac.accountExists(id)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ac.deleteAccount(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(!ac.accountExists(id)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Account deleted"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Account deletion failed."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Account not found."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Help method to get a valid and positive integer from input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param prompt message to explain what is asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return integer >= 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private int getValidInt(String prompt){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\n" + prompt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int option = Integer.parseInt(scanner.nextLine()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (option >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return option; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Please enter a positive integer.\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (NumberFormatException e){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Please enter a valid integer\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Help method to get a valid string that only contains letters from input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param prompt message to explain what is asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return Capitalized string with only letters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private String getValidName(String prompt){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\n" + prompt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String name = scanner.nextLine().trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (name.isBlank()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nCannot be blank"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if(!Pattern.matches("^[a-zA-Z]+$", name)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nMust only contain letters"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+302
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edge case: Single-character name produces empty suffix. If else{
- return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
+ String capitalized = name.substring(0, 1).toUpperCase();
+ if (name.length() > 1) {
+ capitalized += name.substring(1).toLowerCase();
+ }
+ return capitalized;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Help method to get a correctly formated SSN from input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param prompt message to explain what is asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return String with YYMMDD-XXXX formatting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private String getValidSSN(String prompt){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\n" + prompt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String ssn = scanner.nextLine().trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ssn.isBlank()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nCannot be blank"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if(!Pattern.matches("^\\d{6}-\\d{4}$", ssn)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\nMust follow pattern YYMMDD-XXXX"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ssn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Help method to get a valid password from input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param prompt message to explain what is asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return string of at least 6 characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private String getValidPassword(String prompt){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(true){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("\n" + prompt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String pw = scanner.nextLine(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(pw.length() < 6){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Password must be at least 6 characters"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //Todo: Starting point for your code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Determines if the application is running in development mode based on system properties, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * environment variables, or command-line arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved configuration values are ignored - environment variables won't work.
The code resolves config with fallback to environment variables (lines 29-31) but then directly uses
System.getProperty()instead of the resolved values. This breaks the intended fallback behavior.📝 Committable suggestion
🤖 Prompt for AI Agents