Search in sources :

Example 1 with Archive

use of uk.nhs.digital.ps.beans.Archive 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());
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) Archive(uk.nhs.digital.ps.beans.Archive) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Aggregations

HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)1 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)1 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)1 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 Archive (uk.nhs.digital.ps.beans.Archive)1