use of org.hippoecm.hst.content.beans.ObjectBeanManagerException 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);
}
}
use of org.hippoecm.hst.content.beans.ObjectBeanManagerException 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);
}
}
use of org.hippoecm.hst.content.beans.ObjectBeanManagerException in project hippo by NHS-digital-website.
the class EventsComponent method executeQuery.
@Override
protected <T extends EssentialsListComponentInfo> Pageable<HippoBean> executeQuery(HstRequest request, T paramInfo, HstQuery query) throws QueryException {
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());
}
}
Aggregations