1 |
1 |
package edu.ucsb.nceas.metacat.annotation;
|
2 |
2 |
|
3 |
3 |
import java.io.InputStream;
|
|
4 |
import java.io.InputStreamReader;
|
4 |
5 |
import java.io.StringReader;
|
5 |
6 |
import java.net.URL;
|
6 |
7 |
import java.net.URLEncoder;
|
|
8 |
import java.util.ArrayList;
|
|
9 |
import java.util.List;
|
7 |
10 |
|
|
11 |
|
8 |
12 |
import org.apache.commons.io.IOUtils;
|
9 |
13 |
import org.apache.log4j.Logger;
|
|
14 |
import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
|
10 |
15 |
import org.w3c.dom.Node;
|
|
16 |
import org.w3c.dom.NodeList;
|
11 |
17 |
|
|
18 |
import edu.ucsb.nceas.metacat.dataone.MNodeService;
|
12 |
19 |
import edu.ucsb.nceas.utilities.XMLUtilities;
|
13 |
20 |
|
14 |
21 |
public class OrcidService {
|
15 |
22 |
|
16 |
23 |
private static Logger logMetacat = Logger.getLogger(OrcidService.class);
|
17 |
24 |
|
18 |
|
private static final String REST_URL = "http://pub.sandbox.orcid.org/v1.1/search/orcid-bio";
|
|
25 |
//private static final String REST_URL = "http://pub.sandbox.orcid.org/v1.1/search/orcid-bio";
|
|
26 |
private static final String REST_URL = "http://pub.orcid.org/v1.1/search/orcid-bio";
|
19 |
27 |
|
|
28 |
|
20 |
29 |
/**
|
21 |
30 |
* Look up possible ORCID from orcid service.
|
22 |
31 |
* @see "http://support.orcid.org/knowledgebase/articles/132354-searching-with-the-public-api"
|
... | ... | |
31 |
40 |
|
32 |
41 |
String urlParameters = "";
|
33 |
42 |
if (surName != null) {
|
|
43 |
surName = surName.replaceAll(" ", "%20");
|
34 |
44 |
urlParameters += "+family-name:\"" + surName + "\"";
|
35 |
45 |
}
|
36 |
46 |
if (otherNames != null) {
|
37 |
47 |
for (String otherName: otherNames) {
|
|
48 |
otherName = otherName.replaceAll(" ", "%20");
|
38 |
49 |
urlParameters += "+other-names:\"" + otherName + "\"";
|
39 |
50 |
}
|
40 |
51 |
}
|
41 |
52 |
if (givenNames != null) {
|
42 |
53 |
for (String givenName: givenNames) {
|
|
54 |
givenName = givenName.replaceAll(" ", "%20");
|
43 |
55 |
urlParameters += "+given-names:\"" + givenName + "\"";
|
44 |
56 |
}
|
45 |
57 |
}
|
46 |
58 |
|
47 |
|
urlParameters = URLEncoder.encode(urlParameters, "UTF-8");
|
|
59 |
//urlParameters = URLEncoder.encode(urlParameters, "UTF-8");
|
48 |
60 |
|
49 |
61 |
String url = REST_URL + "?q=" + urlParameters + "&rows=1";
|
50 |
62 |
URL restURL = new URL(url);
|
... | ... | |
64 |
76 |
|
65 |
77 |
return null;
|
66 |
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Look up indexed creators
|
|
82 |
*/
|
|
83 |
public static List<String> lookupCreators(boolean includeObsolete) {
|
|
84 |
// Search for the creators if we can find them
|
|
85 |
List<String> retList = null;
|
|
86 |
try {
|
|
87 |
String query = "q=-obsoletedBy:[* TO *]&rows=0&facet=true&facet.limit=-1&facet.field=origin";
|
|
88 |
if (includeObsolete) {
|
|
89 |
query = "q=*:*&rows=0&facet=true&facet.limit=-1&facet.field=origin";
|
|
90 |
}
|
|
91 |
|
|
92 |
MockHttpServletRequest request = new MockHttpServletRequest(null, null, null);
|
|
93 |
InputStream results = MNodeService.getInstance(request ).query("solr", query);
|
|
94 |
Node rootNode = XMLUtilities.getXMLReaderAsDOMTreeRootNode(new InputStreamReader(results, "UTF-8"));
|
|
95 |
//String resultString = XMLUtilities.getDOMTreeAsString(rootNode);
|
|
96 |
NodeList nodeList = XMLUtilities.getNodeListWithXPath(rootNode, "//lst[@name=\"origin\"]/int/@name");
|
|
97 |
if (nodeList != null && nodeList.getLength() > 0) {
|
|
98 |
retList = new ArrayList<String>();
|
|
99 |
for (int i = 0; i < nodeList.getLength(); i++) {
|
|
100 |
String found = nodeList.item(i).getFirstChild().getNodeValue();
|
|
101 |
retList.add(found);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
} catch (Exception e) {
|
|
105 |
logMetacat.error("Error checking for creators[s]: " + e.getMessage(), e);
|
|
106 |
}
|
|
107 |
|
|
108 |
return retList;
|
|
109 |
}
|
67 |
110 |
}
|
switch to the production ORCID server for looking up orcid matches for our creators.
add test to summarize how many creator matches we can actually find. https://projects.ecoinformatics.org/ecoinfo/issues/6423