Search in sources :

Example 1 with SearchResultTab

use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.

the class SearchPageComponentTest method blankQueryReturnsTabs.

@Test
public void blankQueryReturnsTabs() {
    MockHstRequest request = new MockHstRequest();
    request.setParameterMap("", Collections.emptyMap());
    int newsResults = 9;
    int tasksResults = 5;
    int teamsResults = 2;
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.NEWS)).thenReturn(newsResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TASKS)).thenReturn(tasksResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TEAMS)).thenReturn(teamsResults);
    underTest.doBeforeRender(request, new MockHstResponse());
    List<SearchResultTab> tabs = (List<SearchResultTab>) request.getAttribute(REQUEST_ATTR_SEARCH_TABS);
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.NEWS, newsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TASKS, tasksResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TEAMS, teamsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.PEOPLE, 0)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.ALL, newsResults + tasksResults + teamsResults)));
}
Also used : MockHstRequest(org.hippoecm.hst.mock.core.component.MockHstRequest) MockHstResponse(org.hippoecm.hst.mock.core.component.MockHstResponse) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with SearchResultTab

use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.

the class SearchPageComponentTest method newsQueryLimitsSearchAreaAndPopulatesTabs.

@Test
public void newsQueryLimitsSearchAreaAndPopulatesTabs() {
    MockHstRequest request = new MockHstRequest();
    request.setParameterMap("", Collections.emptyMap());
    request.addParameter(REQUEST_ATTR_AREA, "news");
    int newsResults = 53;
    int tasksResults = 5;
    int teamsResults = 2;
    Pageable<HippoBean> documentResults = new DefaultPagination<>(Collections.singletonList(new Task()), newsResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResults(Mockito.nullable(String.class), anyInt(), anyInt(), eq(SearchArea.NEWS))).thenReturn(documentResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TASKS)).thenReturn(tasksResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TEAMS)).thenReturn(teamsResults);
    underTest.doBeforeRender(request, new MockHstResponse());
    assertEquals(documentResults, request.getAttribute(REQUEST_ATTR_PAGEABLE));
    Mockito.verify(bloomreachSearchProvider, Mockito.never()).getBloomreachResultsCount(Mockito.nullable(String.class), eq(SearchArea.NEWS));
    List<SearchResultTab> tabs = (List<SearchResultTab>) request.getAttribute(REQUEST_ATTR_SEARCH_TABS);
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.NEWS, newsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TASKS, tasksResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TEAMS, teamsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.PEOPLE, 0)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.ALL, newsResults + tasksResults + teamsResults)));
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Task(uk.nhs.digital.intranet.beans.Task) MockHstRequest(org.hippoecm.hst.mock.core.component.MockHstRequest) MockHstResponse(org.hippoecm.hst.mock.core.component.MockHstResponse) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab) DefaultPagination(org.onehippo.cms7.essentials.components.paging.DefaultPagination) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with SearchResultTab

use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.

the class SearchPageComponentTest method peopleQueryReturnsResultsAndPopulatesTabs.

@Test
public void peopleQueryReturnsResultsAndPopulatesTabs() throws ProviderCommunicationException {
    MockHstRequest request = new MockHstRequest();
    request.setParameterMap("", Collections.emptyMap());
    request.addParameter(REQUEST_ATTR_QUERY, "query string here");
    mockHstRequestContext.setAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME, "logged-into-microsoft-access-token");
    request.addParameter(REQUEST_ATTR_AREA, "people");
    int newsResults = 13;
    int tasksResults = 5;
    int teamsResults = 2;
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(anyString(), eq(SearchArea.NEWS))).thenReturn(newsResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(anyString(), eq(SearchArea.TASKS))).thenReturn(tasksResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(anyString(), eq(SearchArea.TEAMS))).thenReturn(teamsResults);
    List<Person> expectedPeopleResults = Collections.singletonList(new Person("1", "bob", "finance"));
    Mockito.when(graphProvider.getPeople(anyString())).thenReturn(expectedPeopleResults);
    underTest.doBeforeRender(request, new MockHstResponse());
    assertEquals(expectedPeopleResults, request.getAttribute(REQUEST_ATTR_PEOPLE_RESULTS));
    Mockito.verify(bloomreachSearchProvider, Mockito.never()).getBloomreachResults(anyString(), anyInt(), anyInt(), any());
    List<SearchResultTab> tabs = (List<SearchResultTab>) request.getAttribute(REQUEST_ATTR_SEARCH_TABS);
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.NEWS, newsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TASKS, tasksResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TEAMS, teamsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.PEOPLE, expectedPeopleResults.size())));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.ALL, newsResults + tasksResults + teamsResults + expectedPeopleResults.size())));
}
Also used : MockHstRequest(org.hippoecm.hst.mock.core.component.MockHstRequest) MockHstResponse(org.hippoecm.hst.mock.core.component.MockHstResponse) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab) ArrayList(java.util.ArrayList) List(java.util.List) Person(uk.nhs.digital.intranet.model.Person) Test(org.junit.Test)

Example 4 with SearchResultTab

use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.

the class SearchPageComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    HstRequestContext requestContext = RequestContextProvider.get();
    List<SearchResultTab> searchResultTabs = new ArrayList<>();
    try {
        searchContent(request, searchResultTabs);
        searchPeople(request, searchResultTabs);
    } finally {
        request.setAttribute(REQUEST_ATTR_AREA, getAreaOption(request).getDisplayName());
        request.setAttribute(REQUEST_ATTR_QUERY, getSearchQuery(request, true));
        searchResultTabs.add(new SearchResultTab(SearchArea.ALL, searchResultTabs.stream().reduce(0, (sum, tab) -> sum + tab.getNumberOfResults(), Integer::sum)));
        searchResultTabs.sort(Comparator.comparing(SearchResultTab::getTabName));
        request.setAttribute(REQUEST_ATTR_SEARCH_TABS, searchResultTabs);
        request.setAttribute("authorizationUrl", getAuthorizationUrl());
        request.setAttribute("loginRequired", !hasValidAccessToken(requestContext));
    }
}
Also used : SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 5 with SearchResultTab

use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.

the class SearchPageComponent method searchContent.

private void searchContent(HstRequest request, List<SearchResultTab> searchResultTabs) {
    final SearchArea searchArea = getAreaOption(request);
    final String searchQuery = getSearchQuery(request, true);
    if (searchArea != SearchArea.PEOPLE) {
        final Pageable<HippoBean> bloomreachResults = bloomreachSearchProvider.getBloomreachResults(searchQuery, getComponentInfo(request).getPageSize(), getCurrentPage(request), searchArea);
        request.setAttribute(REQUEST_ATTR_PAGEABLE, bloomreachResults);
        if (searchArea != SearchArea.ALL) {
            searchResultTabs.add(new SearchResultTab(searchArea, Math.toIntExact(bloomreachResults.getTotal())));
        }
    }
    SearchArea.getDocumentSearchAreasWithout(searchArea).forEach(unselectedSearchArea -> searchResultTabs.add(new SearchResultTab(unselectedSearchArea, bloomreachSearchProvider.getBloomreachResultsCount(searchQuery, unselectedSearchArea))));
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) SearchArea(uk.nhs.digital.intranet.enums.SearchArea) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab)

Aggregations

SearchResultTab (uk.nhs.digital.intranet.model.SearchResultTab)8 MockHstRequest (org.hippoecm.hst.mock.core.component.MockHstRequest)5 MockHstResponse (org.hippoecm.hst.mock.core.component.MockHstResponse)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)2 SearchArea (uk.nhs.digital.intranet.enums.SearchArea)2 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 DefaultPagination (org.onehippo.cms7.essentials.components.paging.DefaultPagination)1 Task (uk.nhs.digital.intranet.beans.Task)1 Person (uk.nhs.digital.intranet.model.Person)1 ProviderCommunicationException (uk.nhs.digital.intranet.model.exception.ProviderCommunicationException)1