Search in sources :

Example 21 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class DatasetComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final HstRequestContext ctx = request.getRequestContext();
    Dataset dataset = (Dataset) ctx.getContentBean();
    if (!dataset.isPubliclyAccessible()) {
        try {
            response.forward("/error/404");
        } catch (IOException ioException) {
            throw new HstComponentException("forward failed", ioException);
        }
        return;
    }
    request.setAttribute("dataset", dataset);
}
Also used : Dataset(uk.nhs.digital.ps.beans.Dataset) IOException(java.io.IOException) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 22 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class PublicationComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final HstRequestContext ctx = request.getRequestContext();
    Publication publication = (Publication) ctx.getContentBean();
    request.setAttribute("publication", publication);
    request.setAttribute("index", getIndex(publication));
    request.setAttribute("keyFactImageSections", pageSectionGrouper.groupSections(publication.getKeyFactImages()));
}
Also used : Publication(uk.nhs.digital.ps.beans.Publication) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 23 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class AccessTokenValve method invoke.

@Override
public void invoke(final ValveContext context) throws ContainerException {
    try {
        final HstRequestContext requestContext = context.getRequestContext();
        final Optional<Cookie> cookieOptional = getCookie(requestContext.getServletRequest(), Constants.ACCESS_TOKEN_COOKIE_NAME);
        if (cookieOptional.isPresent()) {
            final Cookie cookie = cookieOptional.get();
            AccessToken accessToken = encoder.decode(cookie.getValue());
            if (accessToken.isExpired()) {
                try {
                    accessToken = getNewAccessToken(requestContext, accessToken);
                } catch (final AuthorizationException e) {
                    LOGGER.warn("Refresh token expired or not existent. User will need to login again.");
                    removeAccessToken(requestContext);
                    return;
                }
            }
            requestContext.setAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME, accessToken.getToken());
        }
    } finally {
        context.invokeNext();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) AuthorizationException(uk.nhs.digital.intranet.model.exception.AuthorizationException) AccessToken(uk.nhs.digital.intranet.model.AccessToken) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 24 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class NiHubComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final HstRequestContext ctx = request.getRequestContext();
    request.setAttribute("document", ctx.getContentBean());
}
Also used : HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 25 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext 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

HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)42 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)17 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)11 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)8 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)8 RepositoryException (javax.jcr.RepositoryException)6 Query (javax.jcr.query.Query)5 QueryManager (javax.jcr.query.QueryManager)5 QueryResult (javax.jcr.query.QueryResult)5 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)5 Node (javax.jcr.Node)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 NodeIterator (javax.jcr.NodeIterator)3 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)3 ValueList (org.onehippo.forge.selection.hst.contentbean.ValueList)3 Collectors (java.util.stream.Collectors)2 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)2 ObjectBeanManagerException (org.hippoecm.hst.content.beans.ObjectBeanManagerException)2 ObjectConverter (org.hippoecm.hst.content.beans.manager.ObjectConverter)2 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)2