Search in sources :

Example 1 with HstQuery

use of org.hippoecm.hst.content.beans.query.HstQuery in project hippo by NHS-digital-website.

the class Task method getRelatedDocuments.

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

Example 2 with HstQuery

use of org.hippoecm.hst.content.beans.query.HstQuery in project hippo by NHS-digital-website.

the class CommonFieldsBean method getRelatedDocuments.

protected <T extends HippoBean> List<T> getRelatedDocuments(List<String> properties, int limit, String orderBy, String orderDirection, Class<T> beanClass, List<BaseFilter> andFilters) throws HstComponentException, QueryException {
    HstQuery query = getInitialQuery(properties, beanClass);
    applyRestrictionsToQuery(query, limit, orderBy, orderDirection, andFilters);
    return toList(query.execute().getHippoBeans());
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery)

Example 3 with HstQuery

use of org.hippoecm.hst.content.beans.query.HstQuery 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 4 with HstQuery

use of org.hippoecm.hst.content.beans.query.HstQuery 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)

Example 5 with HstQuery

use of org.hippoecm.hst.content.beans.query.HstQuery in project hippo by NHS-digital-website.

the class CiBreadcrumbProvider method loadCiLandingBean.

/**
 * <p>
 * Query the repository to see if this document sits under one of the Clinical Indicator
 * folders, and if so load in the CiLanding bean (which is used to create the breadcrumb).
 * The CiLanding document has a property called urlNameOfContentFolder which links
 * the CiLanding page to the appropriate content folder
 * </p>
 */
private void loadCiLandingBean() {
    HstQueryBuilder queryBuilder = HstQueryBuilder.create(RequestContextProvider.get().getSiteContentBaseBean());
    final HstQueryResult hstQueryResult;
    Constraint[] constraints = Arrays.stream(currentDocumentBean.getPath().split("/")).map((pathSegment) -> constraint("publicationsystem:urlNameOfContentFolder").equalTo(pathSegment)).toArray(Constraint[]::new);
    final HstQuery query = queryBuilder.ofTypes(CiLanding.class).where(or(constraints)).build();
    try {
        hstQueryResult = query.execute();
    } catch (QueryException queryException) {
        throw new HstComponentException("Exception occurred during ci folder search.", queryException);
    }
    if (hstQueryResult.getHippoBeans().hasNext()) {
        isClinicalIndicator = true;
        ciLandingBean = (CiLanding) hstQueryResult.getHippoBeans().nextHippoBean();
    }
}
Also used : BreadcrumbItem(org.onehippo.forge.breadcrumb.om.BreadcrumbItem) java.util(java.util) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) HstRequest(org.hippoecm.hst.core.component.HstRequest) ConstraintBuilder.or(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoFolder(org.hippoecm.hst.content.beans.standard.HippoFolder) Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) uk.nhs.digital.ps.beans(uk.nhs.digital.ps.beans) RequestContextProvider(org.hippoecm.hst.container.RequestContextProvider) ConstraintBuilder.constraint(org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) Constraint(org.hippoecm.hst.content.beans.query.builder.Constraint) HstComponentException(org.hippoecm.hst.core.component.HstComponentException) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Aggregations

HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)26 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)18 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)15 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)12 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)7 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)4 Filter (org.hippoecm.hst.content.beans.query.filter.Filter)4 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)4 Node (javax.jcr.Node)3 BaseFilter (org.hippoecm.hst.content.beans.query.filter.BaseFilter)3 ValueList (org.onehippo.forge.selection.hst.contentbean.ValueList)3 NodeIterator (javax.jcr.NodeIterator)2 RepositoryException (javax.jcr.RepositoryException)2 Query (javax.jcr.query.Query)2 QueryManager (javax.jcr.query.QueryManager)2 QueryResult (javax.jcr.query.QueryResult)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ObjectBeanManagerException (org.hippoecm.hst.content.beans.ObjectBeanManagerException)2 ObjectConverter (org.hippoecm.hst.content.beans.manager.ObjectConverter)2