Skip to content

Commit

Permalink
Clean-up code and add comments to queryUrl section in 'findDataPids' …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
doulikecookiedough committed Oct 26, 2024
1 parent ea5dd09 commit dcd0551
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/edu/ucsb/nceas/mdqengine/MDQEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,19 @@ public ArrayList<String> findDataPids(NodeReference nodeId, String identifier) t
}

try {
// String together the solr query URL to grab the data pids
String nodeEndpoint = D1Client.getMN(nodeId).getNodeBaseServiceUrl();
String encodedId = URLEncoder.encode(identifier, "UTF-8");
// This is necessary for metacat's solr to process the requested queryUrl
String encodedQuotes = URLEncoder.encode("\"", "UTF-8");
// String queryUrl = nodeEndpoint + "/query/solr/?q=isDocumentedBy:" + "\"" + encodedId + "\"" + "&fl=id";
String queryUrl = nodeEndpoint + "/query/solr/?q=isDocumentedBy:" + encodedQuotes + encodedId + encodedQuotes + "&fl=id";
// The quotations wrapping the identifier are necessary for solr to parse the request
String valueToEncode = "\"" + identifier + "\"";
String encodedId = URLEncoder.encode(valueToEncode, "UTF-8");
String queryUrl = nodeEndpoint + "/query/solr/?q=isDocumentedBy:" + encodedId + "&fl=id";
log.debug("queryURL: " + queryUrl);

URL url = new URL(queryUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
// A user-agent is necessary otherwise we will get a http 403 forbidden error
connection.setRequestProperty("User-Agent", "MetadigEngine/feature-hashstore-support");
if (dataOneAuthToken != null) {
connection.setRequestProperty("Authorization", "Bearer " + dataOneAuthToken);
Expand Down

0 comments on commit dcd0551

Please sign in to comment.