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());
}
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());
}
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;
}
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);
}
}
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();
}
}
Aggregations