Skip to content

Commit

Permalink
get affiliation from ORCID response #3338
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Dec 13, 2016
1 parent 33387dd commit 0ebed7b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ protected ParsedUserResponse parseUserResponse(String responseBody) {
String familyName = getNodes(doc, "orcid-message", "orcid-profile", "orcid-bio", "personal-details", "family-name" )
.stream().findFirst().map( Node::getTextContent )
.map( String::trim ).orElse("");
String affiliation = getNodes(doc, "orcid-message", "orcid-profile", "orcid-activities", "affiliations", "affiliation", "organization", "name" )
.stream().findFirst().map( Node::getTextContent )
.map( String::trim ).orElse("");
List<String> emails = new ArrayList<>();
getNodes(doc, "orcid-message", "orcid-profile", "orcid-bio","contact-details","email").forEach( n ->{
String email = n.getTextContent().trim();
Expand All @@ -98,7 +101,7 @@ protected ParsedUserResponse parseUserResponse(String responseBody) {
}

final ParsedUserResponse userResponse = new ParsedUserResponse(
new AuthenticatedUserDisplayInfo(firstName, familyName, primaryEmail, "", ""), orcidId, username);
new AuthenticatedUserDisplayInfo(firstName, familyName, primaryEmail, affiliation, ""), orcidId, username);
userResponse.emails.addAll(emails);

return userResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package edu.harvard.iq.dataverse.authorization.providers.oauth2.impl;

import edu.harvard.iq.dataverse.authorization.providers.oauth2.AbstractOAuth2AuthenticationProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

Expand Down Expand Up @@ -45,6 +47,66 @@ public class OrcidOAuth2APTest extends OrcidOAuth2AP {
+ " </orcid-profile>\n"
+ "</orcid-message>";

private final String NO_EMAIL_HAS_AFFILIATION = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
+ "<orcid-message xmlns=\"http://www.orcid.org/ns/orcid\">\n"
+ " <message-version>1.2</message-version>\n"
+ " <orcid-profile type=\"user\">\n"
+ " <orcid-identifier>\n"
+ " <uri>http://orcid.org/0000-0002-3283-0661</uri>\n"
+ " <path>0000-0002-3283-0661</path>\n"
+ " <host>orcid.org</host>\n"
+ " </orcid-identifier>\n"
+ " <orcid-preferences>\n"
+ " <locale>en</locale>\n"
+ " </orcid-preferences>\n"
+ " <orcid-history>\n"
+ " <creation-method>Direct</creation-method>\n"
+ " <submission-date>2015-11-30T23:14:04.260Z</submission-date>\n"
+ " <last-modified-date>2016-12-13T19:45:57.958Z</last-modified-date>\n"
+ " <claimed>true</claimed>\n"
+ " <verified-email>true</verified-email>\n"
+ " <verified-primary-email>true</verified-primary-email>\n"
+ " </orcid-history>\n"
+ " <orcid-bio>\n"
+ " <personal-details>\n"
+ " <given-names>Pete K.</given-names>\n"
+ " <family-name>Dataversky</family-name>\n"
+ " </personal-details>\n"
+ " </orcid-bio>\n"
+ " <orcid-activities>\n"
+ " <affiliations>\n"
+ " <affiliation visibility=\"public\" put-code=\"1378745\">\n"
+ " <type>employment</type>\n"
+ " <department-name>BCMP</department-name>\n"
+ " <organization>\n"
+ " <name>Harvard Medical School</name>\n"
+ " <address>\n"
+ " <city>Boston</city>\n"
+ " <region>MA</region>\n"
+ " <country>US</country>\n"
+ " </address>\n"
+ " <disambiguated-organization>\n"
+ " <disambiguated-organization-identifier>1811</disambiguated-organization-identifier>\n"
+ " <disambiguation-source>RINGGOLD</disambiguation-source>\n"
+ " </disambiguated-organization>\n"
+ " </organization>\n"
+ " <source>\n"
+ " <source-orcid>\n"
+ " <uri>http://orcid.org/0000-0002-3283-0661</uri>\n"
+ " <path>0000-0002-3283-0661</path>\n"
+ " <host>orcid.org</host>\n"
+ " </source-orcid>\n"
+ " <source-name>Pete K. Dataversky</source-name>\n"
+ " <source-date>2015-11-30T23:18:22.764Z</source-date>\n"
+ " </source>\n"
+ " <created-date>2015-11-30T23:18:22.764Z</created-date>\n"
+ " <last-modified-date>2016-05-07T02:26:10.970Z</last-modified-date>\n"
+ " </affiliation>\n"
+ " </affiliations>\n"
+ " </orcid-activities>\n"
+ " </orcid-profile>\n"
+ "</orcid-message>";

public OrcidOAuth2APTest() {
super("", "", "");
}
Expand All @@ -66,6 +128,23 @@ public void testParseUserResponse() {

}

@Test
public void testParseUserResponseNoEmailHasAffiliation() {
OrcidOAuth2AP sut = new OrcidOAuth2AP("clientId", "clientSecret", "userEndpoint");
final AbstractOAuth2AuthenticationProvider.ParsedUserResponse actual = sut.parseUserResponse(NO_EMAIL_HAS_AFFILIATION);

assertEquals("0000-0002-3283-0661", actual.userIdInProvider);
assertEquals("Pete K.", actual.displayInfo.getFirstName());
assertEquals("Dataversky", actual.displayInfo.getLastName());
assertEquals("", actual.displayInfo.getEmailAddress());
assertEquals("Harvard Medical School", actual.displayInfo.getAffiliation());
assertEquals("", actual.displayInfo.getPosition());
List<String> emptyList = new ArrayList<>();
assertEquals(emptyList, actual.emails);
assertEquals("Pete.Dataversky", actual.username);

}

@Test
public void testParseUserResponse_noEmails() {
OrcidOAuth2AP sut = new OrcidOAuth2AP("clientId", "clientSecret", "userEndpoint");
Expand Down

0 comments on commit 0ebed7b

Please sign in to comment.