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)));
}
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();
}
}
}
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);
}
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);
}
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);
}
}
Aggregations