Search in sources :

Example 1 with Pageable

use of org.onehippo.cms7.essentials.components.paging.Pageable in project hippo by NHS-digital-website.

the class SearchPageComponentTest method blankQueryReturnsDocumentsForAllDocTypes.

@Test
public void blankQueryReturnsDocumentsForAllDocTypes() {
    MockHstRequest request = new MockHstRequest();
    request.setParameterMap("", Collections.emptyMap());
    Pageable<HippoBean> documentResults = new DefaultPagination<>(Collections.singletonList(new Task()));
    Mockito.when(bloomreachSearchProvider.getBloomreachResults(Mockito.nullable(String.class), anyInt(), anyInt(), eq(SearchArea.ALL))).thenReturn(documentResults);
    underTest.doBeforeRender(request, new MockHstResponse());
    assertEquals(documentResults, request.getAttribute(REQUEST_ATTR_PAGEABLE));
}
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) DefaultPagination(org.onehippo.cms7.essentials.components.paging.DefaultPagination) Test(org.junit.Test)

Example 2 with Pageable

use of org.onehippo.cms7.essentials.components.paging.Pageable 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 Pageable

use of org.onehippo.cms7.essentials.components.paging.Pageable in project hippo by NHS-digital-website.

the class SearchComponentTest method pageableNumbersTest.

@Test
@UseDataProvider("pageableTests")
public void pageableNumbersTest(long maxPages, int currentPage, List<Integer> expected) throws Exception {
    Pageable pageable = mock(Pageable.class);
    given(pageable.getTotalPages()).willReturn(maxPages);
    given(pageable.getCurrentPage()).willReturn(currentPage);
    // then
    assertEquals("Pageable numbers are as expected", expected, searchComponent.getHstPageNumbers(pageable));
}
Also used : Pageable(org.onehippo.cms7.essentials.components.paging.Pageable) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with Pageable

use of org.onehippo.cms7.essentials.components.paging.Pageable in project hippo by NHS-digital-website.

the class FeedHubComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    filters = new ArrayList<>();
    filterValues = new HashMap<>();
    String[] yearParams = getPublicRequestParameters(request, "year");
    filterValues.put("year", yearParams);
    if (yearParams.length > 0) {
        filterValues.put("month", getPublicRequestParameters(request, "month"));
    }
    filterValues.put("type[]", getPublicRequestParameters(request, "type[]"));
    filterValues.put("severity", getPublicRequestParameters(request, "severity"));
    request.setAttribute("filterValues", filterValues);
    long filterCount = filterValues.values().stream().filter(value -> value.length > 0).count();
    request.setAttribute("filterCount", filterCount);
    queryText = getPublicRequestParameter(request, "query");
    if (queryText == null) {
        queryText = "";
    }
    request.setAttribute("query", queryText);
    sort = getPublicRequestParameter(request, "sort");
    if (sort == null) {
        sort = "date-desc";
    }
    request.setAttribute("sort", sort);
    String activeFiltersString = getPublicRequestParameter(request, "active-filters");
    if (activeFiltersString != null) {
        String[] activeFilters = activeFiltersString.split(",");
        request.setAttribute("activeFilters", activeFilters);
    }
    try {
        List<HippoBean> feed = getFeed(request);
        request.setAttribute("feed", feed);
        Pageable<HippoBean> pagedFeed = pageResults(feed, request);
        request.setAttribute("pageable", pagedFeed);
        final HstRequestContext context = request.getRequestContext();
        FeedHub feedHub = (FeedHub) context.getContentBean();
        switch(feedHub.getFeedType()) {
            case "News":
                getNewsFilters(feed);
                break;
            case "Supplementary information":
                getSupInfoFilters(feed);
                break;
            case "Events":
                getEventFilters(feed);
                break;
            case "Cyber Alerts":
                getCyberAlertFilters(feed);
                break;
            default:
        }
        request.setAttribute("filters", filters);
    } catch (QueryException e) {
        e.printStackTrace();
    }
}
Also used : Pageable(org.onehippo.cms7.essentials.components.paging.Pageable) java.util(java.util) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) HstRequest(org.hippoecm.hst.core.component.HstRequest) IteratorUtils.toList(org.apache.commons.collections.IteratorUtils.toList) ConstraintBuilder.or(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or) HstResponse(org.hippoecm.hst.core.component.HstResponse) SimpleDateFormat(java.text.SimpleDateFormat) ConstraintBuilder.and(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and) uk.nhs.digital.website.beans(uk.nhs.digital.website.beans) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) DateTools(org.hippoecm.repository.util.DateTools) Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) ParseException(java.text.ParseException) ConstraintBuilder.constraint(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Aggregations

HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)3 Test (org.junit.Test)3 MockHstRequest (org.hippoecm.hst.mock.core.component.MockHstRequest)2 MockHstResponse (org.hippoecm.hst.mock.core.component.MockHstResponse)2 DefaultPagination (org.onehippo.cms7.essentials.components.paging.DefaultPagination)2 Pageable (org.onehippo.cms7.essentials.components.paging.Pageable)2 Task (uk.nhs.digital.intranet.beans.Task)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)1 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)1 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)1 ConstraintBuilder.and (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and)1 ConstraintBuilder.constraint (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint)1