Skip to content

Commit

Permalink
Merge pull request #59 from cathrkri/46-mvp-webscrabing-av-innsamling…
Browse files Browse the repository at this point in the history
…skontrollen-for-description

Merged issue 46 with develop
  • Loading branch information
roaraf authored Apr 8, 2026
2 parents 9157331 + 72c77e3 commit 12f46bc
Show file tree
Hide file tree
Showing 8 changed files with 553 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.DonationRegistry;
import ntnu.systemutvikling.team6.scraper.APICharityData;
import ntnu.systemutvikling.team6.scraper.URLCharityScraper;

/**
* Manages the Database with MySQL tables and JDBC.
Expand Down Expand Up @@ -74,6 +75,10 @@ charity_name VARCHAR(255) NOT NULL,
charity_link VARCHAR(255) NOT NULL,
pre_approved TINYINT NOT NULL,
status VARCHAR(255) NOT NULL,
description TEXT,
logoURL TEXT,
categories TEXT,
key_values TEXT,
UNIQUE KEY unique_org_number (org_number)
) ENGINE=InnoDB;
Expand Down Expand Up @@ -127,13 +132,17 @@ public void addAPIDataToTable(List<Charity> charities) {
conn.setAutoCommit(false);
String sql_query =
"""
INSERT INTO Charities (UUID_charities, org_number, charity_name, charity_link, pre_approved, status)
VALUES (?, ?, ?, ?, ?, ?)
INSERT INTO Charities (UUID_charities, org_number, charity_name, charity_link, pre_approved, status, description, logoURL, categories, key_values)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
charity_name = VALUES(charity_name),
charity_link = VALUES(charity_link),
pre_approved = VALUES(pre_approved),
status = VALUES(status)
status = VALUES(status),
description = VALUES(description),
logoURL = VALUES(logoURL),
categories = VALUES(categories),
key_values = VALUES(key_values)
""";

try (PreparedStatement ps = conn.prepareStatement(sql_query)) {
Expand All @@ -143,12 +152,24 @@ INSERT INTO Charities (UUID_charities, org_number, charity_name, charity_link, p
} else {
ps.setString(1, charity.getUUID().toString());
}
// Scrapes description, logo, categories, and key values from IK
URLCharityScraper urlScraper = new URLCharityScraper(charity.getURL());
urlScraper.scrapeCharityPage();

charity.setDescription(urlScraper.getDescription());
charity.setCategory(urlScraper.getCategories());
charity.setLogoURL(urlScraper.getLogoURL());
charity.setKeyValues(urlScraper.getKeyValues());

ps.setString(2, charity.getOrg_number().replaceAll("\\s", ""));
ps.setString(3, charity.getName());
ps.setString(4, charity.getDescription());
ps.setBoolean(5, charity.getPreApproved()); // Description is the link
ps.setString(4, charity.getURL());
ps.setBoolean(5, charity.getPreApproved());
ps.setString(6, charity.getStatus());
ps.setString(7, charity.getDescription());
ps.setString(8, charity.getLogoURL());
ps.setString(9, charity.getCategory());
ps.setString(10, charity.getKeyValues());

ps.addBatch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class Charity {
/* Name of the charity */
private String name;

/* Description of the charity's mission and activities */
private String description;
/* URL of the charity */
private String url;

/* Is the charity verified? */
private String status;
Expand All @@ -31,6 +31,15 @@ public class Charity {
/* Category for the charity */
private String category;

/* Description for the charity */
private String description;

/* URL for the logo of the charity */
private String logoURL;

/* Key values for the charity */
private String keyValues;

/* List that contains the charity's Feedbacks */
private List<Feedback> feedbacks;

Expand All @@ -48,7 +57,7 @@ public Charity(
this.UUID = java.util.UUID.randomUUID();
this.org_number = org_number.replaceAll("\\s", "");
this.name = name;
this.description = "Les mer her: " + link;
this.url = link;
this.is_pre_approved = is_pre_approved;
this.status = status;
this.feedbacks = new ArrayList<>();
Expand All @@ -74,11 +83,14 @@ public Charity(
this.UUID = UUID.fromString(uuid);
this.org_number = org_number.replaceAll("\\s", "");
this.name = name;
this.description = link;
this.url = link;
this.is_pre_approved = is_pre_approved;
this.status = status;
this.feedbacks = new ArrayList<>();
this.category = "";
this.description = "";
this.logoURL = "";
this.keyValues = "";
this.feedbacks = new ArrayList<>();
}

/** Getters for the charity's attributes. */
Expand Down Expand Up @@ -110,8 +122,20 @@ public String getName() {
return name;
}

public String getURL() {
return this.url;
}

public String getDescription() {
return description;
return this.description;
}

public String getLogoURL() {
return this.logoURL;
}

public String getKeyValues() {
return this.keyValues;
}

/** Setter for verification status. This one sets the charity as verified. */
Expand All @@ -123,4 +147,24 @@ public void setVerified() {
public void setUnverified() {
this.status = "Veto";
}

/** Setter for categories. */
public void setCategory(String category) {
this.category = category;
}

/** Setter for description. */
public void setDescription(String description) {
this.description = description;
}

/** Setter for the URL of the charity's logo. */
public void setLogoURL(String url) {
this.logoURL = url;
}

/** Setter for the charity's key values. */
public void setKeyValues(String values) {
this.keyValues = values;
}
}
Loading

0 comments on commit 12f46bc

Please sign in to comment.