use of org.orcid.jaxb.model.message.OtherName in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setOtherNames.
private void setOtherNames(ProfileEntity profileEntity, OtherNames otherNames) {
String sourceId = getSourceId();
SortedSet<OtherNameEntity> existingOtherNameEntities = profileEntity.getOtherNames();
Iterator<OtherNameEntity> existingIt = null;
if (existingOtherNameEntities != null) {
existingIt = existingOtherNameEntities.iterator();
}
// Iterate over the list of existing elements, to see which ones still exists but preserving all the ones where the calling client is not the source of
if (existingIt != null) {
while (existingIt.hasNext()) {
OtherNameEntity existing = existingIt.next();
String existingElementSource = existing.getElementSourceId();
if (sourceId != null && !sourceId.equals(existingElementSource)) {
// If am not the source of this element, do nothing
} else {
// If am the source, check if the element exists in the list of incoming elements
String value = existing.getDisplayName();
boolean found = false;
if (otherNames != null && otherNames.getOtherName() != null) {
for (OtherName newOtherName : otherNames.getOtherName()) {
if (Objects.equals(value, newOtherName.getContent())) {
found = true;
break;
}
}
}
// If it doesn't exists, remove it from the existing elements
if (!found) {
existingIt.remove();
}
}
}
}
// Iterate over the list of all new ones and add the ones that doesn't exists yet
if (otherNames != null && otherNames.getOtherName() != null) {
for (OtherName newOtherName : otherNames.getOtherName()) {
boolean exists = false;
if (existingOtherNameEntities != null) {
for (OtherNameEntity existingEntity : existingOtherNameEntities) {
if (Objects.equals(newOtherName.getContent(), existingEntity.getDisplayName())) {
exists = true;
// If the profile is not claimed, you can update the visibility
if (profileEntity.getClaimed() == null || !profileEntity.getClaimed()) {
// Update the visibility of existing elements if the profile is not claimed
String existingVisibilityValue = existingEntity.getVisibility() == null ? null : existingEntity.getVisibility().value();
String listVisibilityValue = otherNames.getVisibility() == null ? null : otherNames.getVisibility().value();
if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
}
}
break;
}
}
}
if (!exists) {
if (existingOtherNameEntities == null) {
existingOtherNameEntities = new TreeSet<OtherNameEntity>();
profileEntity.setOtherNames(existingOtherNameEntities);
}
OtherNameEntity newEntity = new OtherNameEntity();
newEntity.setProfile(profileEntity);
// Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newEntity);
newEntity.setDisplayName(newOtherName.getContent());
newEntity.setVisibility(getDefaultVisibility(profileEntity, otherNames.getVisibility(), OrcidVisibilityDefaults.OTHER_NAMES_DEFAULT));
newEntity.setDisplayIndex(0L);
for (OtherNameEntity tempEntity : existingOtherNameEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
existingOtherNameEntities.add(newEntity);
}
}
}
}
use of org.orcid.jaxb.model.message.OtherName in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testUpdateOrcidBioKeepTheUserVisibility.
@Test
@Transactional
public void testUpdateOrcidBioKeepTheUserVisibility() {
OrcidProfile profile = createBasicProfile();
String orcidIdentifier = null;
profile.setOrcidIdentifier(orcidIdentifier);
setBio(profile, Visibility.LIMITED);
OrcidHistory orcidHistory = new OrcidHistory();
orcidHistory.setClaimed(new Claimed(true));
orcidHistory.setCreationMethod(CreationMethod.DIRECT);
orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
profile.setOrcidHistory(orcidHistory);
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 = orcidProfileManager.createOrcidProfile(profile, true, false);
// Update it setting it to PUBLIC and check
profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
assertNotNull(profile);
assertNotNull(profile.getOrcidBio());
OrcidBio bioToUpdate = profile.getOrcidBio();
assertEquals(Visibility.LIMITED, bioToUpdate.getBiography().getVisibility());
assertEquals("This is my biography", bioToUpdate.getBiography().getContent());
assertEquals(Visibility.LIMITED, bioToUpdate.getContactDetails().getAddress().getCountry().getVisibility());
assertEquals(Iso3166Country.US, bioToUpdate.getContactDetails().getAddress().getCountry().getValue());
assertEquals(Visibility.LIMITED, bioToUpdate.getExternalIdentifiers().getVisibility());
assertEquals(1, bioToUpdate.getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(Visibility.LIMITED, bioToUpdate.getKeywords().getVisibility());
assertEquals(1, bioToUpdate.getKeywords().getKeyword().size());
assertEquals(Visibility.LIMITED, bioToUpdate.getPersonalDetails().getOtherNames().getVisibility());
assertEquals(1, bioToUpdate.getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals(Visibility.LIMITED, bioToUpdate.getResearcherUrls().getVisibility());
assertEquals(1, bioToUpdate.getResearcherUrls().getResearcherUrl().size());
// Update bio
bioToUpdate.getBiography().setContent("Updated biography");
bioToUpdate.getBiography().setVisibility(Visibility.PRIVATE);
// Update address
bioToUpdate.getContactDetails().getAddress().getCountry().setValue(Iso3166Country.CR);
bioToUpdate.getContactDetails().getAddress().getCountry().setVisibility(Visibility.PRIVATE);
// Update external identifiers
ExternalIdentifier extId = new ExternalIdentifier();
extId.setExternalIdCommonName(new ExternalIdCommonName("common-name-2"));
extId.setExternalIdReference(new ExternalIdReference("ext-id-reference-2"));
extId.setExternalIdUrl(new ExternalIdUrl("http://orcid.org/ext-id/2"));
extId.setVisibility(Visibility.PRIVATE);
bioToUpdate.getExternalIdentifiers().setVisibility(Visibility.PRIVATE);
bioToUpdate.getExternalIdentifiers().getExternalIdentifier().add(extId);
// Update keywords
Keyword k = new Keyword();
k.setContent("keyword-2");
k.setVisibility(Visibility.PRIVATE);
bioToUpdate.getKeywords().getKeyword().add(k);
bioToUpdate.getKeywords().setVisibility(Visibility.PRIVATE);
// Update researcher urls
ResearcherUrl rUrl = new ResearcherUrl();
rUrl.setUrl(new Url("http://orcid.org/researcher-url-2"));
rUrl.setUrlName(new UrlName("url-name-2"));
rUrl.setVisibility(Visibility.PRIVATE);
bioToUpdate.getResearcherUrls().getResearcherUrl().add(rUrl);
bioToUpdate.getResearcherUrls().setVisibility(Visibility.PRIVATE);
// Update other names
OtherName o = new OtherName();
o.setContent("other-name-2");
o.setVisibility(Visibility.PRIVATE);
bioToUpdate.getPersonalDetails().getOtherNames().getOtherName().add(o);
bioToUpdate.getPersonalDetails().getOtherNames().setVisibility(Visibility.PRIVATE);
// Update the biography
orcidProfileManager.updateOrcidBio(profile);
// Get the record again and check that visibilities where not updated
OrcidProfile updatedProfile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
assertNotNull(updatedProfile);
assertNotNull(updatedProfile.getOrcidBio());
OrcidBio updatedBio = updatedProfile.getOrcidBio();
assertEquals(Visibility.LIMITED, updatedBio.getBiography().getVisibility());
assertEquals("Updated biography", updatedBio.getBiography().getContent());
assertEquals(Visibility.LIMITED, updatedBio.getContactDetails().getAddress().getCountry().getVisibility());
assertEquals(Iso3166Country.US, updatedBio.getContactDetails().getAddress().getCountry().getValue());
assertEquals(Visibility.LIMITED, updatedBio.getExternalIdentifiers().getVisibility());
assertEquals(2, updatedBio.getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(Visibility.LIMITED, updatedBio.getKeywords().getVisibility());
assertEquals(2, updatedBio.getKeywords().getKeyword().size());
assertEquals(Visibility.LIMITED, updatedBio.getPersonalDetails().getOtherNames().getVisibility());
assertEquals(2, updatedBio.getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals(Visibility.LIMITED, updatedBio.getResearcherUrls().getVisibility());
assertEquals(2, updatedBio.getResearcherUrls().getResearcherUrl().size());
}
use of org.orcid.jaxb.model.message.OtherName in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method deactivateOrcidProfile.
@Override
@Transactional
@Deprecated
public OrcidProfile deactivateOrcidProfile(OrcidProfile existingOrcidProfile) {
OrcidProfile blankedOrcidProfile = new OrcidProfile();
OrcidBio existingBio = existingOrcidProfile.getOrcidBio();
OrcidBio minimalBio = new OrcidBio();
ContactDetails minimalContactDetails = new ContactDetails();
minimalContactDetails.getEmail().addAll(existingBio.getContactDetails().getEmail());
OrcidInternal minimalOrcidInternal = new OrcidInternal();
minimalOrcidInternal.setSecurityDetails(existingOrcidProfile.getOrcidInternal().getSecurityDetails());
OrcidHistory deactivatedOrcidHistory = existingOrcidProfile.getOrcidHistory();
deactivatedOrcidHistory.setDeactivationDate(new DeactivationDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
blankedOrcidProfile.setOrcidHistory(deactivatedOrcidHistory);
// only names names from bio with a visibility setting
PersonalDetails minimalPersonalDetails = new PersonalDetails();
minimalPersonalDetails.setOtherNames(null);
CreditName creditName = new CreditName();
creditName.setVisibility(Visibility.PUBLIC);
minimalPersonalDetails.setCreditName(creditName);
minimalPersonalDetails.setGivenNames(new GivenNames("Given Names Deactivated"));
minimalPersonalDetails.setFamilyName(new FamilyName("Family Name Deactivated"));
for (Email email : minimalContactDetails.getEmail()) {
setVisibilityToPrivate(email);
}
setVisibilityToPrivate(minimalPersonalDetails.getOtherNames());
if (minimalPersonalDetails.getOtherNames() != null && minimalPersonalDetails.getOtherNames().getOtherName() != null) {
for (OtherName name : minimalPersonalDetails.getOtherNames().getOtherName()) setVisibilityToPrivate(name);
}
minimalBio.setPersonalDetails(minimalPersonalDetails);
minimalBio.setContactDetails(minimalContactDetails);
minimalBio.setBiography(new Biography());
minimalBio.setExternalIdentifiers(new ExternalIdentifiers());
blankedOrcidProfile.setOrcidBio(minimalBio);
blankedOrcidProfile.setOrcidIdentifier(existingOrcidProfile.getOrcidIdentifier().getPath());
OrcidProfile profileToReturn = updateOrcidProfile(blankedOrcidProfile);
userConnectionDao.deleteByOrcid(existingOrcidProfile.getOrcidIdentifier().getPath());
notificationManager.sendAmendEmail(profileToReturn, AmendedSection.UNKNOWN);
return profileToReturn;
}
use of org.orcid.jaxb.model.message.OtherName in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method addDefaultVisibilityToBioItems.
private void addDefaultVisibilityToBioItems(OrcidProfile orcidProfile, Visibility defaultActivityVis, Boolean isClaimed) {
if (defaultActivityVis == null) {
defaultActivityVis = Visibility.PRIVATE;
}
if (isClaimed == null) {
isClaimed = false;
}
if (orcidProfile.getOrcidBio() != null) {
if (orcidProfile.getOrcidBio().getBiography() != null) {
if (isClaimed) {
orcidProfile.getOrcidBio().getBiography().setVisibility(defaultActivityVis);
} else {
Visibility visibility = orcidProfile.getOrcidBio().getBiography().getVisibility();
orcidProfile.getOrcidBio().getBiography().setVisibility(visibility != null ? visibility : Visibility.PRIVATE);
}
}
if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null) {
Visibility listVisibility = orcidProfile.getOrcidBio().getExternalIdentifiers().getVisibility();
for (ExternalIdentifier x : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
if (isClaimed) {
x.setVisibility(defaultActivityVis);
} else {
x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
}
}
}
if (orcidProfile.getOrcidBio().getKeywords() != null) {
Visibility listVisibility = orcidProfile.getOrcidBio().getKeywords().getVisibility();
for (Keyword x : orcidProfile.getOrcidBio().getKeywords().getKeyword()) {
if (isClaimed) {
x.setVisibility(defaultActivityVis);
} else {
x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
}
}
}
if (orcidProfile.getOrcidBio().getResearcherUrls() != null) {
Visibility listVisibility = orcidProfile.getOrcidBio().getResearcherUrls().getVisibility();
for (ResearcherUrl x : orcidProfile.getOrcidBio().getResearcherUrls().getResearcherUrl()) {
if (isClaimed) {
x.setVisibility(defaultActivityVis);
} else {
x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
}
}
}
if (orcidProfile.getOrcidBio().getPersonalDetails() != null && orcidProfile.getOrcidBio().getPersonalDetails().getOtherNames() != null) {
Visibility listVisibility = orcidProfile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility();
for (OtherName x : orcidProfile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName()) {
if (isClaimed) {
x.setVisibility(defaultActivityVis);
} else {
x.setVisibility(listVisibility != null ? listVisibility : Visibility.PRIVATE);
}
}
}
if (orcidProfile.getOrcidBio().getContactDetails() != null && orcidProfile.getOrcidBio().getContactDetails().getAddress() != null && orcidProfile.getOrcidBio().getContactDetails().getAddress().getCountry() != null) {
Country country = orcidProfile.getOrcidBio().getContactDetails().getAddress().getCountry();
if (isClaimed) {
country.setVisibility(defaultActivityVis);
} else {
country.setVisibility(country.getVisibility() != null ? country.getVisibility() : Visibility.PRIVATE);
}
}
}
}
use of org.orcid.jaxb.model.message.OtherName 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);
}
}
}
}
}
}
Aggregations