Skip to content

Commit

Permalink
Maven: maven fmt:format method, also deleted databaseManagerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 13, 2026
1 parent ff29284 commit d400748
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import ntnu.systemutvikling.team6.models.user.User;

/**
* This class is responsible for sending concurrent information about the user to the User
* database, and user settings to the settings database.
* This class is responsible for sending concurrent information about the user to the User database,
* and user settings to the settings database.
*
* @author Robin Strand Prestmo
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.models.registry.DonationRegistry;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ FOREIGN KEY (`User_UUID_User`)
ENGINE = InnoDB;
""";
String charityVanityTable =
"""
"""
CREATE TABLE IF NOT EXISTS `apbaluna`.`Charities` (
`UUID_charities` CHAR(36) NOT NULL,
`org_number` VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.models.Feedback;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.models.user.User;

/**
Expand Down Expand Up @@ -38,10 +37,11 @@ public CharitySelect(DatabaseConnection connection) {
* who submitted each piece of feedback.
*
* <p>The query performs a LEFT JOIN between the {@code Charities}, {@code Feedback}, {@code
* User}, {@code CharityVanity}, and {@code category(s)} tables. Each unique charity is added once to the registry; any feedback rows found for
* that charity are appended to its feedback list.
* User}, {@code CharityVanity}, and {@code category(s)} tables. Each unique charity is added once
* to the registry; any feedback rows found for that charity are appended to its feedback list.
*
* <p>Note: charities with no feedback and categories are still included in the result due to the LEFT JOIN.
* <p>Note: charities with no feedback and categories are still included in the result due to the
* LEFT JOIN.
*
* @return a {@link CharityRegistry} containing all charities found in the database, each
* populated with its associated {@link Feedback} objects (if any)
Expand Down Expand Up @@ -91,15 +91,14 @@ public CharityRegistry getCharitiesFromDB() {
rs.getString("description"),
rs.getString("logoURL"),
rs.getString("keyValues"),
rs.getBytes("logoBLOB")
);
rs.getBytes("logoBLOB"));
registry.addCharity(currentCharity);
lastCharity = currentId;
seenFeedbackIds.clear();
}

String categoryName = rs.getString("category");
if (categoryName != null & !currentCharity.getCategory().contains(categoryName)){
if (categoryName != null & !currentCharity.getCategory().contains(categoryName)) {
currentCharity.getCategory().add(categoryName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ public Charity(
}

/**
* Contructor for creating a new charity. Taylored to match data given from DATABASE.
* Expects paramaters that will fill all attributes. EXECPT for feedbacks and categories.
* Contructor for creating a new charity. Taylored to match data given from DATABASE. Expects
* paramaters that will fill all attributes. EXECPT for feedbacks and categories.
*
* @param org_number matches from innsamlingkontrollen
* @param name matches from innsamlingkontrollen
* @param is_pre_approved name matches from innsamlingkontrollen
* @param status name matches from innsamlingkontrollen
*/
public Charity(String uuid,
public Charity(
String uuid,
String org_number,
String name,
String url,
Expand Down Expand Up @@ -146,7 +147,7 @@ public String getKeyValues() {
}

public byte[] getLogoBlob() {
return this.logoBlob;
return this.logoBlob;
}

/** Setter for verification status. This one sets the charity as verified. */
Expand Down Expand Up @@ -179,15 +180,13 @@ public void setKeyValues(String values) {
this.keyValues = values;
}

/** Setter for the charity's logo Blob. */
/** Setter for the charity's logo Blob. */
public void setLogoBlob(byte[] logoBlob) {
this.logoBlob = logoBlob;
this.logoBlob = logoBlob;
}

/**
* Setter for
*/
public void setFeedbacks(ArrayList<Feedback> feedbacks){
/** Setter for setting feedbacks */
public void setFeedbacks(ArrayList<Feedback> feedbacks) {
this.feedbacks = feedbacks;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ntnu.systemutvikling.team6.models.registry;

import ntnu.systemutvikling.team6.models.Charity;

import java.util.*;
import ntnu.systemutvikling.team6.models.Charity;

public class CharityRegistry {
private final List<Charity> charities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ntnu.systemutvikling.team6.models.registry;

import ntnu.systemutvikling.team6.models.Donation;

import java.util.*;
import ntnu.systemutvikling.team6.models.Donation;

public class DonationRegistry {
private final List<Donation> donations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
package ntnu.systemutvikling.team6.scraper;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.scraper.scraperComponents.APICharityScraper;
import ntnu.systemutvikling.team6.scraper.scraperComponents.URLCharityScraper;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.http.HttpClient;

public class FullCharityScrape {
private APICharityScraper apiScraper;
private APICharityScraper apiScraper;

public FullCharityScrape() throws URISyntaxException {
HttpClient https = HttpClient.newHttpClient();
this.apiScraper = new APICharityScraper(https);
}
public FullCharityScrape() throws URISyntaxException {
HttpClient https = HttpClient.newHttpClient();
this.apiScraper = new APICharityScraper(https);
}

public CharityRegistry getAPIAndURLCharityData() throws IOException, InterruptedException {
CharityRegistry charityRegistry = null;
if (apiScraper.checkConnection()) {
charityRegistry = apiScraper.parseJSON(apiScraper.getJSONData());
for (Charity charity : charityRegistry.getAllCharities()) {
System.out.println(charity.getName());
}
// Scrapes description, logo, categories, and key values from IK
int charityCounter = 0;
for (Charity charity : charityRegistry.getAllCharities()) {
charityCounter++;
public CharityRegistry getAPIAndURLCharityData() throws IOException, InterruptedException {
CharityRegistry charityRegistry = null;
if (apiScraper.checkConnection()) {
charityRegistry = apiScraper.parseJSON(apiScraper.getJSONData());
for (Charity charity : charityRegistry.getAllCharities()) {
System.out.println(charity.getName());
}
// Scrapes description, logo, categories, and key values from IK
int charityCounter = 0;
for (Charity charity : charityRegistry.getAllCharities()) {
charityCounter++;

System.out.println("Scraping charity vanity details: " + charityCounter + " of " + charityRegistry.getAllCharities().size());
URLCharityScraper urlScraper = new URLCharityScraper(charity.getURL());
urlScraper.scrapeCharityPage();
System.out.println(
"Scraping charity vanity details: "
+ charityCounter
+ " of "
+ charityRegistry.getAllCharities().size());
URLCharityScraper urlScraper = new URLCharityScraper(charity.getURL());
urlScraper.scrapeCharityPage();

charity.setDescription(urlScraper.getDescription());
charity.setCategory(urlScraper.getCategories());
charity.setLogoURL(urlScraper.getLogoURL());
charity.setKeyValues(urlScraper.getKeyValues());
byte[] logoBlob = LogoDownloader.downloadImageAsBlob(charity.getLogoURL());
charity.setLogoBlob(logoBlob);
}
}
return charityRegistry;
charity.setDescription(urlScraper.getDescription());
charity.setCategory(urlScraper.getCategories());
charity.setLogoURL(urlScraper.getLogoURL());
charity.setKeyValues(urlScraper.getKeyValues());
byte[] logoBlob = LogoDownloader.downloadImageAsBlob(charity.getLogoURL());
charity.setLogoBlob(logoBlob);
}
}
return charityRegistry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static byte[] downloadImageAsBlob(String imageUrl) {
* @param fileName the filename of the .png image file
*/
public static void convertBlobToPNG(byte[] imageBytes, String fileName) {
if (imageBytes == null) {
return;
}
if (imageBytes == null) {
return;
}
try {
Path folder = Paths.get("target", "logo");
Files.createDirectories(folder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ public String getLogoURL() {
*
* @return a String of strings containing the categories for the charity
*/
public String getCategories() {
public List<String> getCategories() {
/*
StringBuilder categoriesString = new StringBuilder();
for (int i = 0; i < this.categories.size(); i++) {
Expand All @@ -265,7 +266,8 @@ public String getCategories() {
categoriesString.append(",");
}
}
return categoriesString.toString();
*/
return categories;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class APIToDatabaseService {
private final DatabaseConnection connection;

/**
* Contractor for APIToDatabaseService. It uses a DatabaseConnection object that contains a connection
* credentials.
* Contractor for APIToDatabaseService. It uses a DatabaseConnection object that contains a
* connection credentials.
*
* @param connection
*/
Expand All @@ -23,14 +23,14 @@ public APIToDatabaseService(DatabaseConnection connection) {

/**
* This method is used to verify the integrity of the data in the {@code charities} table and to
* update it based on the data retrieved from the IK API and the charity's URL.
* The param charities are retrieved from
* the IK API through the APICharityData class. Called in initialize method in
* HmHApplication.java, which is the main class of the application, to ensure that the data is up
* to date when the application starts. Uses a temp table to ensure that the data in the database
* is consistent with the data from the API.
* update it based on the data retrieved from the IK API and the charity's URL. The param
* charities are retrieved from the IK API through the APICharityData class. Called in initialize
* method in HmHApplication.java, which is the main class of the application, to ensure that the
* data is up to date when the application starts. Uses a temp table to ensure that the data in
* the database is consistent with the data from the API.
*
* <p>Uses a URLScraper object to get data not contained in the API, and static methods from
* LogoDownloader to get the charity's logo as a blob.</p>
* LogoDownloader to get the charity's logo as a blob.
*
* @param charities a list of {@code Charity} objects to add to the database
*/
Expand All @@ -41,13 +41,13 @@ public void addAPIDataToTable(List<Charity> charities) {
conn = connection.getMySqlConnection();
conn.setAutoCommit(false);
String sql_query =
"""
"""
INSERT INTO Charities (UUID_charities, org_number, pre_approved, status)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
pre_approved = VALUES(pre_approved),
status = VALUES(status);
INSERT INTO CharityVanity (UUID_charity, charity_name, charity_link, description, logoURL, key_values, logoBlob)
VALUES (?, ?, ?, ?, ?, ?, ?,)
ON DUPLICATE KEY UPDATE
Expand All @@ -68,7 +68,6 @@ INSERT INTO CharityVanity (UUID_charity, charity_name, charity_link, description
} else {
ps.setString(1, charity.getUUID().toString());
ps.setString(5, charity.getUUID().toString());

}
// Charity
ps.setString(2, charity.getOrg_number().replaceAll("\\s", ""));
Expand Down
Loading

0 comments on commit d400748

Please sign in to comment.