Search in sources :

Example 1 with CyberAlertComponentInfo

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);
    }
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) ObjectBeanManagerException(org.hippoecm.hst.content.beans.ObjectBeanManagerException) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) HstQueryBuilder(org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder) CyberAlertComponentInfo(uk.nhs.digital.common.components.info.CyberAlertComponentInfo) CyberAlert(uk.nhs.digital.website.beans.CyberAlert) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Aggregations

ObjectBeanManagerException (org.hippoecm.hst.content.beans.ObjectBeanManagerException)1 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)1 HstQueryBuilder (org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder)1 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)1 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 CyberAlertComponentInfo (uk.nhs.digital.common.components.info.CyberAlertComponentInfo)1 CyberAlert (uk.nhs.digital.website.beans.CyberAlert)1