use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class Api12MembersTest method personUpdateTest.
@Test
public void personUpdateTest() throws InterruptedException, JSONException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String giveName = getUser1GivenName();
String familyName = getUser1FamilyNames();
String creditName = getUser1CreditName();
String accessToken = getAccessToken(userId, password, Arrays.asList("/person/update", "/orcid-bio/read-limited"), clientId, clientSecret, clientRedirectUri, true);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
OrcidBio orcidBio = new OrcidBio();
PersonalDetails personalDetails = new PersonalDetails();
personalDetails.setGivenNames(new GivenNames("My given name"));
personalDetails.setFamilyName(new FamilyName("My family name"));
CreditName creditNameElement = new CreditName("My credit name");
creditNameElement.setVisibility(Visibility.LIMITED);
personalDetails.setCreditName(creditNameElement);
orcidBio.setPersonalDetails(personalDetails);
orcidProfile.setOrcidBio(orcidBio);
ClientResponse clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
ClientResponse response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
OrcidMessage orcidMessageWithBio = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithBio);
assertNotNull(orcidMessageWithBio.getOrcidProfile());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames());
assertEquals("My given name", orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName());
assertEquals("My family name", orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName());
assertEquals("My credit name", orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getContent());
assertEquals(Visibility.LIMITED, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getVisibility());
//Rollback changes
orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidBio = new OrcidBio();
personalDetails = new PersonalDetails();
personalDetails.setGivenNames(new GivenNames(giveName));
personalDetails.setFamilyName(new FamilyName(familyName));
creditNameElement = new CreditName(creditName);
creditNameElement.setVisibility(Visibility.PUBLIC);
personalDetails.setCreditName(creditNameElement);
orcidBio.setPersonalDetails(personalDetails);
orcidProfile.setOrcidBio(orcidBio);
clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
orcidMessageWithBio = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithBio);
assertNotNull(orcidMessageWithBio.getOrcidProfile());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames());
assertEquals(giveName, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName());
assertEquals(familyName, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName());
assertEquals(creditName, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getContent());
assertEquals(Visibility.PUBLIC, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getVisibility());
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class EmailsTest method cantUpdateEmailsTest.
/**
* Test update email for a specific user
* */
@Test
public void cantUpdateEmailsTest() throws JSONException, InterruptedException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String originalEmail = getUser1UserName();
String password = getUser1Password();
String accessToken = getAccessToken(userId, password, Arrays.asList("/orcid-bio/update"), clientId, clientSecret, clientRedirectUri, true);
long time = System.currentTimeMillis();
String updatedEmail = time + "@update.com";
ContactDetails contactDetails = new ContactDetails();
contactDetails.getEmail().add(new Email(updatedEmail));
OrcidBio orcidBio = new OrcidBio();
orcidBio.setContactDetails(contactDetails);
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setType(OrcidType.USER);
orcidProfile.setOrcidBio(orcidBio);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2");
orcidMessage.setOrcidProfile(orcidProfile);
ClientResponse clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
clientResponse = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertEquals(200, clientResponse.getStatus());
OrcidMessage result = clientResponse.getEntity(OrcidMessage.class);
// Check returning message
assertNotNull(result);
assertNotNull(result.getOrcidProfile());
assertNotNull(result.getOrcidProfile().getOrcidBio());
assertNotNull(result.getOrcidProfile().getOrcidBio().getContactDetails());
assertNotNull(result.getOrcidProfile().getOrcidBio().getContactDetails().getEmail());
boolean haveOriginalEmail = false;
for (Email email : result.getOrcidProfile().getOrcidBio().getContactDetails().getEmail()) {
assertFalse(email.getValue().equals(updatedEmail));
if (email.getValue().equals(originalEmail)) {
haveOriginalEmail = true;
}
}
assertTrue(haveOriginalEmail);
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class RegistrationControllerTest method createBasicProfile.
protected OrcidProfile createBasicProfile() {
OrcidProfile profile = new OrcidProfile();
profile.setPassword("password");
profile.setVerificationCode("1234");
profile.setSecurityQuestionAnswer("random answer");
OrcidBio bio = new OrcidBio();
ContactDetails contactDetails = new ContactDetails();
contactDetails.addOrReplacePrimaryEmail(new Email("will@semantico.com"));
bio.setContactDetails(contactDetails);
profile.setOrcidBio(bio);
PersonalDetails personalDetails = new PersonalDetails();
bio.setPersonalDetails(personalDetails);
personalDetails.setGivenNames(new GivenNames("Will"));
personalDetails.setFamilyName(new FamilyName("Simpson"));
bio.setBiography(new Biography("Will is a software developer"));
ResearcherUrls researcherUrls = new ResearcherUrls();
bio.setResearcherUrls(researcherUrls);
researcherUrls.getResearcherUrl().add(new ResearcherUrl(new Url("http://www.wjrs.co.uk"), null));
OrcidWorks orcidWorks = new OrcidWorks();
profile.setOrcidWorks(orcidWorks);
return profile;
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class VisibilityFilterImplTest method testOrcidMessageWithNullOrcidProfile.
@Test
public void testOrcidMessageWithNullOrcidProfile() throws JAXBException {
OrcidMessage orcidMessage = getOrcidMessage("/orcid-search-result-message.xml");
OrcidMessage filteredMessage = visibilityFilter.filter(orcidMessage, Visibility.PUBLIC);
assertNotNull(filteredMessage);
assertNull(filteredMessage.getOrcidProfile());
assertEquals(2, filteredMessage.getOrcidSearchResults().getNumFound());
for (int i = 0; i < filteredMessage.getOrcidSearchResults().getNumFound(); i++) {
OrcidSearchResult searchResult = filteredMessage.getOrcidSearchResults().getOrcidSearchResult().get(i);
OrcidBio orcidBio = searchResult.getOrcidProfile().getOrcidBio();
// check private emails stripped out
assertEquals(1, orcidBio.getContactDetails().getEmail().size());
}
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method addSourceToEmails.
/**
* Preserves existing source for existing emails, and adds specified source
* for new emails
*
* @param orcidProfile
* The incoming profile
* @param existingProfileEntity
* The existing profile entity from the DB
* @param amenderOrcid
* The source of new emails (from the security context)
*/
private void addSourceToEmails(OrcidProfile orcidProfile, ProfileEntity existingProfileEntity, String amenderOrcid) {
Map<String, EmailEntity> existingMap = new HashMap<>();
Set<EmailEntity> existingEmails = existingProfileEntity.getEmails();
if (existingEmails != null) {
existingMap = EmailEntity.mapByLowerCaseEmail(existingEmails);
}
OrcidBio orcidBio = orcidProfile.getOrcidBio();
if (orcidBio != null) {
ContactDetails contactDetails = orcidBio.getContactDetails();
if (contactDetails != null) {
for (Email email : contactDetails.getEmail()) {
EmailEntity existingEmail = existingMap.get(email.getValue().toLowerCase());
if (existingEmail == null) {
if (OrcidStringUtils.isValidOrcid(amenderOrcid)) {
email.setSourceClientId(amenderOrcid);
} else {
email.setSource(amenderOrcid);
}
} else {
email.setSource(existingEmail.getSourceId());
email.setSourceClientId(existingEmail.getClientSourceId());
}
}
}
}
}
Aggregations