Search in sources :

Example 1 with RelevancyScore

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

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

Aggregations

BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)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 Funding (org.orcid.jaxb.model.message.Funding)2 FundingList (org.orcid.jaxb.model.message.FundingList)2 LastModifiedDate (org.orcid.jaxb.model.message.LastModifiedDate)2 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)2 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 OrcidSearchResult (org.orcid.jaxb.model.message.OrcidSearchResult)2 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)2 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)2 RelevancyScore (org.orcid.jaxb.model.message.RelevancyScore)2