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());
}
}
Aggregations