use of org.hippoecm.hst.core.request.HstRequestContext 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());
}
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class ApiEndpoint method getApiMasterParent.
public ApiMaster getApiMasterParent() {
final HstRequestContext context = RequestContextProvider.get();
try {
HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), "website:apiendpointgroups/website:apirequest/@hippo:docbase", ApiMaster.class, false);
linkedBeanQuery.setLimit(1);
HstQueryResult hstQueryResult = linkedBeanQuery.execute();
HippoBeanIterator hippoBeanIterator = hstQueryResult.getHippoBeans();
if (hippoBeanIterator.getSize() > 0) {
return (ApiMaster) hippoBeanIterator.nextHippoBean();
} else {
return null;
}
} catch (QueryException queryException) {
log.warn("QueryException ", queryException);
}
return null;
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class OrganisationDataResource method getOrg.
@GET
@Path("/")
public List<OdsOrganisation> getOrg(@Context HttpServletRequest request, @Context HttpServletResponse servletResponse, @QueryParam("orgName") String orgName) {
if (odsResults == null) {
try {
log.debug("Loading ODS Data");
HstRequestContext context = new DefaultRestContext(this, request).getRequestContext();
QueryManager manager = context.getSession().getWorkspace().getQueryManager();
Query jcrQuery = manager.createQuery("/jcr:root/content/assets//*[@jcr:primaryType='externalstorage:resource']", "xpath");
QueryResult execute = jcrQuery.execute();
NodeIterator iterator = execute.getNodes();
while (iterator.hasNext()) {
Node node = iterator.nextNode();
if (node.getPath().contains("/content/assets/ODS_Data")) {
Value val = node.getProperty("jcr:data").getValue();
// convert JSON array to Java List
odsResults = new ObjectMapper().readValue(val.getString().replace("\n", ""), new TypeReference<List<OdsOrganisation>>() {
});
break;
}
}
} catch (RepositoryException | JsonProcessingException e) {
log.debug("Failed to load ODS Data ", e);
}
}
List<OdsOrganisation> filterOrg = odsResults.stream().filter(b -> (b.getOrgName() + " " + b.getCode()).toUpperCase().contains(orgName.toUpperCase())).collect(Collectors.toList());
return filterOrg;
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class Series method getRelatedDocuments.
protected <T extends HippoBean> List<T> getRelatedDocuments(String property, Class<T> beanClass) throws HstComponentException, QueryException {
final HstRequestContext context = RequestContextProvider.get();
HstQuery query = ContentBeanUtils.createIncomingBeansQuery(this.getCanonicalBean(), context.getSiteContentBaseBean(), property, beanClass, false);
return toList(query.execute().getHippoBeans());
}
use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.
the class CiLandingComponent method doBeforeRender.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
request.setAttribute("document", ctx.getContentBean());
}
Aggregations