Search in sources :

Example 6 with HstQuery

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

the class PublicationBase method getRelatedDocuments.

protected <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 7 with HstQuery

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

the class ArchiveComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final HstRequestContext requestContext = request.getRequestContext();
    final HippoBean contentBean = requestContext.getContentBean();
    final Archive archiveIndexDocument;
    if (contentBean.isHippoFolderBean()) {
        final List<Archive> archiveIndexDocuments = contentBean.getChildBeans(Archive.class);
        if (archiveIndexDocuments.size() != 1) {
            reportInvalidTarget(request, contentBean, archiveIndexDocuments.size());
            return;
        }
        archiveIndexDocument = archiveIndexDocuments.get(0);
    } else if (contentBean instanceof Archive) {
        archiveIndexDocument = (Archive) contentBean;
    } else {
        reportInvalidInvocation(request, contentBean);
        return;
    }
    request.setAttribute("archive", archiveIndexDocument);
    try {
        final HstQuery query = requestContext.getQueryManager().createQuery(archiveIndexDocument.getParentBean(), Publication.class, LegacyPublication.class);
        query.addOrderByDescending("publicationsystem:NominalDate");
        final HstQueryResult hstQueryResult = query.execute();
        request.setAttribute("publications", hstQueryResult.getHippoBeans());
    } catch (QueryException queryException) {
        log.error("Failed to find publications for archive " + archiveIndexDocument.getTitle(), queryException);
        reportDisplayError(request, archiveIndexDocument.getTitle());
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) Archive(uk.nhs.digital.ps.beans.Archive) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 8 with HstQuery

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

the class BloomreachSearchProvider method getBloomreachResultsCount.

public int getBloomreachResultsCount(String queryString, SearchArea searchArea) {
    HstQuery query = getQuery(queryString, searchArea);
    query.setLimit(0);
    try {
        final HstQueryResult execute = query.execute();
        return execute.getTotalSize();
    } catch (QueryException e) {
        LOG.error("Error running query: {}", e.getMessage());
        LOG.debug("Query exception: ", e);
        return 0;
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 9 with HstQuery

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

the class ApiEndpoint method getApiMasterParent.

public ApiMaster getApiMasterParent() {
    final HstRequestContext context = RequestContextProvider.get();
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:apiendpointgroups/website:apirequest/@hippo:docbase", ApiMaster.class, false);
        linkedBeanQuery.setLimit(1);
        HstQueryResult hstQueryResult = linkedBeanQuery.execute();
        HippoBeanIterator hippoBeanIterator = hstQueryResult.getHippoBeans();
        if (hippoBeanIterator.getSize() > 0) {
            return (ApiMaster) hippoBeanIterator.nextHippoBean();
        } else {
            return null;
        }
    } 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) HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 10 with HstQuery

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

the class PolicyPageLinkedBeansComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    // linkPath property contains the relative path of the links property in the published workflow document
    String linkPath = getComponentParameter("linkPath");
    final HstRequestContext context = request.getRequestContext();
    // we assume a PublishedWorkChapter as content bean, thus expect a PublishedWork as "parent" document
    PolicyPage policyPage = context.getContentBean(PolicyPage.class);
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(policyPage, context.getSiteContentBaseBean(), linkPath, Policy.class, false);
        // chapter cannot be re-used across different publishedworkflow
        linkedBeanQuery.setLimit(1);
        // linked documents will contain the publishedworkflow document containing all the chapters
        HstQueryResult linkedDocuments = linkedBeanQuery.execute();
        request.setAttribute("linkeddocuments", linkedDocuments);
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) PolicyPage(uk.nhs.digital.website.beans.PolicyPage) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) 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