Search in sources :

Example 21 with OrcidBio

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());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) FamilyName(org.orcid.jaxb.model.message.FamilyName) GivenNames(org.orcid.jaxb.model.message.GivenNames) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) CreditName(org.orcid.jaxb.model.message.CreditName) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Test(org.junit.Test)

Example 22 with OrcidBio

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);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientResponse(com.sun.jersey.api.client.ClientResponse) Email(org.orcid.jaxb.model.message.Email) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test)

Example 23 with OrcidBio

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;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Email(org.orcid.jaxb.model.message.Email) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) FamilyName(org.orcid.jaxb.model.message.FamilyName) GivenNames(org.orcid.jaxb.model.message.GivenNames) Biography(org.orcid.jaxb.model.message.Biography) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Url(org.orcid.jaxb.model.message.Url) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 24 with OrcidBio

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());
    }
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test)

Example 25 with OrcidBio

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());
                }
            }
        }
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Aggregations

OrcidBio (org.orcid.jaxb.model.message.OrcidBio)56 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)38 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)28 Test (org.junit.Test)27 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)23 Email (org.orcid.jaxb.model.message.Email)20 GivenNames (org.orcid.jaxb.model.message.GivenNames)20 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)19 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)16 FamilyName (org.orcid.jaxb.model.message.FamilyName)16 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)15 CreditName (org.orcid.jaxb.model.message.CreditName)14 BaseTest (org.orcid.core.BaseTest)13 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)11 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)11 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)10 ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)9 OtherNames (org.orcid.jaxb.model.message.OtherNames)9 Biography (org.orcid.jaxb.model.message.Biography)8 Keyword (org.orcid.jaxb.model.message.Keyword)8