Search in sources :

Example 6 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean 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 7 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class CustomBreadcrumbProvider method addURLBasedParentItems.

@Override
protected void addURLBasedParentItems(final List<BreadcrumbItem> items, final HippoBean currentBean, final ResolvedSiteMapItem currentSmi, final ResolvedSiteMapItem deepestExpandedmenuItemSmi, final HstRequest request) {
    final String ancestorPath = deepestExpandedmenuItemSmi.getPathInfo();
    final String currentPath = currentSmi.getPathInfo();
    if (currentPath.startsWith(ancestorPath)) {
        String trailingPath = currentPath.substring(ancestorPath.length());
        if (trailingPath.startsWith("/")) {
            trailingPath = trailingPath.substring(1);
        }
        if (trailingPath.endsWith("/_index_")) {
            trailingPath = trailingPath.substring(0, trailingPath.indexOf("/_index_"));
        }
        int steps = trailingPath.split("/").length;
        HippoBean currentItemBean = currentBean;
        for (int i = 0; i < steps; i++) {
            BreadcrumbItem item = getBreadcrumbItem(request, currentItemBean);
            if (item != null) {
                items.add(item);
            }
            currentItemBean = currentItemBean.getParentBean();
        }
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) BreadcrumbItem(org.onehippo.forge.breadcrumb.om.BreadcrumbItem)

Example 8 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class CallToActionComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    CallToActionComponentInfo info = getComponentParametersInfo(request);
    HippoBean document = getHippoBeanForPath(info.getDocument(), HippoBean.class);
    request.setAttribute("document", document);
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) CallToActionComponentInfo(uk.nhs.digital.common.components.info.CallToActionComponentInfo)

Example 9 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class CaseStudyComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    CaseStudyComponentInfo componentInfo = getComponentParametersInfo(request);
    final String textAlignment = componentInfo.getTextAlignment();
    HippoBean document = getHippoBeanForPath(componentInfo.getDocument(), HippoBean.class);
    request.setAttribute("document", document);
    request.setAttribute("textAlignment", textAlignment);
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) CaseStudyComponentInfo(uk.nhs.digital.common.components.info.CaseStudyComponentInfo)

Example 10 with HippoBean

use of org.hippoecm.hst.content.beans.standard.HippoBean in project hippo by NHS-digital-website.

the class CyberAlertComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    final CyberAlertComponentInfo componentParametersInfo = getComponentParametersInfo(request);
    final int configuredAlertSize = componentParametersInfo.getNumberOfAlertsToDisplay();
    request.setAttribute("title", componentParametersInfo.getTitle());
    try {
        final HippoBean baseContentBean = request.getRequestContext().getSiteContentBaseBean();
        final HippoBean cyberAlertScope = (HippoBean) request.getRequestContext().getObjectBeanManager().getObject(baseContentBean.getPath() + "/cyber-alerts");
        HstQueryBuilder builder = HstQueryBuilder.create(cyberAlertScope);
        HstQueryResult alertsQueryResult = builder.ofTypes(CyberAlert.class).orderByDescending("publicationsystem:NominalDate").build().execute();
        List<CyberAlert> alertsListToDisplay;
        if (alertsQueryResult != null && configuredAlertSize > 0) {
            alertsListToDisplay = createCyberAlertsList(configuredAlertSize, alertsQueryResult);
            request.setAttribute("cyberAlertList", alertsListToDisplay);
        }
    } catch (QueryException | ObjectBeanManagerException e) {
        LOGGER.error("Failed to execute Cyber Alerts Query ", e);
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ObjectBeanManagerException(org.hippoecm.hst.content.beans.ObjectBeanManagerException) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) CyberAlertComponentInfo(uk.nhs.digital.common.components.info.CyberAlertComponentInfo) CyberAlert(uk.nhs.digital.website.beans.CyberAlert) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Aggregations

HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)46 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)10 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)10 ArrayList (java.util.ArrayList)7 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)7 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)7 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)6 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)5 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)5 SimpleDateFormat (java.text.SimpleDateFormat)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)4 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)4 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)4 DateTools (org.hippoecm.repository.util.DateTools)4 ParseException (java.text.ParseException)3 Function (java.util.function.Function)3 Node (javax.jcr.Node)3 ConstraintBuilder.and (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.and)3