Search in sources :

Example 1 with HstQueryResult

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

the class CyberAlertComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    final CyberAlertComponentInfo componentParametersInfo = getComponentParametersInfo(request);
    final int configuredAlertSize = componentParametersInfo.getNumberOfAlertsToDisplay();
    request.setAttribute("title", componentParametersInfo.getTitle());
    try {
        final HippoBean baseContentBean = request.getRequestContext().getSiteContentBaseBean();
        final HippoBean cyberAlertScope = (HippoBean) request.getRequestContext().getObjectBeanManager().getObject(baseContentBean.getPath() + "/cyber-alerts");
        HstQueryBuilder builder = HstQueryBuilder.create(cyberAlertScope);
        HstQueryResult alertsQueryResult = builder.ofTypes(CyberAlert.class).orderByDescending("publicationsystem:NominalDate").build().execute();
        List<CyberAlert> alertsListToDisplay;
        if (alertsQueryResult != null && configuredAlertSize > 0) {
            alertsListToDisplay = createCyberAlertsList(configuredAlertSize, alertsQueryResult);
            request.setAttribute("cyberAlertList", alertsListToDisplay);
        }
    } catch (QueryException | ObjectBeanManagerException e) {
        LOGGER.error("Failed to execute Cyber Alerts Query ", e);
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ObjectBeanManagerException(org.hippoecm.hst.content.beans.ObjectBeanManagerException) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) CyberAlertComponentInfo(uk.nhs.digital.common.components.info.CyberAlertComponentInfo) CyberAlert(uk.nhs.digital.website.beans.CyberAlert) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 2 with HstQueryResult

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

the class ApiCatalogueJcrRepository method taxonomyFiltersMapping.

@Override
public Optional<String> taxonomyFiltersMapping() {
    try {
        final Node mappingDocumentHandle = JcrUtils.getNodeIfExists(TAXONOMY_FILTERS_MAPPING_DOCUMENT_PATH, session);
        if (mappingDocumentHandle == null) {
            log.warn("API Catalogue's taxonomy-filters mapping document not found at {}", TAXONOMY_FILTERS_MAPPING_DOCUMENT_PATH);
            return Optional.empty();
        }
        final HstQueryResult hstQueryResult = queryForPublishedVariant(mappingDocumentHandle).execute();
        return Optional.of(hstQueryResult.getHippoBeans()).filter(Iterator::hasNext).map(HippoBeanIterator::nextHippoBean).map(HippoBean::getProperty).map(properties -> properties.get("website:text")).filter(String.class::isInstance).map(String.class::cast);
    } catch (final Exception cause) {
        throw new RuntimeException("Failed to retrieve taxonomy-filters mapping YAML for scope node " + TAXONOMY_FILTERS_MAPPING_DOCUMENT_PATH, cause);
    }
}
Also used : HippoBeanIterator(org.hippoecm.hst.content.beans.standard.HippoBeanIterator) Node(javax.jcr.Node) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 3 with HstQueryResult

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

Example 4 with HstQueryResult

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

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

Aggregations

HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)15 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)12 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)10 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)9 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)7 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)4 CyberAlert (uk.nhs.digital.website.beans.CyberAlert)3 Node (javax.jcr.Node)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)2 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)2 java.util (java.util)1 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)1 RequestContextProvider (org.hippoecm.hst.container.RequestContextProvider)1 ObjectBeanManagerException (org.hippoecm.hst.content.beans.ObjectBeanManagerException)1 HstQueryManager (org.hippoecm.hst.content.beans.query.HstQueryManager)1 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)1 ConstraintBuilder.constraint (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.constraint)1 ConstraintBuilder.or (org.hippoecm.hst.content.beans.query.builder.ConstraintBuilder.or)1