Search in sources :

Example 26 with ExternalIdentifier

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

the class OrcidMessageUtil method setSourceName.

public void setSourceName(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidActivities() != null) {
            OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
            if (orcidActivities.getAffiliations() != null) {
                Affiliations affs = orcidActivities.getAffiliations();
                List<Affiliation> affList = affs.getAffiliation();
                if (affList != null) {
                    for (Affiliation aff : affList) {
                        setSourceName(aff);
                    }
                }
            }
            if (orcidActivities.getFundings() != null) {
                FundingList fundingList = orcidActivities.getFundings();
                List<Funding> fundings = fundingList.getFundings();
                if (fundings != null) {
                    for (Funding funding : fundings) {
                        setSourceName(funding);
                    }
                }
            }
            if (orcidActivities.getOrcidWorks() != null) {
                OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
                List<OrcidWork> works = orcidWorks.getOrcidWork();
                if (works != null) {
                    for (OrcidWork work : works) {
                        setSourceName(work);
                    }
                }
            }
        }
        if (orcidProfile.getOrcidBio() != null) {
            OrcidBio orcidBio = orcidProfile.getOrcidBio();
            if (orcidBio.getContactDetails() != null) {
                Address address = orcidBio.getContactDetails().getAddress();
                if (address != null) {
                    setSourceName(address);
                }
            }
            if (orcidBio.getExternalIdentifiers() != null) {
                ExternalIdentifiers extIds = orcidBio.getExternalIdentifiers();
                List<ExternalIdentifier> extIdsList = extIds.getExternalIdentifier();
                if (extIdsList != null) {
                    for (ExternalIdentifier extId : extIdsList) {
                        setSourceName(extId);
                    }
                }
            }
            if (orcidBio.getKeywords() != null) {
                Keywords keywords = orcidBio.getKeywords();
                List<Keyword> keywordList = keywords.getKeyword();
                if (keywordList != null) {
                    for (Keyword keyword : keywordList) {
                        setSourceName(keyword);
                    }
                }
            }
            if (orcidBio.getPersonalDetails() != null) {
                OtherNames otherNames = orcidBio.getPersonalDetails().getOtherNames();
                if (otherNames != null) {
                    List<OtherName> otherNameList = otherNames.getOtherName();
                    if (otherNameList != null) {
                        for (OtherName otherName : otherNameList) {
                            setSourceName(otherName);
                        }
                    }
                }
            }
            if (orcidBio.getResearcherUrls() != null) {
                ResearcherUrls rUrls = orcidBio.getResearcherUrls();
                List<ResearcherUrl> rUrlList = rUrls.getResearcherUrl();
                if (rUrlList != null) {
                    for (ResearcherUrl rUrl : rUrlList) {
                        setSourceName(rUrl);
                    }
                }
            }
        }
    }
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Address(org.orcid.jaxb.model.message.Address) Keyword(org.orcid.jaxb.model.message.Keyword) Funding(org.orcid.jaxb.model.message.Funding) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OtherName(org.orcid.jaxb.model.message.OtherName) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) FundingList(org.orcid.jaxb.model.message.FundingList) Affiliations(org.orcid.jaxb.model.message.Affiliations) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 27 with ExternalIdentifier

use of org.orcid.jaxb.model.message.ExternalIdentifier 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

ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)27 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)19 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)17 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)15 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)15 ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)12 Test (org.junit.Test)11 FundingExternalIdentifier (org.orcid.jaxb.model.message.FundingExternalIdentifier)10 Keyword (org.orcid.jaxb.model.message.Keyword)10 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)10 ExternalIdUrl (org.orcid.jaxb.model.message.ExternalIdUrl)9 FundingExternalIdentifiers (org.orcid.jaxb.model.message.FundingExternalIdentifiers)9 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)8 OtherNames (org.orcid.jaxb.model.message.OtherNames)8 ResearcherUrl (org.orcid.jaxb.model.message.ResearcherUrl)8 Keywords (org.orcid.jaxb.model.message.Keywords)7 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)7 OtherName (org.orcid.jaxb.model.message.OtherName)7 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)6