Skip to content

Commit

Permalink
Feat: Updated and added JavaDoc for API object and scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 15, 2026
1 parent 7daf841 commit facf2fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Represents data parsed from the IK API JSON response. Instances are immutable; to update any
* value, a new object must be created.
*
* <p>Receives data directly from {@link APICharityScraper} or {@link IKOrganizationScraper}.
* <p>Receives data directly from {@link APICharityScraper}.
*
* <p>{@code org_number} should be a unique number, as it is used as a primary key in {@link
* DatabaseManager}.
Expand All @@ -20,6 +20,7 @@ public class APICharityData {

/**
* Constructs a new APICharityData object.
* This class represents the data provided from the IK Api, and is used expand and provide data to our design of a charity.
*
* @param org_number a unique number that identifies the organization
* @param name the name of the organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,22 @@ public String getJSONData() throws IOException, InterruptedException {
}

/**
* Parses the JSON data using gson and creates a list of APICharityData objects.
* Parses the JSON data using gson and translates the {@code APICharityData} into our predefined charity classes
* and puts it in a CharityRegistry object.
*
*
* @param JSONData the {@code String} of JSON data to be parsed
* @return a list of APICharityDaya objects
* @return a CharityRegistry class object
* @throws com.google.gson.JsonSyntaxException if the provided JSON is not valid
*/
// public List<APICharityData> parseJSON(String JSONData) {
public CharityRegistry parseJSON(String JSONData) {
Gson gson = new Gson();
APICharityData[] charityData = gson.fromJson(JSONData, APICharityData[].class);

if (charityData == null) {
// return new ArrayList<>();
return new CharityRegistry();
}

// Filters out "obs" status due to non-unique org_number values
/*
return Arrays.stream(charityData)
.filter(c-> !"obs".equalsIgnoreCase(c.getStatus()))
.toList();
*/

// Alternate using predefiend Charity class
CharityRegistry charityRegistry = new CharityRegistry();
for (APICharityData apiCharityData : charityData) {
Charity charity =
Expand All @@ -102,20 +93,4 @@ public CharityRegistry parseJSON(String JSONData) {
}
return charityRegistry;
}
/**
* Synchronizes the {@code charities} table with the provided list of APICharityData.
*
* <p>Summary of function:
*
* <ul>
* <li>Inserts new records
* <li>Updates existing records using {@code ON DUPLICATE KEY UPDATE}
* <li>Removes database records that are not present in the provided list
* </ul>
*
* A temporary table is used to determine which records should be deleted.
*
* @param charities a list of ApiCharityDaya objects
* @throws RuntimeException if a {@link SQLException} occurs during database synchronization
*/
}

0 comments on commit facf2fc

Please sign in to comment.