From 9cb3206d33d76bdde7eb8a95f613fac2c01abb97 Mon Sep 17 00:00:00 2001 From: Roar Date: Wed, 4 Mar 2026 20:45:46 +0100 Subject: [PATCH] Updated APICharityData Added javadoc descriptions, throws an exception if org_number is invalid, and automatically normalizes the value of org_number. --- .../team6/models/APICharityData.java | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/APICharityData.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/APICharityData.java index d94db88..10f3acf 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/APICharityData.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/APICharityData.java @@ -1,5 +1,17 @@ package ntnu.sytemutvikling.team6.models; +/** + * Represents data parsed from the IK API JSON response. + * Instances are immutable; to update any value, a new object must be created. + *

+ * Receives data directly from {@link APICharityScraper} or {@link IKOrganizationScraper}. + *

+ *

+ * {@code org_number} should be a unique number, as it is used as a primary key + * in {@link DatabaseManager}. + *

+ */ + public class APICharityData { private final String org_number; private final String name; @@ -7,30 +19,73 @@ public class APICharityData { private final String url; private final boolean is_pre_approved; + /** + * Constructs a new APICharityData object. + * @param org_number a unique number that identifies the organization + * @param name the name of the organization + * @param status {@code approved} for approved organizations, + * {@code obs} for non-approved organizations + * @param url the URL for more info about the organization on the IK domain + * @param is_pre_approved whether the organization was pre-approved + */ + public APICharityData(String org_number, String name, String status, String url, boolean is_pre_approved) { - this.org_number = org_number; + if (org_number == null || org_number.isBlank()) { + throw new IllegalArgumentException("ERROR: Org number cannot be null or blank"); + } + this.org_number = org_number.replaceAll("\\s", ""); this.name = name; this.status = status; this.url = url; this.is_pre_approved = is_pre_approved; } + /** + * Returns the organization number. Must not be {@code null} or blank. + * + * @return the organization number + */ + public String getOrg_number() { return this.org_number; } + /** + * Returns the name of the organization. Whitespace removed. + * + * @return the name of the organization + */ + public String getName() { return name; } + /** + * Returns whether the organization is approved or not + * @return the approved status of the organization + */ + public String getStatus() { return status; } + /** + * Returns the URL of the organizations information page on IK + * + * @return the URL for more info about the organization + */ + public String getUrl() { return url; } + /** + * Returns whether the organization was pre-approved. + * + * @return {@code true} if organization was pre-approved
+ * {@code false} otherwise + */ + public boolean getIs_pre_approved() { return this.is_pre_approved; }