36 |
36 |
*/
|
37 |
37 |
public static String lookupOrcid(String surName, String[] givenNames, String[] otherNames) {
|
38 |
38 |
|
|
39 |
String url = null;
|
|
40 |
|
39 |
41 |
try {
|
40 |
42 |
|
41 |
43 |
String urlParameters = "";
|
42 |
44 |
if (surName != null) {
|
43 |
|
surName = surName.replaceAll(" ", "%20");
|
|
45 |
// surName = surName.replaceAll(" ", "%20");
|
44 |
46 |
urlParameters += "+family-name:\"" + surName + "\"";
|
45 |
47 |
}
|
46 |
48 |
if (otherNames != null) {
|
47 |
49 |
for (String otherName: otherNames) {
|
48 |
|
otherName = otherName.replaceAll(" ", "%20");
|
|
50 |
// otherName = otherName.replaceAll(" ", "%20");
|
49 |
51 |
urlParameters += "+other-names:\"" + otherName + "\"";
|
50 |
52 |
}
|
51 |
53 |
}
|
52 |
54 |
if (givenNames != null) {
|
53 |
55 |
for (String givenName: givenNames) {
|
54 |
|
givenName = givenName.replaceAll(" ", "%20");
|
|
56 |
// givenName = givenName.replaceAll(" ", "%20");
|
55 |
57 |
urlParameters += "+given-names:\"" + givenName + "\"";
|
56 |
58 |
}
|
57 |
59 |
}
|
58 |
60 |
|
59 |
|
//urlParameters = URLEncoder.encode(urlParameters, "UTF-8");
|
|
61 |
urlParameters = URLEncoder.encode(urlParameters, "UTF-8");
|
60 |
62 |
|
61 |
|
String url = REST_URL + "?q=" + urlParameters + "&rows=1";
|
|
63 |
url = REST_URL + "?q=" + urlParameters + "&rows=1";
|
62 |
64 |
URL restURL = new URL(url);
|
63 |
65 |
InputStream is = restURL.openStream();
|
64 |
66 |
String results = IOUtils.toString(is);
|
65 |
67 |
logMetacat.debug("RESULTS: " + results);
|
66 |
68 |
Node doc = XMLUtilities.getXMLReaderAsDOMTreeRootNode(new StringReader(results));
|
67 |
|
Node orcidUriNodeList = XMLUtilities.getNodeWithXPath(doc, "//*[local-name()=\"uri\"]");
|
|
69 |
Node orcidUriNodeList = XMLUtilities.getNodeWithXPath(doc, "//*[local-name()=\"orcid-identifier\"]/*[local-name()=\"uri\"]");
|
68 |
70 |
if (orcidUriNodeList != null) {
|
69 |
71 |
String orcidUri = orcidUriNodeList.getFirstChild().getNodeValue();
|
70 |
72 |
logMetacat.info("Found ORCID URI: " + orcidUri);
|
71 |
73 |
return orcidUri;
|
72 |
74 |
}
|
73 |
75 |
} catch (Exception e) {
|
74 |
|
logMetacat.error("Could not lookup ORCID for surName=" + surName, e);
|
|
76 |
logMetacat.error("Could not lookup ORCID using: " + url, e);
|
75 |
77 |
}
|
76 |
78 |
|
77 |
79 |
return null;
|
adjust tests for production service -- more "real" information shows additional return values from the query.