Search in sources :

Example 1 with HstRequest

use of org.hippoecm.hst.core.component.HstRequest in project hippo by NHS-digital-website.

the class TaskHubComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    final ComponentList bean = (ComponentList) request.getRequestContext().getContentBean();
    List<?> priorityTaskList = getTasksFromLinkBlocks(bean.getBlocks()).filter(task -> ((Task) task).getPriorityAction()).collect(Collectors.toList());
    request.setAttribute("priorityTasks", priorityTaskList);
    List<?> alternativeTaskList = getTasksFromLinkBlocks(bean.getBlocks()).flatMap(task -> addAlternativeNameEntries((Task) task)).collect(Collectors.toList());
    request.setAttribute("alternativeTasks", alternativeTaskList);
}
Also used : Task(uk.nhs.digital.intranet.beans.Task) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) HstRequest(org.hippoecm.hst.core.component.HstRequest) ComponentList(uk.nhs.digital.website.beans.ComponentList) HstResponse(org.hippoecm.hst.core.component.HstResponse) uk.nhs.digital.common.components(uk.nhs.digital.common.components) Internallink(uk.nhs.digital.website.beans.Internallink) Collectors(java.util.stream.Collectors) Task(uk.nhs.digital.intranet.beans.Task) ComponentList(uk.nhs.digital.website.beans.ComponentList)

Example 2 with HstRequest

use of org.hippoecm.hst.core.component.HstRequest 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

Collectors (java.util.stream.Collectors)2 HstRequest (org.hippoecm.hst.core.component.HstRequest)2 HstResponse (org.hippoecm.hst.core.component.HstResponse)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)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 ConstraintBuilder.or (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or)1 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)1 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)1 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)1