Search in sources :

Example 6 with Search

use of org.orcid.jaxb.model.search_v2.Search in project ORCID-Source by ORCID.

the class OrcidSearchManagerImpl method findOrcidIds.

@Override
public Search findOrcidIds(Map<String, List<String>> queryParameters) {
    Search search = new Search();
    OrcidSolrResults orcidSolrResults = solrDao.findByDocumentCriteria(queryParameters);
    if (orcidSolrResults != null && orcidSolrResults.getResults() != null) {
        List<Result> orcidIdList = orcidSolrResults.getResults().stream().map(r -> {
            Result result = new Result();
            result.setOrcidIdentifier(recordManagerReadOnly.getOrcidIdentifier(r.getOrcid()));
            return result;
        }).collect(Collectors.toList());
        search.getResults().addAll(orcidIdList);
        search.setNumFound(orcidSolrResults.getNumFound());
    } else {
        search.setNumFound(0L);
    }
    return search;
}
Also used : OrcidProfileCacheManager(org.orcid.core.manager.OrcidProfileCacheManager) Arrays(java.util.Arrays) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) ArrayList(java.util.ArrayList) Search(org.orcid.jaxb.model.search_v2.Search) Value(org.springframework.beans.factory.annotation.Value) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults) Result(org.orcid.jaxb.model.search_v2.Result) Map(java.util.Map) RecordManagerReadOnly(org.orcid.core.manager.read_only.RecordManagerReadOnly) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Resource(javax.annotation.Resource) FundingList(org.orcid.jaxb.model.message.FundingList) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) OrcidSearchManager(org.orcid.core.manager.OrcidSearchManager) OrcidSearchResults(org.orcid.jaxb.model.message.OrcidSearchResults) List(java.util.List) Funding(org.orcid.jaxb.model.message.Funding) RelevancyScore(org.orcid.jaxb.model.message.RelevancyScore) BufferedReader(java.io.BufferedReader) SolrDao(org.orcid.persistence.dao.SolrDao) Required(org.springframework.beans.factory.annotation.Required) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Search(org.orcid.jaxb.model.search_v2.Search) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults) Result(org.orcid.jaxb.model.search_v2.Result) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult)

Example 7 with Search

use of org.orcid.jaxb.model.search_v2.Search in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_GeneralTest method testSearchByQuery.

@Test
public void testSearchByQuery() {
    Search search = new Search();
    Result result = new Result();
    result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id"));
    search.getResults().add(result);
    OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class);
    Mockito.when(orcidSearchManager.findOrcidIds(Matchers.<Map<String, List<String>>>any())).thenReturn(search);
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.doNothing().when(orcidSecurityManager).checkScopes(Mockito.any(ScopePathType.class));
    MemberV2ApiServiceDelegatorImpl delegator = new MemberV2ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    Response response = delegator.searchByQuery(new HashMap<String, List<String>>());
    assertNotNull(response);
    assertNotNull(response.getEntity());
    assertTrue(response.getEntity() instanceof Search);
    assertEquals(1, ((Search) response.getEntity()).getResults().size());
    assertEquals("some-orcid-id", ((Search) response.getEntity()).getResults().get(0).getOrcidIdentifier().getPath());
}
Also used : Response(javax.ws.rs.core.Response) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Search(org.orcid.jaxb.model.search_v2.Search) MemberV2ApiServiceDelegatorImpl(org.orcid.api.memberV2.server.delegator.impl.MemberV2ApiServiceDelegatorImpl) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) List(java.util.List) OrcidSearchManager(org.orcid.core.manager.OrcidSearchManager) Result(org.orcid.jaxb.model.search_v2.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 8 with Search

use of org.orcid.jaxb.model.search_v2.Search in project ORCID-Source by ORCID.

the class OrcidSearchManagerImplTest method testFindOrcidIds.

@Test
public void testFindOrcidIds() {
    when(solrDao.findByDocumentCriteria(Matchers.<Map<String, List<String>>>any())).thenReturn(multipleResultsForQuery());
    Search search = orcidSearchManager.findOrcidIds(new HashMap<>());
    assertNotNull(search);
    assertEquals(2, search.getResults().size());
    assertEquals(Long.valueOf(2), search.getNumFound());
    assertEquals("5678", search.getResults().get(0).getOrcidIdentifier().getPath());
    assertEquals("6789", search.getResults().get(1).getOrcidIdentifier().getPath());
}
Also used : Search(org.orcid.jaxb.model.search_v2.Search) ArrayList(java.util.ArrayList) FundingList(org.orcid.jaxb.model.message.FundingList) List(java.util.List) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 9 with Search

use of org.orcid.jaxb.model.search_v2.Search in project ORCID-Source by ORCID.

the class OrcidSearchManagerImplTest method testFindOrcidIdsNoResults.

@Test
public void testFindOrcidIdsNoResults() {
    when(solrDao.findByDocumentCriteria(Matchers.<Map<String, List<String>>>any())).thenReturn(new OrcidSolrResults());
    Search search = orcidSearchManager.findOrcidIds(new HashMap<>());
    assertNotNull(search);
    assertEquals(Long.valueOf(0), search.getNumFound());
    assertEquals(0, search.getResults().size());
}
Also used : Search(org.orcid.jaxb.model.search_v2.Search) ArrayList(java.util.ArrayList) FundingList(org.orcid.jaxb.model.message.FundingList) List(java.util.List) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 10 with Search

use of org.orcid.jaxb.model.search_v2.Search in project ORCID-Source by ORCID.

the class PublicV2ApiServiceVersionedDelegatorTest method testSearchByQuery.

@Test
public void testSearchByQuery() {
    Search search = new Search();
    Result result = new Result();
    result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id"));
    search.getResults().add(result);
    Response searchResponse = Response.ok(search).build();
    PublicV2ApiServiceDelegatorImpl delegator = Mockito.mock(PublicV2ApiServiceDelegatorImpl.class);
    Mockito.when(delegator.searchByQuery(Matchers.<Map<String, List<String>>>any())).thenReturn(searchResponse);
    PublicV2ApiServiceVersionedDelegatorImpl versionedDelegator = new PublicV2ApiServiceVersionedDelegatorImpl();
    versionedDelegator.setMemberV2ApiServiceDelegator(delegator);
    Response response = versionedDelegator.searchByQuery(new HashMap<String, List<String>>());
    // just testing MemberV2ApiServiceDelegatorImpl's response is returned 
    assertNotNull(response);
    assertNotNull(response.getEntity());
    assertTrue(response.getEntity() instanceof Search);
    assertEquals(1, ((Search) response.getEntity()).getResults().size());
    assertEquals("some-orcid-id", ((Search) response.getEntity()).getResults().get(0).getOrcidIdentifier().getPath());
}
Also used : Response(javax.ws.rs.core.Response) PublicV2ApiServiceDelegatorImpl(org.orcid.api.publicV2.server.delegator.impl.PublicV2ApiServiceDelegatorImpl) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Search(org.orcid.jaxb.model.search_v2.Search) PublicV2ApiServiceVersionedDelegatorImpl(org.orcid.api.publicV2.server.delegator.impl.PublicV2ApiServiceVersionedDelegatorImpl) ArrayList(java.util.ArrayList) List(java.util.List) Result(org.orcid.jaxb.model.search_v2.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Search (org.orcid.jaxb.model.search_v2.Search)10 List (java.util.List)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Response (javax.ws.rs.core.Response)5 Result (org.orcid.jaxb.model.search_v2.Result)5 DBUnitTest (org.orcid.test.DBUnitTest)5 OrcidSearchManager (org.orcid.core.manager.OrcidSearchManager)4 OrcidIdentifier (org.orcid.jaxb.model.common_v2.OrcidIdentifier)4 PublicV2ApiServiceDelegatorImpl (org.orcid.api.publicV2.server.delegator.impl.PublicV2ApiServiceDelegatorImpl)3 OrcidSecurityManager (org.orcid.core.manager.OrcidSecurityManager)3 FundingList (org.orcid.jaxb.model.message.FundingList)3 MemberV2ApiServiceDelegatorImpl (org.orcid.api.memberV2.server.delegator.impl.MemberV2ApiServiceDelegatorImpl)2 BaseTest (org.orcid.core.BaseTest)2 OrcidSolrResults (org.orcid.utils.solr.entities.OrcidSolrResults)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1