Search in sources :

Example 56 with OrcidBio

use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.

the class OrcidProfileToSolrDocument method convert.

@Deprecated
public OrcidSolrDocument convert(OrcidProfile profile) {
    // Check if the profile is locked
    if (profile.isLocked()) {
        profile.downgradeToOrcidIdentifierOnly();
    }
    OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
    profileIndexDocument.setOrcid(profile.getOrcidIdentifier().getPath());
    OrcidDeprecated orcidDeprecated = profile.getOrcidDeprecated();
    if (orcidDeprecated != null) {
        profileIndexDocument.setPrimaryRecord(orcidDeprecated.getPrimaryRecord() != null ? orcidDeprecated.getPrimaryRecord().getOrcidIdentifier().getPath() : null);
    }
    OrcidBio orcidBio = profile.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 = profile.getOrcidActivities();
        if (orcidActivities != null) {
            if (orcidBio != null && orcidBio.getKeywords() != null) {
                List<Keyword> keyWords = orcidBio.getKeywords().getKeyword();
                if (keyWords != null && keyWords.size() > 0) {
                    List<String> keywordValues = new ArrayList<String>();
                    for (Keyword keyword : keyWords) {
                        keywordValues.add(keyword.getContent());
                    }
                    profileIndexDocument.setKeywords(keywordValues);
                }
            }
        }
        List<OrcidWork> orcidWorks = profile.retrieveOrcidWorks() != null ? profile.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
                             */
                        boolean nullSafeCheckForWorkExternalIdentifier = workExternalIdentifier.getWorkExternalIdentifierId() != null && !StringUtils.isBlank(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
                        if (nullSafeCheckForWorkExternalIdentifier) {
                            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 = profile.retrieveFundings() != null ? profile.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(profile);
    OrcidHistory orcidHistory = profile.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());
        }
    }
    return profileIndexDocument;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) Email(org.orcid.jaxb.model.message.Email) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) HashMap(java.util.HashMap) Funding(org.orcid.jaxb.model.message.Funding) ArrayList(java.util.ArrayList) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ArrayList(java.util.ArrayList) List(java.util.List) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) WorkExternalIdentifierType(org.orcid.jaxb.model.message.WorkExternalIdentifierType) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) Keyword(org.orcid.jaxb.model.message.Keyword) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherName(org.orcid.jaxb.model.message.OtherName) Title(org.orcid.jaxb.model.message.Title) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Subtitle(org.orcid.jaxb.model.message.Subtitle) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated)

Aggregations

OrcidBio (org.orcid.jaxb.model.message.OrcidBio)56 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)38 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)28 Test (org.junit.Test)27 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)23 Email (org.orcid.jaxb.model.message.Email)20 GivenNames (org.orcid.jaxb.model.message.GivenNames)20 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)19 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)16 FamilyName (org.orcid.jaxb.model.message.FamilyName)16 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)15 CreditName (org.orcid.jaxb.model.message.CreditName)14 BaseTest (org.orcid.core.BaseTest)13 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)11 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)11 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)10 ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)9 OtherNames (org.orcid.jaxb.model.message.OtherNames)9 Biography (org.orcid.jaxb.model.message.Biography)8 Keyword (org.orcid.jaxb.model.message.Keyword)8