Search in sources :

Example 1 with LastModifiedDate

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

the class OrcidSearchManagerImpl method buildSearchResultsFromPublicProfile.

private List<OrcidSearchResult> buildSearchResultsFromPublicProfile(List<OrcidSolrResult> solrResults) {
    List<OrcidSearchResult> orcidSearchResults = new ArrayList<OrcidSearchResult>();
    for (OrcidSolrResult solrResult : solrResults) {
        OrcidMessage orcidMessage = null;
        String orcid = solrResult.getOrcid();
        try {
            orcidSecurityManager.checkProfile(orcid);
        } catch (DeactivatedException | LockedException | OrcidDeprecatedException x) {
            OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
            RelevancyScore relevancyScore = new RelevancyScore();
            relevancyScore.setValue(solrResult.getRelevancyScore());
            orcidSearchResult.setRelevancyScore(relevancyScore);
            OrcidProfile orcidProfile = new OrcidProfile();
            orcidProfile.setOrcidIdentifier(new OrcidIdentifier(jpaJaxbAdapter.getOrcidIdBase(orcid)));
            OrcidHistory history = new OrcidHistory();
            Date recordLastModified = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
            history.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(recordLastModified)));
            orcidProfile.setOrcidHistory(history);
            orcidSearchResult.setOrcidProfile(orcidProfile);
            orcidSearchResults.add(orcidSearchResult);
            continue;
        }
        if (cachingSource.equals(SOLR)) {
            try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
                if (reader != null) {
                    BufferedReader br = new BufferedReader(reader);
                    orcidMessage = OrcidMessage.unmarshall(br);
                }
            } catch (IOException e) {
                throw new OrcidSearchException("Error closing record stream from solr search results for orcid: " + orcid, e);
            }
        }
        OrcidProfile orcidProfile = null;
        if (orcidMessage == null) {
            // Fall back to DB
            orcidProfile = orcidProfileCacheManager.retrievePublicBio(orcid);
        } else {
            orcidProfile = orcidMessage.getOrcidProfile();
        }
        if (orcidProfile != null) {
            OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
            RelevancyScore relevancyScore = new RelevancyScore();
            relevancyScore.setValue(solrResult.getRelevancyScore());
            orcidSearchResult.setRelevancyScore(relevancyScore);
            OrcidWorks orcidWorksTitlesOnly = new OrcidWorks();
            OrcidWorks fullOrcidWorks = orcidProfile.retrieveOrcidWorks();
            if (fullOrcidWorks != null && !fullOrcidWorks.getOrcidWork().isEmpty()) {
                for (OrcidWork fullOrcidWork : fullOrcidWorks.getOrcidWork()) {
                    OrcidWork orcidWorkSubset = new OrcidWork();
                    orcidWorkSubset.setVisibility(fullOrcidWork.getVisibility());
                    orcidWorkSubset.setWorkTitle(fullOrcidWork.getWorkTitle());
                    orcidWorkSubset.setWorkExternalIdentifiers(fullOrcidWork.getWorkExternalIdentifiers());
                    orcidWorksTitlesOnly.getOrcidWork().add(orcidWorkSubset);
                }
            }
            FundingList reducedFundings = new FundingList();
            FundingList fullOrcidFundings = orcidProfile.retrieveFundings();
            if (fullOrcidFundings != null && !fullOrcidFundings.getFundings().isEmpty()) {
                for (Funding fullOrcidFunding : fullOrcidFundings.getFundings()) {
                    Funding reducedFunding = new Funding();
                    reducedFunding.setVisibility(fullOrcidFunding.getVisibility());
                    reducedFunding.setDescription(fullOrcidFunding.getDescription());
                    reducedFunding.setTitle(fullOrcidFunding.getTitle());
                    reducedFundings.getFundings().add(reducedFunding);
                }
            }
            orcidProfile.setOrcidWorks(orcidWorksTitlesOnly);
            orcidProfile.setFundings(reducedFundings);
            orcidSearchResult.setOrcidProfile(orcidProfile);
            orcidSearchResults.add(orcidSearchResult);
        }
    }
    return orcidSearchResults;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) LockedException(org.orcid.core.security.aop.LockedException) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) Funding(org.orcid.jaxb.model.message.Funding) ArrayList(java.util.ArrayList) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Date(java.util.Date) LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) DeactivatedException(org.orcid.core.exception.DeactivatedException) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) RelevancyScore(org.orcid.jaxb.model.message.RelevancyScore) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) FundingList(org.orcid.jaxb.model.message.FundingList) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) BufferedReader(java.io.BufferedReader)

Example 2 with LastModifiedDate

use of org.orcid.jaxb.model.message.LastModifiedDate 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);
}
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) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) 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) 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)

Example 3 with LastModifiedDate

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

the class OrcidSearchManagerImpl method buildSearchResultsFromPublicProfile.

private List<OrcidSearchResult> buildSearchResultsFromPublicProfile(List<OrcidSolrResult> solrResults) {
    List<OrcidSearchResult> orcidSearchResults = new ArrayList<OrcidSearchResult>();
    for (OrcidSolrResult solrResult : solrResults) {
        OrcidMessage orcidMessage = null;
        String orcid = solrResult.getOrcid();
        try {
            orcidSecurityManager.checkProfile(orcid);
        } catch (DeactivatedException | LockedException | OrcidDeprecatedException x) {
            OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
            RelevancyScore relevancyScore = new RelevancyScore();
            relevancyScore.setValue(solrResult.getRelevancyScore());
            orcidSearchResult.setRelevancyScore(relevancyScore);
            OrcidProfile orcidProfile = new OrcidProfile();
            orcidProfile.setOrcidIdentifier(new OrcidIdentifier(jpaJaxbAdapter.getOrcidIdBase(orcid)));
            OrcidHistory history = new OrcidHistory();
            Date recordLastModified = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
            history.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(recordLastModified)));
            orcidProfile.setOrcidHistory(history);
            orcidSearchResult.setOrcidProfile(orcidProfile);
            orcidSearchResults.add(orcidSearchResult);
            continue;
        }
        if (cachingSource.equals(SOLR)) {
            try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
                if (reader != null) {
                    BufferedReader br = new BufferedReader(reader);
                    orcidMessage = OrcidMessage.unmarshall(br);
                }
            } catch (IOException e) {
                throw new OrcidSearchException("Error closing record stream from solr search results for orcid: " + orcid, e);
            }
        }
        OrcidProfile orcidProfile = null;
        if (orcidMessage == null) {
            // Fall back to DB
            orcidProfile = orcidProfileCacheManager.retrievePublicBio(orcid);
        } else {
            orcidProfile = orcidMessage.getOrcidProfile();
        }
        if (orcidProfile != null) {
            OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
            RelevancyScore relevancyScore = new RelevancyScore();
            relevancyScore.setValue(solrResult.getRelevancyScore());
            orcidSearchResult.setRelevancyScore(relevancyScore);
            OrcidWorks orcidWorksTitlesOnly = new OrcidWorks();
            OrcidWorks fullOrcidWorks = orcidProfile.retrieveOrcidWorks();
            if (fullOrcidWorks != null && !fullOrcidWorks.getOrcidWork().isEmpty()) {
                for (OrcidWork fullOrcidWork : fullOrcidWorks.getOrcidWork()) {
                    OrcidWork orcidWorkSubset = new OrcidWork();
                    orcidWorkSubset.setVisibility(fullOrcidWork.getVisibility());
                    orcidWorkSubset.setWorkTitle(fullOrcidWork.getWorkTitle());
                    orcidWorkSubset.setWorkExternalIdentifiers(fullOrcidWork.getWorkExternalIdentifiers());
                    orcidWorksTitlesOnly.getOrcidWork().add(orcidWorkSubset);
                }
            }
            FundingList reducedFundings = new FundingList();
            FundingList fullOrcidFundings = orcidProfile.retrieveFundings();
            if (fullOrcidFundings != null && !fullOrcidFundings.getFundings().isEmpty()) {
                for (Funding fullOrcidFunding : fullOrcidFundings.getFundings()) {
                    Funding reducedFunding = new Funding();
                    reducedFunding.setVisibility(fullOrcidFunding.getVisibility());
                    reducedFunding.setDescription(fullOrcidFunding.getDescription());
                    reducedFunding.setTitle(fullOrcidFunding.getTitle());
                    reducedFundings.getFundings().add(reducedFunding);
                }
            }
            orcidProfile.setOrcidWorks(orcidWorksTitlesOnly);
            orcidProfile.setFundings(reducedFundings);
            orcidSearchResult.setOrcidProfile(orcidProfile);
            orcidSearchResults.add(orcidSearchResult);
        }
    }
    return orcidSearchResults;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) LockedException(org.orcid.core.security.aop.LockedException) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) Funding(org.orcid.jaxb.model.message.Funding) ArrayList(java.util.ArrayList) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Date(java.util.Date) LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) DeactivatedException(org.orcid.core.exception.DeactivatedException) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) RelevancyScore(org.orcid.jaxb.model.message.RelevancyScore) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) FundingList(org.orcid.jaxb.model.message.FundingList) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) BufferedReader(java.io.BufferedReader)

Example 4 with LastModifiedDate

use of org.orcid.jaxb.model.message.LastModifiedDate 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)

Example 5 with LastModifiedDate

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

the class T2OrcidApiServiceVersionedDelegatorTest method testCreateProfileWithInvalidHistoryElements.

@Test
public void testCreateProfileWithInvalidHistoryElements() {
    OrcidMessage orcidMessage = createStubOrcidMessage();
    orcidMessage.setMessageVersion("1.2");
    // Claimed should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setClaimed(new Claimed(false));
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Claimed status should not be specified when creating a profile"));
    }
    // Creation method should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setCreationMethod(CreationMethod.API);
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Creation method should not be specified when creating a profile"));
    }
    // Completion date should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setCompletionDate(new CompletionDate());
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Completion date should not be specified when creating a profile"));
    }
    // Submission date should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setSubmissionDate(new SubmissionDate());
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Submission date should not be specified when creating a profile"));
    }
    // Last modified date should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setLastModifiedDate(new LastModifiedDate());
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Last modified date should not be specified when creating a profile"));
    }
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) CompletionDate(org.orcid.jaxb.model.message.CompletionDate) Claimed(org.orcid.jaxb.model.message.Claimed) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

LastModifiedDate (org.orcid.jaxb.model.message.LastModifiedDate)5 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)5 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)5 ArrayList (java.util.ArrayList)4 Funding (org.orcid.jaxb.model.message.Funding)4 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)4 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DeactivatedException (org.orcid.core.exception.DeactivatedException)2 OrcidDeprecatedException (org.orcid.core.exception.OrcidDeprecatedException)2 OrcidSearchException (org.orcid.core.exception.OrcidSearchException)2 LockedException (org.orcid.core.security.aop.LockedException)2 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)2 Email (org.orcid.jaxb.model.message.Email)2