Skip to content
Open

Moon #12

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
478a8f2
add deadline
github-classroom[bot] Nov 28, 2025
eca520c
test first commit
met4lk1tty Nov 28, 2025
2760978
Moved test file to correct structure
met4lk1tty Nov 28, 2025
4c2fa50
Enable dev mode and add test logging in Main
met4lk1tty Nov 28, 2025
1815cd2
Implement login loop in Main using System.in for input
met4lk1tty Nov 28, 2025
66cca47
Add menu options to run method
met4lk1tty Nov 28, 2025
d0e7c92
add listMoonMissions method
met4lk1tty Nov 28, 2025
008acb8
add getMoonMissionById method
met4lk1tty Nov 28, 2025
ce95e82
add countMissionsByYear method
met4lk1tty Nov 28, 2025
687784b
Implement more method cases in switch
met4lk1tty Nov 28, 2025
7493b37
Implement visible id to method listMoonMissions when printing menu op…
met4lk1tty Nov 28, 2025
08cc1b8
Implement createAccount method, passes integration test
met4lk1tty Dec 1, 2025
97ff845
implement createAccount, updateAccountPassword, and listAccounts help…
met4lk1tty Dec 1, 2025
c376082
add deleteAccount method with user ID input and confirmation - passe…
met4lk1tty Dec 1, 2025
3b4145a
Create class SimpleDriverManagerDataSource
met4lk1tty Dec 1, 2025
aa41e0d
Create interface AccountRepository
met4lk1tty Dec 1, 2025
98a30f1
Create interface MoonMissionRepository
met4lk1tty Dec 1, 2025
f40b9f2
Create record Accont and MoonMission
met4lk1tty Dec 1, 2025
be0f8b5
Implemented immutable data (records) for Account and MoonMission to r…
met4lk1tty Dec 1, 2025
fc8ac6e
Impl AccountRepositoryJdbcImpl class
met4lk1tty Dec 4, 2025
63a1f71
Impl MoonMissionJdbcImpl class
met4lk1tty Dec 4, 2025
46735bd
Impl AppFlow class
met4lk1tty Dec 4, 2025
ccf957d
Impl AccountRepository interface
met4lk1tty Dec 4, 2025
ebb3209
Impl MoonMissionRepository interface
met4lk1tty Dec 4, 2025
4929580
Impl AccountImpl class
met4lk1tty Dec 4, 2025
27fe08d
Move MoonMission and Account records to model package, update code
met4lk1tty Dec 11, 2025
15310fb
Move AccountRepository and MoonMissionRepository to repository packag…
met4lk1tty Dec 11, 2025
4dbc5b0
update class name CLIFlow to BaseRepository, move to repository package
met4lk1tty Dec 11, 2025
b3e3ced
update class name AccountImpl to AccountRepositoryJdbc, move to repos…
met4lk1tty Dec 11, 2025
d761c6d
update clas name MoonMissionImpl to MoonMissionRepositoryJdbc, move t…
met4lk1tty Dec 11, 2025
87184b4
move methods from main: isDevMode and resolveConfig to new class Conf…
met4lk1tty Dec 11, 2025
05866a6
move menu loop from main: to package cli and new class menuCLI
met4lk1tty Dec 11, 2025
7687e25
move login from main: to package cli and new class LoginManager
met4lk1tty Dec 11, 2025
fab16bf
create class InputReader in package cli
met4lk1tty Dec 11, 2025
c72e434
create class AccountCLI in package cli
met4lk1tty Dec 11, 2025
aaa0145
create class MoonMissionCLI in package cli
met4lk1tty Dec 11, 2025
75105b4
move method readline from main: to input reader class
met4lk1tty Dec 11, 2025
bfbe2cd
move methods listmoonmissions, getmoonmissionbyid, countmissionsbyyea…
met4lk1tty Dec 11, 2025
b04d846
update main
met4lk1tty Dec 11, 2025
966a100
update repository classes
met4lk1tty Dec 11, 2025
a3b8b13
update MoonMissionCLI
met4lk1tty Dec 11, 2025
1e2d5fc
update MenyCLI
met4lk1tty Dec 11, 2025
bd45ee4
update LoginManager
met4lk1tty Dec 11, 2025
50c4fbc
update InputReader
met4lk1tty Dec 11, 2025
645fca3
add interface handleExitOrMenu to CLI package
met4lk1tty Dec 11, 2025
cb4e370
update AccountCLI
met4lk1tty Dec 11, 2025
6ddbfe3
add class RepositoryException to repository package
met4lk1tty Dec 11, 2025
089411e
add AccountService and MoonMissionService class to service package
met4lk1tty Dec 11, 2025
9d26027
update main and SimpleDriverManagerDataSource class
met4lk1tty Dec 11, 2025
ce8c5ac
update test deleteaccount with yes confirmation of deleting account
met4lk1tty Dec 11, 2025
311755d
Refactor AccountCLI to display accounts using toString() in updatePas…
met4lk1tty Dec 11, 2025
81ccb5f
random commit
met4lk1tty Dec 11, 2025
7efbfd3
Refactor repositories and services to use unchecked RepositoryException
met4lk1tty Dec 11, 2025
b32a557
remove comment from record
met4lk1tty Dec 11, 2025
d5653e8
Refactor: replace manual year filtering with service.countMissionsByY…
met4lk1tty Dec 11, 2025
ba15350
add javadoc comments to cli package
met4lk1tty Dec 11, 2025
1893076
add jacadoc comments to model package
met4lk1tty Dec 11, 2025
fb2a25b
add javadoc comments to repository package
met4lk1tty Dec 11, 2025
c10196b
add javadoc comments to service package
met4lk1tty Dec 11, 2025
9a9f51b
add javdoc comments to main example package
met4lk1tty Dec 11, 2025
c2ed679
add more javadocs because coderabbit said so
met4lk1tty Dec 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/339Lr3BJ)
### How the tests work (and Docker requirement)

This project ships with an end‑to‑end CLI integration test suite that uses Testcontainers to spin up a temporary MySQL database.
Expand Down
117 changes: 117 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>jdbc</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.4</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>com.example.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>6.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-params</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-engine</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.6</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>byte-buddy</artifactId>
<groupId>net.bytebuddy</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.20.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.21.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mockito.version>5.20.0</mockito.version>
<junit.jupiter.version>6.0.1</junit.jupiter.version>
<assertj.core.version>3.27.6</assertj.core.version>
</properties>
</project>
Comment on lines +1 to +117
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for the source pom.xml and verify Java version usage
echo "=== Source pom.xml ==="
if [ -f pom.xml ]; then
  cat pom.xml | head -50
else
  echo "pom.xml not found at root"
  fd "pom.xml" -t f | head -5
fi

echo -e "\n=== Checking .gitignore for dependency-reduced-pom.xml ==="
if [ -f .gitignore ]; then
  cat .gitignore
else
  echo ".gitignore does not exist"
fi

echo -e "\n=== List files in repository root ==="
ls -la | head -30

Repository: ithsjava25/ithsjava25-java-databas-jdbc-javafx-classrom

Length of output: 2977


🌐 Web query:

Java 25 release date stable version 2025

💡 Result:

The stable (General Availability) release date for Java (JDK) 25 was September 16, 2025. [1][2]

Sources:

  • JDK 25 proposed schedule / confirmation. [1]
  • OpenJDK announcement that JDK 25 is generally available (GA build). [2]

Add dependency-reduced-pom.xml to .gitignore.

The file dependency-reduced-pom.xml is automatically generated by maven-shade-plugin during the build process and should be excluded from version control (add to .gitignore) to avoid merge conflicts and repository bloat. Add the following line to .gitignore:

dependency-reduced-pom.xml

Note: Java 25 is now stable (released September 2025) and intentionally configured for this classroom project; no action needed on that front.

🤖 Prompt for AI Agents
In dependency-reduced-pom.xml around lines 1 to 117, the generated file produced
by the maven-shade-plugin is tracked in git; update the repository's .gitignore
to add a line excluding dependency-reduced-pom.xml so this generated file is not
committed (add the single entry "dependency-reduced-pom.xml" to .gitignore and
commit that change).

37 changes: 37 additions & 0 deletions src/main/java/com/example/ConfigUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example;

import java.util.Arrays;

/**
* Utility class for reading configuration and environment variables.
*/
public class ConfigUtils {

/**
* Determines if the application should run in development mode.
* Checks system property "devMode", environment variable "DEV_MODE",
* and command-line argument "--dev".
*
* @param args command-line arguments
* @return true if dev mode is enabled, false otherwise
*/
public static boolean isDevMode(String[] args) {
if (Boolean.getBoolean("devMode")) return true;
if ("true".equalsIgnoreCase(System.getenv("DEV_MODE"))) return true;
return Arrays.asList(args).contains("--dev");
}

/**
* Resolves a configuration value from system properties or environment variables.
* Returns null if neither is set.
*
* @param propertyKey system property key
* @param envKey environment variable key
* @return trimmed configuration value or null if not set
*/
public static String resolveConfig(String propertyKey, String envKey) {
String v = System.getProperty(propertyKey);
if (v == null || v.trim().isEmpty()) v = System.getenv(envKey);
return (v == null || v.trim().isEmpty()) ? null : v.trim();
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/example/DevDatabaseInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import org.testcontainers.containers.MySQLContainer;

/**
* Initializes a MySQL development database using Testcontainers.
* Sets system properties for JDBC URL, username, and password after startup.
*/
public class DevDatabaseInitializer {
private static MySQLContainer<?> mysql;

Expand All @@ -21,4 +25,4 @@ public static void start() {
System.setProperty("APP_DB_PASS", mysql.getPassword());
}
}
}
}
88 changes: 41 additions & 47 deletions src/main/java/com/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
package com.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Arrays;

import com.example.cli.*;
import com.example.repository.*;
import com.example.service.*;

/**
* Entry point for the Moon Mission application.
*
* <p>
* Initializes the development database if dev mode is enabled, sets up repositories,
* services, and CLI components, handles user login, and shows the main menu.
* </p>
*/
public class Main {

static void main(String[] args) {
if (isDevMode(args)) {
/**
* Starts the application.
*
* @param args Command-line arguments. Supports "--dev" to enable dev mode.
*/
public static void main(String[] args) {
if (ConfigUtils.isDevMode(args)) {
DevDatabaseInitializer.start();
}
new Main().run();
}

public void run() {
// Resolve DB settings with precedence: System properties -> Environment variables
String jdbcUrl = resolveConfig("APP_JDBC_URL", "APP_JDBC_URL");
String dbUser = resolveConfig("APP_DB_USER", "APP_DB_USER");
String dbPass = resolveConfig("APP_DB_PASS", "APP_DB_PASS");
String jdbcUrl = ConfigUtils.resolveConfig("APP_JDBC_URL", "APP_JDBC_URL");
String dbUser = ConfigUtils.resolveConfig("APP_DB_USER", "APP_DB_USER");
String dbPass = ConfigUtils.resolveConfig("APP_DB_PASS", "APP_DB_PASS");

if (jdbcUrl == null || dbUser == null || dbPass == null) {
throw new IllegalStateException(
"Missing DB configuration. Provide APP_JDBC_URL, APP_DB_USER, APP_DB_PASS " +
"as system properties (-Dkey=value) or environment variables.");
throw new IllegalStateException("Missing DB configuration.");
}

try (Connection connection = DriverManager.getConnection(jdbcUrl, dbUser, dbPass)) {
} catch (SQLException e) {
throw new RuntimeException(e);
}
//Todo: Starting point for your code
}
SimpleDriverManagerDataSource dataSource = new SimpleDriverManagerDataSource(jdbcUrl, dbUser, dbPass);
boolean devMode = ConfigUtils.isDevMode(args);

/**
* Determines if the application is running in development mode based on system properties,
* environment variables, or command-line arguments.
*
* @param args an array of command-line arguments
* @return {@code true} if the application is in development mode; {@code false} otherwise
*/
private static boolean isDevMode(String[] args) {
if (Boolean.getBoolean("devMode")) //Add VM option -DdevMode=true
return true;
if ("true".equalsIgnoreCase(System.getenv("DEV_MODE"))) //Environment variable DEV_MODE=true
return true;
return Arrays.asList(args).contains("--dev"); //Argument --dev
}
AccountRepositoryJdbc accountRepo = new AccountRepositoryJdbc(dataSource, devMode);
MoonMissionRepositoryJdbc missionRepo = new MoonMissionRepositoryJdbc(dataSource, devMode);

/**
* Reads configuration with precedence: Java system property first, then environment variable.
* Returns trimmed value or null if neither source provides a non-empty value.
*/
private static String resolveConfig(String propertyKey, String envKey) {
String v = System.getProperty(propertyKey);
if (v == null || v.trim().isEmpty()) {
v = System.getenv(envKey);
AccountService accountService = new AccountService(accountRepo);
MoonMissionService missionService = new MoonMissionService(missionRepo);

InputReader input = new InputReader();

AccountCLI accountCLI = new AccountCLI(accountService, input);
MoonMissionCLI missionCLI = new MoonMissionCLI(missionService, input);
MenuCLI menu = new MenuCLI(accountCLI, missionCLI, input);

LoginManager loginManager = new LoginManager(accountService, input);

if (loginManager.login()) {
menu.showMainMenu();
}
return (v == null || v.trim().isEmpty()) ? null : v.trim();
}
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/example/SimpleDriverManagerDataSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
* Simple DataSource implementation using DriverManager.
*
* <p>
* Provides basic JDBC connections using a URL, username, and password.
* Only getConnection methods are supported; other DataSource features throw
* UnsupportedOperationException.
* </p>
*/
public class SimpleDriverManagerDataSource implements DataSource {
private final String url;
private final String username;
private final String password;

/**
* Creates a new DataSource with the given JDBC parameters.
*
* @param url the JDBC URL
* @param username the database username
* @param password the database password
*/
public SimpleDriverManagerDataSource(String url, String username, String password) {
this.url = url;
this.username = username;
this.password = password;
}

@Override
public Connection getConnection() throws SQLException { return DriverManager.getConnection(url, username, password); }

@Override
public Connection getConnection(String username, String password) throws SQLException { return DriverManager.getConnection(url, username, password); }

@Override public <T> T unwrap(Class<T> iface) { throw new UnsupportedOperationException(); }
@Override public boolean isWrapperFor(Class<?> iface) { return false; }
@Override public java.io.PrintWriter getLogWriter() { throw new UnsupportedOperationException(); }
@Override public void setLogWriter(java.io.PrintWriter out) { throw new UnsupportedOperationException(); }
@Override public void setLoginTimeout(int seconds) { throw new UnsupportedOperationException(); }
@Override public int getLoginTimeout() { return 0; }
@Override public java.util.logging.Logger getParentLogger() { throw new UnsupportedOperationException(); }
}
Loading