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());
}
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());
}
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);
}
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
}
}
}
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());
}
}
Aggregations