use of org.orcid.jaxb.model.message.OtherNames 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.OtherNames in project ORCID-Source by ORCID.
the class OrcidApiAuthorizationSecurityAspect method visibilityResponseFilter.
@AfterReturning(pointcut = "@annotation(accessControl)", returning = "response")
public void visibilityResponseFilter(Response response, AccessControl accessControl) {
if (accessControl.requestComesFromInternalApi()) {
return;
}
Object entity = response.getEntity();
if (entity != null && OrcidMessage.class.isAssignableFrom(entity.getClass())) {
OrcidMessage orcidMessage = (OrcidMessage) entity;
//If it is search results, don't filter them, just return them
if (orcidMessage.getOrcidSearchResults() != null) {
return;
}
// get the client id
Object authentication = getAuthentication();
Set<Visibility> visibilities = new HashSet<Visibility>();
if (allowAnonymousAccess((Authentication) authentication, accessControl)) {
visibilities.add(Visibility.PUBLIC);
} else {
visibilities = permissionChecker.obtainVisibilitiesForAuthentication(getAuthentication(), accessControl.requiredScope(), orcidMessage);
}
//If the message contains a bio, and the given name is filtered, restore it as an empty space
boolean setEmptyGivenNameIfFiltered = false;
if (orcidMessage.getOrcidProfile() != null) {
if (orcidMessage.getOrcidProfile() != null && orcidMessage.getOrcidProfile().getOrcidBio() != null) {
setEmptyGivenNameIfFiltered = true;
}
}
ScopePathType requiredScope = accessControl.requiredScope();
// If the required scope is */read-limited or */update
if (isUpdateOrReadScope(requiredScope)) {
// if it should be able to
if (OrcidOAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OrcidOAuth2Authentication orcidAuth = (OrcidOAuth2Authentication) getAuthentication();
OAuth2Request authorization = orcidAuth.getOAuth2Request();
String clientId = authorization.getClientId();
// #1: Get the user orcid
String userOrcid = getUserOrcidFromOrcidMessage(orcidMessage);
// #2: Evaluate the scope to know which field to filter
boolean allowWorks = false;
boolean allowFunding = false;
boolean allowAffiliations = false;
// Get the update equivalent scope, if it is reading, but,
// doesnt have the read permissions, check if it have the
// update permissions
ScopePathType equivalentUpdateScope = getEquivalentUpdateScope(requiredScope);
if (requiredScope.equals(ScopePathType.READ_LIMITED)) {
if (hasScopeEnabled(clientId, userOrcid, ScopePathType.ORCID_WORKS_READ_LIMITED.getContent(), ScopePathType.ORCID_WORKS_UPDATE.getContent()))
allowWorks = true;
if (hasScopeEnabled(clientId, userOrcid, ScopePathType.FUNDING_READ_LIMITED.getContent(), ScopePathType.FUNDING_UPDATE.getContent()))
allowFunding = true;
if (hasScopeEnabled(clientId, userOrcid, ScopePathType.AFFILIATIONS_READ_LIMITED.getContent(), ScopePathType.AFFILIATIONS_UPDATE.getContent()))
allowAffiliations = true;
} else if (requiredScope.equals(ScopePathType.ORCID_WORKS_UPDATE) || requiredScope.equals(ScopePathType.ORCID_WORKS_READ_LIMITED)) {
// works
if (hasScopeEnabled(clientId, userOrcid, requiredScope.getContent(), equivalentUpdateScope == null ? null : equivalentUpdateScope.getContent()))
// If so, allow him to see private works
allowWorks = true;
} else if (requiredScope.equals(ScopePathType.FUNDING_UPDATE) || requiredScope.equals(ScopePathType.FUNDING_READ_LIMITED)) {
// funding
if (hasScopeEnabled(clientId, userOrcid, requiredScope.getContent(), equivalentUpdateScope == null ? null : equivalentUpdateScope.getContent()))
// If so, allow him to see private funding
allowFunding = true;
} else if (requiredScope.equals(ScopePathType.AFFILIATIONS_UPDATE) || requiredScope.equals(ScopePathType.AFFILIATIONS_READ_LIMITED)) {
// affiliations
if (hasScopeEnabled(clientId, userOrcid, requiredScope.getContent(), equivalentUpdateScope == null ? null : equivalentUpdateScope.getContent()))
// If so, allow him to see private affiliations
allowAffiliations = true;
}
visibilityFilter.filter(orcidMessage, clientId, allowWorks, allowFunding, allowAffiliations, visibilities.toArray(new Visibility[visibilities.size()]));
} else {
visibilityFilter.filter(orcidMessage, null, false, false, false, visibilities.toArray(new Visibility[visibilities.size()]));
}
} else {
visibilityFilter.filter(orcidMessage, null, false, false, false, visibilities.toArray(new Visibility[visibilities.size()]));
}
//If the given name was set at the beginning and now is filtered, it means we should restore it as an empty field
if (setEmptyGivenNameIfFiltered) {
if (orcidMessage.getOrcidProfile() != null) {
if (orcidMessage.getOrcidProfile().getOrcidBio() == null) {
orcidMessage.getOrcidProfile().setOrcidBio(new OrcidBio());
}
if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails() == null) {
orcidMessage.getOrcidProfile().getOrcidBio().setPersonalDetails(new PersonalDetails());
}
}
}
//Filter given or family names visibility
if (orcidMessage.getOrcidProfile() != null) {
if (orcidMessage.getOrcidProfile().getOrcidBio() != null) {
if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails() != null) {
if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames() != null) {
orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().setVisibility(null);
} else {
//Null given names could break client integrations, so, lets return an empty string
GivenNames empty = new GivenNames();
empty.setContent(StringUtils.EMPTY);
orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().setGivenNames(empty);
}
if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName() != null) {
orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().setVisibility(null);
}
}
}
}
//replace section visibilities now we may have filtered items
if (orcidMessage.getOrcidProfile() != null) {
if (orcidMessage.getOrcidProfile().getOrcidBio() != null) {
if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails() != null) {
OtherNames n = orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getOtherNames();
if (n != null) {
n.setVisibility(getMostFromCollection(n.getOtherName()));
}
}
ExternalIdentifiers ids = orcidMessage.getOrcidProfile().getOrcidBio().getExternalIdentifiers();
if (ids != null) {
ids.setVisibility(getMostFromCollection(ids.getExternalIdentifier()));
}
Keywords kws = orcidMessage.getOrcidProfile().getOrcidBio().getKeywords();
if (kws != null) {
kws.setVisibility(getMostFromCollection(kws.getKeyword()));
}
ResearcherUrls urls = orcidMessage.getOrcidProfile().getOrcidBio().getResearcherUrls();
if (urls != null) {
urls.setVisibility(getMostFromCollection(urls.getResearcherUrl()));
}
}
}
}
}
use of org.orcid.jaxb.model.message.OtherNames in project ORCID-Source by ORCID.
the class JpaJaxbEntityAdapterToOrcidProfileTest method checkPersonalDetails.
private void checkPersonalDetails(PersonalDetails personalDetails) {
assertNotNull(personalDetails);
FamilyName familyName = personalDetails.getFamilyName();
assertNotNull(familyName);
assertEquals("Sellers", familyName.getContent());
GivenNames givenNames = personalDetails.getGivenNames();
assertNotNull(givenNames);
assertEquals("Peter", givenNames.getContent());
CreditName creditName = personalDetails.getCreditName();
assertNotNull(creditName);
assertEquals("P. Sellers III", creditName.getContent());
assertEquals("LIMITED", creditName.getVisibility().name());
OtherNames otherNames = personalDetails.getOtherNames();
assertNotNull(otherNames);
List<String> otherNameList = otherNames.getOtherNamesAsStrings();
Collections.sort(otherNameList);
assertEquals(2, otherNameList.size());
assertEquals("Flibberdy Flabinah", otherNameList.get(0));
assertEquals("Slibberdy Slabinah", otherNameList.get(1));
}
use of org.orcid.jaxb.model.message.OtherNames in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testDefaultVisibilityForItemsAppliedOnUpdate.
@Test
@Transactional
@Rollback(true)
public void testDefaultVisibilityForItemsAppliedOnUpdate() {
OrcidProfile profile = createBasicProfile();
OrcidHistory orcidHistory = new OrcidHistory();
orcidHistory.setClaimed(new Claimed(true));
orcidHistory.setCreationMethod(CreationMethod.DIRECT);
orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
profile.setOrcidHistory(orcidHistory);
Keyword k = new Keyword("word", null);
Keywords kk = new Keywords();
kk.getKeyword().add(k);
kk.setVisibility(Visibility.LIMITED);
ResearcherUrl r = new ResearcherUrl(new Url("http://whatever.com"), null);
ResearcherUrls rr = new ResearcherUrls();
rr.getResearcherUrl().add(r);
rr.setVisibility(Visibility.LIMITED);
ExternalIdentifier i = new ExternalIdentifier(null);
i.setExternalIdReference(new ExternalIdReference("ref"));
i.setExternalIdCommonName(new ExternalIdCommonName("cn"));
ExternalIdentifiers ii = new ExternalIdentifiers();
ii.getExternalIdentifier().add(i);
ii.setVisibility(Visibility.LIMITED);
OtherNames oo = new OtherNames();
oo.addOtherName("other", null);
oo.setVisibility(Visibility.LIMITED);
profile.getOrcidBio().setKeywords(kk);
profile.getOrcidBio().setResearcherUrls(rr);
profile.getOrcidBio().setExternalIdentifiers(ii);
profile.getOrcidBio().getPersonalDetails().setOtherNames(oo);
//Create the profile
profile = orcidProfileManager.createOrcidProfile(profile, true, false);
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);
profile.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
//Claim the profile
profile = orcidProfileManager.updateOrcidProfile(profile);
//now attempt to alter privacy. It should fail as record has been claimed.
profile.getOrcidBio().getKeywords().setVisibility(Visibility.PUBLIC);
profile.getOrcidBio().getResearcherUrls().setVisibility(Visibility.PUBLIC);
profile.getOrcidBio().getExternalIdentifiers().setVisibility(Visibility.PUBLIC);
profile.getOrcidBio().getPersonalDetails().getOtherNames().setVisibility(Visibility.PUBLIC);
profile = orcidProfileManager.updateOrcidProfile(profile);
assertEquals("word", profile.getOrcidBio().getKeywords().getKeyword().iterator().next().getContent());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getKeywords().getKeyword().iterator().next().getVisibility());
assertEquals(new Url("http://whatever.com"), profile.getOrcidBio().getResearcherUrls().getResearcherUrl().iterator().next().getUrl());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().iterator().next().getVisibility());
assertEquals("cn", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getExternalIdCommonName().getContent());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getVisibility());
assertEquals("other", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().iterator().next().getContent());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().iterator().next().getVisibility());
}
use of org.orcid.jaxb.model.message.OtherNames in project ORCID-Source by ORCID.
the class OrcidSearchManagerImplTest method getOrcidProfileAllIndexFieldsPopulated.
private OrcidProfile getOrcidProfileAllIndexFieldsPopulated() {
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setOrcidIdentifier("5678");
OrcidBio orcidBio = new OrcidBio();
PersonalDetails personalDetails = new PersonalDetails();
personalDetails.setFamilyName(new FamilyName("Logan"));
personalDetails.setGivenNames(new GivenNames("Donald Edward"));
personalDetails.setCreditName(new CreditName("Stanley Higgins"));
OtherNames otherNames = new OtherNames();
otherNames.getOtherName().add(new OtherName("Edward Bass", null));
otherNames.getOtherName().add(new OtherName("Gareth Dove", null));
personalDetails.setOtherNames(otherNames);
orcidBio.setPersonalDetails(personalDetails);
orcidProfile.setOrcidBio(orcidBio);
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
Affiliations affiliations = new Affiliations();
orcidActivities.setAffiliations(affiliations);
OrcidWorks orcidWorks = new OrcidWorks();
orcidProfile.setOrcidWorks(orcidWorks);
OrcidWork orcidWork1 = new OrcidWork();
OrcidWork orcidWork2 = new OrcidWork();
assignWorkIdentifers(orcidWork1, orcidWork2);
orcidWorks.getOrcidWork().add(orcidWork1);
orcidWorks.getOrcidWork().add(orcidWork2);
orcidProfile.setOrcidWorks(orcidWorks);
FundingList orcidFundings = new FundingList();
orcidProfile.setFundings(orcidFundings);
Funding funding1 = new Funding();
funding1.setVisibility(Visibility.PUBLIC);
FundingTitle title = new FundingTitle();
title.setTitle(new Title("grant1"));
funding1.setTitle(title);
funding1.setDescription("Grant 1 - a short description");
funding1.setPutCode("grant 1 - put-code");
Funding funding2 = new Funding();
funding2.setVisibility(Visibility.PUBLIC);
FundingTitle title2 = new FundingTitle();
title2.setTitle(new Title("grant2"));
funding2.setTitle(title2);
funding2.setDescription("Grant 2 - a short description");
funding2.setPutCode("grant 2 - put-code");
orcidFundings.getFundings().add(funding1);
orcidFundings.getFundings().add(funding2);
return orcidProfile;
}
Aggregations