From e746035551a7f7840f3f9873c57ea9e89f33076f Mon Sep 17 00:00:00 2001
From: Lucy Ciara Herud-Thomassen <86323303+LucyCiara@users.noreply.github.com>
Date: Fri, 20 Mar 2026 17:00:03 +0100
Subject: [PATCH 1/4] feat[app]: overwrite close method to export information
to database on exit
---
src/main/java/edu/group5/app/App.java | 52 ++++++++++++++++++++-------
1 file changed, 39 insertions(+), 13 deletions(-)
diff --git a/src/main/java/edu/group5/app/App.java b/src/main/java/edu/group5/app/App.java
index 782922c..5870b77 100644
--- a/src/main/java/edu/group5/app/App.java
+++ b/src/main/java/edu/group5/app/App.java
@@ -3,10 +3,12 @@
import edu.group5.app.control.MainController;
import edu.group5.app.control.wrapper.DbWrapper;
import edu.group5.app.control.wrapper.OrgApiWrapper;
+import edu.group5.app.model.donation.Donation;
import edu.group5.app.model.donation.DonationRepository;
import edu.group5.app.model.donation.DonationService;
import edu.group5.app.model.organization.OrganizationRepository;
import edu.group5.app.model.organization.OrganizationService;
+import edu.group5.app.model.user.User;
import edu.group5.app.model.user.UserRepository;
import edu.group5.app.model.user.UserService;
import javafx.application.Application;
@@ -16,19 +18,30 @@
import java.util.List;
+import java.util.logging.Logger;
+
/**
* Main entry point for the Help-Me-Help charity donation application.
* Handles database connection, data loading, and application setup.
*/
public class App extends Application {
+ DbWrapper dbWrapper;
+ UserRepository userRepository;
+ DonationRepository donationRepository;
+ private Logger logger;
+ private MainController controller;
+ private Scene scene;
+
@Override
- public void start(Stage stage) {
- DbWrapper dbWrapper = new DbWrapper(true);
+ public void init() {
+ this.logger = Logger.getLogger(App.class.getName());
+ this.logger.info("Application starting");
+
+ this.dbWrapper = new DbWrapper(false);
OrgApiWrapper orgApiWrapper = new OrgApiWrapper("https://app.innsamlingskontrollen.no/api/public/v1/all");
- if (!dbWrapper.connect()) {
- System.err.println("Failed to connect to database");
- return;
+ while (!dbWrapper.connect()) {
+ this.logger.warning("Failed to connect to database");
}
// Load data from database
@@ -47,26 +60,39 @@ public void start(Stage stage) {
}
// Create repositories with fetched data
- UserRepository userRepository = new UserRepository(userData);
- DonationRepository donationRepository = new DonationRepository(donationData);
+ this.userRepository = new UserRepository(userData);
+ this.donationRepository = new DonationRepository(donationData);
OrganizationRepository organizationRepository = new OrganizationRepository(organizationData);
// Create services (backend wiring)
- UserService userService = new UserService(userRepository);
- DonationService donationService = new DonationService(donationRepository, organizationRepository);
+ UserService userService = new UserService(this.userRepository);
+ DonationService donationService = new DonationService(this.donationRepository, organizationRepository);
OrganizationService organizationService = new OrganizationService(organizationRepository);
- MainController controller = new MainController(userService, donationService, organizationService);
+ this.controller = new MainController(userService, donationService, organizationService);
- Scene scene = controller.getMainView().getScene();
- controller.showLoginPage();
+ this.scene = controller.getMainView().getScene();
+ }
+
+ @Override
+ public void start(Stage stage) {
+ this.controller.showLoginPage();
stage.getIcons().add(new Image(getClass().getResource("/header/images/hmh-logo.png").toExternalForm()));
stage.setTitle("Help-Me-Help");
- stage.setScene(scene);
+ stage.setScene(this.scene);
stage.show();
}
+ @Override
+ public void stop() {
+ this.logger.info("Application stopping");
+ this.dbWrapper.connect();
+ this.dbWrapper.exportUsers(this.userRepository.export());
+ this.dbWrapper.exportDonations(this.donationRepository.export());
+ this.dbWrapper.disconnect();
+ }
+
public static void main(String[] args) {
launch(args);
}
From ab5ab0614c3ebf6678dbb6a159e2fa9091a9ed7a Mon Sep 17 00:00:00 2001
From: Lucy Ciara Herud-Thomassen <86323303+LucyCiara@users.noreply.github.com>
Date: Fri, 20 Mar 2026 17:11:52 +0100
Subject: [PATCH 2/4] fix[app]: properly call the stop super method when
overriding
---
src/main/java/edu/group5/app/App.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/edu/group5/app/App.java b/src/main/java/edu/group5/app/App.java
index 5870b77..d657fb8 100644
--- a/src/main/java/edu/group5/app/App.java
+++ b/src/main/java/edu/group5/app/App.java
@@ -85,7 +85,8 @@ public void start(Stage stage) {
}
@Override
- public void stop() {
+ public void stop() throws Exception {
+ super.stop();
this.logger.info("Application stopping");
this.dbWrapper.connect();
this.dbWrapper.exportUsers(this.userRepository.export());
From 4444322d068a9705ba335f7652e3629a02f44512 Mon Sep 17 00:00:00 2001
From: Lucy Ciara Herud-Thomassen <86323303+LucyCiara@users.noreply.github.com>
Date: Fri, 20 Mar 2026 18:02:59 +0100
Subject: [PATCH 3/4] fix&test[model]: fix the repositories not only adding new
rows
---
.../edu/group5/app/model/DBRepository.java | 24 ++---
.../model/donation/DonationRepository.java | 87 +++++++++++--------
.../group5/app/model/user/UserRepository.java | 61 +++++++++----
.../donation/DonationRepositoryTest.java | 9 ++
.../app/model/user/UserRepositoryTest.java | 9 ++
5 files changed, 126 insertions(+), 64 deletions(-)
diff --git a/src/main/java/edu/group5/app/model/DBRepository.java b/src/main/java/edu/group5/app/model/DBRepository.java
index f3363b7..3cd1fa9 100644
--- a/src/main/java/edu/group5/app/model/DBRepository.java
+++ b/src/main/java/edu/group5/app/model/DBRepository.java
@@ -1,18 +1,21 @@
package edu.group5.app.model;
+
import java.util.HashMap;
import java.util.Map;
import java.util.List;
+
/**
* Abstract base class for repositories that store their data
* in a database-related structure.
*
*
- * Extends {@link Repository} and specifies that the content
- * is stored as a {@link Map}.
+ * Extends {@link Repository} and specifies that the content
+ * is stored as a {@link Map}.
*
*/
public abstract class DBRepository extends Repository {
protected final Map contentLock;
+
/**
* Constructs a DBRepository with the given content.
*
@@ -23,19 +26,18 @@ protected DBRepository(Map content) {
this.contentLock = new HashMap<>();
}
- protected void updateContentLock() {
- synchronized (contentLock) {
- contentLock.clear();
- contentLock.putAll(this.content);
- }
- }
+ protected abstract void updateContentLock();
public abstract boolean addContent(V value);
/**
- * Exports the repository content as a list of Object arrays, where each array represents a row of data.
- * This method is intended for converting the repository content into a format suitable for database storage or export.
- * @return a List of Object arrays representing the repository content for database export
+ * Exports the repository content as a list of Object arrays, where each array
+ * represents a row of data.
+ * This method is intended for converting the repository content into a format
+ * suitable for database storage or export.
+ *
+ * @return a List of Object arrays representing the repository content for
+ * database export
*/
public abstract List