Skip to content

Commit

Permalink
merged release/v2.0.0 into refactor/frontend-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
emilfa committed Mar 26, 2026
2 parents 1fc75a7 + 5db4ec6 commit 6bab090
Show file tree
Hide file tree
Showing 20 changed files with 411 additions and 120 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<version>2.2.224</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>
</dependencies>

<build>
Expand Down
53 changes: 40 additions & 13 deletions src/main/java/edu/group5/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,33 @@

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;

BorderPane root;
AppState appState;
NavigationController nav;

private Logger logger;

@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
Expand All @@ -49,20 +63,23 @@ 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);

BorderPane root = new BorderPane();
AppState appState = new AppState();
NavigationController nav = new NavigationController(root, appState, userService, donationService, organizationService);
this.root = new BorderPane();
this.appState = new AppState();
this.nav = new NavigationController(root, appState, userService, donationService, organizationService);
}

nav.showLoginPage();
@Override
public void start(Stage stage) {
this.nav.showLoginPage();

Scene scene = new Scene(root, 1280, 720);
stage.getIcons().add(new Image(getClass().getResource("/header/images/hmh-logo.png").toExternalForm()));
Expand All @@ -71,6 +88,16 @@ public void start(Stage stage) {
stage.show();
}

@Override
public void stop() throws Exception {
super.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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.group5.app.model.organization.OrganizationService;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class OrganizationController {
private final AppState appState;
Expand All @@ -24,4 +25,8 @@ public Organization getOrgById(int orgId) {
public Map<Integer, Organization> getTrustedOrgs() {
return service.getTrustedOrganizations();
}

public CompletableFuture<Map<Integer, Organization>> getOrganizationsWithLogosAsync() {
return service.getTrustedOrganizationsWithLogosAsync();
}
}
10 changes: 8 additions & 2 deletions src/main/java/edu/group5/app/control/wrapper/DbWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ public List<Object[]> importUsers() {

public int exportUsers(List<Object[]> data) {
this.importUsers();

if (data == null) {
throw new IllegalArgumentException("data can't be null");
}
if (data.isEmpty()) {
return 0;
}
if (data.get(0).length != 6) {
throw new IllegalArgumentException("data's arrays must have a length of 6");
}
Expand Down Expand Up @@ -184,10 +187,13 @@ private List<Object[]> importDonations(int user_id, boolean all) {

public int exportDonations(List<Object[]> data) {
this.fetchAllDonations();

if (data == null) {
throw new IllegalArgumentException("data can't be null");
}
if (data.isEmpty()) {
return 0;
}
if (data.get(0).length != 6) {
throw new IllegalArgumentException("data's arrays must have a length of 6");
}
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/edu/group5/app/model/DBRepository.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>
* 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}.
* </p>
*/
public abstract class DBRepository<K, V> extends Repository<K, V> {
protected final Map<K, V> contentLock;

/**
* Constructs a DBRepository with the given content.
*
Expand All @@ -23,19 +26,18 @@ protected DBRepository(Map<K, V> 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<Object[]> export();
}
Loading

0 comments on commit 6bab090

Please sign in to comment.