Skip to content

Commit

Permalink
update removeQuery to remove fragments as well
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaAburaneh committed Dec 13, 2023
1 parent d663bf3 commit fd52e8d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/ca/gc/tbs/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void autoTag() {
}

String text = URLEncoder.encode(problem.getProblemDetails(), StandardCharsets.UTF_8.name());
String URL = removeQueryParams(problem.getUrl()).toLowerCase();
String URL = removeQueryAndFragment(problem.getUrl()).toLowerCase();

if (tier1Spreadsheet.containsKey(URL)) {
model = tier1Spreadsheet.get(URL)[0];
Expand Down Expand Up @@ -428,7 +428,7 @@ public void airTableSpreadsheetSync() {
continue;
}
String UTM_values = extractUtmValues(problem.getUrl());
problem.setUrl(removeQueryParams(problem.getUrl().toLowerCase()));
problem.setUrl(removeQueryAndFragment(problem.getUrl().toLowerCase()));

// if tier 1 and tier 2 spreadsheet don't contain URL, add it to Tier 2 and set sync to true
if (!tier1Spreadsheet.containsKey(problem.getUrl()) && !tier2Spreadsheet.contains(problem.getUrl())) {
Expand Down Expand Up @@ -543,16 +543,20 @@ public String extractUtmValues(String url) throws URISyntaxException {
}


public String removeQueryParams(String url) throws URISyntaxException {
public String removeQueryAndFragment(String url) {
try {
URIBuilder builder = new URIBuilder(url);
return builder.removeQuery().build().toString();
// Remove query and fragment
builder.clearParameters();
builder.setFragment(null);
return builder.build().toString();
} catch (Exception e) {
e.printStackTrace();
return url; // Return the original URL if there's an exception
}
}


// Sets attributes. Made it into a function to make the code look a bit more readable.
public void setAirProblemAttributes(AirTableProblemEnhanced airProblem, Problem problem) {
airProblem.setUniqueID(problem.getId());
Expand Down

0 comments on commit fd52e8d

Please sign in to comment.