use of org.hippoecm.hst.content.beans.query.exceptions.QueryException 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();
}
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException 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());
}
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException 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;
}
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException 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;
}
use of org.hippoecm.hst.content.beans.query.exceptions.QueryException in project hippo by NHS-digital-website.
the class ProjectUpdateFeedComponent method doBeforeRender.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
super.doBeforeRender(request, response);
final HippoBean document = request.getRequestContext().getContentBean();
if (document != null) {
request.setAttribute("document", document);
}
try {
List<ProjectUpdate> unfilteredResults = toList(HstQueryBuilder.create(document.getParentBean()).ofTypes(ProjectUpdate.class).build().execute().getHippoBeans());
request.setAttribute("organisations", organisations(unfilteredResults));
request.setAttribute("updateTypes", types(unfilteredResults));
request.setAttribute("years", years(unfilteredResults));
} catch (QueryException e) {
log.error("Query for filter generation failed: {}", e.getMessage());
}
request.setAttribute("selectedOrganisation", getSelectedOrganisationTitle(request));
request.setAttribute("selectedUpdateType", getSelectedUpdateType(request));
request.setAttribute("selectedYear", getYearToFilter(request));
}
Aggregations