use of org.orcid.jaxb.model.message.PersonalDetails in project ORCID-Source by ORCID.
the class OrcidJaxbCopyManagerTest method testUpdateCreditNamePreservingVisibility.
@Test
public void testUpdateCreditNamePreservingVisibility() throws Exception {
OrcidBio existingOrcidBioProtected = protectedOrcidMessage.getOrcidProfile().getOrcidBio();
OrcidBio updatedOrcidBioPublic = publicOrcidMessage.getOrcidProfile().getOrcidBio();
PersonalDetails existingOrcidPersonalDetails = protectedOrcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails();
PersonalDetails updatedOrcidPersonalDetails = publicOrcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails();
// set default of credit to limited on existing and null on updated
// -should remain as limited and not 'downgrade'
assertEquals(existingOrcidPersonalDetails.getCreditName().getContent(), "J. S. Carberry");
assertEquals(Visibility.LIMITED, existingOrcidPersonalDetails.getCreditName().getVisibility());
updatedOrcidPersonalDetails.setCreditName(new CreditName("Don"));
updatedOrcidPersonalDetails.getCreditName().setVisibility(Visibility.PRIVATE);
orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingOrcidBioProtected, updatedOrcidBioPublic);
assertEquals(existingOrcidPersonalDetails.getCreditName().getContent(), "Don");
assertEquals(Visibility.PRIVATE, existingOrcidPersonalDetails.getCreditName().getVisibility());
updatedOrcidPersonalDetails.setCreditName(new CreditName("Jimmy"));
updatedOrcidPersonalDetails.getCreditName().setVisibility(null);
orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingOrcidBioProtected, updatedOrcidBioPublic);
assertEquals("Don", existingOrcidBioProtected.getPersonalDetails().getCreditName().getContent());
assertEquals(Visibility.PRIVATE, existingOrcidPersonalDetails.getCreditName().getVisibility());
}
use of org.orcid.jaxb.model.message.PersonalDetails in project ORCID-Source by ORCID.
the class OrcidIndexManagerImpl method persistProfileInformationForIndexing.
@Override
@Deprecated
public void persistProfileInformationForIndexing(OrcidProfile orcidProfile) {
// Check if the profile is locked
if (orcidProfile.isLocked()) {
orcidProfile.downgradeToOrcidIdentifierOnly();
}
OrcidMessage messageToFilter = new OrcidMessage();
messageToFilter.setOrcidProfile(orcidProfile);
OrcidMessage filteredMessage = visibilityFilter.filter(messageToFilter, Visibility.PUBLIC);
OrcidProfile filteredProfile = filteredMessage.getOrcidProfile();
OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
profileIndexDocument.setOrcid(filteredProfile.getOrcidIdentifier().getPath());
OrcidDeprecated orcidDeprecated = filteredProfile.getOrcidDeprecated();
if (orcidDeprecated != null) {
profileIndexDocument.setPrimaryRecord(orcidDeprecated.getPrimaryRecord() != null ? orcidDeprecated.getPrimaryRecord().getOrcidIdentifier().getPath() : null);
}
OrcidBio orcidBio = filteredProfile.getOrcidBio();
if (orcidBio != null) {
PersonalDetails personalDetails = orcidBio.getPersonalDetails();
boolean persistPersonalDetails = personalDetails != null;
if (persistPersonalDetails) {
profileIndexDocument.setFamilyName(personalDetails.getFamilyName() != null ? personalDetails.getFamilyName().getContent() : null);
profileIndexDocument.setGivenNames(personalDetails.getGivenNames() != null ? personalDetails.getGivenNames().getContent() : null);
profileIndexDocument.setCreditName(personalDetails.getCreditName() != null ? personalDetails.getCreditName().getContent() : null);
List<OtherName> otherNames = personalDetails.getOtherNames() != null ? personalDetails.getOtherNames().getOtherName() : null;
if (otherNames != null && !otherNames.isEmpty()) {
List<String> names = new ArrayList<String>();
for (OtherName otherName : otherNames) {
names.add(otherName.getContent());
}
profileIndexDocument.setOtherNames(names);
}
}
ContactDetails contactDetails = orcidBio.getContactDetails();
if (contactDetails != null) {
for (Email email : contactDetails.getEmail()) {
profileIndexDocument.addEmailAddress(email.getValue());
}
}
ExternalIdentifiers externalIdentifiers = orcidBio.getExternalIdentifiers();
if (externalIdentifiers != null) {
List<String> extIdOrcids = new ArrayList<String>();
List<String> extIdRefs = new ArrayList<String>();
List<String> extIdOrcidsAndRefs = new ArrayList<String>();
for (ExternalIdentifier externalIdentifier : externalIdentifiers.getExternalIdentifier()) {
Source source = externalIdentifier.getSource();
String sourcePath = null;
if (source != null) {
sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
extIdOrcids.add(sourcePath);
}
}
ExternalIdReference externalIdReference = externalIdentifier.getExternalIdReference();
if (externalIdReference != null) {
extIdRefs.add(externalIdReference.getContent());
}
if (NullUtils.noneNull(sourcePath, externalIdReference)) {
extIdOrcidsAndRefs.add(sourcePath + "=" + externalIdReference.getContent());
}
}
if (!extIdOrcids.isEmpty()) {
profileIndexDocument.setExternalIdSources(extIdOrcids);
}
if (!extIdRefs.isEmpty()) {
profileIndexDocument.setExternalIdReferences(extIdRefs);
}
if (!extIdOrcidsAndRefs.isEmpty()) {
profileIndexDocument.setExternalIdSourcesAndReferences(extIdOrcidsAndRefs);
}
}
OrcidActivities orcidActivities = filteredProfile.getOrcidActivities();
if (orcidActivities != null) {
// Affiliations affiliations =
// orcidActivities.getAffiliations();
// if (affiliations != null) {
// List<Affiliation> pastInsts = affiliations
// .getAffiliationsByType(AffiliationType.PAST_INSTITUTION);
// if (pastInsts != null && !pastInsts.isEmpty()) {
// List<String> pastInstNames = new ArrayList<String>();
// for (Affiliation pastAffiliation : pastInsts) {
// pastInstNames.add(pastAffiliation
// .getAffiliationName());
// }
//
// profileIndexDocument
// .setAffiliatePastInstitutionNames(pastInstNames);
// }
//
// List<Affiliation> primaryInsts = affiliations
// .getAffiliationsByType(AffiliationType.CURRENT_PRIMARY_INSTITUTION);
// if (primaryInsts != null && !primaryInsts.isEmpty()) {
// List<String> primaryInstNames = new ArrayList<String>();
// for (Affiliation primaryAffiliation : primaryInsts) {
// primaryInstNames.add(primaryAffiliation
// .getAffiliationName());
// }
//
// profileIndexDocument
// .setAffiliatePrimaryInstitutionNames(primaryInstNames);
// }
//
// List<Affiliation> currentNonPrimaryInsts = affiliations
// .getAffiliationsByType(AffiliationType.CURRENT_INSTITUTION);
// if (currentNonPrimaryInsts != null
// && !currentNonPrimaryInsts.isEmpty()) {
// List<String> affiliateInstNames = new ArrayList<String>();
// for (Affiliation currentAffiliation : currentNonPrimaryInsts)
// {
// affiliateInstNames.add(currentAffiliation
// .getAffiliationName());
// }
//
// profileIndexDocument
// .setAffiliateInstitutionNames(affiliateInstNames);
// }
// }
List<String> keywords = extractKeywordsAsStringFromBio(orcidBio);
if (keywords != null) {
profileIndexDocument.setKeywords(keywords);
}
}
List<OrcidWork> orcidWorks = filteredProfile.retrieveOrcidWorks() != null ? filteredProfile.retrieveOrcidWorks().getOrcidWork() : null;
if (orcidWorks != null) {
List<String> workTitles = new ArrayList<String>();
Map<WorkExternalIdentifierType, List<String>> allExternalIdentifiers = new HashMap<WorkExternalIdentifierType, List<String>>();
for (OrcidWork orcidWork : orcidWorks) {
if (orcidWork.getWorkExternalIdentifiers() != null) {
for (WorkExternalIdentifier workExternalIdentifier : orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
/**
* Creates a map that contains all different
* external identifiers for the current work
* */
if (nullSafeCheckForWorkExternalIdentifier(workExternalIdentifier)) {
WorkExternalIdentifierType type = workExternalIdentifier.getWorkExternalIdentifierType();
if (!allExternalIdentifiers.containsKey(type)) {
List<String> content = new ArrayList<String>();
content.add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
allExternalIdentifiers.put(type, content);
} else {
allExternalIdentifiers.get(type).add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
}
}
}
}
if (orcidWork.getWorkTitle() != null) {
Title workMainTitle = orcidWork.getWorkTitle().getTitle();
Subtitle worksubTitle = orcidWork.getWorkTitle().getSubtitle();
TranslatedTitle translatedTitle = orcidWork.getWorkTitle().getTranslatedTitle();
if (workMainTitle != null && !StringUtils.isBlank(workMainTitle.getContent())) {
workTitles.add(workMainTitle.getContent());
}
if (worksubTitle != null && !StringUtils.isBlank(worksubTitle.getContent())) {
workTitles.add(worksubTitle.getContent());
}
if (translatedTitle != null && !StringUtils.isBlank(translatedTitle.getContent())) {
workTitles.add(translatedTitle.getContent());
}
}
}
profileIndexDocument.setWorkTitles(workTitles);
// Set the list of external identifiers to the document list
addExternalIdentifiersToIndexDocument(profileIndexDocument, allExternalIdentifiers);
}
List<Funding> orcidFundings = filteredProfile.retrieveFundings() != null ? filteredProfile.retrieveFundings().getFundings() : null;
if (orcidFundings != null) {
List<String> fundingTitle = new ArrayList<String>();
for (Funding orcidFunding : orcidFundings) {
FundingTitle title = orcidFunding.getTitle();
if (title != null) {
if (title.getTitle() != null && !StringUtils.isBlank(title.getTitle().getContent())) {
fundingTitle.add(title.getTitle().getContent());
}
if (title.getTranslatedTitle() != null && StringUtils.isBlank(title.getTranslatedTitle().getContent())) {
fundingTitle.add(title.getTranslatedTitle().getContent());
}
}
}
profileIndexDocument.setFundingTitles(fundingTitle);
}
}
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
orcidMessage.setOrcidProfile(filteredProfile);
OrcidHistory orcidHistory = filteredProfile.getOrcidHistory();
if (orcidHistory != null) {
LastModifiedDate lastModifiedDate = orcidHistory.getLastModifiedDate();
if (lastModifiedDate != null) {
profileIndexDocument.setProfileLastModifiedDate(lastModifiedDate.getValue().toGregorianCalendar().getTime());
}
SubmissionDate submissionDate = orcidHistory.getSubmissionDate();
if (submissionDate != null) {
profileIndexDocument.setProfileSubmissionDate(submissionDate.getValue().toGregorianCalendar().getTime());
}
}
if (indexPublicProfile) {
profileIndexDocument.setPublicProfileMessage(orcidMessage.toXmlString());
}
solrDao.persist(profileIndexDocument);
}
use of org.orcid.jaxb.model.message.PersonalDetails in project ORCID-Source by ORCID.
the class NotificationManagerImpl method deriveEmailFriendlyName.
@Override
public String deriveEmailFriendlyName(OrcidProfile orcidProfile) {
if (orcidProfile.getOrcidBio() != null && orcidProfile.getOrcidBio().getPersonalDetails() != null) {
PersonalDetails personalDetails = orcidProfile.getOrcidBio().getPersonalDetails();
// all...
if (personalDetails.getCreditName() != null)
if (!PojoUtil.isEmpty(personalDetails.getCreditName().getContent()))
return personalDetails.getCreditName().getContent();
if (personalDetails.getGivenNames() != null) {
String givenName = personalDetails.getGivenNames().getContent();
String familyName = personalDetails.getFamilyName() != null && !StringUtils.isBlank(personalDetails.getFamilyName().getContent()) ? " " + personalDetails.getFamilyName().getContent() : "";
return givenName + familyName;
}
}
return LAST_RESORT_ORCID_USER_EMAIL_NAME;
}
use of org.orcid.jaxb.model.message.PersonalDetails in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method createGroupProfile.
private OrcidProfile createGroupProfile(OrcidClientGroup orcidClientGroup) {
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setType(OrcidType.GROUP);
orcidProfile.setGroupType(orcidClientGroup.getType());
OrcidHistory orcidHistory = new OrcidHistory();
orcidProfile.setOrcidHistory(orcidHistory);
orcidHistory.setClaimed(new Claimed(true));
orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
OrcidBio orcidBio = new OrcidBio();
orcidProfile.setOrcidBio(orcidBio);
PersonalDetails personalDetails = new PersonalDetails();
orcidBio.setPersonalDetails(personalDetails);
personalDetails.setCreditName(new CreditName(orcidClientGroup.getGroupName()));
ContactDetails contactDetails = new ContactDetails();
orcidBio.setContactDetails(contactDetails);
Email primaryEmail = new Email(orcidClientGroup.getEmail());
primaryEmail.setVisibility(Visibility.PRIVATE);
primaryEmail.setVerified(true);
contactDetails.addOrReplacePrimaryEmail(primaryEmail);
if (!PojoUtil.isEmpty(orcidClientGroup.getSalesforceId())) {
OrcidInternal orcidInternal = new OrcidInternal();
orcidInternal.setSalesforceId(new SalesforceId(orcidClientGroup.getSalesforceId()));
orcidProfile.setOrcidInternal(orcidInternal);
}
return orcidProfile;
}
use of org.orcid.jaxb.model.message.PersonalDetails in project ORCID-Source by ORCID.
the class OrcidJaxbCopyManagerImpl method copyUpdatedPersonalDetailsToExistingPreservingVisibility.
@Override
public void copyUpdatedPersonalDetailsToExistingPreservingVisibility(OrcidBio existing, OrcidBio updated) {
PersonalDetails existingPersonalDetails = existing.getPersonalDetails();
PersonalDetails updatedPersonalDetails = updated.getPersonalDetails();
// if no update, nothing to do
if (updatedPersonalDetails == null) {
return;
}
// compare to
if (existingPersonalDetails == null) {
existing.setPersonalDetails(updatedPersonalDetails);
return;
}
// otherwise preserve visibility of other names && credit names
copyOtherNamesPreservingVisibility(existingPersonalDetails, updatedPersonalDetails);
copyCreditNamePreservingVisibility(existingPersonalDetails, updatedPersonalDetails);
if (updatedPersonalDetails.getFamilyName() != null && !PojoUtil.isEmpty(updatedPersonalDetails.getFamilyName().getContent())) {
existingPersonalDetails.setFamilyName(updatedPersonalDetails.getFamilyName());
}
if (updatedPersonalDetails.getGivenNames() != null && !PojoUtil.isEmpty(updatedPersonalDetails.getGivenNames().getContent())) {
existingPersonalDetails.setGivenNames(updatedPersonalDetails.getGivenNames());
}
}
Aggregations