Search in sources :

Example 16 with HstQuery

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

the class Person method getBusinessUnits.

public List<BusinessUnit> getBusinessUnits() throws HstComponentException, QueryException {
    Role role = this.getRoles();
    if (role != null) {
        HstQuery query = HstQueryBuilder.create(RequestContextProvider.get().getSiteContentBaseBean()).where(constraint("website:responsiblerole").notEqualTo(null)).ofTypes(BusinessUnit.class).orderByAscending("website:order").build();
        List<BusinessUnit> businessUnits = toList(query.execute().getHippoBeans());
        if (businessUnits.size() > 0) {
            List<BusinessUnit> filteredUnits = new ArrayList<BusinessUnit>();
            for (BusinessUnit unit : businessUnits) {
                List<HippoBean> rolepickers = role.getRolepicker();
                for (HippoBean picker : rolepickers) {
                    if (picker != null) {
                        JobRolePicker rolepicker = (JobRolePicker) picker;
                        CommonFieldsBean jobrole = (CommonFieldsBean) rolepicker.getPrimaryrolepicker();
                        JobRole unitrole = (JobRole) unit.getResponsiblerole();
                        if (jobrole != null && unitrole != null && unitrole.getSingleProperty("jcr:uuid").toString().equals(jobrole.getSingleProperty("jcr:uuid").toString())) {
                            filteredUnits.add(unit);
                        }
                    }
                }
            }
            return filteredUnits;
        }
    }
    return null;
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ArrayList(java.util.ArrayList)

Example 17 with HstQuery

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

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

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

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

the class FeedListComponent method executeQuery.

/**
 * Copied from uk.nhs.digital.common.components.EventsComponent
 * Added a check for the "website:event" doctype.
 * Runs super if not,
 * Super from org.onehippo.cms7.essentials.components.EssentialsListComponent;
 */
@Override
protected <T extends EssentialsListComponentInfo> Pageable<HippoBean> executeQuery(HstRequest request, T paramInfo, HstQuery query) throws QueryException {
    final FeedListComponentInfo info = getComponentParametersInfo(request);
    final String documentTypes = info.getDocumentTypes();
    if (documentTypes.equals("website:event")) {
        int pageSize = this.getPageSize(request, paramInfo);
        int page = this.getCurrentPage(request);
        query.setLimit(pageSize);
        query.setOffset((page - 1) * pageSize);
        this.applyExcludeScopes(request, query, paramInfo);
        this.buildAndApplyFilters(request, query);
        try {
            // the query coming from the component is manually extended since it needs to consider intervals
            String eventQueryString = query.getQueryAsString(true);
            // appending the query containing filters the on the interval compound
            String queryString = eventQueryString + addIntervalFilter(request);
            HstRequestContext requestContext = request.getRequestContext();
            QueryManager jcrQueryManager = requestContext.getSession().getWorkspace().getQueryManager();
            Query jcrQuery = jcrQueryManager.createQuery(queryString, "xpath");
            QueryResult queryResult = jcrQuery.execute();
            ObjectConverter objectConverter = requestContext.getContentBeansTool().getObjectConverter();
            NodeIterator it = queryResult.getNodes();
            List parentNodes = new ArrayList();
            List<String> parentPath = new ArrayList();
            // For this reason this component needs to fetch the parent node
            while (it.hasNext() && parentPath.size() < pageSize) {
                Node interval = it.nextNode();
                Node eventNode = interval.getParent();
                if (eventNode.getPrimaryNodeType().isNodeType("website:event") && !parentPath.contains(eventNode.getPath())) {
                    parentPath.add(eventNode.getPath());
                    parentNodes.add(objectConverter.getObject(eventNode));
                }
            }
            return this.getPageableFactory().createPageable(parentNodes, page, pageSize);
        } catch (RepositoryException repositoryEx) {
            throw new QueryException(repositoryEx.getMessage());
        } catch (ObjectBeanManagerException converterEx) {
            throw new QueryException(converterEx.getMessage());
        }
    } else {
        return super.executeQuery(request, paramInfo, query);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) Query(javax.jcr.query.Query) ObjectConverter(org.hippoecm.hst.content.beans.manager.ObjectConverter) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) FeedListComponentInfo(uk.nhs.digital.common.components.info.FeedListComponentInfo) ObjectBeanManagerException(org.hippoecm.hst.content.beans.ObjectBeanManagerException) QueryResult(javax.jcr.query.QueryResult) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) QueryManager(javax.jcr.query.QueryManager) ValueList(org.onehippo.forge.selection.hst.contentbean.ValueList) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

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