use of uk.nhs.digital.common.components.info.CyberAlertComponentInfo 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);
}
}
Aggregations