use of org.orcid.jaxb.model.message.Country 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.Country 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.Country 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.Country in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setCountry.
private void setCountry(ProfileEntity profileEntity, ContactDetails contactDetails) {
Country contactCountry = contactDetails.getAddress() != null && contactDetails.getAddress().getCountry() != null ? contactDetails.getAddress().getCountry() : null;
Iso3166Country country = contactCountry != null ? contactCountry.getValue() : null;
if (country != null) {
Set<AddressEntity> addresses = profileEntity.getAddresses();
if (addresses == null) {
addresses = new HashSet<AddressEntity>();
profileEntity.setAddresses(addresses);
}
boolean addIt = true;
//If the address exists, don't add it
for (AddressEntity address : addresses) {
if (Objects.equals(country.value(), address.getIso2Country().value())) {
addIt = false;
}
}
if (addIt) {
AddressEntity newAddress = new AddressEntity();
newAddress.setDateCreated(new Date());
//The default country is the smallest one, so, lets add this one as the biggest display index possible for the record
newAddress.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(country.value()));
newAddress.setLastModified(new Date());
newAddress.setUser(profileEntity);
newAddress.setVisibility(getDefaultVisibility(profileEntity, contactCountry.getVisibility(), OrcidVisibilityDefaults.COUNTRY_DEFAULT));
//Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newAddress);
newAddress.setDisplayIndex(0L);
for (AddressEntity address : addresses) address.setDisplayIndex(address.getDisplayIndex() + 1L);
addresses.add(newAddress);
}
}
}
use of org.orcid.jaxb.model.message.Country in project ORCID-Source by ORCID.
the class VisibilityFilterImpl method filter.
/**
* Remove the elements that are not present in the list of set of
* {@link org.orcid.jaxb.model.message .Visibility}s present in the array
* passed in.
*
* @param messageToBeFiltered
* the {@link org.orcid.jaxb.model.message.OrcidMessage} that
* will be traversed looking for
* {@link org .orcid.jaxb.model.message.VisibilityType} elements.
* @param source
* The orcid source that is executing the request
* @param removeAttribute
* should all {@link org.orcid.jaxb.model.message.Visibility}
* elements be removed from the object graph. This has the effect
* that they will not be present in the resulting JAXB
* serialisation.
* @param visibilities
* What {@link org.orcid.jaxb.model.message.Visibility} elements
* should be allowed.
* @return the cleansed {@link org.orcid.jaxb.model.message.OrcidMessage}
*/
@Override
public OrcidMessage filter(OrcidMessage messageToBeFiltered, final String sourceId, final boolean allowPrivateWorks, final boolean allowPrivateFunding, final boolean allowPrivateAffiliations, Visibility... visibilities) {
if (messageToBeFiltered == null || visibilities == null || visibilities.length == 0) {
return null;
}
String messageIdForLog = getMessageIdForLog(messageToBeFiltered);
LOGGER.debug("About to filter message: " + messageIdForLog);
final Set<Visibility> visibilitySet = new HashSet<Visibility>(Arrays.asList(visibilities));
if (visibilitySet.contains(Visibility.SYSTEM)) {
return messageToBeFiltered;
} else {
TreeCleaner treeCleaner = new TreeCleaner();
treeCleaner.clean(messageToBeFiltered, new TreeCleaningStrategy() {
public TreeCleaningDecision needsStripping(Object obj) {
TreeCleaningDecision decision = TreeCleaningDecision.DEFAULT;
if (obj != null) {
Class<?> clazz = obj.getClass();
if (!PojoUtil.isEmpty(sourceId)) {
if (allowPrivateAffiliations && Affiliation.class.isAssignableFrom(clazz)) {
Affiliation affiliation = (Affiliation) obj;
Source source = affiliation.getSource();
if (source != null) {
String sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
if (sourceId.equals(sourcePath)) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
} else if (allowPrivateFunding && Funding.class.isAssignableFrom(clazz)) {
Funding funding = (Funding) obj;
Source source = funding.getSource();
if (source != null) {
String sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
if (sourceId.equals(sourcePath)) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
} else if (allowPrivateWorks && OrcidWork.class.isAssignableFrom(clazz)) {
OrcidWork work = (OrcidWork) obj;
Source source = work.getSource();
if (source != null) {
if (sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
}
// fields are inside the country element
if (Address.class.isAssignableFrom(clazz)) {
Address address = (Address) obj;
// Remove empty addresses
if (address.getCountry() == null) {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
} else {
Country country = address.getCountry();
// Allow public addresses
if (Visibility.PUBLIC.equals(country.getVisibility())) {
decision = TreeCleaningDecision.IGNORE;
} else if (visibilitySet.contains(Visibility.LIMITED)) {
// Allow limited visibility when possible
if (Visibility.LIMITED.equals(country.getVisibility())) {
decision = TreeCleaningDecision.IGNORE;
} else {
// As last resource, check the source
Source source = country.getSource();
if (source != null && sourceId != null && sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
} else {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
}
}
}
}
}
if (Email.class.isAssignableFrom(clazz)) {
// include all emails if present
try {
Authentication authentication = getAuthentication();
if (authentication != null && messageToBeFiltered.getOrcidProfile() != null) {
permissionChecker.checkPermissions(getAuthentication(), ScopePathType.EMAIL_READ_PRIVATE, messageToBeFiltered.getOrcidProfile().retrieveOrcidPath());
decision = TreeCleaningDecision.IGNORE;
}
} catch (AccessControlException e) {
// private email can't be read, do nothing here
}
}
// that implements PrivateVisibleToSource
if (sourceId != null)
if (PrivateVisibleToSource.class.isAssignableFrom(clazz) && visibilitySet.contains(Visibility.LIMITED)) {
Source source = ((PrivateVisibleToSource) obj).getSource();
if (source != null) {
if (sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
if (TreeCleaningDecision.DEFAULT.equals(decision)) {
if (WorkContributors.class.isAssignableFrom(clazz)) {
decision = TreeCleaningDecision.IGNORE;
} else if (VisibilityType.class.isAssignableFrom(clazz)) {
VisibilityType visibilityType = (VisibilityType) obj;
if ((visibilityType.getVisibility() == null || !visibilitySet.contains(visibilityType.getVisibility()))) {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
}
}
}
}
return decision;
}
});
OrcidProfile orcidProfile = messageToBeFiltered.getOrcidProfile();
if (orcidProfile != null) {
orcidProfile.setOrcidInternal(null);
}
LOGGER.debug("Finished filtering message: " + messageIdForLog);
return messageToBeFiltered;
}
}
Aggregations