Search in sources :

Example 31 with HstRequestContext

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

the class CommonFieldsBean method getInitialQuery.

protected <T extends HippoBean> HstQuery getInitialQuery(List<String> properties, Class<T> beanClass) throws HstComponentException, QueryException {
    final HstRequestContext context = RequestContextProvider.get();
    HstQuery query = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), properties, beanClass, false);
    return query;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 32 with HstRequestContext

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

the class PolicyPage method getPolicy.

public Policy getPolicy() {
    final HstRequestContext context = RequestContextProvider.get();
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:childPage/@hippo:docbase", Policy.class, false);
        linkedBeanQuery.setLimit(1);
        return (Policy) 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 33 with HstRequestContext

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

the class HubNewsAndEvents method getLatestBlog.

public List<HippoBean> getLatestBlog() throws QueryException {
    HstRequestContext requestContext = RequestContextProvider.get();
    HippoBean scope = requestContext.getSiteContentBaseBean();
    HstQuery hstBlogQuery = HstQueryBuilder.create(scope).ofTypes(Blog.class).orderByDescending("website:dateofpublication").build();
    HstQueryResult blogResult = hstBlogQuery.execute();
    return toList(blogResult.getHippoBeans());
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 34 with HstRequestContext

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

the class HubNewsAndEvents method getLatestNewsArticles.

public List<HippoBean> getLatestNewsArticles() throws QueryException {
    HstRequestContext requestContext = RequestContextProvider.get();
    HippoBean scope = requestContext.getSiteContentBaseBean().getBean("news/latest-news");
    HstQuery hstNewsQuery = HstQueryBuilder.create(scope).ofTypes(News.class).orderByDescending("website:publisheddatetime").build();
    HstQueryResult newsResult = hstNewsQuery.execute();
    return toList(newsResult.getHippoBeans());
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 35 with HstRequestContext

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

the class SupplementaryInformationHubComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    final HstRequestContext context = request.getRequestContext();
    final SupplementaryInformationHub document = (SupplementaryInformationHub) context.getContentBean();
    if (document != null) {
        request.setAttribute("document", document);
    }
    List<SupplementaryInformation> si = getListOfSupplementaryInformation();
    request.setAttribute("years", years(si));
    String selectedYear = DocumentUtils.findYearOrDefault(getSelectedYear(request), Calendar.getInstance().get(Calendar.YEAR));
    request.setAttribute("selectedYear", selectedYear);
    final Month selectedMonth = findMonthOrNull(getSelectedMonth(request));
    if (Objects.nonNull(selectedMonth)) {
        request.setAttribute("selectedMonth", selectedMonth);
    }
    request.setAttribute("months", months(Integer.parseInt(selectedYear), si));
}
Also used : SupplementaryInformation(uk.nhs.digital.website.beans.SupplementaryInformation) Month(java.time.Month) SupplementaryInformationHub(uk.nhs.digital.website.beans.SupplementaryInformationHub) 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