Search in sources :

Example 16 with OrcidSearchResult

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

the class OrcidSearchManagerImpl method findOrcidsByQuery.

@Override
public OrcidMessage findOrcidsByQuery(Map<String, List<String>> query) {
    OrcidMessage orcidMessage = new OrcidMessage();
    OrcidSearchResults searchResults = new OrcidSearchResults();
    OrcidSolrResults orcidSolrResults = solrDao.findByDocumentCriteria(query);
    searchResults.setNumFound(orcidSolrResults.getNumFound());
    List<OrcidSolrResult> indexedOrcids = orcidSolrResults.getResults();
    if (indexedOrcids != null && !indexedOrcids.isEmpty()) {
        List<OrcidSearchResult> orcidSearchResults = buildSearchResultsFromPublicProfile(indexedOrcids);
        searchResults.getOrcidSearchResult().addAll(orcidSearchResults);
    }
    orcidMessage.setOrcidSearchResults(searchResults);
    return orcidMessage;
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) OrcidSearchResults(org.orcid.jaxb.model.message.OrcidSearchResults) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults)

Example 17 with OrcidSearchResult

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

the class RegistrationController method findPotentialDuplicatesByFirstNameLastName.

private List<OrcidProfile> findPotentialDuplicatesByFirstNameLastName(String firstName, String lastName) {
    LOGGER.debug("About to search for potential duplicates during registration for first name={}, last name={}", firstName, lastName);
    List<OrcidProfile> orcidProfiles = new ArrayList<OrcidProfile>();
    SearchOrcidSolrCriteria queryForm = new SearchOrcidSolrCriteria();
    queryForm.setGivenName(firstName);
    queryForm.setFamilyName(lastName);
    String query = queryForm.deriveQueryString();
    OrcidMessage visibleProfiles = orcidSearchManager.findOrcidsByQuery(query, DUP_SEARCH_START, DUP_SEARCH_ROWS);
    if (visibleProfiles.getOrcidSearchResults() != null) {
        for (OrcidSearchResult searchResult : visibleProfiles.getOrcidSearchResults().getOrcidSearchResult()) {
            orcidProfiles.add(searchResult.getOrcidProfile());
        }
    }
    LOGGER.debug("Found {} potential duplicates during registration for first name={}, last name={}", new Object[] { orcidProfiles.size(), firstName, lastName });
    return orcidProfiles;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) SearchOrcidSolrCriteria(org.orcid.frontend.web.controllers.helper.SearchOrcidSolrCriteria) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ArrayList(java.util.ArrayList)

Example 18 with OrcidSearchResult

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

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

the class OrcidSearchManagerImplTest method recordDeactivatedTest.

@Test
public void recordDeactivatedTest() {
    OrcidProfile orcidProfile = getOrcidProfileAllIndexFieldsPopulated();
    orcidProfile.getOrcidIdentifier().setPath("0000");
    when(mockSolrDao.findByDocumentCriteria("rndQuery", null, null)).thenReturn(invalidRecordSearchResult());
    when(mockOrcidProfileCacheManager.retrievePublicBio("0000")).thenReturn(orcidProfile);
    doThrow(new DeactivatedException()).when(mockOrcidSecurityManager).checkProfile("0000");
    OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidsByQuery("rndQuery");
    assertNotNull(retrievedOrcidMessage);
    assertTrue(retrievedOrcidMessage.getOrcidSearchResults() != null && retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().size() == 1);
    OrcidSearchResult searchResult = retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().get(0);
    OrcidProfile profileReturnedFromSearch = searchResult.getOrcidProfile();
    assertEquals("0000", profileReturnedFromSearch.getOrcidIdentifier().getPath());
    assertNotNull(profileReturnedFromSearch.getOrcidHistory().getLastModifiedDate().getValue());
    assertNull(profileReturnedFromSearch.getOrcidActivities());
    assertNull(profileReturnedFromSearch.getOrcidBio());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) DeactivatedException(org.orcid.core.exception.DeactivatedException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 20 with OrcidSearchResult

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

the class OrcidSearchManagerImplTest method orcidRetrievalAllDataPresentInDb.

@Test
@Rollback
public void orcidRetrievalAllDataPresentInDb() throws Exception {
    when(mockSolrDao.findByOrcid("1434")).thenReturn(getOrcidSolrResult("5678", new Float(37.2)));
    when(mockOrcidProfileCacheManager.retrievePublicBio("5678")).thenReturn(getOrcidProfileAllIndexFieldsPopulated());
    String orcid = "1434";
    // demonstrate that the mapping from solr (profile 1234) and dao (5678)
    // are truly seperate - the search results only return a subset of the
    // full orcid
    // because we want to keep the payload down.
    OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidSearchResultsById(orcid);
    assertNotNull(retrievedOrcidMessage);
    assertTrue(retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().size() == 1);
    OrcidSearchResult result = retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().get(0);
    assertTrue(new Float(37.2).compareTo(result.getRelevancyScore().getValue()) == 0);
    OrcidProfile retrievedProfile = result.getOrcidProfile();
    assertEquals("5678", retrievedProfile.getOrcidIdentifier().getPath());
    OrcidBio orcidBio = retrievedProfile.getOrcidBio();
    assertEquals("Logan", orcidBio.getPersonalDetails().getFamilyName().getContent());
    assertEquals("Donald Edward", orcidBio.getPersonalDetails().getGivenNames().getContent());
    assertEquals("Stanley Higgins", orcidBio.getPersonalDetails().getCreditName().getContent());
    List<String> otherNames = orcidBio.getPersonalDetails().getOtherNames().getOtherNamesAsStrings();
    assertTrue(otherNames.contains("Edward Bass"));
    assertTrue(otherNames.contains("Gareth Dove"));
    OrcidWorks orcidWorks = retrievedProfile.retrieveOrcidWorks();
    OrcidWork orcidWork1 = orcidWorks.getOrcidWork().get(0);
    OrcidWork orcidWork2 = orcidWorks.getOrcidWork().get(1);
    assertTrue(orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().size() == 1);
    assertEquals("work1-doi1", orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
    assertTrue(orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().size() == 2);
    assertEquals("work2-doi1", orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
    assertEquals("work2-doi2", orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(1).getWorkExternalIdentifierId().getContent());
    List<Funding> fundings = retrievedProfile.retrieveFundings().getFundings();
    Funding funding1 = fundings.get(0);
    Funding funding2 = fundings.get(1);
    // check returns a reduced payload
    assertNotNull(funding1.getTitle());
    assertNotNull(funding1.getTitle().getTitle());
    assertEquals("grant1", funding1.getTitle().getTitle().getContent());
    assertEquals("Grant 1 - a short description", funding1.getDescription());
    assertNull(funding1.getPutCode());
    assertNotNull(funding2.getTitle());
    assertNotNull(funding2.getTitle().getTitle());
    assertEquals("grant2", funding2.getTitle().getTitle().getContent());
    assertEquals("Grant 2 - a short description", funding2.getDescription());
    assertNull(funding2.getPutCode());
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Funding(org.orcid.jaxb.model.message.Funding) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)26 OrcidSearchResult (org.orcid.jaxb.model.message.OrcidSearchResult)26 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)19 Test (org.junit.Test)15 BaseTest (org.orcid.core.BaseTest)14 OrcidSearchResults (org.orcid.jaxb.model.message.OrcidSearchResults)8 OrcidSolrResult (org.orcid.utils.solr.entities.OrcidSolrResult)8 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)7 Rollback (org.springframework.test.annotation.Rollback)6 ArrayList (java.util.ArrayList)5 DeactivatedException (org.orcid.core.exception.DeactivatedException)4 OrcidDeprecatedException (org.orcid.core.exception.OrcidDeprecatedException)4 LockedException (org.orcid.core.security.aop.LockedException)4 Funding (org.orcid.jaxb.model.message.Funding)4 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)4 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)4 OrcidSolrResults (org.orcid.utils.solr.entities.OrcidSolrResults)4 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2