Search in sources :

Example 6 with HstRequestContext

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

the class GeneralArticleComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest hstRequest, final HstResponse hstResponse) {
    super.doBeforeRender(hstRequest, hstResponse);
    final HstRequestContext context = RequestContextProvider.get();
    HttpServletRequest request = context.getServletRequest();
    Object bean = hstRequest.getAttribute(REQUEST_ATTR_DOCUMENT);
    if (bean != null && bean instanceof HippoBean) {
        General generalDocument = (General) bean;
        if (StringUtils.isNotBlank(generalDocument.getEarlyAccessKey()) && !generalDocument.getEarlyAccessKey().equals(request.getParameter("key"))) {
            LOGGER.debug("Early access key is set and no or wrong key is being used. Redirecting to 404 error code");
            hstResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
            HstResponseUtils.sendRedirect(hstRequest, hstResponse, "/error/404");
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) General(uk.nhs.digital.website.beans.General) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 7 with HstRequestContext

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

the class CyberAlert method getBasePath.

@JsonProperty
public String getBasePath() {
    if (getPublicallyAccessible() || getLimitedAccess()) {
        final HstRequestContext context = RequestContextProvider.get();
        if (context != null) {
            // DW-1077 - compose this documetn base URL for REST API purposes
            HttpServletRequest req = context.getServletRequest();
            StringBuffer url = req.getRequestURL();
            String base = url.substring(0, url.length() - req.getRequestURI().length() + req.getContextPath().length());
            // remove basepath part ('content/documents/corporate-website')
            // and compose full path
            String pathSuffix = this.getPath().replace("/" + context.getSiteContentBasePath(), "");
            // remove '/site/' if exists
            return (base + pathSuffix).replace("/site/", "/");
        }
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Example 8 with HstRequestContext

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

the class CyberAlert method getFullAccess.

@JsonIgnore
private Boolean getFullAccess() {
    Boolean fullAccess = true;
    final HstRequestContext context = RequestContextProvider.get();
    if (context != null) {
        HttpServletRequest request = context.getServletRequest();
        String limitedParam = request.getParameter("_limited");
        if (limitedParam != null && limitedParam.equals("true")) {
            fullAccess = false;
        }
    }
    return fullAccess;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 9 with HstRequestContext

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

the class Publishedworkchapter method getPublishedWork.

public Publishedwork getPublishedWork() {
    final HstRequestContext context = RequestContextProvider.get();
    // Publishedworkchapter publishedWorkChapter = context.getContentBean(Publishedworkchapter.class);
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:links/@hippo:docbase", Publishedwork.class, false);
        linkedBeanQuery.setLimit(1);
        return (Publishedwork) linkedBeanQuery.execute().getHippoBeans().nextHippoBean();
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
    return null;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 10 with HstRequestContext

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

the class ProjectUpdateFeedComponent method addOrganisationFilter.

private void addOrganisationFilter(List<BaseFilter> filters, HstRequest request, HstQuery query) {
    String organisationTitle = getSelectedOrganisationTitle(request);
    if (StringUtils.isNotBlank(organisationTitle)) {
        HippoBeanIterator organisationBeans;
        try {
            final HstRequestContext requestContext = request.getRequestContext();
            HstQuery orgQuery = requestContext.getQueryManager().createQuery(requestContext.getSiteContentBaseBean(), Organisation.class);
            Filter orgNameFilter = orgQuery.createFilter();
            orgNameFilter.addEqualToCaseInsensitive("website:title", organisationTitle);
            orgQuery.setFilter(orgNameFilter);
            organisationBeans = orgQuery.execute().getHippoBeans();
        } catch (QueryException e) {
            log.debug("Error finding organisation with title {}: {}", organisationTitle, e);
            return;
        }
        if (organisationBeans.getSize() == 0) {
            return;
        }
        String jcrQuery;
        if (organisationBeans.getSize() > 1) {
            StringBuilder jcrQueryBuilder = new StringBuilder(String.format("((website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
            while (organisationBeans.hasNext()) {
                jcrQueryBuilder.append(String.format(" or (website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID()));
            }
            jcrQueryBuilder.append(")");
            jcrQuery = jcrQueryBuilder.toString();
        } else {
            jcrQuery = String.format("(website:organisation/@hippo:docbase = '%s')", ((HippoDocument) organisationBeans.nextHippoBean()).getCanonicalHandleUUID());
        }
        Filter filter = query.createFilter();
        filter.addJCRExpression(jcrQuery);
        filters.add(filter);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoDocument(org.hippoecm.hst.content.beans.standard.HippoDocument) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) BaseFilter(org.hippoecm.hst.content.beans.query.filter.BaseFilter) Filter(org.hippoecm.hst.content.beans.query.filter.Filter) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) 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