Project

General

Profile

« Previous | Next » 

Revision 8776

adjust tests for production service -- more "real" information shows additional return values from the query.

View differences:

test/edu/ucsb/nceas/metacat/annotation/OrcidServiceTest.java
63 63
	}
64 64
	
65 65
	public void testLookup() {
66
		String[] otherNames = new String[] {"Matthew Jones"};
66
		String[] otherNames = new String[] {"Matthew Bentley Jones"};
67 67
		String orcid = OrcidService.lookupOrcid(null, null, otherNames);
68
		assertEquals("http://sandbox-1.orcid.org/0000-0003-2141-4459", orcid);
68
		assertEquals("http://orcid.org/0000-0003-0077-4738", orcid);
69 69
	}
70 70
	
71 71
	public void findMatches() {
src/edu/ucsb/nceas/metacat/annotation/OrcidService.java
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;

Also available in: Unified diff