From fc85476374771805a3314509ab0140df8d1a5e1d Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Thu, 12 Mar 2026 22:13:47 +0100 Subject: [PATCH] Fix: Maven Clean. --- .../team6/DAO/DonationDAO.java | 3 +- .../systemutvikling/team6/HmHApplication.java | 29 ++--- .../java/ntnu/systemutvikling/team6/Main.java | 12 +- .../team6/database/DatabaseConnection.java | 123 +++++++++--------- 4 files changed, 78 insertions(+), 89 deletions(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java index 99abf9b..eed2e8c 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java @@ -1,4 +1,3 @@ package ntnu.systemutvikling.team6.DAO; -public class DonationDAO { -} +public class DonationDAO {} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java index e1ed1af..b27f5af 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java @@ -1,43 +1,39 @@ package ntnu.systemutvikling.team6; +import static javafx.application.Application.launch; + +import java.net.http.HttpClient; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import ntnu.systemutvikling.team6.database.DatabaseConnection; import ntnu.systemutvikling.team6.database.DatabaseManager; import ntnu.systemutvikling.team6.models.Charity; import ntnu.systemutvikling.team6.models.CharityRegistry; import ntnu.systemutvikling.team6.scraper.APICharityScraper; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.http.HttpClient; - -import static javafx.application.Application.launch; - public class HmHApplication extends Application { @Override public void start(Stage stage) throws Exception { - FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/fxml/frontPage.fxml")); + FXMLLoader fxmlLoader = + new FXMLLoader(HmHApplication.class.getResource("/fxml/frontPage.fxml")); Scene scene = new Scene(fxmlLoader.load()); stage.setTitle("Help Me Help"); stage.setScene(scene); - stage.setMinHeight(700); - stage.setMinWidth(1100); + stage.setFullScreen(true); stage.show(); } @Override - public void init(){ + public void init() { /* Test and create tables to MySQL if ain't any */ try { DatabaseManager db = new DatabaseManager(); db.testConnection(); db.createTables(); - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } /* Test and get data from Innsamlingkontrollen API */ @@ -46,17 +42,18 @@ public void init(){ APICharityScraper scraper = new APICharityScraper(https); DatabaseManager db = new DatabaseManager(); - if (scraper.checkConnection()){ + if (scraper.checkConnection()) { CharityRegistry charityRegistry = scraper.parseJSON(scraper.getJSONData()); - for (Charity charity : charityRegistry.getAllCharities()){ - System.out.println(charity.toString()); + for (Charity charity : charityRegistry.getAllCharities()) { + System.out.println(charity.getName()); } db.addAPIDataToTable(charityRegistry.getAllCharities()); } - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } + public static void main(String[] args) { System.out.println("Hello world!"); launch(args); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java index e3e2ee5..e06a045 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java @@ -1,12 +1,8 @@ package ntnu.systemutvikling.team6; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Scene; -import javafx.stage.Stage; -public class Main { - public static void main(String[] args) { - HmHApplication.main(args); - } +public class Main { + public static void main(String[] args) { + HmHApplication.main(args); + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java index fb9ffec..7ec66b0 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java @@ -4,80 +4,77 @@ import java.sql.DriverManager; import java.sql.SQLException; -/** - * Represents a reusable database connection through enviroment variables. - */ - +/** Represents a reusable database connection through enviroment variables. */ public class DatabaseConnection { - private final String databaseURL; - private final String username; - private final String password; - /** - * Constructs a new {@code DatabaseConnection} using database credentials - * retrieved from system environment variables. - * - * @throws IllegalStateException if either databaseURL, username, or password is {@code null} or blank - */ - - // Values stored in system environment variables for security (using ntnu's phpmyadmin for this project) - public DatabaseConnection(){ - this.databaseURL = "jdbc:mysql://namox.idi.ntnu.no:3306/apbaluna?useSSL=false&serverTimezone=UTC"; - this.username = "apbaluna"; - this.password = "GYntUFPG"; + private final String databaseURL; + private final String username; + private final String password; - if (this.databaseURL == null || this.databaseURL.isBlank()) { - throw new IllegalStateException("Database environment variable URL has not been set"); - } + /** + * Constructs a new {@code DatabaseConnection} using database credentials retrieved from system + * environment variables. + * + * @throws IllegalStateException if either databaseURL, username, or password is {@code null} or + * blank + */ - if (this.username == null || this.username.isBlank()) { - throw new IllegalStateException("Username environment variable has not been set"); - } + // Values stored in system environment variables for security (using ntnu's phpmyadmin for this + // project) + public DatabaseConnection() { + this.databaseURL = + "jdbc:mysql://namox.idi.ntnu.no:3306/apbaluna?useSSL=false&serverTimezone=UTC"; + this.username = "apbaluna"; + this.password = "GYntUFPG"; - if (this.password == null || this.password.isBlank()) { - throw new IllegalStateException("Password environment variable has not been set"); - } + if (this.databaseURL == null || this.databaseURL.isBlank()) { + throw new IllegalStateException("Database environment variable URL has not been set"); } - /** - * Constructs a new {@code DatabaseConnection} using database credentials - *

- * Used primarily for JUnit tests. Production should use the constructor - * using environment variables. - *

- * - * @param databaseURL the url to the database - * @param username the username used to log in to the database - * @param password the password used to log in to the database - * @throws IllegalArgumentException if databaseURL, username, or password is - * {@code null} or blank - */ - - public DatabaseConnection(String databaseURL, String username, String password) { - this.databaseURL = databaseURL; - this.username = username; - this.password = password; + if (this.username == null || this.username.isBlank()) { + throw new IllegalStateException("Username environment variable has not been set"); + } - if (this.databaseURL == null || this.databaseURL.isBlank()) { - throw new IllegalArgumentException("Database environment variable URL has not been set"); - } + if (this.password == null || this.password.isBlank()) { + throw new IllegalStateException("Password environment variable has not been set"); + } + } - if (this.username == null || this.username.isBlank()) { - throw new IllegalArgumentException("Username environment variable has not been set"); - } + /** + * Constructs a new {@code DatabaseConnection} using database credentials + * + *

Used primarily for JUnit tests. Production should use the constructor using environment + * variables. + * + * @param databaseURL the url to the database + * @param username the username used to log in to the database + * @param password the password used to log in to the database + * @throws IllegalArgumentException if databaseURL, username, or password is {@code null} or blank + */ + public DatabaseConnection(String databaseURL, String username, String password) { + this.databaseURL = databaseURL; + this.username = username; + this.password = password; - if (this.password == null || this.password.isBlank()) { - throw new IllegalArgumentException("Password environment variable has not been set"); - } + if (this.databaseURL == null || this.databaseURL.isBlank()) { + throw new IllegalArgumentException("Database environment variable URL has not been set"); } + if (this.username == null || this.username.isBlank()) { + throw new IllegalArgumentException("Username environment variable has not been set"); + } - /** - * Creates and returns a new MySQL database connection. - * - * @return a {@link Connection} to the database - * @throws SQLException if the connection cannot be established - */ - public Connection getMySqlConnection() throws SQLException { - return DriverManager.getConnection(databaseURL, username, password); + if (this.password == null || this.password.isBlank()) { + throw new IllegalArgumentException("Password environment variable has not been set"); } + } + + /** + * Creates and returns a new MySQL database connection. + * + * @return a {@link Connection} to the database + * @throws SQLException if the connection cannot be established + */ + public Connection getMySqlConnection() throws SQLException { + return DriverManager.getConnection(databaseURL, username, password); + } }