Search in sources :

Example 1 with Search

use of org.orcid.jaxb.model.v3.dev1.search.Search in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_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));
    MemberV3ApiServiceDelegatorImpl delegator = new MemberV3ApiServiceDelegatorImpl();
    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.v3.dev1.common.OrcidIdentifier) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) List(java.util.List) MemberV3ApiServiceDelegatorImpl(org.orcid.api.memberV3.server.delegator.impl.MemberV3ApiServiceDelegatorImpl) OrcidSearchManager(org.orcid.core.manager.v3.OrcidSearchManager) Result(org.orcid.jaxb.model.v3.dev1.search.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with Search

use of org.orcid.jaxb.model.v3.dev1.search.Search in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testSearchByQueryLegalStart.

@Test
public void testSearchByQueryLegalStart() {
    Map<String, List<String>> params = new HashMap<>();
    params.put("start", Arrays.asList(Integer.toString(OrcidSearchManager.MAX_SEARCH_START)));
    LocaleManager localeManager = Mockito.mock(LocaleManagerImpl.class);
    Mockito.when(localeManager.resolveMessage(Mockito.anyString())).thenReturn("a message");
    OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class);
    Mockito.when(orcidSearchManager.findOrcidIds(Mockito.anyMap())).thenReturn(new Search());
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null);
    PublicV3ApiServiceDelegatorImpl delegator = new PublicV3ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "localeManager", localeManager);
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    Response response = delegator.searchByQuery(params);
    assertNotNull(response);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) PublicV3ApiServiceDelegatorImpl(org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) ArrayList(java.util.ArrayList) List(java.util.List) LocaleManager(org.orcid.core.locale.LocaleManager) OrcidSearchManager(org.orcid.core.manager.v3.OrcidSearchManager) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with Search

use of org.orcid.jaxb.model.v3.dev1.search.Search in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorImpl method searchByQuery.

@Override
public Response searchByQuery(Map<String, List<String>> solrParams) {
    validateSearchParams(solrParams);
    Search search = orcidSearchManager.findOrcidIds(solrParams);
    return Response.ok(search).build();
}
Also used : Search(org.orcid.jaxb.model.v3.dev1.search.Search)

Example 4 with Search

use of org.orcid.jaxb.model.v3.dev1.search.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) OrcidSearchManager(org.orcid.core.manager.v3.OrcidSearchManager) Arrays(java.util.Arrays) Date(java.util.Date) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) DateUtils(org.orcid.utils.DateUtils) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) ProfileDao(org.orcid.persistence.dao.ProfileDao) Map(java.util.Map) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) Result(org.orcid.jaxb.model.v3.dev1.search.Result) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) Jpa2JaxbAdapter(org.orcid.core.adapter.Jpa2JaxbAdapter) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) RecordManagerReadOnly(org.orcid.core.manager.v3.read_only.RecordManagerReadOnly) Resource(javax.annotation.Resource) FundingList(org.orcid.jaxb.model.message.FundingList) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) DeactivatedException(org.orcid.core.exception.DeactivatedException) OrcidSearchResults(org.orcid.jaxb.model.message.OrcidSearchResults) List(java.util.List) LockedException(org.orcid.core.security.aop.LockedException) 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) LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults) Result(org.orcid.jaxb.model.v3.dev1.search.Result) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult)

Example 5 with Search

use of org.orcid.jaxb.model.v3.dev1.search.Search in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest 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);
    PublicV3ApiServiceDelegatorImpl delegator = new PublicV3ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null);
    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) OrcidIdentifier(org.orcid.jaxb.model.v3.dev1.common.OrcidIdentifier) PublicV3ApiServiceDelegatorImpl(org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl) Search(org.orcid.jaxb.model.v3.dev1.search.Search) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) ArrayList(java.util.ArrayList) List(java.util.List) OrcidSearchManager(org.orcid.core.manager.v3.OrcidSearchManager) Result(org.orcid.jaxb.model.v3.dev1.search.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Search (org.orcid.jaxb.model.v3.dev1.search.Search)8 List (java.util.List)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 OrcidSearchManager (org.orcid.core.manager.v3.OrcidSearchManager)4 Response (javax.ws.rs.core.Response)3 OrcidSecurityManager (org.orcid.core.manager.v3.OrcidSecurityManager)3 FundingList (org.orcid.jaxb.model.message.FundingList)3 Result (org.orcid.jaxb.model.v3.dev1.search.Result)3 PublicV3ApiServiceDelegatorImpl (org.orcid.api.publicV3.server.delegator.impl.PublicV3ApiServiceDelegatorImpl)2 BaseTest (org.orcid.core.BaseTest)2 OrcidIdentifier (org.orcid.jaxb.model.v3.dev1.common.OrcidIdentifier)2 DBUnitTest (org.orcid.test.DBUnitTest)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 Date (java.util.Date)1 HashMap (java.util.HashMap)1