Search in sources :

Example 1 with Address

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

the class OrcidJaxbCopyManagerTest method testUpdateOtherNamePreservingVisibility.

@Test
public void testUpdateOtherNamePreservingVisibility() throws Exception {
    OrcidBio existingOrcidBioProtected = protectedOrcidMessage.getOrcidProfile().getOrcidBio();
    OrcidBio updatedOrcidBioPublic = publicOrcidMessage.getOrcidProfile().getOrcidBio();
    PersonalDetails existingOrcidPersonalDetails = protectedOrcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails();
    PersonalDetails updatedOrcidPersonalDetails = publicOrcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails();
    OtherNames existingOtherNames = existingOrcidPersonalDetails.getOtherNames();
    assertEquals(Visibility.LIMITED, existingOtherNames.getVisibility());
    assertTrue(existingOtherNames.getOtherName().size() == 2);
    assertEquals("Josiah S Carberry", existingOtherNames.getOtherName().get(0).getContent());
    assertEquals("Josiah Carberry", existingOtherNames.getOtherName().get(1).getContent());
    // check content and visibility update updates the content
    OtherNames updatedOtherNames = new OtherNames();
    updatedOtherNames.getOtherName().clear();
    updatedOtherNames.addOtherName("Another 1", null);
    updatedOtherNames.addOtherName("Another 2", null);
    updatedOtherNames.setVisibility(Visibility.PRIVATE);
    updatedOrcidPersonalDetails.setOtherNames(updatedOtherNames);
    Address existingContactDetailsAddress = existingOrcidBioProtected.getContactDetails().getAddress();
    assertEquals(Iso3166Country.US, existingContactDetailsAddress.getCountry().getValue());
    existingContactDetailsAddress.getCountry().setVisibility(Visibility.LIMITED);
    Address nullVisibilityContactAddress = new Address();
    nullVisibilityContactAddress.setCountry(new Country(Iso3166Country.BM));
    nullVisibilityContactAddress.getCountry().setVisibility(null);
    updatedOrcidBioPublic.getContactDetails().setAddress(nullVisibilityContactAddress);
    orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingOrcidBioProtected, updatedOrcidBioPublic);
    existingOtherNames = existingOrcidPersonalDetails.getOtherNames();
    assertTrue(existingOtherNames.getOtherName().size() == 2);
    assertEquals("Another 1", existingOtherNames.getOtherName().get(0).getContent());
    assertEquals("Another 2", existingOtherNames.getOtherName().get(1).getContent());
    assertEquals(Visibility.PRIVATE, existingOtherNames.getVisibility());
    // check content and visibility update of null
    updatedOtherNames = new OtherNames();
    updatedOtherNames.getOtherName().clear();
    updatedOtherNames.addOtherName("Yet Another 1", null);
    updatedOtherNames.addOtherName("Yet Another 2", null);
    updatedOtherNames.setVisibility(null);
    updatedOrcidPersonalDetails.setOtherNames(updatedOtherNames);
    orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingOrcidBioProtected, updatedOrcidBioPublic);
    assertEquals(2, existingOrcidBioProtected.getPersonalDetails().getOtherNames().getOtherName().size());
    assertEquals("Yet Another 1", existingOrcidBioProtected.getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
    assertEquals("Yet Another 2", existingOrcidBioProtected.getPersonalDetails().getOtherNames().getOtherName().get(1).getContent());
    assertEquals(Visibility.PRIVATE, existingOrcidBioProtected.getPersonalDetails().getOtherNames().getVisibility());
    existingContactDetailsAddress = existingOrcidBioProtected.getContactDetails().getAddress();
    assertEquals(Visibility.LIMITED, existingContactDetailsAddress.getCountry().getVisibility());
    assertEquals(Iso3166Country.BM, existingContactDetailsAddress.getCountry().getValue());
}
Also used : OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Address(org.orcid.jaxb.model.message.Address) OtherNames(org.orcid.jaxb.model.message.OtherNames) Country(org.orcid.jaxb.model.message.Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 2 with Address

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

the class OrcidJaxbCopyManagerTest method testUpdatedContactDetailsToExistingPreservingVisibility.

@Test
public void testUpdatedContactDetailsToExistingPreservingVisibility() throws Exception {
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-0000000000000000");
    OrcidBio existingOrcidBioProtected = protectedOrcidMessage.getOrcidProfile().getOrcidBio();
    OrcidBio updatedOrcidBioPublic = publicOrcidMessage.getOrcidProfile().getOrcidBio();
    ContactDetails existingContactDetails = existingOrcidBioProtected.getContactDetails();
    ContactDetails updatedContactDetails = updatedOrcidBioPublic.getContactDetails();
    assertEquals("josiah_carberry@brown.edu", existingContactDetails.retrievePrimaryEmail().getValue());
    assertEquals(Visibility.LIMITED, existingContactDetails.retrievePrimaryEmail().getVisibility());
    String[] alternativeEmails = new String[] { "josiah_carberry_1@brown.edu" };
    for (String alternativeEmail : alternativeEmails) {
        Email email = existingContactDetails.getEmailByString(alternativeEmail);
        assertNotNull(email);
        assertEquals(Visibility.LIMITED, email.getVisibility());
    }
    assertEquals(2, existingContactDetails.getEmail().size());
    Address existingAddress = existingContactDetails.getAddress();
    assertTrue(Iso3166Country.US.equals(existingAddress.getCountry().getValue()) && existingAddress.getCountry().getVisibility() == null);
    Address updatedAddress = new Address();
    Country country = new Country(Iso3166Country.GB);
    country.setVisibility(Visibility.LIMITED);
    updatedAddress.setCountry(country);
    updatedOrcidBioPublic.getContactDetails().setAddress(updatedAddress);
    List<Email> updatedEmailList = new ArrayList<>();
    Email updatedMainEmail = new Email("jimmyb@semantico.com");
    updatedMainEmail.setSourceClientId("APP-0000000000000000");
    updatedMainEmail.setVisibility(Visibility.PUBLIC);
    updatedMainEmail.setPrimary(true);
    updatedEmailList.add(updatedMainEmail);
    String[] updatedAlternativeEmails = new String[] { "jimmyb1@semantico.com" };
    for (String alternativeEmail : updatedAlternativeEmails) {
        Email email = new Email(alternativeEmail);
        email.setPrimary(false);
        email.setVerified(false);
        email.setVisibility(Visibility.PRIVATE);
        email.setSourceClientId("APP-0000000000000000");
        updatedEmailList.add(email);
    }
    updatedContactDetails.getEmail().clear();
    updatedContactDetails.getEmail().addAll(updatedEmailList);
    updatedContactDetails.setAddress(updatedAddress);
    orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingOrcidBioProtected, updatedOrcidBioPublic);
    existingContactDetails = existingOrcidBioProtected.getContactDetails();
    assertEquals("josiah_carberry@brown.edu", existingContactDetails.retrievePrimaryEmail().getValue());
    assertEquals(Visibility.LIMITED, existingContactDetails.retrievePrimaryEmail().getVisibility());
    //Emails remain unchanged
    assertEquals(2, existingContactDetails.getEmail().size());
    assertEquals(Iso3166Country.GB, existingContactDetails.getAddress().getCountry().getValue());
    assertEquals(OrcidVisibilityDefaults.COUNTRY_DEFAULT.getVisibility(), existingContactDetails.getAddress().getCountry().getVisibility());
    updatedContactDetails = new ContactDetails();
    updatedOrcidBioPublic.setContactDetails(updatedContactDetails);
    updatedAddress = new Address();
    country = new Country(Iso3166Country.AU);
    country.setVisibility(null);
    updatedAddress.setCountry(country);
    updatedContactDetails.setAddress(updatedAddress);
    updatedEmailList = new ArrayList<>();
    updatedMainEmail = new Email("jimmyb1@semantico.com");
    updatedMainEmail.setVisibility(Visibility.PUBLIC);
    updatedEmailList.add(updatedMainEmail);
    String[] moreAlternativeEmails = new String[] { "jimmyb3@semantico.com" };
    for (String alternativeEmail : moreAlternativeEmails) {
        Email email = new Email(alternativeEmail);
        email.setPrimary(false);
        email.setVisibility(Visibility.PRIVATE);
        email.setSourceClientId("APP-0000000000000000");
        updatedEmailList.add(email);
    }
    updatedContactDetails.getEmail().clear();
    updatedContactDetails.getEmail().addAll(updatedEmailList);
    orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingOrcidBioProtected, updatedOrcidBioPublic);
    existingContactDetails = existingOrcidBioProtected.getContactDetails();
    //Emails remain unchanged
    assertEquals(2, existingContactDetails.getEmail().size());
    assertEquals(Iso3166Country.AU, existingContactDetails.getAddress().getCountry().getValue());
}
Also used : Email(org.orcid.jaxb.model.message.Email) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) Address(org.orcid.jaxb.model.message.Address) ArrayList(java.util.ArrayList) Country(org.orcid.jaxb.model.message.Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 3 with Address

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

the class OrcidProfileManagerImplTest method setBio.

private void setBio(OrcidProfile profile, Visibility defaultVisibility) {
    OrcidBio bio = new OrcidBio();
    Biography biography = new Biography("This is my biography");
    if (defaultVisibility != null) {
        biography.setVisibility(defaultVisibility);
    }
    bio.setBiography(biography);
    ContactDetails contactDetails = new ContactDetails();
    Address address = new Address();
    address.setCountry(new Country(Iso3166Country.US));
    if (defaultVisibility != null) {
        address.getCountry().setVisibility(defaultVisibility);
    }
    contactDetails.setAddress(address);
    List<Email> emails = new ArrayList<Email>();
    Email email = new Email();
    email.setPrimary(true);
    email.setValue(System.currentTimeMillis() + "@test.orcid.org");
    emails.add(email);
    contactDetails.setEmail(emails);
    bio.setContactDetails(contactDetails);
    ExternalIdentifiers extIds = new ExternalIdentifiers();
    ExternalIdentifier extId = new ExternalIdentifier();
    extId.setExternalIdCommonName(new ExternalIdCommonName("common-name"));
    extId.setExternalIdReference(new ExternalIdReference("ext-id-reference"));
    extId.setExternalIdUrl(new ExternalIdUrl("http://orcid.org/ext-id"));
    extIds.getExternalIdentifier().add(extId);
    if (defaultVisibility != null) {
        extIds.setVisibility(defaultVisibility);
    }
    bio.setExternalIdentifiers(extIds);
    Keywords keywords = new Keywords();
    Keyword keyword = new Keyword();
    keyword.setContent("k1");
    keywords.getKeyword().add(keyword);
    if (defaultVisibility != null) {
        keywords.setVisibility(defaultVisibility);
    }
    bio.setKeywords(keywords);
    PersonalDetails personalDetails = new PersonalDetails();
    personalDetails.setCreditName(new CreditName("credit-name"));
    personalDetails.setGivenNames(new GivenNames("given-names"));
    personalDetails.setFamilyName(new FamilyName("family-name"));
    OtherNames otherNames = new OtherNames();
    OtherName otherName = new OtherName();
    otherName.setContent("o1");
    otherNames.getOtherName().add(otherName);
    if (defaultVisibility != null) {
        otherNames.setVisibility(defaultVisibility);
    }
    personalDetails.setOtherNames(otherNames);
    bio.setPersonalDetails(personalDetails);
    ResearcherUrls researcherUrls = new ResearcherUrls();
    ResearcherUrl researcherUrl = new ResearcherUrl();
    researcherUrl.setUrl(new Url("http://orcid.org/researcher-url-1"));
    researcherUrl.setUrlName(new UrlName("url-name-1"));
    researcherUrls.getResearcherUrl().add(researcherUrl);
    if (defaultVisibility != null) {
        researcherUrls.setVisibility(defaultVisibility);
    }
    bio.setResearcherUrls(researcherUrls);
    profile.setOrcidBio(bio);
}
Also used : Email(org.orcid.jaxb.model.message.Email) Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Address(org.orcid.jaxb.model.message.Address) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) FamilyName(org.orcid.jaxb.model.message.FamilyName) OtherNames(org.orcid.jaxb.model.message.OtherNames) ArrayList(java.util.ArrayList) Url(org.orcid.jaxb.model.message.Url) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) 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) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) Keyword(org.orcid.jaxb.model.message.Keyword) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) CreditName(org.orcid.jaxb.model.message.CreditName) OtherName(org.orcid.jaxb.model.message.OtherName) UrlName(org.orcid.jaxb.model.message.UrlName) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Country(org.orcid.jaxb.model.message.Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country)

Example 4 with Address

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

the class RDFMessageBodyWriter method describeContactDetails.

private void describeContactDetails(ContactDetails contactDetails, Individual person, OntModel m) {
    if (contactDetails == null) {
        return;
    }
    List<Email> emails = contactDetails.getEmail();
    if (emails != null) {
        for (Email email : emails) {
            if (email.isCurrent()) {
                Individual mbox = m.createIndividual("mailto:" + email.getValue(), null);
                person.addProperty(FOAF.mbox, mbox);
            }
        }
    }
    Address addr = contactDetails.getAddress();
    if (addr != null) {
        if (addr.getCountry() != null) {
            String countryCode = addr.getCountry().getValue().name();
            Individual position = m.createIndividual(Geonames.Feature);
            position.addProperty(Geonames.countryCode, countryCode);
            person.addProperty(FOAF.based_near, position);
            Individual country = getCountry(countryCode);
            if (country != null) {
                country = addToModel(position.getOntModel(), country);
                position.addProperty(Geonames.parentCountry, country);
            }
        // TODO: Include URI and (a) full name of country
        // Potential source: geonames.org
        // See https://gist.github.com/stain/7566375
        }
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) Address(org.orcid.jaxb.model.message.Address) Individual(org.apache.jena.ontology.Individual)

Example 5 with Address

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

the class OrcidJaxbCopyManagerImpl method copyUpdatedAddress.

private void copyUpdatedAddress(ContactDetails existingContactDetails, ContactDetails updatedContactDetails) {
    if (updatedContactDetails == null) {
        return;
    }
    if (existingContactDetails.getAddress() == null) {
        existingContactDetails.setAddress(updatedContactDetails.getAddress());
    } else {
        Address existingAddress = existingContactDetails.getAddress();
        Address updatedAddress = updatedContactDetails.getAddress();
        if (updatedAddress != null) {
            if (existingAddress.getCountry() != null) {
                if (!Visibility.PRIVATE.equals(existingAddress.getCountry().getVisibility())) {
                    if (updatedAddress.getCountry() != null) {
                        existingAddress.getCountry().setValue(updatedAddress.getCountry().getValue());
                    }
                }
            } else {
                existingAddress.setCountry(updatedAddress.getCountry());
            }
        }
    }
    if (existingContactDetails.getAddress() != null && existingContactDetails.getAddress().getCountry() != null && existingContactDetails.getAddress().getCountry().getVisibility() == null) {
        existingContactDetails.getAddress().getCountry().setVisibility(OrcidVisibilityDefaults.COUNTRY_DEFAULT.getVisibility());
    }
}
Also used : Address(org.orcid.jaxb.model.message.Address)

Aggregations

Address (org.orcid.jaxb.model.message.Address)10 Email (org.orcid.jaxb.model.message.Email)7 Country (org.orcid.jaxb.model.message.Country)6 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)6 Iso3166Country (org.orcid.jaxb.model.message.Iso3166Country)5 OtherNames (org.orcid.jaxb.model.message.OtherNames)5 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)4 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)4 ResearcherUrl (org.orcid.jaxb.model.message.ResearcherUrl)4 ResearcherUrls (org.orcid.jaxb.model.message.ResearcherUrls)4 ArrayList (java.util.ArrayList)3 CreditName (org.orcid.jaxb.model.message.CreditName)3 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)3 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)3 FamilyName (org.orcid.jaxb.model.message.FamilyName)3 Keyword (org.orcid.jaxb.model.message.Keyword)3 Keywords (org.orcid.jaxb.model.message.Keywords)3 Test (org.junit.Test)2 BaseTest (org.orcid.core.BaseTest)2 Affiliation (org.orcid.jaxb.model.message.Affiliation)2