Search in sources :

Example 11 with ExternalIdCommonName

use of org.orcid.jaxb.model.message.ExternalIdCommonName in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testPrimaryAddressDontChangeOnClaimedRecords.

@Test
@Transactional
@Rollback(true)
public void testPrimaryAddressDontChangeOnClaimedRecords() {
    OrcidProfile profile = createBasicProfile();
    String orcidIdentifier = null;
    profile.setOrcidIdentifier(orcidIdentifier);
    setBio(profile, Visibility.PUBLIC);
    String email = profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue();
    profile = orcidProfileManager.createOrcidProfile(profile, true, false);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidIdentifier());
    assertFalse(PojoUtil.isEmpty(profile.getOrcidIdentifier().getPath()));
    profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
    assertNotNull(profile);
    assertNotNull(profile.getOrcidBio());
    assertNotNull(profile.getOrcidBio().getBiography());
    assertEquals("This is my biography", profile.getOrcidBio().getBiography().getContent());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getBiography().getVisibility());
    assertNotNull(profile.getOrcidBio().getContactDetails());
    assertNotNull(profile.getOrcidBio().getContactDetails().getAddress());
    assertNotNull(profile.getOrcidBio().getContactDetails().getAddress().getCountry());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getVisibility());
    assertEquals(Iso3166Country.US, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
    assertNotNull(profile.getOrcidBio().getContactDetails().getEmail());
    assertEquals(1, profile.getOrcidBio().getContactDetails().getEmail().size());
    assertNotNull(profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertEquals(email, profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertNotNull(profile.getOrcidBio().getExternalIdentifiers());
    assertNotNull(profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getExternalIdentifiers().getVisibility());
    assertEquals(1, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals("common-name", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("ext-id-reference", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
    assertEquals("http://orcid.org/ext-id", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
    assertNotNull(profile.getOrcidBio().getKeywords());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getKeywords().getVisibility());
    assertEquals(1, profile.getOrcidBio().getKeywords().getKeyword().size());
    assertEquals("k1", profile.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
    assertNotNull(profile.getOrcidBio().getPersonalDetails());
    assertNotNull(profile.getOrcidBio().getPersonalDetails().getOtherNames());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
    assertEquals(1, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
    assertEquals("o1", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
    assertNotNull(profile.getOrcidBio().getResearcherUrls());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getResearcherUrls().getVisibility());
    assertEquals(1, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://orcid.org/researcher-url-1", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
    assertEquals("url-name-1", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
    ProfileEntity profileEntity = profileDao.find(profile.getOrcidIdentifier().getPath());
    assertNotNull(profileEntity);
    assertNotNull(profileEntity.getAddresses());
    assertEquals(1, profileEntity.getAddresses().size());
    assertEquals(org.orcid.jaxb.model.common_v2.Iso3166Country.US, profileEntity.getAddresses().iterator().next().getIso2Country());
    // Update all values
    profile.getOrcidBio().getBiography().setContent("This is my biography # 2");
    profile.getOrcidBio().getContactDetails().getAddress().setCountry(new Country(Iso3166Country.CR));
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setSource(null);
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdCommonName(new ExternalIdCommonName("common-name-2"));
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdReference(new ExternalIdReference("ext-id-reference-2"));
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdUrl(new ExternalIdUrl("http://orcid.org/ext-id-2"));
    profile.getOrcidBio().getKeywords().getKeyword().get(0).setSource(null);
    profile.getOrcidBio().getKeywords().getKeyword().get(0).setContent("k2");
    profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setSource(null);
    profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setContent("o2");
    profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setSource(null);
    profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrl(new Url("http://orcid.org/researcher-url-2"));
    profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrlName(new UrlName("url-name-2"));
    orcidProfileManager.updateOrcidBio(profile);
    // Everything should be updated but the primary address that was already set
    profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
    assertNotNull(profile);
    assertNotNull(profile.getOrcidBio());
    assertNotNull(profile.getOrcidBio().getBiography());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getBiography().getVisibility());
    assertEquals("This is my biography # 2", profile.getOrcidBio().getBiography().getContent());
    assertNotNull(profile.getOrcidBio().getContactDetails());
    assertNotNull(profile.getOrcidBio().getContactDetails().getAddress());
    assertNotNull(profile.getOrcidBio().getContactDetails().getAddress().getCountry());
    assertNotNull(profile.getOrcidBio().getContactDetails().getEmail());
    assertEquals(1, profile.getOrcidBio().getContactDetails().getEmail().size());
    assertNotNull(profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertEquals(email, profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertNotNull(profile.getOrcidBio().getExternalIdentifiers());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getExternalIdentifiers().getVisibility());
    assertNotNull(profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals("common-name-2", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("ext-id-reference-2", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
    assertEquals("http://orcid.org/ext-id-2", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
    assertNotNull(profile.getOrcidBio().getKeywords());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getKeywords().getVisibility());
    assertEquals(1, profile.getOrcidBio().getKeywords().getKeyword().size());
    assertEquals("k2", profile.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
    assertNotNull(profile.getOrcidBio().getPersonalDetails());
    assertNotNull(profile.getOrcidBio().getPersonalDetails().getOtherNames());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
    assertEquals(1, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
    assertEquals("o2", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
    assertNotNull(profile.getOrcidBio().getResearcherUrls());
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getResearcherUrls().getVisibility());
    assertEquals(1, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://orcid.org/researcher-url-2", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
    assertEquals("url-name-2", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
    // Primary address should remain
    assertEquals(Iso3166Country.US, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
    profileEntity = profileDao.find(profile.getOrcidIdentifier().getPath());
    assertNotNull(profileEntity);
    assertNotNull(profileEntity.getAddresses());
    assertEquals(2, profileEntity.getAddresses().size());
    Iterator<AddressEntity> it = profileEntity.getAddresses().iterator();
    while (it.hasNext()) {
        assertThat(it.next().getIso2Country(), anyOf(is(org.orcid.jaxb.model.common_v2.Iso3166Country.US), is(org.orcid.jaxb.model.common_v2.Iso3166Country.CR)));
    }
    // Claim the record
    OrcidHistory orcidHistory = new OrcidHistory();
    orcidHistory.setClaimed(new Claimed(true));
    orcidHistory.setCreationMethod(CreationMethod.DIRECT);
    orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile.setOrcidHistory(orcidHistory);
    Preferences preferences = new Preferences();
    preferences.setSendChangeNotifications(new SendChangeNotifications(true));
    preferences.setSendOrcidNews(new SendOrcidNews(true));
    // Default visibility for user will be LIMITED
    preferences.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    preferences.setNotificationsEnabled(DefaultPreferences.NOTIFICATIONS_ENABLED);
    preferences.setSendEmailFrequencyDays(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS);
    preferences.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
    OrcidInternal internal = new OrcidInternal();
    internal.setPreferences(preferences);
    profile.setOrcidInternal(internal);
    orcidProfileManager.updateOrcidProfile(profile);
    // Everything should be updated but the address, because the record is claimed
    profile.getOrcidBio().getBiography().setContent("This is my biography # 3");
    profile.getOrcidBio().getContactDetails().getAddress().setCountry(new Country(Iso3166Country.PE));
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setSource(null);
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdCommonName(new ExternalIdCommonName("common-name-3"));
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdReference(new ExternalIdReference("ext-id-reference-3"));
    profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdUrl(new ExternalIdUrl("http://orcid.org/ext-id-3"));
    profile.getOrcidBio().getKeywords().getKeyword().get(0).setSource(null);
    profile.getOrcidBio().getKeywords().getKeyword().get(0).setContent("k3");
    profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setSource(null);
    profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setContent("o3");
    profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setSource(null);
    profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrl(new Url("http://orcid.org/researcher-url-3"));
    profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrlName(new UrlName("url-name-3"));
    orcidProfileManager.updateOrcidBio(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
    assertNotNull(profile);
    assertNotNull(profile.getOrcidBio());
    assertNotNull(profile.getOrcidBio().getBiography());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getBiography().getVisibility());
    assertEquals("This is my biography # 3", profile.getOrcidBio().getBiography().getContent());
    assertNotNull(profile.getOrcidBio().getContactDetails());
    assertNotNull(profile.getOrcidBio().getContactDetails().getAddress());
    assertNotNull(profile.getOrcidBio().getContactDetails().getAddress().getCountry());
    assertNotNull(profile.getOrcidBio().getContactDetails().getEmail());
    assertEquals(1, profile.getOrcidBio().getContactDetails().getEmail().size());
    assertNotNull(profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertEquals(email, profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertNotNull(profile.getOrcidBio().getExternalIdentifiers());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getExternalIdentifiers().getVisibility());
    assertNotNull(profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals("common-name-3", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("ext-id-reference-3", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
    assertEquals("http://orcid.org/ext-id-3", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
    assertNotNull(profile.getOrcidBio().getKeywords());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getKeywords().getVisibility());
    assertEquals(1, profile.getOrcidBio().getKeywords().getKeyword().size());
    assertEquals("k3", profile.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
    assertNotNull(profile.getOrcidBio().getPersonalDetails());
    assertNotNull(profile.getOrcidBio().getPersonalDetails().getOtherNames());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
    assertEquals(1, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
    assertEquals("o3", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
    assertNotNull(profile.getOrcidBio().getResearcherUrls());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getResearcherUrls().getVisibility());
    assertEquals(1, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://orcid.org/researcher-url-3", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
    assertEquals("url-name-3", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
    profileEntity = profileDao.find(profile.getOrcidIdentifier().getPath());
    assertNotNull(profileEntity);
    assertNotNull(profileEntity.getAddresses());
    assertEquals(3, profileEntity.getAddresses().size());
    it = profileEntity.getAddresses().iterator();
    while (it.hasNext()) {
        assertThat(it.next().getIso2Country(), anyOf(is(org.orcid.jaxb.model.common_v2.Iso3166Country.US), is(org.orcid.jaxb.model.common_v2.Iso3166Country.CR), is(org.orcid.jaxb.model.common_v2.Iso3166Country.PE)));
    }
    // Primary address should remain
    assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getVisibility());
    assertEquals(Iso3166Country.US, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
}
Also used : SendOrcidNews(org.orcid.jaxb.model.message.SendOrcidNews) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) UrlName(org.orcid.jaxb.model.message.UrlName) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Url(org.orcid.jaxb.model.message.Url) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) Claimed(org.orcid.jaxb.model.message.Claimed) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Country(org.orcid.jaxb.model.message.Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) Preferences(org.orcid.jaxb.model.message.Preferences) DefaultPreferences(org.orcid.core.constants.DefaultPreferences) SendChangeNotifications(org.orcid.jaxb.model.message.SendChangeNotifications) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with ExternalIdCommonName

use of org.orcid.jaxb.model.message.ExternalIdCommonName in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testDefaultPrivacyOnBio.

@Test
public void testDefaultPrivacyOnBio() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4499", ScopePathType.ORCID_BIO_UPDATE);
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4499"));
    orcidMessage.setOrcidProfile(orcidProfile);
    OrcidBio orcidBio = new OrcidBio();
    orcidProfile.setOrcidBio(orcidBio);
    PersonalDetails personalDetails = new PersonalDetails();
    orcidBio.setPersonalDetails(personalDetails);
    GivenNames givenNames = new GivenNames("Test given names");
    personalDetails.setGivenNames(givenNames);
    CreditName creditName = new CreditName("Credit Name");
    personalDetails.setCreditName(creditName);
    ExternalIdentifier id = new ExternalIdentifier();
    id.setExternalIdCommonName(new ExternalIdCommonName("cn1"));
    id.setExternalIdReference(new ExternalIdReference("value1"));
    orcidBio.setExternalIdentifiers(new ExternalIdentifiers());
    orcidBio.getExternalIdentifiers().getExternalIdentifier().add(id);
    personalDetails.setOtherNames(new OtherNames());
    personalDetails.getOtherNames().addOtherName("on1", null);
    orcidBio.setKeywords(new Keywords());
    orcidBio.getKeywords().getKeyword().add(new Keyword("kw1", null));
    orcidBio.setResearcherUrls(new ResearcherUrls());
    orcidBio.getResearcherUrls().getResearcherUrl().add(new ResearcherUrl(new Url("http://rurl2.com"), null));
    t2OrcidApiServiceDelegator.updateBioDetails(mockedUriInfo, "4444-4444-4444-4499", orcidMessage);
    OrcidProfile p = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4499");
    assertEquals("cn1", p.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals(Visibility.PUBLIC, p.getOrcidBio().getExternalIdentifiers().getVisibility());
    assertEquals("on1", p.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
    assertEquals(Visibility.PUBLIC, p.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
    assertEquals("kw1", p.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
    assertEquals(Visibility.PUBLIC, p.getOrcidBio().getKeywords().getVisibility());
    assertEquals(new Url("http://rurl2.com"), p.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl());
    assertEquals(Visibility.PUBLIC, p.getOrcidBio().getResearcherUrls().getVisibility());
// now test what happens if we add a new one.
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) Keyword(org.orcid.jaxb.model.message.Keyword) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) CreditName(org.orcid.jaxb.model.message.CreditName) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) Url(org.orcid.jaxb.model.message.Url) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) GivenNames(org.orcid.jaxb.model.message.GivenNames) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with ExternalIdCommonName

use of org.orcid.jaxb.model.message.ExternalIdCommonName in project ORCID-Source by ORCID.

the class Api12MembersTest method addExternalIdentifiersTest.

@Test
public void addExternalIdentifiersTest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientRedirectUri = getClient1RedirectUri();
    String clientSecret = getClient1ClientSecret();
    String userId = getUser1OrcidId();
    String password = getUser1Password();
    String accessToken = getAccessToken(userId, password, Arrays.asList("/person/update", "/orcid-bio/read-limited"), clientId, clientSecret, clientRedirectUri, true);
    // Check the current record and get the num of existing ext ids
    ClientResponse response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    OrcidMessage orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithExtIds);
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
    int initialNumberOfExtIds = 0;
    if (orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers() != null && orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier() != null) {
        initialNumberOfExtIds = orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size();
    }
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
    OrcidProfile orcidProfile = new OrcidProfile();
    OrcidBio orcidBio = new OrcidBio();
    ExternalIdentifier extId = new ExternalIdentifier();
    Long time = System.currentTimeMillis();
    String commonName = "ext-id-common-name-" + time;
    String idReference = "ext-id-reference-" + time;
    extId.setExternalIdCommonName(new ExternalIdCommonName(commonName));
    extId.setExternalIdReference(new ExternalIdReference(idReference));
    ExternalIdentifiers extIds = new ExternalIdentifiers();
    extIds.getExternalIdentifier().add(extId);
    orcidBio.setExternalIdentifiers(extIds);
    orcidProfile.setOrcidBio(orcidBio);
    orcidMessage.setOrcidProfile(orcidProfile);
    ClientResponse clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessage, accessToken);
    assertEquals(200, clientResponse.getStatus());
    response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithExtIds);
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    boolean found = false;
    for (ExternalIdentifier newExtId : orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
        if (commonName.equals(newExtId.getExternalIdCommonName().getContent())) {
            assertEquals(idReference, newExtId.getExternalIdReference().getContent());
            found = true;
        }
    }
    assertTrue(found);
    // Try to add a duplicate
    long initialSize = orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size();
    ExternalIdentifier dupExtId = new ExternalIdentifier();
    dupExtId.setExternalIdCommonName(new ExternalIdCommonName(commonName));
    dupExtId.setExternalIdReference(new ExternalIdReference(idReference));
    orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
    assertEquals(initialSize + 1, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessageWithExtIds, accessToken);
    assertEquals(200, clientResponse.getStatus());
    response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithExtIds);
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertEquals(initialSize, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    found = false;
    for (ExternalIdentifier newExtId : orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
        if (commonName.equals(newExtId.getExternalIdCommonName().getContent())) {
            assertEquals(idReference, newExtId.getExternalIdReference().getContent());
            found = true;
        }
    }
    assertTrue(found);
    // Add a new one and the duplicate again, verify only the new one was added
    String newExtIdValue = "new-ext-id-" + System.currentTimeMillis();
    ExternalIdentifier newExtId = new ExternalIdentifier();
    newExtId.setExternalIdCommonName(new ExternalIdCommonName(newExtIdValue));
    newExtId.setExternalIdReference(new ExternalIdReference(newExtIdValue));
    orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
    orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().add(newExtId);
    assertEquals(initialSize + 2, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessageWithExtIds, accessToken);
    assertEquals(200, clientResponse.getStatus());
    response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessageWithExtIds);
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
    assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertEquals(initialSize + 1, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    boolean foundOld = false;
    boolean foundNew = false;
    for (ExternalIdentifier element : orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
        if (commonName.equals(element.getExternalIdCommonName().getContent())) {
            assertEquals(idReference, element.getExternalIdReference().getContent());
            foundOld = true;
        } else if (newExtIdValue.equals(element.getExternalIdCommonName().getContent())) {
            assertEquals(newExtIdValue, element.getExternalIdReference().getContent());
            foundNew = true;
        }
    }
    assertTrue(foundOld);
    assertTrue(foundNew);
    // Delete both ext ids
    response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
    Iterator<ExternalIdentifier> it = orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator();
    while (it.hasNext()) {
        ExternalIdentifier element = it.next();
        if (commonName.equals(element.getExternalIdCommonName().getContent()) || newExtIdValue.equals(element.getExternalIdCommonName().getContent())) {
            it.remove();
        }
    }
    clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessageWithExtIds, accessToken);
    assertEquals(200, clientResponse.getStatus());
    response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    // It should have the same number of ext ids as before the test
    assertEquals(initialNumberOfExtIds, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Test(org.junit.Test)

Aggregations

ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)13 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)13 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)12 Test (org.junit.Test)11 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)11 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)11 ExternalIdUrl (org.orcid.jaxb.model.message.ExternalIdUrl)10 FundingExternalIdentifier (org.orcid.jaxb.model.message.FundingExternalIdentifier)10 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)10 FundingExternalIdentifiers (org.orcid.jaxb.model.message.FundingExternalIdentifiers)9 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)9 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)9 ResearcherUrl (org.orcid.jaxb.model.message.ResearcherUrl)7 Url (org.orcid.jaxb.model.message.Url)7 Keyword (org.orcid.jaxb.model.message.Keyword)6 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)6 OtherNames (org.orcid.jaxb.model.message.OtherNames)6 Keywords (org.orcid.jaxb.model.message.Keywords)5 ResearcherUrls (org.orcid.jaxb.model.message.ResearcherUrls)5 DBUnitTest (org.orcid.test.DBUnitTest)5